internal DropSourceBehavior(ICollection dragComponents, Control source, Point initialMouseLocation)
 {
     this.serviceProviderSource = source.Site;
     if (this.serviceProviderSource != null)
     {
         this.behaviorServiceSource = (BehaviorService) this.serviceProviderSource.GetService(typeof(BehaviorService));
         if ((this.behaviorServiceSource != null) && ((dragComponents != null) && (dragComponents.Count > 0)))
         {
             this.srcHost = (IDesignerHost) this.serviceProviderSource.GetService(typeof(IDesignerHost));
             if (this.srcHost != null)
             {
                 this.data = new BehaviorDataObject(dragComponents, source, this);
                 this.allowedEffects = DragDropEffects.Move | DragDropEffects.Copy;
                 this.dragComponents = new DragComponent[dragComponents.Count];
                 this.parentGridSize = Size.Empty;
                 this.lastEffect = DragDropEffects.None;
                 this.lastFeedbackLocation = new Point(-1, -1);
                 this.lastSnapOffset = Point.Empty;
                 this.dragImageRect = Rectangle.Empty;
                 this.clearDragImageRect = Rectangle.Empty;
                 this.InitiateDrag(initialMouseLocation, dragComponents);
             }
         }
     }
 }
 public RibbonPanelGlyph(BehaviorService behaviorService, RibbonTabDesigner designer, RibbonTab tab)
     : base(new RibbonPanelGlyphBehavior(designer, tab))
 {
     _behaviorService = behaviorService;
     _tab = tab;
     size = new Size(60, 16);
 }
 public RibbonQuickAccessToolbarGlyph(BehaviorService behaviorService, RibbonDesigner designer, Ribbon ribbon)
     : base(new RibbonQuickAccessGlyphBehavior(designer, ribbon))
 {
     _behaviorService = behaviorService;
     _componentDesigner = designer;
     _ribbon = ribbon;
 }
Exemple #4
0
 internal DropSourceBehavior(ICollection dragComponents, Control source, Point initialMouseLocation)
 {
     this.serviceProviderSource = source.Site;
     if (this.serviceProviderSource != null)
     {
         this.behaviorServiceSource = (BehaviorService)this.serviceProviderSource.GetService(typeof(BehaviorService));
         if ((this.behaviorServiceSource != null) && ((dragComponents != null) && (dragComponents.Count > 0)))
         {
             this.srcHost = (IDesignerHost)this.serviceProviderSource.GetService(typeof(IDesignerHost));
             if (this.srcHost != null)
             {
                 this.data                 = new BehaviorDataObject(dragComponents, source, this);
                 this.allowedEffects       = DragDropEffects.Move | DragDropEffects.Copy;
                 this.dragComponents       = new DragComponent[dragComponents.Count];
                 this.parentGridSize       = Size.Empty;
                 this.lastEffect           = DragDropEffects.None;
                 this.lastFeedbackLocation = new Point(-1, -1);
                 this.lastSnapOffset       = Point.Empty;
                 this.dragImageRect        = Rectangle.Empty;
                 this.clearDragImageRect   = Rectangle.Empty;
                 this.InitiateDrag(initialMouseLocation, dragComponents);
             }
         }
     }
 }
 public RibbonTabGlyph(BehaviorService behaviorService, RibbonDesigner designer, Controls.Ribbon.Ribbon ribbon)
     : base(new RibbonTabGlyphBehavior(designer, ribbon))
 {
     _behaviorService = behaviorService;
     _ribbon = ribbon;
     size = new Size(60, 16);
 }
Exemple #6
0
        /// <summary>
        ///  This method is called when we lose capture, which can occur when another window requests capture or the user presses ESC during a drag.  We check to see if we are currently dragging, and if we are we abort the transaction.  We pop our behavior off the stack at this time.
        /// </summary>
        public override void OnLoseCapture(Glyph g, EventArgs e)
        {
            _captureLost = true;
            if (_pushedBehavior)
            {
                _pushedBehavior = false;
                Debug.Assert(BehaviorService != null, "We should have a behavior service.");
                if (BehaviorService != null)
                {
                    if (_dragging)
                    {
                        _dragging = false;
                        //make sure we get rid of the selection rectangle
                        for (int i = 0; !_captureLost && i < _resizeComponents.Length; i++)
                        {
                            Control   control    = _resizeComponents[i].resizeControl as Control;
                            Rectangle borderRect = BehaviorService.ControlRectInAdornerWindow(control);
                            if (!borderRect.IsEmpty)
                            {
                                using (Graphics graphics = BehaviorService.AdornerWindowGraphics)
                                {
                                    graphics.SetClip(borderRect);
                                    using (Region newRegion = new Region(borderRect))
                                    {
                                        newRegion.Exclude(Rectangle.Inflate(borderRect, -BorderSize, -BorderSize));
                                        BehaviorService.Invalidate(newRegion);
                                    }

                                    graphics.ResetClip();
                                }
                            }
                        }

                        //re-enable all glyphs in all adorners
                        BehaviorService.EnableAllAdorners(true);
                    }

                    BehaviorService.PopBehavior(this);

                    if (_lastResizeRegion != null)
                    {
                        BehaviorService.Invalidate(_lastResizeRegion); //might be the same, might not.
                        _lastResizeRegion.Dispose();
                        _lastResizeRegion = null;
                    }
                }
            }

            Debug.Assert(!_dragging, "How can we be dragging without pushing a behavior?");
            // If we still have a transaction, roll it back.
            if (_resizeTransaction != null)
            {
                DesignerTransaction t = _resizeTransaction;
                _resizeTransaction = null;
                using (t)
                {
                    t.Cancel();
                }
            }
        }
 public RibbonTabGlyph(BehaviorService behaviorService, RibbonDesigner designer, Ribbon ribbon)
    : base(new RibbonTabGlyphBehavior(designer, ribbon))
 {
    _behaviorService = behaviorService;
    _componentDesigner = designer;
    _ribbon = ribbon;
 }
Exemple #8
0
 public ToolboxItemSnapLineBehavior(IServiceProvider serviceProvider, BehaviorService behaviorService, ControlDesigner controlDesigner) : this(serviceProvider, behaviorService)
 {
     this.designer = controlDesigner;
     if ((controlDesigner != null) && !controlDesigner.ParticipatesWithSnapLines)
     {
         this.targetAllowsSnapLines = false;
     }
 }
 public ToolboxItemSnapLineBehavior(IServiceProvider serviceProvider, BehaviorService behaviorService, ControlDesigner controlDesigner) : this(serviceProvider, behaviorService)
 {
     this.designer = controlDesigner;
     if ((controlDesigner != null) && !controlDesigner.ParticipatesWithSnapLines)
     {
         this.targetAllowsSnapLines = false;
     }
 }
 protected Behavior(bool callParentBehavior, BehaviorService behaviorService)
 {
     if (callParentBehavior && (behaviorService == null))
     {
         throw new ArgumentException("behaviorService");
     }
     this.callParentBehavior = callParentBehavior;
     this.bhvSvc = behaviorService;
 }
