Пример #1
0
        public void Resize(Rectangle deltaBounds)
        {
            SelectionRules rules = this.SelectionRules;

            if (this.CheckSelectionRules(rules, SelectionRules.Locked) || !this.CheckSelectionRules(rules, SelectionRules.Moveable))
            {
                return;
            }

            Rectangle bounds = (Rectangle)TypeDescriptor.GetProperties(_control)["Bounds"].GetValue(_control);

            if (CheckSelectionRules(rules, SelectionRules.LeftSizeable))
            {
                bounds.X     += deltaBounds.X;
                bounds.Width += deltaBounds.Width;
            }
            if (CheckSelectionRules(rules, SelectionRules.RightSizeable) && !CheckSelectionRules(rules, SelectionRules.LeftSizeable))
            {
                bounds.Y     += deltaBounds.Y;
                bounds.Width += deltaBounds.Width;
            }
            if (CheckSelectionRules(rules, SelectionRules.TopSizeable))
            {
                bounds.Y      += deltaBounds.Y;
                bounds.Height += deltaBounds.Height;
            }
            if (CheckSelectionRules(rules, SelectionRules.BottomSizeable) && !CheckSelectionRules(rules, SelectionRules.TopSizeable))
            {
                bounds.Height += deltaBounds.Height;
            }

            TypeDescriptor.GetProperties(_control)["Bounds"].SetValue(_control, bounds);
        }
        private void InitializeGlyph(Rectangle controlBounds, SelectionRules selRules, SelectionBorderGlyphType type)
        {
            base.rules         = SelectionRules.None;
            base.hitTestCursor = Cursors.Default;
            if ((selRules & SelectionRules.Moveable) != SelectionRules.None)
            {
                base.rules         = SelectionRules.Moveable;
                base.hitTestCursor = Cursors.SizeAll;
            }
            base.bounds    = DesignerUtils.GetBoundsForNoResizeSelectionType(controlBounds, type);
            base.hitBounds = base.bounds;
            switch (type)
            {
            case SelectionBorderGlyphType.Top:
            case SelectionBorderGlyphType.Bottom:
                this.hitBounds.Y      -= (DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE) / 2;
                this.hitBounds.Height += DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE;
                return;

            case SelectionBorderGlyphType.Left:
            case SelectionBorderGlyphType.Right:
                this.hitBounds.X     -= (DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE) / 2;
                this.hitBounds.Width += DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE;
                return;
            }
        }
Пример #3
0
        private Rectangle AdjustToGrid(Rectangle controlBounds, SelectionRules rules)
        {
            Rectangle rectangle = controlBounds;

            if ((rules & SelectionRules.RightSizeable) != SelectionRules.None)
            {
                int num = controlBounds.Right % this.parentGridSize.Width;
                if (num > (this.parentGridSize.Width / 2))
                {
                    rectangle.Width += this.parentGridSize.Width - num;
                }
                else
                {
                    rectangle.Width -= num;
                }
            }
            else if ((rules & SelectionRules.LeftSizeable) != SelectionRules.None)
            {
                int num2 = controlBounds.Left % this.parentGridSize.Width;
                if (num2 > (this.parentGridSize.Width / 2))
                {
                    rectangle.X     += this.parentGridSize.Width - num2;
                    rectangle.Width -= this.parentGridSize.Width - num2;
                }
                else
                {
                    rectangle.X     -= num2;
                    rectangle.Width += num2;
                }
            }
            if ((rules & SelectionRules.BottomSizeable) != SelectionRules.None)
            {
                int num3 = controlBounds.Bottom % this.parentGridSize.Height;
                if (num3 > (this.parentGridSize.Height / 2))
                {
                    rectangle.Height += this.parentGridSize.Height - num3;
                }
                else
                {
                    rectangle.Height -= num3;
                }
            }
            else if ((rules & SelectionRules.TopSizeable) != SelectionRules.None)
            {
                int num4 = controlBounds.Top % this.parentGridSize.Height;
                if (num4 > (this.parentGridSize.Height / 2))
                {
                    rectangle.Y      += this.parentGridSize.Height - num4;
                    rectangle.Height -= this.parentGridSize.Height - num4;
                }
                else
                {
                    rectangle.Y      -= num4;
                    rectangle.Height += num4;
                }
            }
            rectangle.Width  = Math.Max(rectangle.Width, this.parentGridSize.Width);
            rectangle.Height = Math.Max(rectangle.Height, this.parentGridSize.Height);
            return(rectangle);
        }
        private void InitializeGlyph(Rectangle controlBounds, SelectionRules selRules, SelectionBorderGlyphType type)
        {
            base.rules = SelectionRules.None;
            base.hitTestCursor = Cursors.Default;
            if ((selRules & SelectionRules.Moveable) != SelectionRules.None)
            {
                base.rules = SelectionRules.Moveable;
                base.hitTestCursor = Cursors.SizeAll;
            }
            base.bounds = DesignerUtils.GetBoundsForNoResizeSelectionType(controlBounds, type);
            base.hitBounds = base.bounds;
            switch (type)
            {
                case SelectionBorderGlyphType.Top:
                case SelectionBorderGlyphType.Bottom:
                    this.hitBounds.Y -= (DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE) / 2;
                    this.hitBounds.Height += DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE;
                    return;

                case SelectionBorderGlyphType.Left:
                case SelectionBorderGlyphType.Right:
                    this.hitBounds.X -= (DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE) / 2;
                    this.hitBounds.Width += DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE;
                    return;
            }
        }
Пример #5
0
 private void _browserStateNotificationService_SelectionRuleCreated(object sender, SelectionRuleCreatedEventArgs e)
 {
     if (e.SelectionRule.ProfileId == Id)
     {
         SelectionRules.Add(new SelectionRuleViewModel(_mediator, e.SelectionRule));
     }
 }
Пример #6
0
        /// <summary>
        ///     Adds the given <see cref="IMemberSelectionRule" /> to the factory.
        /// </summary>
        /// <exception cref="ArgumentNullException">memberSelectionRule can not be null.</exception>
        /// <param name="memberSelectionRule">The <see cref="IMemberSelectionRule" /> to add.</param>
        /// <returns>Returns the modified factory.</returns>
        public IInstanceFactory AddSelectionRule(IMemberSelectionRule memberSelectionRule)
        {
            memberSelectionRule.ThrowIfNull(nameof(memberSelectionRule));

            SelectionRules.Add(memberSelectionRule);
            return(this);
        }
 private Rectangle AdjustToGrid(Rectangle controlBounds, SelectionRules rules)
 {
     Rectangle rectangle = controlBounds;
     if ((rules & SelectionRules.RightSizeable) != SelectionRules.None)
     {
         int num = controlBounds.Right % this.parentGridSize.Width;
         if (num > (this.parentGridSize.Width / 2))
         {
             rectangle.Width += this.parentGridSize.Width - num;
         }
         else
         {
             rectangle.Width -= num;
         }
     }
     else if ((rules & SelectionRules.LeftSizeable) != SelectionRules.None)
     {
         int num2 = controlBounds.Left % this.parentGridSize.Width;
         if (num2 > (this.parentGridSize.Width / 2))
         {
             rectangle.X += this.parentGridSize.Width - num2;
             rectangle.Width -= this.parentGridSize.Width - num2;
         }
         else
         {
             rectangle.X -= num2;
             rectangle.Width += num2;
         }
     }
     if ((rules & SelectionRules.BottomSizeable) != SelectionRules.None)
     {
         int num3 = controlBounds.Bottom % this.parentGridSize.Height;
         if (num3 > (this.parentGridSize.Height / 2))
         {
             rectangle.Height += this.parentGridSize.Height - num3;
         }
         else
         {
             rectangle.Height -= num3;
         }
     }
     else if ((rules & SelectionRules.TopSizeable) != SelectionRules.None)
     {
         int num4 = controlBounds.Top % this.parentGridSize.Height;
         if (num4 > (this.parentGridSize.Height / 2))
         {
             rectangle.Y += this.parentGridSize.Height - num4;
             rectangle.Height -= this.parentGridSize.Height - num4;
         }
         else
         {
             rectangle.Y -= num4;
             rectangle.Height += num4;
         }
     }
     rectangle.Width = Math.Max(rectangle.Width, this.parentGridSize.Width);
     rectangle.Height = Math.Max(rectangle.Height, this.parentGridSize.Height);
     return rectangle;
 }
Пример #8
0
 private void _browserStateNotificationService_SelectionRuleDeleted(object sender, SelectionRuleDeletedEventArgs e)
 {
     if (e.SelectionRule.ProfileId == Id)
     {
         var selectionRule = SelectionRules.Single(x => x.Id == e.SelectionRule.Id);
         SelectionRules.Remove(selectionRule);
     }
 }
Пример #9
0
        /// <summary>
        /// Helper function that initializes the Glyph based on bounds, type, and bordersize.
        /// </summary>
        private void InitializeGlyph(Rectangle controlBounds, SelectionRules selRules, SelectionBorderGlyphType type)
        {
            rules         = SelectionRules.None;
            hitTestCursor = Cursors.Default;

            //this will return the rect representing the bounds of the glyph
            bounds    = DesignerUtils.GetBoundsForSelectionType(controlBounds, type);
            hitBounds = bounds;

            // The hitbounds for the border is actually a bit bigger than the glyph bounds
            switch (type)
            {
            case SelectionBorderGlyphType.Top:
                if ((selRules & SelectionRules.TopSizeable) != 0)
                {
                    hitTestCursor = Cursors.SizeNS;
                    rules         = SelectionRules.TopSizeable;
                }
                // We want to apply the SELECTIONBORDERHITAREA to the top and the bottom of the selection border glyph
                hitBounds.Y      -= (DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE) / 2;
                hitBounds.Height += DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE;
                break;

            case SelectionBorderGlyphType.Bottom:
                if ((selRules & SelectionRules.BottomSizeable) != 0)
                {
                    hitTestCursor = Cursors.SizeNS;
                    rules         = SelectionRules.BottomSizeable;
                }
                // We want to apply the SELECTIONBORDERHITAREA to the top and the bottom of the selection border glyph
                hitBounds.Y      -= (DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE) / 2;
                hitBounds.Height += DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE;
                break;

            case SelectionBorderGlyphType.Left:
                if ((selRules & SelectionRules.LeftSizeable) != 0)
                {
                    hitTestCursor = Cursors.SizeWE;
                    rules         = SelectionRules.LeftSizeable;
                }
                // We want to apply the SELECTIONBORDERHITAREA to the left and the right of the selection border glyph
                hitBounds.X     -= (DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE) / 2;
                hitBounds.Width += DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE;
                break;

            case SelectionBorderGlyphType.Right:
                if ((selRules & SelectionRules.RightSizeable) != 0)
                {
                    hitTestCursor = Cursors.SizeWE;
                    rules         = SelectionRules.RightSizeable;
                }
                // We want to apply the SELECTIONBORDERHITAREA to the left and the right of the selection border glyph
                hitBounds.X     -= (DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE) / 2;
                hitBounds.Width += DesignerUtils.SELECTIONBORDERHITAREA - DesignerUtils.SELECTIONBORDERSIZE;
                break;
            }
        }
