private void JoinControls(bool forceLayout)
        {
            ToolStripPanelControlCollection controls = base.Controls as ToolStripPanelControlCollection;

            if (controls.Count > 0)
            {
                controls.Sort();
                Control[] array = new Control[controls.Count];
                controls.CopyTo(array, 0);
                for (int i = 0; i < array.Length; i++)
                {
                    int count = this.RowsInternal.Count;
                    ISupportToolStripPanel panel = array[i] as ISupportToolStripPanel;
                    if (((panel == null) || (panel.ToolStripPanelRow == null)) || (panel.IsCurrentlyDragging || !panel.ToolStripPanelRow.Bounds.Contains(array[i].Location)))
                    {
                        if (array[i].AutoSize)
                        {
                            array[i].Size = array[i].PreferredSize;
                        }
                        Point location = array[i].Location;
                        if (this.state[stateRightToLeftChanged])
                        {
                            location = new Point(base.Width - array[i].Right, location.Y);
                        }
                        this.Join(array[i] as ToolStrip, array[i].Location);
                        if ((count < this.RowsInternal.Count) || forceLayout)
                        {
                            this.OnLayout(new LayoutEventArgs(this, PropertyNames.Rows));
                        }
                    }
                }
            }
            this.state[stateRightToLeftChanged] = false;
        }
Beispiel #2
0
        public override Size GetPreferredSize(Size constrainingSize)
        {
            ISupportToolStripPanel draggedControl = DraggedControl;
            Size preferredSize = Size.Empty;

            if (draggedControl.Stretch)
            {
                if (ToolStripPanelRow.Orientation == Orientation.Horizontal)
                {
                    constrainingSize.Width = ToolStripPanelRow.Bounds.Width;
                    preferredSize          = _wrappedToolStrip.GetPreferredSize(constrainingSize);
                    preferredSize.Width    = constrainingSize.Width;
                }
                else
                {
                    constrainingSize.Height = ToolStripPanelRow.Bounds.Height;
                    preferredSize           = _wrappedToolStrip.GetPreferredSize(constrainingSize);
                    preferredSize.Height    = constrainingSize.Height;
                }
            }
            else
            {
                preferredSize = (!_wrappedToolStrip.AutoSize) ? _wrappedToolStrip.Size : _wrappedToolStrip.GetPreferredSize(constrainingSize);
            }

            // return LayoutUtils.IntersectSizes(constrainingSize, preferredSize);
            return(preferredSize);
        }
            private void OnAdd(ISupportToolStripPanel controlToBeDragged, int index)
            {
                if (_owner != null)
                {
                    LayoutTransaction layoutTransaction = null;
                    if (ToolStripPanel != null && ToolStripPanel.ParentInternal != null)
                    {
                        layoutTransaction = new LayoutTransaction(ToolStripPanel, ToolStripPanel.ParentInternal, PropertyNames.Parent);
                    }

                    try
                    {
                        if (controlToBeDragged != null)
                        {
                            controlToBeDragged.ToolStripPanelRow = _owner;

                            if (controlToBeDragged is Control control)
                            {
                                control.ParentInternal = _owner.ToolStripPanel;
                                _owner.OnControlAdded(control, index);
                            }
                        }
                    }
                    finally
                    {
                        if (layoutTransaction != null)
                        {
                            layoutTransaction.Dispose();
                        }
                    }
                }
            }
        protected override void OnControlRemoved(ControlEventArgs e)
        {
            ISupportToolStripPanel control = e.Control as ISupportToolStripPanel;

            if ((control != null) && (control.ToolStripPanelRow != null))
            {
                control.ToolStripPanelRow.ControlsInternal.Remove(e.Control);
            }
            base.OnControlRemoved(e);
        }
 protected override void OnLayout(LayoutEventArgs e)
 {
     if ((e.AffectedComponent != this.ParentInternal) && (e.AffectedComponent is Control))
     {
         ISupportToolStripPanel affectedComponent = e.AffectedComponent as ISupportToolStripPanel;
         if ((affectedComponent != null) && this.RowsInternal.Contains(affectedComponent.ToolStripPanelRow))
         {
             LayoutTransaction.DoLayout(affectedComponent.ToolStripPanelRow, e.AffectedComponent as IArrangedElement, e.AffectedProperty);
         }
     }
     base.OnLayout(e);
 }
 private void Debug_VerifyNoOverlaps()
 {
     foreach (Control control in base.Controls)
     {
         foreach (Control control2 in base.Controls)
         {
             if (control != control2)
             {
                 Rectangle bounds = control.Bounds;
                 bounds.Intersect(control2.Bounds);
                 if (!LayoutUtils.IsZeroWidthOrHeight(bounds))
                 {
                     ISupportToolStripPanel panel  = control as ISupportToolStripPanel;
                     ISupportToolStripPanel panel2 = control2 as ISupportToolStripPanel;
                     string str = string.Format(CultureInfo.CurrentCulture, "OVERLAP detection:\r\n{0}: {1} row {2} row bounds {3}", new object[] { (control.Name == null) ? "" : control.Name, control.Bounds, !this.RowsInternal.Contains(panel.ToolStripPanelRow) ? "unknown" : this.RowsInternal.IndexOf(panel.ToolStripPanelRow).ToString(CultureInfo.CurrentCulture), panel.ToolStripPanelRow.Bounds }) + string.Format(CultureInfo.CurrentCulture, "\r\n{0}: {1} row {2} row bounds {3}", new object[] { (control2.Name == null) ? "" : control2.Name, control2.Bounds, !this.RowsInternal.Contains(panel2.ToolStripPanelRow) ? "unknown" : this.RowsInternal.IndexOf(panel2.ToolStripPanelRow).ToString(CultureInfo.CurrentCulture), panel2.ToolStripPanelRow.Bounds });
                 }
             }
         }
     }
 }
