public ToolStripItemGlyph(ToolStripItem item, ToolStripItemDesigner itemDesigner, Rectangle bounds, System.Windows.Forms.Design.Behavior.Behavior b)
     : base(bounds, Cursors.Default, item, b)
 {
     this._item = item;
     this._bounds = bounds;
     this._itemDesigner = itemDesigner;
 }
Example #2
0
        // Occurs when MouseUp TooLStripItem glyph
        public override bool OnMouseUp(Glyph g, MouseButtons button)
        {
            ToolStripItemGlyph glyph     = g as ToolStripItemGlyph;
            ToolStripItem      glyphItem = glyph.Item;

            if (MouseHandlerPresent(glyphItem))
            {
                return(false);
            }

            SetParentDesignerValuesForDragDrop(glyphItem, false, Point.Empty);
            if (_doubleClickFired)
            {
                if (glyph != null && button == MouseButtons.Left)
                {
                    ISelectionService selSvc = GetSelectionService(glyphItem);
                    if (selSvc is null)
                    {
                        return(false);
                    }

                    ToolStripItem selectedItem = selSvc.PrimarySelection as ToolStripItem;
                    // Check if this item is already selected ...
                    if (selectedItem == glyphItem)
                    {
                        // If timer != null.. we are in DoubleClick before the "InSitu Timer" so KILL IT.
                        if (_timer != null)
                        {
                            _timer.Enabled = false;
                            _timer.Tick   -= new System.EventHandler(OnDoubleClickTimerTick);
                            _timer.Dispose();
                            _timer = null;
                        }

                        // If the Selecteditem is already in editmode ... bail out
                        if (selectedItem != null)
                        {
                            ToolStripItemDesigner selectedItemDesigner = glyph.ItemDesigner;
                            if (selectedItemDesigner != null && selectedItemDesigner.IsEditorActive)
                            {
                                return(false);
                            }

                            selectedItemDesigner.DoDefaultAction();
                        }

                        _doubleClickFired = false;
                        _mouseUpFired     = false;
                    }
                }
            }
            else
            {
                _mouseUpFired = true;
            }

            return(false);
        }
