internal void ProcessDrop(ColumnManagerCell draggedCell, RelativePoint mousePosition)
        {
            var manager = default(ColumnReorderingDragSourceManager);

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

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                manager.CommitReordering();
            }
            else
            {
                this.HideDropMark();

                var dataGridContext = this.DataGridContext;
                Debug.Assert(dataGridContext != null);

                if (dataGridContext != null)
                {
                    var targetColumn = draggedCell.ParentColumn;
                    var pivotColumn  = this.ParentColumn;

                    Debug.Assert(targetColumn != null);
                    Debug.Assert(pivotColumn != null);

                    var relativePosition = mousePosition.GetPoint(this);
                    var offset           = Point.Subtract(mousePosition.GetPoint(draggedCell), relativePosition);
                    var moveBefore       = true;

                    // We assumme the cells are layouted horizontally.
                    if (Math.Abs(offset.X) >= Math.Abs(offset.Y))
                    {
                        // Consider the case where the columns are layouted from left to right in reverse order.
                        var reverse = ((offset.X > 0d) == (targetColumn.VisiblePosition >= pivotColumn.VisiblePosition));

                        moveBefore = ((relativePosition.X < this.ActualWidth / 2d) != reverse);
                    }
                    // We assume the cells are layouted vertically.
                    else
                    {
                        // Consider the case where the columns are layouted from top to bottom in reverse order.
                        var reverse = ((offset.Y > 0d) == (targetColumn.VisiblePosition >= pivotColumn.VisiblePosition));

                        moveBefore = ((relativePosition.Y < this.ActualHeight / 2d) != reverse);
                    }

                    var success = (moveBefore)
                          ? dataGridContext.MoveColumnBefore(targetColumn, pivotColumn)
                          : dataGridContext.MoveColumnAfter(targetColumn, pivotColumn);

                    Debug.Assert(success);
                }
            }
        }
Example #2
0
        bool IDropTarget.CanDropElement(UIElement draggedElement, RelativePoint mousePosition)
        {
            var draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell == null)
            {
                return(false);
            }

            var manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

            if ((manager != null) && manager.IsAnimatedColumnReorderingEnabled && draggedCell.IsBeingDragged)
            {
                var dataGridContext = DataGridControl.GetDataGridContext(this);
                if ((dataGridContext == null) || !dataGridContext.Columns.Contains(draggedCell.ParentColumn))
                {
                    return(false);
                }

                // We are not interested by the y-axis.
                var relativePoint = mousePosition.GetPoint(this);
                var xPosition     = new RelativePoint(this, new Point(relativePoint.X, this.ActualHeight / 2d));

                var targetCell = (from dropTarget in manager.GetDropTargetsAtPoint(xPosition)
                                  let dropCell = dropTarget as ColumnManagerCell
                                                 where (dropCell != null)
                                                 select dropCell).FirstOrDefault();
                if ((targetCell == null) || (targetCell == draggedCell) || (( IDropTarget )targetCell).CanDropElement(draggedElement, xPosition))
                {
                    return(true);
                }
            }

            return(false);
        }
        internal void UpdateAlignment(RelativePoint mousePosition)
        {
            var relativePosition = mousePosition.GetPoint(this.AdornedElement);
            var elementSize      = this.AdornedElement.RenderSize;

            if (m_orientation == DropMarkOrientation.Horizontal)
            {
                this.Alignment = (relativePosition.Y < elementSize.Height / 2d) ? DropMarkAlignment.Near : DropMarkAlignment.Far;
            }
            else
            {
                this.Alignment = (relativePosition.X < elementSize.Width / 2d) ? DropMarkAlignment.Near : DropMarkAlignment.Far;
            }
        }
        bool IDropTarget.CanDropElement(UIElement draggedElement, RelativePoint mousePosition)
        {
            var draggedCell = draggedElement as ColumnManagerCell;

            if ((draggedCell == null) || (this == draggedCell))
            {
                return(false);
            }

            var parentRow = this.ParentRow as ColumnManagerRow;

            if ((parentRow == null) || !parentRow.AllowColumnReorder)
            {
                return(false);
            }

            var draggedDetailContext = draggedCell.DataGridContext;
            var sourceDetailContext  = this.DataGridContext;

            Debug.Assert((draggedDetailContext != null) && (sourceDetailContext != null));

            if ((sourceDetailContext.SourceDetailConfiguration != draggedDetailContext.SourceDetailConfiguration) ||
                (sourceDetailContext.GroupLevelDescriptions != draggedDetailContext.GroupLevelDescriptions))
            {
                return(false);
            }

            if (!ColumnManagerCell.CanMove(draggedCell))
            {
                return(false);
            }

            var manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                if (!manager.CanReorder(draggedCell, this, mousePosition))
                {
                    return(false);
                }
            }
            else
            {
                var relativePosition = mousePosition.GetPoint(this);
                var moveBefore       = (relativePosition.X <= this.ActualWidth / 2d);

                if (moveBefore)
                {
                    if (!draggedCell.CanMoveBefore(this.ParentColumn))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!draggedCell.CanMoveAfter(this.ParentColumn))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }