protected override void OnOpening(CancelEventArgs e)
 {
     base.Groups["StandardList"].Items.Clear();
     base.Groups["CustomList"].Items.Clear();
     base.Populated = false;
     foreach (ToolStripItem item in ToolStripDesignerUtils.GetStandardItemMenuItems(this.component, this.onClick, this.convertTo))
     {
         base.Groups["StandardList"].Items.Add(item);
         if (this.convertTo)
         {
             ItemTypeToolStripMenuItem item2 = item as ItemTypeToolStripMenuItem;
             if (((item2 != null) && (this.currentItem != null)) && (item2.ItemType == this.currentItem.GetType()))
             {
                 item2.Enabled = false;
             }
         }
     }
     foreach (ToolStripItem item3 in ToolStripDesignerUtils.GetCustomItemMenuItems(this.component, this.onClick, this.convertTo, this.serviceProvider))
     {
         base.Groups["CustomList"].Items.Add(item3);
         if (this.convertTo)
         {
             ItemTypeToolStripMenuItem item4 = item3 as ItemTypeToolStripMenuItem;
             if (((item4 != null) && (this.currentItem != null)) && (item4.ItemType == this.currentItem.GetType()))
             {
                 item4.Enabled = false;
             }
         }
     }
     base.OnOpening(e);
 }
Example #2
0
 private void PopulateList()
 {
     this.insertToolStripMenuItem          = new ToolStripMenuItem();
     this.insertToolStripMenuItem.Text     = System.Design.SR.GetString("ToolStripItemContextMenuInsert");
     this.insertToolStripMenuItem.DropDown = ToolStripDesignerUtils.GetNewItemDropDown(this.ParentTool, this.currentItem, new EventHandler(this.AddNewItemClick), false, this.serviceProvider);
     base.Add(this.insertToolStripMenuItem);
 }
Example #3
0
        protected override void OnOpening(CancelEventArgs e)
        {
            Groups["StandardList"].Items.Clear();
            Groups["CustomList"].Items.Clear();
            Populated = false;

            // plumb through the standard and custom items.
            foreach (ToolStripItem item in ToolStripDesignerUtils.GetStandardItemMenuItems(_component, _onClick, _convertTo))
            {
                Groups["StandardList"].Items.Add(item);
                if (_convertTo)
                {
                    if (item is ItemTypeToolStripMenuItem toolItem && _currentItem != null && toolItem.ItemType == _currentItem.GetType())
                    {
                        toolItem.Enabled = false;
                    }
                }
            }

            foreach (ToolStripItem item in ToolStripDesignerUtils.GetCustomItemMenuItems(_component, _onClick, _convertTo, _serviceProvider))
            {
                Groups["CustomList"].Items.Add(item);
                if (_convertTo)
                {
                    if (item is ItemTypeToolStripMenuItem toolItem && _currentItem != null && toolItem.ItemType == _currentItem.GetType())
                    {
                        toolItem.Enabled = false;
                    }
                }
            }

            base.OnOpening(e);
        }
Example #4
0
 public void GetGlyphs(ref GlyphCollection glyphs, System.Windows.Forms.Design.Behavior.Behavior standardBehavior)
 {
     if (this.ImmediateParent != null)
     {
         Rectangle glyphBounds = this.GetGlyphBounds();
         ToolStripDesignerUtils.GetAdjustedBounds(this.ToolStripItem, ref glyphBounds);
         BehaviorService service = (BehaviorService)this.GetService(typeof(BehaviorService));
         if (service.ControlRectInAdornerWindow((Control)this.ImmediateParent).Contains(glyphBounds.Left, glyphBounds.Top))
         {
             if (this.ToolStripItem.IsOnDropDown)
             {
                 ToolStrip currentParent = this.ToolStripItem.GetCurrentParent();
                 if (currentParent == null)
                 {
                     currentParent = this.ToolStripItem.Owner;
                 }
                 if ((currentParent != null) && currentParent.Visible)
                 {
                     glyphs.Add(new MiniLockedBorderGlyph(glyphBounds, SelectionBorderGlyphType.Top, standardBehavior, true));
                     glyphs.Add(new MiniLockedBorderGlyph(glyphBounds, SelectionBorderGlyphType.Bottom, standardBehavior, true));
                     glyphs.Add(new MiniLockedBorderGlyph(glyphBounds, SelectionBorderGlyphType.Left, standardBehavior, true));
                     glyphs.Add(new MiniLockedBorderGlyph(glyphBounds, SelectionBorderGlyphType.Right, standardBehavior, true));
                 }
             }
             else
             {
                 glyphs.Add(new MiniLockedBorderGlyph(glyphBounds, SelectionBorderGlyphType.Top, standardBehavior, true));
                 glyphs.Add(new MiniLockedBorderGlyph(glyphBounds, SelectionBorderGlyphType.Bottom, standardBehavior, true));
                 glyphs.Add(new MiniLockedBorderGlyph(glyphBounds, SelectionBorderGlyphType.Left, standardBehavior, true));
                 glyphs.Add(new MiniLockedBorderGlyph(glyphBounds, SelectionBorderGlyphType.Right, standardBehavior, true));
             }
         }
     }
 }