Example #3
0
        // Set values before initiating the Drag-Drop
        private void SetParentDesignerValuesForDragDrop(ToolStripItem glyphItem, bool setValues, Point mouseLoc)
        {
            if (glyphItem.Site is null)
            {
                return;
            }

            // Remember the point where the mouse down occurred. The DragSize indicates the size that the mouse can move before a drag event should be started.
            Size dragSize = new Size(1, 1);

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

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

            // implement Drag Drop for individual ToolStrip Items While this item is getting selected.. Get the index of the item the mouse is below.
            if (glyphItem.Placement == ToolStripItemPlacement.Overflow || (glyphItem.Placement == ToolStripItemPlacement.Main && !(glyphItem.IsOnDropDown)))
            {
                ToolStripItemDesigner itemDesigner    = designerHost.GetDesigner(glyphItem) as ToolStripItemDesigner;
                ToolStrip             parentToolStrip = itemDesigner.GetMainToolStrip();
                if (designerHost.GetDesigner(parentToolStrip) is ToolStripDesigner parentDesigner)
                {
                    if (setValues)
                    {
                        parentDesigner.IndexOfItemUnderMouseToDrag = parentToolStrip.Items.IndexOf(glyphItem);
                        // Create a rectangle using the DragSize, with the mouse position being at the center of the rectangle. On SelectionChanged we recreate the Glyphs ... so need to stash this value on the parentDesigner....
                        parentDesigner.DragBoxFromMouseDown = _dragBoxFromMouseDown = new Rectangle(new Point(mouseLoc.X - (dragSize.Width / 2), mouseLoc.Y - (dragSize.Height / 2)), dragSize);
                    }
                    else
                    {
                        parentDesigner.IndexOfItemUnderMouseToDrag = -1;
                        parentDesigner.DragBoxFromMouseDown        = _dragBoxFromMouseDown = Rectangle.Empty;
                    }
                }
            }
            else if (glyphItem.IsOnDropDown)
            {
                //Get the OwnerItem's Designer and set the value...
                if (glyphItem.Owner is ToolStripDropDown parentDropDown)
                {
                    ToolStripItem ownerItem = parentDropDown.OwnerItem;
                    if (designerHost.GetDesigner(ownerItem) is ToolStripItemDesigner ownerItemDesigner)
                    {
                        if (setValues)
                        {
                            ownerItemDesigner.indexOfItemUnderMouseToDrag = parentDropDown.Items.IndexOf(glyphItem);
                            // Create a rectangle using the DragSize, with the mouse position being at the center of the rectangle. On SelectionChanged we recreate the Glyphs ... so need to stash this value on the parentDesigner....
                            ownerItemDesigner.dragBoxFromMouseDown = _dragBoxFromMouseDown = new Rectangle(new Point(mouseLoc.X - (dragSize.Width / 2), mouseLoc.Y - (dragSize.Height / 2)), dragSize);
                        }
                        else
                        {
                            ownerItemDesigner.indexOfItemUnderMouseToDrag = -1;
                            ownerItemDesigner.dragBoxFromMouseDown        = _dragBoxFromMouseDown = Rectangle.Empty;
                        }
                    }
                }
            }
        }
        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);
        }
        public override bool OnMouseUp(Glyph g, MouseButtons button)
        {
            ToolStripItemGlyph glyph = g as ToolStripItemGlyph;
            ToolStripItem      item  = glyph.Item;

            if (!this.MouseHandlerPresent(item))
            {
                this.SetParentDesignerValuesForDragDrop(item, false, Point.Empty);
                if (this.doubleClickFired)
                {
                    if ((glyph != null) && (button == MouseButtons.Left))
                    {
                        ISelectionService selectionService = this.GetSelectionService(item);
                        if (selectionService == null)
                        {
                            return(false);
                        }
                        ToolStripItem primarySelection = selectionService.PrimarySelection as ToolStripItem;
                        if (primarySelection == item)
                        {
                            if (this._timer != null)
                            {
                                this._timer.Enabled = false;
                                this._timer.Tick   -= new EventHandler(this.OnDoubleClickTimerTick);
                                this._timer.Dispose();
                                this._timer = null;
                            }
                            if (primarySelection != null)
                            {
                                ToolStripItemDesigner itemDesigner = glyph.ItemDesigner;
                                if ((itemDesigner != null) && itemDesigner.IsEditorActive)
                                {
                                    return(false);
                                }
                                itemDesigner.DoDefaultAction();
                            }
                            this.doubleClickFired = false;
                            this.mouseUpFired     = false;
                        }
                    }
                }
                else
                {
                    this.mouseUpFired = true;
                }
            }
            return(false);
        }
 private void SetParentDesignerValuesForDragDrop(ToolStripItem glyphItem, bool setValues, Point mouseLoc)
 {
     if (glyphItem.Site != null)
     {
         Size          size    = new Size(1, 1);
         IDesignerHost service = (IDesignerHost)glyphItem.Site.GetService(typeof(IDesignerHost));
         if ((glyphItem.Placement == ToolStripItemPlacement.Overflow) || ((glyphItem.Placement == ToolStripItemPlacement.Main) && !glyphItem.IsOnDropDown))
         {
             ToolStrip         mainToolStrip = (service.GetDesigner(glyphItem) as ToolStripItemDesigner).GetMainToolStrip();
             ToolStripDesigner designer      = service.GetDesigner(mainToolStrip) as ToolStripDesigner;
             if (designer != null)
             {
                 if (setValues)
                 {
                     designer.IndexOfItemUnderMouseToDrag = mainToolStrip.Items.IndexOf(glyphItem);
                     designer.DragBoxFromMouseDown        = this.dragBoxFromMouseDown = new Rectangle(new Point(mouseLoc.X - (size.Width / 2), mouseLoc.Y - (size.Height / 2)), size);
                 }
                 else
                 {
                     designer.IndexOfItemUnderMouseToDrag = -1;
                     designer.DragBoxFromMouseDown        = this.dragBoxFromMouseDown = Rectangle.Empty;
                 }
             }
         }
         else if (glyphItem.IsOnDropDown)
         {
             ToolStripDropDown owner = glyphItem.Owner as ToolStripDropDown;
             if (owner != null)
             {
                 ToolStripItem         ownerItem = owner.OwnerItem;
                 ToolStripItemDesigner designer3 = service.GetDesigner(ownerItem) as ToolStripItemDesigner;
                 if (designer3 != null)
                 {
                     if (setValues)
                     {
                         designer3.indexOfItemUnderMouseToDrag = owner.Items.IndexOf(glyphItem);
                         designer3.dragBoxFromMouseDown        = this.dragBoxFromMouseDown = new Rectangle(new Point(mouseLoc.X - (size.Width / 2), mouseLoc.Y - (size.Height / 2)), size);
                     }
                     else
                     {
                         designer3.indexOfItemUnderMouseToDrag = -1;
                         designer3.dragBoxFromMouseDown        = this.dragBoxFromMouseDown = Rectangle.Empty;
                     }
                 }
             }
         }
     }
 }
        /// <summary>
        ///  Activates the editor for the given item.If there's still an editor around  for the previous-edited item, it is deactivated. Pass in 'null' to deactivate and remove the current editor, if any.
        /// </summary>
        internal void ActivateEditor(ToolStripItem item, bool clicked)
        {
            if (item != _currentItem)
            {
                // Remove old editor
                if (_editor != null)
                {
                    _behaviorService.AdornerWindowControl.Controls.Remove(_editor);
                    _behaviorService.Invalidate(_editor.Bounds);
                    _editorUI    = null;
                    _editor      = null;
                    _currentItem = null;
                    _itemDesigner.IsEditorActive = false;

                    // Show the previously edited glyph
                    if (_currentItem != null)
                    {
                        _currentItem = null;
                    }
                }

                if (item != null)
                {
                    // Add new editor from the item...
                    _currentItem = item;
                    if (_designerHost != null)
                    {
                        _itemDesigner = (ToolStripItemDesigner)_designerHost.GetDesigner(_currentItem);
                    }

                    _editorUI = (ToolStripTemplateNode)_itemDesigner.Editor;
                    // If we got an editor, position and focus it.
                    if (_editorUI != null)
                    {
                        // Hide this glyph while it's being edited
                        _itemDesigner.IsEditorActive = true;
                        _editor = new ToolStripEditorControl(_editorUI.EditorToolStrip, _editorUI.Bounds);
                        _behaviorService.AdornerWindowControl.Controls.Add(_editor);
                        _lastKnownEditorBounds = _editor.Bounds;
                        _editor.BringToFront();
                        // this is important since the ToolStripEditorControl listens    to textchanged messages from TextBox.
                        _editorUI.ignoreFirstKeyUp = true;
                        // Select the Editor... Put Text and Select it ...
                        _editorUI.FocusEditor(_currentItem);
                    }
                }
            }
        }
 public void Dispose()
 {
     if (this.toolDesigner != null)
     {
         this.toolDesigner.Dispose();
         this.toolDesigner = null;
     }
     if (this.toolItemDesigner != null)
     {
         this.toolItemDesigner.Dispose();
         this.toolItemDesigner = null;
     }
     if (this.componentChangeSvc != null)
     {
         this.componentChangeSvc.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemoved);
         this.componentChangeSvc = null;
     }
 }
 /// <summary>
 ///  Disposes of this object, removing all commands from the menu service.
 /// </summary>
 public void Dispose()
 {
     if (_toolDesigner != null)
     {
         _toolDesigner.Dispose();
         _toolDesigner = null;
     }
     if (_toolItemDesigner != null)
     {
         _toolItemDesigner.Dispose();
         _toolItemDesigner = null;
     }
     if (_componentChangeSvc != null)
     {
         _componentChangeSvc.ComponentRemoved -= new ComponentEventHandler(OnComponentRemoved);
         _componentChangeSvc = null;
     }
 }
 public void Dispose()
 {
     if (this.toolDesigner != null)
     {
         this.toolDesigner.Dispose();
         this.toolDesigner = null;
     }
     if (this.toolItemDesigner != null)
     {
         this.toolItemDesigner.Dispose();
         this.toolItemDesigner = null;
     }
     if (this.componentChangeSvc != null)
     {
         this.componentChangeSvc.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemoved);
         this.componentChangeSvc = null;
     }
 }
        private void OnImageToolStripMenuItemClick(object sender, EventArgs e)
        {
            IDesignerHost service = (IDesignerHost)this.serviceProvider.GetService(typeof(IDesignerHost));

            if (service != null)
            {
                ToolStripItemDesigner designer = service.GetDesigner(this.currentItem) as ToolStripItemDesigner;
                if (designer != null)
                {
                    try
                    {
                        EditorServiceContext.EditValue(designer, this.currentItem, "Image");
                    }
                    catch (InvalidOperationException exception)
                    {
                        ((IUIService)this.serviceProvider.GetService(typeof(IUIService))).ShowError(exception.Message);
                    }
                }
            }
        }
        private void AddSelectionGlyphs(SelectionManager selMgr, ISelectionService selectionService)
        {
            ICollection     selectedComponents = selectionService.GetSelectedComponents();
            GlyphCollection glyphs             = new GlyphCollection();

            foreach (object obj2 in selectedComponents)
            {
                ToolStripItem component = obj2 as ToolStripItem;
                if (component != null)
                {
                    ToolStripItemDesigner designer = (ToolStripItemDesigner)this.host.GetDesigner(component);
                    if (designer != null)
                    {
                        designer.GetGlyphs(ref glyphs, new ResizeBehavior(component.Site));
                    }
                }
            }
            if (glyphs.Count > 0)
            {
                selMgr.SelectionGlyphAdorner.Glyphs.AddRange(glyphs);
            }
        }
 internal void ActivateEditor(ToolStripItem item, bool clicked)
 {
     if (item != this.currentItem)
     {
         if (this.editor != null)
         {
             this.behaviorService.AdornerWindowControl.Controls.Remove(this.editor);
             this.behaviorService.Invalidate(this.editor.Bounds);
             this.editorUI = null;
             this.editor = null;
             this.currentItem = null;
             this.itemDesigner.IsEditorActive = false;
             if (this.currentItem != null)
             {
                 this.currentItem = null;
             }
         }
         if (item != null)
         {
             this.currentItem = item;
             if (this.designerHost != null)
             {
                 this.itemDesigner = (ToolStripItemDesigner) this.designerHost.GetDesigner(this.currentItem);
             }
             this.editorUI = this.itemDesigner.Editor;
             if (this.editorUI != null)
             {
                 this.itemDesigner.IsEditorActive = true;
                 this.editor = new ToolStripEditorControl(this.editorUI.EditorToolStrip, this.editorUI.Bounds);
                 this.behaviorService.AdornerWindowControl.Controls.Add(this.editor);
                 this.lastKnownEditorBounds = this.editor.Bounds;
                 this.editor.BringToFront();
                 this.editorUI.ignoreFirstKeyUp = true;
                 this.editorUI.FocusEditor(this.currentItem);
             }
         }
     }
 }
 internal void ActivateEditor(ToolStripItem item, bool clicked)
 {
     if (item != this.currentItem)
     {
         if (this.editor != null)
         {
             this.behaviorService.AdornerWindowControl.Controls.Remove(this.editor);
             this.behaviorService.Invalidate(this.editor.Bounds);
             this.editorUI    = null;
             this.editor      = null;
             this.currentItem = null;
             this.itemDesigner.IsEditorActive = false;
             if (this.currentItem != null)
             {
                 this.currentItem = null;
             }
         }
         if (item != null)
         {
             this.currentItem = item;
             if (this.designerHost != null)
             {
                 this.itemDesigner = (ToolStripItemDesigner)this.designerHost.GetDesigner(this.currentItem);
             }
             this.editorUI = this.itemDesigner.Editor;
             if (this.editorUI != null)
             {
                 this.itemDesigner.IsEditorActive = true;
                 this.editor = new ToolStripEditorControl(this.editorUI.EditorToolStrip, this.editorUI.Bounds);
                 this.behaviorService.AdornerWindowControl.Controls.Add(this.editor);
                 this.lastKnownEditorBounds = this.editor.Bounds;
                 this.editor.BringToFront();
                 this.editorUI.ignoreFirstKeyUp = true;
                 this.editorUI.FocusEditor(this.currentItem);
             }
         }
     }
 }
        /// <summary>
        ///  When any MouseMove message enters the BehaviorService's AdornerWindow (mousemove, ncmousemove) it is first passed here, to the top-most Behavior in the BehaviorStack.  Returning 'true' from this function signifies that  the Message was 'handled' by the Behavior and should not continue to be processed.
        /// </summary>
        public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc)
        {
            bool retVal = false;
            ToolStripItemGlyph glyph     = g as ToolStripItemGlyph;
            ToolStripItem      glyphItem = glyph.Item;
            ISelectionService  selSvc    = GetSelectionService(glyphItem);

            if (selSvc == null || glyphItem.Site == null || MouseHandlerPresent(glyphItem))
            {
                return(false);
            }
            if (!selSvc.GetComponentSelected(glyphItem))
            {
                PaintInsertionMark(glyphItem);
                retVal = false;
            }

            if (button == MouseButtons.Left && glyph != null && glyph.ItemDesigner != null && !glyph.ItemDesigner.IsEditorActive)
            {
                Rectangle     dragBox      = Rectangle.Empty;
                IDesignerHost designerHost = (IDesignerHost)glyphItem.Site.GetService(typeof(IDesignerHost));
                Debug.Assert(designerHost != null, "Invalid DesignerHost");
                if (glyphItem.Placement == ToolStripItemPlacement.Overflow || (glyphItem.Placement == ToolStripItemPlacement.Main && !(glyphItem.IsOnDropDown)))
                {
                    ToolStripItemDesigner itemDesigner    = glyph.ItemDesigner;
                    ToolStrip             parentToolStrip = itemDesigner.GetMainToolStrip();
                    if (designerHost.GetDesigner(parentToolStrip) is ToolStripDesigner parentDesigner)
                    {
                        dragBox = parentDesigner.DragBoxFromMouseDown;
                    }
                }
                else if (glyphItem.IsOnDropDown)
                {
                    //Get the OwnerItem's Designer and set the value...
                    if (glyphItem.Owner is ToolStripDropDown parentDropDown)
                    {
                        ToolStripItem ownerItem = parentDropDown.OwnerItem;
                        if (designerHost.GetDesigner(ownerItem) is ToolStripItemDesigner ownerItemDesigner)
                        {
                            dragBox = ownerItemDesigner.dragBoxFromMouseDown;
                        }
                    }
                }
                // If the mouse moves outside the rectangle, start the drag.
                if (dragBox != Rectangle.Empty && !dragBox.Contains(mouseLoc.X, mouseLoc.Y))
                {
                    if (_timer != null)
                    {
                        _timer.Enabled = false;
                        _timer.Tick   -= new System.EventHandler(OnDoubleClickTimerTick);
                        _timer.Dispose();
                        _timer = null;
                    }

                    // Proceed with the drag and drop, passing in the list item.
                    try
                    {
                        ArrayList   dragItems = new ArrayList();
                        ICollection selComps  = selSvc.GetSelectedComponents();
                        //create our list of controls-to-drag
                        foreach (IComponent comp in selComps)
                        {
                            if (comp is ToolStripItem item)
                            {
                                dragItems.Add(item);
                            }
                        }

                        //Start Drag-Drop only if ToolStripItem is the primary Selection
                        if (selSvc.PrimarySelection is ToolStripItem selectedItem)
                        {
                            ToolStrip owner = selectedItem.Owner;
                            ToolStripItemDataObject data = new ToolStripItemDataObject(dragItems, selectedItem, owner);
                            DropSource.QueryContinueDrag += new QueryContinueDragEventHandler(QueryContinueDrag);
                            if (glyphItem is ToolStripDropDownItem ddItem)
                            {
                                if (designerHost.GetDesigner(ddItem) is ToolStripMenuItemDesigner itemDesigner)
                                {
                                    itemDesigner.InitializeBodyGlyphsForItems(false, ddItem);
                                    ddItem.HideDropDown();
                                }
                            }
                            else if (glyphItem.IsOnDropDown && !glyphItem.IsOnOverflow)
                            {
                                ToolStripDropDown     dropDown  = glyphItem.GetCurrentParent() as ToolStripDropDown;
                                ToolStripDropDownItem ownerItem = dropDown.OwnerItem as ToolStripDropDownItem;
                                selSvc.SetSelectedComponents(new IComponent[] { ownerItem }, SelectionTypes.Replace);
                            }
                            DropSource.DoDragDrop(data, DragDropEffects.All);
                        }
                    }
                    finally
                    {
                        DropSource.QueryContinueDrag -= new QueryContinueDragEventHandler(QueryContinueDrag);
                        //Reset all Drag-Variables
                        SetParentDesignerValuesForDragDrop(glyphItem, false, Point.Empty);
                        ToolStripDesigner.s_dragItem = null;
                        _dropSource = null;
                    }
                    retVal = false;
                }
            }
            return(retVal);
        }
        // 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 ToolStripItemGlyph(ToolStripItem item, ToolStripItemDesigner itemDesigner, Rectangle bounds, System.Windows.Forms.Design.Behavior.Behavior b) : base(bounds, Cursors.Default, item, b)
 {
     _item         = item;
     _bounds       = bounds;
     _itemDesigner = itemDesigner;
 }
        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);
                    }
                }
            }
        }
        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);
        }
