public SelectionUIService(IDesignerHost host) { base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.StandardClick | ControlStyles.Opaque, true); this.host = host; this.dragHandler = null; this.dragComponents = null; this.selectionItems = new Hashtable(); this.selectionHandlers = new Hashtable(); this.AllowDrop = true; this.Text = "SelectionUIOverlay"; this.selSvc = (ISelectionService) host.GetService(typeof(ISelectionService)); if (this.selSvc != null) { this.selSvc.SelectionChanged += new EventHandler(this.OnSelectionChanged); } host.TransactionOpened += new EventHandler(this.OnTransactionOpened); host.TransactionClosed += new DesignerTransactionCloseEventHandler(this.OnTransactionClosed); if (host.InTransaction) { this.OnTransactionOpened(host, EventArgs.Empty); } IComponentChangeService service = (IComponentChangeService) host.GetService(typeof(IComponentChangeService)); if (service != null) { service.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemove); service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged); } SystemEvents.DisplaySettingsChanged += new EventHandler(this.OnSystemSettingChanged); SystemEvents.InstalledFontsChanged += new EventHandler(this.OnSystemSettingChanged); SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(this.OnUserPreferenceChanged); }
void ISelectionUIService.EndDrag(bool cancel) { this.containerDrag = null; ISelectionUIHandler dragHandler = this.dragHandler; object[] dragComponents = this.dragComponents; this.dragHandler = null; this.dragComponents = null; this.dragRules = SelectionRules.None; if (dragHandler == null) { throw new InvalidOperationException(); } DesignerTransaction transaction = null; try { IComponent component = dragComponents[0] as IComponent; if ((dragComponents.Length > 1) || (((dragComponents.Length == 1) && (component != null)) && (component.Site == null))) { transaction = this.host.CreateTransaction(System.Design.SR.GetString("DragDropMoveComponents", new object[] { dragComponents.Length })); } else if ((dragComponents.Length == 1) && (component != null)) { transaction = this.host.CreateTransaction(System.Design.SR.GetString("DragDropMoveComponent", new object[] { component.Site.Name })); } try { dragHandler.EndDrag(dragComponents, cancel); } catch (Exception) { } } finally { if (transaction != null) { transaction.Commit(); } base.Visible = this.savedVisible; ((ISelectionUIService) this).SyncSelection(); if (this.dragTransaction != null) { this.dragTransaction.Commit(); this.dragTransaction = null; } this.EndMouseDrag(Control.MousePosition); } }
void ISelectionUIService.ClearSelectionUIHandler(object component, ISelectionUIHandler handler) { ISelectionUIHandler handler2 = (ISelectionUIHandler) this.selectionHandlers[component]; if (handler2 == handler) { this.selectionHandlers[component] = null; } }
bool ISelectionUIService.BeginDrag(SelectionRules rules, int initialX, int initialY) { if (this.dragHandler != null) { return false; } if (rules == SelectionRules.None) { return false; } if (this.selSvc == null) { return false; } this.savedVisible = base.Visible; ICollection selectedComponents = this.selSvc.GetSelectedComponents(); object[] array = new object[selectedComponents.Count]; selectedComponents.CopyTo(array, 0); array = ((ISelectionUIService) this).FilterSelection(array, rules); if (array.Length == 0) { return false; } ISelectionUIHandler handler = null; object primarySelection = this.selSvc.PrimarySelection; if (primarySelection != null) { handler = this.GetHandler(primarySelection); } if (handler == null) { return false; } ArrayList list = new ArrayList(); for (int i = 0; i < array.Length; i++) { if ((this.GetHandler(array[i]) == handler) && ((handler.GetComponentRules(array[i]) & rules) == rules)) { list.Add(array[i]); } } if (list.Count == 0) { return false; } array = list.ToArray(); bool flag = false; this.dragComponents = array; this.dragRules = rules; this.dragHandler = handler; string transactionName = GetTransactionName(rules, array); this.dragTransaction = this.host.CreateTransaction(transactionName); try { if (!handler.QueryBeginDrag(array, rules, initialX, initialY) || (this.dragHandler == null)) { return flag; } try { flag = handler.BeginDrag(array, rules, initialX, initialY); } catch (Exception) { flag = false; } } finally { if (!flag) { this.dragComponents = null; this.dragRules = SelectionRules.None; this.dragHandler = null; if (this.dragTransaction != null) { this.dragTransaction.Commit(); this.dragTransaction = null; } } } return flag; }
void ISelectionUIService.AssignSelectionUIHandler(object component, ISelectionUIHandler handler) { ISelectionUIHandler handler2 = (ISelectionUIHandler) this.selectionHandlers[component]; if (handler2 != null) { if (handler != handler2) { throw new InvalidOperationException(); } } else { this.selectionHandlers[component] = handler; if ((this.selSvc != null) && this.selSvc.GetComponentSelected(component)) { SelectionUIItem item = new SelectionUIItem(this, component); this.selectionItems[component] = item; this.UpdateWindowRegion(); item.Invalidate(); } } }
public SelectionUIItem(SelectionUIService selUIsvc, object component) { this.selUIsvc = selUIsvc; this.component = component; this.selectionStyle = SelectionStyles.Selected; this.handler = selUIsvc.GetHandler(component); this.sizes = inactiveSizeArray; this.cursors = inactiveCursorArray; IComponent component2 = component as IComponent; if (component2 != null) { ControlDesigner designer = selUIsvc.host.GetDesigner(component2) as ControlDesigner; if (designer != null) { this.control = designer.Control; } } this.UpdateRules(); this.UpdateGrabSettings(); this.UpdateSize(); }