private void EnterInSituMode(ToolStripItemGlyph glyph)
 {
     if ((glyph.ItemDesigner != null) && !glyph.ItemDesigner.IsEditorActive)
     {
         glyph.ItemDesigner.ShowEditNode(false);
     }
 }
 // Tries to put the item in the Insitu edit mode after the double click timer has ticked
 private void EnterInSituMode(ToolStripItemGlyph glyph)
 {
     if (glyph.ItemDesigner != null && !glyph.ItemDesigner.IsEditorActive)
     {
         glyph.ItemDesigner.ShowEditNode(false);
     }
 }
Beispiel #3
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);
        }
        public override void OnDragOver(Glyph g, DragEventArgs e)
        {
            ToolStripItemGlyph glyph = g as ToolStripItemGlyph;
            ToolStripItem      item  = glyph.Item;

            if (e.Data is ToolStripItemDataObject)
            {
                this.PaintInsertionMark(item);
                e.Effect = (Control.ModifierKeys == Keys.Control) ? DragDropEffects.Copy : DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
        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);
        }
        /// <summary>
        ///  OnDragOver can be overridden so that a Behavior can specify its own Drag/Drop rules.
        /// </summary>
        public override void OnDragOver(Glyph g, DragEventArgs e)
        {
            // Determine whether string data exists in the drop data. If not, then the drop effect reflects that the drop cannot occur.
            ToolStripItemGlyph glyph     = g as ToolStripItemGlyph;
            ToolStripItem      glyphItem = glyph.Item;

            if (e.Data is ToolStripItemDataObject)
            {
                PaintInsertionMark(glyphItem);
                e.Effect = (Control.ModifierKeys == Keys.Control) ? DragDropEffects.Copy : DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
 private void AddItemBodyGlyph(ToolStripItem item)
 {
     if (item != null)
     {
         ToolStripItemDesigner itemDesigner = (ToolStripItemDesigner) this.host.GetDesigner(item);
         if (itemDesigner != null)
         {
             Rectangle glyphBounds = itemDesigner.GetGlyphBounds();
             System.Windows.Forms.Design.Behavior.Behavior b = new ToolStripItemBehavior();
             ToolStripItemGlyph glyph = new ToolStripItemGlyph(item, itemDesigner, glyphBounds, b);
             itemDesigner.bodyGlyph = glyph;
             if (this.toolStripAdornerWindowService != null)
             {
                 this.toolStripAdornerWindowService.DropDownAdorner.Glyphs.Add(glyph);
             }
         }
     }
 }
        public override bool OnMouseLeave(Glyph g)
        {
            ToolStripItemGlyph glyph = g as ToolStripItemGlyph;

            if (glyph != null)
            {
                ToolStripItem item = glyph.Item;
                if (this.MouseHandlerPresent(item))
                {
                    return(false);
                }
                ISelectionService selectionService = this.GetSelectionService(item);
                if ((selectionService != null) && !selectionService.GetComponentSelected(item))
                {
                    this.ClearInsertionMark(item);
                }
            }
            return(false);
        }
        /// <summary>
        ///  OnDragEnter can be overridden so that a Behavior can specify its own Drag/Drop rules.
        /// </summary>
        public override void OnDragEnter(Glyph g, DragEventArgs e)
        {
            ToolStripItemGlyph glyph     = g as ToolStripItemGlyph;
            ToolStripItem      glyphItem = glyph.Item;

            if (e.Data is ToolStripItemDataObject data)
            {
                // support move only within same container.
                if (data.Owner == glyphItem.Owner)
                {
                    PaintInsertionMark(glyphItem);
                    ToolStripDesigner.s_dragItem = glyphItem;
                    e.Effect = DragDropEffects.Move;
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
        public override void OnDragEnter(Glyph g, DragEventArgs e)
        {
            ToolStripItemGlyph      glyph = g as ToolStripItemGlyph;
            ToolStripItem           item  = glyph.Item;
            ToolStripItemDataObject data  = e.Data as ToolStripItemDataObject;

            if (data != null)
            {
                if (data.Owner == item.Owner)
                {
                    this.PaintInsertionMark(item);
                    ToolStripDesigner.dragItem = item;
                    e.Effect = DragDropEffects.Move;
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
 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;
 }
        /// <summary>
        ///  OnDragLeave can be overridden so that a Behavior can specify its own Drag/Drop rules.
        /// </summary>
        public override void OnDragLeave(Glyph g, EventArgs e)
        {
            ToolStripItemGlyph glyph = g as ToolStripItemGlyph;

            ClearInsertionMark(glyph.Item);
        }
        /// <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 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);
        }
 protected override ControlBodyGlyph GetControlGlyph(GlyphSelectionType selectionType)
 {
     if (!this.ToolStrip.IsHandleCreated)
     {
         return null;
     }
     SelectionManager manager = (SelectionManager) this.GetService(typeof(SelectionManager));
     if (((manager != null) && (this.ToolStrip != null)) && (this.CanAddItems && this.ToolStrip.Visible))
     {
         object primarySelection = this.SelectionService.PrimarySelection;
         System.Windows.Forms.Design.Behavior.Behavior b = new ToolStripItemBehavior();
         if (this.ToolStrip.Items.Count > 0)
         {
             ToolStripItem[] array = new ToolStripItem[this.ToolStrip.Items.Count];
             this.ToolStrip.Items.CopyTo(array, 0);
             foreach (ToolStripItem item in array)
             {
                 if (item != null)
                 {
                     ToolStripItemDesigner designer = (ToolStripItemDesigner) this.host.GetDesigner(item);
                     if (((item != primarySelection) && (designer != null)) && designer.IsEditorActive)
                     {
                         designer.Editor.Commit(false, false);
                     }
                 }
             }
         }
         IMenuEditorService service = (IMenuEditorService) this.GetService(typeof(IMenuEditorService));
         if ((service == null) || ((service != null) && !service.IsActive()))
         {
             foreach (ToolStripItem item2 in this.ToolStrip.Items)
             {
                 if (!(item2 is DesignerToolStripControlHost) && (item2.Placement == ToolStripItemPlacement.Main))
                 {
                     ToolStripItemDesigner itemDesigner = (ToolStripItemDesigner) this.host.GetDesigner(item2);
                     if (itemDesigner != null)
                     {
                         bool flag2 = item2 == primarySelection;
                         if (flag2)
                         {
                             ((ToolStripItemBehavior) b).dragBoxFromMouseDown = this.dragBoxFromMouseDown;
                         }
                         if (!flag2)
                         {
                             item2.AutoSize = (itemDesigner != null) ? itemDesigner.AutoSize : true;
                         }
                         Rectangle glyphBounds = itemDesigner.GetGlyphBounds();
                         Control parent = this.ToolStrip.Parent;
                         Rectangle parentBounds = base.BehaviorService.ControlRectInAdornerWindow(parent);
                         if (IsGlyphTotallyVisible(glyphBounds, parentBounds) && item2.Visible)
                         {
                             ToolStripItemGlyph glyph = new ToolStripItemGlyph(item2, itemDesigner, glyphBounds, b);
                             itemDesigner.bodyGlyph = glyph;
                             manager.BodyGlyphAdorner.Glyphs.Add(glyph);
                         }
                     }
                 }
             }
         }
     }
     return base.GetControlGlyph(selectionType);
 }
 internal ToolStripItem AddNewItem(System.Type t, string text, bool enterKeyPressed, bool tabKeyPressed)
 {
     DesignerTransaction transaction = this.host.CreateTransaction(System.Design.SR.GetString("ToolStripAddingItem", new object[] { t.Name }));
     ToolStripItem item = null;
     try
     {
         this._addingItem = true;
         this.ToolStrip.SuspendLayout();
         IComponent component = this.host.CreateComponent(t, NameFromText(text, t, base.Component.Site));
         ToolStripItemDesigner itemDesigner = this.host.GetDesigner(component) as ToolStripItemDesigner;
         try
         {
             if (!string.IsNullOrEmpty(text))
             {
                 itemDesigner.InternalCreate = true;
             }
             if (itemDesigner != null)
             {
                 itemDesigner.InitializeNewComponent(null);
             }
         }
         finally
         {
             itemDesigner.InternalCreate = false;
         }
         item = component as ToolStripItem;
         if (item != null)
         {
             PropertyDescriptor descriptor = TypeDescriptor.GetProperties(item)["Text"];
             if ((descriptor != null) && !string.IsNullOrEmpty(text))
             {
                 descriptor.SetValue(item, text);
             }
             if (((item is ToolStripButton) || (item is ToolStripSplitButton)) || (item is ToolStripDropDownButton))
             {
                 Image image = null;
                 try
                 {
                     image = new Bitmap(typeof(ToolStripButton), "blank.bmp");
                 }
                 catch (Exception exception)
                 {
                     if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                     {
                         throw;
                     }
                 }
                 PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(item)["Image"];
                 if ((descriptor2 != null) && (image != null))
                 {
                     descriptor2.SetValue(item, image);
                 }
                 PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(item)["DisplayStyle"];
                 if (descriptor3 != null)
                 {
                     descriptor3.SetValue(item, ToolStripItemDisplayStyle.Image);
                 }
                 PropertyDescriptor descriptor4 = TypeDescriptor.GetProperties(item)["ImageTransparentColor"];
                 if (descriptor4 != null)
                 {
                     descriptor4.SetValue(item, Color.Magenta);
                 }
             }
         }
         this.ToolStrip.ResumeLayout();
         if (!tabKeyPressed)
         {
             if (enterKeyPressed)
             {
                 if (!itemDesigner.SetSelection(enterKeyPressed) && (this.KeyboardHandlingService != null))
                 {
                     this.KeyboardHandlingService.SelectedDesignerControl = this.editorNode;
                     this.SelectionService.SetSelectedComponents(null, SelectionTypes.Replace);
                 }
             }
             else
             {
                 this.KeyboardHandlingService.SelectedDesignerControl = null;
                 this.SelectionService.SetSelectedComponents(new IComponent[] { item }, SelectionTypes.Replace);
                 this.editorNode.RefreshSelectionGlyph();
             }
         }
         else if (this.keyboardHandlingService != null)
         {
             this.KeyboardHandlingService.SelectedDesignerControl = this.editorNode;
             this.SelectionService.SetSelectedComponents(null, SelectionTypes.Replace);
         }
         if ((itemDesigner != null) && (item.Placement != ToolStripItemPlacement.Overflow))
         {
             Rectangle glyphBounds = itemDesigner.GetGlyphBounds();
             SelectionManager service = (SelectionManager) this.GetService(typeof(SelectionManager));
             System.Windows.Forms.Design.Behavior.Behavior b = new ToolStripItemBehavior();
             ToolStripItemGlyph glyph = new ToolStripItemGlyph(item, itemDesigner, glyphBounds, b);
             service.BodyGlyphAdorner.Glyphs.Insert(0, glyph);
             return item;
         }
         if ((itemDesigner != null) && (item.Placement == ToolStripItemPlacement.Overflow))
         {
             this.RemoveBodyGlyphsForOverflow();
             this.AddBodyGlyphsForOverflow();
         }
         return item;
     }
     catch (Exception exception2)
     {
         this.ToolStrip.ResumeLayout();
         if (this._pendingTransaction != null)
         {
             this._pendingTransaction.Cancel();
             this._pendingTransaction = null;
         }
         if (transaction != null)
         {
             transaction.Cancel();
             transaction = null;
         }
         CheckoutException exception3 = exception2 as CheckoutException;
         if ((exception3 != null) && (exception3 != CheckoutException.Canceled))
         {
             throw;
         }
     }
     finally
     {
         if (this._pendingTransaction != null)
         {
             this._pendingTransaction.Cancel();
             this._pendingTransaction = null;
             if (transaction != null)
             {
                 transaction.Cancel();
             }
         }
         else if (transaction != null)
         {
             transaction.Commit();
             transaction = null;
         }
         this._addingItem = false;
     }
     return item;
 }
        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);
        }