Пример #10
0
        /// <summary>
        /// Конвертация SelectionRules в VSelectionRules.
        /// </summary>
        private static VSelectionRules ConvertSelectionRulesToVSelectionRules(SelectionRules selectionRule)
        {
            switch (selectionRule)
            {
            case SelectionRules.Topfer: return(VSelectionRules.Topfer);

            default: return(VSelectionRules.Topfer);
            }
        }
 internal NoResizeHandleGlyph(Rectangle controlBounds, SelectionRules selRules, bool primarySelection, System.Windows.Forms.Design.Behavior.Behavior behavior) : base(behavior)
 {
     this.isPrimary = primarySelection;
     base.hitTestCursor = Cursors.Default;
     base.rules = SelectionRules.None;
     if ((selRules & SelectionRules.Moveable) != SelectionRules.None)
     {
         base.rules = SelectionRules.Moveable;
         base.hitTestCursor = Cursors.SizeAll;
     }
     base.bounds = new Rectangle(controlBounds.X - DesignerUtils.NORESIZEHANDLESIZE, controlBounds.Y - DesignerUtils.NORESIZEHANDLESIZE, DesignerUtils.NORESIZEHANDLESIZE, DesignerUtils.NORESIZEHANDLESIZE);
     base.hitBounds = base.bounds;
 }
 internal NoResizeHandleGlyph(Rectangle controlBounds, SelectionRules selRules, bool primarySelection, System.Windows.Forms.Design.Behavior.Behavior behavior) : base(behavior)
 {
     this.isPrimary     = primarySelection;
     base.hitTestCursor = Cursors.Default;
     base.rules         = SelectionRules.None;
     if ((selRules & SelectionRules.Moveable) != SelectionRules.None)
     {
         base.rules         = SelectionRules.Moveable;
         base.hitTestCursor = Cursors.SizeAll;
     }
     base.bounds    = new Rectangle(controlBounds.X - DesignerUtils.NORESIZEHANDLESIZE, controlBounds.Y - DesignerUtils.NORESIZEHANDLESIZE, DesignerUtils.NORESIZEHANDLESIZE, DesignerUtils.NORESIZEHANDLESIZE);
     base.hitBounds = base.bounds;
 }
Пример #13
0
 /// <summary>
 /// NoResizeHandleGlyph's constructor takes additional parameters: 'type' and 'primary selection'. Also, we create/cache our pen & brush here to avoid this action with every paint message.
 /// </summary>
 internal NoResizeHandleGlyph(Rectangle controlBounds, SelectionRules selRules, bool primarySelection, Behavior behavior) : base(behavior)
 {
     _isPrimary    = primarySelection;
     hitTestCursor = Cursors.Default;
     rules         = SelectionRules.None;
     if ((selRules & SelectionRules.Moveable) != 0)
     {
         rules         = SelectionRules.Moveable;
         hitTestCursor = Cursors.SizeAll;
     }
     // The handle is always upperleft
     bounds    = new Rectangle(controlBounds.X - DesignerUtils.NORESIZEHANDLESIZE, controlBounds.Y - DesignerUtils.NORESIZEHANDLESIZE, DesignerUtils.NORESIZEHANDLESIZE, DesignerUtils.NORESIZEHANDLESIZE);
     hitBounds = bounds;
 }
Пример #14
0
        public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
        {
            if (button != MouseButtons.Left)
            {
                return(this.pushedBehavior);
            }
            this.targetResizeRules = SelectionRules.None;
            SelectionGlyphBase base2 = g as SelectionGlyphBase;

            if (base2 != null)
            {
                this.targetResizeRules = base2.SelectionRules;
                this.cursor            = base2.HitTestCursor;
            }
            if (this.targetResizeRules != SelectionRules.None)
            {
                ISelectionService service = (ISelectionService)this.serviceProvider.GetService(typeof(ISelectionService));
                if (service == null)
                {
                    return(false);
                }
                this.initialPoint   = mouseLoc;
                this.lastMouseLoc   = mouseLoc;
                this.primaryControl = service.PrimarySelection as Control;
                ArrayList list = new ArrayList();
                foreach (object obj2 in service.GetSelectedComponents())
                {
                    if (obj2 is Control)
                    {
                        PropertyDescriptor descriptor = TypeDescriptor.GetProperties(obj2)["Locked"];
                        if ((descriptor == null) || !((bool)descriptor.GetValue(obj2)))
                        {
                            list.Add(obj2);
                        }
                    }
                }
                if (list.Count == 0)
                {
                    return(false);
                }
                this.resizeComponents = new ResizeComponent[list.Count];
                for (int i = 0; i < list.Count; i++)
                {
                    this.resizeComponents[i].resizeControl = list[i];
                }
                this.pushedBehavior = true;
                this.BehaviorService.PushCaptureBehavior(this);
            }
            return(false);
        }
Пример #15
0
        /// <summary>
        ///  Queries to see if a drag operation
        ///  is valid on this handler for the given set of components.
        ///  If it returns true, BeginDrag will be called immediately after.
        /// </summary>
        public bool QueryBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
        {
            IComponentChangeService cs = (IComponentChangeService)GetService(typeof(IComponentChangeService));

            if (cs != null)
            {
                try
                {
                    if (components != null && components.Length > 0)
                    {
                        foreach (object c in components)
                        {
                            cs.OnComponentChanging(c, TypeDescriptor.GetProperties(c)["Location"]);
                            PropertyDescriptor sizeProp = TypeDescriptor.GetProperties(c)["Size"];

                            if (sizeProp != null && sizeProp.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden))
                            {
                                sizeProp = TypeDescriptor.GetProperties(c)["ClientSize"];
                            }

                            cs.OnComponentChanging(c, sizeProp);
                        }
                    }
                    else
                    {
                        cs.OnComponentChanging(GetComponent(), null);
                    }
                }
                catch (CheckoutException coEx)
                {
                    if (coEx == CheckoutException.Canceled)
                    {
                        // cancel the drag.
                        return(false);
                    }

                    throw;
                }
                catch (InvalidOperationException)
                {
                    // If the doc data for this designer is currently locked, we will get an exception here. In this
                    // case, just eat the exception. If this exception was thrown by someone else, that's fine too.
                    // No point in bubbling exceptions here anyway.

                    return(false);
                }
            }

            return(components != null && components.Length > 0);
        }
 public static SelectionRules FilterSelectionRules(SelectionRules baseRules, Control control, bool autoSize)
 {
     if (autoSize)
     {
         if (AutoSizePanel.CanAutoSizeWidth(control))
         {
             baseRules &= ~(SelectionRules.LeftSizeable | SelectionRules.RightSizeable);
         }
         if (AutoSizePanel.CanAutoSizeHeight(control))
         {
             baseRules &= ~(SelectionRules.TopSizeable | SelectionRules.BottomSizeable);
         }
     }
     return(baseRules);
 }
Пример #17
0
        /// <summary>
        ///  Begins a drag operation.  A designer should examine the list of components
        ///  to see if it wants to support the drag.  If it does, it should return
        ///  true.  If it returns true, the designer should provide
        ///  UI feedback about the drag at this time.  Typically, this feedback consists
        ///  of an inverted rectangle for each component, or a caret if the component
        ///  is text.
        /// </summary>
        public virtual bool BeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
        {
            dragOffset     = new Rectangle();
            originalCoords = null;
            this.rules     = rules;

            dragControls = new Control[components.Length];
            for (int i = 0; i < components.Length; i++)
            {
                Debug.Assert(components[i] is IComponent, "Selection UI handler only deals with IComponents");
                dragControls[i] = GetControl((IComponent)components[i]);
                Debug.Assert(dragControls[i] != null, "Everyone must have a control");
            }

            // allow the cliprect to go just beyond the window by one grid.  This helps with round off
            // problems.  We can only do this if the container itself is not in the selection.  Also,
            // if the container is a form and it has autoscroll turned on, we allow a drag beyond the
            // container boundary on the width and height, but not top and left.
            //
            bool       containerSelected = false;
            IComponent container         = GetComponent();

            for (int i = 0; i < components.Length; i++)
            {
                if (components[i] == container)
                {
                    containerSelected = true;
                    break;
                }
            }

            if (!containerSelected)
            {
                Control   containerControl = GetControl();
                Size      snapSize         = GetCurrentSnapSize();
                Rectangle containerRect    = containerControl.RectangleToScreen(containerControl.ClientRectangle);
                containerRect.Inflate(snapSize.Width, snapSize.Height);
                ScrollableControl sc = GetControl() as ScrollableControl;
                if (sc != null && sc.AutoScroll)
                {
                    Rectangle screen = SystemInformation.VirtualScreen;
                    containerRect.Width  = screen.Width;
                    containerRect.Height = screen.Height;
                }
            }

            return(true);
        }
        public void InitializeTest()
        {
            Panel panel = (Panel)((IContainer)_helper.IDesignerHost).Components[0];              // the root control
            DocumentDesignerTest designer = _helper.IDesignerHost.GetDesigner(panel) as DocumentDesignerTest;

            SelectionRules rules = SelectionRules.BottomSizeable | SelectionRules.RightSizeable | SelectionRules.Visible;

            Assert.AreEqual(rules, designer.SelectionRules, "#1");
            Assert.AreEqual(new Point(0, 0), (Point)_helper.GetValue(panel, "Location"), "#2");
#if NET_2_0
            Assert.AreEqual(ViewTechnology.Default, ((IRootDesigner)designer).SupportedTechnologies[0], "#3");
            Assert.IsTrue(((IRootDesigner)designer).GetView(ViewTechnology.Default) is Control, "#4");
#else
            Assert.AreEqual(ViewTechnology.WindowsForms, ((IRootDesigner)designer).SupportedTechnologies[0], "#3");
            Assert.IsTrue(((IRootDesigner)designer).GetView(ViewTechnology.WindowsForms) is Control, "#4");
#endif
        }
        public void SelectionRulesTest()
        {
            Button          button   = (Button)_helper.CreateControl(typeof(TestButton), null);
            ControlDesigner designer = _helper.IDesignerHost.GetDesigner(button) as ControlDesigner;

            SelectionRules selectionRules = SelectionRules.AllSizeable | SelectionRules.Moveable | SelectionRules.Visible;

            Assert.AreEqual(selectionRules, designer.SelectionRules, "#1");

            button.Dock    = DockStyle.Left;
            selectionRules = SelectionRules.RightSizeable | SelectionRules.Visible;
            Assert.AreEqual(selectionRules, designer.SelectionRules, "#2");

            button.Dock    = DockStyle.Fill;
            selectionRules = SelectionRules.Visible;
            Assert.AreEqual(selectionRules, designer.SelectionRules, "#3");
        }