Exemple #11
0
 protected Behavior(bool callParentBehavior, BehaviorService behaviorService)
 {
     if (callParentBehavior && (behaviorService == null))
     {
         throw new ArgumentException("behaviorService");
     }
     this.callParentBehavior = callParentBehavior;
     this.bhvSvc             = behaviorService;
 }
Exemple #12
0
 /// <summary>
 ///  Constructor that parents itself to the Designer Frame and hooks all
 ///  necessary events.
 /// </summary>
 internal AdornerWindow(BehaviorService behaviorService, Control designerFrame)
 {
     _behaviorService = behaviorService;
     DesignerFrame    = designerFrame;
     Dock             = DockStyle.Fill;
     AllowDrop        = true;
     Text             = "AdornerWindow";
     SetStyle(ControlStyles.Opaque, true);
 }
 internal ToolStripPanelSelectionBehavior(ToolStripPanel containerControl, IServiceProvider serviceProvider)
 {
     this.behaviorService = (BehaviorService)serviceProvider.GetService(typeof(BehaviorService));
     if (this.behaviorService != null)
     {
         this.relatedControl  = containerControl;
         this.serviceProvider = serviceProvider;
     }
 }
 public DesignerActionKeyboardBehavior(DesignerActionPanel panel, IServiceProvider serviceProvider, BehaviorService behaviorService) : base(true, behaviorService)
 {
     this.panel = panel;
     if (serviceProvider != null)
     {
         this.menuService = serviceProvider.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
         this.daUISvc = serviceProvider.GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
     }
 }
        private bool _selectionChanging;                    //we dont want the OnSelectionChanged to be recursively called.

        /// <summary>
        ///  Constructor.  Here we query for necessary services and cache them for perf. reasons. We also hook to Component Added/Removed/Changed notifications so we can keep in sync when the designers' components change.  Also, we create our custom Adorner and add it to the BehaviorService.
        /// </summary>
        public SelectionManager(IServiceProvider serviceProvider, BehaviorService behaviorService)
        {
            _prevSelectionBounds  = null;
            _prevPrimarySelection = null;
            _behaviorService      = behaviorService;
            _serviceProvider      = serviceProvider;

            _selSvc       = (ISelectionService)serviceProvider.GetService(typeof(ISelectionService));
            _designerHost = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));

            if (_designerHost is null || _selSvc is null)
            {
                Debug.Fail("SelectionManager - Host or SelSvc is null, can't continue");
            }

            //sync the BehaviorService's begindrag event
            behaviorService.BeginDrag += new BehaviorDragDropEventHandler(OnBeginDrag);

            //sync the BehaviorService's Synchronize event
            behaviorService.Synchronize += new EventHandler(OnSynchronize);

            _selSvc.SelectionChanged += new EventHandler(OnSelectionChanged);
            _rootComponent            = (Control)_designerHost.RootComponent;

            //create and add both of our adorners,
            //one for selection, one for bodies
            _selectionAdorner = new Adorner();
            _bodyAdorner      = new Adorner();
            behaviorService.Adorners.Add(_bodyAdorner);
            behaviorService.Adorners.Add(_selectionAdorner); //adding this will cause the adorner to get setup with a ptr
                                                             //to the beh.svc.

            _componentToDesigner = new Hashtable();

            IComponentChangeService cs = (IComponentChangeService)serviceProvider.GetService(typeof(IComponentChangeService));

            if (cs != null)
            {
                cs.ComponentAdded   += new ComponentEventHandler(OnComponentAdded);
                cs.ComponentRemoved += new ComponentEventHandler(OnComponentRemoved);
                cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
            }

            _designerHost.TransactionClosed += new DesignerTransactionCloseEventHandler(OnTransactionClosed);

            // designeraction UI
            if (_designerHost.GetService(typeof(DesignerOptionService)) is DesignerOptionService options)
            {
                PropertyDescriptor p = options.Options.Properties["UseSmartTags"];
                if (p != null && p.PropertyType == typeof(bool) && (bool)p.GetValue(null))
                {
                    _designerActionUI = new DesignerActionUI(serviceProvider, _selectionAdorner);
                    behaviorService.DesignerActionUI = _designerActionUI;
                }
            }
        }
 public ToolboxItemSnapLineBehavior(IServiceProvider serviceProvider, BehaviorService behaviorService, ControlDesigner controlDesigner)
     : this(serviceProvider, behaviorService)
 {
     designer = controlDesigner;
     //check to see if the current designer participate with SnapLines
     if (controlDesigner != null && !controlDesigner.ParticipatesWithSnapLines)
     {
         targetAllowsSnapLines = false;
     }
 }
