public void Remove(Link value)
            {
                if (value.Owner != _owner)
                {
                    return;
                }

                _owner._links.Remove(value);

                if (_owner.AutoSize)
                {
                    LayoutTransaction.DoLayout(_owner.ParentInternal, _owner, PropertyNames.Links);
                    _owner.AdjustSize();
                    _owner.Invalidate();
                }

                _owner._links.Sort(LinkLabel.s_linkComparer);

                _owner.ValidateNoOverlappingLinks();
                _owner.UpdateSelectability();
                _owner.InvalidateTextLayout();
                _owner.Invalidate();

                if (_owner.FocusLink is null && _owner._links.Count > 0)
                {
                    _owner.FocusLink = (Link)_owner._links[0];
                }
            }
Example #2
0
        public void SetRowSpan(object control, int value)
        {
            ArgumentNullException.ThrowIfNull(control);

            if (value < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(value), value));
            }

            if (IsStub)
            {
                _stub.SetRowSpan(control, value);
            }
            else
            {
                IArrangedElement element = LayoutEngine.CastToArrangedElement(control);
                if (element.Container is not null)
                {
                    TableLayout.ClearCachedAssignments(TableLayout.GetContainerInfo(element.Container));
                }

                TableLayout.GetLayoutInfo(element).RowSpan = value;
                LayoutTransaction.DoLayout(element.Container, element, PropertyNames.RowSpan);
                Debug.Assert(GetRowSpan(element) == value, "row span should equal to the value we set");
            }
        }
Example #3
0
 private void PerformLayoutIfOwned()
 {
     if (this.Owner != null)
     {
         LayoutTransaction.DoLayout(this.Owner, this.Owner, this.PropertyName);
     }
 }
Example #4
0
 private void SetCellPosition(object control, int row, int column, bool rowSpecified, bool colSpecified)
 {
     if (IsStub)
     {
         if (colSpecified)
         {
             _stub.SetColumn(control, column);
         }
         if (rowSpecified)
         {
             _stub.SetRow(control, row);
         }
     }
     else
     {
         IArrangedElement element = LayoutEngine.CastToArrangedElement(control);
         if (element.Container != null)
         {
             TableLayout.ClearCachedAssignments(TableLayout.GetContainerInfo(element.Container));
         }
         TableLayout.LayoutInfo layoutInfo = TableLayout.GetLayoutInfo(element);
         if (colSpecified)
         {
             layoutInfo.ColumnPosition = column;
         }
         if (rowSpecified)
         {
             layoutInfo.RowPosition = row;
         }
         LayoutTransaction.DoLayout(element.Container, element, PropertyNames.TableIndex);
         Debug.Assert(!colSpecified || GetColumn(element) == column, "column position shoule equal to what we set");
         Debug.Assert(!rowSpecified || GetRow(element) == row, "row position shoule equal to what we set");
     }
 }
Example #5
0
 private void SetCellPosition(object control, int row, int column, bool rowSpecified, bool colSpecified)
 {
     if (this.IsStub)
     {
         if (colSpecified)
         {
             this._stub.SetColumn(control, column);
         }
         if (rowSpecified)
         {
             this._stub.SetRow(control, row);
         }
     }
     else
     {
         IArrangedElement element = this.LayoutEngine.CastToArrangedElement(control);
         if (element.Container != null)
         {
             System.Windows.Forms.Layout.TableLayout.ClearCachedAssignments(System.Windows.Forms.Layout.TableLayout.GetContainerInfo(element.Container));
         }
         System.Windows.Forms.Layout.TableLayout.LayoutInfo layoutInfo = System.Windows.Forms.Layout.TableLayout.GetLayoutInfo(element);
         if (colSpecified)
         {
             layoutInfo.ColumnPosition = column;
         }
         if (rowSpecified)
         {
             layoutInfo.RowPosition = row;
         }
         LayoutTransaction.DoLayout(element.Container, element, PropertyNames.TableIndex);
     }
 }