Пример #20
0
        /// <summary>
        /// Builds up an array of snaplines used during resize to adjust/snap the controls bounds.
        /// </summary>
        private SnapLine[] GenerateSnapLines(SelectionRules rules, Point loc)
        {
            ArrayList lines = new ArrayList(2);

            //the four margins and edges of our control
            if ((rules & SelectionRules.BottomSizeable) != 0)
            {
                lines.Add(new SnapLine(SnapLineType.Bottom, loc.Y - 1));
                if (_primaryControl != null)
                {
                    lines.Add(new SnapLine(SnapLineType.Horizontal, loc.Y + _primaryControl.Margin.Bottom, SnapLine.MarginBottom, SnapLinePriority.Always));
                }
            }
            else if ((rules & SelectionRules.TopSizeable) != 0)
            {
                lines.Add(new SnapLine(SnapLineType.Top, loc.Y));
                if (_primaryControl != null)
                {
                    lines.Add(new SnapLine(SnapLineType.Horizontal, loc.Y - _primaryControl.Margin.Top, SnapLine.MarginTop, SnapLinePriority.Always));
                }
            }

            if ((rules & SelectionRules.RightSizeable) != 0)
            {
                lines.Add(new SnapLine(SnapLineType.Right, loc.X - 1));
                if (_primaryControl != null)
                {
                    lines.Add(new SnapLine(SnapLineType.Vertical, loc.X + _primaryControl.Margin.Right, SnapLine.MarginRight, SnapLinePriority.Always));
                }
            }
            else if ((rules & SelectionRules.LeftSizeable) != 0)
            {
                lines.Add(new SnapLine(SnapLineType.Left, loc.X));
                if (_primaryControl != null)
                {
                    lines.Add(new SnapLine(SnapLineType.Vertical, loc.X - _primaryControl.Margin.Left, SnapLine.MarginLeft, SnapLinePriority.Always));
                }
            }

            SnapLine[] l = new SnapLine[lines.Count];
            lines.CopyTo(l);

            return(l);
        }
        public static SelectionRules FilterContainerSelectionRules(SelectionRules baseRules, Control control, bool autoSize)
        {
            if (autoSize)
            {
                bool flag  = false;
                bool flag2 = true;
                bool flag3 = true;
                for (int i = 0; i < control.Controls.Count; i++)
                {
                    Control control2 = control.Controls[i];
                    if (control2.Visible)
                    {
                        flag = true;
                        switch (control2.Dock)
                        {
                        case DockStyle.None:
                            flag2 = false;
                            flag3 = false;
                            break;

                        case DockStyle.Top:
                        case DockStyle.Bottom:
                            flag3 = false;
                            break;

                        case DockStyle.Left:
                        case DockStyle.Right:
                            flag2 = false;
                            break;
                        }
                    }
                }
                if (flag && !flag2 && AutoSizePanel.CanAutoSizeWidth(control))
                {
                    baseRules &= ~(SelectionRules.LeftSizeable | SelectionRules.RightSizeable);
                }
                if (flag && !flag3 && AutoSizePanel.CanAutoSizeHeight(control))
                {
                    baseRules &= ~(SelectionRules.TopSizeable | SelectionRules.BottomSizeable);
                }
            }
            return(baseRules);
        }
        public bool QueryBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
        {
            IComponentChangeService service = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));

            if (service != null)
            {
                try
                {
                    if ((components != null) && (components.Length > 0))
                    {
                        foreach (object obj2 in components)
                        {
                            service.OnComponentChanging(obj2, TypeDescriptor.GetProperties(obj2)["Location"]);
                            PropertyDescriptor member = TypeDescriptor.GetProperties(obj2)["Size"];
                            if ((member != null) && member.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden))
                            {
                                member = TypeDescriptor.GetProperties(obj2)["ClientSize"];
                            }
                            service.OnComponentChanging(obj2, member);
                        }
                    }
                    else
                    {
                        service.OnComponentChanging(this.GetComponent(), null);
                    }
                }
                catch (CheckoutException exception)
                {
                    if (exception != CheckoutException.Canceled)
                    {
                        throw exception;
                    }
                    return(false);
                }
                catch (InvalidOperationException)
                {
                    return(false);
                }
            }
            return((components != null) && (components.Length > 0));
        }
Пример #23
0
        private SnapLine[] GenerateSnapLines(SelectionRules rules, Point loc)
        {
            ArrayList list = new ArrayList(2);

            if ((rules & SelectionRules.BottomSizeable) != SelectionRules.None)
            {
                list.Add(new SnapLine(SnapLineType.Bottom, loc.Y - 1));
                if (this.primaryControl != null)
                {
                    list.Add(new SnapLine(SnapLineType.Horizontal, loc.Y + this.primaryControl.Margin.Bottom, "Margin.Bottom", SnapLinePriority.Always));
                }
            }
            else if ((rules & SelectionRules.TopSizeable) != SelectionRules.None)
            {
                list.Add(new SnapLine(SnapLineType.Top, loc.Y));
                if (this.primaryControl != null)
                {
                    list.Add(new SnapLine(SnapLineType.Horizontal, loc.Y - this.primaryControl.Margin.Top, "Margin.Top", SnapLinePriority.Always));
                }
            }
            if ((rules & SelectionRules.RightSizeable) != SelectionRules.None)
            {
                list.Add(new SnapLine(SnapLineType.Right, loc.X - 1));
                if (this.primaryControl != null)
                {
                    list.Add(new SnapLine(SnapLineType.Vertical, loc.X + this.primaryControl.Margin.Right, "Margin.Right", SnapLinePriority.Always));
                }
            }
            else if ((rules & SelectionRules.LeftSizeable) != SelectionRules.None)
            {
                list.Add(new SnapLine(SnapLineType.Left, loc.X));
                if (this.primaryControl != null)
                {
                    list.Add(new SnapLine(SnapLineType.Vertical, loc.X - this.primaryControl.Margin.Left, "Margin.Left", SnapLinePriority.Always));
                }
            }
            SnapLine[] array = new SnapLine[list.Count];
            list.CopyTo(array);
            return(array);
        }
        /// <include file='doc\SelectionUIHandler.uex' path='docs/doc[@for="SelectionUIHandler.QueryBeginDrag"]/*' />
        /// <devdoc>
        ///     Queries to see if a drag operation
        ///     is valid on this handler for the given set of components.
        ///     If it returns true, BeginDrag will be called immediately after.
        /// </devdoc>
        public bool QueryBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
        {
            IComponentChangeService cs = (IComponentChangeService)GetService(typeof(IComponentChangeService));

            if (cs != null)
            {
                try {
                    if (components != null && components.Length > 0)
                    {
                        foreach (object c in components)
                        {
                            cs.OnComponentChanging(c, TypeDescriptor.GetProperties(c)["Location"]);
                            PropertyDescriptor sizeProp = TypeDescriptor.GetProperties(c)["Size"];

                            if (sizeProp != null && sizeProp.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden))
                            {
                                sizeProp = TypeDescriptor.GetProperties(c)["ClientSize"];
                            }
                            cs.OnComponentChanging(c, sizeProp);
                        }
                    }
                    else
                    {
                        cs.OnComponentChanging(GetComponent(), null);
                    }
                }
                catch (CheckoutException coEx) {
                    if (coEx == CheckoutException.Canceled)
                    {
                        // cancel the drag.
                        return(false);
                    }
                    throw coEx;
                }
            }
            return(components != null && components.Length > 0);
        }
        public virtual bool BeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
        {
            this.dragOffset     = new Rectangle();
            this.originalCoords = null;
            this.rules          = rules;
            this.dragControls   = new Control[components.Length];
            for (int i = 0; i < components.Length; i++)
            {
                this.dragControls[i] = this.GetControl((IComponent)components[i]);
            }
            bool       flag      = false;
            IComponent component = this.GetComponent();

            for (int j = 0; j < components.Length; j++)
            {
                if (components[j] == component)
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                Control   control         = this.GetControl();
                Size      currentSnapSize = this.GetCurrentSnapSize();
                Rectangle rectangle       = control.RectangleToScreen(control.ClientRectangle);
                rectangle.Inflate(currentSnapSize.Width, currentSnapSize.Height);
                ScrollableControl control2 = this.GetControl() as ScrollableControl;
                if ((control2 != null) && control2.AutoScroll)
                {
                    Rectangle virtualScreen = SystemInformation.VirtualScreen;
                    rectangle.Width  = virtualScreen.Width;
                    rectangle.Height = virtualScreen.Height;
                }
            }
            return(true);
        }
 public virtual bool BeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
 {
     this.dragOffset = new Rectangle();
     this.originalCoords = null;
     this.rules = rules;
     this.dragControls = new Control[components.Length];
     for (int i = 0; i < components.Length; i++)
     {
         this.dragControls[i] = this.GetControl((IComponent) components[i]);
     }
     bool flag = false;
     IComponent component = this.GetComponent();
     for (int j = 0; j < components.Length; j++)
     {
         if (components[j] == component)
         {
             flag = true;
             break;
         }
     }
     if (!flag)
     {
         Control control = this.GetControl();
         Size currentSnapSize = this.GetCurrentSnapSize();
         Rectangle rectangle = control.RectangleToScreen(control.ClientRectangle);
         rectangle.Inflate(currentSnapSize.Width, currentSnapSize.Height);
         ScrollableControl control2 = this.GetControl() as ScrollableControl;
         if ((control2 != null) && control2.AutoScroll)
         {
             Rectangle virtualScreen = SystemInformation.VirtualScreen;
             rectangle.Width = virtualScreen.Width;
             rectangle.Height = virtualScreen.Height;
         }
     }
     return true;
 }
 private ArrayList GenerateSnapLines(SelectionRules rules, Control primaryControl, int directionOffsetX, int directionOffsetY)
 {
     ArrayList list = new ArrayList(2);
     Point point = base.BehaviorService.ControlToAdornerWindow(primaryControl);
     bool flag = (primaryControl.Parent != null) && primaryControl.Parent.IsMirrored;
     if (directionOffsetX != 0)
     {
         if (!flag)
         {
             if ((rules & SelectionRules.RightSizeable) != SelectionRules.None)
             {
                 list.Add(new SnapLine(SnapLineType.Right, (point.X + primaryControl.Width) - 1));
                 list.Add(new SnapLine(SnapLineType.Vertical, (point.X + primaryControl.Width) + primaryControl.Margin.Right, "Margin.Right", SnapLinePriority.Always));
             }
         }
         else if ((rules & SelectionRules.LeftSizeable) != SelectionRules.None)
         {
             list.Add(new SnapLine(SnapLineType.Left, point.X));
             list.Add(new SnapLine(SnapLineType.Vertical, point.X - primaryControl.Margin.Left, "Margin.Left", SnapLinePriority.Always));
         }
     }
     if ((directionOffsetY != 0) && ((rules & SelectionRules.BottomSizeable) != SelectionRules.None))
     {
         list.Add(new SnapLine(SnapLineType.Bottom, (point.Y + primaryControl.Height) - 1));
         list.Add(new SnapLine(SnapLineType.Horizontal, (point.Y + primaryControl.Height) + primaryControl.Margin.Bottom, "Margin.Bottom", SnapLinePriority.Always));
     }
     return list;
 }
 public void UpdateRules()
 {
     if (this.handler == null)
     {
         this.selectionRules = SelectionRules.None;
     }
     else
     {
         SelectionRules selectionRules = this.selectionRules;
         this.selectionRules = this.handler.GetComponentRules(this.component);
         if (this.selectionRules != selectionRules)
         {
             this.UpdateGrabSettings();
             this.Invalidate();
         }
     }
 }
