public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc == null)
         {
             return(value);
         }
         if (this.selector == null)
         {
             this.selector = new Selector(this);
             DesignerUtils.ApplyTreeViewThemeStyles(this.selector);
         }
         this.prevValue = value;
         this.currValue = value;
         this.FillTreeWithData(this.selector, context, provider);
         this.selector.Start(edSvc, value);
         edSvc.DropDownControl(this.selector);
         this.selector.Stop();
         if (this.prevValue != this.currValue)
         {
             value = this.currValue;
         }
     }
     return(value);
 }
Beispiel #2
0
        internal void Invalidate()
        {
            IComponent relatedComponent = ((DesignerActionBehavior)this.Behavior).RelatedComponent;
            Point      empty            = Point.Empty;
            Control    c = relatedComponent as Control;

            if (((c != null) && !(relatedComponent is ToolStripDropDown)) && (this.adorner != null))
            {
                empty    = this.adorner.BehaviorService.ControlToAdornerWindow(c);
                empty.X += c.Width;
            }
            else
            {
                ComponentTray alternativeParent = this.alternativeParent as ComponentTray;
                if (alternativeParent != null)
                {
                    ComponentTray.TrayControl trayControlFromComponent = alternativeParent.GetTrayControlFromComponent(relatedComponent);
                    if (trayControlFromComponent != null)
                    {
                        this.alternativeBounds = trayControlFromComponent.Bounds;
                    }
                }
                Rectangle boundsForNoResizeSelectionType = DesignerUtils.GetBoundsForNoResizeSelectionType(this.alternativeBounds, SelectionBorderGlyphType.Top);
                empty.X = boundsForNoResizeSelectionType.Right;
                empty.Y = boundsForNoResizeSelectionType.Top;
            }
            empty.X    -= this.GlyphImageOpened.Width + 5;
            empty.Y    -= this.GlyphImageOpened.Height - 2;
            this.bounds = new Rectangle(empty.X, empty.Y, this.GlyphImageOpened.Width, this.GlyphImageOpened.Height);
        }
        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;
            }
        }
Beispiel #4
0
 private void InitializeGlyph(Rectangle controlBounds, SelectionBorderGlyphType type)
 {
     base.hitTestCursor = Cursors.Default;
     base.rules         = SelectionRules.None;
     base.bounds        = DesignerUtils.GetBoundsForSelectionType(controlBounds, type);
     base.hitBounds     = base.bounds;
 }
Beispiel #5
0
        /// <summary>
        /// Helper function that initializes the Glyph based on bounds, type, primary sel, and bordersize.
        /// </summary>
        private void InitializeGlyph(Rectangle controlBounds, SelectionBorderGlyphType type)
        {
            hitTestCursor = Cursors.Default;     // always default cursor for locked
            rules         = SelectionRules.None; // never change sel rules for locked

            // this will return the rect representing the bounds of the glyph
            bounds    = DesignerUtils.GetBoundsForSelectionType(controlBounds, type);
            hitBounds = bounds;
        }
        /// <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;
            }
        }
        private void InitializeGlyph(Rectangle controlBounds, SelectionBorderGlyphType type, bool primarySelection)
        {
            base.hitTestCursor = Cursors.Default;
            base.rules         = SelectionRules.None;
            int borderSize = 1;

            this.type      = type;
            base.bounds    = DesignerUtils.GetBoundsForSelectionType(controlBounds, type, borderSize);
            base.hitBounds = base.bounds;
        }
Beispiel #8
0
        /// <summary>
        /// 取得容器中线段数
        /// </summary>
        /// <returns></returns>
        private int GetLineIdentityNo()
        {
            int        iNo   = 0;
            List <int> lstNo = new List <int>();

            for (int i = 0; i < this.Elements.Count; i++)
            {
                if (((IControlBase)this.Elements[i]).Type == ElementType.Line)
                {
                    if (((IControlBase)this.Elements[i]).Title.IndexOf("新建连线") != -1)
                    {
                        Int32.TryParse(((IControlBase)this.Elements[i]).Title.Substring(("新建连线").Length), out iNo);
                        if (iNo != 0)
                        {
                            lstNo.Add(iNo);
                        }
                    }
                }
            }
            return(DesignerUtils.GetIdentityNo(lstNo));
        }
Beispiel #9
0
 public override void Paint(PaintEventArgs pe)
 {
     DesignerUtils.DrawSelectionBorder(pe.Graphics, bounds);
 }
 public override void Paint(PaintEventArgs pe)
 {
     DesignerUtils.DrawLockedHandle(pe.Graphics, base.bounds, this.isPrimary, this);
 }
