/// <summary>
        ///  We override our base class's WndProc to monitor certain messages.
        /// </summary>
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            switch (m.Msg)
            {
            case (int)User32.WM.HSCROLL:
            case (int)User32.WM.VSCROLL:

                // When we scroll, we reposition a control without causing a
                // property change event.  Therefore, we must tell the
                // SelectionManager to refresh its glyphs.
                if (selManager == null)
                {
                    selManager = GetService(typeof(SelectionManager)) as SelectionManager;
                }

                if (selManager != null)
                {
                    selManager.Refresh();
                }

                // Now we must paint our adornments, since the scroll does not
                // trigger a paint event
                //
                Control.Invalidate();
                Control.Update();
                break;
            }
        }
Esempio n. 2
0
        ///
        ///
        ///      Called when the current selection changes.  Here we check to
        ///      see if the newly selected component is one of our tabs.  If it
        ///      is, we make sure that the tab is the currently visible tab.
        ///
        private void OnSelectionChanged(Object sender, EventArgs e)
        {
            ISelectionService svc = (ISelectionService)GetService(typeof(ISelectionService));

            tabControlSelected = false;//this is for HitTest purposes

            if (svc != null)
            {
                ICollection selComponents = svc.GetSelectedComponents();

                TabControl tabControl = (TabControl)Component;

                foreach (object comp in selComponents)
                {
                    if (comp == tabControl)
                    {
                        tabControlSelected = true;//this is for HitTest purposes
                    }

                    TabPage page = GetTabPageOfComponent(comp);

                    if (page != null && page.Parent == tabControl)
                    {
                        tabControlSelected     = false; //this is for HitTest purposes
                        tabControl.SelectedTab = page;
                        SelectionManager selMgr = (SelectionManager)GetService(typeof(SelectionManager));
                        selMgr.Refresh();
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        protected override void OnDragDrop(DragEventArgs de)
        {
            base.OnDragDrop(de);
            SelectionManager service = this.GetService(typeof(SelectionManager)) as SelectionManager;

            if (service != null)
            {
                service.Refresh();
            }
        }
 private void HideMenu()
 {
     if (this.menuItem != null)
     {
         if ((this.parentMenu != null) && (this.parentFormDesigner != null))
         {
             this.parentFormDesigner.Menu = this.parentMenu;
         }
         this.selected = false;
         if (this.host.RootComponent is Control)
         {
             this.menuItem.DropDown.AutoClose = true;
             this.menuItem.HideDropDown();
             this.menuItem.Visible   = false;
             this.designMenu.Visible = false;
             ToolStripAdornerWindowService service = (ToolStripAdornerWindowService)this.GetService(typeof(ToolStripAdornerWindowService));
             if (service != null)
             {
                 service.Invalidate();
             }
             if (((BehaviorService)this.GetService(typeof(BehaviorService))) != null)
             {
                 if (this.dummyToolStripGlyph != null)
                 {
                     SelectionManager manager = (SelectionManager)this.GetService(typeof(SelectionManager));
                     if (manager != null)
                     {
                         if (manager.BodyGlyphAdorner.Glyphs.Contains(this.dummyToolStripGlyph))
                         {
                             manager.BodyGlyphAdorner.Glyphs.Remove(this.dummyToolStripGlyph);
                         }
                         manager.Refresh();
                     }
                 }
                 this.dummyToolStripGlyph = null;
             }
             if (this.menuItem != null)
             {
                 ToolStripMenuItemDesigner designer = this.host.GetDesigner(this.menuItem) as ToolStripMenuItemDesigner;
                 if (designer != null)
                 {
                     designer.UnHookEvents();
                     designer.RemoveTypeHereNode(this.menuItem);
                 }
             }
         }
     }
 }
Esempio n. 5
0
 private void OnControlRemoved(object sender, ControlEventArgs e)
 {
     if (this.panel.Controls.Count == 0)
     {
         if (this.containerSelectorGlyph != null)
         {
             this.containerSelectorGlyph.IsExpanded = false;
         }
         if ((this.designerHost != null) && !this.designerHost.Loading)
         {
             SelectionManager service = (SelectionManager)this.GetService(typeof(SelectionManager));
             if (service != null)
             {
                 service.Refresh();
             }
         }
     }
 }
 private void ChangeProperty(Component comp, string propertyName, object value)
 {
     if (this.host != null)
     {
         ToolStripPanel         panel    = comp as ToolStripPanel;
         ToolStripPanelDesigner designer = this.host.GetDesigner(comp) as ToolStripPanelDesigner;
         if (propertyName.Equals("Visible"))
         {
             foreach (Control control in panel.Controls)
             {
                 PropertyDescriptor descriptor = TypeDescriptor.GetProperties(control)["Visible"];
                 if (descriptor != null)
                 {
                     descriptor.SetValue(control, value);
                 }
             }
             if (!((bool)value))
             {
                 if (panel != null)
                 {
                     panel.Padding = new Padding(0);
                 }
                 if ((designer != null) && (designer.ToolStripPanelSelectorGlyph != null))
                 {
                     designer.ToolStripPanelSelectorGlyph.IsExpanded = false;
                 }
             }
         }
         PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(comp)[propertyName];
         if (descriptor2 != null)
         {
             descriptor2.SetValue(comp, value);
         }
         SelectionManager service = (SelectionManager)this.provider.GetService(typeof(SelectionManager));
         if (service != null)
         {
             service.Refresh();
         }
         if (designer != null)
         {
             designer.InvalidateGlyph();
         }
     }
 }
 private void OnSplitterMoved(object sender, SplitterEventArgs e)
 {
     if ((this.InheritanceAttribute != InheritanceAttribute.InheritedReadOnly) && !this.splitterDistanceException)
     {
         try
         {
             base.RaiseComponentChanging(TypeDescriptor.GetProperties(this.splitContainer)["SplitterDistance"]);
             base.RaiseComponentChanged(TypeDescriptor.GetProperties(this.splitContainer)["SplitterDistance"], null, null);
             if (this.disabledGlyphs)
             {
                 base.BehaviorService.EnableAllAdorners(true);
                 SelectionManager service = (SelectionManager)this.GetService(typeof(SelectionManager));
                 if (service != null)
                 {
                     service.Refresh();
                 }
                 this.disabledGlyphs = false;
             }
         }
         catch (InvalidOperationException exception)
         {
             ((IUIService)base.Component.Site.GetService(typeof(IUIService))).ShowError(exception.Message);
         }
         catch (CheckoutException exception2)
         {
             if (exception2 == CheckoutException.Canceled)
             {
                 try
                 {
                     this.splitterDistanceException       = true;
                     this.splitContainer.SplitterDistance = this.initialSplitterDist;
                     return;
                 }
                 finally
                 {
                     this.splitterDistanceException = false;
                 }
             }
             throw;
         }
     }
 }
Esempio n. 8
0
 private void OnControlAdded(object sender, ControlEventArgs e)
 {
     if (e.Control is ToolStrip)
     {
         this.panel.Padding = new System.Windows.Forms.Padding(0);
         if (this.containerSelectorGlyph != null)
         {
             this.containerSelectorGlyph.IsExpanded = false;
         }
         PropertyDescriptor descriptor = TypeDescriptor.GetProperties(e.Control)["Dock"];
         if (descriptor != null)
         {
             descriptor.SetValue(e.Control, DockStyle.None);
         }
         if ((this.designerHost != null) && !this.designerHost.Loading)
         {
             SelectionManager service = (SelectionManager)this.GetService(typeof(SelectionManager));
             if (service != null)
             {
                 service.Refresh();
             }
         }
     }
 }
        /// <summary>
        ///  Here is where all the fun stuff starts.  We create the structure and apply the naming here.
        /// </summary>
        private void CreateStandardMenuStrip(IDesignerHost host, MenuStrip tool)
        {
            // build the static menu items structure.
            string[][] menuItemNames = new string[][]
            {
                new string[] { SR.StandardMenuFile, SR.StandardMenuNew, SR.StandardMenuOpen, "-", SR.StandardMenuSave, SR.StandardMenuSaveAs, "-", SR.StandardMenuPrint, SR.StandardMenuPrintPreview, "-", SR.StandardMenuExit },
                new string[] { SR.StandardMenuEdit, SR.StandardMenuUndo, SR.StandardMenuRedo, "-", SR.StandardMenuCut, SR.StandardMenuCopy, SR.StandardMenuPaste, "-", SR.StandardMenuSelectAll },
                new string[] { SR.StandardMenuTools, SR.StandardMenuCustomize, SR.StandardMenuOptions },
                new string[] { SR.StandardMenuHelp, SR.StandardMenuContents, SR.StandardMenuIndex, SR.StandardMenuSearch, "-", SR.StandardMenuAbout }
            };

            // build the static menu items image list that maps one-one with above menuItems structure. this is required so that the in LOCALIZED build we dont use the Localized item string.
            string[][] menuItemImageNames = new string[][]
            {
                new string[] { "", "new", "open", "-", "save", "", "-", "print", "printPreview", "-", "" },
                new string[] { "", "", "", "-", "cut", "copy", "paste", "-", "" },
                new string[] { "", "", "" },
                new string[] { "", "", "", "", "-", "" }
            };

            Keys[][] menuItemShortcuts = new Keys[][]
            {
                new Keys[] { /*File*/ Keys.None, /*New*/ Keys.Control | Keys.N, /*Open*/ Keys.Control | Keys.O, /*Separator*/ Keys.None, /*Save*/ Keys.Control | Keys.S, /*SaveAs*/ Keys.None, Keys.None, /*Print*/ Keys.Control | Keys.P, /*PrintPreview*/ Keys.None, /*Separator*/ Keys.None, /*Exit*/ Keys.None },
                new Keys[] { /*Edit*/ Keys.None, /*Undo*/ Keys.Control | Keys.Z, /*Redo*/ Keys.Control | Keys.Y, /*Separator*/ Keys.None, /*Cut*/ Keys.Control | Keys.X, /*Copy*/ Keys.Control | Keys.C, /*Paste*/ Keys.Control | Keys.V, /*Separator*/ Keys.None, /*SelectAll*/ Keys.None },
                new Keys[] { /*Tools*/ Keys.None, /*Customize*/ Keys.None, /*Options*/ Keys.None },
                new Keys[] { /*Help*/ Keys.None, /*Contents*/ Keys.None, /*Index*/ Keys.None, /*Search*/ Keys.None, /*Separator*/ Keys.None, /*About*/ Keys.None }
            };

            Debug.Assert(host != null, "can't create standard menu without designer _host.");
            if (host is null)
            {
                return;
            }

            tool.SuspendLayout();
            ToolStripDesigner.s_autoAddNewItems = false;
            // create a transaction so this happens as an atomic unit.
            DesignerTransaction createMenu = _host.CreateTransaction(SR.StandardMenuCreateDesc);

            try
            {
                INameCreationService nameCreationService = (INameCreationService)_provider.GetService(typeof(INameCreationService));
                string defaultName = "standardMainMenuStrip";
                string name        = defaultName;
                int    index       = 1;

                if (host != null)
                {
                    while (_host.Container.Components[name] != null)
                    {
                        name = defaultName + (index++).ToString(CultureInfo.InvariantCulture);
                    }
                }

                // now build the menu items themselves.
                for (int j = 0; j < menuItemNames.Length; j++)
                {
                    string[]          menuArray = menuItemNames[j];
                    ToolStripMenuItem rootItem  = null;
                    for (int i = 0; i < menuArray.Length; i++)
                    {
                        name = null;
                        // for separators, just use the default name.  Otherwise, remove any non-characters and  get the name from the text.
                        string itemText = menuArray[i];
                        name = NameFromText(itemText, typeof(ToolStripMenuItem), nameCreationService, true);
                        ToolStripItem item = null;
                        if (name.Contains("Separator"))
                        {
                            // create the componennt.
                            item = (ToolStripSeparator)_host.CreateComponent(typeof(ToolStripSeparator), name);
                            IDesigner designer = _host.GetDesigner(item);
                            if (designer is ComponentDesigner)
                            {
                                ((ComponentDesigner)designer).InitializeNewComponent(null);
                            }

                            item.Text = itemText;
                        }
                        else
                        {
                            // create the componennt.
                            item = (ToolStripMenuItem)_host.CreateComponent(typeof(ToolStripMenuItem), name);
                            IDesigner designer = _host.GetDesigner(item);
                            if (designer is ComponentDesigner)
                            {
                                ((ComponentDesigner)designer).InitializeNewComponent(null);
                            }

                            item.Text = itemText;
                            Keys shortcut = menuItemShortcuts[j][i];
                            if ((item is ToolStripMenuItem) && shortcut != Keys.None)
                            {
                                if (!ToolStripManager.IsShortcutDefined(shortcut) && ToolStripManager.IsValidShortcut(shortcut))
                                {
                                    ((ToolStripMenuItem)item).ShortcutKeys = shortcut;
                                }
                            }

                            Bitmap image = null;
                            try
                            {
                                image = GetImage(menuItemImageNames[j][i]);
                            }
                            catch
                            {
                                // eat the exception.. as you may not find image for all MenuItems.
                            }

                            if (image != null)
                            {
                                PropertyDescriptor imageProperty = TypeDescriptor.GetProperties(item)["Image"];
                                Debug.Assert(imageProperty != null, "Could not find 'Image' property in ToolStripItem.");
                                if (imageProperty != null)
                                {
                                    imageProperty.SetValue(item, image);
                                }

                                item.ImageTransparentColor = Color.Magenta;
                            }
                        }

                        // the first item in each array is the root item.
                        if (i == 0)
                        {
                            rootItem = (ToolStripMenuItem)item;
                            rootItem.DropDown.SuspendLayout();
                        }
                        else
                        {
                            rootItem.DropDownItems.Add(item);
                        }

                        //If Last SubItem Added the Raise the Events
                        if (i == menuArray.Length - 1)
                        {
                            // member is OK to be null...
                            MemberDescriptor member = TypeDescriptor.GetProperties(rootItem)["DropDownItems"];
                            _componentChangeSvc.OnComponentChanging(rootItem, member);
                            _componentChangeSvc.OnComponentChanged(rootItem, member, null, null);
                        }
                    }

                    // finally, add it to the MainMenu.
                    rootItem.DropDown.ResumeLayout(false);
                    tool.Items.Add(rootItem);
                    //If Last SubItem Added the Raise the Events
                    if (j == menuItemNames.Length - 1)
                    {
                        // member is OK to be null...
                        MemberDescriptor topMember = TypeDescriptor.GetProperties(tool)["Items"];
                        _componentChangeSvc.OnComponentChanging(tool, topMember);
                        _componentChangeSvc.OnComponentChanged(tool, topMember, null, null);
                    }
                }
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException)
                {
                    IUIService uiService = (IUIService)_provider.GetService(typeof(IUIService));
                    uiService.ShowError(e.Message);
                }

                if (createMenu != null)
                {
                    createMenu.Cancel();
                    createMenu = null;
                }
            }
            finally
            {
                ToolStripDesigner.s_autoAddNewItems = true;
                if (createMenu != null)
                {
                    createMenu.Commit();
                    createMenu = null;
                }

                tool.ResumeLayout();
                // Select the Main Menu...
                ISelectionService selSvc = (ISelectionService)_provider.GetService(typeof(ISelectionService));
                if (selSvc != null)
                {
                    selSvc.SetSelectedComponents(new object[] { _designer.Component });
                }

                //Refresh the Glyph
                DesignerActionUIService actionUIService = (DesignerActionUIService)_provider.GetService(typeof(DesignerActionUIService));
                if (actionUIService != null)
                {
                    actionUIService.Refresh(_designer.Component);
                }

                // this will invalidate the Selection Glyphs.
                SelectionManager selMgr = (SelectionManager)_provider.GetService(typeof(SelectionManager));
                selMgr.Refresh();
            }
        }
        /// <summary>
        ///  Here is where all the fun stuff starts.  We create the structure and apply the naming here.
        /// </summary>
        private void CreateStandardToolStrip(IDesignerHost host, ToolStrip tool)
        {
            // build the static menu items structure.
            //
            string[] menuItemNames = new string[] { SR.StandardMenuNew, SR.StandardMenuOpen, SR.StandardMenuSave, SR.StandardMenuPrint, "-", SR.StandardToolCut, SR.StandardMenuCopy, SR.StandardMenuPaste, "-", SR.StandardToolHelp };

            // build a image list mapping one-one the above menuItems list... this is required so that the in LOCALIZED build we dont use the Localized item string.
            string[] menuItemImageNames = new string[] { "new", "open", "save", "print", "-", "cut", "copy", "paste", "-", "help" };
            Debug.Assert(host != null, "can't create standard menu without designer _host.");

            if (host is null)
            {
                return;
            }

            tool.SuspendLayout();
            ToolStripDesigner.s_autoAddNewItems = false;
            // create a transaction so this happens as an atomic unit.
            DesignerTransaction createMenu = _host.CreateTransaction(SR.StandardMenuCreateDesc);

            try
            {
                INameCreationService nameCreationService = (INameCreationService)_provider.GetService(typeof(INameCreationService));
                string defaultName = "standardMainToolStrip";
                string name        = defaultName;
                int    index       = 1;
                if (host != null)
                {
                    while (_host.Container.Components[name] != null)
                    {
                        name = defaultName + (index++).ToString(CultureInfo.InvariantCulture);
                    }
                }

                //keep an index in the MenuItemImageNames .. so that mapping is maintained.
                int menuItemImageNamesCount = 0;
                // now build the menu items themselves.
                foreach (string itemText in menuItemNames)
                {
                    name = null;
                    // for separators, just use the default name.  Otherwise, remove any non-characters and get the name from the text.
                    defaultName = "ToolStripButton";
                    name        = NameFromText(itemText, typeof(ToolStripButton), nameCreationService, true);
                    ToolStripItem item = null;
                    if (name.Contains("Separator"))
                    {
                        // create the componennt.
                        item = (ToolStripSeparator)_host.CreateComponent(typeof(ToolStripSeparator), name);
                        IDesigner designer = _host.GetDesigner(item);
                        if (designer is ComponentDesigner)
                        {
                            ((ComponentDesigner)designer).InitializeNewComponent(null);
                        }
                    }
                    else
                    {
                        // create the component.
                        item = (ToolStripButton)_host.CreateComponent(typeof(ToolStripButton), name);
                        IDesigner designer = _host.GetDesigner(item);
                        if (designer is ComponentDesigner)
                        {
                            ((ComponentDesigner)designer).InitializeNewComponent(null);
                        }

                        PropertyDescriptor displayStyleProperty = TypeDescriptor.GetProperties(item)["DisplayStyle"];
                        Debug.Assert(displayStyleProperty != null, "Could not find 'Text' property in ToolStripItem.");
                        if (displayStyleProperty != null)
                        {
                            displayStyleProperty.SetValue(item, ToolStripItemDisplayStyle.Image);
                        }

                        PropertyDescriptor textProperty = TypeDescriptor.GetProperties(item)["Text"];
                        Debug.Assert(textProperty != null, "Could not find 'Text' property in ToolStripItem.");
                        if (textProperty != null)
                        {
                            textProperty.SetValue(item, itemText);
                        }

                        Bitmap image = null;
                        try
                        {
                            image = GetImage(menuItemImageNames[menuItemImageNamesCount]);
                        }
                        catch
                        {
                            // eat the exception.. as you may not find image for all MenuItems.
                        }

                        if (image != null)
                        {
                            PropertyDescriptor imageProperty = TypeDescriptor.GetProperties(item)["Image"];
                            Debug.Assert(imageProperty != null, "Could not find 'Image' property in ToolStripItem.");
                            if (imageProperty != null)
                            {
                                imageProperty.SetValue(item, image);
                            }

                            item.ImageTransparentColor = Color.Magenta;
                        }
                    }

                    tool.Items.Add(item);
                    //increment the counter...
                    menuItemImageNamesCount++;
                }

                // finally, add it to the Main ToolStrip.
                MemberDescriptor topMember = TypeDescriptor.GetProperties(tool)["Items"];
                _componentChangeSvc.OnComponentChanging(tool, topMember);
                _componentChangeSvc.OnComponentChanged(tool, topMember, null, null);
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException)
                {
                    IUIService uiService = (IUIService)_provider.GetService(typeof(IUIService));
                    uiService.ShowError(e.Message);
                }

                if (createMenu != null)
                {
                    createMenu.Cancel();
                    createMenu = null;
                }
            }
            finally
            {
                //Reset the AutoAdd state
                ToolStripDesigner.s_autoAddNewItems = true;
                if (createMenu != null)
                {
                    createMenu.Commit();
                    createMenu = null;
                }

                tool.ResumeLayout();
                // Select the Main Menu...
                ISelectionService selSvc = (ISelectionService)_provider.GetService(typeof(ISelectionService));
                if (selSvc != null)
                {
                    selSvc.SetSelectedComponents(new object[] { _designer.Component });
                }

                //Refresh the Glyph
                DesignerActionUIService actionUIService = (DesignerActionUIService)_provider.GetService(typeof(DesignerActionUIService));
                if (actionUIService != null)
                {
                    actionUIService.Refresh(_designer.Component);
                }

                // this will invalidate the Selection Glyphs.
                SelectionManager selMgr = (SelectionManager)_provider.GetService(typeof(SelectionManager));
                selMgr.Refresh();
            }
        }
Esempio n. 11
0
        internal virtual void CommitEdit(System.Type type, string text, bool commit, bool enterKeyPressed, bool tabKeyPressed)
        {
            System.Windows.Forms.ToolStripItem component = null;
            SelectionManager manager         = (SelectionManager)this.GetService(typeof(SelectionManager));
            BehaviorService  service         = (BehaviorService)this.GetService(typeof(BehaviorService));
            ToolStrip        immediateParent = this.ImmediateParent as ToolStrip;

            immediateParent.SuspendLayout();
            this.HideDummyNode();
            IDesignerHost     host     = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            ToolStripDesigner designer = (ToolStripDesigner)host.GetDesigner(this.ToolStripItem.Owner);

            if ((designer != null) && (designer.EditManager != null))
            {
                designer.EditManager.ActivateEditor(null, false);
            }
            if ((immediateParent is MenuStrip) && (type == typeof(ToolStripSeparator)))
            {
                IDesignerHost host2 = (IDesignerHost)this.GetService(typeof(IDesignerHost));
                if (host2 != null)
                {
                    IUIService service2 = (IUIService)host2.GetService(typeof(IUIService));
                    if (service2 != null)
                    {
                        service2.ShowError(System.Design.SR.GetString("ToolStripSeparatorError"));
                        commit = false;
                        if (this.selSvc != null)
                        {
                            this.selSvc.SetSelectedComponents(new object[] { immediateParent });
                        }
                    }
                }
            }
            if (!commit)
            {
                if (this.dummyItemAdded)
                {
                    this.dummyItemAdded = false;
                    this.RemoveItem();
                    if (designer.NewItemTransaction != null)
                    {
                        designer.NewItemTransaction.Cancel();
                        designer.NewItemTransaction = null;
                    }
                }
                goto Label_0246;
            }
            if (this.dummyItemAdded)
            {
                try
                {
                    this.RemoveItem();
                    component = designer.AddNewItem(type, text, enterKeyPressed, false);
                    goto Label_020B;
                }
                finally
                {
                    if (designer.NewItemTransaction != null)
                    {
                        designer.NewItemTransaction.Commit();
                        designer.NewItemTransaction = null;
                    }
                }
            }
            DesignerTransaction transaction = host.CreateTransaction(System.Design.SR.GetString("ToolStripItemPropertyChangeTransaction"));

            try
            {
                PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.ToolStripItem)["Text"];
                string             str        = (string)descriptor.GetValue(this.ToolStripItem);
                if ((descriptor != null) && (text != str))
                {
                    descriptor.SetValue(this.ToolStripItem, text);
                }
                if (enterKeyPressed && (this.selSvc != null))
                {
                    this.SelectNextItem(this.selSvc, enterKeyPressed, designer);
                }
            }
            catch (Exception exception)
            {
                if (transaction != null)
                {
                    transaction.Cancel();
                    transaction = null;
                }
                if (manager != null)
                {
                    manager.Refresh();
                }
                if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                {
                    throw;
                }
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Commit();
                    transaction = null;
                }
            }
Label_020B:
            this.dummyItemAdded = false;
Label_0246:
            immediateParent.ResumeLayout();
            if ((component != null) && !component.IsOnDropDown)
            {
                ToolStripDropDownItem item2 = component as ToolStripDropDownItem;
                if (item2 != null)
                {
                    Rectangle glyphBounds   = ((ToolStripItemDesigner)host.GetDesigner(component)).GetGlyphBounds();
                    Control   rootComponent = host.RootComponent as Control;
                    if ((rootComponent != null) && (service != null))
                    {
                        Rectangle parentBounds = service.ControlRectInAdornerWindow(rootComponent);
                        if (!ToolStripDesigner.IsGlyphTotallyVisible(glyphBounds, parentBounds))
                        {
                            item2.HideDropDown();
                        }
                    }
                }
            }
            if (manager != null)
            {
                manager.Refresh();
            }
        }
