internal void ProcessDrop(ColumnManagerCell draggedCell)
        {
            ColumnReorderingDragSourceManager manager = null;

            if (draggedCell != null)
            {
                manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;
            }

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                manager.CommitReordering();
            }
            else
            {
                int oldPosition = draggedCell.ParentColumn.VisiblePosition;
                int newPosition = this.ParentColumn.VisiblePosition;

                if (m_dropMarkAdorner != null)
                {
                    DropMarkAlignment alignment = m_dropMarkAdorner.Alignment;

                    this.HideDropMark();

                    if (draggedCell.ParentColumn.VisiblePosition < newPosition)
                    {
                        if (alignment == DropMarkAlignment.Near)
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition - 1;
                        }
                        else
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition;
                        }
                    }
                    else
                    {
                        if (alignment == DropMarkAlignment.Near)
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition;
                        }
                        else
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition + 1;
                        }
                    }

                    // This will force every Rows to update there layout
                    ColumnReorderingEventArgs e = new ColumnReorderingEventArgs(ColumnManagerCell.ColumnReorderingEvent, oldPosition, newPosition);
                    this.RaiseEvent(e);
                }
            }
        }
Example #2
0
        private void ShowDropMark(Point mousePosition, DropMarkAlignment defaultAlignment, bool forceDefaultAlignment)
        {
            if (m_dropMarkAdorner == null)
            {
                DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                DataGridControl grid = (dataGridContext != null)
          ? dataGridContext.DataGridControl
          : null;

                Pen pen = UIViewBase.GetDropMarkPen(this);

                if ((pen == null) && (grid != null))
                {
                    UIViewBase uiViewBase = grid.GetView() as UIViewBase;
                    pen = uiViewBase.DefaultDropMarkPen;
                }

                DropMarkOrientation orientation = Nequeo.Wpf.DataGrid.Views.UIViewBase.GetDropMarkOrientation(this);

                if ((orientation == DropMarkOrientation.Default) && (grid != null))
                {
                    UIViewBase uiViewBase = grid.GetView() as UIViewBase;

                    orientation = uiViewBase.DefaultDropMarkOrientation;
                }

                m_dropMarkAdorner = new DropMarkAdorner(this, pen, orientation);

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);

                if (adornerLayer != null)
                {
                    adornerLayer.Add(m_dropMarkAdorner);
                }
            }

            if (forceDefaultAlignment)
            {
                m_dropMarkAdorner.ForceAlignment(defaultAlignment);
            }
            else
            {
                m_dropMarkAdorner.UpdateAlignment(mousePosition);
            }
        }