Beispiel #11
0
        private void InitiateDrag(Point initialMouseLocation, ICollection dragComps)
        {
            this.dragObjects = new ArrayList(dragComps);
            this.DisableAdorners(this.serviceProviderSource, this.behaviorServiceSource, false);
            Control control   = this.dragObjects[0] as Control;
            Control control2  = (control != null) ? control.Parent : null;
            Color   backColor = (control2 != null) ? control2.BackColor : Color.Empty;

            this.dragImageRect      = Rectangle.Empty;
            this.clearDragImageRect = Rectangle.Empty;
            this.initialMouseLoc    = initialMouseLocation;
            for (int i = 0; i < this.dragObjects.Count; i++)
            {
                Control c = (Control)this.dragObjects[i];
                this.dragComponents[i].dragComponent  = this.dragObjects[i];
                this.dragComponents[i].positionOffset = new Point(c.Location.X - control.Location.X, c.Location.Y - control.Location.Y);
                Rectangle rect = this.behaviorServiceSource.ControlRectInAdornerWindow(c);
                if (this.dragImageRect.IsEmpty)
                {
                    this.dragImageRect   = rect;
                    this.dragImageRegion = new Region(rect);
                }
                else
                {
                    this.dragImageRect = Rectangle.Union(this.dragImageRect, rect);
                    this.dragImageRegion.Union(rect);
                }
                this.dragComponents[i].draggedLocation         = rect.Location;
                this.dragComponents[i].originalControlLocation = this.dragComponents[i].draggedLocation;
                DesignerUtils.GenerateSnapShot(c, ref this.dragComponents[i].dragImage, (i == 0) ? 2 : 1, 1.0, backColor);
                if ((control2 != null) && this.shareParent)
                {
                    this.dragComponents[i].zorderIndex = control2.Controls.GetChildIndex(c, false);
                    if (this.dragComponents[i].zorderIndex == -1)
                    {
                        this.shareParent = false;
                    }
                }
            }
            if (this.shareParent)
            {
                Array.Sort(this.dragComponents, this);
            }
            for (int j = 0; j < this.dragComponents.Length; j++)
            {
                if (control.Equals(this.dragComponents[j].dragComponent as Control))
                {
                    this.primaryComponentIndex = j;
                    break;
                }
            }
            if (control2 != null)
            {
                this.suspendedParent = control2;
                this.suspendedParent.SuspendLayout();
                this.GetParentSnapInfo(this.suspendedParent, this.behaviorServiceSource);
            }
            int width = this.dragImageRect.Width;

            if (width == 0)
            {
                width = 1;
            }
            int height = this.dragImageRect.Height;

            if (height == 0)
            {
                height = 1;
            }
            this.dragImage = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
            using (Graphics graphics = Graphics.FromImage(this.dragImage))
            {
                graphics.Clear(Color.Chartreuse);
            }
            ((Bitmap)this.dragImage).MakeTransparent(Color.Chartreuse);
            using (Graphics graphics2 = Graphics.FromImage(this.dragImage))
            {
                using (SolidBrush brush = new SolidBrush(control.BackColor))
                {
                    for (int k = 0; k < this.dragComponents.Length; k++)
                    {
                        Rectangle rectangle2 = new Rectangle(this.dragComponents[k].draggedLocation.X - this.dragImageRect.X, this.dragComponents[k].draggedLocation.Y - this.dragImageRect.Y, this.dragComponents[k].dragImage.Width, this.dragComponents[k].dragImage.Height);
                        graphics2.FillRectangle(brush, rectangle2);
                        graphics2.DrawImage(this.dragComponents[k].dragImage, rectangle2, new Rectangle(0, 0, this.dragComponents[k].dragImage.Width, this.dragComponents[k].dragImage.Height), GraphicsUnit.Pixel);
                    }
                }
            }
            this.originalDragImageLocation = new Point(this.dragImageRect.X, this.dragImageRect.Y);
            this.ShowHideDragControls(false);
            this.cleanedUpDrag = false;
        }