Example #20
0
        public static void InvalidateSelection(ArrayList originalSelComps, ToolStripItem nextSelection, IServiceProvider provider, bool shiftPressed)
        {
            // if we are not selecting a ToolStripItem then return (dont invalidate).
            if (nextSelection == null || provider == null)
            {
                return;
            }
            //InvalidateOriginal SelectedComponents.
            Region invalidateRegion        = null;
            Region itemRegion              = null;
            int    GLYPHBORDER             = 1;
            int    GLYPHINSET              = 2;
            ToolStripItemDesigner designer = null;
            bool templateNodeSelected      = false;

            try
            {
                Rectangle     invalidateBounds = Rectangle.Empty;
                IDesignerHost designerHost     = (IDesignerHost)provider.GetService(typeof(IDesignerHost));

                if (designerHost != null)
                {
                    foreach (Component comp in originalSelComps)
                    {
                        if (comp is ToolStripItem selItem)
                        {
                            if ((originalSelComps.Count > 1) ||
                                (originalSelComps.Count == 1 && selItem.GetCurrentParent() != nextSelection.GetCurrentParent()) ||
                                selItem is ToolStripSeparator || selItem is ToolStripControlHost || !selItem.IsOnDropDown || selItem.IsOnOverflow)
                            {
                                // finally Invalidate the selection rect ...
                                designer = designerHost.GetDesigner(selItem) as ToolStripItemDesigner;
                                if (designer != null)
                                {
                                    invalidateBounds = designer.GetGlyphBounds();
                                    GetAdjustedBounds(selItem, ref invalidateBounds);
                                    invalidateBounds.Inflate(GLYPHBORDER, GLYPHBORDER);

                                    if (invalidateRegion == null)
                                    {
                                        invalidateRegion = new Region(invalidateBounds);
                                        invalidateBounds.Inflate(-GLYPHINSET, -GLYPHINSET);
                                        invalidateRegion.Exclude(invalidateBounds);
                                    }
                                    else
                                    {
                                        itemRegion = new Region(invalidateBounds);
                                        invalidateBounds.Inflate(-GLYPHINSET, -GLYPHINSET);
                                        itemRegion.Exclude(invalidateBounds);
                                        invalidateRegion.Union(itemRegion);
                                    }
                                }
                            }
                        }
                    }
                }

                if (invalidateRegion != null || templateNodeSelected || shiftPressed)
                {
                    BehaviorService behaviorService = (BehaviorService)provider.GetService(typeof(BehaviorService));
                    if (behaviorService != null)
                    {
                        if (invalidateRegion != null)
                        {
                            behaviorService.Invalidate(invalidateRegion);
                        }

                        // When a ToolStripItem is PrimarySelection, the glyph bounds are not invalidated  through the SelectionManager so we have to do this.
                        designer = designerHost.GetDesigner(nextSelection) as ToolStripItemDesigner;
                        if (designer != null)
                        {
                            invalidateBounds = designer.GetGlyphBounds();
                            GetAdjustedBounds(nextSelection, ref invalidateBounds);
                            invalidateBounds.Inflate(GLYPHBORDER, GLYPHBORDER);
                            invalidateRegion = new Region(invalidateBounds);

                            invalidateBounds.Inflate(-GLYPHINSET, -GLYPHINSET);
                            invalidateRegion.Exclude(invalidateBounds);
                            behaviorService.Invalidate(invalidateRegion);
                        }
                    }
                }
            }
            finally
            {
                if (invalidateRegion != null)
                {
                    invalidateRegion.Dispose();
                }

                if (itemRegion != null)
                {
                    itemRegion.Dispose();
                }
            }
        }