Example #3
0
        void IDropTarget.Drop(UIElement draggedElement)
        {
            if (m_dropMarkAdorner != null)
            {
                DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                Debug.Assert(dataGridContext != null);
                if (dataGridContext != null)
                {
                    GroupLevelDescription draggedOverGroupLevelDescription = this.Content as GroupLevelDescription;

                    Debug.Assert(draggedOverGroupLevelDescription != null);
                    if (draggedOverGroupLevelDescription != null)
                    {
                        DropMarkAlignment alignment = m_dropMarkAdorner.Alignment;

                        this.HideDropMark();

                        ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

                        if (draggedCell != null)
                        {
                            GroupingHelper.AddNewGroupFromColumnManagerCell(draggedCell, draggedOverGroupLevelDescription, alignment, dataGridContext.DataGridControl);
                        }
                        else
                        {
                            GroupByItem draggedGroupBy = draggedElement as GroupByItem;

                            Debug.Assert(draggedGroupBy != null);

                            if (draggedGroupBy != null)
                            {
                                GroupLevelDescription draggedGroupLevelDescription = draggedGroupBy.Content as GroupLevelDescription;

                                GroupingHelper.MoveGroupDescription(dataGridContext.Columns, dataGridContext.Items.GroupDescriptions, draggedOverGroupLevelDescription, alignment, draggedGroupLevelDescription, dataGridContext.DataGridControl);
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        public void UpdateAlignment(Point mousePosition)
        {
            DropMarkAlignment alignment = DropMarkAlignment.Near;

            if (m_orientation == DropMarkOrientation.Horizontal)
            {
                // A horizontal drop mark is either displayed at the top or at the bottom of the AdornedElement.
                Rect hitTestRect = new Rect(0d, 0d, this.AdornedElement.RenderSize.Width, this.AdornedElement.RenderSize.Height / 2);

                if (hitTestRect.Contains(mousePosition))
                {
                    alignment = DropMarkAlignment.Near;
                }
                else
                {
                    alignment = DropMarkAlignment.Far;
                }
            }
            else
            {
                // A vertical drop mark is either displayed at the left or at the right of the AdornedElement.
                Rect hitTestRect = new Rect(0d, 0d, this.AdornedElement.RenderSize.Width / 2, this.AdornedElement.RenderSize.Height);

                if (hitTestRect.Contains(mousePosition))
                {
                    alignment = DropMarkAlignment.Near;
                }
                else
                {
                    alignment = DropMarkAlignment.Far;
                }
            }

            if (alignment != m_alignment)
            {
                m_alignment = alignment;
                this.UpdatePosition();
            }
        }
Example #5
0
        void IDropTarget.Drop(UIElement draggedElement)
        {
            ColumnManagerCell draggedColumnManagerCell = draggedElement as ColumnManagerCell;

            if (m_dropMarkAdorner != null)
            {
                GroupLevelDescription draggedOverGroupLevelDescription = this.Content as GroupLevelDescription;

                DropMarkAlignment alignment = m_dropMarkAdorner.Alignment;
                this.HideDropMark();

                if (draggedColumnManagerCell != null)
                {
                    DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                    DataGridControl parentGrid = (dataGridContext != null)
            ? dataGridContext.DataGridControl
            : null;

                    GroupingHelper.AddNewGroupFromColumnManagerCell(draggedColumnManagerCell, draggedOverGroupLevelDescription, alignment, parentGrid);
                }
                else
                {
                    HierarchicalGroupByItem draggedGroupByItem = draggedElement as HierarchicalGroupByItem;

                    if (draggedGroupByItem == null)
                    {
                        return;
                    }

                    GroupLevelDescription draggedGroupLevelDescription = draggedGroupByItem.Content as GroupLevelDescription;

                    DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                    DataGridControl parentDataGridControl = (dataGridContext != null)
            ? dataGridContext.DataGridControl
            : null;

                    GroupLevelDescription destinationGroupLevelDescription = this.Content as GroupLevelDescription;

                    GroupingHelper.MoveGroupDescription(this.ParentColumns, this.ParentGroupDescriptions,
                                                        destinationGroupLevelDescription, alignment,
                                                        draggedGroupLevelDescription, parentDataGridControl);
                }
            }
            else
            {
                // We try to add a new Group which is not in the current GroupLevelDescriptions
                if (draggedColumnManagerCell == null)
                {
                    return;
                }

                DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                DataGridControl parentGrid = (dataGridContext != null)
          ? dataGridContext.DataGridControl
          : null;

                GroupingHelper.AppendNewGroupFromColumnManagerCell(draggedColumnManagerCell, parentGrid);
            }

            HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

            Debug.Assert(parentGBC != null);
            if (parentGBC == null)
            {
                throw new DataGridInternalException("A hierarchical group-by item must be rooted by a HierarchicalGroupByControl.");
            }

            // Notify groups have changed for NoGroupContent
            parentGBC.UpdateHasGroups();
        }
Example #6
0
        public static void MoveGroupDescription(ColumnCollection targetColumns, ObservableCollection <GroupDescription> targetGroupDescriptions, GroupLevelDescription targetGroupLevelDescription, DropMarkAlignment targetAlignment, GroupLevelDescription movedGroupLevelDescription, DataGridControl parentDataGridControl)
        {
            Debug.Assert(targetColumns != null);
            Debug.Assert(targetGroupDescriptions != null);
            Debug.Assert(targetGroupLevelDescription != null);
            Debug.Assert(movedGroupLevelDescription != null);

            if ((parentDataGridControl == null) ||
                (targetColumns == null) ||
                (targetGroupDescriptions == null) ||
                (targetGroupLevelDescription == null) ||
                (movedGroupLevelDescription == null))
            {
                return;
            }

            int oldPos = GroupingHelper.GetGroupDescriptionIndex(targetGroupDescriptions, movedGroupLevelDescription, DropMarkAlignment.Near);
            int newPos = GroupingHelper.GetGroupDescriptionIndex(targetGroupDescriptions, targetGroupLevelDescription, targetAlignment);

            if (newPos > oldPos)
            {
                newPos--;
            }

            if (newPos != oldPos)
            {
                Debug.Assert(oldPos < targetGroupDescriptions.Count);

                targetGroupDescriptions.Move(oldPos, newPos);
            }
        }
Example #7
0
        public static void AddNewGroupFromColumnManagerCell(ColumnManagerCell cell, GroupLevelDescription draggedOverDescription, DropMarkAlignment alignment, DataGridControl parentDataGridControl)
        {
            if (cell == null)
            {
                return;
            }

            DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext(cell);
            DataGridControl cellParentGrid      = cellDataGridContext.DataGridControl;

            if ((cellDataGridContext == null) ||
                (parentDataGridControl == null) ||
                (parentDataGridControl != cellParentGrid))
            {
                return;
            }

            // By default, add it at the end
            int newPos = cellDataGridContext.GroupLevelDescriptions.Count;

            if (draggedOverDescription != null)
            {
                newPos = GroupingHelper.GetGroupDescriptionIndexFromFieldName(cellDataGridContext, draggedOverDescription.FieldName, alignment);
            }

            ColumnBase column = cell.ParentColumn;

            if (column != null)
            {
                GroupingHelper.AddNewGroupFromColumn(column, cellDataGridContext.Items.GroupDescriptions, newPos);
            }
        }
Example #8
0
    public static void MoveGroupDescription( ColumnCollection targetColumns, ObservableCollection<GroupDescription> targetGroupDescriptions, GroupLevelDescription targetGroupLevelDescription, DropMarkAlignment targetAlignment, GroupLevelDescription movedGroupLevelDescription, DataGridControl parentDataGridControl )
    {
      Debug.Assert( targetColumns != null );
      Debug.Assert( targetGroupDescriptions != null );
      Debug.Assert( targetGroupLevelDescription != null );
      Debug.Assert( movedGroupLevelDescription != null );

      if( ( parentDataGridControl == null ) ||
          ( targetColumns == null ) ||
          ( targetGroupDescriptions == null ) ||
          ( targetGroupLevelDescription == null ) ||
          ( movedGroupLevelDescription == null ) )
        return;

      int oldPos = GroupingHelper.GetGroupDescriptionIndex( targetGroupDescriptions, movedGroupLevelDescription, DropMarkAlignment.Near );
      int newPos = GroupingHelper.GetGroupDescriptionIndex( targetGroupDescriptions, targetGroupLevelDescription, targetAlignment );

      if( newPos > oldPos )
        newPos--;

      if( newPos != oldPos )
      {
        Debug.Assert( oldPos < targetGroupDescriptions.Count );

        targetGroupDescriptions.Move( oldPos, newPos );
      }
    }
        public static void AddNewGroupFromColumnManagerCell(ColumnManagerCell cell, GroupLevelDescription draggedOverDescription, DropMarkAlignment alignment, DataGridControl parentDataGridControl)
        {
            if (cell == null)
            {
                return;
            }

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(cell);
            ColumnBase      column          = cell.ParentColumn;

            if ((dataGridContext == null) ||
                (parentDataGridControl == null) ||
                (column == null) ||
                (parentDataGridControl != dataGridContext.DataGridControl))
            {
                return;
            }

            var addGroupCommand = dataGridContext.AddGroupCommand;

            if (draggedOverDescription != null)
            {
                var position = GroupingHelper.GetGroupDescriptionIndexFromFieldName(dataGridContext, draggedOverDescription.FieldName, alignment);

                if (addGroupCommand.CanExecute(column, position))
                {
                    addGroupCommand.Execute(column, position);
                }
            }
            else
            {
                if (addGroupCommand.CanExecute(column))
                {
                    addGroupCommand.Execute(column);
                }
            }
        }
Example #10
0
 public void ForceAlignment(DropMarkAlignment alignment)
 {
     m_alignment = alignment;
 }
    public static int GetGroupDescriptionIndex( ObservableCollection<GroupDescription> groupDescriptions, GroupLevelDescription groupLevelDescription, DropMarkAlignment alignment )
    {
      int groupIndex = groupDescriptions.IndexOf( groupLevelDescription.GroupDescription );

      if( groupIndex > -1 )
      {
        if( alignment == DropMarkAlignment.Far )
          groupIndex++;

        return groupIndex;
      }
      else
      {
        // return the size of the Collection if not found
        return groupDescriptions.Count;
      }
    }
    public static void MoveGroupDescription( ColumnCollection targetColumns, ObservableCollection<GroupDescription> targetGroupDescriptions, GroupLevelDescription targetGroupLevelDescription, DropMarkAlignment targetAlignment, GroupLevelDescription movedGroupLevelDescription, DataGridControl parentDataGridControl )
    {
      Debug.Assert( targetColumns != null );
      Debug.Assert( targetGroupDescriptions != null );
      Debug.Assert( targetGroupLevelDescription != null );
      Debug.Assert( movedGroupLevelDescription != null );

      if( ( parentDataGridControl == null ) ||
          ( targetColumns == null ) ||
          ( targetGroupDescriptions == null ) ||
          ( targetGroupLevelDescription == null ) ||
          ( movedGroupLevelDescription == null ) )
        return;

      int oldPos = GroupingHelper.GetGroupDescriptionIndex( targetGroupDescriptions, movedGroupLevelDescription, DropMarkAlignment.Near );
      int newPos = GroupingHelper.GetGroupDescriptionIndex( targetGroupDescriptions, targetGroupLevelDescription, targetAlignment );

      if( newPos > oldPos )
      {
        newPos--;
      }

      if( newPos != oldPos )
      {
        Debug.Assert( oldPos < targetGroupDescriptions.Count );

        using( parentDataGridControl.SetQueueBringIntoViewRestrictions( AutoScrollCurrentItemSourceTriggers.CollectionViewCurrentItemChanged ) )
        {
          targetGroupDescriptions.Move( oldPos, newPos );
        }
      }
    }
    public static void AddNewGroupFromColumnManagerCell( ColumnManagerCell cell, GroupLevelDescription draggedOverDescription, DropMarkAlignment alignment, DataGridControl parentDataGridControl )
    {
      if( cell == null )
        return;

      DataGridContext dataGridContext = DataGridControl.GetDataGridContext( cell );
      ColumnBase column = cell.ParentColumn;

      if( ( dataGridContext == null ) ||
          ( parentDataGridControl == null ) ||
          ( column == null ) ||
          ( parentDataGridControl != dataGridContext.DataGridControl ) )
        return;

      var addGroupCommand = dataGridContext.AddGroupCommand;

      if( draggedOverDescription != null )
      {
        var position = GroupingHelper.GetGroupDescriptionIndexFromFieldName( dataGridContext, draggedOverDescription.FieldName, alignment );

        if( addGroupCommand.CanExecute( column, position ) )
        {
          addGroupCommand.Execute( column, position );
        }
      }
      else
      {
        if( addGroupCommand.CanExecute( column ) )
        {
          addGroupCommand.Execute( column );
        }
      }
    }
    public static int GetGroupDescriptionIndexFromFieldName( DataGridContext dataGridContext, string fieldName, DropMarkAlignment alignment )
    {
      ObservableCollection<GroupDescription> groupDescriptions = dataGridContext.Items.GroupDescriptions;

      for( int i = groupDescriptions.Count - 1; i >= 0; i-- )
      {
        if( DataGridContext.GetColumnNameFromGroupDescription( groupDescriptions[ i ] ) == fieldName )
        {
          if( alignment == DropMarkAlignment.Far )
            i++;

          return i;
        }
      }

      return dataGridContext.Items.GroupDescriptions.Count;
    }
    private void ShowDropMark( Point mousePosition, DropMarkAlignment defaultAlignment, bool forceDefaultAlignment )
    {
      if( m_dropMarkAdorner == null )
      {
        DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this );

        DataGridControl grid = ( dataGridContext != null )
          ? dataGridContext.DataGridControl
          : null;

        Pen pen = UIViewBase.GetDropMarkPen( this );

        if( ( pen == null ) && ( grid != null ) )
        {
          UIViewBase uiViewBase = grid.GetView() as UIViewBase;
          pen = uiViewBase.DefaultDropMarkPen;
        }

        DropMarkOrientation orientation = Xceed.Wpf.DataGrid.Views.UIViewBase.GetDropMarkOrientation( this );

        if( ( orientation == DropMarkOrientation.Default ) && ( grid != null ) )
        {
          UIViewBase uiViewBase = grid.GetView() as UIViewBase;

          orientation = uiViewBase.DefaultDropMarkOrientation;
        }

        m_dropMarkAdorner = new DropMarkAdorner( this, pen, orientation );

        AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer( this );

        if( adornerLayer != null )
          adornerLayer.Add( m_dropMarkAdorner );
      }

      if( forceDefaultAlignment )
      {
        m_dropMarkAdorner.ForceAlignment( defaultAlignment );
      }
      else
      {
        m_dropMarkAdorner.UpdateAlignment( mousePosition );
      }
    }
Example #16
0
        public static int GetGroupDescriptionIndex(ObservableCollection <GroupDescription> groupDescriptions, GroupLevelDescription groupLevelDescription, DropMarkAlignment alignment)
        {
            int groupIndex = groupDescriptions.IndexOf(groupLevelDescription.GroupDescription);

            if (groupIndex > -1)
            {
                if (alignment == DropMarkAlignment.Far)
                {
                    groupIndex++;
                }

                return(groupIndex);
            }
            else
            {
                // return the size of the Collection if not found
                return(groupDescriptions.Count);
            }
        }
Example #17
0
        public static int GetGroupDescriptionIndexFromFieldName(DataGridContext dataGridContext, string fieldName, DropMarkAlignment alignment)
        {
            ObservableCollection <GroupDescription> groupDescriptions = dataGridContext.Items.GroupDescriptions;

            for (int i = groupDescriptions.Count - 1; i >= 0; i--)
            {
                if (DataGridContext.GetColumnNameFromGroupDescription(groupDescriptions[i]) == fieldName)
                {
                    if (alignment == DropMarkAlignment.Far)
                    {
                        i++;
                    }

                    return(i);
                }
            }

            return(dataGridContext.Items.GroupDescriptions.Count);
        }
Example #18
0
 public void ForceAlignment( DropMarkAlignment alignment )
 {
   m_alignment = alignment;
 }
Example #19
0
        public static void MoveGroupDescription(ColumnCollection targetColumns, ObservableCollection <GroupDescription> targetGroupDescriptions, GroupLevelDescription targetGroupLevelDescription, DropMarkAlignment targetAlignment, GroupLevelDescription movedGroupLevelDescription, DataGridControl parentDataGridControl)
        {
            Debug.Assert(targetColumns != null);
            Debug.Assert(targetGroupDescriptions != null);
            Debug.Assert(targetGroupLevelDescription != null);
            Debug.Assert(movedGroupLevelDescription != null);

            if ((parentDataGridControl == null) ||
                (targetColumns == null) ||
                (targetGroupDescriptions == null) ||
                (targetGroupLevelDescription == null) ||
                (movedGroupLevelDescription == null))
            {
                return;
            }

            int oldPos = GroupingHelper.GetGroupDescriptionIndex(targetGroupDescriptions, movedGroupLevelDescription, DropMarkAlignment.Near);
            int newPos = GroupingHelper.GetGroupDescriptionIndex(targetGroupDescriptions, targetGroupLevelDescription, targetAlignment);

            if (newPos > oldPos)
            {
                newPos--;
            }

            if (newPos != oldPos)
            {
                Debug.Assert(oldPos < targetGroupDescriptions.Count);

                using (parentDataGridControl.SetQueueBringIntoViewRestrictions(AutoScrollCurrentItemSourceTriggers.CollectionViewCurrentItemChanged))
                {
                    targetGroupDescriptions.Move(oldPos, newPos);
                }
            }
        }
Example #20
0
    public static void AddNewGroupFromColumnManagerCell( ColumnManagerCell cell, GroupLevelDescription draggedOverDescription, DropMarkAlignment alignment, DataGridControl parentDataGridControl )
    {
      if( cell == null )
        return;

      DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext( cell );
      DataGridControl cellParentGrid = cellDataGridContext.DataGridControl;

      if( ( cellDataGridContext == null ) ||
          ( parentDataGridControl == null ) ||
          ( parentDataGridControl != cellParentGrid ) )
        return;

      // By default, add it at the end
      int newPos = cellDataGridContext.GroupLevelDescriptions.Count;

      if( draggedOverDescription != null )
        newPos = GroupingHelper.GetGroupDescriptionIndexFromFieldName( cellDataGridContext, draggedOverDescription.FieldName, alignment );

      ColumnBase column = cell.ParentColumn;

      if( column != null )
      {
        GroupingHelper.AddNewGroupFromColumn( column, cellDataGridContext.Items.GroupDescriptions, newPos );
      }
    }