Example #5
0
            private void OnFormLoad(object sender, EventArgs e)
            {
                this.newItemTypes.ItemHeight = Math.Max(0x10, this.Font.Height);
                Component instance = base.Context.Instance as Component;

                if (instance != null)
                {
                    System.Type[] standardItemTypes = ToolStripDesignerUtils.GetStandardItemTypes(instance);
                    this.newItemTypes.Items.Clear();
                    foreach (System.Type type in standardItemTypes)
                    {
                        this.newItemTypes.Items.Add(new TypeListItem(type));
                    }
                    this.newItemTypes.SelectedIndex = 0;
                    this.customItemIndex            = -1;
                    standardItemTypes = ToolStripDesignerUtils.GetCustomItemTypes(instance, instance.Site);
                    if (standardItemTypes.Length > 0)
                    {
                        this.customItemIndex = this.newItemTypes.Items.Count;
                        foreach (System.Type type2 in standardItemTypes)
                        {
                            this.newItemTypes.Items.Add(new TypeListItem(type2));
                        }
                    }
                    if (this.listBoxItems.Items.Count > 0)
                    {
                        this.listBoxItems.SelectedIndex = 0;
                    }
                }
            }
        // Gets the painting rect for SelectionRects
        private static Rectangle GetPaintingBounds(IDesignerHost designerHost, ToolStripItem item)
        {
            Rectangle bounds = Rectangle.Empty;

            if (designerHost.GetDesigner(item) is ToolStripItemDesigner itemDesigner)
            {
                bounds = itemDesigner.GetGlyphBounds();
                ToolStripDesignerUtils.GetAdjustedBounds(item, ref bounds);
                // So that the mouseOver glyph matches the selectionGlyph.
                bounds.Inflate(1, 1);
                bounds.Width--;
                bounds.Height--;
            }
            return(bounds);
        }
        private static Rectangle GetPaintingBounds(IDesignerHost designerHost, ToolStripItem item)
        {
            Rectangle             empty    = Rectangle.Empty;
            ToolStripItemDesigner designer = designerHost.GetDesigner(item) as ToolStripItemDesigner;

            if (designer != null)
            {
                empty = designer.GetGlyphBounds();
                ToolStripDesignerUtils.GetAdjustedBounds(item, ref empty);
                empty.Inflate(1, 1);
                empty.Width--;
                empty.Height--;
            }
            return(empty);
        }
        // Occurs when MouseDown on the TooLStripItem glyph
        public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
        {
            ToolStripItemGlyph glyph     = g as ToolStripItemGlyph;
            ToolStripItem      glyphItem = glyph.Item;
            ISelectionService  selSvc    = GetSelectionService(glyphItem);
            BehaviorService    bSvc      = GetBehaviorService(glyphItem);
            ToolStripKeyboardHandlingService keyService = GetKeyBoardHandlingService(glyphItem);

            if ((button == MouseButtons.Left) && (keyService != null) && (keyService.TemplateNodeActive))
            {
                if (keyService.ActiveTemplateNode.IsSystemContextMenuDisplayed)
                {
                    // skip behaviors when the context menu is displayed
                    return(false);
                }
            }

            IDesignerHost designerHost = (IDesignerHost)glyphItem.Site.GetService(typeof(IDesignerHost));

            Debug.Assert(designerHost != null, "Invalid DesignerHost");

            //Cache original selection
            ICollection originalSelComps = null;

            if (selSvc != null)
            {
                originalSelComps = selSvc.GetSelectedComponents();
            }

            // Add the TemplateNode to the Selection if it is currently Selected as the GetSelectedComponents wont do it for us.
            ArrayList origSel = new ArrayList(originalSelComps);

            if (origSel.Count == 0)
            {
                if (keyService != null && keyService.SelectedDesignerControl != null)
                {
                    origSel.Add(keyService.SelectedDesignerControl);
                }
            }

            if (keyService != null)
            {
                keyService.SelectedDesignerControl = null;
                if (keyService.TemplateNodeActive)
                {
                    // If templateNode Active .. commit and Select it
                    keyService.ActiveTemplateNode.CommitAndSelect();
                    // if the selected item is clicked .. then commit the node and reset the selection (refer 488002)
                    if (selSvc.PrimarySelection is ToolStripItem currentSel && currentSel == glyphItem)
                    {
                        selSvc.SetSelectedComponents(null, SelectionTypes.Replace);
                    }
                }
            }

            if (selSvc == null || MouseHandlerPresent(glyphItem))
            {
                return(false);
            }

            if (glyph != null && button == MouseButtons.Left)
            {
                ToolStripItem selectedItem = selSvc.PrimarySelection as ToolStripItem;
                // Always set the Drag-Rect for Drag-Drop...
                SetParentDesignerValuesForDragDrop(glyphItem, true, mouseLoc);
                // Check if this item is already selected ...
                if (selectedItem != null && selectedItem == glyphItem)
                {
                    // If the Selecteditem is already in editmode ... bail out
                    if (selectedItem != null)
                    {
                        ToolStripItemDesigner selectedItemDesigner = glyph.ItemDesigner;
                        if (selectedItemDesigner != null && selectedItemDesigner.IsEditorActive)
                        {
                            return(false);
                        }
                    }

                    // Check if this is CTRL + Click or SHIFT + Click, if so then just remove the selection
                    bool removeSel = (Control.ModifierKeys & (Keys.Control | Keys.Shift)) > 0;
                    if (removeSel)
                    {
                        selSvc.SetSelectedComponents(new IComponent[] { selectedItem }, SelectionTypes.Remove);
                        return(false);
                    }

                    //start Double Click Timer
                    // This is required for the second down in selection which can be the first down of a Double click on the glyph confusing... hence this comment ...
                    // Heres the scenario ....
                    // DOWN 1 - selects the ITEM
                    // DOWN 2 - ITEM goes into INSITU....
                    // DOUBLE CLICK - dont show code..
                    // Open INSITU after the double click time
                    if (selectedItem is ToolStripMenuItem)
                    {
                        _timer = new Timer
                        {
                            Interval = SystemInformation.DoubleClickTime
                        };
                        _timer.Tick   += new EventHandler(OnDoubleClickTimerTick);
                        _timer.Enabled = true;
                        _selectedGlyph = glyph;
                    }
                }
                else
                {
                    bool shiftPressed = (Control.ModifierKeys & Keys.Shift) > 0;
                    // We should process MouseDown only if we are not yet selected....
                    if (!selSvc.GetComponentSelected(glyphItem))
                    {
                        //Reset the State... On the Glpyhs .. we get MouseDown - Mouse UP (for single Click) And we get MouseDown - MouseUp - DoubleClick - Up (for double Click) Hence reset the state at start....
                        _mouseUpFired     = false;
                        _doubleClickFired = false;
                        //Implementing Shift + Click....
                        // we have 2 items, namely, selectedItem (current PrimarySelection) and glyphItem (item which has received mouseDown) FIRST check if they have common parent...  IF YES then get the indices of the two and SELECT all items from LOWER index to the HIGHER index.
                        if (shiftPressed && (selectedItem != null && CommonParent(selectedItem, glyphItem)))
                        {
                            ToolStrip parent = null;
                            if (glyphItem.IsOnOverflow)
                            {
                                parent = glyphItem.Owner;
                            }
                            else
                            {
                                parent = glyphItem.GetCurrentParent();
                            }
                            int startIndexOfSelection = Math.Min(parent.Items.IndexOf(selectedItem), parent.Items.IndexOf(glyphItem));
                            int endIndexOfSelection   = Math.Max(parent.Items.IndexOf(selectedItem), parent.Items.IndexOf(glyphItem));
                            int countofItemsSelected  = (endIndexOfSelection - startIndexOfSelection) + 1;

                            // if two adjacent items are selected ...
                            if (countofItemsSelected == 2)
                            {
                                selSvc.SetSelectedComponents(new IComponent[] { glyphItem });
                            }
                            else
                            {
                                object[] totalObjects = new object[countofItemsSelected];
                                int      j            = 0;
                                for (int i = startIndexOfSelection; i <= endIndexOfSelection; i++)
                                {
                                    totalObjects[j++] = parent.Items[i];
                                }
                                selSvc.SetSelectedComponents(new IComponent[] { parent }, SelectionTypes.Replace);
                                ToolStripDesigner.s_shiftState = true;
                                selSvc.SetSelectedComponents(totalObjects, SelectionTypes.Replace);
                            }
                        }
                        //End Implmentation
                        else
                        {
                            if (glyphItem.IsOnDropDown && ToolStripDesigner.s_shiftState)
                            {
                                //Invalidate glyh only if we are in ShiftState...
                                ToolStripDesigner.s_shiftState = false;
                                if (bSvc != null)
                                {
                                    bSvc.Invalidate(glyphItem.Owner.Bounds);
                                }
                            }
                            selSvc.SetSelectedComponents(new IComponent[] { glyphItem }, SelectionTypes.Auto);
                        }
                        // Set the appropriate object.
                        if (keyService != null)
                        {
                            keyService.ShiftPrimaryItem = glyphItem;
                        }
                    }
                    // we are already selected and if shiftpressed...
                    else if (shiftPressed || (Control.ModifierKeys & Keys.Control) > 0)
                    {
                        selSvc.SetSelectedComponents(new IComponent[] { glyphItem }, SelectionTypes.Remove);
                    }
                }
            }

            if (glyph != null && button == MouseButtons.Right)
            {
                if (!selSvc.GetComponentSelected(glyphItem))
                {
                    selSvc.SetSelectedComponents(new IComponent[] { glyphItem });
                }
            }

            // finally Invalidate all selections
            ToolStripDesignerUtils.InvalidateSelection(origSel, glyphItem, glyphItem.Site, false);
            return(false);
        }
        public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
        {
            ToolStripItemGlyph glyph            = g as ToolStripItemGlyph;
            ToolStripItem      item             = glyph.Item;
            ISelectionService  selectionService = this.GetSelectionService(item);
            BehaviorService    behaviorService  = this.GetBehaviorService(item);
            ToolStripKeyboardHandlingService keyBoardHandlingService = this.GetKeyBoardHandlingService(item);

            if (((button != MouseButtons.Left) || (keyBoardHandlingService == null)) || (!keyBoardHandlingService.TemplateNodeActive || !keyBoardHandlingService.ActiveTemplateNode.IsSystemContextMenuDisplayed))
            {
                IDesignerHost service          = (IDesignerHost)item.Site.GetService(typeof(IDesignerHost));
                ToolStripItem primarySelection = selectionService.PrimarySelection as ToolStripItem;
                ICollection   c = null;
                if (selectionService != null)
                {
                    c = selectionService.GetSelectedComponents();
                }
                ArrayList originalSelComps = new ArrayList(c);
                if (((originalSelComps.Count == 0) && (keyBoardHandlingService != null)) && (keyBoardHandlingService.SelectedDesignerControl != null))
                {
                    originalSelComps.Add(keyBoardHandlingService.SelectedDesignerControl);
                }
                if (keyBoardHandlingService != null)
                {
                    keyBoardHandlingService.SelectedDesignerControl = null;
                    if (keyBoardHandlingService.TemplateNodeActive)
                    {
                        keyBoardHandlingService.ActiveTemplateNode.CommitAndSelect();
                        if ((primarySelection != null) && (primarySelection == item))
                        {
                            selectionService.SetSelectedComponents(null, SelectionTypes.Replace);
                        }
                    }
                }
                if ((selectionService == null) || this.MouseHandlerPresent(item))
                {
                    return(false);
                }
                if ((glyph != null) && (button == MouseButtons.Left))
                {
                    ToolStripItem oldSelection = selectionService.PrimarySelection as ToolStripItem;
                    this.SetParentDesignerValuesForDragDrop(item, true, mouseLoc);
                    if ((oldSelection != null) && (oldSelection == item))
                    {
                        if (oldSelection != null)
                        {
                            ToolStripItemDesigner itemDesigner = glyph.ItemDesigner;
                            if ((itemDesigner != null) && itemDesigner.IsEditorActive)
                            {
                                return(false);
                            }
                        }
                        if ((Control.ModifierKeys & (Keys.Control | Keys.Shift)) > Keys.None)
                        {
                            selectionService.SetSelectedComponents(new IComponent[] { oldSelection }, SelectionTypes.Remove);
                            return(false);
                        }
                        if (oldSelection is ToolStripMenuItem)
                        {
                            this._timer          = new Timer();
                            this._timer.Interval = SystemInformation.DoubleClickTime;
                            this._timer.Tick    += new EventHandler(this.OnDoubleClickTimerTick);
                            this._timer.Enabled  = true;
                            this.selectedGlyph   = glyph;
                        }
                    }
                    else
                    {
                        bool flag2 = (Control.ModifierKeys & Keys.Shift) > Keys.None;
                        if (!selectionService.GetComponentSelected(item))
                        {
                            this.mouseUpFired     = false;
                            this.doubleClickFired = false;
                            if ((flag2 && (oldSelection != null)) && this.CommonParent(oldSelection, item))
                            {
                                ToolStrip owner = null;
                                if (item.IsOnOverflow)
                                {
                                    owner = item.Owner;
                                }
                                else
                                {
                                    owner = item.GetCurrentParent();
                                }
                                int num  = Math.Min(owner.Items.IndexOf(oldSelection), owner.Items.IndexOf(item));
                                int num2 = Math.Max(owner.Items.IndexOf(oldSelection), owner.Items.IndexOf(item));
                                int num3 = (num2 - num) + 1;
                                if (num3 == 2)
                                {
                                    selectionService.SetSelectedComponents(new IComponent[] { item });
                                }
                                else
                                {
                                    object[] components = new object[num3];
                                    int      num4       = 0;
                                    for (int i = num; i <= num2; i++)
                                    {
                                        components[num4++] = owner.Items[i];
                                    }
                                    selectionService.SetSelectedComponents(new IComponent[] { owner }, SelectionTypes.Replace);
                                    ToolStripDesigner.shiftState = true;
                                    selectionService.SetSelectedComponents(components, SelectionTypes.Replace);
                                }
                            }
                            else
                            {
                                if (item.IsOnDropDown && ToolStripDesigner.shiftState)
                                {
                                    ToolStripDesigner.shiftState = false;
                                    if (behaviorService != null)
                                    {
                                        behaviorService.Invalidate(item.Owner.Bounds);
                                    }
                                }
                                selectionService.SetSelectedComponents(new IComponent[] { item }, SelectionTypes.Auto);
                            }
                            if (keyBoardHandlingService != null)
                            {
                                keyBoardHandlingService.ShiftPrimaryItem = item;
                            }
                        }
                        else if (flag2 || ((Control.ModifierKeys & Keys.Control) > Keys.None))
                        {
                            selectionService.SetSelectedComponents(new IComponent[] { item }, SelectionTypes.Remove);
                        }
                    }
                }
                if (((glyph != null) && (button == MouseButtons.Right)) && !selectionService.GetComponentSelected(item))
                {
                    selectionService.SetSelectedComponents(new IComponent[] { item });
                }
                ToolStripDesignerUtils.InvalidateSelection(originalSelComps, item, item.Site, false);
            }
            return(false);
        }
        private void PopulateList()
        {
            ToolStripItem currentItem = this.currentItem;

            if (!(currentItem is ToolStripControlHost) && !(currentItem is ToolStripSeparator))
            {
                this.imageToolStripMenuItem       = new ToolStripMenuItem();
                this.imageToolStripMenuItem.Text  = System.Design.SR.GetString("ToolStripItemContextMenuSetImage");
                this.imageToolStripMenuItem.Image = new Bitmap(typeof(ToolStripMenuItem), "image.bmp");
                this.imageToolStripMenuItem.ImageTransparentColor = Color.Magenta;
                this.imageToolStripMenuItem.Click += new EventHandler(this.OnImageToolStripMenuItemClick);
                this.enabledToolStripMenuItem      = this.CreateBooleanItem("E&nabled", "Enabled");
                base.AddRange(new ToolStripItem[] { this.imageToolStripMenuItem, this.enabledToolStripMenuItem });
                if (currentItem is ToolStripMenuItem)
                {
                    this.checkedToolStripMenuItem          = this.CreateBooleanItem("C&hecked", "Checked");
                    this.showShortcutKeysToolStripMenuItem = this.CreateBooleanItem("ShowShortcut&Keys", "ShowShortcutKeys");
                    base.AddRange(new ToolStripItem[] { this.checkedToolStripMenuItem, this.showShortcutKeysToolStripMenuItem });
                }
                else
                {
                    if (currentItem is ToolStripLabel)
                    {
                        this.isLinkToolStripMenuItem = this.CreateBooleanItem("IsLin&k", "IsLink");
                        base.Add(this.isLinkToolStripMenuItem);
                    }
                    if (currentItem is ToolStripStatusLabel)
                    {
                        this.springToolStripMenuItem = this.CreateBooleanItem("Sprin&g", "Spring");
                        base.Add(this.springToolStripMenuItem);
                    }
                    this.leftToolStripMenuItem           = this.CreateEnumValueItem("Alignment", "Left", ToolStripItemAlignment.Left);
                    this.rightToolStripMenuItem          = this.CreateEnumValueItem("Alignment", "Right", ToolStripItemAlignment.Right);
                    this.noneStyleToolStripMenuItem      = this.CreateEnumValueItem("DisplayStyle", "None", ToolStripItemDisplayStyle.None);
                    this.textStyleToolStripMenuItem      = this.CreateEnumValueItem("DisplayStyle", "Text", ToolStripItemDisplayStyle.Text);
                    this.imageStyleToolStripMenuItem     = this.CreateEnumValueItem("DisplayStyle", "Image", ToolStripItemDisplayStyle.Image);
                    this.imageTextStyleToolStripMenuItem = this.CreateEnumValueItem("DisplayStyle", "ImageAndText", ToolStripItemDisplayStyle.ImageAndText);
                    this.alignmentToolStripMenuItem      = this.CreatePropertyBasedItem("Ali&gnment", "Alignment", "alignment.bmp");
                    this.alignmentToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.leftToolStripMenuItem, this.rightToolStripMenuItem });
                    this.displayStyleToolStripMenuItem = this.CreatePropertyBasedItem("Displa&yStyle", "DisplayStyle", "displaystyle.bmp");
                    this.displayStyleToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.noneStyleToolStripMenuItem, this.textStyleToolStripMenuItem, this.imageStyleToolStripMenuItem, this.imageTextStyleToolStripMenuItem });
                    base.AddRange(new ToolStripItem[] { this.alignmentToolStripMenuItem, this.displayStyleToolStripMenuItem });
                }
                this.toolStripSeparator1 = new ToolStripSeparator();
                base.Add(this.toolStripSeparator1);
            }
            this.convertToolStripMenuItem          = new ToolStripMenuItem();
            this.convertToolStripMenuItem.Text     = System.Design.SR.GetString("ToolStripItemContextMenuConvertTo");
            this.convertToolStripMenuItem.DropDown = ToolStripDesignerUtils.GetNewItemDropDown(this.ParentTool, this.currentItem, new EventHandler(this.AddNewItemClick), true, this.serviceProvider);
            this.insertToolStripMenuItem           = new ToolStripMenuItem();
            this.insertToolStripMenuItem.Text      = System.Design.SR.GetString("ToolStripItemContextMenuInsert");
            this.insertToolStripMenuItem.DropDown  = ToolStripDesignerUtils.GetNewItemDropDown(this.ParentTool, this.currentItem, new EventHandler(this.AddNewItemClick), false, this.serviceProvider);
            base.AddRange(new ToolStripItem[] { this.convertToolStripMenuItem, this.insertToolStripMenuItem });
            if (this.currentItem is ToolStripDropDownItem)
            {
                IDesignerHost service = (IDesignerHost)this.serviceProvider.GetService(typeof(IDesignerHost));
                if (service != null)
                {
                    ToolStripItemDesigner designer = service.GetDesigner(this.currentItem) as ToolStripItemDesigner;
                    if (designer != null)
                    {
                        this.verbManager = new CollectionEditVerbManager(System.Design.SR.GetString("ToolStripDropDownItemCollectionEditorVerb"), designer, TypeDescriptor.GetProperties(this.currentItem)["DropDownItems"], false);
                        this.editItemsToolStripMenuItem        = new ToolStripMenuItem();
                        this.editItemsToolStripMenuItem.Text   = System.Design.SR.GetString("ToolStripDropDownItemCollectionEditorVerb");
                        this.editItemsToolStripMenuItem.Click += new EventHandler(this.OnEditItemsMenuItemClick);
                        this.editItemsToolStripMenuItem.Image  = new Bitmap(typeof(ToolStripMenuItem), "editdropdownlist.bmp");
                        this.editItemsToolStripMenuItem.ImageTransparentColor = Color.Magenta;
                        base.Add(this.editItemsToolStripMenuItem);
                    }
                }
            }
        }