Exemple #17
0
        internal DragAssistanceManager(IServiceProvider serviceProvider, Graphics graphics, ArrayList dragComponents, Image backgroundImage, bool resizing, bool ctrlDrag)
        {
            this.edgePen                   = SystemPens.Highlight;
            this.marginAndPaddingPen       = SystemPens.InactiveCaption;
            this.baselinePen               = new Pen(Color.Fuchsia);
            this.verticalSnapLines         = new ArrayList();
            this.horizontalSnapLines       = new ArrayList();
            this.targetVerticalSnapLines   = new ArrayList();
            this.targetHorizontalSnapLines = new ArrayList();
            this.targetSnapLineTypes       = new ArrayList();
            this.tempVertLines             = new ArrayList();
            this.tempHorzLines             = new ArrayList();
            this.vertLines                 = new Line[0];
            this.horzLines                 = new Line[0];
            this.snapLineToBounds          = new Hashtable();
            this.serviceProvider           = serviceProvider;
            this.behaviorService           = serviceProvider.GetService(typeof(BehaviorService)) as BehaviorService;
            IDesignerHost host    = serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;
            IUIService    service = serviceProvider.GetService(typeof(IUIService)) as IUIService;

            if ((host != null) && (this.behaviorService != null))
            {
                if (graphics == null)
                {
                    this.graphics = this.behaviorService.AdornerWindowGraphics;
                }
                else
                {
                    this.graphics = graphics;
                }
                if (service != null)
                {
                    if (service.Styles["VsColorSnaplines"] is Color)
                    {
                        this.edgePen        = new Pen((Color)service.Styles["VsColorSnaplines"]);
                        this.disposeEdgePen = true;
                    }
                    if (service.Styles["VsColorSnaplinesTextBaseline"] is Color)
                    {
                        this.baselinePen.Dispose();
                        this.baselinePen = new Pen((Color)service.Styles["VsColorSnaplinesTextBaseline"]);
                    }
                    if (service.Styles["VsColorSnaplinesMarginAndPadding"] is Color)
                    {
                        this.marginAndPaddingPen = new Pen((Color)service.Styles["VsColorSnaplinesMarginAndPadding"]);
                        this.disposeMarginPen    = true;
                    }
                }
                this.backgroundImage     = backgroundImage;
                this.rootComponentHandle = (host.RootComponent is Control) ? ((Control)host.RootComponent).Handle : IntPtr.Zero;
                this.resizing            = resizing;
                this.ctrlDrag            = ctrlDrag;
                this.Initialize(dragComponents, host);
            }
        }
 private void Init(Control containerControl, IServiceProvider serviceProvider)
 {
     this.behaviorService = (BehaviorService) serviceProvider.GetService(typeof(BehaviorService));
     if (this.behaviorService != null)
     {
         this.containerControl = containerControl;
         this.serviceProvider = serviceProvider;
         this.initialDragPoint = Point.Empty;
         this.okToMove = false;
     }
 }
 internal ToolStripPanelSelectionGlyph(Rectangle bounds, Cursor cursor, IComponent relatedComponent, IServiceProvider provider, ToolStripPanelSelectionBehavior behavior) : base(bounds, cursor, relatedComponent, behavior)
 {
     this.relatedBehavior = behavior;
     this.provider        = provider;
     this.relatedPanel    = relatedComponent as ToolStripPanel;
     this.behaviorService = (BehaviorService)provider.GetService(typeof(BehaviorService));
     if ((this.behaviorService != null) && (((IDesignerHost)provider.GetService(typeof(IDesignerHost))) != null))
     {
         this.UpdateGlyph();
     }
 }
 internal DragAssistanceManager(IServiceProvider serviceProvider, Graphics graphics, ArrayList dragComponents, Image backgroundImage, bool resizing, bool ctrlDrag)
 {
     this.edgePen = SystemPens.Highlight;
     this.marginAndPaddingPen = SystemPens.InactiveCaption;
     this.baselinePen = new Pen(Color.Fuchsia);
     this.verticalSnapLines = new ArrayList();
     this.horizontalSnapLines = new ArrayList();
     this.targetVerticalSnapLines = new ArrayList();
     this.targetHorizontalSnapLines = new ArrayList();
     this.targetSnapLineTypes = new ArrayList();
     this.tempVertLines = new ArrayList();
     this.tempHorzLines = new ArrayList();
     this.vertLines = new Line[0];
     this.horzLines = new Line[0];
     this.snapLineToBounds = new Hashtable();
     this.serviceProvider = serviceProvider;
     this.behaviorService = serviceProvider.GetService(typeof(BehaviorService)) as BehaviorService;
     IDesignerHost host = serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;
     IUIService service = serviceProvider.GetService(typeof(IUIService)) as IUIService;
     if ((host != null) && (this.behaviorService != null))
     {
         if (graphics == null)
         {
             this.graphics = this.behaviorService.AdornerWindowGraphics;
         }
         else
         {
             this.graphics = graphics;
         }
         if (service != null)
         {
             if (service.Styles["VsColorSnaplines"] is Color)
             {
                 this.edgePen = new Pen((Color) service.Styles["VsColorSnaplines"]);
                 this.disposeEdgePen = true;
             }
             if (service.Styles["VsColorSnaplinesTextBaseline"] is Color)
             {
                 this.baselinePen.Dispose();
                 this.baselinePen = new Pen((Color) service.Styles["VsColorSnaplinesTextBaseline"]);
             }
             if (service.Styles["VsColorSnaplinesMarginAndPadding"] is Color)
             {
                 this.marginAndPaddingPen = new Pen((Color) service.Styles["VsColorSnaplinesMarginAndPadding"]);
                 this.disposeMarginPen = true;
             }
         }
         this.backgroundImage = backgroundImage;
         this.rootComponentHandle = (host.RootComponent is Control) ? ((Control) host.RootComponent).Handle : IntPtr.Zero;
         this.resizing = resizing;
         this.ctrlDrag = ctrlDrag;
         this.Initialize(dragComponents, host);
     }
 }
 internal ToolStripPanelSelectionGlyph(Rectangle bounds, Cursor cursor, IComponent relatedComponent, IServiceProvider provider, ToolStripPanelSelectionBehavior behavior) : base(bounds, cursor, relatedComponent, behavior)
 {
     this.relatedBehavior = behavior;
     this.provider = provider;
     this.relatedPanel = relatedComponent as ToolStripPanel;
     this.behaviorService = (BehaviorService) provider.GetService(typeof(BehaviorService));
     if ((this.behaviorService != null) && (((IDesignerHost) provider.GetService(typeof(IDesignerHost))) != null))
     {
         this.UpdateGlyph();
     }
 }
Exemple #22
0
 private void Init(Control containerControl, IServiceProvider serviceProvider)
 {
     this.behaviorService = (BehaviorService)serviceProvider.GetService(typeof(BehaviorService));
     if (this.behaviorService != null)
     {
         this.containerControl = containerControl;
         this.serviceProvider  = serviceProvider;
         this.initialDragPoint = Point.Empty;
         this.okToMove         = false;
     }
 }
Exemple #23
0
 public ToolboxItemSnapLineBehavior(IServiceProvider serviceProvider, BehaviorService behaviorService)
 {
     this.serviceProvider       = serviceProvider;
     this.behaviorService       = behaviorService;
     this.designer              = null;
     this.isPushed              = false;
     this.lastRectangle         = Rectangle.Empty;
     this.lastOffset            = Point.Empty;
     this.statusCommandUI       = new StatusCommandUI(serviceProvider);
     this.targetAllowsDragBox   = true;
     this.targetAllowsSnapLines = true;
 }
 internal TableLayoutPanelBehavior(TableLayoutPanel panel, TableLayoutPanelDesigner designer, IServiceProvider serviceProvider)
 {
     this.table = panel;
     this.designer = designer;
     this.serviceProvider = serviceProvider;
     this.behaviorService = serviceProvider.GetService(typeof(BehaviorService)) as BehaviorService;
     if (this.behaviorService != null)
     {
         this.pushedBehavior = false;
         this.lastMouseLoc = Point.Empty;
     }
 }
 internal TableLayoutPanelBehavior(TableLayoutPanel panel, TableLayoutPanelDesigner designer, IServiceProvider serviceProvider)
 {
     this.table           = panel;
     this.designer        = designer;
     this.serviceProvider = serviceProvider;
     this.behaviorService = serviceProvider.GetService(typeof(BehaviorService)) as BehaviorService;
     if (this.behaviorService != null)
     {
         this.pushedBehavior = false;
         this.lastMouseLoc   = Point.Empty;
     }
 }
 public ToolboxItemSnapLineBehavior(IServiceProvider serviceProvider, BehaviorService behaviorService)
 {
     this.serviceProvider = serviceProvider;
     this.behaviorService = behaviorService;
     this.designer = null;
     this.isPushed = false;
     this.lastRectangle = Rectangle.Empty;
     this.lastOffset = Point.Empty;
     this.statusCommandUI = new StatusCommandUI(serviceProvider);
     this.targetAllowsDragBox = true;
     this.targetAllowsSnapLines = true;
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.PopBehavior();
         if (this.selectionService != null)
         {
             this.selectionService.SelectionChanged -= new EventHandler(this.selectionService_SelectionChanged);
         }
         this.selectionService = null;
         this.behaviorService = null;
     }
 }
