Exemple #1
0
        public ToolboxItemToolboxNode(ToolboxItem item)
            : base(item.TypeName, item.AssemblyName.FullName)
        {
            base.Name = item.DisplayName;
            if (item.Bitmap != null)
            {
                base.Icon = ImageToPixbuf(item.Bitmap);
            }

            foreach (ToolboxItemFilterAttribute tbfa in item.Filter)
            {
                base.ItemFilters.Add(tbfa);
            }

            //we only need to serialise the ToolboxItem if it is non-standard, because we can reliably recreate the two built-in types
            if (item.GetType() == typeof(ToolboxItem))
            {
                toolboxItemType = null; //no-op, but this has consequences
            }
            else if (item.GetType() == typeof(System.Web.UI.Design.WebControlToolboxItem))
            {
                toolboxItemType = new TypeReference(typeof(System.Web.UI.Design.WebControlToolboxItem));
            }
            else
            {
                serializedToolboxItem = SerializeToolboxItem(item);
                toolboxItemType       = new TypeReference(item.GetType());
            }
        }
Exemple #2
0
        /// <summary>
        /// true if can drop item from selected toolbox item
        /// </summary>
        /// <returns></returns>
        public bool CanDropFromSelectedToolboxItem(DragEventArgs de, bool isOnTable)
        {
            bool        canDrop     = true;
            ToolboxItem toolboxItem = GetToolboxItem(de) ?? SelectedToolboxItem;

            if (toolboxItem != null)
            {
                IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
                Type          type;
                CanParentArgs canParentArgs;
                if (toolboxItem is ICanParentArgsProvider)
                {
                    canParentArgs = ((ICanParentArgsProvider)toolboxItem).GetCanParentArgs(host, isOnTable, DragOperationType.Drop);
                }
                else
                {
                    type          = toolboxItem.GetType(host);
                    canParentArgs = new CanParentArgs(type, null, DragOperationType.Drop);
                }

                if (canParentArgs.ChildControlType != null)
                {
                    canDrop = CanParent(canParentArgs);
                }
                else
                {
                    canDrop = false;
                }
            }
            return(canDrop);
        }
Exemple #3
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);
 }
Exemple #4
0
        public void ToolBoxItem_Constructor()
        {
            var         type      = typeof(Bitmap);
            ToolboxItem underTest = new ToolboxItem(type);

            Assert.Equal("System.Drawing.Bitmap", underTest.TypeName);
            Assert.Equal("Bitmap", underTest.DisplayName);
            Assert.Equal("Bitmap", underTest.ToString());
            Assert.False(underTest.Locked);
            Assert.True(underTest.GetType().IsSerializable);
        }
Exemple #5
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);
 }
        public override void OnDragDrop(Glyph g, DragEventArgs e)
        {
            ToolStripPanelSelectionGlyph glyph = g as ToolStripPanelSelectionGlyph;
            bool      flag     = false;
            ArrayList controls = null;

            DropSourceBehavior.BehaviorDataObject data = e.Data as DropSourceBehavior.BehaviorDataObject;
            if (data == null)
            {
                if ((e.Data is DataObject) && (controls == null))
                {
                    IToolboxService service = (IToolboxService)this.serviceProvider.GetService(typeof(IToolboxService));
                    IDesignerHost   host    = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;
                    if ((service != null) && (host != null))
                    {
                        ToolboxItem tool = service.DeserializeToolboxItem(e.Data, host);
                        if (((tool.GetType(host) == typeof(ToolStrip)) || (tool.GetType(host) == typeof(MenuStrip))) || (tool.GetType(host) == typeof(StatusStrip)))
                        {
                            ToolStripPanelDesigner designer = host.GetDesigner(this.relatedControl) as ToolStripPanelDesigner;
                            if (designer != null)
                            {
                                OleDragDropHandler oleDragHandler = designer.GetOleDragHandler();
                                if (oleDragHandler != null)
                                {
                                    oleDragHandler.CreateTool(tool, this.relatedControl, 0, 0, 0, 0, false, false);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                controls = new ArrayList(data.DragComponents);
                foreach (Component component in controls)
                {
                    ToolStrip strip = component as ToolStrip;
                    if ((strip != null) && (strip.Parent != this.relatedControl))
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    Control parent = this.relatedControl.Parent;
                    if (parent != null)
                    {
                        try
                        {
                            parent.SuspendLayout();
                            this.ExpandPanel(false);
                            Rectangle bounds = glyph.Bounds;
                            glyph.IsExpanded = true;
                            this.behaviorService.Invalidate(bounds);
                            this.behaviorService.Invalidate(glyph.Bounds);
                            this.ReParentControls(controls, e.Effect == DragDropEffects.Copy);
                        }
                        finally
                        {
                            parent.ResumeLayout(true);
                        }
                    }
                }
                data.CleanupDrag();
            }
        }
        public void GetType_Null()
        {
            ToolboxItem item = new ToolboxItem();

            Assert.IsNull(item.GetType(null), "GetType(null)");
        }