internal DesignerActionGlyph GetDesignerActionGlyph(IComponent comp, DesignerActionListCollection dalColl)
        {
            InheritanceAttribute attribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(comp)[typeof(InheritanceAttribute)];

            if (attribute != InheritanceAttribute.InheritedReadOnly)
            {
                if (dalColl == null)
                {
                    dalColl = this.designerActionService.GetComponentActions(comp);
                }
                if ((dalColl != null) && (dalColl.Count > 0))
                {
                    DesignerActionGlyph glyph = null;
                    if (this.componentToGlyph[comp] == null)
                    {
                        DesignerActionBehavior behavior = new DesignerActionBehavior(this.serviceProvider, comp, dalColl, this);
                        if (!(comp is Control) || (comp is ToolStripDropDown))
                        {
                            ComponentTray service = this.serviceProvider.GetService(typeof(ComponentTray)) as ComponentTray;
                            if (service != null)
                            {
                                ComponentTray.TrayControl trayControlFromComponent = service.GetTrayControlFromComponent(comp);
                                if (trayControlFromComponent != null)
                                {
                                    Rectangle bounds = trayControlFromComponent.Bounds;
                                    glyph = new DesignerActionGlyph(behavior, bounds, service);
                                }
                            }
                        }
                        if (glyph == null)
                        {
                            glyph = new DesignerActionGlyph(behavior, this.designerActionAdorner);
                        }
                        if (glyph != null)
                        {
                            this.componentToGlyph.Add(comp, glyph);
                        }
                        return(glyph);
                    }
                    glyph = this.componentToGlyph[comp] as DesignerActionGlyph;
                    if (glyph != null)
                    {
                        DesignerActionBehavior behavior2 = glyph.Behavior as DesignerActionBehavior;
                        if (behavior2 != null)
                        {
                            behavior2.ActionLists = dalColl;
                        }
                        glyph.Invalidate();
                    }
                    return(glyph);
                }
                this.RemoveActionGlyph(comp);
            }
            return(null);
        }
Exemplo n.º 2
0
            protected override IComponent[] CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
            {
                IDesignerSerializationService ds = (IDesignerSerializationService)host.GetService(typeof(IDesignerSerializationService));

                if (ds == null)
                {
                    return(null);
                }

                // Deserialize to components collection
                //
                ICollection objects    = ds.Deserialize(_serializationData);
                ArrayList   components = new ArrayList();

                foreach (object obj in objects)
                {
                    if (obj != null && obj is IComponent)
                    {
                        components.Add(obj);
                    }
                }

                IComponent[] componentsArray = new IComponent[components.Count];
                components.CopyTo(componentsArray, 0);

                ArrayList trayComponents = null;

                // Parent and locate each Control
                //
                if (defaultValues == null)
                {
                    defaultValues = new Hashtable();
                }
                Control parentControl = defaultValues["Parent"] as Control;

                if (parentControl != null)
                {
                    ParentControlDesigner parentControlDesigner = host.GetDesigner(parentControl) as ParentControlDesigner;
                    if (parentControlDesigner != null)
                    {
                        // Determine bounds of all controls
                        //
                        Rectangle bounds = Rectangle.Empty;

                        foreach (IComponent component in componentsArray)
                        {
                            Control childControl = component as Control;

                            if (childControl != null && childControl != parentControl && childControl.Parent == null)
                            {
                                if (bounds.IsEmpty)
                                {
                                    bounds = childControl.Bounds;
                                }
                                else
                                {
                                    bounds = Rectangle.Union(bounds, childControl.Bounds);
                                }
                            }
                        }

                        defaultValues.Remove("Size");    // don't care about the drag size
                        foreach (IComponent component in componentsArray)
                        {
                            Control childControl = component as Control;
                            Form    form         = childControl as Form;
                            if (childControl != null &&
                                !(form != null && form.TopLevel) && // Don't add top-level forms
                                childControl.Parent == null)
                            {
                                defaultValues["Offset"] = new Size(childControl.Bounds.X - bounds.X, childControl.Bounds.Y - bounds.Y);
                                parentControlDesigner.AddControl(childControl, defaultValues);
                            }
                        }
                    }
                }

                // VSWhidbey 516338 - When creating an item for the tray, template items will have
                // an old location stored in them, so they may show up on top of other items.
                // So we need to call UpdatePastePositions for each one to get the tray to
                // arrange them properly.
                //
                ComponentTray tray = (ComponentTray)host.GetService(typeof(ComponentTray));

                if (tray != null)
                {
                    foreach (IComponent component in componentsArray)
                    {
                        ComponentTray.TrayControl c = tray.GetTrayControlFromComponent(component);

                        if (c != null)
                        {
                            if (trayComponents == null)
                            {
                                trayComponents = new ArrayList();
                            }

                            trayComponents.Add(c);
                        }
                    }

                    if (trayComponents != null)
                    {
                        tray.UpdatePastePositions(trayComponents);
                    }
                }

                return(componentsArray);
            }