/// <summary> /// check dragged components are within their parent /// </summary> /// <param name="g">represent the Form</param> /// <param name="e"></param> /// <returns></returns> private bool candrop(Glyph g, System.Windows.Forms.DragEventArgs e) { bool bRet = false; if (ComponentsDraged != null && ComponentsDraged.Count > 0) { System.Windows.Forms.Design.Behavior.ControlBodyGlyph cbg = g as System.Windows.Forms.Design.Behavior.ControlBodyGlyph; if (cbg != null) { MethodDiagramViewer mv = cbg.RelatedComponent as MethodDiagramViewer; if (mv != null) { bRet = true; IEnumerator ie = ComponentsDraged.GetEnumerator(); while (ie.MoveNext()) { ActionViewer v = ie.Current as ActionViewer; if (v != null) { if (mv.GUID != v.ParentGuid) { bRet = false; break; } } } } } } if (!bRet) { e.Effect = System.Windows.Forms.DragDropEffects.None; } return(bRet); }
protected override void Dispose(bool disposing) { if (disposing) { if (this.selSvc != null) { this.selSvc.SelectionChanged -= new EventHandler(this.OnSelectionChanged); this.selSvc.SelectionChanging -= new EventHandler(this.OnSelectionChanging); } this.DisposeMenu(); if (this.designMenu != null) { this.designMenu.Dispose(); this.designMenu = null; } if (this.dummyToolStripGlyph != null) { this.dummyToolStripGlyph = null; } if (this.undoEngine != null) { this.undoEngine.Undone -= new EventHandler(this.OnUndone); } } base.Dispose(disposing); }
public override void OnDragDrop(Glyph g, DragEventArgs e) { System.Windows.Forms.Design.Behavior.ControlBodyGlyph cbg = g as System.Windows.Forms.Design.Behavior.ControlBodyGlyph; IToolboxService tbsvc = designerHost.GetService(typeof(IToolboxService)) as IToolboxService; ISelectionService selsvc = designerHost.GetService(typeof(ISelectionService)) as ISelectionService; if (cbg != null && cbg.RelatedComponent != null && cbg.RelatedComponent is Control) { ToolboxItem item = e.Data.GetData(typeof(ToolboxItem)) as ToolboxItem; IToolboxUser tbu = designerHost.GetDesigner(designerHost.RootComponent) as IToolboxUser; (designerHost.RootComponent as Control).SuspendLayout(); tbu.ToolPicked(item); if (selsvc.PrimarySelection != null && selsvc.PrimarySelection is Control) { Control createdControl = selsvc.PrimarySelection as Control; PropertyDescriptor parentProperty = TypeDescriptor.GetProperties(createdControl)["Parent"]; //获取粘贴到的父容器 ParentControlDesigner parentDesigner = null; parentDesigner = designerHost.GetDesigner(cbg.RelatedComponent) as ParentControlDesigner; if (parentDesigner == null) { parentDesigner = designerHost.GetDesigner(designerHost.RootComponent) as DocumentDesigner; } if (parentDesigner != null && parentDesigner.CanParent(createdControl)) { parentProperty.SetValue(createdControl, parentDesigner.Control); Point p1 = bhsvc.AdornerWindowToScreen(); } tbsvc.SelectedToolboxItemUsed(); Point adroP = bhsvc.AdornerWindowToScreen(); createdControl.Left = e.X - adroP.X - (cbg.RelatedComponent as Control).Left; createdControl.Top = e.Y - adroP.Y - (cbg.RelatedComponent as Control).Top; } (designerHost.RootComponent as Control).ResumeLayout(); } bhsvc.PopBehavior(this); }
private void AddControlGlyphs(Control c, GlyphSelectionType selType) { ControlDesigner designer = (ControlDesigner)this.componentToDesigner[c]; if (designer != null) { ControlBodyGlyph controlGlyphInternal = designer.GetControlGlyphInternal(selType); if (controlGlyphInternal != null) { this.bodyAdorner.Glyphs.Add(controlGlyphInternal); if ((selType == GlyphSelectionType.SelectedPrimary) || (selType == GlyphSelectionType.Selected)) { if (this.curSelectionBounds[this.curCompIndex] == Rectangle.Empty) { this.curSelectionBounds[this.curCompIndex] = controlGlyphInternal.Bounds; } else { this.curSelectionBounds[this.curCompIndex] = Rectangle.Union(this.curSelectionBounds[this.curCompIndex], controlGlyphInternal.Bounds); } } } GlyphCollection glyphs = designer.GetGlyphs(selType); if (glyphs != null) { this.selectionAdorner.Glyphs.AddRange(glyphs); if ((selType == GlyphSelectionType.SelectedPrimary) || (selType == GlyphSelectionType.Selected)) { foreach (Glyph glyph2 in glyphs) { this.curSelectionBounds[this.curCompIndex] = Rectangle.Union(this.curSelectionBounds[this.curCompIndex], glyph2.Bounds); } } } } if ((selType == GlyphSelectionType.SelectedPrimary) || (selType == GlyphSelectionType.Selected)) { this.curCompIndex++; } }
protected override ControlBodyGlyph GetControlGlyph(GlyphSelectionType selectionType) { ControlBodyGlyph glyph = null; SelectionManager service = (SelectionManager) this.GetService(typeof(SelectionManager)); if (service != null) { Rectangle bounds = base.BehaviorService.ControlRectInAdornerWindow(this.splitterPanel1); SplitterPanelDesigner designer = this.designerHost.GetDesigner(this.splitterPanel1) as SplitterPanelDesigner; this.OnSetCursor(); if (designer != null) { glyph = new ControlBodyGlyph(bounds, Cursor.Current, this.splitterPanel1, designer); service.BodyGlyphAdorner.Glyphs.Add(glyph); } bounds = base.BehaviorService.ControlRectInAdornerWindow(this.splitterPanel2); designer = this.designerHost.GetDesigner(this.splitterPanel2) as SplitterPanelDesigner; if (designer != null) { glyph = new ControlBodyGlyph(bounds, Cursor.Current, this.splitterPanel2, designer); service.BodyGlyphAdorner.Glyphs.Add(glyph); } } return base.GetControlGlyph(selectionType); }
protected virtual ControlBodyGlyph GetControlGlyph(GlyphSelectionType selectionType) { this.OnSetCursor(); Cursor current = Cursor.Current; Rectangle bounds = this.BehaviorService.ControlRectInAdornerWindow(this.Control); ControlBodyGlyph glyph = null; System.Windows.Forms.Control parent = this.Control.Parent; if (((parent != null) && (this.host != null)) && (this.host.RootComponent != base.Component)) { Rectangle rectangle2 = parent.RectangleToScreen(parent.ClientRectangle); Rectangle rect = this.Control.RectangleToScreen(this.Control.ClientRectangle); if (!rectangle2.Contains(rect) && !rectangle2.IntersectsWith(rect)) { ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService)); if ((service != null) && service.GetComponentSelected(this.Control)) { glyph = new ControlBodyGlyph(bounds, current, this.Control, this.MoveBehavior); } else if (current == Cursors.SizeAll) { current = Cursors.Default; } } } if (glyph == null) { glyph = new ControlBodyGlyph(bounds, current, this.Control, this); } return glyph; }
public void ShowMenu() { if (this.menuItem != null) { Control parent = this.designMenu.Parent; Form component = parent as Form; if (component != null) { this.parentFormDesigner = this.host.GetDesigner(component) as FormDocumentDesigner; if ((this.parentFormDesigner != null) && (this.parentFormDesigner.Menu != null)) { this.parentMenu = this.parentFormDesigner.Menu; this.parentFormDesigner.Menu = null; } } this.selected = true; this.designMenu.Visible = true; this.designMenu.BringToFront(); this.menuItem.Visible = true; if ((this.currentParent != null) && (this.currentParent != this.menuItem)) { ToolStripMenuItemDesigner designer = this.host.GetDesigner(this.currentParent) as ToolStripMenuItemDesigner; if (designer != null) { designer.RemoveTypeHereNode(this.currentParent); } } this.menuItem.DropDown = this.dropDown; this.menuItem.DropDown.OwnerItem = this.menuItem; if (this.dropDown.Items.Count > 0) { ToolStripItem[] array = new ToolStripItem[this.dropDown.Items.Count]; this.dropDown.Items.CopyTo(array, 0); foreach (ToolStripItem item in array) { if (item is DesignerToolStripControlHost) { this.dropDown.Items.Remove(item); } } } ToolStripMenuItemDesigner designer2 = (ToolStripMenuItemDesigner) this.host.GetDesigner(this.menuItem); BehaviorService service = (BehaviorService) this.GetService(typeof(BehaviorService)); if (service != null) { if ((designer2 != null) && (parent != null)) { Rectangle parentBounds = service.ControlRectInAdornerWindow(parent); if (ToolStripDesigner.IsGlyphTotallyVisible(service.ControlRectInAdornerWindow(this.designMenu), parentBounds)) { designer2.InitializeDropDown(); } } if (this.dummyToolStripGlyph == null) { Point pos = service.ControlToAdornerWindow(this.designMenu); Rectangle bounds = this.designMenu.Bounds; bounds.Offset(pos); this.dummyToolStripGlyph = new ControlBodyGlyph(bounds, Cursor.Current, this.menuItem, new ContextMenuStripBehavior(this.menuItem)); SelectionManager manager = (SelectionManager) this.GetService(typeof(SelectionManager)); if (manager != null) { manager.BodyGlyphAdorner.Glyphs.Insert(0, this.dummyToolStripGlyph); } } ToolStripKeyboardHandlingService service2 = (ToolStripKeyboardHandlingService) this.GetService(typeof(ToolStripKeyboardHandlingService)); if (service2 != null) { int num = this.dropDown.Items.Count - 1; if (num >= 0) { service2.SelectedDesignerControl = this.dropDown.Items[num]; } } } } }
private void HideMenu() { if (this.menuItem != null) { if ((this.parentMenu != null) && (this.parentFormDesigner != null)) { this.parentFormDesigner.Menu = this.parentMenu; } this.selected = false; if (this.host.RootComponent is Control) { this.menuItem.DropDown.AutoClose = true; this.menuItem.HideDropDown(); this.menuItem.Visible = false; this.designMenu.Visible = false; ToolStripAdornerWindowService service = (ToolStripAdornerWindowService) this.GetService(typeof(ToolStripAdornerWindowService)); if (service != null) { service.Invalidate(); } if (((BehaviorService) this.GetService(typeof(BehaviorService))) != null) { if (this.dummyToolStripGlyph != null) { SelectionManager manager = (SelectionManager) this.GetService(typeof(SelectionManager)); if (manager != null) { if (manager.BodyGlyphAdorner.Glyphs.Contains(this.dummyToolStripGlyph)) { manager.BodyGlyphAdorner.Glyphs.Remove(this.dummyToolStripGlyph); } manager.Refresh(); } } this.dummyToolStripGlyph = null; } if (this.menuItem != null) { ToolStripMenuItemDesigner designer = this.host.GetDesigner(this.menuItem) as ToolStripMenuItemDesigner; if (designer != null) { designer.UnHookEvents(); designer.RemoveTypeHereNode(this.menuItem); } } } } }
protected override ControlBodyGlyph GetControlGlyph(GlyphSelectionType selectionType) { SelectionManager service = (SelectionManager) this.GetService(typeof(SelectionManager)); if (service != null) { for (int i = 0; i <= 4; i++) { Control c = this.panels[i]; Rectangle bounds = base.BehaviorService.ControlRectInAdornerWindow(c); ControlDesigner designer = this.InternalControlDesigner(i); this.OnSetCursor(); if (designer != null) { ControlBodyGlyph glyph = new ControlBodyGlyph(bounds, Cursor.Current, c, designer); service.BodyGlyphAdorner.Glyphs.Add(glyph); bool flag = true; ICollection selectedComponents = this.selectionSvc.GetSelectedComponents(); if (!this.selectionSvc.GetComponentSelected(this.toolStripContainer)) { foreach (object obj2 in selectedComponents) { if (this.ContainerParent(obj2 as Control) == this.toolStripContainer) { flag = true; } else { flag = false; } } } if (flag) { ToolStripPanelDesigner designer2 = designer as ToolStripPanelDesigner; if (designer2 != null) { this.AddPanelSelectionGlyph(designer2, service); } } } } } return base.GetControlGlyph(selectionType); }