Example #6
0
 public void SetRowSpan(object control, int value)
 {
     if (value < 1)
     {
         throw new ArgumentOutOfRangeException("RowSpan", System.Windows.Forms.SR.GetString("InvalidArgument", new object[] { "RowSpan", value.ToString(CultureInfo.CurrentCulture) }));
     }
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     if (this.IsStub)
     {
         this._stub.SetRowSpan(control, value);
     }
     else
     {
         IArrangedElement element = this.LayoutEngine.CastToArrangedElement(control);
         if (element.Container != null)
         {
             System.Windows.Forms.Layout.TableLayout.ClearCachedAssignments(System.Windows.Forms.Layout.TableLayout.GetContainerInfo(element.Container));
         }
         System.Windows.Forms.Layout.TableLayout.GetLayoutInfo(element).RowSpan = value;
         LayoutTransaction.DoLayout(element.Container, element, PropertyNames.RowSpan);
     }
 }
Example #7
0
            /// <summary>
            ///  Removes control from this control. Inheriting controls should call
            ///  base.remove to ensure that the control is removed.
            /// </summary>
            public virtual void Remove(Control value)
            {
                // Sanity check parameter
                if (value == null)
                {
                    return;     // Don't do anything
                }

                if (value.ParentInternal == Owner)
                {
                    Debug.Assert(Owner != null);

                    value.SetParentHandle(IntPtr.Zero);

                    // Remove the control from the internal control array
                    //
                    InnerList.Remove(value);
                    value.AssignParent(null);
                    LayoutTransaction.DoLayout(Owner, value, PropertyNames.Parent);
                    Owner.OnControlRemoved(new ControlEventArgs(value));

                    // ContainerControl needs to see it needs to find a new ActiveControl.
                    if (Owner.GetContainerControl() is ContainerControl cc)
                    {
                        cc.AfterControlRemoved(value, Owner);
                    }
                }
            }
Example #8
0
            /// <summary>
            ///  This is internal virtual method so that "Readonly Collections" can override this and throw as they should not allow changing
            ///  the child control indices.
            /// </summary>
            internal virtual void SetChildIndexInternal(Control child, int newIndex)
            {
                // Sanity check parameters
                if (child == null)
                {
                    throw new ArgumentNullException(nameof(child));
                }

                int currentIndex = GetChildIndex(child);

                if (currentIndex == newIndex)
                {
                    return;
                }

                if (newIndex >= Count || newIndex == -1)
                {
                    newIndex = Count - 1;
                }

                MoveElement(child, currentIndex, newIndex);
                child.UpdateZOrder();

                LayoutTransaction.DoLayout(Owner, child, PropertyNames.ChildIndex);
            }
Example #9
0
        public void SetRowSpan(object control, int value)
        {
            if (value < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(value), string.Format(SR.InvalidArgument, "RowSpan", (value).ToString(CultureInfo.CurrentCulture)));
            }
            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }

            if (IsStub)
            {
                _stub.SetRowSpan(control, value);
            }
            else
            {
                IArrangedElement element = LayoutEngine.CastToArrangedElement(control);
                // LayoutInfo.SetColumnSpan() throws ArgumentException if out of range.
                if (element.Container != null)
                {
                    TableLayout.ClearCachedAssignments(TableLayout.GetContainerInfo(element.Container));
                }
                TableLayout.GetLayoutInfo(element).RowSpan = value;
                LayoutTransaction.DoLayout(element.Container, element, PropertyNames.RowSpan);
                Debug.Assert(GetRowSpan(element) == value, "row span should equal to the value we set");
            }
        }
Example #10
0
 private void OnAdd(ToolStripPanelRow value, int index)
 {
     if (_owner is not null)
     {
         LayoutTransaction.DoLayout(_owner, value, PropertyNames.Parent);
     }
 }
 protected override void OnVisibleChanged(EventArgs e)
 {
     if (base.Visible)
     {
         LayoutTransaction.DoLayout(this, this, PropertyNames.Visible);
     }
     base.OnVisibleChanged(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);
 }
 public override int GetChildCount()
 {
     if ((owner == null) || !owner.HasDropDownItems)
     {
         return(-1);
     }
     if (owner.DropDown.LayoutRequired)
     {
         LayoutTransaction.DoLayout(owner.DropDown, owner.DropDown, PropertyNames.Items);
     }
     return(owner.DropDown.AccessibilityObject.GetChildCount());
 }