Beispiel #7
0
        public override Size GetPreferredSize(Size constrainingSize)
        {
            ISupportToolStripPanel draggedControl = this.DraggedControl;
            Size empty = Size.Empty;

            if (draggedControl.Stretch)
            {
                if (this.ToolStripPanelRow.Orientation == Orientation.Horizontal)
                {
                    constrainingSize.Width = this.ToolStripPanelRow.Bounds.Width;
                    empty       = this._wrappedToolStrip.GetPreferredSize(constrainingSize);
                    empty.Width = constrainingSize.Width;
                    return(empty);
                }
                constrainingSize.Height = this.ToolStripPanelRow.Bounds.Height;
                empty        = this._wrappedToolStrip.GetPreferredSize(constrainingSize);
                empty.Height = constrainingSize.Height;
                return(empty);
            }
            return(!this._wrappedToolStrip.AutoSize ? this._wrappedToolStrip.Size : this._wrappedToolStrip.GetPreferredSize(constrainingSize));
        }
Beispiel #8
0
            public override void JoinRow(ToolStrip toolStripToDrag, Point locationToDrag)
            {
                Debug.WriteLineIf(ToolStripPanelMouseDebug.TraceVerbose, "Vertical JoinRow called ");
                int index;

                if (!Row.ControlsInternal.Contains(toolStripToDrag))
                {
                    Row.SuspendLayout();
                    try
                    {
                        if (Row.ControlsInternal.Count > 0)
                        {
                            // walk through the columns and determine which column you want to insert into.
                            for (index = 0; index < Row.Cells.Count; index++)
                            {
                                ToolStripPanelCell cell = Row.Cells[index] as ToolStripPanelCell;
                                if (!cell.Visible && !cell.ControlInDesignMode)
                                {
                                    continue;
                                }

                                //  [:   ]  [: x  ]
                                if (cell.Bounds.Contains(locationToDrag))
                                {
                                    break;
                                }

                                // take into account the following scenarios
                                //  [:   ]  x [:   ]
                                // x [:  ]    [:   ]
                                if (cell.Bounds.Y >= locationToDrag.Y)
                                {
                                    break;
                                }
                            }

                            Control controlToPushAside = Row.ControlsInternal[index];
                            // Plop the new control in the midst of the row in question.
                            if (index < Row.ControlsInternal.Count)
                            {
                                Row.ControlsInternal.Insert(index, toolStripToDrag);
                            }
                            else
                            {
                                Row.ControlsInternal.Add(toolStripToDrag);
                            }

                            // since layout is suspended the control may not be set to its preferred size yet
                            int controlToDragWidth = (toolStripToDrag.AutoSize) ? toolStripToDrag.PreferredSize.Height : toolStripToDrag.Height;

                            //
                            // now make it look like it belongs in the row.
                            //
                            // PUSH the controls after it to the right

                            int requiredSpace = controlToDragWidth;

                            if (index == 0)
                            {
                                // make sure we account for the left side
                                requiredSpace += locationToDrag.Y;
                            }

                            int freedSpace = 0;

                            if (index < Row.ControlsInternal.Count - 1)
                            {
                                ToolStripPanelCell nextCell = GetNextVisibleCell(index + 1, /*forward*/ true);
                                if (nextCell != null)
                                {
                                    Padding nextCellMargin = nextCell.Margin;

                                    // if we've already got the empty space
                                    // (available to us via the margin) use that.
                                    if (nextCellMargin.Top > requiredSpace)
                                    {
                                        nextCellMargin.Top -= requiredSpace;
                                        nextCell.Margin     = nextCellMargin;
                                        freedSpace          = requiredSpace;
                                    }
                                    else
                                    {
                                        // otherwise we've got to
                                        // push all controls after this point to the right
                                        // this dumps the extra stuff into the margin of index+1
                                        freedSpace = MoveDown(index + 1, requiredSpace - freedSpace);

                                        // refetch the margin for "index+1" and remove the freed space
                                        // from it - we want to actually put this to use on the control
                                        // before this one - we're making room for the control at
                                        // position "index"
                                        if (freedSpace > 0)
                                        {
                                            nextCellMargin      = nextCell.Margin;
                                            nextCellMargin.Top -= freedSpace;
                                            nextCell.Margin     = nextCellMargin;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // we're adding to the end.
                                ToolStripPanelCell nextCell = GetNextVisibleCell(Row.Cells.Count - 2, /*forward*/ false);
                                ToolStripPanelCell lastCell = GetNextVisibleCell(Row.Cells.Count - 1, /*forward*/ false);

                                // count the stuff at the end of the row as freed space
                                if (nextCell != null && lastCell != null)
                                {
                                    Padding lastCellMargin = lastCell.Margin;
                                    lastCellMargin.Top = Math.Max(0, locationToDrag.Y - nextCell.Bounds.Bottom);
                                    lastCell.Margin    = lastCellMargin;
                                    freedSpace         = requiredSpace;
                                }
                            }

                            // If we still need more space, then...
                            // PUSH the controls before it to the left
                            if (freedSpace < requiredSpace && index > 0)
                            {
                                freedSpace = MoveUp(index - 1, requiredSpace - freedSpace);
                            }

                            if (index == 0)
                            {
                                // if the index is zero and there were controls in the row
                                // we need to take care of pushing over the new cell.
                                if (freedSpace - controlToDragWidth > 0)
                                {
                                    ToolStripPanelCell newCell       = Row.Cells[index] as ToolStripPanelCell;
                                    Padding            newCellMargin = newCell.Margin;
                                    newCellMargin.Top = freedSpace - controlToDragWidth;
                                    newCell.Margin    = newCellMargin;
                                }
                            }
                        }
                        else
                        {
                            // we're adding to the beginning.
                            Row.ControlsInternal.Add(toolStripToDrag);

#if DEBUG
                            ISupportToolStripPanel ctg         = toolStripToDrag as ISupportToolStripPanel;
                            ToolStripPanelRow      newPanelRow = ctg.ToolStripPanelRow;
                            Debug.Assert(newPanelRow == Row, "we should now be in the new panel row.");
#endif
                            if (Row.Cells.Count > 0)
                            {
                                ToolStripPanelCell cell = GetNextVisibleCell(Row.Cells.Count - 1, /*forward*/ false);
                                if (cell != null)
                                {
                                    Padding cellMargin = cell.Margin;
                                    cellMargin.Top = Math.Max(0, locationToDrag.Y - Row.Margin.Top);
                                    cell.Margin    = cellMargin;
                                }
                            }
                        }
                    }
                    finally
                    {
                        Row.ResumeLayout(true);
                    }
                }
            }
        private void MoveInsideContainer(ToolStrip toolStripToDrag, Point clientLocation)
        {
            ISupportToolStripPanel panel = toolStripToDrag;

            if (!panel.IsCurrentlyDragging || this.DragBounds.Contains(clientLocation))
            {
                bool flag = false;
                ClearDragFeedback();
                if ((((toolStripToDrag.Site != null) && toolStripToDrag.Site.DesignMode) && base.IsHandleCreated) && ((clientLocation.X < 0) || (clientLocation.Y < 0)))
                {
                    Point pt = base.PointToClient(WindowsFormsUtils.LastCursorPoint);
                    if (base.ClientRectangle.Contains(pt))
                    {
                        clientLocation = pt;
                    }
                }
                ToolStripPanelRow toolStripPanelRow = panel.ToolStripPanelRow;
                bool flag2 = false;
                if (((toolStripPanelRow != null) && toolStripPanelRow.Visible) && (toolStripPanelRow.ToolStripPanel == this))
                {
                    if (toolStripToDrag.IsCurrentlyDragging)
                    {
                        flag2 = toolStripPanelRow.DragBounds.Contains(clientLocation);
                    }
                    else
                    {
                        flag2 = toolStripPanelRow.Bounds.Contains(clientLocation);
                    }
                }
                if (flag2)
                {
                    panel.ToolStripPanelRow.MoveControl(toolStripToDrag, this.GetStartLocation(toolStripToDrag), clientLocation);
                }
                else
                {
                    ToolStripPanelRow row2 = this.PointToRow(clientLocation);
                    if (row2 == null)
                    {
                        int count = this.RowsInternal.Count;
                        if (this.Orientation == System.Windows.Forms.Orientation.Horizontal)
                        {
                            count = (clientLocation.Y <= base.Padding.Left) ? 0 : count;
                        }
                        else
                        {
                            count = (clientLocation.X <= base.Padding.Left) ? 0 : count;
                        }
                        ToolStripPanelRow row3 = null;
                        if (this.RowsInternal.Count > 0)
                        {
                            if (count == 0)
                            {
                                row3 = this.RowsInternal[0];
                            }
                            else if (count > 0)
                            {
                                row3 = this.RowsInternal[count - 1];
                            }
                        }
                        if (((row3 != null) && (row3.ControlsInternal.Count == 1)) && row3.ControlsInternal.Contains(toolStripToDrag))
                        {
                            row2 = row3;
                            if (toolStripToDrag.IsInDesignMode)
                            {
                                Point endClientLocation = (this.Orientation == System.Windows.Forms.Orientation.Horizontal) ? new Point(clientLocation.X, row2.Bounds.Y) : new Point(row2.Bounds.X, clientLocation.Y);
                                panel.ToolStripPanelRow.MoveControl(toolStripToDrag, this.GetStartLocation(toolStripToDrag), endClientLocation);
                            }
                        }
                        else
                        {
                            row2 = new ToolStripPanelRow(this);
                            this.RowsInternal.Insert(count, row2);
                        }
                    }
                    else if (!row2.CanMove(toolStripToDrag))
                    {
                        int index = this.RowsInternal.IndexOf(row2);
                        if (((toolStripPanelRow != null) && (toolStripPanelRow.ControlsInternal.Count == 1)) && ((index > 0) && ((index - 1) == this.RowsInternal.IndexOf(toolStripPanelRow))))
                        {
                            return;
                        }
                        row2 = new ToolStripPanelRow(this);
                        this.RowsInternal.Insert(index, row2);
                        clientLocation.Y = row2.Bounds.Y;
                    }
                    flag = toolStripPanelRow != row2;
                    if ((!flag && (toolStripPanelRow != null)) && (toolStripPanelRow.ControlsInternal.Count > 1))
                    {
                        toolStripPanelRow.LeaveRow(toolStripToDrag);
                        toolStripPanelRow = null;
                        flag = true;
                    }
                    if (flag)
                    {
                        if (toolStripPanelRow != null)
                        {
                            toolStripPanelRow.LeaveRow(toolStripToDrag);
                        }
                        row2.JoinRow(toolStripToDrag, clientLocation);
                    }
                    if (flag && panel.IsCurrentlyDragging)
                    {
                        for (int i = 0; i < this.RowsInternal.Count; i++)
                        {
                            LayoutTransaction.DoLayout(this.RowsInternal[i], this, PropertyNames.Rows);
                        }
                        if (this.RowsInternal.IndexOf(row2) > 0)
                        {
                            System.Windows.Forms.IntSecurity.AdjustCursorPosition.Assert();
                            try
                            {
                                Point point3 = toolStripToDrag.PointToScreen(toolStripToDrag.GripRectangle.Location);
                                if (this.Orientation == System.Windows.Forms.Orientation.Vertical)
                                {
                                    point3.X += toolStripToDrag.GripRectangle.Width / 2;
                                    point3.Y  = Cursor.Position.Y;
                                }
                                else
                                {
                                    point3.Y += toolStripToDrag.GripRectangle.Height / 2;
                                    point3.X  = Cursor.Position.X;
                                }
                                Cursor.Position = point3;
                            }
                            finally
                            {
                                CodeAccessPermission.RevertAssert();
                            }
                        }
                    }
                }
            }
        }
 private void OnAdd(ISupportToolStripPanel controlToBeDragged, int index)
 {
     if (this.owner != null)
     {
         LayoutTransaction transaction = null;
         if ((this.ToolStripPanel != null) && (this.ToolStripPanel.ParentInternal != null))
         {
             transaction = new LayoutTransaction(this.ToolStripPanel, this.ToolStripPanel.ParentInternal, PropertyNames.Parent);
         }
         try
         {
             if (controlToBeDragged != null)
             {
                 controlToBeDragged.ToolStripPanelRow = this.owner;
                 Control control = controlToBeDragged as Control;
                 if (control != null)
                 {
                     control.ParentInternal = this.owner.ToolStripPanel;
                     this.owner.OnControlAdded(control, index);
                 }
             }
         }
         finally
         {
             if (transaction != null)
             {
                 transaction.Dispose();
             }
         }
     }
 }