Пример #29
0
 internal SelectionBorderGlyph(Rectangle controlBounds, SelectionRules rules, SelectionBorderGlyphType type, Behavior?behavior)
     : base(behavior)
 {
     InitializeGlyph(controlBounds, rules, type);
 }
 internal NoResizeSelectionBorderGlyph(Rectangle controlBounds, SelectionRules rules, SelectionBorderGlyphType type, System.Windows.Forms.Design.Behavior.Behavior behavior) : base(behavior)
 {
     this.InitializeGlyph(controlBounds, rules, type);
 }
 bool ISelectionUIHandler.QueryBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
 {
     return this.DragHandler.QueryBeginDrag(components, rules, initialX, initialY);
 }
Пример #32
0
        /// <summary>
        /// Called during the resize operation, we'll try to determine an offset so that the controls snap to the grid settings of the parent.
        /// </summary>
        private Rectangle AdjustToGrid(Rectangle controlBounds, SelectionRules rules)
        {
            Rectangle rect = controlBounds;

            if ((rules & SelectionRules.RightSizeable) != 0)
            {
                int xDelta = controlBounds.Right % _parentGridSize.Width;
                if (xDelta > _parentGridSize.Width / 2)
                {
                    rect.Width += _parentGridSize.Width - xDelta;
                }
                else
                {
                    rect.Width -= xDelta;
                }
            }
            else if ((rules & SelectionRules.LeftSizeable) != 0)
            {
                int xDelta = controlBounds.Left % _parentGridSize.Width;
                if (xDelta > _parentGridSize.Width / 2)
                {
                    rect.X     += _parentGridSize.Width - xDelta;
                    rect.Width -= _parentGridSize.Width - xDelta;
                }
                else
                {
                    rect.X     -= xDelta;
                    rect.Width += xDelta;
                }
            }

            if ((rules & SelectionRules.BottomSizeable) != 0)
            {
                int yDelta = controlBounds.Bottom % _parentGridSize.Height;
                if (yDelta > _parentGridSize.Height / 2)
                {
                    rect.Height += _parentGridSize.Height - yDelta;
                }
                else
                {
                    rect.Height -= yDelta;
                }
            }
            else if ((rules & SelectionRules.TopSizeable) != 0)
            {
                int yDelta = controlBounds.Top % _parentGridSize.Height;
                if (yDelta > _parentGridSize.Height / 2)
                {
                    rect.Y      += _parentGridSize.Height - yDelta;
                    rect.Height -= _parentGridSize.Height - yDelta;
                }
                else
                {
                    rect.Y      -= yDelta;
                    rect.Height += yDelta;
                }
            }

            //validate our dimensions
            rect.Width  = Math.Max(rect.Width, _parentGridSize.Width);
            rect.Height = Math.Max(rect.Height, _parentGridSize.Height);

            return(rect);
        }
Пример #33
0
        /// <summary>
        /// In response to a MouseDown, the SelectionBehavior will push (initiate) a dragBehavior by alerting the SelectionMananger that a new control has been selected and the mouse is down. Note that this is only if we find the related control's Dock property == none.
        /// </summary>
        public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
        {
            //we only care about the right mouse button for resizing
            if (button != MouseButtons.Left)
            {
                //pass any other mouse click along - unless we've already started our resize in which case we'll ignore it
                return(_pushedBehavior);
            }
            //start with no selection rules and try to obtain this info from the glyph
            _targetResizeRules = SelectionRules.None;
            if (g is SelectionGlyphBase sgb)
            {
                _targetResizeRules = sgb.SelectionRules;
                _cursor            = sgb.HitTestCursor;
            }

            if (_targetResizeRules == SelectionRules.None)
            {
                return(false);
            }

            ISelectionService selSvc = (ISelectionService)_serviceProvider.GetService(typeof(ISelectionService));

            if (selSvc == null)
            {
                return(false);
            }

            _initialPoint = mouseLoc;
            _lastMouseLoc = mouseLoc;
            //build up a list of our selected controls
            _primaryControl = selSvc.PrimarySelection as Control;

            // Since we don't know exactly how many valid objects we are going to have we use this temp
            ArrayList components = new ArrayList();

            foreach (object o in selSvc.GetSelectedComponents())
            {
                if (o is Control)
                {
                    //don't drag locked controls
                    PropertyDescriptor prop = TypeDescriptor.GetProperties(o)["Locked"];
                    if (prop != null)
                    {
                        if ((bool)prop.GetValue(o))
                        {
                            continue;
                        }
                    }
                    components.Add(o);
                }
            }

            if (components.Count == 0)
            {
                return(false);
            }

            _resizeComponents = new ResizeComponent[components.Count];
            for (int i = 0; i < components.Count; i++)
            {
                _resizeComponents[i].resizeControl = components[i];
            }

            //push this resizebehavior
            _pushedBehavior = true;
            BehaviorService.PushCaptureBehavior(this);
            return(false);
        }
 internal NoResizeSelectionBorderGlyph(Rectangle controlBounds, SelectionRules rules, SelectionBorderGlyphType type, System.Windows.Forms.Design.Behavior.Behavior behavior) : base(behavior)
 {
     this.InitializeGlyph(controlBounds, rules, type);
 }
 protected override void OnMouseDown(MouseEventArgs me)
 {
     if ((this.dragHandler == null) && (this.selSvc != null))
     {
         try
         {
             Point point = base.PointToScreen(new Point(me.X, me.Y));
             HitTestInfo hitTest = this.GetHitTest(point, 3);
             int num = hitTest.hitTest;
             if ((num & 0x200) != 0)
             {
                 this.selSvc.SetSelectedComponents(new object[] { hitTest.selectionUIHit.component }, SelectionTypes.Auto);
                 SelectionRules moveable = SelectionRules.Moveable;
                 if (((ISelectionUIService) this).BeginDrag(moveable, point.X, point.Y))
                 {
                     base.Visible = false;
                     this.containerDrag = hitTest.selectionUIHit.component;
                     this.BeginMouseDrag(point, num);
                 }
             }
             else if ((num != 0x100) && (me.Button == MouseButtons.Left))
             {
                 SelectionRules none = SelectionRules.None;
                 this.ctrlSelect = (Control.ModifierKeys & Keys.Control) != Keys.None;
                 if (!this.ctrlSelect)
                 {
                     this.selSvc.SetSelectedComponents(new object[] { hitTest.selectionUIHit.component }, SelectionTypes.Click);
                 }
                 if ((num & 12) != 0)
                 {
                     none |= SelectionRules.Moveable;
                 }
                 if ((num & 3) != 0)
                 {
                     if ((num & 0x41) == 0x41)
                     {
                         none |= SelectionRules.RightSizeable;
                     }
                     if ((num & 0x11) == 0x11)
                     {
                         none |= SelectionRules.LeftSizeable;
                     }
                     if ((num & 0x22) == 0x22)
                     {
                         none |= SelectionRules.TopSizeable;
                     }
                     if ((num & 130) == 130)
                     {
                         none |= SelectionRules.BottomSizeable;
                     }
                     if (((ISelectionUIService) this).BeginDrag(none, point.X, point.Y))
                     {
                         this.BeginMouseDrag(point, num);
                     }
                 }
                 else
                 {
                     this.dragRules = none;
                     this.BeginMouseDrag(point, num);
                 }
             }
             else if (num == 0x100)
             {
                 this.dragRules = SelectionRules.None;
                 this.mouseDragAnchor = InvalidPoint;
             }
         }
         catch (Exception exception)
         {
             if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
             {
                 throw;
             }
             if (exception != CheckoutException.Canceled)
             {
                 this.DisplayError(exception);
             }
         }
     }
 }
 private object[] FilterSelection(object[] components, SelectionRules selectionRules)
 {
     object[] objArray = null;
     if (components != null)
     {
         if (selectionRules != SelectionRules.None)
         {
             IDesignerHost service = (IDesignerHost) this.GetService(typeof(IDesignerHost));
             if (service != null)
             {
                 ArrayList list = new ArrayList();
                 foreach (IComponent component in components)
                 {
                     ControlDesigner designer = service.GetDesigner(component) as ControlDesigner;
                     if ((designer != null) && ((designer.SelectionRules & selectionRules) == selectionRules))
                     {
                         list.Add(component);
                     }
                 }
                 objArray = list.ToArray();
             }
         }
         if (objArray != null)
         {
             return objArray;
         }
     }
     return new object[0];
 }
