Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        /// <include file='doc\VsWindowPane.uex' path='docs/doc[@for="VsWindowPane.IVsToolboxUser.ItemPicked"]/*' />
        /// <devdoc>
        ///     This happens when a user double-clicks a toolbox item.  We add the
        ///     item to the center of the form.
        /// </devdoc>
        void IVsToolboxUser.ItemPicked(NativeMethods.IOleDataObject pDO)
        {
            if (toolboxService == null)
            {
                toolboxService = (IToolboxService)GetService((typeof(IToolboxService)));
            }

            if (toolboxService != null)
            {
                ToolboxItem item = toolboxService.DeserializeToolboxItem(pDO, DesignerHost);

                if (item != null)
                {
                    if (OnToolPicked(item))
                    {
                        toolboxService.SelectedToolboxItemUsed();
                    }
                }
            }

            if (toolboxUser == null)
            {
                toolboxUser = (IVsToolboxUser)GetService(typeof(IVsToolboxUser));
            }

            if (toolboxUser != null)
            {
                toolboxUser.ItemPicked(pDO);
            }
        }
Exemplo n.º 3
0
        /// <include file='doc\CompositionDesigner.uex' path='docs/doc[@for="ComponentDocumentDesigner.IToolboxUser.ToolPicked"]/*' />
        /// <internalonly/>
        /// <devdoc>
        /// <para>Creates the specified tool.</para>
        /// </devdoc>
        void IToolboxUser.ToolPicked(ToolboxItem tool)
        {
            compositionUI.CreateComponentFromTool(tool);
            IToolboxService toolboxService = (IToolboxService)GetService(typeof(IToolboxService));

            if (toolboxService != null)
            {
                toolboxService.SelectedToolboxItemUsed();
            }
        }
Exemplo n.º 4
0
        protected override void OnMouseDragEnd(bool cancel)
        {
            IUISelectionService selectionServ = this.GetService(typeof(IUISelectionService)) as IUISelectionService;

            if (selectionServ != null)
            {
                // If there is a Toolbox component seleted then create it instead of finishing the selection
                IToolboxService toolBoxService = this.GetService(typeof(IToolboxService)) as IToolboxService;
                if (!cancel && toolBoxService != null && toolBoxService.GetSelectedToolboxItem() != null)
                {
                    if (selectionServ.SelectionInProgress)
                    {
                        bool hasSize = selectionServ.SelectionBounds.Width > 0 &&
                                       selectionServ.SelectionBounds.Height > 0;
                        CreateToolCore(toolBoxService.GetSelectedToolboxItem(),
                                       selectionServ.SelectionBounds.X,
                                       selectionServ.SelectionBounds.Y,
                                       selectionServ.SelectionBounds.Width,
                                       selectionServ.SelectionBounds.Height,
                                       true, hasSize);
                        toolBoxService.SelectedToolboxItemUsed();
                        cancel = true;
                    }
                    else if (!selectionServ.SelectionInProgress &&
                             !selectionServ.ResizeInProgress && !selectionServ.DragDropInProgress)
                    {
                        CreateTool(toolBoxService.GetSelectedToolboxItem(), _mouseDownPoint);
                        toolBoxService.SelectedToolboxItemUsed();
                        cancel = true;
                    }
                }

                if (selectionServ.SelectionInProgress || selectionServ.ResizeInProgress)
                {
                    selectionServ.MouseDragEnd(cancel);
                }
            }
        }
