示例#1
0
        private void OnSplit(object sender, SplitEventArgs args)
        {
            MergeCancelClick(null, null);

            var zonePanel = sender as GridZone;
            int zoneIndex = Preview.Children.IndexOf(zonePanel);

            if (_data.CanSplit(zoneIndex, args.Offset, args.Orientation))
            {
                _data.Split(zoneIndex, args.Offset, args.Orientation);
                SetupUI();
            }
        }
示例#2
0
        private void OnFullSplit(object o, SplitEventArgs e)
        {
            UIElementCollection previewChildren = Preview.Children;
            UIElement           splitee         = (UIElement)o;

            GridLayoutModel model        = Model;
            int             spliteeIndex = previewChildren.IndexOf(splitee);

            int rows = model.Rows;
            int cols = model.Columns;

            _startRow = -1;
            _startCol = -1;

            for (int row = rows - 1; row >= 0; row--)
            {
                for (int col = cols - 1; col >= 0; col--)
                {
                    if (model.CellChildMap[row, col] == spliteeIndex)
                    {
                        _dragHandles.RemoveDragHandles();
                        _startRow = _endRow = row;
                        _startCol = _endCol = col;
                        ExtendRangeToHaveEvenCellEdges();

                        for (row = _startRow; row <= _endRow; row++)
                        {
                            for (col = _startCol; col <= _endCol; col++)
                            {
                                if ((row != _startRow) || (col != _startCol))
                                {
                                    model.CellChildMap[row, col] = AddZone();
                                }
                            }
                        }

                        OnGridDimensionsChanged();
                        return;
                    }
                }
            }
        }
示例#3
0
        private void OnSplit(object o, SplitEventArgs e)
        {
            MergeCancelClick(null, null);

            UIElementCollection previewChildren = Preview.Children;
            GridZone            splitee         = (GridZone)o;

            int             spliteeIndex = previewChildren.IndexOf(splitee);
            GridLayoutModel model        = Model;

            int rows = model.Rows;
            int cols = model.Columns;

            Tuple <int, int> rowCol = _data.RowColByIndex(spliteeIndex);
            int foundRow            = rowCol.Item1;
            int foundCol            = rowCol.Item2;

            int newChildIndex = AddZone();

            double offset = e.Offset;
            double space  = e.Space;

            if (e.Orientation == Orientation.Vertical)
            {
                if (splitee.VerticalSnapPoints != null)
                {
                    offset += Canvas.GetLeft(splitee);
                    int  count = splitee.VerticalSnapPoints.Length;
                    bool foundExistingSplit = false;
                    int  splitCol           = foundCol;

                    for (int i = 0; i <= count; i++)
                    {
                        if (foundExistingSplit)
                        {
                            int walkRow = foundRow;
                            while ((walkRow < rows) && (_data.GetIndex(walkRow, foundCol + i) == spliteeIndex))
                            {
                                _data.SetIndex(walkRow++, foundCol + i, newChildIndex);
                            }
                        }

                        if (_data.ColumnBottom(foundCol + i) == offset)
                        {
                            foundExistingSplit = true;
                            splitCol           = foundCol + i;

                            // use existing division
                        }
                    }

                    if (foundExistingSplit)
                    {
                        _data.ReplaceIndicesToMaintainOrder(Preview.Children.Count);
                        _dragHandles.UpdateForExistingVerticalSplit(model, foundRow, splitCol);
                        OnGridDimensionsChanged();
                        return;
                    }

                    while (_data.ColumnBottom(foundCol) < offset)
                    {
                        foundCol++;
                    }

                    offset -= _data.ColumnTop(foundCol);
                }

                _dragHandles.UpdateAfterVerticalSplit(foundCol);
                _data.SplitColumn(foundCol, spliteeIndex, newChildIndex, space, offset, ActualWidth);
                _dragHandles.AddDragHandle(Orientation.Vertical, foundRow, foundCol, model);
            }
            else
            {
                // Horizontal
                if (splitee.HorizontalSnapPoints != null)
                {
                    offset += Canvas.GetTop(splitee);
                    int  count = splitee.HorizontalSnapPoints.Length;
                    bool foundExistingSplit = false;
                    int  splitRow           = foundRow;

                    for (int i = 0; i <= count; i++)
                    {
                        if (foundExistingSplit)
                        {
                            int walkCol = foundCol;
                            while ((walkCol < cols) && (_data.GetIndex(foundRow + i, walkCol) == spliteeIndex))
                            {
                                _data.SetIndex(foundRow + i, walkCol++, newChildIndex);
                            }
                        }

                        if (_data.RowEnd(foundRow + i) == offset)
                        {
                            foundExistingSplit = true;
                            splitRow           = foundRow + i;

                            // use existing division
                        }
                    }

                    if (foundExistingSplit)
                    {
                        _data.ReplaceIndicesToMaintainOrder(Preview.Children.Count);
                        _dragHandles.UpdateForExistingHorizontalSplit(model, splitRow, foundCol);
                        OnGridDimensionsChanged();
                        return;
                    }

                    while (_data.RowEnd(foundRow) < offset)
                    {
                        foundRow++;
                    }

                    offset -= _data.RowStart(foundRow);
                }

                _dragHandles.UpdateAfterHorizontalSplit(foundRow);
                _data.SplitRow(foundRow, spliteeIndex, newChildIndex, space, offset, ActualHeight);
                _dragHandles.AddDragHandle(Orientation.Horizontal, foundRow, foundCol, model);
            }

            Size actualSize = new Size(ActualWidth, ActualHeight);

            ArrangeGridRects(actualSize);
        }
