/// <include file='doc\CompositionDesigner.uex' path='docs/doc[@for="ComponentDocumentDesigner.CompositionUI.CompositionSelectionUIHandler.GetControl1"]/*' /> /// <devdoc> /// Retrieves the UI control for the given component. /// </devdoc> protected override Control GetControl(IComponent component) { return(TrayControl.FromComponent(component)); }
private bool PositionInNextAutoSlot(TrayControl c, Control prevCtl, bool dirtyDesigner) { if (this.whiteSpace.IsEmpty) { this.whiteSpace = new Point(this.selectionUISvc.GetAdornmentDimensions(AdornmentType.GrabHandle)); this.whiteSpace.X = (this.whiteSpace.X * 2) + 3; this.whiteSpace.Y = (this.whiteSpace.Y * 2) + 3; } if (prevCtl == null) { Rectangle displayRectangle = this.DisplayRectangle; Point point = new Point(displayRectangle.X + this.whiteSpace.X, displayRectangle.Y + this.whiteSpace.Y); if (!c.Location.Equals(point)) { c.Location = point; if (dirtyDesigner) { IComponent component = c.Component; PropertyDescriptor descriptor = TypeDescriptor.GetProperties(component)["TrayLocation"]; if (descriptor != null) { Point autoScrollPosition = base.AutoScrollPosition; point = new Point(point.X - autoScrollPosition.X, point.Y - autoScrollPosition.Y); descriptor.SetValue(component, point); } } else { c.Location = point; } return true; } } else { Rectangle bounds = prevCtl.Bounds; Point point3 = new Point((bounds.X + bounds.Width) + this.whiteSpace.X, bounds.Y); if ((point3.X + c.Size.Width) > base.Size.Width) { point3.X = this.whiteSpace.X; point3.Y += bounds.Height + this.whiteSpace.Y; } if (!c.Location.Equals(point3)) { if (dirtyDesigner) { IComponent component2 = c.Component; PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(component2)["TrayLocation"]; if (descriptor2 != null) { Point point4 = base.AutoScrollPosition; point3 = new Point(point3.X - point4.X, point3.Y - point4.Y); descriptor2.SetValue(component2, point3); } } else { c.Location = point3; } return true; } } return false; }
public virtual void AddComponent(IComponent component) { IDesignerHost service = (IDesignerHost) this.GetService(typeof(IDesignerHost)); if (this.CanDisplayComponent(component)) { if (this.selectionUISvc == null) { this.selectionUISvc = (ISelectionUIService) this.GetService(typeof(ISelectionUIService)); if (this.selectionUISvc == null) { this.selectionUISvc = new SelectionUIService(service); service.AddService(typeof(ISelectionUIService), this.selectionUISvc); } this.grabHandle = this.selectionUISvc.GetAdornmentDimensions(AdornmentType.GrabHandle); } TrayControl control = new TrayControl(this, component); base.SuspendLayout(); try { base.Controls.Add(control); this.controls.Add(control); TypeDescriptor.Refresh(component); if ((service != null) && !service.Loading) { this.PositionControl(control); } if (this.selectionUISvc != null) { this.selectionUISvc.AssignSelectionUIHandler(component, this); } InheritanceAttribute inheritanceAttribute = control.InheritanceAttribute; if (inheritanceAttribute.InheritanceLevel != InheritanceLevel.NotInherited) { System.Windows.Forms.Design.InheritanceUI inheritanceUI = this.InheritanceUI; if (inheritanceUI != null) { inheritanceUI.AddInheritedControl(control, inheritanceAttribute.InheritanceLevel); } } } finally { base.ResumeLayout(); } if ((service != null) && !service.Loading) { base.ScrollControlIntoView(control); } } }
private void PositionControl(TrayControl c) { if (!this.autoArrange) { if (this.mouseDropLocation == InvalidPoint) { Control prevCtl = null; if (this.controls.Count > 1) { int index = this.controls.IndexOf(c); if (index >= 1) { prevCtl = (Control) this.controls[index - 1]; } } this.PositionInNextAutoSlot(c, prevCtl, true); } else if (!c.Location.Equals(this.mouseDropLocation)) { c.Location = this.mouseDropLocation; } } else if (this.mouseDropLocation != InvalidPoint) { this.RearrangeInAutoSlots(c, this.mouseDropLocation); } else { Control control2 = null; if (this.controls.Count > 1) { int num2 = this.controls.IndexOf(c); if (num2 >= 1) { control2 = (Control) this.controls[num2 - 1]; } } this.PositionInNextAutoSlot(c, control2, true); } }