Exemple #28
0
        private void Init(Control containerControl, IServiceProvider serviceProvider)
        {
            _behaviorService = (BehaviorService)serviceProvider.GetService(typeof(BehaviorService));
            if (_behaviorService is null)
            {
                Debug.Fail("Could not get the BehaviorService from ContainerSelectroBehavior!");
                return;
            }

            _containerControl = containerControl;
            _serviceProvider  = serviceProvider;
            _initialDragPoint = Point.Empty;
            _okToMove         = false;
        }
 public override void Initialize(IComponent component)
 {
     base.Initialize(component);
     if (component.Site != null)
     {
         this.selectionService = this.GetService(typeof(ISelectionService)) as ISelectionService;
         this.behaviorService = this.GetService(typeof(BehaviorService)) as BehaviorService;
         if ((this.behaviorService != null) && (this.selectionService != null))
         {
             this.behavior = new FilterCutCopyPasteDeleteBehavior(true, this.behaviorService);
             this.UpdateBehavior();
             this.selectionService.SelectionChanged += new EventHandler(this.selectionService_SelectionChanged);
         }
     }
 }
 internal GlyphCollection GetGlyphs(ToolStrip parent, GlyphCollection glyphs, System.Windows.Forms.Design.Behavior.Behavior standardBehavior)
 {
     if (this.b == null)
     {
         this.b = (BehaviorService) parent.Site.GetService(typeof(BehaviorService));
     }
     Point pos = this.b.ControlToAdornerWindow(base.Parent);
     Rectangle bounds = this.Bounds;
     bounds.Offset(pos);
     bounds.Inflate(-2, -2);
     glyphs.Add(new MiniLockedBorderGlyph(bounds, SelectionBorderGlyphType.Top, standardBehavior, true));
     glyphs.Add(new MiniLockedBorderGlyph(bounds, SelectionBorderGlyphType.Bottom, standardBehavior, true));
     glyphs.Add(new MiniLockedBorderGlyph(bounds, SelectionBorderGlyphType.Left, standardBehavior, true));
     glyphs.Add(new MiniLockedBorderGlyph(bounds, SelectionBorderGlyphType.Right, standardBehavior, true));
     return glyphs;
 }
 public void Dispose()
 {
     if (this.designerHost != null)
     {
         this.designerHost.TransactionClosed -= new DesignerTransactionCloseEventHandler(this.OnTransactionClosed);
         this.designerHost = null;
     }
     if (this.serviceProvider != null)
     {
         IComponentChangeService service = (IComponentChangeService)this.serviceProvider.GetService(typeof(IComponentChangeService));
         if (service != null)
         {
             service.ComponentAdded   -= new ComponentEventHandler(this.OnComponentAdded);
             service.ComponentChanged -= new ComponentChangedEventHandler(this.OnComponentChanged);
             service.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemoved);
         }
         if (this.selSvc != null)
         {
             this.selSvc.SelectionChanged -= new EventHandler(this.OnSelectionChanged);
             this.selSvc = null;
         }
         this.serviceProvider = null;
     }
     if (this.behaviorService != null)
     {
         this.behaviorService.Adorners.Remove(this.bodyAdorner);
         this.behaviorService.Adorners.Remove(this.selectionAdorner);
         this.behaviorService.BeginDrag   -= new BehaviorDragDropEventHandler(this.OnBeginDrag);
         this.behaviorService.Synchronize -= new EventHandler(this.OnSynchronize);
         this.behaviorService              = null;
     }
     if (this.selectionAdorner != null)
     {
         this.selectionAdorner.Glyphs.Clear();
         this.selectionAdorner = null;
     }
     if (this.bodyAdorner != null)
     {
         this.bodyAdorner.Glyphs.Clear();
         this.bodyAdorner = null;
     }
     if (this.designerActionUI != null)
     {
         this.designerActionUI.Dispose();
         this.designerActionUI = null;
     }
 }
 internal ToolStripAdornerWindowService(IServiceProvider serviceProvider, Control windowFrame)
 {
     this.serviceProvider = serviceProvider;
     this.toolStripAdornerWindow = new ToolStripAdornerWindow(windowFrame);
     this.bs = (BehaviorService) serviceProvider.GetService(typeof(BehaviorService));
     int adornerWindowIndex = this.bs.AdornerWindowIndex;
     this.os = (IOverlayService) serviceProvider.GetService(typeof(IOverlayService));
     if (this.os != null)
     {
         this.os.InsertOverlay(this.toolStripAdornerWindow, adornerWindowIndex);
     }
     this.dropDownAdorner = new Adorner();
     int count = this.bs.Adorners.Count;
     if (count > 1)
     {
         this.bs.Adorners.Insert(count - 1, this.dropDownAdorner);
     }
 }
 public void Dispose()
 {
     if (this.os != null)
     {
         this.os.RemoveOverlay(this.toolStripAdornerWindow);
     }
     this.toolStripAdornerWindow.Dispose();
     if (this.bs != null)
     {
         this.bs.Adorners.Remove(this.dropDownAdorner);
         this.bs = null;
     }
     if (this.dropDownAdorner != null)
     {
         this.dropDownAdorner.Glyphs.Clear();
         this.dropDownAdorner = null;
     }
 }
 public DesignerActionUI(IServiceProvider serviceProvider, Adorner containerAdorner)
 {
     this.serviceProvider = serviceProvider;
     this.designerActionAdorner = containerAdorner;
     this.behaviorService = (BehaviorService) serviceProvider.GetService(typeof(BehaviorService));
     this.menuCommandService = (IMenuCommandService) serviceProvider.GetService(typeof(IMenuCommandService));
     this.selSvc = (ISelectionService) serviceProvider.GetService(typeof(ISelectionService));
     if ((this.behaviorService != null) && (this.selSvc != null))
     {
         this.designerActionService = (DesignerActionService) serviceProvider.GetService(typeof(DesignerActionService));
         if (this.designerActionService == null)
         {
             this.designerActionService = new DesignerActionService(serviceProvider);
             this.disposeActionService = true;
         }
         this.designerActionUIService = (DesignerActionUIService) serviceProvider.GetService(typeof(DesignerActionUIService));
         if (this.designerActionUIService == null)
         {
             this.designerActionUIService = new DesignerActionUIService(serviceProvider);
             this.disposeActionUIService = true;
         }
         this.designerActionUIService.DesignerActionUIStateChange += new DesignerActionUIStateChangeEventHandler(this.OnDesignerActionUIStateChange);
         this.designerActionService.DesignerActionListsChanged += new DesignerActionListsChangedEventHandler(this.OnDesignerActionsChanged);
         this.lastPanelComponent = null;
         IComponentChangeService service = (IComponentChangeService) serviceProvider.GetService(typeof(IComponentChangeService));
         if (service != null)
         {
             service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
         }
         if (this.menuCommandService != null)
         {
             this.cmdShowDesignerActions = new MenuCommand(new EventHandler(this.OnKeyShowDesignerActions), MenuCommands.KeyInvokeSmartTag);
             this.menuCommandService.AddCommand(this.cmdShowDesignerActions);
         }
         this.uiService = (IUIService) serviceProvider.GetService(typeof(IUIService));
         if (this.uiService != null)
         {
             this.mainParentWindow = this.uiService.GetDialogOwnerWindow();
         }
         this.componentToGlyph = new Hashtable();
         this.marshalingControl = new Control();
         this.marshalingControl.CreateControl();
     }
 }
