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);
             }
         }
     }
 }
 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;
 }