Example #14
0
            public int Add(Link value)
            {
                if (value is not null && value.Length != 0)
                {
                    LinksAdded = true;
                }

                // check for the special case where the list is in the "magic"
                // state of having only the default link in it. In that case
                // we want to clear the list before adding this link.
                //
                if (_owner._links.Count == 1 &&
                    this[0].Start == 0 &&
                    this[0]._length == -1)
                {
                    _owner._links.Clear();
                    _owner.FocusLink = null;
                }

                // Set the owner control for this link
                value.Owner = _owner;

                _owner._links.Add(value);

                if (_owner.AutoSize)
                {
                    LayoutTransaction.DoLayout(_owner.ParentInternal, _owner, PropertyNames.Links);
                    _owner.AdjustSize();
                    _owner.Invalidate();
                }

                if (_owner.Links.Count > 1)
                {
                    _owner._links.Sort(LinkLabel.s_linkComparer);
                }

                _owner.ValidateNoOverlappingLinks();
                _owner.UpdateSelectability();
                _owner.InvalidateTextLayout();
                _owner.Invalidate();

                if (_owner.Links.Count > 1)
                {
                    return(IndexOf(value));
                }
                else
                {
                    return(0);
                }
            }
 protected override void OnRightToLeftChanged(EventArgs e)
 {
     base.OnRightToLeftChanged(e);
     if (this.HasDropDownItems)
     {
         if (this.DropDown.Visible)
         {
             LayoutTransaction.DoLayout(this.DropDown, this, PropertyNames.RightToLeft);
         }
         else
         {
             CommonProperties.xClearPreferredSizeCache(this.DropDown);
             this.DropDown.LayoutRequired = true;
         }
     }
 }
            public virtual void Clear()
            {
                bool doLayout = _owner._links.Count > 0 && _owner.AutoSize;

                _owner._links.Clear();

                if (doLayout)
                {
                    LayoutTransaction.DoLayout(_owner.ParentInternal, _owner, PropertyNames.Links);
                    _owner.AdjustSize();
                    _owner.Invalidate();
                }

                _owner.UpdateSelectability();
                _owner.InvalidateTextLayout();
                _owner.Invalidate();
            }
Example #17
0
 protected override void OnRightToLeftChanged(EventArgs e)
 {
     base.OnRightToLeftChanged(e);
     if (HasDropDownItems)
     {
         // only perform a layout on a visible dropdown - otherwise clear the preferred size cache.
         if (DropDown.Visible)
         {
             LayoutTransaction.DoLayout(DropDown, this, PropertyNames.RightToLeft);
         }
         else
         {
             CommonProperties.xClearPreferredSizeCache(DropDown);
             DropDown.LayoutRequired = true;
         }
     }
 }
 public void Insert(int index, ToolStripItem value)
 {
     this.CheckCanAddOrInsertItem(value);
     this.SetOwner(value);
     base.InnerList.Insert(index, value);
     if (this.itemsCollection && (this.owner != null))
     {
         if (this.owner.IsHandleCreated)
         {
             LayoutTransaction.DoLayout(this.owner, value, PropertyNames.Parent);
         }
         else
         {
             CommonProperties.xClearPreferredSizeCache(this.owner);
         }
         this.owner.OnItemAdded(new ToolStripItemEventArgs(value));
     }
 }
 /// <include file='doc\ToolStripItemCollection.uex' path='docs/doc[@for="ToolStripItemCollection.Insert"]/*' />
 /// <devdoc>
 /// <para>[To be supplied.]</para>
 /// </devdoc>
 public void Insert(int index, ToolStripItem value)
 {
     CheckCanAddOrInsertItem(value);
     SetOwner(value);
     InnerList.Insert(index, value);
     if (itemsCollection && owner != null)
     {
         if (owner.IsHandleCreated)
         {
             LayoutTransaction.DoLayout(owner, value, PropertyNames.Parent);
         }
         else
         {
             // next time we fetch the preferred size, recalc it.
             CommonProperties.xClearPreferredSizeCache(owner);
         }
         owner.OnItemAdded(new ToolStripItemEventArgs(value));
     }
 }