Exemple #35
0
 private void GetParentSnapInfo(Control parentControl, BehaviorService bhvSvc)
 {
     this.parentGridSize = Size.Empty;
     if ((bhvSvc != null) && !bhvSvc.UseSnapLines)
     {
         PropertyDescriptor descriptor = TypeDescriptor.GetProperties(parentControl)["SnapToGrid"];
         if ((descriptor != null) && ((bool)descriptor.GetValue(parentControl)))
         {
             PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(parentControl)["GridSize"];
             if ((descriptor2 != null) && (this.dragComponents[this.primaryComponentIndex].dragComponent is Control))
             {
                 this.parentGridSize = (Size)descriptor2.GetValue(parentControl);
                 this.parentLocation = bhvSvc.MapAdornerWindowPoint(parentControl.Handle, Point.Empty);
                 if ((parentControl.Parent != null) && parentControl.Parent.IsMirrored)
                 {
                     this.parentLocation.Offset(-parentControl.Width, 0);
                 }
             }
         }
     }
 }
        public SelectionManager(IServiceProvider serviceProvider, BehaviorService behaviorService)
        {
            this.behaviorService = behaviorService;
            this.serviceProvider = serviceProvider;
            this.selSvc          = (ISelectionService)serviceProvider.GetService(typeof(ISelectionService));
            this.designerHost    = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));
            if (this.designerHost != null)
            {
                ISelectionService selSvc = this.selSvc;
            }
            behaviorService.BeginDrag    += new BehaviorDragDropEventHandler(this.OnBeginDrag);
            behaviorService.Synchronize  += new EventHandler(this.OnSynchronize);
            this.selSvc.SelectionChanged += new EventHandler(this.OnSelectionChanged);
            this.rootComponent            = (Control)this.designerHost.RootComponent;
            this.selectionAdorner         = new Adorner();
            this.bodyAdorner              = new Adorner();
            behaviorService.Adorners.Add(this.bodyAdorner);
            behaviorService.Adorners.Add(this.selectionAdorner);
            this.componentToDesigner = new Hashtable();
            IComponentChangeService service = (IComponentChangeService)serviceProvider.GetService(typeof(IComponentChangeService));

            if (service != null)
            {
                service.ComponentAdded   += new ComponentEventHandler(this.OnComponentAdded);
                service.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemoved);
                service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
            }
            this.designerHost.TransactionClosed += new DesignerTransactionCloseEventHandler(this.OnTransactionClosed);
            DesignerOptionService service2 = this.designerHost.GetService(typeof(DesignerOptionService)) as DesignerOptionService;

            if (service2 != null)
            {
                PropertyDescriptor descriptor = service2.Options.Properties["UseSmartTags"];
                if (((descriptor != null) && (descriptor.PropertyType == typeof(bool))) && ((bool)descriptor.GetValue(null)))
                {
                    this.designerActionUI            = new DesignerActionUI(serviceProvider, this.selectionAdorner);
                    behaviorService.DesignerActionUI = this.designerActionUI;
                }
            }
        }
        /// <summary>
        /// Initialize a new instance of the KryptonSplitContainerGlyph class.
        /// </summary>
        /// <param name="selectionService">Reference to the selection service.</param>
        /// <param name="behaviorService">Reference to the behavior service.</param>
        /// <param name="adorner">Reference to the containing adorner.</param>
        /// <param name="relatedDesigner">Reference to the containing designer.</param>
        public KryptonSplitContainerGlyph(ISelectionService selectionService,
                                          BehaviorService behaviorService,
                                          Adorner adorner,
                                          IDesigner relatedDesigner)
            : base(new KryptonSplitContainerBehavior(relatedDesigner))
        {
            Debug.Assert(selectionService != null);
            Debug.Assert(behaviorService != null);
            Debug.Assert(adorner != null);
            Debug.Assert(relatedDesigner != null);

            // Remember incoming references
            _selectionService = selectionService;
            _behaviorService = behaviorService;
            _adorner = adorner;

            // Find the related control
            _splitContainer = relatedDesigner.Component as KryptonSplitContainer;

            // We want to know whenever the selection has changed or a property has changed
            _selectionService.SelectionChanged += new EventHandler(OnSelectionChanged);
        }
