public static void SetAnchor(IArrangedElement container, IArrangedElement element, AnchorStyles value)
        {
            AnchorStyles anchor = GetAnchor(element);

            if (anchor != value)
            {
                if (CommonProperties.GetNeedsDockLayout(element))
                {
                    SetDock(element, DockStyle.None);
                }
                CommonProperties.xSetAnchor(element, value);
                if (CommonProperties.GetNeedsAnchorLayout(element))
                {
                    UpdateAnchorInfo(element);
                }
                else
                {
                    SetAnchorInfo(element, null);
                }
                if (element.Container != null)
                {
                    bool flag  = IsAnchored(anchor, AnchorStyles.Right) && !IsAnchored(value, AnchorStyles.Right);
                    bool flag2 = IsAnchored(anchor, AnchorStyles.Bottom) && !IsAnchored(value, AnchorStyles.Bottom);
                    if ((element.Container.Container != null) && (flag | flag2))
                    {
                        LayoutTransaction.DoLayout(element.Container.Container, element, PropertyNames.Anchor);
                    }
                    LayoutTransaction.DoLayout(element.Container, element, PropertyNames.Anchor);
                }
            }
        }
Exemple #2
0
        public static void SetFlowDirection(IArrangedElement container, FlowDirection value)
        {
            SourceGenerated.EnumValidator.Validate(value);

            container.Properties.SetInteger(s_flowDirectionProperty, (int)value);
            LayoutTransaction.DoLayout(container, container, PropertyNames.FlowDirection);
            Debug.Assert(GetFlowDirection(container) == value, "GetFlowDirection should return the same value as we set");
        }
Exemple #3
0
        internal static void SetFlowBreak(IArrangedElement element, bool value)
        {
            BitVector32 layoutState = GetLayoutState(element);

            layoutState[_flowBreakSection] = value ? 1 : 0;
            SetLayoutState(element, layoutState);
            LayoutTransaction.DoLayout(element.Container, element, PropertyNames.FlowBreak);
        }
 public static void SetFlowDirection(IArrangedElement container, FlowDirection value)
 {
     if (!System.Windows.Forms.ClientUtils.IsEnumValid(value, (int)value, 0, 3))
     {
         throw new InvalidEnumArgumentException("value", (int)value, typeof(FlowDirection));
     }
     container.Properties.SetInteger(_flowDirectionProperty, (int)value);
     LayoutTransaction.DoLayout(container, container, PropertyNames.FlowDirection);
 }
Exemple #5
0
        internal static void SetMargin(IArrangedElement element, Padding value)
        {
            Debug.Assert(value != GetMargin(element), "PERF: Caller should guard against setting Margin to original value.");

            element.Properties.SetPadding(_marginProperty, value);

            Debug.Assert(GetMargin(element) == value, "Error detected setting Margin.");

            LayoutTransaction.DoLayout(element.Container, element, PropertyNames.Margin);
        }
Exemple #6
0
        internal static void SetMaximumSize(IArrangedElement element, Size value)
        {
            element.Properties.SetSize(_maximumSizeProperty, value);
            Rectangle bounds = element.Bounds;

            bounds.Width  = Math.Min(bounds.Width, value.Width);
            bounds.Height = Math.Min(bounds.Height, value.Height);
            element.SetBounds(bounds, BoundsSpecified.Size);
            LayoutTransaction.DoLayout(element.Container, element, PropertyNames.MaximumSize);
        }
Exemple #7
0
 public static void SetFlowDirection(IArrangedElement container, FlowDirection value)
 {
     //valid values are 0x0 to 0x3
     if (!ClientUtils.IsEnumValid(value, (int)value, (int)FlowDirection.LeftToRight, (int)FlowDirection.BottomUp))
     {
         throw new InvalidEnumArgumentException("value", (int)value, typeof(FlowDirection));
     }
     container.Properties.SetInteger(_flowDirectionProperty, (int)value);
     LayoutTransaction.DoLayout(container, container, PropertyNames.FlowDirection);
     Debug.Assert(GetFlowDirection(container) == value, "GetFlowDirection should return the same value as we set");
 }
Exemple #8
0
        internal static void SetFlowBreak(IArrangedElement element, bool value)
        {
            Debug.Assert(value != GetFlowBreak(element), "PERF: Caller should guard against setting FlowBreak to original value.");

            BitVector32 state = GetLayoutState(element);

            state[_flowBreakSection] = value ? 1 : 0;
            SetLayoutState(element, state);

            LayoutTransaction.DoLayout(element.Container, element, PropertyNames.FlowBreak);

            Debug.Assert(GetFlowBreak(element) == value, "Error detected setitng SetFlowBreak.");
        }
Exemple #9
0
 // This overload should be used when a property has changed that affects preferred size,
 // but you only want to layout if a certain condition exists (say you want to layout your
 // parent because your preferred size has changed).
 public static void DoLayoutIf(bool condition, IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, string property)
 {
     if (!condition)
     {
         if (elementCausingLayout != null)
         {
             CommonProperties.xClearPreferredSizeCache(elementCausingLayout);
         }
     }
     else
     {
         LayoutTransaction.DoLayout(elementToLayout, elementCausingLayout, property);
     }
 }
