Beispiel #1
0
        protected override bool OnDragEnd(Point dragStartPosition, Point dragEndPosition)
        {
            LayoutLineHeaderAdorner lineHeaderAdorner  = this.ActiveAdorner as LayoutLineHeaderAdorner;
            NewGridlineAdorner      newGridlineAdorner = this.ActiveAdorner as NewGridlineAdorner;

            if (lineHeaderAdorner != null)
            {
                ((GridRowColumnAdornerSet)lineHeaderAdorner.AdornerSet).DraggingGridline = false;
            }
            else if (newGridlineAdorner != null && this.IsNewGridlineEnabled)
            {
                GridElement        grid = (GridElement)((Adorner)this.ActiveAdorner).Element;
                GridLayoutDesigner gridLayoutDesigner = (GridLayoutDesigner)grid.LayoutDesigner;
                dragEndPosition = this.ToolBehaviorContext.SnappingEngine.SnapPoint(dragEndPosition);
                Matrix transformFromRoot = this.ActiveView.GetComputedTransformFromRoot((SceneElement)grid);
                dragEndPosition *= transformFromRoot;
                if (newGridlineAdorner.IsX)
                {
                    gridLayoutDesigner.AddVerticalGridline(grid, dragEndPosition.X);
                }
                else
                {
                    gridLayoutDesigner.AddHorizontalGridline(grid, dragEndPosition.Y);
                }
            }
            this.ToolBehaviorContext.SnappingEngine.Stop();
            this.CommitEditTransaction();
            return(base.OnDragEnd(dragStartPosition, dragEndPosition));
        }
Beispiel #2
0
        protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow)
        {
            SceneView activeView = this.ActiveView;
            LayoutLineHeaderAdorner lineHeaderAdorner = this.ActiveAdorner as LayoutLineHeaderAdorner;
            GridElement             grid = (GridElement)((Adorner)this.ActiveAdorner).Element;
            GridLayoutDesigner      gridLayoutDesigner = (GridLayoutDesigner)grid.LayoutDesigner;

            activeView.EnsureVisible(this.ActiveAdorner, scrollNow);
            Matrix transformFromRoot = activeView.GetComputedTransformFromRoot((SceneElement)grid);

            dragStartPosition   *= transformFromRoot;
            dragCurrentPosition  = this.ToolBehaviorContext.SnappingEngine.SnapPoint(dragCurrentPosition);
            dragCurrentPosition *= transformFromRoot;
            if (lineHeaderAdorner == null || lineHeaderAdorner.Index <= 0)
            {
                return(false);
            }
            this.EnsureEditTransaction();
            if (lineHeaderAdorner.IsX)
            {
                if (this.firstLineHeaderDrag)
                {
                    this.effectiveLineHeaderIndex = lineHeaderAdorner.Index;
                    if (dragCurrentPosition.X < dragStartPosition.X)
                    {
                        while (this.effectiveLineHeaderIndex > 1 && grid.GetComputedColumnWidth(this.effectiveLineHeaderIndex - 1) < 1.0 / activeView.Zoom)
                        {
                            --this.effectiveLineHeaderIndex;
                        }
                        this.firstLineHeaderDrag = false;
                    }
                    else if (dragCurrentPosition.X > dragStartPosition.X)
                    {
                        while (this.effectiveLineHeaderIndex < grid.ColumnDefinitions.Count - 2 && grid.GetComputedColumnWidth(this.effectiveLineHeaderIndex) < 1.0 / activeView.Zoom)
                        {
                            ++this.effectiveLineHeaderIndex;
                        }
                        this.firstLineHeaderDrag = false;
                    }
                }
                if (!this.firstLineHeaderDrag)
                {
                    int    num   = this.effectiveLineHeaderIndex - 1;
                    double width = dragCurrentPosition.X - grid.GetComputedPositionOfColumn(num);
                    gridLayoutDesigner.AdjustColumn(grid, num, width, this.IsShiftDown, !grid.ViewModel.IsInGridDesignMode);
                }
            }
            else
            {
                if (this.firstLineHeaderDrag)
                {
                    this.effectiveLineHeaderIndex = lineHeaderAdorner.Index;
                    if (dragCurrentPosition.Y < dragStartPosition.Y)
                    {
                        while (this.effectiveLineHeaderIndex > 1 && grid.GetComputedRowHeight(this.effectiveLineHeaderIndex - 1) < 1.0 / activeView.Zoom)
                        {
                            --this.effectiveLineHeaderIndex;
                        }
                        this.firstLineHeaderDrag = false;
                    }
                    else if (dragCurrentPosition.Y > dragStartPosition.Y)
                    {
                        while (this.effectiveLineHeaderIndex < grid.RowDefinitions.Count - 2 && grid.GetComputedRowHeight(this.effectiveLineHeaderIndex) < 1.0 / activeView.Zoom)
                        {
                            ++this.effectiveLineHeaderIndex;
                        }
                        this.firstLineHeaderDrag = false;
                    }
                }
                if (!this.firstLineHeaderDrag)
                {
                    int    row    = this.effectiveLineHeaderIndex - 1;
                    double height = dragCurrentPosition.Y - grid.GetComputedPositionOfRow(row);
                    gridLayoutDesigner.AdjustRow(grid, row, height, this.IsShiftDown, !grid.ViewModel.IsInGridDesignMode);
                }
            }
            ((Adorner)this.ActiveAdorner).AdornerSet.InvalidateRender();
            this.UpdateEditTransaction();
            return(true);
        }