Example #11
0
 private void OnlistBoxItems_DrawItem(object sender, DrawItemEventArgs e)
 {
     if (e.Index != -1)
     {
         System.Type itemType = null;
         string      str      = null;
         bool        flag     = false;
         bool        flag2    = false;
         bool        flag3    = (e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit;
         if (sender is ListBox)
         {
             ListBox   box       = sender as ListBox;
             Component component = box.Items[e.Index] as Component;
             if (component == null)
             {
                 return;
             }
             if (component is ToolStripItem)
             {
                 flag = true;
             }
             itemType = component.GetType();
             str      = (component.Site != null) ? component.Site.Name : itemType.Name;
         }
         else
         {
             if (!(sender is ComboBox))
             {
                 return;
             }
             flag2 = (e.Index == this.customItemIndex) && !flag3;
             TypeListItem item = ((ComboBox)sender).Items[e.Index] as TypeListItem;
             if (item == null)
             {
                 return;
             }
             itemType = item.Type;
             str      = item.ToString();
         }
         if (itemType != null)
         {
             Color empty = Color.Empty;
             if (flag2)
             {
                 e.Graphics.DrawLine(SystemPens.ControlDark, (int)(e.Bounds.X + 2), (int)(e.Bounds.Y + 2), (int)(e.Bounds.Right - 2), (int)(e.Bounds.Y + 2));
             }
             Rectangle bounds = e.Bounds;
             bounds.Size = new Size(0x10, 0x10);
             int x = flag3 ? 0 : 2;
             bounds.Offset(x, 1);
             if (flag2)
             {
                 bounds.Offset(0, 4);
             }
             if (flag)
             {
                 bounds.X += 20;
             }
             if (!flag3)
             {
                 bounds.Intersect(e.Bounds);
             }
             Bitmap toolboxBitmap = ToolStripDesignerUtils.GetToolboxBitmap(itemType);
             if (toolboxBitmap != null)
             {
                 if (flag3)
                 {
                     e.Graphics.DrawImage(toolboxBitmap, e.Bounds.X, e.Bounds.Y, 0x10, 0x10);
                 }
                 else
                 {
                     e.Graphics.FillRectangle(SystemBrushes.Window, bounds);
                     e.Graphics.DrawImage(toolboxBitmap, bounds);
                 }
             }
             Rectangle rectangle2 = e.Bounds;
             rectangle2.X = bounds.Right + 6;
             rectangle2.Y = bounds.Top - 1;
             if (!flag3)
             {
                 rectangle2.Y += 2;
             }
             rectangle2.Intersect(e.Bounds);
             Rectangle rect = e.Bounds;
             rect.X = rectangle2.X - 2;
             if (flag2)
             {
                 rect.Y      += 4;
                 rect.Height -= 4;
             }
             if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
             {
                 empty = SystemColors.HighlightText;
                 e.Graphics.FillRectangle(SystemBrushes.Highlight, rect);
             }
             else
             {
                 empty = SystemColors.WindowText;
                 e.Graphics.FillRectangle(SystemBrushes.Window, rect);
             }
             if (!string.IsNullOrEmpty(str))
             {
                 TextFormatFlags flags = TextFormatFlags.Default;
                 TextRenderer.DrawText(e.Graphics, str, this.Font, rectangle2, empty, flags);
             }
             if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
             {
                 rect.Width--;
                 ControlPaint.DrawFocusRectangle(e.Graphics, rect, e.ForeColor, e.BackColor);
             }
         }
     }
 }
Example #12
0
 public override string ToString()
 {
     return(ToolStripDesignerUtils.GetToolboxDescription(this.Type));
 }