Example #20
0
        public override int GetChildCount()
        {
            if ((owner == null) || !owner.HasDropDownItems)
            {
                return(-1);
            }

            // Do not expose child items when the submenu is collapsed to prevent Narrator from announcing
            // invisible menu items when Narrator is in item's mode (CAPSLOCK + Arrow Left/Right) or
            // in scan mode (CAPSLOCK + Space)
            if (AccessibilityImprovements.Level3 && ExpandCollapseState == UnsafeNativeMethods.ExpandCollapseState.Collapsed)
            {
                return(0);
            }

            if (owner.DropDown.LayoutRequired)
            {
                LayoutTransaction.DoLayout(owner.DropDown, owner.DropDown, PropertyNames.Items);
            }
            return(owner.DropDown.AccessibilityObject.GetChildCount());
        }
        protected virtual void AdjustFormScrollbars(bool displayScrollbars)
        {
            bool      flag = false;
            Rectangle displayRectInternal = this.GetDisplayRectInternal();

            if (!displayScrollbars && (this.HScroll || this.VScroll))
            {
                flag = this.SetVisibleScrollbars(false, false);
            }
            if (!displayScrollbars)
            {
                Rectangle clientRectangle = base.ClientRectangle;
                displayRectInternal.Width  = clientRectangle.Width;
                displayRectInternal.Height = clientRectangle.Height;
            }
            else
            {
                flag |= this.ApplyScrollbarChanges(displayRectInternal);
            }
            if (flag)
            {
                LayoutTransaction.DoLayout(this, this, PropertyNames.DisplayRectangle);
            }
        }
        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();
                            }
                        }
                    }
                }
            }
        }
 protected override void OnRightToLeftChanged(EventArgs e)
 {
     base.OnRightToLeftChanged(e);
     this.resetRTLHScrollValue = true;
     LayoutTransaction.DoLayout(this, this, PropertyNames.RightToLeft);
 }
Example #24
0
            /// <summary>
            ///  Adds a child control to this control. The control becomes the last control in
            ///  the child control list. If the control is already a child of another control it
            ///  is first removed from that control.
            /// </summary>
            public virtual void Add(Control value)
            {
                if (value == null)
                {
                    return;
                }

                if (value.GetTopLevel())
                {
                    throw new ArgumentException(SR.TopLevelControlAdd);
                }

                // Verify that the control being added is on the same thread as
                // us...or our parent chain.
                if (Owner.CreateThreadId != value.CreateThreadId)
                {
                    throw new ArgumentException(SR.AddDifferentThreads);
                }

                CheckParentingCycle(Owner, value);

                if (value._parent == Owner)
                {
                    value.SendToBack();
                    return;
                }

                // Remove the new control from its old parent (if any)
                if (value._parent != null)
                {
                    value._parent.Controls.Remove(value);
                }

                // Add the control
                InnerList.Add(value);

                if (value._tabIndex == -1)
                {
                    // Find the next highest tab index
                    int nextTabIndex = 0;
                    for (int c = 0; c < (Count - 1); c++)
                    {
                        int t = this[c].TabIndex;
                        if (nextTabIndex <= t)
                        {
                            nextTabIndex = t + 1;
                        }
                    }
                    value._tabIndex = nextTabIndex;
                }

                // if we don't suspend layout, AssignParent will indirectly trigger a layout event
                // before we're ready (AssignParent will fire a PropertyChangedEvent("Visible"), which calls PerformLayout)
#if DEBUG
                int dbgLayoutCheck = Owner.LayoutSuspendCount;
#endif
                Owner.SuspendLayout();

                try
                {
                    Control oldParent = value._parent;
                    try
                    {
                        // AssignParent calls into user code - this could throw, which
                        // would make us short-circuit the rest of the reparenting logic.
                        // you could end up with a control half reparented.
                        value.AssignParent(Owner);
                    }
                    finally
                    {
                        if (oldParent != value._parent && (Owner._state & STATE_CREATED) != 0)
                        {
                            value.SetParentHandle(Owner.InternalHandle);
                            if (value.Visible)
                            {
                                value.CreateControl();
                            }
                        }
                    }

                    value.InitLayout();
                }
                finally
                {
                    Owner.ResumeLayout(false);
#if DEBUG
                    Owner.AssertLayoutSuspendCount(dbgLayoutCheck);
#endif
                }

                // Not putting in the finally block, as it would eat the original
                // exception thrown from AssignParent if the following throws an exception.
                LayoutTransaction.DoLayout(Owner, value, PropertyNames.Parent);
                Owner.OnControlAdded(new ControlEventArgs(value));
            }