Beispiel #3
0
        protected override bool OnClickEnd(Point pointerPosition, int clickCount)
        {
            GridLockAdorner                    gridLockAdorner         = this.ActiveAdorner as GridLockAdorner;
            LayoutBackgroundAdorner            backgroundAdorner       = this.ActiveAdorner as LayoutBackgroundAdorner;
            LayoutLineHeaderAdorner            lineHeaderAdorner       = this.ActiveAdorner as LayoutLineHeaderAdorner;
            GridDesignModeAdorner              designModeAdorner       = this.ActiveAdorner as GridDesignModeAdorner;
            NewGridlineAdorner                 newGridlineAdorner      = this.ActiveAdorner as NewGridlineAdorner;
            LayoutEmptyBackgroundHeaderAdorner backgroundHeaderAdorner = this.ActiveAdorner as LayoutEmptyBackgroundHeaderAdorner;
            GridElement        grid = (GridElement)((Adorner)this.ActiveAdorner).Element;
            GridLayoutDesigner gridLayoutDesigner = (GridLayoutDesigner)grid.LayoutDesigner;

            pointerPosition = this.ToolBehaviorContext.SnappingEngine.SnapPoint(pointerPosition);
            Matrix transformFromRoot = this.ActiveView.GetComputedTransformFromRoot((SceneElement)grid);

            pointerPosition *= transformFromRoot;
            if (backgroundHeaderAdorner == null)
            {
                if (lineHeaderAdorner != null)
                {
                    ((GridRowColumnAdornerSet)lineHeaderAdorner.AdornerSet).DraggingGridline = false;
                    if (clickCount > 1)
                    {
                        if (lineHeaderAdorner.IsX)
                        {
                            gridLayoutDesigner.RemoveColumn(grid, lineHeaderAdorner.Index);
                        }
                        else
                        {
                            gridLayoutDesigner.RemoveRow(grid, lineHeaderAdorner.Index);
                        }
                    }
                }
                else if (gridLockAdorner != null)
                {
                    using (SceneEditTransaction editTransaction = this.ActiveDocument.CreateEditTransaction(StringTable.UndoUnitToggleGridProperty))
                    {
                        if (gridLockAdorner.IsX)
                        {
                            ColumnDefinitionNode columnDefinitionNode = grid.ColumnDefinitions[gridLockAdorner.Index];
                            GridLength           width = columnDefinitionNode.Width;
                            if (width.IsAuto)
                            {
                                columnDefinitionNode.ClearValue(ColumnDefinitionNode.MinWidthProperty);
                                gridLayoutDesigner.SetColumnWidthToStar(grid, gridLockAdorner.Index);
                            }
                            else if (width.IsAbsolute)
                            {
                                gridLayoutDesigner.SetColumnWidth(grid, gridLockAdorner.Index, GridLength.Auto, columnDefinitionNode.ComputedWidth);
                            }
                            else
                            {
                                gridLayoutDesigner.SetColumnWidth(grid, gridLockAdorner.Index, new GridLength(columnDefinitionNode.ComputedWidth), double.NaN);
                            }
                        }
                        else
                        {
                            RowDefinitionNode rowDefinitionNode = grid.RowDefinitions[gridLockAdorner.Index];
                            GridLength        height            = rowDefinitionNode.Height;
                            if (height.IsAuto)
                            {
                                rowDefinitionNode.ClearValue(RowDefinitionNode.MinHeightProperty);
                                gridLayoutDesigner.SetRowHeightToStar(grid, gridLockAdorner.Index);
                            }
                            else if (height.IsAbsolute)
                            {
                                gridLayoutDesigner.SetRowHeight(grid, gridLockAdorner.Index, GridLength.Auto, rowDefinitionNode.ComputedHeight);
                            }
                            else
                            {
                                gridLayoutDesigner.SetRowHeight(grid, gridLockAdorner.Index, new GridLength(rowDefinitionNode.ComputedHeight), double.NaN);
                            }
                        }
                        editTransaction.Commit();
                    }
                }
                else if (backgroundAdorner != null)
                {
                    if (backgroundAdorner.IsX)
                    {
                        GridColumnSelectionSet columnSelectionSet   = this.ActiveSceneViewModel.GridColumnSelectionSet;
                        ColumnDefinitionNode   columnDefinitionNode = grid.ColumnDefinitions[backgroundAdorner.Index];
                        columnSelectionSet.GridLineMode = false;
                        if (this.IsShiftDown)
                        {
                            columnSelectionSet.ToggleSelection(columnDefinitionNode);
                        }
                        else
                        {
                            columnSelectionSet.SetSelection(columnDefinitionNode);
                        }
                    }
                    else
                    {
                        GridRowSelectionSet gridRowSelectionSet = this.ActiveSceneViewModel.GridRowSelectionSet;
                        RowDefinitionNode   rowDefinitionNode   = grid.RowDefinitions[backgroundAdorner.Index];
                        gridRowSelectionSet.GridLineMode = false;
                        if (this.IsShiftDown)
                        {
                            gridRowSelectionSet.ToggleSelection(rowDefinitionNode);
                        }
                        else
                        {
                            gridRowSelectionSet.SetSelection(rowDefinitionNode);
                        }
                    }
                }
                else if (newGridlineAdorner != null && this.IsNewGridlineEnabled)
                {
                    if (newGridlineAdorner.IsX)
                    {
                        gridLayoutDesigner.AddVerticalGridline(grid, pointerPosition.X);
                    }
                    else
                    {
                        gridLayoutDesigner.AddHorizontalGridline(grid, pointerPosition.Y);
                    }
                }
                else if (designModeAdorner != null)
                {
                    grid.ViewModel.IsInGridDesignMode = !designModeAdorner.Grid.ViewModel.IsInGridDesignMode;
                }
            }
            this.ToolBehaviorContext.SnappingEngine.Stop();
            this.ActiveView.UpdateLayout();
            this.ActiveSceneViewModel.RefreshSelection();
            return(base.OnClickEnd(pointerPosition, clickCount));
        }