Esempio n. 12
0
        private void OnSelectionChanged(object sender, EventArgs e)
        {
            ISelectionService service = sender as ISelectionService;

            if (service != null)
            {
                System.Windows.Forms.ToolStripItem primarySelection = service.PrimarySelection as System.Windows.Forms.ToolStripItem;
                System.Windows.Forms.ToolStripItem.ToolStripItemAccessibleObject accessibilityObject = this.ToolStripItem.AccessibilityObject as System.Windows.Forms.ToolStripItem.ToolStripItemAccessibleObject;
                if (accessibilityObject != null)
                {
                    accessibilityObject.AddState(AccessibleStates.None);
                    ToolStrip mainToolStrip = this.GetMainToolStrip();
                    if (service.GetComponentSelected(this.ToolStripItem))
                    {
                        ToolStrip immediateParent = this.ImmediateParent as ToolStrip;
                        int       index           = 0;
                        if (immediateParent != null)
                        {
                            index = immediateParent.Items.IndexOf(primarySelection);
                        }
                        accessibilityObject.AddState(AccessibleStates.Selected);
                        if (mainToolStrip != null)
                        {
                            System.Design.UnsafeNativeMethods.NotifyWinEvent(0x8007, new HandleRef(immediateParent, immediateParent.Handle), -4, index + 1);
                        }
                        if (primarySelection == this.ToolStripItem)
                        {
                            accessibilityObject.AddState(AccessibleStates.Focused);
                            if (mainToolStrip != null)
                            {
                                System.Design.UnsafeNativeMethods.NotifyWinEvent(0x8005, new HandleRef(immediateParent, immediateParent.Handle), -4, index + 1);
                            }
                        }
                    }
                }
                if ((((primarySelection != null) && (this.ToolStripItem != null)) && (primarySelection.IsOnDropDown && this.ToolStripItem.Equals(primarySelection))) && !(this.ToolStripItem is ToolStripMenuItem))
                {
                    IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
                    if (host != null)
                    {
                        ToolStripDropDown owner = primarySelection.Owner as ToolStripDropDown;
                        if ((owner != null) && !owner.Visible)
                        {
                            ToolStripDropDownItem ownerItem = owner.OwnerItem as ToolStripDropDownItem;
                            if (ownerItem != null)
                            {
                                ToolStripMenuItemDesigner designer = (ToolStripMenuItemDesigner)host.GetDesigner(ownerItem);
                                if (designer != null)
                                {
                                    designer.InitializeDropDown();
                                }
                                SelectionManager manager = (SelectionManager)this.GetService(typeof(SelectionManager));
                                if (manager != null)
                                {
                                    manager.Refresh();
                                }
                            }
                        }
                    }
                }
            }
        }