示例#4
0
        private void OnSplit(object o, SplitEventArgs e)
        {
            UIElementCollection previewChildren = Preview.Children;
            GridZone            splitee         = (GridZone)o;

            int             spliteeIndex = previewChildren.IndexOf(splitee);
            GridLayoutModel model        = Model;

            int rows     = model.Rows;
            int cols     = model.Columns;
            int foundRow = -1;
            int foundCol = -1;

            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < cols; col++)
                {
                    if (model.CellChildMap[row, col] == spliteeIndex)
                    {
                        foundRow = row;
                        foundCol = col;
                        break;
                    }
                }

                if (foundRow != -1)
                {
                    break;
                }
            }

            int newChildIndex = AddZone();

            double offset = e.Offset;

            if (e.Orientation == Orientation.Vertical)
            {
                if (splitee.VerticalSnapPoints != null)
                {
                    offset += Canvas.GetLeft(splitee);
                    int  count = splitee.VerticalSnapPoints.Length;
                    bool foundExistingSplit = false;

                    for (int i = 0; i <= count; i++)
                    {
                        if (foundExistingSplit)
                        {
                            int walkRow = foundRow;
                            while ((walkRow < rows) && (model.CellChildMap[walkRow, foundCol + i] == spliteeIndex))
                            {
                                model.CellChildMap[walkRow++, foundCol + i] = newChildIndex;
                            }
                        }

                        if (_colInfo[foundCol + i].End == offset)
                        {
                            foundExistingSplit = true;

                            // use existing division
                        }
                    }

                    if (foundExistingSplit)
                    {
                        OnGridDimensionsChanged();
                        return;
                    }

                    while (_colInfo[foundCol].End < offset)
                    {
                        foundCol++;
                    }

                    offset -= _colInfo[foundCol].Start;
                }

                AddDragHandle(Orientation.Vertical, cols - 1);
                cols++;
                int[,] newCellChildMap = new int[rows, cols];
                int[]        newColPercents = new int[cols];
                RowColInfo[] newColInfo     = new RowColInfo[cols];

                int sourceCol = 0;
                for (int col = 0; col < cols; col++)
                {
                    for (int row = 0; row < rows; row++)
                    {
                        if ((col > foundCol) && (model.CellChildMap[row, sourceCol] == spliteeIndex))
                        {
                            newCellChildMap[row, col] = newChildIndex;
                        }
                        else
                        {
                            newCellChildMap[row, col] = model.CellChildMap[row, sourceCol];
                        }
                    }

                    if (col != foundCol)
                    {
                        sourceCol++;
                    }
                }

                model.CellChildMap = newCellChildMap;

                sourceCol = 0;
                for (int col = 0; col < cols; col++)
                {
                    if (col == foundCol)
                    {
                        RowColInfo[] split = _colInfo[col].Split(offset);
                        newColPercents[col] = split[0].Percent;
                        newColInfo[col++]   = split[0];
                        newColPercents[col] = split[1].Percent;
                        newColInfo[col]     = split[1];
                        sourceCol++;
                    }
                    else
                    {
                        newColPercents[col] = model.ColumnPercents[sourceCol];
                        newColInfo[col]     = _colInfo[sourceCol++];
                    }
                }

                _colInfo             = newColInfo;
                model.ColumnPercents = newColPercents;

                model.Columns++;
            }
            else
            {
                // Horizontal
                if (splitee.HorizontalSnapPoints != null)
                {
                    offset += Canvas.GetTop(splitee);
                    int  count = splitee.HorizontalSnapPoints.Length;
                    bool foundExistingSplit = false;

                    for (int i = 0; i <= count; i++)
                    {
                        if (foundExistingSplit)
                        {
                            int walkCol = foundCol;
                            while ((walkCol < cols) && (model.CellChildMap[foundRow + i, walkCol] == spliteeIndex))
                            {
                                model.CellChildMap[foundRow + i, walkCol] = newChildIndex;
                            }
                        }

                        if (_rowInfo[foundRow + i].End == offset)
                        {
                            foundExistingSplit = true;

                            // use existing division
                        }
                    }

                    if (foundExistingSplit)
                    {
                        OnGridDimensionsChanged();
                        return;
                    }

                    while (_rowInfo[foundRow].End < offset)
                    {
                        foundRow++;
                    }

                    offset -= _rowInfo[foundRow].Start;
                }

                AddDragHandle(Orientation.Horizontal, rows - 1);
                rows++;
                int[,] newCellChildMap = new int[rows, cols];
                int[]        newRowPercents = new int[rows];
                RowColInfo[] newRowInfo     = new RowColInfo[rows];

                int sourceRow = 0;
                for (int row = 0; row < rows; row++)
                {
                    for (int col = 0; col < cols; col++)
                    {
                        if ((row > foundRow) && (model.CellChildMap[sourceRow, col] == spliteeIndex))
                        {
                            newCellChildMap[row, col] = newChildIndex;
                        }
                        else
                        {
                            newCellChildMap[row, col] = model.CellChildMap[sourceRow, col];
                        }
                    }

                    if (row != foundRow)
                    {
                        sourceRow++;
                    }
                }

                model.CellChildMap = newCellChildMap;

                sourceRow = 0;
                for (int row = 0; row < rows; row++)
                {
                    if (row == foundRow)
                    {
                        RowColInfo[] split = _rowInfo[row].Split(offset);
                        newRowPercents[row] = split[0].Percent;
                        newRowInfo[row++]   = split[0];
                        newRowPercents[row] = split[1].Percent;
                        newRowInfo[row]     = split[1];
                        sourceRow++;
                    }
                    else
                    {
                        newRowPercents[row] = model.RowPercents[sourceRow];
                        newRowInfo[row]     = _rowInfo[sourceRow++];
                    }
                }

                _rowInfo          = newRowInfo;
                model.RowPercents = newRowPercents;

                model.Rows++;
            }
        }