Exemple #38
0
        private void DisableAdorners(IServiceProvider serviceProvider, BehaviorService behaviorService, bool hostChange)
        {
            Adorner          bodyGlyphAdorner = null;
            SelectionManager service          = (SelectionManager)serviceProvider.GetService(typeof(SelectionManager));

            if (service != null)
            {
                bodyGlyphAdorner = service.BodyGlyphAdorner;
            }
            foreach (Adorner adorner2 in behaviorService.Adorners)
            {
                if ((bodyGlyphAdorner == null) || !adorner2.Equals(bodyGlyphAdorner))
                {
                    adorner2.EnabledInternal = false;
                }
            }
            behaviorService.Invalidate();
            if (hostChange)
            {
                service.OnBeginDrag(new BehaviorDragDropEventArgs(this.dragObjects));
            }
        }
 public SelectionManager(IServiceProvider serviceProvider, BehaviorService behaviorService)
 {
     this.behaviorService = behaviorService;
     this.serviceProvider = serviceProvider;
     this.selSvc = (ISelectionService) serviceProvider.GetService(typeof(ISelectionService));
     this.designerHost = (IDesignerHost) serviceProvider.GetService(typeof(IDesignerHost));
     if (this.designerHost != null)
     {
         ISelectionService selSvc = this.selSvc;
     }
     behaviorService.BeginDrag += new BehaviorDragDropEventHandler(this.OnBeginDrag);
     behaviorService.Synchronize += new EventHandler(this.OnSynchronize);
     this.selSvc.SelectionChanged += new EventHandler(this.OnSelectionChanged);
     this.rootComponent = (Control) this.designerHost.RootComponent;
     this.selectionAdorner = new Adorner();
     this.bodyAdorner = new Adorner();
     behaviorService.Adorners.Add(this.bodyAdorner);
     behaviorService.Adorners.Add(this.selectionAdorner);
     this.componentToDesigner = new Hashtable();
     IComponentChangeService service = (IComponentChangeService) serviceProvider.GetService(typeof(IComponentChangeService));
     if (service != null)
     {
         service.ComponentAdded += new ComponentEventHandler(this.OnComponentAdded);
         service.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemoved);
         service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
     }
     this.designerHost.TransactionClosed += new DesignerTransactionCloseEventHandler(this.OnTransactionClosed);
     DesignerOptionService service2 = this.designerHost.GetService(typeof(DesignerOptionService)) as DesignerOptionService;
     if (service2 != null)
     {
         PropertyDescriptor descriptor = service2.Options.Properties["UseSmartTags"];
         if (((descriptor != null) && (descriptor.PropertyType == typeof(bool))) && ((bool) descriptor.GetValue(null)))
         {
             this.designerActionUI = new DesignerActionUI(serviceProvider, this.selectionAdorner);
             behaviorService.DesignerActionUI = this.designerActionUI;
         }
     }
 }
        /// <summary>
        /// This is called in response to the mouse moving far enough away from its initial point.  Basically, we calculate the bounds for each control we're resizing and disable any adorners.
        /// </summary>
        private void InitiateResize()
        {
            bool      useSnapLines = BehaviorService.UseSnapLines;
            ArrayList components   = new ArrayList();

            //check to see if the current designer participate with SnapLines cache the control bounds
            for (int i = 0; i < _resizeComponents.Length; i++)
            {
                _resizeComponents[i].resizeBounds = ((Control)(_resizeComponents[i].resizeControl)).Bounds;
                if (useSnapLines)
                {
                    components.Add(_resizeComponents[i].resizeControl);
                }
                if (_serviceProvider.GetService(typeof(IDesignerHost)) is IDesignerHost designerHost)
                {
                    if (designerHost.GetDesigner(_resizeComponents[i].resizeControl as Component) is ControlDesigner designer)
                    {
                        _resizeComponents[i].resizeRules = designer.SelectionRules;
                    }
                    else
                    {
                        Debug.Fail("Initiating resize. Could not get the designer for " + _resizeComponents[i].resizeControl.ToString());
                        _resizeComponents[i].resizeRules = SelectionRules.None;
                    }
                }
            }

            //disable all glyphs in all adorners
            BehaviorService.EnableAllAdorners(false);
            //build up our resize transaction
            IDesignerHost host = (IDesignerHost)_serviceProvider.GetService(typeof(IDesignerHost));

            if (host != null)
            {
                string locString;
                if (_resizeComponents.Length == 1)
                {
                    string name = TypeDescriptor.GetComponentName(_resizeComponents[0].resizeControl);
                    if (name == null || name.Length == 0)
                    {
                        name = _resizeComponents[0].resizeControl.GetType().Name;
                    }
                    locString = string.Format(SR.BehaviorServiceResizeControl, name);
                }
                else
                {
                    locString = string.Format(SR.BehaviorServiceResizeControls, _resizeComponents.Length);
                }
                _resizeTransaction = host.CreateTransaction(locString);
            }

            _initialResize = true;
            if (useSnapLines)
            {
                //instantiate our class to manage snap/margin lines...
                _dragManager = new DragAssistanceManager(_serviceProvider, components, true);
            }
            else if (_resizeComponents.Length > 0)
            {
                //try to get the parents grid and snap settings
                if (_resizeComponents[0].resizeControl is Control control && control.Parent != null)
                {
                    PropertyDescriptor snapProp = TypeDescriptor.GetProperties(control.Parent)["SnapToGrid"];
                    if (snapProp != null && (bool)snapProp.GetValue(control.Parent))
                    {
                        PropertyDescriptor gridProp = TypeDescriptor.GetProperties(control.Parent)["GridSize"];
                        if (gridProp != null)
                        {
                            //cache of the gridsize and the location of the parent on the adornerwindow
                            _parentGridSize    = (Size)gridProp.GetValue(control.Parent);
                            _parentLocation    = _behaviorService.ControlToAdornerWindow(control);
                            _parentLocation.X -= control.Location.X;
                            _parentLocation.Y -= control.Location.Y;
                        }
                    }
                }
            }
            _captureLost = false;
        }
 private void DisableAdorners(IServiceProvider serviceProvider, BehaviorService behaviorService, bool hostChange)
 {
     Adorner bodyGlyphAdorner = null;
     SelectionManager service = (SelectionManager) serviceProvider.GetService(typeof(SelectionManager));
     if (service != null)
     {
         bodyGlyphAdorner = service.BodyGlyphAdorner;
     }
     foreach (Adorner adorner2 in behaviorService.Adorners)
     {
         if ((bodyGlyphAdorner == null) || !adorner2.Equals(bodyGlyphAdorner))
         {
             adorner2.EnabledInternal = false;
         }
     }
     behaviorService.Invalidate();
     if (hostChange)
     {
         service.OnBeginDrag(new BehaviorDragDropEventArgs(this.dragObjects));
     }
 }
Exemple #42
0
 protected Behavior(bool callParentBehavior, BehaviorService behaviorService)
 {
     throw new NotImplementedException();
 }
Exemple #43
0
		protected Behavior (bool callParentBehavior, BehaviorService behaviorService)
		{
			throw new NotImplementedException ();
		}
 public DesignerActionKeyboardBehavior(DesignerActionPanel panel, IServiceProvider serviceProvider, BehaviorService behaviorService) : base(true, behaviorService)
 {
     this.panel = panel;
     if (serviceProvider != null)
     {
         this.menuService = serviceProvider.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
         this.daUISvc     = serviceProvider.GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
     }
 }
 private Point AdornerToControl(Point ptAdorner)
 {
     if (this.bs == null)
     {
         this.bs = (BehaviorService) this.designer.GetService(typeof(BehaviorService));
     }
     if (this.bs != null)
     {
         Point p = this.bs.AdornerWindowToScreen();
         p.X += ptAdorner.X;
         p.Y += ptAdorner.Y;
         return this.designer.Control.PointToClient(p);
     }
     return ptAdorner;
 }
 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);
                         }
                     }
                     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 ? this.dragComponents[this.primaryComponentIndex].zorderIndex : 0, 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 ? this.dragComponents[i].zorderIndex : 0, 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 num6 = tray.Controls.Count - num;
                             if (num6 > 0)
                             {
                                 ArrayList components = new ArrayList();
                                 for (int n = 0; n < num6; 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 num8 = 0; num8 < list.Count; num8++)
                 {
                     this.dragComponents[num8].dragComponent = list[num8];
                 }
             }
             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);
     }
 }