Пример #37
0
        /// <include file='doc\ControlCommandSet.uex' path='docs/doc[@for="ControlCommandSet.OnKeySize"]/*' />
        /// <devdoc>
        ///     Called for the various sizing commands we support.
        /// </devdoc>
        protected void OnKeySize(object sender, EventArgs e)
        {
            // Arrow keys.  Begin a drag if the selection isn't locked.
            //
            ISelectionService   selSvc = SelectionService;
            ISelectionUIService uiSvc  = SelectionUIService;

            if (uiSvc != null && selSvc != null)
            {
                //added to remove the selection rectangle: bug(54692)
                //
                uiSvc.Visible = false;
                object comp = selSvc.PrimarySelection;
                if (comp != null && comp is IComponent)
                {
                    PropertyDescriptor lockedProp = TypeDescriptor.GetProperties(comp)["Locked"];
                    if (lockedProp == null || (lockedProp.PropertyType == typeof(bool) && ((bool)lockedProp.GetValue(comp))) == false)
                    {
                        SelectionRules rules       = SelectionRules.Visible;
                        CommandID      cmd         = ((MenuCommand)sender).CommandID;
                        bool           invertSnap  = false;
                        int            moveOffsetX = 0;
                        int            moveOffsetY = 0;

                        if (cmd.Equals(MenuCommands.KeySizeHeightDecrease))
                        {
                            moveOffsetY = -1;
                            rules      |= SelectionRules.BottomSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeySizeHeightIncrease))
                        {
                            moveOffsetY = 1;
                            rules      |= SelectionRules.BottomSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeySizeWidthDecrease))
                        {
                            moveOffsetX = -1;
                            rules      |= SelectionRules.RightSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeySizeWidthIncrease))
                        {
                            moveOffsetX = 1;
                            rules      |= SelectionRules.RightSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeyNudgeHeightDecrease))
                        {
                            moveOffsetY = -1;
                            invertSnap  = true;
                            rules      |= SelectionRules.BottomSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeyNudgeHeightIncrease))
                        {
                            moveOffsetY = 1;
                            invertSnap  = true;
                            rules      |= SelectionRules.BottomSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeyNudgeWidthDecrease))
                        {
                            moveOffsetX = -1;
                            invertSnap  = true;
                            rules      |= SelectionRules.RightSizeable;
                        }
                        else if (cmd.Equals(MenuCommands.KeyNudgeWidthIncrease))
                        {
                            moveOffsetX = 1;
                            invertSnap  = true;
                            rules      |= SelectionRules.RightSizeable;
                        }
                        else
                        {
                            Debug.Fail("Unknown command mapped to OnKeySize: " + cmd.ToString());
                        }

                        if (uiSvc.BeginDrag(rules, 0, 0))
                        {
                            bool               snapOn        = false;
                            Size               snapSize      = Size.Empty;
                            IComponent         snapComponent = null;
                            PropertyDescriptor snapProperty  = null;

                            // Gets the needed snap information
                            //
                            IDesignerHost       host  = (IDesignerHost)GetService(typeof(IDesignerHost));
                            DesignerTransaction trans = null;

                            try {
                                if (host != null)
                                {
                                    GetSnapInformation(host, (IComponent)comp, out snapSize, out snapComponent, out snapProperty);

                                    if (selSvc.SelectionCount > 1)
                                    {
                                        trans = host.CreateTransaction(SR.GetString(SR.DragDropSizeComponents, selSvc.SelectionCount));
                                    }
                                    else
                                    {
                                        trans = host.CreateTransaction(SR.GetString(SR.DragDropSizeComponent, ((IComponent)comp).Site.Name));
                                    }

                                    if (snapProperty != null)
                                    {
                                        snapOn = (bool)snapProperty.GetValue(snapComponent);

                                        if (invertSnap)
                                        {
                                            snapOn = !snapOn;
                                            snapProperty.SetValue(snapComponent, snapOn);
                                        }
                                    }
                                }

                                if (snapOn && !snapSize.IsEmpty)
                                {
                                    moveOffsetX *= snapSize.Width;
                                    moveOffsetY *= snapSize.Height;
                                }


                                // Now move the controls the correct # of pixels.
                                //
                                uiSvc.DragMoved(new Rectangle(0, 0, moveOffsetX, moveOffsetY));
                                uiSvc.EndDrag(false);

                                if (host != null)
                                {
                                    if (invertSnap && snapProperty != null)
                                    {
                                        snapOn = !snapOn;
                                        snapProperty.SetValue(snapComponent, snapOn);
                                    }
                                }
                            }
                            finally {
                                if (trans != null)
                                {
                                    trans.Commit();
                                    uiSvc.Visible = true;
                                }
                            }
                        }
                    }
                }

                uiSvc.Visible = true;
            }
        }
 public bool QueryBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
 {
     IComponentChangeService service = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
     if (service != null)
     {
         try
         {
             if ((components != null) && (components.Length > 0))
             {
                 foreach (object obj2 in components)
                 {
                     service.OnComponentChanging(obj2, TypeDescriptor.GetProperties(obj2)["Location"]);
                     PropertyDescriptor member = TypeDescriptor.GetProperties(obj2)["Size"];
                     if ((member != null) && member.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden))
                     {
                         member = TypeDescriptor.GetProperties(obj2)["ClientSize"];
                     }
                     service.OnComponentChanging(obj2, member);
                 }
             }
             else
             {
                 service.OnComponentChanging(this.GetComponent(), null);
             }
         }
         catch (CheckoutException exception)
         {
             if (exception != CheckoutException.Canceled)
             {
                 throw exception;
             }
             return false;
         }
         catch (InvalidOperationException)
         {
             return false;
         }
     }
     return ((components != null) && (components.Length > 0));
 }
Пример #39
0
		private bool CheckSelectionRules (SelectionRules rules, SelectionRules toCheck)
		{
			return ((rules & toCheck) == toCheck);
		}
 public bool DoBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
 {
     if (((rules & SelectionRules.AllSizeable) != SelectionRules.None) || (Control.MouseButtons == MouseButtons.None))
     {
         return true;
     }
     Control designerControl = this.client.GetDesignerControl();
     this.localDrag = true;
     this.localDragInside = false;
     this.dragComps = components;
     this.dragBase = new Point(initialX, initialY);
     this.localDragOffset = Point.Empty;
     designerControl.PointToClient(new Point(initialX, initialY));
     DragDropEffects allowedEffects = DragDropEffects.Move | DragDropEffects.Copy;
     for (int i = 0; i < components.Length; i++)
     {
         InheritanceAttribute attribute = (InheritanceAttribute) TypeDescriptor.GetAttributes(components[i])[typeof(InheritanceAttribute)];
         if (!attribute.Equals(InheritanceAttribute.NotInherited) && !attribute.Equals(InheritanceAttribute.InheritedReadOnly))
         {
             allowedEffects &= ~DragDropEffects.Move;
             allowedEffects |= 0x4000000;
         }
     }
     DataObject data = new ComponentDataObjectWrapper(new ComponentDataObject(this.client, this.serviceProvider, components, initialX, initialY));
     System.Design.NativeMethods.MSG msg = new System.Design.NativeMethods.MSG();
     while (System.Design.NativeMethods.PeekMessage(ref msg, IntPtr.Zero, 15, 15, 1))
     {
         System.Design.NativeMethods.TranslateMessage(ref msg);
         System.Design.NativeMethods.DispatchMessage(ref msg);
     }
     bool freezePainting = OleDragDropHandler.freezePainting;
     AddCurrentDrag(data, this.client.Component);
     ArrayList allowDropCache = new ArrayList();
     foreach (object obj3 in components)
     {
         Control control2 = obj3 as Control;
         if ((control2 != null) && control2.HasChildren)
         {
             this.DisableDragDropChildren(control2.Controls, allowDropCache);
         }
     }
     DragDropEffects none = DragDropEffects.None;
     IDesignerHost host = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
     DesignerTransaction transaction = null;
     if (host != null)
     {
         transaction = host.CreateTransaction(System.Design.SR.GetString("DragDropDragComponents", new object[] { components.Length }));
     }
     try
     {
         none = designerControl.DoDragDrop(data, allowedEffects);
         if (transaction != null)
         {
             transaction.Commit();
         }
     }
     finally
     {
         RemoveCurrentDrag(data);
         foreach (Control control3 in allowDropCache)
         {
             control3.AllowDrop = true;
         }
         OleDragDropHandler.freezePainting = freezePainting;
         if (transaction != null)
         {
             ((IDisposable) transaction).Dispose();
         }
     }
     bool flag3 = (((none & DragDropEffects.Move) != DragDropEffects.None) || ((none & 0x4000000) != DragDropEffects.None)) && this.localDragInside;
     ISelectionUIService service = (ISelectionUIService) this.GetService(typeof(ISelectionUIService));
     if ((service != null) && service.Dragging)
     {
         service.EndDrag(!flag3);
     }
     if (!this.localDragOffset.IsEmpty && (none != DragDropEffects.None))
     {
         this.DrawDragFrames(this.dragComps, this.localDragOffset, this.localDragEffect, Point.Empty, DragDropEffects.None, false);
     }
     this.localDragOffset = Point.Empty;
     this.dragComps = null;
     this.localDrag = this.localDragInside = false;
     this.dragBase = Point.Empty;
     return false;
 }
Пример #41
0
 /// <summary>
 ///  Queries to see if a drag operation
 ///  is valid on this handler for the given set of components.
 ///  If it returns true, BeginDrag will be called immediately after.
 /// </summary>
 public bool QueryBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
 {
     throw new NotImplementedException(SR.NotImplementedByDesign);
 }
 public static string GetTransactionName(SelectionRules rules, object[] objects)
 {
     if ((rules & SelectionRules.Moveable) != SelectionRules.None)
     {
         if (objects.Length > 1)
         {
             return System.Design.SR.GetString("DragDropMoveComponents", new object[] { objects.Length });
         }
         string name = string.Empty;
         if (objects.Length > 0)
         {
             IComponent component = objects[0] as IComponent;
             if ((component != null) && (component.Site != null))
             {
                 name = component.Site.Name;
             }
             else
             {
                 name = objects[0].GetType().Name;
             }
         }
         return System.Design.SR.GetString("DragDropMoveComponent", new object[] { name });
     }
     if ((rules & SelectionRules.AllSizeable) != SelectionRules.None)
     {
         if (objects.Length > 1)
         {
             return System.Design.SR.GetString("DragDropSizeComponents", new object[] { objects.Length });
         }
         string str3 = string.Empty;
         if (objects.Length > 0)
         {
             IComponent component2 = objects[0] as IComponent;
             if ((component2 != null) && (component2.Site != null))
             {
                 str3 = component2.Site.Name;
             }
             else
             {
                 str3 = objects[0].GetType().Name;
             }
         }
         return System.Design.SR.GetString("DragDropSizeComponent", new object[] { str3 });
     }
     return System.Design.SR.GetString("DragDropDragComponents", new object[] { objects.Length });
 }
 void ISelectionUIService.EndDrag(bool cancel)
 {
     this.containerDrag = null;
     ISelectionUIHandler dragHandler = this.dragHandler;
     object[] dragComponents = this.dragComponents;
     this.dragHandler = null;
     this.dragComponents = null;
     this.dragRules = SelectionRules.None;
     if (dragHandler == null)
     {
         throw new InvalidOperationException();
     }
     DesignerTransaction transaction = null;
     try
     {
         IComponent component = dragComponents[0] as IComponent;
         if ((dragComponents.Length > 1) || (((dragComponents.Length == 1) && (component != null)) && (component.Site == null)))
         {
             transaction = this.host.CreateTransaction(System.Design.SR.GetString("DragDropMoveComponents", new object[] { dragComponents.Length }));
         }
         else if ((dragComponents.Length == 1) && (component != null))
         {
             transaction = this.host.CreateTransaction(System.Design.SR.GetString("DragDropMoveComponent", new object[] { component.Site.Name }));
         }
         try
         {
             dragHandler.EndDrag(dragComponents, cancel);
         }
         catch (Exception)
         {
         }
     }
     finally
     {
         if (transaction != null)
         {
             transaction.Commit();
         }
         base.Visible = this.savedVisible;
         ((ISelectionUIService) this).SyncSelection();
         if (this.dragTransaction != null)
         {
             this.dragTransaction.Commit();
             this.dragTransaction = null;
         }
         this.EndMouseDrag(Control.MousePosition);
     }
 }
