From e15dd9b4fdc2dd87ca778775d2c49d2aefee75cf Mon Sep 17 00:00:00 2001 From: Ivan Zlatev Date: Thu, 10 Sep 2009 14:03:55 +0000 Subject: [PATCH] 2009-09-10 Ivan N. Zlatev * DocumentDesigner.cs: Changing the ISelectionService at run time was a bad idea, so wrap it inside the extended UISelectionService instead. svn path=/trunk/mcs/; revision=141679 --- .../System.ComponentModel.Design/ChangeLog | 5 ++ .../System.Windows.Forms.Design/ChangeLog | 5 ++ .../DocumentDesigner.cs | 19 +++---- .../UISelectionService.cs | 53 +++++++++++-------- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/mcs/class/System.Design/System.ComponentModel.Design/ChangeLog b/mcs/class/System.Design/System.ComponentModel.Design/ChangeLog index f608e4f8611..f2361691ac8 100644 --- a/mcs/class/System.Design/System.ComponentModel.Design/ChangeLog +++ b/mcs/class/System.Design/System.ComponentModel.Design/ChangeLog @@ -1,3 +1,8 @@ +2009-09-10 Ivan N. Zlatev + + * DesignSurface.cs: Changing the ISelectionService at run time was a + bad idea, so wrap it inside the extended UISelectionService instead. + 2009-09-10 Ivan N. Zlatev * DesignSurface.cs: Provide the default implementation of the diff --git a/mcs/class/System.Design/System.Windows.Forms.Design/ChangeLog b/mcs/class/System.Design/System.Windows.Forms.Design/ChangeLog index 2e4c47e2877..7bdc5c999fa 100644 --- a/mcs/class/System.Design/System.Windows.Forms.Design/ChangeLog +++ b/mcs/class/System.Design/System.Windows.Forms.Design/ChangeLog @@ -1,3 +1,8 @@ +2009-09-10 Ivan N. Zlatev + + * DocumentDesigner.cs: Changing the ISelectionService at run time was a + bad idea, so wrap it inside the extended UISelectionService instead. + 2009-09-10 Ivan N. Zlatev * DocumentDesigner.cs: If there is already a ISelectionService registered diff --git a/mcs/class/System.Design/System.Windows.Forms.Design/DocumentDesigner.cs b/mcs/class/System.Design/System.Windows.Forms.Design/DocumentDesigner.cs index 8df62b001cc..14e6aa682d3 100644 --- a/mcs/class/System.Design/System.Windows.Forms.Design/DocumentDesigner.cs +++ b/mcs/class/System.Design/System.Windows.Forms.Design/DocumentDesigner.cs @@ -289,19 +289,14 @@ namespace System.Windows.Forms.Design private void InitializeSelectionService () { - ISelectionService selection = this.GetService (typeof (ISelectionService)) as ISelectionService; - if (selection != null && selection is IUISelectionService) - return; - - IServiceContainer serviceContainer = this.GetService (typeof (IServiceContainer)) as IServiceContainer; - if (selection != null) - serviceContainer.RemoveService (typeof (ISelectionService)); - - selection = new UISelectionService (serviceContainer); - serviceContainer.AddService (typeof (ISelectionService), (ISelectionService) selection); - serviceContainer.AddService (typeof (IUISelectionService), (IUISelectionService) selection); + IUISelectionService guiSelectionService = this.GetService (typeof (IUISelectionService)) as IUISelectionService; + if (guiSelectionService == null) { + IServiceContainer serviceContainer = this.GetService (typeof (IServiceContainer)) as IServiceContainer; + serviceContainer.AddService (typeof (IUISelectionService), (IUISelectionService) new UISelectionService (serviceContainer)); + } - selection.SetSelectedComponents (new IComponent[] { this.Component }); + ISelectionService selectionService = this.GetService (typeof (ISelectionService)) as ISelectionService; + selectionService.SetSelectedComponents (new IComponent[] { this.Component }); } #if !NET_2_0 diff --git a/mcs/class/System.Design/System.Windows.Forms.Design/UISelectionService.cs b/mcs/class/System.Design/System.Windows.Forms.Design/UISelectionService.cs index 6a4bc6e9235..4b2292a492b 100644 --- a/mcs/class/System.Design/System.Windows.Forms.Design/UISelectionService.cs +++ b/mcs/class/System.Design/System.Windows.Forms.Design/UISelectionService.cs @@ -38,19 +38,33 @@ using System.Windows.Forms; namespace System.Windows.Forms.Design { - internal class UISelectionService : SelectionService, IUISelectionService + internal class UISelectionService : IUISelectionService { private IServiceProvider _serviceProvider; private DesignerTransaction _transaction; + private ISelectionService _selectionService; - public UISelectionService (IServiceProvider serviceProvider) : base (serviceProvider) + public UISelectionService (IServiceProvider serviceProvider) { if (serviceProvider == null) throw new ArgumentNullException ("serviceProvider"); _serviceProvider = serviceProvider; _transaction = null; + + _selectionService = serviceProvider.GetService (typeof (ISelectionService)) as ISelectionService; + if (_selectionService == null) { + IServiceContainer serviceContainer = serviceProvider.GetService (typeof (IServiceContainer)) as IServiceContainer; + _selectionService = new SelectionService (serviceContainer); + serviceContainer.AddService (typeof (ISelectionService), (ISelectionService) _selectionService); + } + + _selectionService.SelectionChanged += new EventHandler (OnSelectionChanged); + } + + private ISelectionService SelectionService { + get { return _selectionService; } } private object GetService (Type service) @@ -92,11 +106,11 @@ namespace System.Windows.Forms.Design SelectionFrame frame = GetSelectionFrameAt (x, y); if (frame != null && frame.HitTest (x, y)) { - this.SetSelectedComponents (new IComponent[] { frame.Control }); + this.SelectionService.SetSelectedComponents (new IComponent[] { frame.Control }); if (_transaction == null) { IDesignerHost host = this.GetService (typeof (IDesignerHost)) as IDesignerHost; _transaction = host.CreateTransaction ("Resize " + - (this.SelectionCount == 1 ? ((IComponent)this.PrimarySelection).Site.Name : "controls")); + (this.SelectionService.SelectionCount == 1 ? ((IComponent)this.SelectionService.PrimarySelection).Site.Name : "controls")); } this.ResizeBegin (x, y); } @@ -146,12 +160,12 @@ namespace System.Windows.Forms.Design if (_transaction == null) { IDesignerHost host = this.GetService (typeof (IDesignerHost)) as IDesignerHost; _transaction = host.CreateTransaction ("Move " + - (this.SelectionCount == 1? ((IComponent)this.PrimarySelection).Site.Name : "controls")); + (this.SelectionService.SelectionCount == 1? ((IComponent)this.SelectionService.PrimarySelection).Site.Name : "controls")); } _dragging = true; _firstMove = true; - if (this.PrimarySelection != null) - ((Control)this.PrimarySelection).DoDragDrop (new ControlDataObject ((Control)this.PrimarySelection), DragDropEffects.All); + if (this.SelectionService.PrimarySelection != null) + ((Control)this.SelectionService.PrimarySelection).DoDragDrop (new ControlDataObject ((Control)this.SelectionService.PrimarySelection), DragDropEffects.All); } // container cordinates @@ -200,7 +214,7 @@ namespace System.Windows.Forms.Design // Send mouse up message to the primary selection // Else for parentcontroldesigner there is no mouseup event and it doesn't set allow drop back to false // - Native.SendMessage (((Control)this.PrimarySelection).Handle, Native.Msg.WM_LBUTTONUP, (IntPtr) 0, (IntPtr) 0); + Native.SendMessage (((Control)this.SelectionService.PrimarySelection).Handle, Native.Msg.WM_LBUTTONUP, (IntPtr) 0, (IntPtr) 0); if (_transaction != null) { if (cancel) _transaction.Cancel (); @@ -216,15 +230,15 @@ namespace System.Windows.Forms.Design bool reparent = false; Control oldParent = null; - if (((Control)this.PrimarySelection).Parent != container && !this.GetComponentSelected (container)) { + if (((Control)this.SelectionService.PrimarySelection).Parent != container && !this.SelectionService.GetComponentSelected (container)) { reparent = true; - oldParent = ((Control)this.PrimarySelection).Parent; + oldParent = ((Control)this.SelectionService.PrimarySelection).Parent; } // FIXME: Should check selectionstyle per control to determine if it's locked... // if locked -> don't move // - ICollection selection = this.GetSelectedComponents (); + ICollection selection = this.SelectionService.GetSelectedComponents (); foreach (Component component in selection) { Control control = component as Control; if (reparent) @@ -361,7 +375,7 @@ namespace System.Windows.Forms.Design // do not change selection if nothing has changed // if (selectedControls.Count != 0) - this.SetSelectedComponents (selectedControls, SelectionTypes.Replace); + this.SelectionService.SetSelectedComponents (selectedControls, SelectionTypes.Replace); _selectionContainer.Refresh (); } @@ -384,7 +398,7 @@ namespace System.Windows.Forms.Design { // Console.WriteLine ("ResizeContinue"); Rectangle deltaBounds = _selectionFrame.ResizeContinue (x, y); - ICollection selection = this.GetSelectedComponents (); + ICollection selection = this.SelectionService.GetSelectedComponents (); foreach (IComponent component in selection) { if (component is Control) { @@ -445,10 +459,10 @@ namespace System.Windows.Forms.Design { IDesignerHost host = this.GetService (typeof (IDesignerHost)) as IDesignerHost; - if (host == null || !(this.PrimarySelection is Control)) + if (host == null || !(this.SelectionService.PrimarySelection is Control)) return; - if ((Control)this.PrimarySelection == container) { + if ((Control)this.SelectionService.PrimarySelection == container) { if (_selecting) { Color negativeColor = Color.FromArgb ((byte)~(_selectionContainer.BackColor.R), (byte)~(_selectionContainer.BackColor.G), @@ -456,7 +470,7 @@ namespace System.Windows.Forms.Design DrawSelectionRectangle (gfx, _selectionRectangle, negativeColor); } } - else if (((Control)this.PrimarySelection).Parent == container) { + else if (((Control)this.SelectionService.PrimarySelection).Parent == container) { foreach (SelectionFrame frame in _selectionFrames) frame.OnPaint (gfx); } @@ -471,10 +485,9 @@ namespace System.Windows.Forms.Design } - protected override void OnSelectionChanged () + private void OnSelectionChanged (object sender, EventArgs args) { - - ICollection selection = this.GetSelectedComponents (); + ICollection selection = this.SelectionService.GetSelectedComponents (); if (_selectionFrames.Count == 0) { foreach (Component component in selection) { @@ -502,8 +515,6 @@ namespace System.Windows.Forms.Design else root.Refresh (); } - - base.OnSelectionChanged (); } private ICollection GetControlsIn (Rectangle rect) -- 2.25.1