Beispiel #12
0
        private void EndDragDrop(bool allowSetChildIndexOnDrop)
        {
            Control target = this.data.Target as Control;

            if (target != null)
            {
                if (this.serviceProviderTarget == null)
                {
                    this.serviceProviderTarget = target.Site;
                    if (this.serviceProviderTarget == null)
                    {
                        return;
                    }
                }
                if (this.destHost == null)
                {
                    this.destHost = (IDesignerHost)this.serviceProviderTarget.GetService(typeof(IDesignerHost));
                    if (this.destHost == null)
                    {
                        return;
                    }
                }
                if (this.behaviorServiceTarget == null)
                {
                    this.behaviorServiceTarget = (BehaviorService)this.serviceProviderTarget.GetService(typeof(BehaviorService));
                    if (this.behaviorServiceTarget == null)
                    {
                        return;
                    }
                }
                ArrayList               list        = null;
                bool                    flag        = this.lastEffect == DragDropEffects.Copy;
                Control                 source      = this.data.Source;
                bool                    localDrag   = source.Equals(target);
                PropertyDescriptor      member      = TypeDescriptor.GetProperties(target)["Controls"];
                PropertyDescriptor      descriptor2 = TypeDescriptor.GetProperties(source)["Controls"];
                IComponentChangeService service     = (IComponentChangeService)this.serviceProviderSource.GetService(typeof(IComponentChangeService));
                IComponentChangeService service2    = (IComponentChangeService)this.serviceProviderTarget.GetService(typeof(IComponentChangeService));
                if (this.dragAssistanceManager != null)
                {
                    this.dragAssistanceManager.OnMouseUp();
                }
                ISelectionService service3 = null;
                if (flag || ((this.srcHost != this.destHost) && (this.destHost != null)))
                {
                    service3 = (ISelectionService)this.serviceProviderTarget.GetService(typeof(ISelectionService));
                }
                try
                {
                    if ((this.dragComponents != null) && (this.dragComponents.Length > 0))
                    {
                        string str;
                        DesignerTransaction transaction  = null;
                        DesignerTransaction transaction2 = null;
                        if (this.dragComponents.Length == 1)
                        {
                            string componentName = TypeDescriptor.GetComponentName(this.dragComponents[0].dragComponent);
                            if ((componentName == null) || (componentName.Length == 0))
                            {
                                componentName = this.dragComponents[0].dragComponent.GetType().Name;
                            }
                            str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControl" : "BehaviorServiceMoveControl", new object[] { componentName });
                        }
                        else
                        {
                            str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControls" : "BehaviorServiceMoveControls", new object[] { this.dragComponents.Length });
                        }
                        if ((this.srcHost != null) && (((this.srcHost == this.destHost) || (this.destHost == null)) || !flag))
                        {
                            transaction = this.srcHost.CreateTransaction(str);
                        }
                        if ((this.srcHost != this.destHost) && (this.destHost != null))
                        {
                            transaction2 = this.destHost.CreateTransaction(str);
                        }
                        try
                        {
                            ComponentTray tray = null;
                            int           num  = 0;
                            if (flag)
                            {
                                tray = this.serviceProviderTarget.GetService(typeof(ComponentTray)) as ComponentTray;
                                num  = (tray != null) ? tray.Controls.Count : 0;
                                ArrayList objects = new ArrayList();
                                for (int j = 0; j < this.dragComponents.Length; j++)
                                {
                                    objects.Add(this.dragComponents[j].dragComponent);
                                }
                                objects = DesignerUtils.CopyDragObjects(objects, this.serviceProviderTarget) as ArrayList;
                                if (objects == null)
                                {
                                    return;
                                }
                                list = new ArrayList();
                                for (int k = 0; k < objects.Count; k++)
                                {
                                    list.Add(this.dragComponents[k].dragComponent);
                                    this.dragComponents[k].dragComponent = objects[k];
                                }
                            }
                            if ((!localDrag || flag) && ((service != null) && (service2 != null)))
                            {
                                service2.OnComponentChanging(target, member);
                                if (!flag)
                                {
                                    service.OnComponentChanging(source, descriptor2);
                                }
                            }
                            int num4 = ParentControlDesigner.DetermineTopChildIndex(target);
                            this.DropControl(this.primaryComponentIndex, target, source, localDrag);
                            Point p = this.behaviorServiceSource.AdornerWindowPointToScreen(this.dragComponents[this.primaryComponentIndex].draggedLocation);
                            p = ((Control)this.dragComponents[this.primaryComponentIndex].dragComponent).Parent.PointToClient(p);
                            if (((Control)this.dragComponents[this.primaryComponentIndex].dragComponent).Parent.IsMirrored)
                            {
                                p.Offset(-((Control)this.dragComponents[this.primaryComponentIndex].dragComponent).Width, 0);
                            }
                            Control            dragComponent = this.dragComponents[this.primaryComponentIndex].dragComponent as Control;
                            PropertyDescriptor descriptor3   = TypeDescriptor.GetProperties(dragComponent)["Location"];
                            if ((dragComponent != null) && (descriptor3 != null))
                            {
                                try
                                {
                                    service2.OnComponentChanging(dragComponent, descriptor3);
                                }
                                catch (CheckoutException exception)
                                {
                                    if (exception != CheckoutException.Canceled)
                                    {
                                        throw;
                                    }
                                    return;
                                }
                            }
                            this.SetLocationPropertyAndChildIndex(this.primaryComponentIndex, target, p, this.shareParent ? (num4 + this.dragComponents[this.primaryComponentIndex].zorderIndex) : num4, allowSetChildIndexOnDrop);
                            if (service3 != null)
                            {
                                service3.SetSelectedComponents(new object[] { this.dragComponents[this.primaryComponentIndex].dragComponent }, SelectionTypes.Click | SelectionTypes.Replace);
                            }
                            for (int i = 0; i < this.dragComponents.Length; i++)
                            {
                                if (i != this.primaryComponentIndex)
                                {
                                    this.DropControl(i, target, source, localDrag);
                                    Point dropPoint = new Point(p.X + this.dragComponents[i].positionOffset.X, p.Y + this.dragComponents[i].positionOffset.Y);
                                    this.SetLocationPropertyAndChildIndex(i, target, dropPoint, this.shareParent ? (num4 + this.dragComponents[i].zorderIndex) : num4, allowSetChildIndexOnDrop);
                                    if (service3 != null)
                                    {
                                        service3.SetSelectedComponents(new object[] { this.dragComponents[i].dragComponent }, SelectionTypes.Add);
                                    }
                                }
                            }
                            if ((!localDrag || flag) && ((service != null) && (service2 != null)))
                            {
                                service2.OnComponentChanged(target, member, target.Controls, target.Controls);
                                if (!flag)
                                {
                                    service.OnComponentChanged(source, descriptor2, source.Controls, source.Controls);
                                }
                            }
                            if (list != null)
                            {
                                for (int m = 0; m < list.Count; m++)
                                {
                                    this.dragComponents[m].dragComponent = list[m];
                                }
                                list = null;
                            }
                            if (flag)
                            {
                                if (tray == null)
                                {
                                    tray = this.serviceProviderTarget.GetService(typeof(ComponentTray)) as ComponentTray;
                                }
                                if (tray != null)
                                {
                                    int num7 = tray.Controls.Count - num;
                                    if (num7 > 0)
                                    {
                                        ArrayList components = new ArrayList();
                                        for (int n = 0; n < num7; n++)
                                        {
                                            components.Add(tray.Controls[num + n]);
                                        }
                                        tray.UpdatePastePositions(components);
                                    }
                                }
                            }
                            this.CleanupDrag(false);
                            if (transaction != null)
                            {
                                transaction.Commit();
                                transaction = null;
                            }
                            if (transaction2 != null)
                            {
                                transaction2.Commit();
                                transaction2 = null;
                            }
                        }
                        finally
                        {
                            if (transaction != null)
                            {
                                transaction.Cancel();
                            }
                            if (transaction2 != null)
                            {
                                transaction2.Cancel();
                            }
                        }
                    }
                }
                finally
                {
                    if (list != null)
                    {
                        for (int num9 = 0; num9 < list.Count; num9++)
                        {
                            this.dragComponents[num9].dragComponent = list[num9];
                        }
                    }
                    this.CleanupDrag(false);
                    if (this.statusCommandUITarget != null)
                    {
                        this.statusCommandUITarget.SetStatusInformation((service3 == null) ? (this.dragComponents[this.primaryComponentIndex].dragComponent as Component) : (service3.PrimarySelection as Component));
                    }
                }
                this.lastFeedbackLocation = new Point(-1, -1);
            }
        }
        private void ReParentControls(ArrayList controls, bool copy)
        {
            IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if ((host != null) && (controls.Count > 0))
            {
                string str;
                if ((controls.Count == 1) && (controls[0] is ToolStrip))
                {
                    string componentName = TypeDescriptor.GetComponentName(controls[0]);
                    if ((componentName == null) || (componentName.Length == 0))
                    {
                        componentName = controls[0].GetType().Name;
                    }
                    str = System.Design.SR.GetString(copy ? "BehaviorServiceCopyControl" : "BehaviorServiceMoveControl", new object[] { componentName });
                }
                else
                {
                    str = System.Design.SR.GetString(copy ? "BehaviorServiceCopyControls" : "BehaviorServiceMoveControls", new object[] { controls.Count });
                }
                DesignerTransaction transaction = host.CreateTransaction(str);
                try
                {
                    ArrayList         objects = null;
                    ISelectionService service = (ISelectionService)this.serviceProvider.GetService(typeof(ISelectionService));
                    if (copy)
                    {
                        objects = new ArrayList();
                        service = (ISelectionService)this.serviceProvider.GetService(typeof(ISelectionService));
                    }
                    for (int i = 0; i < controls.Count; i++)
                    {
                        Control control = controls[i] as Control;
                        if (control is ToolStrip)
                        {
                            if (copy)
                            {
                                objects.Clear();
                                objects.Add(control);
                                objects = DesignerUtils.CopyDragObjects(objects, this.serviceProvider) as ArrayList;
                                if (objects != null)
                                {
                                    control         = objects[0] as Control;
                                    control.Visible = true;
                                }
                            }
                            Control relatedControl           = this.relatedControl;
                            IComponentChangeService service2 = this.serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                            PropertyDescriptor      member   = TypeDescriptor.GetProperties(relatedControl)["Controls"];
                            Control parent = control.Parent;
                            if ((parent != null) && !copy)
                            {
                                if (service2 != null)
                                {
                                    service2.OnComponentChanging(parent, member);
                                }
                                parent.Controls.Remove(control);
                            }
                            if (service2 != null)
                            {
                                service2.OnComponentChanging(relatedControl, member);
                            }
                            relatedControl.Controls.Add(control);
                            if (((service2 != null) && (parent != null)) && !copy)
                            {
                                service2.OnComponentChanged(parent, member, null, null);
                            }
                            if (service2 != null)
                            {
                                service2.OnComponentChanged(relatedControl, member, null, null);
                            }
                            if (service != null)
                            {
                                service.SetSelectedComponents(new object[] { control }, (i == 0) ? (SelectionTypes.Click | SelectionTypes.Replace) : SelectionTypes.Add);
                            }
                        }
                    }
                }
                catch
                {
                    if (transaction != null)
                    {
                        transaction.Cancel();
                        transaction = null;
                    }
                }
                finally
                {
                    if (transaction != null)
                    {
                        transaction.Commit();
                        transaction = null;
                    }
                }
            }
        }