Пример #44
0
        /// <summary>
        /// This method will either initiate a new resize operation or continue with an existing one.  If we're currently dragging (i.e. resizing) then we look at the resize rules and set the bounds of each control to the new location of the mouse pointer.
        /// </summary>
        public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc)
        {
            if (!_pushedBehavior)
            {
                return(false);
            }

            bool altKeyPressed = Control.ModifierKeys == Keys.Alt;

            if (altKeyPressed && _dragManager != null)
            {
                //erase any snaplines (if we had any)
                _dragManager.EraseSnapLines();
            }

            if (!altKeyPressed && mouseLoc.Equals(_lastMouseLoc))
            {
                return(true);
            }

            // When DesignerWindowPane has scrollbars and we resize, shrinking the the DesignerWindowPane makes it look like the mouse has moved to the BS.  To compensate for that we keep track of the mouse's previous position in screen coordinates, and use that to compare if the mouse has really moved.
            if (_lastMouseAbs != null)
            {
                NativeMethods.POINT mouseLocAbs = new NativeMethods.POINT(mouseLoc.X, mouseLoc.Y);
                UnsafeNativeMethods.ClientToScreen(new HandleRef(this, _behaviorService.AdornerWindowControl.Handle), mouseLocAbs);
                if (mouseLocAbs.x == _lastMouseAbs.x && mouseLocAbs.y == _lastMouseAbs.y)
                {
                    return(true);
                }
            }

            if (!_dragging)
            {
                if (Math.Abs(_initialPoint.X - mouseLoc.X) > DesignerUtils.MinDragSize.Width / 2 || Math.Abs(_initialPoint.Y - mouseLoc.Y) > DesignerUtils.MinDragSize.Height / 2)
                {
                    InitiateResize();
                    _dragging = true;
                }
                else
                {
                    return(false);
                }
            }

            if (_resizeComponents == null || _resizeComponents.Length == 0)
            {
                return(false);
            }
            // we do these separately so as not to disturb the cached sizes for values we're not actually changing.  For example, if a control is docked top and we modify the height, the width shouldn't be modified.
            PropertyDescriptor propWidth  = null;
            PropertyDescriptor propHeight = null;
            PropertyDescriptor propTop    = null;
            PropertyDescriptor propLeft   = null;

            // We do this to make sure that Undo works correctly.
            if (_initialResize)
            {
                propWidth  = TypeDescriptor.GetProperties(_resizeComponents[0].resizeControl)["Width"];
                propHeight = TypeDescriptor.GetProperties(_resizeComponents[0].resizeControl)["Height"];
                propTop    = TypeDescriptor.GetProperties(_resizeComponents[0].resizeControl)["Top"];
                propLeft   = TypeDescriptor.GetProperties(_resizeComponents[0].resizeControl)["Left"];

                // validate each of the property descriptors.
                if (propWidth != null && !typeof(int).IsAssignableFrom(propWidth.PropertyType))
                {
                    propWidth = null;
                }

                if (propHeight != null && !typeof(int).IsAssignableFrom(propHeight.PropertyType))
                {
                    propHeight = null;
                }

                if (propTop != null && !typeof(int).IsAssignableFrom(propTop.PropertyType))
                {
                    propTop = null;
                }

                if (propLeft != null && !typeof(int).IsAssignableFrom(propLeft.PropertyType))
                {
                    propLeft = null;
                }
            }

            Control targetControl = _resizeComponents[0].resizeControl as Control;

            _lastMouseLoc = mouseLoc;
            _lastMouseAbs = new NativeMethods.POINT(mouseLoc.X, mouseLoc.Y);
            UnsafeNativeMethods.ClientToScreen(new HandleRef(this, _behaviorService.AdornerWindowControl.Handle), _lastMouseAbs);
            int minHeight = Math.Max(targetControl.MinimumSize.Height, MINSIZE);
            int minWidth  = Math.Max(targetControl.MinimumSize.Width, MINSIZE);

            if (_dragManager != null)
            {
                bool shouldSnap             = true;
                bool shouldSnapHorizontally = true;
                //if the targetcontrol is at min-size then we do not want to offer up snaplines
                if ((((_targetResizeRules & SelectionRules.BottomSizeable) != 0) || ((_targetResizeRules & SelectionRules.TopSizeable) != 0)) &&
                    (targetControl.Height == minHeight))
                {
                    shouldSnap = false;
                }
                else if ((((_targetResizeRules & SelectionRules.RightSizeable) != 0) || ((_targetResizeRules & SelectionRules.LeftSizeable) != 0)) &&
                         (targetControl.Width == minWidth))
                {
                    shouldSnap = false;
                }

                //if the targetControl has IntegralHeight turned on, then don't snap if the control can be resized vertically
                PropertyDescriptor propIntegralHeight = TypeDescriptor.GetProperties(targetControl)["IntegralHeight"];
                if (propIntegralHeight != null)
                {
                    object value = propIntegralHeight.GetValue(targetControl);
                    if (value is bool && (bool)value == true)
                    {
                        shouldSnapHorizontally = false;
                    }
                }

                if (!altKeyPressed && shouldSnap)
                {
                    //here, ask the snapline engine to suggest an offset during our resize
                    // Remembering the last snapoffset allows us to correctly erase snaplines, if the user subsequently holds down the Alt-Key. Remember that we don't physically move the mouse, we move the control. So if we didn't remember the last snapoffset and the user then hit the Alt-Key, we would actually redraw the control at the actual mouse location, which would make the control "jump" which is not what the user would expect. Why does the control "jump"? Because when a control is snapped, we have offset the control relative to where the mouse is, but we have not update the physical mouse position.
                    // When the user hits the Alt-Key they expect the control to be where it was (whether snapped or not). we can't rely on lastSnapOffset to check whether we snapped. We used to check if it was empty, but it can be empty and we still snapped (say the control was snapped, as you continue to move the mouse, it will stay snapped for a while. During that while the snapoffset will got from x to -x (or vice versa) and a one point hit 0.
                    // Since we have to calculate the new size/location differently based on whether we snapped or not, we have to know for sure if we snapped. We do different math because of bug 264996:
                    //  - if you snap, we want to move the control edge.
                    //  - otherwise, we just want to change the size by the number of pixels moved.
                    _lastSnapOffset = _dragManager.OnMouseMove(targetControl, GenerateSnapLines(_targetResizeRules, mouseLoc), ref _didSnap, shouldSnapHorizontally);
                }
                else
                {
                    _dragManager.OnMouseMove(new Rectangle(-100, -100, 0, 0)); /*just an invalid rect - so we won't snap*///);
                }

                // If there's a line to snap to, the offset will come back non-zero. In that case we should adjust the mouse position with the offset such that the size calculation below takes that offset into account. If there's no line, then the offset is 0, and there's no harm in adding the offset.
                mouseLoc.X += _lastSnapOffset.X;
                mouseLoc.Y += _lastSnapOffset.Y;
            }

            // IF WE ARE SNAPPING TO A CONTROL, then we also need to adjust for the offset between the initialPoint (where the MouseDown happened) and the edge of the control otherwise we would be those pixels off when resizing the control. Remember that snaplines are based on the targetControl, so we need to use the targetControl to figure out the offset.
            Rectangle controlBounds = new Rectangle(_resizeComponents[0].resizeBounds.X, _resizeComponents[0].resizeBounds.Y,
                                                    _resizeComponents[0].resizeBounds.Width, _resizeComponents[0].resizeBounds.Height);

            if ((_didSnap) && (targetControl.Parent != null))
            {
                controlBounds.Location = _behaviorService.MapAdornerWindowPoint(targetControl.Parent.Handle, controlBounds.Location);
                if (targetControl.Parent.IsMirrored)
                {
                    controlBounds.Offset(-controlBounds.Width, 0);
                }
            }

            Rectangle newBorderRect    = Rectangle.Empty;
            Rectangle targetBorderRect = Rectangle.Empty;
            bool      drawSnapline     = true;
            Color     backColor        = targetControl.Parent != null ? targetControl.Parent.BackColor : Color.Empty;

            for (int i = 0; i < _resizeComponents.Length; i++)
            {
                Control   control   = _resizeComponents[i].resizeControl as Control;
                Rectangle bounds    = control.Bounds;
                Rectangle oldBounds = bounds;
                // We need to compute the offset beased on the original cached Bounds ... ListBox doesnt allow drag on the top boundary if this is not done when it is "IntegralHeight"
                Rectangle baseBounds    = _resizeComponents[i].resizeBounds;
                Rectangle oldBorderRect = BehaviorService.ControlRectInAdornerWindow(control);
                bool      needToUpdate  = true;
                // The ResizeBehavior can easily get into a situation where we are fighting with a layout engine. E.g., We resize control to 50px, LayoutEngine lays out and finds 50px was too small and resized back to 100px.  This is what should happen, but it looks bad in the designer.  To avoid the flicker we temporarily turn off painting while we do the resize.
                UnsafeNativeMethods.SendMessage(control.Handle, Interop.WindowMessages.WM_SETREDRAW, false, /* unused = */ 0);
                try
                {
                    bool fRTL = false;
                    // If the container is mirrored the control origin is in upper-right, so we need to adjust our math for that. Remember that mouse coords have origin in upper left.
                    if (control.Parent != null && control.Parent.IsMirrored)
                    {
                        fRTL = true;
                    }
                    // figure out which ones we're actually changing so we don't blow away the controls cached sizing state.  This is important if things are docked we don't want to destroy their "pre-dock" size.
                    BoundsSpecified specified = BoundsSpecified.None;
                    // When we check if we should change height, width, location,  we first have to check if the targetControl allows resizing, and then if the control we are currently resizing allows it as well.
                    SelectionRules resizeRules = _resizeComponents[i].resizeRules;
                    if (((_targetResizeRules & SelectionRules.BottomSizeable) != 0) &&
                        ((resizeRules & SelectionRules.BottomSizeable) != 0))
                    {
                        int pixelHeight;
                        if (_didSnap)
                        {
                            pixelHeight = mouseLoc.Y - controlBounds.Bottom;
                        }
                        else
                        {
                            pixelHeight = AdjustPixelsForIntegralHeight(control, mouseLoc.Y - _initialPoint.Y);
                        }

                        bounds.Height = Math.Max(minHeight, baseBounds.Height + pixelHeight);
                        specified    |= BoundsSpecified.Height;
                    }

                    if (((_targetResizeRules & SelectionRules.TopSizeable) != 0) &&
                        ((resizeRules & SelectionRules.TopSizeable) != 0))
                    {
                        int yOffset;
                        if (_didSnap)
                        {
                            yOffset = controlBounds.Y - mouseLoc.Y;
                        }
                        else
                        {
                            yOffset = AdjustPixelsForIntegralHeight(control, _initialPoint.Y - mouseLoc.Y);
                        }

                        specified    |= BoundsSpecified.Height;
                        bounds.Height = Math.Max(minHeight, baseBounds.Height + yOffset);
                        if ((bounds.Height != minHeight) ||
                            ((bounds.Height == minHeight) && (oldBounds.Height != minHeight)))
                        {
                            specified |= BoundsSpecified.Y;
                            //if you do it fast enough, we actually could end up placing the control off the parent (say off the form), so enforce a "minimum" location
                            bounds.Y = Math.Min(baseBounds.Bottom - minHeight, baseBounds.Y - yOffset);
                        }
                    }

                    if (((((_targetResizeRules & SelectionRules.RightSizeable) != 0) && ((resizeRules & SelectionRules.RightSizeable) != 0)) && (!fRTL)) ||
                        ((((_targetResizeRules & SelectionRules.LeftSizeable) != 0) && ((resizeRules & SelectionRules.LeftSizeable) != 0)) && (fRTL)))
                    {
                        specified |= BoundsSpecified.Width;
                        int xOffset = _initialPoint.X;
                        if (_didSnap)
                        {
                            xOffset = !fRTL ? controlBounds.Right : controlBounds.Left;
                        }
                        bounds.Width = Math.Max(minWidth, baseBounds.Width + (!fRTL ? (mouseLoc.X - xOffset) : (xOffset - mouseLoc.X)));
                    }

                    if (((((_targetResizeRules & SelectionRules.RightSizeable) != 0) && ((resizeRules & SelectionRules.RightSizeable) != 0)) && (fRTL)) ||
                        ((((_targetResizeRules & SelectionRules.LeftSizeable) != 0) && ((resizeRules & SelectionRules.LeftSizeable) != 0)) && (!fRTL)))
                    {
                        specified |= BoundsSpecified.Width;
                        int xPos = _initialPoint.X;
                        if (_didSnap)
                        {
                            xPos = !fRTL ? controlBounds.Left : controlBounds.Right;
                        }

                        int xOffset = !fRTL ? (xPos - mouseLoc.X) : (mouseLoc.X - xPos);
                        bounds.Width = Math.Max(minWidth, baseBounds.Width + xOffset);
                        if ((bounds.Width != minWidth) ||
                            ((bounds.Width == minWidth) && (oldBounds.Width != minWidth)))
                        {
                            specified |= BoundsSpecified.X;
                            //if you do it fast enough, we actually could end up placing the control off the parent (say off the form), so enforce a "minimum" location
                            bounds.X = Math.Min(baseBounds.Right - minWidth, baseBounds.X - xOffset);
                        }
                    }

                    if (!_parentGridSize.IsEmpty)
                    {
                        bounds = AdjustToGrid(bounds, _targetResizeRules);
                    }

                    // Checking specified (check the diff) rather than bounds.<foo> != resizeBounds[i].<foo> also handles the following corner cases:
                    // 1. Create a form and add 2 buttons. Make sure that they are snapped to the left edge. Now grab the left edge of button 1, and start resizing to the left, past the snapline you will initially get, and then back to the right. What you would expect is to get the left edge snapline again. But without the specified check you wouldn't. This is because the bounds.<foo> != resizeBounds[i].<foo> checks would fail, since the new size would now be the original size. We could probably live with that, except that we draw the snapline below, since we correctly identified one. We could hack it so that we didn't draw the snapline, but that would confuse the user even more.
                    // 2. Create a form and add a single button. Place it at 100,100. Now start resizing it to the left and then back to the right. Note that with the original check (see diff), you would never be able to resize it back to position 100,100. You would get to 99,100 and then to 101,100.
                    if (((specified & BoundsSpecified.Width) == BoundsSpecified.Width) &&
                        _dragging && _initialResize && propWidth != null)
                    {
                        propWidth.SetValue(_resizeComponents[i].resizeControl, bounds.Width);
                    }

                    if (((specified & BoundsSpecified.Height) == BoundsSpecified.Height) &&
                        _dragging && _initialResize && propHeight != null)
                    {
                        propHeight.SetValue(_resizeComponents[i].resizeControl, bounds.Height);
                    }

                    if (((specified & BoundsSpecified.X) == BoundsSpecified.X) &&
                        _dragging && _initialResize && propLeft != null)
                    {
                        propLeft.SetValue(_resizeComponents[i].resizeControl, bounds.X);
                    }

                    if (((specified & BoundsSpecified.Y) == BoundsSpecified.Y) &&
                        _dragging && _initialResize && propTop != null)
                    {
                        propTop.SetValue(_resizeComponents[i].resizeControl, bounds.Y);
                    }

                    // We check the dragging bit here at every turn, because if there was a popup we may have lost capture and we are terminated.  At that point we shouldn't make any changes.
                    if (_dragging)
                    {
                        control.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height, specified);
                        //Get the new resize border
                        newBorderRect = BehaviorService.ControlRectInAdornerWindow(control);
                        if (control.Equals(targetControl))
                        {
                            Debug.Assert(i == 0, "The first control in the Selection should be the target control");
                            targetBorderRect = newBorderRect;
                        }

                        //Check that the control really did resize itself. Some controls (like ListBox, MonthCalendar) might adjust to a slightly different size than the one we pass in SetBounds. If if didn't size, then there's no need to invalidate anything
                        if (control.Bounds == oldBounds)
                        {
                            needToUpdate = false;
                        }
                        // We would expect the bounds now to be what we set it to above, but this might not be the case. If the control is hosted with e.g. a FLP, then setting the bounds above actually might force a re-layout, and the control will get moved to another spot. In this case, we don't really want to draw a snapline. Even if we snapped to a snapline, if the control got moved, the snapline would be in the wrong place.
                        if (control.Bounds != bounds)
                        {
                            drawSnapline = false;
                        }
                    }

                    if (control == _primaryControl && _statusCommandUI != null)
                    {
                        _statusCommandUI.SetStatusInformation(control as Component);
                    }
                }
                finally
                {
                    // While we were resizing we discarded painting messages to reduce flicker.  We now turn painting back on and manually refresh the controls.
                    UnsafeNativeMethods.SendMessage(control.Handle, Interop.WindowMessages.WM_SETREDRAW, true, /* unused = */ 0);
                    //update the control
                    if (needToUpdate)
                    {
                        Control parent = control.Parent;
                        if (parent != null)
                        {
                            control.Invalidate(/* invalidateChildren = */ true);
                            parent.Invalidate(oldBounds, /* invalidateChildren = */ true);
                            parent.Update();
                        }
                        else
                        {
                            control.Refresh();
                        }
                    }

                    //render the resize border
                    if (!newBorderRect.IsEmpty)
                    {
                        using (Region newRegion = new Region(newBorderRect))
                        {
                            newRegion.Exclude(Rectangle.Inflate(newBorderRect, -BorderSize, -BorderSize));
                            //No reason to get smart about only invalidating part of the border. Thought we could be but no.The reason is the order: ... the new border is drawn (last resize) On next mousemove, the control is resized which redraws the control AND ERASES THE BORDER Then we draw the new border - flash baby.                            Thus this will always flicker.
                            if (needToUpdate)
                            {
                                using (Region oldRegion = new Region(oldBorderRect))
                                {
                                    oldRegion.Exclude(Rectangle.Inflate(oldBorderRect, -BorderSize, -BorderSize));
                                    BehaviorService.Invalidate(oldRegion);
                                }
                            }

                            //draw the new border captureLost could be true if a popup came up and caused a lose focus
                            if (!_captureLost)
                            {
                                using (Graphics graphics = BehaviorService.AdornerWindowGraphics)
                                {
                                    if (_lastResizeRegion != null)
                                    {
                                        if (!_lastResizeRegion.Equals(newRegion, graphics))
                                        {
                                            _lastResizeRegion.Exclude(newRegion);          //we don't want to invalidate this region.
                                            BehaviorService.Invalidate(_lastResizeRegion); //might be the same, might not.
                                            _lastResizeRegion.Dispose();
                                            _lastResizeRegion = null;
                                        }
                                    }
                                    DesignerUtils.DrawResizeBorder(graphics, newRegion, backColor);
                                }
                                if (_lastResizeRegion == null)
                                {
                                    _lastResizeRegion = newRegion.Clone(); //we will need to dispose it later.
                                }
                            }
                        }
                    }
                }
            }

            if ((drawSnapline) && (!altKeyPressed) && (_dragManager != null))
            {
                _dragManager.RenderSnapLinesInternal(targetBorderRect);
            }

            _initialResize = false;
            return(true);
        }
 bool ISelectionUIService.BeginDrag(SelectionRules rules, int initialX, int initialY)
 {
     if (this.dragHandler != null)
     {
         return false;
     }
     if (rules == SelectionRules.None)
     {
         return false;
     }
     if (this.selSvc == null)
     {
         return false;
     }
     this.savedVisible = base.Visible;
     ICollection selectedComponents = this.selSvc.GetSelectedComponents();
     object[] array = new object[selectedComponents.Count];
     selectedComponents.CopyTo(array, 0);
     array = ((ISelectionUIService) this).FilterSelection(array, rules);
     if (array.Length == 0)
     {
         return false;
     }
     ISelectionUIHandler handler = null;
     object primarySelection = this.selSvc.PrimarySelection;
     if (primarySelection != null)
     {
         handler = this.GetHandler(primarySelection);
     }
     if (handler == null)
     {
         return false;
     }
     ArrayList list = new ArrayList();
     for (int i = 0; i < array.Length; i++)
     {
         if ((this.GetHandler(array[i]) == handler) && ((handler.GetComponentRules(array[i]) & rules) == rules))
         {
             list.Add(array[i]);
         }
     }
     if (list.Count == 0)
     {
         return false;
     }
     array = list.ToArray();
     bool flag = false;
     this.dragComponents = array;
     this.dragRules = rules;
     this.dragHandler = handler;
     string transactionName = GetTransactionName(rules, array);
     this.dragTransaction = this.host.CreateTransaction(transactionName);
     try
     {
         if (!handler.QueryBeginDrag(array, rules, initialX, initialY) || (this.dragHandler == null))
         {
             return flag;
         }
         try
         {
             flag = handler.BeginDrag(array, rules, initialX, initialY);
         }
         catch (Exception)
         {
             flag = false;
         }
     }
     finally
     {
         if (!flag)
         {
             this.dragComponents = null;
             this.dragRules = SelectionRules.None;
             this.dragHandler = null;
             if (this.dragTransaction != null)
             {
                 this.dragTransaction.Commit();
                 this.dragTransaction = null;
             }
         }
     }
     return flag;
 }
 object[] ISelectionUIService.FilterSelection(object[] components, SelectionRules selectionRules)
 {
     object[] objArray = null;
     if (components != null)
     {
         if (selectionRules != SelectionRules.None)
         {
             ArrayList list = new ArrayList();
             foreach (object obj2 in components)
             {
                 SelectionUIItem item = (SelectionUIItem) this.selectionItems[obj2];
                 if (((item != null) && !(item is ContainerSelectionUIItem)) && ((item.GetRules() & selectionRules) == selectionRules))
                 {
                     list.Add(obj2);
                 }
             }
             objArray = list.ToArray();
         }
         if (objArray != null)
         {
             return objArray;
         }
     }
     return new object[0];
 }
 public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
 {
     if (button != MouseButtons.Left)
     {
         return this.pushedBehavior;
     }
     this.targetResizeRules = SelectionRules.None;
     SelectionGlyphBase base2 = g as SelectionGlyphBase;
     if (base2 != null)
     {
         this.targetResizeRules = base2.SelectionRules;
         this.cursor = base2.HitTestCursor;
     }
     if (this.targetResizeRules != SelectionRules.None)
     {
         ISelectionService service = (ISelectionService) this.serviceProvider.GetService(typeof(ISelectionService));
         if (service == null)
         {
             return false;
         }
         this.initialPoint = mouseLoc;
         this.lastMouseLoc = mouseLoc;
         this.primaryControl = service.PrimarySelection as Control;
         ArrayList list = new ArrayList();
         foreach (object obj2 in service.GetSelectedComponents())
         {
             if (obj2 is Control)
             {
                 PropertyDescriptor descriptor = TypeDescriptor.GetProperties(obj2)["Locked"];
                 if ((descriptor == null) || !((bool) descriptor.GetValue(obj2)))
                 {
                     list.Add(obj2);
                 }
             }
         }
         if (list.Count == 0)
         {
             return false;
         }
         this.resizeComponents = new ResizeComponent[list.Count];
         for (int i = 0; i < list.Count; i++)
         {
             this.resizeComponents[i].resizeControl = list[i];
         }
         this.pushedBehavior = true;
         this.BehaviorService.PushCaptureBehavior(this);
     }
     return false;
 }