Exemple #47
0
		public BehaviorServiceAdornerCollection(BehaviorService behaviorService)
		{
			throw null;
		}
Exemple #48
0
 public ToolboxItemSnapLineBehavior(IServiceProvider serviceProvider, BehaviorService behaviorService, ControlDesigner controlDesigner, bool allowDragBox) : this(serviceProvider, behaviorService, controlDesigner)
 {
     this.designer            = controlDesigner;
     this.targetAllowsDragBox = allowDragBox;
 }
 public FilterCutCopyPasteDeleteBehavior(bool callParentBehavior, BehaviorService behaviorService)
     : base(callParentBehavior, behaviorService)
 {
 }
 public DesignerActionKeyboardBehavior(DesignerActionPanel panel, IServiceProvider serviceProvider, BehaviorService behaviorService) :
     base(true, behaviorService)
 {
     _panel = panel;
     if (serviceProvider != null)
     {
         _menuService = serviceProvider.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
         Debug.Assert(_menuService != null, "we should have found a menu service here...");
         _daUISvc = serviceProvider.GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
     }
 }
        /// <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);
        }
Exemple #52
0
 protected Behavior(bool callParentBehavior, BehaviorService behaviorService)
 {
     throw null;
 }
        /// <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);
        }
 public void Dispose()
 {
     if (this.marshalingControl != null)
     {
         this.marshalingControl.Dispose();
         this.marshalingControl = null;
     }
     if (this.serviceProvider != null)
     {
         IComponentChangeService service = (IComponentChangeService) this.serviceProvider.GetService(typeof(IComponentChangeService));
         if (service != null)
         {
             service.ComponentChanged -= new ComponentChangedEventHandler(this.OnComponentChanged);
         }
         if (this.cmdShowDesignerActions != null)
         {
             IMenuCommandService service2 = (IMenuCommandService) this.serviceProvider.GetService(typeof(IMenuCommandService));
             if (service2 != null)
             {
                 service2.RemoveCommand(this.cmdShowDesignerActions);
             }
         }
     }
     this.serviceProvider = null;
     this.behaviorService = null;
     this.selSvc = null;
     if (this.designerActionService != null)
     {
         this.designerActionService.DesignerActionListsChanged -= new DesignerActionListsChangedEventHandler(this.OnDesignerActionsChanged);
         if (this.disposeActionService)
         {
             this.designerActionService.Dispose();
         }
     }
     this.designerActionService = null;
     if (this.designerActionUIService != null)
     {
         this.designerActionUIService.DesignerActionUIStateChange -= new DesignerActionUIStateChangeEventHandler(this.OnDesignerActionUIStateChange);
         if (this.disposeActionUIService)
         {
             this.designerActionUIService.Dispose();
         }
     }
     this.designerActionUIService = null;
     this.designerActionAdorner = null;
 }
 /// <summary>
 ///  Initializes a new instance of <see cref='BehaviorServiceAdornerCollection' />.
 /// </summary>
 public BehaviorServiceAdornerCollection(BehaviorService behaviorService)
 {
     throw new NotImplementedException(SR.NotImplementedByDesign);
 }
 public MenuCommandHandler(BehaviorService owner, IMenuCommandService menuService)
 {
     _owner      = owner;
     MenuService = menuService;
 }
 public override void Initialize(IComponent component)
 {
     this.initializing = true;
     base.Initialize(component);
     this.initializing = false;
     PropertyDescriptor descriptor = TypeDescriptor.GetProperties(base.Component.GetType())["BackColor"];
     if (((descriptor != null) && (descriptor.PropertyType == typeof(System.Drawing.Color))) && !descriptor.ShouldSerializeValue(base.Component))
     {
         this.Control.BackColor = SystemColors.Control;
     }
     IDesignerHost serviceProvider = (IDesignerHost) this.GetService(typeof(IDesignerHost));
     IExtenderProviderService ex = (IExtenderProviderService) this.GetService(typeof(IExtenderProviderService));
     if (ex != null)
     {
         this.designerExtenders = new DesignerExtenders(ex);
     }
     if (serviceProvider != null)
     {
         serviceProvider.Activated += new EventHandler(this.OnDesignerActivate);
         serviceProvider.Deactivated += new EventHandler(this.OnDesignerDeactivate);
         ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService);
         serviceProvider.AddService(typeof(IEventHandlerService), callback);
         this.frame = new DesignerFrame(component.Site);
         IOverlayService frame = this.frame;
         serviceProvider.AddService(typeof(IOverlayService), frame);
         serviceProvider.AddService(typeof(ISplitWindowService), this.frame);
         this.behaviorService = new BehaviorService(base.Component.Site, this.frame);
         serviceProvider.AddService(typeof(BehaviorService), this.behaviorService);
         this.selectionManager = new SelectionManager(serviceProvider, this.behaviorService);
         serviceProvider.AddService(typeof(SelectionManager), this.selectionManager);
         serviceProvider.AddService(typeof(ToolStripAdornerWindowService), callback);
         IComponentChangeService service = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
         if (service != null)
         {
             service.ComponentAdded += new ComponentEventHandler(this.OnComponentAdded);
             service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
             service.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemoved);
         }
         this.inheritanceUI = new InheritanceUI();
         serviceProvider.AddService(typeof(InheritanceUI), this.inheritanceUI);
         InheritanceService serviceInstance = new DocumentInheritanceService(this);
         serviceProvider.AddService(typeof(IInheritanceService), serviceInstance);
         manager = serviceProvider.GetService(typeof(IDesignerSerializationManager)) as IDesignerSerializationManager;
         serviceInstance.AddInheritedComponents(component, component.Site.Container);
         manager = null;
         this.inheritanceService = serviceInstance;
         if (this.Control.IsHandleCreated)
         {
             this.OnCreateHandle();
         }
         IPropertyValueUIService service5 = (IPropertyValueUIService) component.Site.GetService(typeof(IPropertyValueUIService));
         if (service5 != null)
         {
             this.designBindingValueUIHandler = new DesignBindingValueUIHandler();
             service5.AddPropertyValueUIHandler(new PropertyValueUIHandler(this.designBindingValueUIHandler.OnGetUIValueItem));
         }
         IToolboxService service6 = (IToolboxService) serviceProvider.GetService(typeof(IToolboxService));
         if (service6 != null)
         {
             this.toolboxCreator = new ToolboxItemCreatorCallback(this.OnCreateToolboxItem);
             service6.AddCreator(this.toolboxCreator, axClipFormat, serviceProvider);
             service6.AddCreator(this.toolboxCreator, OleDragDropHandler.DataFormat, serviceProvider);
             service6.AddCreator(this.toolboxCreator, OleDragDropHandler.NestedToolboxItemFormat, serviceProvider);
         }
         serviceProvider.LoadComplete += new EventHandler(this.OnLoadComplete);
     }
     this.commandSet = new ControlCommandSet(component.Site);
     this.frame.Initialize(this.Control);
     this.pbrsFwd = new PbrsForward(this.frame, component.Site);
     this.Location = new Point(0, 0);
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         IDesignerHost host = (IDesignerHost) this.GetService(typeof(IDesignerHost));
         if (host != null)
         {
             ToolStripAdornerWindowService service = (ToolStripAdornerWindowService) this.GetService(typeof(ToolStripAdornerWindowService));
             if (service != null)
             {
                 service.Dispose();
                 host.RemoveService(typeof(ToolStripAdornerWindowService));
             }
             host.Activated -= new EventHandler(this.OnDesignerActivate);
             host.Deactivated -= new EventHandler(this.OnDesignerDeactivate);
             if (this.componentTray != null)
             {
                 ISplitWindowService service2 = (ISplitWindowService) this.GetService(typeof(ISplitWindowService));
                 if (service2 != null)
                 {
                     service2.RemoveSplitWindow(this.componentTray);
                     this.componentTray.Dispose();
                     this.componentTray = null;
                 }
                 host.RemoveService(typeof(ComponentTray));
             }
             IComponentChangeService service3 = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
             if (service3 != null)
             {
                 service3.ComponentAdded -= new ComponentEventHandler(this.OnComponentAdded);
                 service3.ComponentChanged -= new ComponentChangedEventHandler(this.OnComponentChanged);
                 service3.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemoved);
             }
             if (this.undoEngine != null)
             {
                 this.undoEngine.Undoing -= new EventHandler(this.OnUndoing);
                 this.undoEngine.Undone -= new EventHandler(this.OnUndone);
             }
             if (this.toolboxCreator != null)
             {
                 IToolboxService service4 = (IToolboxService) this.GetService(typeof(IToolboxService));
                 if (service4 != null)
                 {
                     service4.RemoveCreator(axClipFormat, host);
                     service4.RemoveCreator(OleDragDropHandler.DataFormat, host);
                     service4.RemoveCreator(OleDragDropHandler.NestedToolboxItemFormat, host);
                 }
                 this.toolboxCreator = null;
             }
         }
         if (this.menuEditorService != null)
         {
             host.RemoveService(typeof(IMenuEditorService));
             this.menuEditorService = null;
         }
         ISelectionService service5 = (ISelectionService) this.GetService(typeof(ISelectionService));
         if (service5 != null)
         {
             service5.SelectionChanged -= new EventHandler(this.OnSelectionChanged);
         }
         if (this.behaviorService != null)
         {
             this.behaviorService.Dispose();
             this.behaviorService = null;
         }
         if (this.selectionManager != null)
         {
             this.selectionManager.Dispose();
             this.selectionManager = null;
         }
         if (this.componentTray != null)
         {
             if (host != null)
             {
                 ISplitWindowService service6 = (ISplitWindowService) this.GetService(typeof(ISplitWindowService));
                 if (service6 != null)
                 {
                     service6.RemoveSplitWindow(this.componentTray);
                 }
             }
             this.componentTray.Dispose();
             this.componentTray = null;
         }
         if (this.pbrsFwd != null)
         {
             this.pbrsFwd.Dispose();
             this.pbrsFwd = null;
         }
         if (this.frame != null)
         {
             this.frame.Dispose();
             this.frame = null;
         }
         if (this.commandSet != null)
         {
             this.commandSet.Dispose();
             this.commandSet = null;
         }
         if (this.inheritanceService != null)
         {
             this.inheritanceService.Dispose();
             this.inheritanceService = null;
         }
         if (this.inheritanceUI != null)
         {
             this.inheritanceUI.Dispose();
             this.inheritanceUI = null;
         }
         if (this.designBindingValueUIHandler != null)
         {
             IPropertyValueUIService service7 = (IPropertyValueUIService) this.GetService(typeof(IPropertyValueUIService));
             if (service7 != null)
             {
                 service7.RemovePropertyValueUIHandler(new PropertyValueUIHandler(this.designBindingValueUIHandler.OnGetUIValueItem));
                 service7 = null;
             }
             this.designBindingValueUIHandler.Dispose();
             this.designBindingValueUIHandler = null;
         }
         if (this.designerExtenders != null)
         {
             this.designerExtenders.Dispose();
             this.designerExtenders = null;
         }
         if (this.axTools != null)
         {
             this.axTools.Clear();
         }
         if (host != null)
         {
             host.RemoveService(typeof(BehaviorService));
             host.RemoveService(typeof(ToolStripAdornerWindowService));
             host.RemoveService(typeof(SelectionManager));
             host.RemoveService(typeof(IInheritanceService));
             host.RemoveService(typeof(IEventHandlerService));
             host.RemoveService(typeof(IOverlayService));
             host.RemoveService(typeof(ISplitWindowService));
             host.RemoveService(typeof(InheritanceUI));
         }
     }
     base.Dispose(disposing);
 }