Example #21
0
        private void RefreshSelectionMenuItem()
        {
            int index = -1;

            if (this.selectionMenuItem != null)
            {
                index = this.Items.IndexOf(this.selectionMenuItem);
                base.Groups["Selection"].Items.Remove(this.selectionMenuItem);
                this.Items.Remove(this.selectionMenuItem);
            }
            ArrayList         list    = new ArrayList();
            int               count   = 0;
            ISelectionService service = this.serviceProvider.GetService(typeof(ISelectionService)) as ISelectionService;
            IDesignerHost     host    = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if ((service != null) && (host != null))
            {
                IComponent rootComponent    = host.RootComponent;
                Control    primarySelection = service.PrimarySelection as Control;
                if (((primarySelection != null) && (rootComponent != null)) && (primarySelection != rootComponent))
                {
                    for (Control control2 = primarySelection.Parent; control2 != null; control2 = control2.Parent)
                    {
                        if (control2.Site != null)
                        {
                            list.Add(control2);
                            count++;
                        }
                        if (control2 == rootComponent)
                        {
                            break;
                        }
                    }
                }
                else if (service.PrimarySelection is ToolStripItem)
                {
                    ToolStripItem         component = service.PrimarySelection as ToolStripItem;
                    ToolStripItemDesigner designer  = host.GetDesigner(component) as ToolStripItemDesigner;
                    if (designer != null)
                    {
                        list  = designer.AddParentTree();
                        count = list.Count;
                    }
                }
            }
            if (count > 0)
            {
                this.selectionMenuItem = new ToolStripMenuItem();
                IUIService service2 = this.serviceProvider.GetService(typeof(IUIService)) as IUIService;
                if (service2 != null)
                {
                    this.selectionMenuItem.DropDown.Renderer = (ToolStripProfessionalRenderer)service2.Styles["VsRenderer"];
                    this.selectionMenuItem.DropDown.Font     = (Font)service2.Styles["DialogFont"];
                }
                this.selectionMenuItem.Text = System.Design.SR.GetString("ContextMenuSelect");
                foreach (Component component2 in list)
                {
                    ToolStripMenuItem item2 = new SelectToolStripMenuItem(component2, this.serviceProvider);
                    this.selectionMenuItem.DropDownItems.Add(item2);
                }
                base.Groups["Selection"].Items.Add(this.selectionMenuItem);
                if (index != -1)
                {
                    this.Items.Insert(index, this.selectionMenuItem);
                }
            }
        }
 public static void InvalidateSelection(ArrayList originalSelComps, ToolStripItem nextSelection, IServiceProvider provider, bool shiftPressed)
 {
     if ((nextSelection != null) && (provider != null))
     {
         Region r      = null;
         Region region = null;
         int    width  = 1;
         int    num2   = 2;
         ToolStripItemDesigner designer = null;
         bool flag = false;
         try
         {
             Rectangle     empty = Rectangle.Empty;
             IDesignerHost host  = (IDesignerHost)provider.GetService(typeof(IDesignerHost));
             if (host != null)
             {
                 foreach (Component component in originalSelComps)
                 {
                     ToolStripItem item = component as ToolStripItem;
                     if ((item != null) && (((originalSelComps.Count > 1) || ((originalSelComps.Count == 1) && (item.GetCurrentParent() != nextSelection.GetCurrentParent()))) || (((item is ToolStripSeparator) || (item is ToolStripControlHost)) || (!item.IsOnDropDown || item.IsOnOverflow))))
                     {
                         designer = host.GetDesigner(item) as ToolStripItemDesigner;
                         if (designer != null)
                         {
                             empty = designer.GetGlyphBounds();
                             GetAdjustedBounds(item, ref empty);
                             empty.Inflate(width, width);
                             if (r == null)
                             {
                                 r = new Region(empty);
                                 empty.Inflate(-num2, -num2);
                                 r.Exclude(empty);
                             }
                             else
                             {
                                 region = new Region(empty);
                                 empty.Inflate(-num2, -num2);
                                 region.Exclude(empty);
                                 r.Union(region);
                             }
                         }
                         else if (item is DesignerToolStripControlHost)
                         {
                             flag = true;
                         }
                     }
                 }
             }
             if (((r != null) || flag) || shiftPressed)
             {
                 BehaviorService service = (BehaviorService)provider.GetService(typeof(BehaviorService));
                 if (service != null)
                 {
                     if (r != null)
                     {
                         service.Invalidate(r);
                     }
                     designer = host.GetDesigner(nextSelection) as ToolStripItemDesigner;
                     if (designer != null)
                     {
                         empty = designer.GetGlyphBounds();
                         GetAdjustedBounds(nextSelection, ref empty);
                         empty.Inflate(width, width);
                         r = new Region(empty);
                         empty.Inflate(-num2, -num2);
                         r.Exclude(empty);
                         service.Invalidate(r);
                     }
                 }
             }
         }
         finally
         {
             if (r != null)
             {
                 r.Dispose();
             }
             if (region != null)
             {
                 region.Dispose();
             }
         }
     }
 }
        public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc)
        {
            bool flag = false;
            ToolStripItemGlyph glyph            = g as ToolStripItemGlyph;
            ToolStripItem      item             = glyph.Item;
            ISelectionService  selectionService = this.GetSelectionService(item);

            if (((selectionService != null) && (item.Site != null)) && !this.MouseHandlerPresent(item))
            {
                if (!selectionService.GetComponentSelected(item))
                {
                    this.PaintInsertionMark(item);
                    flag = false;
                }
                if (((button != MouseButtons.Left) || (glyph == null)) || ((glyph.ItemDesigner == null) || glyph.ItemDesigner.IsEditorActive))
                {
                    return(flag);
                }
                Rectangle     empty   = Rectangle.Empty;
                IDesignerHost service = (IDesignerHost)item.Site.GetService(typeof(IDesignerHost));
                if ((item.Placement == ToolStripItemPlacement.Overflow) || ((item.Placement == ToolStripItemPlacement.Main) && !item.IsOnDropDown))
                {
                    ToolStrip         mainToolStrip = glyph.ItemDesigner.GetMainToolStrip();
                    ToolStripDesigner designer      = service.GetDesigner(mainToolStrip) as ToolStripDesigner;
                    if (designer != null)
                    {
                        empty = designer.DragBoxFromMouseDown;
                    }
                }
                else if (item.IsOnDropDown)
                {
                    ToolStripDropDown owner = item.Owner as ToolStripDropDown;
                    if (owner != null)
                    {
                        ToolStripItem         ownerItem = owner.OwnerItem;
                        ToolStripItemDesigner designer3 = service.GetDesigner(ownerItem) as ToolStripItemDesigner;
                        if (designer3 != null)
                        {
                            empty = designer3.dragBoxFromMouseDown;
                        }
                    }
                }
                if (!(empty != Rectangle.Empty) || empty.Contains(mouseLoc.X, mouseLoc.Y))
                {
                    return(flag);
                }
                if (this._timer != null)
                {
                    this._timer.Enabled = false;
                    this._timer.Tick   -= new EventHandler(this.OnDoubleClickTimerTick);
                    this._timer.Dispose();
                    this._timer = null;
                }
                try
                {
                    ArrayList dragComponents = new ArrayList();
                    foreach (IComponent component in selectionService.GetSelectedComponents())
                    {
                        ToolStripItem item3 = component as ToolStripItem;
                        if (item3 != null)
                        {
                            dragComponents.Add(item3);
                        }
                    }
                    ToolStripItem primarySelection = selectionService.PrimarySelection as ToolStripItem;
                    if (primarySelection != null)
                    {
                        ToolStrip strip2             = primarySelection.Owner;
                        ToolStripItemDataObject data = new ToolStripItemDataObject(dragComponents, primarySelection, strip2);
                        this.DropSource.QueryContinueDrag += new QueryContinueDragEventHandler(this.QueryContinueDrag);
                        ToolStripDropDownItem item5 = item as ToolStripDropDownItem;
                        if (item5 != null)
                        {
                            ToolStripMenuItemDesigner designer4 = service.GetDesigner(item5) as ToolStripMenuItemDesigner;
                            if (designer4 != null)
                            {
                                designer4.InitializeBodyGlyphsForItems(false, item5);
                                item5.HideDropDown();
                            }
                        }
                        else if (item.IsOnDropDown && !item.IsOnOverflow)
                        {
                            ToolStripDropDown     currentParent = item.GetCurrentParent() as ToolStripDropDown;
                            ToolStripDropDownItem item6         = currentParent.OwnerItem as ToolStripDropDownItem;
                            selectionService.SetSelectedComponents(new IComponent[] { item6 }, SelectionTypes.Replace);
                        }
                        this.DropSource.DoDragDrop(data, DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll);
                    }
                }
                finally
                {
                    this.DropSource.QueryContinueDrag -= new QueryContinueDragEventHandler(this.QueryContinueDrag);
                    this.SetParentDesignerValuesForDragDrop(item, false, Point.Empty);
                    ToolStripDesigner.dragItem = null;
                    this.dropSource            = null;
                }
            }
            return(false);
        }