Пример #48
0
        public bool DoBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
        {
            // if we're in a sizing operation, or the mouse isn't down, don't do this!
            if ((rules & SelectionRules.AllSizeable) != SelectionRules.None || Control.MouseButtons == MouseButtons.None)
            {
                return(true);
            }

            Control c = client.GetDesignerControl();

            localDrag       = true;
            localDragInside = false;

            dragComps       = components;
            dragBase        = new Point(initialX, initialY);
            localDragOffset = Point.Empty;
            c.PointToClient(new Point(initialX, initialY));

            DragDropEffects allowedEffects = DragDropEffects.Copy | DragDropEffects.None | DragDropEffects.Move;

            // check to see if any of the components are inherhited. if so, don't allow them to be moved.
            // We replace DragDropEffects.Move with a local bit called AllowLocalMoveOnly which means it
            // can be moved around on the current dropsource/target, but not to another target.  Since only
            // we understand this bit, other drop targets will not allow the move to occur
            //
            for (int i = 0; i < components.Length; i++)
            {
                InheritanceAttribute attr = (InheritanceAttribute)TypeDescriptor.GetAttributes(components[i])[typeof(InheritanceAttribute)];

                if (!attr.Equals(InheritanceAttribute.NotInherited) && !attr.Equals(InheritanceAttribute.InheritedReadOnly))
                {
                    allowedEffects &= ~DragDropEffects.Move;
                    allowedEffects |= (DragDropEffects)AllowLocalMoveOnly;
                }
            }

            DataObject data = new ComponentDataObjectWrapper(new ComponentDataObject(client, serviceProvider, components, initialX, initialY));

            // We make sure we're painted before we start the drag.  Then, we disable window painting to
            // ensure that the drag can proceed without leaving artifacts lying around.  We should be caling LockWindowUpdate,
            // but that causes a horrible flashing because GDI+ uses direct draw.
            //
            User32.MSG msg = default;
            while (User32.PeekMessageW(ref msg, IntPtr.Zero, User32.WM.PAINT, User32.WM.PAINT, User32.PM.REMOVE).IsTrue())
            {
                User32.TranslateMessage(ref msg);
                User32.DispatchMessageW(ref msg);
            }

            // don't do any new painting...
            bool oldFreezePainting = freezePainting;

            // asurt 90345 -- this causes some subtle bugs, so i'm turning it off to see if we really need it, and if we do
            // if we can find a better way.
            //
            //freezePainting = true;

            AddCurrentDrag(data, client.Component);

            // Walk through all the children recursively and disable drag-drop
            // for each of them. This way, we will not accidentally try to drop
            // ourselves into our own children.
            //
            ArrayList allowDropChanged = new ArrayList();

            foreach (object comp in components)
            {
                Control ctl = comp as Control;
                if (ctl != null && ctl.HasChildren)
                {
                    DisableDragDropChildren(ctl.Controls, allowDropChanged);
                }
            }

            DragDropEffects     effect = DragDropEffects.None;
            IDesignerHost       host   = GetService(typeof(IDesignerHost)) as IDesignerHost;
            DesignerTransaction trans  = null;

            if (host != null)
            {
                trans = host.CreateTransaction(string.Format(SR.DragDropDragComponents, components.Length));
            }

            try
            {
                effect = c.DoDragDrop(data, allowedEffects);
                if (trans != null)
                {
                    trans.Commit();
                }
            }
            finally
            {
                RemoveCurrentDrag(data);

                // Reset the AllowDrop for the components being dragged.
                //
                foreach (Control ctl in allowDropChanged)
                {
                    ctl.AllowDrop = true;
                }

                freezePainting = oldFreezePainting;

                if (trans != null)
                {
                    ((IDisposable)trans).Dispose();
                }
            }

            bool isMove = (effect & DragDropEffects.Move) != 0 || ((int)effect & AllowLocalMoveOnly) != 0;

            // since the EndDrag will clear this
            bool isLocalMove = isMove && localDragInside;

            ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService));

            Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control");

            if (selectionUISvc != null)
            {
                // We must check to ensure that UI service is still in drag mode.  It is
                // possible that the user hit escape, which will cancel drag mode.
                //
                if (selectionUISvc.Dragging)
                {
                    // cancel the drag if we aren't doing a local move
                    selectionUISvc.EndDrag(!isLocalMove);
                }
            }

            if (!localDragOffset.IsEmpty && effect != DragDropEffects.None)
            {
                DrawDragFrames(dragComps, localDragOffset, localDragEffect,
                               Point.Empty, DragDropEffects.None, false);
            }

            localDragOffset = Point.Empty;
            dragComps       = null;
            localDrag       = localDragInside = false;
            dragBase        = Point.Empty;

            /*if (!isLocalMove && isMove){
             *  IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
             *  IUndoService  undoService = (IUndoService)GetService(typeof(IUndoService));
             *  IActionUnit unit = null;
             *
             *  if (host != null) {
             *      DesignerTransaction trans = host.CreateTransaction("Drag/drop");
             *      try{
             *          // delete the components
             *          try{
             *              for (int i = 0; i < components.Length; i++){
             *                 if (components[i] is IComponent){
             *                    if (undoService != null){
             *                        unit = new CreateControlActionUnit(host, (IComponent)components[i], true);
             *                    }
             *                    host.DestroyComponent((IComponent)components[i]);
             *                    if (undoService != null){
             *                         undoService.AddAction(unit, false);
             *                    }
             *                 }
             *              }
             *          }catch(CheckoutException ex){
             *              if (ex != CheckoutException.Canceled){
             *                  throw ex;
             *              }
             *          }
             *      }
             *      finally{
             *          trans.Commit();
             *      }
             *  }
             * }*/

            return(false);
        }
 public override bool BeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
 {
     bool flag = base.BeginDrag(components, rules, initialX, initialY);
     this.tray.SuspendLayout();
     return flag;
 }
 private SnapLine[] GenerateSnapLines(SelectionRules rules, Point loc)
 {
     ArrayList list = new ArrayList(2);
     if ((rules & SelectionRules.BottomSizeable) != SelectionRules.None)
     {
         list.Add(new SnapLine(SnapLineType.Bottom, loc.Y - 1));
         if (this.primaryControl != null)
         {
             list.Add(new SnapLine(SnapLineType.Horizontal, loc.Y + this.primaryControl.Margin.Bottom, "Margin.Bottom", SnapLinePriority.Always));
         }
     }
     else if ((rules & SelectionRules.TopSizeable) != SelectionRules.None)
     {
         list.Add(new SnapLine(SnapLineType.Top, loc.Y));
         if (this.primaryControl != null)
         {
             list.Add(new SnapLine(SnapLineType.Horizontal, loc.Y - this.primaryControl.Margin.Top, "Margin.Top", SnapLinePriority.Always));
         }
     }
     if ((rules & SelectionRules.RightSizeable) != SelectionRules.None)
     {
         list.Add(new SnapLine(SnapLineType.Right, loc.X - 1));
         if (this.primaryControl != null)
         {
             list.Add(new SnapLine(SnapLineType.Vertical, loc.X + this.primaryControl.Margin.Right, "Margin.Right", SnapLinePriority.Always));
         }
     }
     else if ((rules & SelectionRules.LeftSizeable) != SelectionRules.None)
     {
         list.Add(new SnapLine(SnapLineType.Left, loc.X));
         if (this.primaryControl != null)
         {
             list.Add(new SnapLine(SnapLineType.Vertical, loc.X - this.primaryControl.Margin.Left, "Margin.Left", SnapLinePriority.Always));
         }
     }
     SnapLine[] array = new SnapLine[list.Count];
     list.CopyTo(array);
     return array;
 }
 bool ISelectionUIHandler.BeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
 {
     if (this.TabOrderActive)
     {
         return false;
     }
     bool flag = this.DragHandler.BeginDrag(components, rules, initialX, initialY);
     if (flag && !this.GetOleDragHandler().DoBeginDrag(components, rules, initialX, initialY))
     {
         return false;
     }
     return flag;
 }