// This is the code that is executed when you drop a tool from the Toolbox in the designer.
        //

        protected static void InvokeCreateTool(ParentControlDesigner toInvoke, ToolboxItem tool)
        {
            if (toInvoke != null)
            {
                toInvoke.CreateTool(tool);
            }
        }
Ejemplo n.º 2
0
 protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
 {
     if (tool != null)
     {
         System.Type c = tool.GetType(this.designerHost);
         if (!typeof(ToolStrip).IsAssignableFrom(c))
         {
             ToolStripContainer parent = this.panel.Parent as ToolStripContainer;
             if (parent != null)
             {
                 ToolStripContentPanel contentPanel = parent.ContentPanel;
                 if (contentPanel != null)
                 {
                     PanelDesigner toInvoke = this.designerHost.GetDesigner(contentPanel) as PanelDesigner;
                     if (toInvoke != null)
                     {
                         ParentControlDesigner.InvokeCreateTool(toInvoke, tool);
                     }
                 }
             }
         }
         else
         {
             base.CreateToolCore(tool, x, y, width, height, hasLocation, hasSize);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
        // ToolPicked is called when the user double-clicks on a toolbox item.
        // The document designer should create a component for the specified tool.
        // Only tools that are enabled in the toolbox will be passed to this method.
        //
        // I create the component in the parent container of the primary selection.
        // If not available I create it in the rootcomponent (this essentially :-) )
        //
        protected virtual void ToolPicked(ToolboxItem tool)
        {
            ISelectionService selectionSvc = GetService(typeof(ISelectionService)) as ISelectionService;
            IDesignerHost     host         = GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (selectionSvc != null && host != null)
            {
                IDesigner designer = host.GetDesigner((IComponent)selectionSvc.PrimarySelection);
                if (designer is ParentControlDesigner)
                {
                    ParentControlDesigner.InvokeCreateTool((ParentControlDesigner)designer, tool);
                }
                else
                {
                    this.CreateTool(tool);
                }
            }
            else
            {
                this.CreateTool(tool);
            }
            IToolboxService tbServ = this.GetService(typeof(IToolboxService)) as IToolboxService;

            tbServ.SelectedToolboxItemUsed();
        }
        protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
        {
            if (this.Selected == null)
            {
                this.Selected = this.splitterPanel1;
            }
            SplitterPanelDesigner toInvoke = (SplitterPanelDesigner)this.designerHost.GetDesigner(this.Selected);

            ParentControlDesigner.InvokeCreateTool(toInvoke, tool);
            return(null);
        }
        // Called by the parent ParentControlDesigner when it is populating the grid-related
        // design-time properties changes
        //
        private void OnParentGridPropertiesChanged(ParentControlDesigner parentDesigner)
        {
            SetValue(this.Component, "DrawGrid", (bool)GetValue(parentDesigner.Component, "DrawGrid"));
            SetValue(this.Component, "SnapToGrid", (bool)GetValue(parentDesigner.Component, "SnapToGrid"));
            SetValue(this.Component, "GridSize", (Size)GetValue(parentDesigner.Component, "GridSize"));

            // Set also the default values to be those, because we should
            // match the parent ParentControlDesigner values.
            // called recursivly, so I will rather go for slower, but no stack-overflowable code
            //
            _defaultDrawGrid   = (bool)GetValue(parentDesigner.Component, "DrawGrid");
            _defaultSnapToGrid = (bool)GetValue(parentDesigner.Component, "SnapToGrid");
            _defaultGridSize   = (Size)GetValue(parentDesigner.Component, "GridSize");

            this.PopulateGridProperties();
        }
        protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
        {
            TabControl control = (TabControl)this.Control;

            if (control.SelectedTab == null)
            {
                throw new ArgumentException(System.Design.SR.GetString("TabControlInvalidTabPageType", new object[] { tool.DisplayName }));
            }
            IDesignerHost service = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            if (service != null)
            {
                TabPageDesigner toInvoke = (TabPageDesigner)service.GetDesigner(control.SelectedTab);
                ParentControlDesigner.InvokeCreateTool(toInvoke, tool);
            }
            return(null);
        }
 // Retrieves the ParentControlDesigner of the specified control if available,
 // else returns null.
 //
 private ParentControlDesigner GetParentControlDesignerOf(Control control)
 {
     if (control != null)
     {
         IDesignerHost designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost;
         if (designerHost != null)
         {
             ParentControlDesigner designer = null;
             designer = designerHost.GetDesigner(this.Control.Parent) as ParentControlDesigner;
             if (designer != null)
             {
                 return(designer);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 8
0
 protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
 {
     if (tool != null)
     {
         System.Type c = tool.GetType(this.designerHost);
         if (typeof(StatusStrip).IsAssignableFrom(c))
         {
             ParentControlDesigner.InvokeCreateTool(this.GetDesigner(this.bottomToolStripPanel), tool);
         }
         else if (typeof(ToolStrip).IsAssignableFrom(c))
         {
             ParentControlDesigner.InvokeCreateTool(this.GetDesigner(this.topToolStripPanel), tool);
         }
         else
         {
             ParentControlDesigner.InvokeCreateTool(this.GetDesigner(this.contentToolStripPanel), tool);
         }
     }
     return(null);
 }
        // Informs all children controls' ParentControlDesigners that the grid properties
        // have changed and passes them
        //
        private void PopulateGridProperties()
        {
            // Control.Invalidate (true) will redraw the control and it's children
            // this will cause a WM_PAINT message to be send and the ControlDesigenr will raise
            // the OnPaintAdornments, where the grid drawing takes place.
            //
            // Note that this should be called *after* the grid properties have changed :-)
            //
            this.Control.Invalidate(false);

            if (this.Control != null)
            {
                ParentControlDesigner designer = null;
                foreach (Control control in this.Control.Controls)
                {
                    designer = this.GetParentControlDesignerOf(control);
                    if (designer != null)
                    {
                        designer.OnParentGridPropertiesChanged(this);
                    }
                }
            }
        }
Ejemplo n.º 10
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);
            }
        // Settings paths taken from the example at:
        // http://msdn2.microsoft.com/en-us/library/system.componentmodel.design.idesigneroptionservice.aspx
        //
        public override void Initialize(IComponent component)
        {
            base.Initialize(component);

            this.Control.AllowDrop = true;

            // Initialize the default values of the Design-Time properties.
            //
            _defaultDrawGrid   = true;
            _defaultSnapToGrid = true;
            _defaultGridSize   = new Size(8, 8);

            // If the parent Control of the designed one has a ParentDesigner then inherit the values
            // from it's designer.
            //
            if (this.Control.Parent != null)
            {
                ParentControlDesigner parentDesigner = GetParentControlDesignerOf(Control.Parent);
                if (parentDesigner != null)
                {
                    _defaultDrawGrid   = (bool)GetValue(parentDesigner.Component, "DrawGrid");
                    _defaultSnapToGrid = (bool)GetValue(parentDesigner.Component, "SnapToGrid");
                    _defaultGridSize   = (Size)GetValue(parentDesigner.Component, "GridSize");
                }
            }
            else
            {
                // Else retrieve them through the IDesignerOptionService (if available)
                //
                IDesignerOptionService options = GetService(typeof(IDesignerOptionService)) as
                                                 IDesignerOptionService;
                if (options != null)
                {
                    object value = null;
                    value = options.GetOptionValue(@"WindowsFormsDesigner\General", "DrawGrid");
                    if (value is bool)
                    {
                        _defaultDrawGrid = (bool)value;
                    }

                    value = options.GetOptionValue(@"WindowsFormsDesigner\General", "SnapToGrid");
                    if (value is bool)
                    {
                        _defaultSnapToGrid = (bool)value;
                    }

                    value = options.GetOptionValue(@"WindowsFormsDesigner\General", "GridSize");
                    if (value is Size)
                    {
                        _defaultGridSize = (Size)value;
                    }
                }
            }

            IComponentChangeService componentChangeSvc = GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (componentChangeSvc != null)
            {
                componentChangeSvc.ComponentRemoving += new ComponentEventHandler(OnComponentRemoving);
                componentChangeSvc.ComponentRemoved  += new ComponentEventHandler(OnComponentRemoved);
            }

            // At the end set whatever we've managed to get
            //
            _drawGrid   = _defaultDrawGrid;
            _snapToGrid = _defaultSnapToGrid;
            _gridSize   = _defaultGridSize;
        }
 /// <summary>
 ///  Creates a new escape handler.
 /// </summary>
 public EscapeHandler(ParentControlDesigner designer)
 {
     this.designer = designer;
 }
 protected static void InvokeCreateTool(ParentControlDesigner toInvoke, ToolboxItem tool)
 {
     toInvoke.CreateTool(tool);
 }
 public EscapeHandler(ParentControlDesigner designer)
 {
     this.designer = designer;
 }
Ejemplo n.º 15
0
 protected static void InvokeCreateTool(ParentControlDesigner toInvoke, ToolboxItem tool)
 {
     // TODO
 }
        public void ChangeParent()
        {
            Cursor current = Cursor.Current;
            DesignerTransaction transaction = this._host.CreateTransaction("Add ToolStripContainer Transaction");

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Control rootComponent          = this._host.RootComponent as Control;
                ParentControlDesigner designer = this._host.GetDesigner(rootComponent) as ParentControlDesigner;
                if (designer != null)
                {
                    ToolStrip component = this._designer.Component as ToolStrip;
                    if (((component != null) && (this._designer != null)) && ((this._designer.Component != null) && (this._provider != null)))
                    {
                        (this._provider.GetService(typeof(DesignerActionUIService)) as DesignerActionUIService).HideUI(component);
                    }
                    ToolboxItem        tool           = new ToolboxItem(typeof(ToolStripContainer));
                    OleDragDropHandler oleDragHandler = designer.GetOleDragHandler();
                    if (oleDragHandler != null)
                    {
                        ToolStripContainer container = oleDragHandler.CreateTool(tool, rootComponent, 0, 0, 0, 0, false, false)[0] as ToolStripContainer;
                        if ((container != null) && (component != null))
                        {
                            IComponentChangeService service = this._provider.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                            Control            parent       = this.GetParent(container, component);
                            PropertyDescriptor member       = TypeDescriptor.GetProperties(parent)["Controls"];
                            Control            control3     = component.Parent;
                            if (control3 != null)
                            {
                                service.OnComponentChanging(control3, member);
                                control3.Controls.Remove(component);
                            }
                            if (parent != null)
                            {
                                service.OnComponentChanging(parent, member);
                                parent.Controls.Add(component);
                            }
                            if (((service != null) && (control3 != null)) && (parent != null))
                            {
                                service.OnComponentChanged(control3, member, null, null);
                                service.OnComponentChanged(parent, member, null, null);
                            }
                            ISelectionService service3 = this._provider.GetService(typeof(ISelectionService)) as ISelectionService;
                            if (service3 != null)
                            {
                                service3.SetSelectedComponents(new IComponent[] { container });
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                if (exception is InvalidOperationException)
                {
                    ((IUIService)this._provider.GetService(typeof(IUIService))).ShowError(exception.Message);
                }
                if (transaction != null)
                {
                    transaction.Cancel();
                    transaction = null;
                }
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Commit();
                    transaction = null;
                }
                Cursor.Current = current;
            }
        }
        // Reminder: We set control.Parent so that it gets serialized for Undo/Redo
        //
        private void Paste(object sender, EventArgs args)
        {
            IDesignerSerializationService stateSerializer = GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService;
            ISelectionService             selection       = GetService(typeof(ISelectionService)) as ISelectionService;
            IDesignerHost           host          = GetService(typeof(IDesignerHost)) as IDesignerHost;
            IComponentChangeService changeService = GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (host == null || stateSerializer == null)
            {
                return;
            }
            //
            // TODO: MWF X11 doesn't seem to support custom clipboard formats - bug #357642
            //
            // IDataObject dataObject = Clipboard.GetDataObject ();
            // byte[] data = dataObject == null ? null : dataObject.GetData (DT_DATA_FORMAT) as byte[];
            // if (data != null) {
            //  MemoryStream stream = new MemoryStream (data);
            //  stateSerializer.Deserialize (new BinaryFormatter().Deserialize (stream));
            // .....
            // }
            //
            if (_clipboard == null)
            {
                return;
            }

            DesignerTransaction transaction = host.CreateTransaction("Paste");
            ICollection         components  = stateSerializer.Deserialize(_clipboard);

            // Console.WriteLine ("Pasted components: ");
            // foreach (object c in components)
            //  Console.WriteLine (((IComponent)c).Site.Name);
            foreach (object component in components)
            {
                Control control = component as Control;
                if (control == null)
                {
                    continue; // pure Components are added to the ComponentTray by the DocumentDesigner
                }
                PropertyDescriptor parentProperty = TypeDescriptor.GetProperties(control)["Parent"];
                if (control.Parent != null)
                {
                    // Already parented during deserialization?
                    // In that case explicitly raise component changing/ed for the Parent property,
                    // so it get's cought by the UndoEngine
                    if (changeService != null)
                    {
                        changeService.OnComponentChanging(control, parentProperty);
                        changeService.OnComponentChanged(control, parentProperty, null, control.Parent);
                    }
                }
                else
                {
                    ParentControlDesigner parentDesigner = null;
                    if (selection != null && selection.PrimarySelection != null)
                    {
                        parentDesigner = host.GetDesigner((IComponent)selection.PrimarySelection) as ParentControlDesigner;
                    }
                    if (parentDesigner == null)
                    {
                        parentDesigner = host.GetDesigner(host.RootComponent) as DocumentDesigner;
                    }
                    if (parentDesigner != null && parentDesigner.CanParent(control))
                    {
                        parentProperty.SetValue(control, parentDesigner.Control);
                    }
                }
            }
            _clipboard = null;
            transaction.Commit();
            ((IDisposable)transaction).Dispose();
        }
Ejemplo n.º 18
0
		internal DesignerHost(BrowserTree objTree, Panel imagePanel)
		{
			_imagePanel = imagePanel;
			if (_host == null) {
				_host = this;
				_serviceContainer = new ServiceContainer();
				_serviceContainer.AddService(typeof(IDesignerHost), _host);
				_serviceContainer.AddService(typeof(IUIService), _host);
				_serviceContainer.AddService(typeof(ISelectionService), _host);
				_serviceContainer.AddService(typeof(IToolboxService), new ToolboxService());
			}

			_container = new DesignerContainer(this);
			_defaultSite = new DesignerSite(this, null, _container,	"Default site");

			_designSurfaceSite = (DesignerSite)_container.CreateSite(_imagePanel, "Design Surface");

			// Hook the design surface to the ParentControlDesigner
			_parentControlDesigner = new DummyDesigner();
			_imagePanel.Site = _designSurfaceSite;
			_designSurfaceSite.Designer = _parentControlDesigner;
			_parentControlDesigner.Initialize(_imagePanel);

			// Used to make sure we don't give a designer for anything higher
			// than the design surface (GetDesigner is called on the 
			// surface's parent)
			_designSurfaceParent = ((Control)_imagePanel).Parent;

			// Get the type for the UI selection service, since its private
			// the compiler will not let us see it
			_typeISelectionUIService = ReflectionHelper.GetType("System.Windows.Forms.Design.ISelectionUIService");

			// This is required to get an instance of the selection 
			// UI service installed, we don't actually use this 
			// designer for anything
			_fakePanel = new Panel();
			IDesigner compDes = new ComponentDocumentDesigner();
			_fakePanel.Site = _container.CreateSite(_fakePanel, "Fake Design Surface");
			compDes.Initialize(_fakePanel);

			// Make the size of the selection service cover the design
			// surface panel so that it will see all of the events
			_selUIService = (Control)GetService(_typeISelectionUIService);
			ObjectBrowser.ImagePanel.ResetSize(_selUIService);
			_imagePanel.Controls.Add(_selUIService);
			_imagePanel.SizeChanged += new EventHandler(ImagePanelSizeChange);

			DesignMode = true;

			// So we change the object selected when a control is selected
			SelectionChanged += new EventHandler(objTree.ControlSelectionChanged);
		}
Ejemplo n.º 19
0
        public void DoOleDragDrop(DragEventArgs de)
        {
            // ASURT 43757: By the time we come here, it means that the user completed the drag-drop and
            // we compute the new location/size of the controls if needed and set the property values.
            // We have to stop freezePainting right here, so that controls can get a chance to validate
            // their new rects.
            //
            freezePainting = false;

            if (selectionHandler == null)
            {
                Debug.Fail("selectionHandler should not be null");
                de.Effect = DragDropEffects.None;
                return;
            }

            // make sure we've actually moved
            if ((localDrag && de.X == dragBase.X && de.Y == dragBase.Y) ||
                de.AllowedEffect == DragDropEffects.None ||
                (!localDrag && !dragOk))
            {
                de.Effect = DragDropEffects.None;
                return;
            }

            bool localMoveOnly = ((int)de.AllowedEffect & AllowLocalMoveOnly) != 0 && localDragInside;

            // if we are dragging inside the local dropsource/target, and and AllowLocalMoveOnly flag is set,
            // we just consider this a normal move.
            //
            bool moveAllowed = (de.AllowedEffect & DragDropEffects.Move) != DragDropEffects.None || localMoveOnly;
            bool copyAllowed = (de.AllowedEffect & DragDropEffects.Copy) != DragDropEffects.None;

            if ((de.Effect & DragDropEffects.Move) != 0 && !moveAllowed)
            {
                // Try copy instead?
                de.Effect = DragDropEffects.Copy;
            }

            // make sure the copy is allowed
            if ((de.Effect & DragDropEffects.Copy) != 0 && !copyAllowed)
            {
                // if copy isn't allowed, don't do anything

                de.Effect = DragDropEffects.None;
                return;
            }

            if (localMoveOnly && (de.Effect & DragDropEffects.Move) != 0)
            {
                de.Effect |= (DragDropEffects)AllowLocalMoveOnly | DragDropEffects.Move;
            }
            else if ((de.Effect & DragDropEffects.Copy) != 0)
            {
                de.Effect = DragDropEffects.Copy;
            }

            if (forceDrawFrames || localDragInside)
            {
                // undraw the drag rect
                localDragOffset = DrawDragFrames(dragComps, localDragOffset, localDragEffect,
                                                 Point.Empty, DragDropEffects.None, forceDrawFrames);
                forceDrawFrames = false;
            }

            Cursor oldCursor = Cursor.Current;

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                if (dragOk || (localDragInside && de.Effect == DragDropEffects.Copy))
                {
                    // add em to this parent.
                    IDesignerHost host      = (IDesignerHost)GetService(typeof(IDesignerHost));
                    IContainer    container = host.RootComponent.Site.Container;

                    object[]    components;
                    IDataObject dataObj        = de.Data;
                    bool        updateLocation = false;

                    if (dataObj is ComponentDataObjectWrapper)
                    {
                        dataObj = ((ComponentDataObjectWrapper)dataObj).InnerData;
                        ComponentDataObject cdo = (ComponentDataObject)dataObj;

                        // if we're moving ot a different container, do a full serialization
                        // to make sure we pick up design time props, etc.
                        //
                        IComponent dragOwner        = GetDragOwnerComponent(de.Data);
                        bool       newContainer     = dragOwner == null || client.Component == null || dragOwner.Site.Container != client.Component.Site.Container;
                        bool       collapseChildren = false;
                        if (de.Effect == DragDropEffects.Copy || newContainer)
                        {
                            // this causes new elements to be created
                            //
                            cdo.Deserialize(serviceProvider, (de.Effect & DragDropEffects.Copy) == 0);
                        }
                        else
                        {
                            collapseChildren = true;
                        }

                        updateLocation = true;
                        components     = cdo.Components;

                        if (collapseChildren)
                        {
                            components = GetTopLevelComponents(components);
                        }
                    }
                    else
                    {
                        object serializationData = dataObj.GetData(DataFormat, true);

                        if (serializationData == null)
                        {
                            Debug.Fail("data object didn't return any data, so how did we allow the drop?");
                            components = Array.Empty <IComponent>();
                        }
                        else
                        {
                            dataObj        = new ComponentDataObject(client, serviceProvider, serializationData);
                            components     = ((ComponentDataObject)dataObj).Components;
                            updateLocation = true;
                        }
                    }

                    // now we need to offset the components locations from the drop mouse
                    // point to the parent, since their current locations are relative
                    // the the mouse pointer
                    if (components != null && components.Length > 0)
                    {
                        Debug.Assert(container != null, "Didn't get a container from the site!");
                        string     name;
                        IComponent comp = null;

                        DesignerTransaction trans = null;

                        try
                        {
                            trans = host.CreateTransaction(SR.DragDropDropComponents);
                            if (!localDrag)
                            {
                                host.Activate();
                            }

                            ArrayList selectComps = new ArrayList();

                            for (int i = 0; i < components.Length; i++)
                            {
                                comp = components[i] as IComponent;

                                if (comp == null)
                                {
                                    comp = null;
                                    continue;
                                }

                                try
                                {
                                    name = null;
                                    if (comp.Site != null)
                                    {
                                        name = comp.Site.Name;
                                    }

                                    Control oldDesignerControl = null;
                                    if (updateLocation)
                                    {
                                        oldDesignerControl = client.GetDesignerControl();
                                        User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW);
                                    }

                                    Point dropPt = client.GetDesignerControl().PointToClient(new Point(de.X, de.Y));

                                    // First check if the component we are dropping have a TrayLocation, and if so, use it
                                    PropertyDescriptor loc = TypeDescriptor.GetProperties(comp)["TrayLocation"];
                                    if (loc == null)
                                    {
                                        // it didn't, so let's check for the regular Location
                                        loc = TypeDescriptor.GetProperties(comp)["Location"];
                                    }

                                    if (loc != null && !loc.IsReadOnly)
                                    {
                                        Rectangle bounds = new Rectangle();
                                        Point     pt     = (Point)loc.GetValue(comp);
                                        bounds.X = dropPt.X + pt.X;
                                        bounds.Y = dropPt.Y + pt.Y;
                                        bounds   = selectionHandler.GetUpdatedRect(Rectangle.Empty, bounds, false);
                                    }

                                    if (!client.AddComponent(comp, name, false))
                                    {
                                        // this means that we just moved the control
                                        // around in the same designer.

                                        de.Effect = DragDropEffects.None;
                                    }
                                    else
                                    {
                                        // make sure the component was added to this client
                                        if (client.GetControlForComponent(comp) == null)
                                        {
                                            updateLocation = false;
                                        }
                                    }

                                    if (updateLocation)
                                    {
                                        ParentControlDesigner parentDesigner = client as ParentControlDesigner;
                                        if (parentDesigner != null)
                                        {
                                            Control c = client.GetControlForComponent(comp);
                                            dropPt     = parentDesigner.GetSnappedPoint(c.Location);
                                            c.Location = dropPt;
                                        }
                                    }

                                    if (oldDesignerControl != null)
                                    {
                                        //((ComponentDataObject)dataObj).ShowControls();
                                        User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW, (IntPtr)1);
                                        oldDesignerControl.Invalidate(true);
                                    }

                                    if (TypeDescriptor.GetAttributes(comp).Contains(DesignTimeVisibleAttribute.Yes))
                                    {
                                        selectComps.Add(comp);
                                    }
                                }
                                catch (CheckoutException ceex)
                                {
                                    if (ceex == CheckoutException.Canceled)
                                    {
                                        break;
                                    }

                                    throw;
                                }
                            }

                            if (host != null)
                            {
                                host.Activate();
                            }

                            // select the newly added components
                            ISelectionService selService = (ISelectionService)GetService(typeof(ISelectionService));

                            selService.SetSelectedComponents((object[])selectComps.ToArray(typeof(IComponent)), SelectionTypes.Replace);
                            localDragInside = false;
                        }
                        finally
                        {
                            if (trans != null)
                            {
                                trans.Commit();
                            }
                        }
                    }
                }

                if (localDragInside)
                {
                    ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService));
                    Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control");

                    if (selectionUISvc != null)
                    {
                        // We must check to ensure that UI service is still in drag mode.  It is
                        // possible that the user hit escape, which will cancel drag mode.
                        //
                        if (selectionUISvc.Dragging && moveAllowed)
                        {
                            Rectangle offset = new Rectangle(de.X - dragBase.X, de.Y - dragBase.Y, 0, 0);
                            selectionUISvc.DragMoved(offset);
                        }
                    }
                }

                dragOk = false;
            }
            finally
            {
                Cursor.Current = oldCursor;
            }
        }
Ejemplo n.º 20
0
		// Called by the parent ParentControlDesigner when it is populating the grid-related
		// design-time properties changes
		//
		private void OnParentGridPropertiesChanged (ParentControlDesigner parentDesigner)
		{
			SetValue (this.Component, "DrawGrid", (bool) GetValue (parentDesigner.Component, "DrawGrid"));
			SetValue (this.Component, "SnapToGrid", (bool) GetValue (parentDesigner.Component, "SnapToGrid"));
			SetValue (this.Component, "GridSize", (Size) GetValue (parentDesigner.Component, "GridSize"));

			// Set also the default values to be those, because we should
			// match the parent ParentControlDesigner values.
			// called recursivly, so I will rather go for slower, but no stack-overflowable code
			// 
			_defaultDrawGrid = (bool) GetValue (parentDesigner.Component, "DrawGrid");
			_defaultSnapToGrid = (bool) GetValue (parentDesigner.Component, "SnapToGrid");
			_defaultGridSize = (Size) GetValue (parentDesigner.Component, "GridSize");

			this.PopulateGridProperties ();
		}