Exemple #10
0
        internal static void SetMaximumSize(IArrangedElement element, Size value)
        {
            Debug.Assert(value != GetMaximumSize(element, new Size(-7109, -7107)),
                         "PERF: Caller should guard against setting MaximumSize to original value.");

            element.Properties.SetSize(_maximumSizeProperty, value);

            // Element bounds may need to truncated to new maximum
            //
            Rectangle bounds = element.Bounds;

            bounds.Width  = Math.Min(bounds.Width, value.Width);
            bounds.Height = Math.Min(bounds.Height, value.Height);
            element.SetBounds(bounds, BoundsSpecified.Size);

            // element.SetBounds does a SetBoundsCore.  We still need to explicitly refresh parent layout.
            LayoutTransaction.DoLayout(element.Container, element, PropertyNames.MaximumSize);

            Debug.Assert(GetMaximumSize(element, new Size(-7109, -7107)) == value, "Error detected setting MaximumSize.");
        }
Exemple #11
0
        public static void SetAnchor(IArrangedElement element, AnchorStyles value)
        {
            AnchorStyles oldValue = GetAnchor(element);

            if (oldValue != value)
            {
                if (CommonProperties.GetNeedsDockLayout(element))
                {
                    // We set dock back to none to cause the element to size back to its original bounds.
                    SetDock(element, DockStyle.None);
                }

                CommonProperties.xSetAnchor(element, value);

                // Updating AnchorInfo is only needed when control is ready for layout. Oneway to check this precondition is to
                // check if the control is parented. This helps avoid calculating AnchorInfo with default initial values of the Control.
                // AnchorInfo is recalculated everytime there is a layout change.
                if (CommonProperties.GetNeedsAnchorLayout(element) && element is Control control && control.Parent is not null)
                {
                    UpdateAnchorInfo(element);
                }
                else
                {
                    SetAnchorInfo(element, null);
                }

                if (element.Container is not null)
                {
                    bool rightReleased  = IsAnchored(oldValue, AnchorStyles.Right) && !IsAnchored(value, AnchorStyles.Right);
                    bool bottomReleased = IsAnchored(oldValue, AnchorStyles.Bottom) && !IsAnchored(value, AnchorStyles.Bottom);
                    if (element.Container.Container is not null && (rightReleased || bottomReleased))
                    {
                        // If the right or bottom anchor is being released, we have a special case where the element's
                        // margin may affect preferredSize where it didn't previously. Rather than do an expensive
                        // check for this in OnLayout, we just detect the case her and force a relayout.
                        LayoutTransaction.DoLayout(element.Container.Container, element, PropertyNames.Anchor);
                    }

                    LayoutTransaction.DoLayout(element.Container, element, PropertyNames.Anchor);
                }
            }
Exemple #12
0
        public static void SetAnchor(IArrangedElement container, IArrangedElement element, AnchorStyles value)
        {
            AnchorStyles oldValue = GetAnchor(element);

            if (oldValue != value)
            {
                if (CommonProperties.GetNeedsDockLayout(element))
                {
                    // We set dock back to none to cause the element to size back to its original bounds.
                    SetDock(element, DockStyle.None);
                }

                CommonProperties.xSetAnchor(element, value);

                if (CommonProperties.GetNeedsAnchorLayout(element))
                {
                    UpdateAnchorInfo(element);
                }
                else
                {
                    SetAnchorInfo(element, null);
                }

                if (element.Container != null)
                {
                    bool rightReleased  = IsAnchored(oldValue, AnchorStyles.Right) && !IsAnchored(value, AnchorStyles.Right);
                    bool bottomReleased = IsAnchored(oldValue, AnchorStyles.Bottom) && !IsAnchored(value, AnchorStyles.Bottom);
                    if (element.Container.Container != null && (rightReleased || bottomReleased))
                    {
                        // If the right or bottom anchor is being released, we have a special case where the element's
                        // margin may affect preferredSize where it didn't previously. Rather than do an expensive
                        // check for this in OnLayout, we just detect the case her and force a relayout.
                        LayoutTransaction.DoLayout(element.Container.Container, element, PropertyNames.Anchor);
                    }

                    LayoutTransaction.DoLayout(element.Container, element, PropertyNames.Anchor);
                }
            }
        }
Exemple #13
0
 public static void SetWrapContents(IArrangedElement container, bool value)
 {
     container.Properties.SetInteger(_wrapContentsProperty, value ? 0 : 1);  // set to 0 if true, 1 if false
     LayoutTransaction.DoLayout(container, container, PropertyNames.WrapContents);
     Debug.Assert(GetWrapContents(container) == value, "GetWrapContents should return the same value as we set");
 }
Exemple #14
0
 internal static void SetMargin(IArrangedElement element, Padding value)
 {
     element.Properties.SetPadding(_marginProperty, value);
     LayoutTransaction.DoLayout(element.Container, element, PropertyNames.Margin);
 }
 public static void SetWrapContents(IArrangedElement container, bool value)
 {
     container.Properties.SetInteger(_wrapContentsProperty, value ? 0 : 1);
     LayoutTransaction.DoLayout(container, container, PropertyNames.WrapContents);
 }
 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();
             }
         }
     }
 }