Exemplo n.º 5
0
        private void OnClientViewDragDrop(object sender, DragEventArgs e)
        {
            if (Diagram != null)
            {
                myHostWindow.Show();
                DiagramClientView.Focus();
            }
            IToolboxService toolboxService = Toolbox;

            if (toolboxService != null)
            {
                toolboxService.SelectedToolboxItemUsed();
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        private void OnRowActivated(object sender, RowActivatedArgs e)
        {
            ItemToolboxNode activatedNode = store.GetNode(e.Path) as ItemToolboxNode;

            DesignerHost    host           = parentServices.GetService(typeof(IDesignerHost)) as DesignerHost;
            IToolboxService toolboxService = parentServices.GetService(typeof(IToolboxService)) as IToolboxService;

            //toolboxitem needs to trigger extra events from toolboxService
            if (selectedNode is ToolboxItemToolboxNode)
            {
                if (toolboxService == null || host == null)
                {
                    return;
                }
                toolboxService.SetSelectedToolboxItem(((ToolboxItemToolboxNode)activatedNode).ToolboxItem);
                activatedNode.Activate(host);
                toolboxService.SelectedToolboxItemUsed();
            }
            else
            {
                activatedNode.Activate(host);
            }
        }
Exemplo n.º 8
0
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            if (drgevent.Effect == DragDropEffects.Copy)
            {
                (designerHost.RootComponent as Control).SuspendLayout();

                IToolboxService   tbsvc  = designerHost.GetService(typeof(IToolboxService)) as IToolboxService;
                IToolboxUser      tbu    = designerHost.GetDesigner(designerHost.RootComponent) as IToolboxUser;
                ISelectionService selsvc = designerHost.GetService(typeof(ISelectionService)) as ISelectionService;

                DesignerTransaction transaction = designerHost.CreateTransaction("DoDragDrop");

                //避免当前有选中控件,会把新创建的控件放到选中控件中
                selsvc.SetSelectedComponents(null);

                ToolboxItem item = drgevent.Data.GetData(typeof(ToolboxItem)) as ToolboxItem;
                tbu.ToolPicked(item);
                ICollection components = item.CreateComponents();
                tbsvc.SelectedToolboxItemUsed();

                Control createdControl = selsvc.PrimarySelection as Control;
                Point   location1      = PointToScreen(this.Location);
                createdControl.Location = new Point(drgevent.X - location1.X + this.Left, drgevent.Y - location1.Y + this.Top);
                selsvc.SetSelectedComponents(null);
                selsvc.SetSelectedComponents(new Control[] { createdControl });

                transaction.Commit();
                ((IDisposable)transaction).Dispose();

                (designerHost.RootComponent as Control).ResumeLayout();
            }
            else
            {
                base.OnDragDrop(drgevent);
            }
        }
Exemplo n.º 9
0
        public IComponent[] CreateTool(ToolboxItem tool, Control parent, int x, int y, int width, int height, bool hasLocation, bool hasSize, ToolboxSnapDragDropEventArgs e)
        {
            // Services we will need
            //
            IToolboxService   toolboxSvc = (IToolboxService)GetService(typeof(IToolboxService));
            ISelectionService selSvc     = (ISelectionService)GetService(typeof(ISelectionService));
            IDesignerHost     host       = (IDesignerHost)GetService(typeof(IDesignerHost));

            IComponent[] comps = Array.Empty <IComponent>();

            Cursor oldCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;
            DesignerTransaction trans = null;

            try
            {
                try
                {
                    if (host != null)
                    {
                        trans = host.CreateTransaction(string.Format(SR.DesignerBatchCreateTool, tool.ToString()));
                    }
                }
                catch (CheckoutException cxe)
                {
                    if (cxe == CheckoutException.Canceled)
                    {
                        return(comps);
                    }

                    throw;
                }

                try
                {
                    try
                    {
                        // First check if we are currently in localization mode (i.e., language is non-default).
                        // If so, we should not permit addition of new components. This is an intentional
                        // change from Everett - see VSWhidbey #292249.
                        if (host != null && CurrentlyLocalizing(host.RootComponent))
                        {
                            IUIService uiService = (IUIService)GetService(typeof(IUIService));
                            if (uiService != null)
                            {
                                uiService.ShowMessage(SR.LocalizingCannotAdd);
                            }

                            comps = Array.Empty <IComponent>();
                            return(comps);
                        }

                        // Create a dictionary of default values that the designer can
                        // use to initialize a control with.
                        Hashtable defaultValues = new Hashtable();
                        if (parent != null)
                        {
                            defaultValues["Parent"] = parent;
                        }

                        // adjust the location if we are in a mirrored parent. That is because the origin
                        // will then be in the upper right rather than upper left.
                        if (parent != null && parent.IsMirrored)
                        {
                            x += width;
                        }

                        if (hasLocation)
                        {
                            defaultValues["Location"] = new Point(x, y);
                        }
                        if (hasSize)
                        {
                            defaultValues["Size"] = new Size(width, height);
                        }
                        //store off extra behavior drag/drop information
                        if (e != null)
                        {
                            defaultValues["ToolboxSnapDragDropEventArgs"] = e;
                        }

                        comps = tool.CreateComponents(host, defaultValues);
                    }
                    catch (CheckoutException checkoutEx)
                    {
                        if (checkoutEx == CheckoutException.Canceled)
                        {
                            comps = Array.Empty <IComponent>();
                        }
                        else
                        {
                            throw;
                        }
                    }
                    catch (ArgumentException argumentEx)
                    {
                        IUIService uiService = (IUIService)GetService(typeof(IUIService));
                        if (uiService != null)
                        {
                            uiService.ShowError(argumentEx);
                        }
                    }
                    catch (Exception ex)
                    {
                        IUIService uiService = (IUIService)GetService(typeof(IUIService));

                        string exceptionMessage = string.Empty;
                        if (ex.InnerException != null)
                        {
                            exceptionMessage = ex.InnerException.ToString();
                        }

                        if (string.IsNullOrEmpty(exceptionMessage))
                        {
                            exceptionMessage = ex.ToString();
                        }

                        if (ex is InvalidOperationException)
                        {
                            exceptionMessage = ex.Message;
                        }

                        if (uiService != null)
                        {
                            uiService.ShowError(ex, string.Format(SR.FailedToCreateComponent, tool.DisplayName, exceptionMessage));
                        }
                        else
                        {
                            throw;
                        }
                    }

                    if (comps == null)
                    {
                        comps = Array.Empty <IComponent>();
                    }
                }
                finally
                {
                    if (toolboxSvc != null && tool.Equals(toolboxSvc.GetSelectedToolboxItem(host)))
                    {
                        toolboxSvc.SelectedToolboxItemUsed();
                    }
                }
            }
            finally
            {
                if (trans != null)
                {
                    trans.Commit();
                }

                Cursor.Current = oldCursor;
            }

            // Finally, select the newly created components.
            //
            if (selSvc != null && comps.Length > 0)
            {
                if (host != null)
                {
                    host.Activate();
                }

                ArrayList selectComps = new ArrayList(comps);

                for (int i = 0; i < comps.Length; i++)
                {
                    if (!TypeDescriptor.GetAttributes(comps[i]).Contains(DesignTimeVisibleAttribute.Yes))
                    {
                        selectComps.Remove(comps[i]);
                    }
                }

                selSvc.SetSelectedComponents(selectComps.ToArray(), SelectionTypes.Replace);
            }

            codemarkers.CodeMarker((int)CodeMarkerEvent.perfFXDesignCreateComponentEnd);
            return(comps);
        }