Exemple #59
0
 /// <summary>
 ///  Initializes a new instance of <see cref="BehaviorServiceAdornerCollection"/>.
 /// </summary>
 public BehaviorServiceAdornerCollection(BehaviorService behaviorService)
 {
     this.behaviorService = behaviorService;
 }
 private void GetParentSnapInfo(Control parentControl, BehaviorService bhvSvc)
 {
     this.parentGridSize = Size.Empty;
     if ((bhvSvc != null) && !bhvSvc.UseSnapLines)
     {
         PropertyDescriptor descriptor = TypeDescriptor.GetProperties(parentControl)["SnapToGrid"];
         if ((descriptor != null) && ((bool) descriptor.GetValue(parentControl)))
         {
             PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(parentControl)["GridSize"];
             if ((descriptor2 != null) && (this.dragComponents[this.primaryComponentIndex].dragComponent is Control))
             {
                 this.parentGridSize = (Size) descriptor2.GetValue(parentControl);
                 this.parentLocation = bhvSvc.MapAdornerWindowPoint(parentControl.Handle, Point.Empty);
                 if ((parentControl.Parent != null) && parentControl.Parent.IsMirrored)
                 {
                     this.parentLocation.Offset(-parentControl.Width, 0);
                 }
             }
         }
     }
 }