Beispiel #14
0
        public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc)
        {
            if (!this.pushedBehavior)
            {
                return(false);
            }
            bool flag = Control.ModifierKeys == Keys.Alt;

            if (flag && (this.dragManager != null))
            {
                this.dragManager.EraseSnapLines();
            }
            if (flag || !mouseLoc.Equals(this.lastMouseLoc))
            {
                if (this.lastMouseAbs != null)
                {
                    System.Design.NativeMethods.POINT pt = new System.Design.NativeMethods.POINT(mouseLoc.X, mouseLoc.Y);
                    System.Design.UnsafeNativeMethods.ClientToScreen(new HandleRef(this, this.behaviorService.AdornerWindowControl.Handle), pt);
                    if ((pt.x == this.lastMouseAbs.x) && (pt.y == this.lastMouseAbs.y))
                    {
                        return(true);
                    }
                }
                if (!this.dragging)
                {
                    if ((Math.Abs((int)(this.initialPoint.X - mouseLoc.X)) <= (DesignerUtils.MinDragSize.Width / 2)) && (Math.Abs((int)(this.initialPoint.Y - mouseLoc.Y)) <= (DesignerUtils.MinDragSize.Height / 2)))
                    {
                        return(false);
                    }
                    this.InitiateResize();
                    this.dragging = true;
                }
                if ((this.resizeComponents == null) || (this.resizeComponents.Length == 0))
                {
                    return(false);
                }
                PropertyDescriptor descriptor  = null;
                PropertyDescriptor descriptor2 = null;
                PropertyDescriptor descriptor3 = null;
                PropertyDescriptor descriptor4 = null;
                if (this.initialResize)
                {
                    descriptor  = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Width"];
                    descriptor2 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Height"];
                    descriptor3 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Top"];
                    descriptor4 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Left"];
                    if ((descriptor != null) && !typeof(int).IsAssignableFrom(descriptor.PropertyType))
                    {
                        descriptor = null;
                    }
                    if ((descriptor2 != null) && !typeof(int).IsAssignableFrom(descriptor2.PropertyType))
                    {
                        descriptor2 = null;
                    }
                    if ((descriptor3 != null) && !typeof(int).IsAssignableFrom(descriptor3.PropertyType))
                    {
                        descriptor3 = null;
                    }
                    if ((descriptor4 != null) && !typeof(int).IsAssignableFrom(descriptor4.PropertyType))
                    {
                        descriptor4 = null;
                    }
                }
                Control resizeControl = this.resizeComponents[0].resizeControl as Control;
                this.lastMouseLoc = mouseLoc;
                this.lastMouseAbs = new System.Design.NativeMethods.POINT(mouseLoc.X, mouseLoc.Y);
                System.Design.UnsafeNativeMethods.ClientToScreen(new HandleRef(this, this.behaviorService.AdornerWindowControl.Handle), this.lastMouseAbs);
                int num  = Math.Max(resizeControl.MinimumSize.Height, 10);
                int num2 = Math.Max(resizeControl.MinimumSize.Width, 10);
                if (this.dragManager != null)
                {
                    bool flag2 = true;
                    bool shouldSnapHorizontally = true;
                    if ((((this.targetResizeRules & SelectionRules.BottomSizeable) != SelectionRules.None) || ((this.targetResizeRules & SelectionRules.TopSizeable) != SelectionRules.None)) && (resizeControl.Height == num))
                    {
                        flag2 = false;
                    }
                    else if ((((this.targetResizeRules & SelectionRules.RightSizeable) != SelectionRules.None) || ((this.targetResizeRules & SelectionRules.LeftSizeable) != SelectionRules.None)) && (resizeControl.Width == num2))
                    {
                        flag2 = false;
                    }
                    PropertyDescriptor descriptor5 = TypeDescriptor.GetProperties(resizeControl)["IntegralHeight"];
                    if (descriptor5 != null)
                    {
                        object obj2 = descriptor5.GetValue(resizeControl);
                        if ((obj2 is bool) && ((bool)obj2))
                        {
                            shouldSnapHorizontally = false;
                        }
                    }
                    if (!flag && flag2)
                    {
                        this.lastSnapOffset = this.dragManager.OnMouseMove(resizeControl, this.GenerateSnapLines(this.targetResizeRules, mouseLoc), ref this.didSnap, shouldSnapHorizontally);
                    }
                    else
                    {
                        this.dragManager.OnMouseMove(new Rectangle(-100, -100, 0, 0));
                    }
                    mouseLoc.X += this.lastSnapOffset.X;
                    mouseLoc.Y += this.lastSnapOffset.Y;
                }
                Rectangle rectangle = new Rectangle(this.resizeComponents[0].resizeBounds.X, this.resizeComponents[0].resizeBounds.Y, this.resizeComponents[0].resizeBounds.Width, this.resizeComponents[0].resizeBounds.Height);
                if (this.didSnap && (resizeControl.Parent != null))
                {
                    rectangle.Location = this.behaviorService.MapAdornerWindowPoint(resizeControl.Parent.Handle, rectangle.Location);
                    if (resizeControl.Parent.IsMirrored)
                    {
                        rectangle.Offset(-rectangle.Width, 0);
                    }
                }
                Rectangle empty     = Rectangle.Empty;
                Rectangle dragRect  = Rectangle.Empty;
                bool      flag4     = true;
                Color     backColor = (resizeControl.Parent != null) ? resizeControl.Parent.BackColor : Color.Empty;
                for (int i = 0; i < this.resizeComponents.Length; i++)
                {
                    Control   c            = this.resizeComponents[i].resizeControl as Control;
                    Rectangle bounds       = c.Bounds;
                    Rectangle rc           = bounds;
                    Rectangle resizeBounds = this.resizeComponents[i].resizeBounds;
                    Rectangle rect         = this.BehaviorService.ControlRectInAdornerWindow(c);
                    bool      flag5        = true;
                    System.Design.UnsafeNativeMethods.SendMessage(c.Handle, 11, false, 0);
                    try
                    {
                        bool flag6 = false;
                        if ((c.Parent != null) && c.Parent.IsMirrored)
                        {
                            flag6 = true;
                        }
                        BoundsSpecified none        = BoundsSpecified.None;
                        SelectionRules  resizeRules = this.resizeComponents[i].resizeRules;
                        if (((this.targetResizeRules & SelectionRules.BottomSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.BottomSizeable) != SelectionRules.None))
                        {
                            int num4;
                            if (this.didSnap)
                            {
                                num4 = mouseLoc.Y - rectangle.Bottom;
                            }
                            else
                            {
                                num4 = AdjustPixelsForIntegralHeight(c, mouseLoc.Y - this.initialPoint.Y);
                            }
                            bounds.Height = Math.Max(num, resizeBounds.Height + num4);
                            none         |= BoundsSpecified.Height;
                        }
                        if (((this.targetResizeRules & SelectionRules.TopSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.TopSizeable) != SelectionRules.None))
                        {
                            int num5;
                            if (this.didSnap)
                            {
                                num5 = rectangle.Y - mouseLoc.Y;
                            }
                            else
                            {
                                num5 = AdjustPixelsForIntegralHeight(c, this.initialPoint.Y - mouseLoc.Y);
                            }
                            none         |= BoundsSpecified.Height;
                            bounds.Height = Math.Max(num, resizeBounds.Height + num5);
                            if ((bounds.Height != num) || ((bounds.Height == num) && (rc.Height != num)))
                            {
                                none    |= BoundsSpecified.Y;
                                bounds.Y = Math.Min((int)(resizeBounds.Bottom - num), (int)(resizeBounds.Y - num5));
                            }
                        }
                        if (((((this.targetResizeRules & SelectionRules.RightSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.RightSizeable) != SelectionRules.None)) && !flag6) || ((((this.targetResizeRules & SelectionRules.LeftSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.LeftSizeable) != SelectionRules.None)) && flag6))
                        {
                            none |= BoundsSpecified.Width;
                            int x = this.initialPoint.X;
                            if (this.didSnap)
                            {
                                x = !flag6 ? rectangle.Right : rectangle.Left;
                            }
                            bounds.Width = Math.Max(num2, resizeBounds.Width + (!flag6 ? (mouseLoc.X - x) : (x - mouseLoc.X)));
                        }
                        if (((((this.targetResizeRules & SelectionRules.RightSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.RightSizeable) != SelectionRules.None)) && flag6) || ((((this.targetResizeRules & SelectionRules.LeftSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.LeftSizeable) != SelectionRules.None)) && !flag6))
                        {
                            none |= BoundsSpecified.Width;
                            int num7 = this.initialPoint.X;
                            if (this.didSnap)
                            {
                                num7 = !flag6 ? rectangle.Left : rectangle.Right;
                            }
                            int num8 = !flag6 ? (num7 - mouseLoc.X) : (mouseLoc.X - num7);
                            bounds.Width = Math.Max(num2, resizeBounds.Width + num8);
                            if ((bounds.Width != num2) || ((bounds.Width == num2) && (rc.Width != num2)))
                            {
                                none    |= BoundsSpecified.X;
                                bounds.X = Math.Min((int)(resizeBounds.Right - num2), (int)(resizeBounds.X - num8));
                            }
                        }
                        if (!this.parentGridSize.IsEmpty)
                        {
                            bounds = this.AdjustToGrid(bounds, this.targetResizeRules);
                        }
                        if ((((none & BoundsSpecified.Width) == BoundsSpecified.Width) && this.dragging) && (this.initialResize && (descriptor != null)))
                        {
                            descriptor.SetValue(this.resizeComponents[i].resizeControl, bounds.Width);
                        }
                        if ((((none & BoundsSpecified.Height) == BoundsSpecified.Height) && this.dragging) && (this.initialResize && (descriptor2 != null)))
                        {
                            descriptor2.SetValue(this.resizeComponents[i].resizeControl, bounds.Height);
                        }
                        if ((((none & BoundsSpecified.X) == BoundsSpecified.X) && this.dragging) && (this.initialResize && (descriptor4 != null)))
                        {
                            descriptor4.SetValue(this.resizeComponents[i].resizeControl, bounds.X);
                        }
                        if ((((none & BoundsSpecified.Y) == BoundsSpecified.Y) && this.dragging) && (this.initialResize && (descriptor3 != null)))
                        {
                            descriptor3.SetValue(this.resizeComponents[i].resizeControl, bounds.Y);
                        }
                        if (this.dragging)
                        {
                            c.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height, none);
                            empty = this.BehaviorService.ControlRectInAdornerWindow(c);
                            if (c.Equals(resizeControl))
                            {
                                dragRect = empty;
                            }
                            if (c.Bounds == rc)
                            {
                                flag5 = false;
                            }
                            if (c.Bounds != bounds)
                            {
                                flag4 = false;
                            }
                        }
                        if ((c == this.primaryControl) && (this.statusCommandUI != null))
                        {
                            this.statusCommandUI.SetStatusInformation(c);
                        }
                    }
                    finally
                    {
                        System.Design.UnsafeNativeMethods.SendMessage(c.Handle, 11, true, 0);
                        if (flag5)
                        {
                            Control parent = c.Parent;
                            if (parent != null)
                            {
                                c.Invalidate(true);
                                parent.Invalidate(rc, true);
                                parent.Update();
                            }
                            else
                            {
                                c.Refresh();
                            }
                        }
                        if (!empty.IsEmpty)
                        {
                            using (Region region = new Region(empty))
                            {
                                region.Exclude(Rectangle.Inflate(empty, -2, -2));
                                if (flag5)
                                {
                                    using (Region region2 = new Region(rect))
                                    {
                                        region2.Exclude(Rectangle.Inflate(rect, -2, -2));
                                        this.BehaviorService.Invalidate(region2);
                                    }
                                }
                                if (!this.captureLost)
                                {
                                    using (Graphics graphics = this.BehaviorService.AdornerWindowGraphics)
                                    {
                                        if ((this.lastResizeRegion != null) && !this.lastResizeRegion.Equals(region, graphics))
                                        {
                                            this.lastResizeRegion.Exclude(region);
                                            this.BehaviorService.Invalidate(this.lastResizeRegion);
                                            this.lastResizeRegion.Dispose();
                                            this.lastResizeRegion = null;
                                        }
                                        DesignerUtils.DrawResizeBorder(graphics, region, backColor);
                                    }
                                    if (this.lastResizeRegion == null)
                                    {
                                        this.lastResizeRegion = region.Clone();
                                    }
                                }
                            }
                        }
                    }
                }
                if ((flag4 && !flag) && (this.dragManager != null))
                {
                    this.dragManager.RenderSnapLinesInternal(dragRect);
                }
                this.initialResize = false;
            }
            return(true);
        }
Beispiel #15
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);
        }
Beispiel #16
0
 /// <summary>
 ///  Very simple paint logic.
 /// </summary>
 public override void Paint(PaintEventArgs pe)
 {
     DesignerUtils.DrawGrabHandle(pe.Graphics, bounds, _isPrimary, this);
 }
        public ObjectDataSourceChooseTypePanel(ObjectDataSourceDesigner objectDataSourceDesigner)
        {
            this._objectDataSourceDesigner = objectDataSourceDesigner;
            this._objectDataSource         = (ObjectDataSource)this._objectDataSourceDesigner.Component;
            this.InitializeComponent();
            this.InitializeUI();
            ITypeDiscoveryService service = null;

            if (this._objectDataSource.Site != null)
            {
                service = (ITypeDiscoveryService)this._objectDataSource.Site.GetService(typeof(ITypeDiscoveryService));
            }
            this._discoveryServiceMode = service != null;
            if (this._discoveryServiceMode)
            {
                this._typeNameTextBox.Visible = false;
                this._exampleLabel.Visible    = false;
                Cursor current = Cursor.Current;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    ICollection is2 = DesignerUtils.FilterGenericTypes(service.GetTypes(typeof(object), true));
                    this._typeNameComboBox.BeginUpdate();
                    if (is2 != null)
                    {
                        StringCollection strings = new StringCollection();
                        strings.Add("My.MyApplication");
                        strings.Add("My.MyComputer");
                        strings.Add("My.MyProject");
                        strings.Add("My.MyUser");
                        this._typeItems = new List <TypeItem>(is2.Count);
                        bool flag = false;
                        foreach (System.Type type in is2)
                        {
                            if (!type.IsEnum && !type.IsInterface)
                            {
                                object[] customAttributes = type.GetCustomAttributes(typeof(DataObjectAttribute), true);
                                if ((customAttributes.Length > 0) && ((DataObjectAttribute)customAttributes[0]).IsDataObject)
                                {
                                    this._typeItems.Add(new TypeItem(type, true));
                                    flag = true;
                                }
                                else if (!strings.Contains(type.FullName))
                                {
                                    this._typeItems.Add(new TypeItem(type, false));
                                }
                            }
                        }
                        object showOnlyDataComponentsState = this._objectDataSourceDesigner.ShowOnlyDataComponentsState;
                        if (showOnlyDataComponentsState == null)
                        {
                            this._filterCheckBox.Checked = flag;
                        }
                        else
                        {
                            this._filterCheckBox.Checked = (bool)showOnlyDataComponentsState;
                        }
                        this.UpdateTypeList();
                    }
                }
                finally
                {
                    this._typeNameComboBox.EndUpdate();
                    Cursor.Current = current;
                }
            }
            else
            {
                this._typeNameComboBox.Visible = false;
                this._filterCheckBox.Visible   = false;
            }
            this.TypeName = this._objectDataSource.TypeName;
        }