コード例 #1
0
        public override void OnDragDrop(Glyph g, DragEventArgs e)
        {
            ToolStripItem dragItem = ToolStripDesigner.dragItem;

            if ((e.Data is ToolStripItemDataObject) && (dragItem != null))
            {
                ToolStripItemDataObject data             = (ToolStripItemDataObject)e.Data;
                ToolStripItem           primarySelection = data.PrimarySelection;
                IDesignerHost           host             = (IDesignerHost)dragItem.Site.GetService(typeof(IDesignerHost));
                if ((dragItem != primarySelection) && (host != null))
                {
                    string    str;
                    ArrayList dragComponents = data.DragComponents;
                    ToolStrip currentParent  = dragItem.GetCurrentParent();
                    int       index          = -1;
                    bool      flag           = e.Effect == DragDropEffects.Copy;
                    if (dragComponents.Count == 1)
                    {
                        string componentName = TypeDescriptor.GetComponentName(dragComponents[0]);
                        if ((componentName == null) || (componentName.Length == 0))
                        {
                            componentName = dragComponents[0].GetType().Name;
                        }
                        str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControl" : "BehaviorServiceMoveControl", new object[] { componentName });
                    }
                    else
                    {
                        str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControls" : "BehaviorServiceMoveControls", new object[] { dragComponents.Count });
                    }
                    DesignerTransaction transaction = host.CreateTransaction(str);
                    try
                    {
                        IComponentChangeService service = (IComponentChangeService)dragItem.Site.GetService(typeof(IComponentChangeService));
                        if (service != null)
                        {
                            ToolStripDropDown down = currentParent as ToolStripDropDown;
                            if (down != null)
                            {
                                ToolStripItem ownerItem = down.OwnerItem;
                                service.OnComponentChanging(ownerItem, TypeDescriptor.GetProperties(ownerItem)["DropDownItems"]);
                            }
                            else
                            {
                                service.OnComponentChanging(currentParent, TypeDescriptor.GetProperties(currentParent)["Items"]);
                            }
                        }
                        if (flag)
                        {
                            if (primarySelection != null)
                            {
                                index = dragComponents.IndexOf(primarySelection);
                            }
                            ToolStripKeyboardHandlingService keyBoardHandlingService = this.GetKeyBoardHandlingService(primarySelection);
                            if (keyBoardHandlingService != null)
                            {
                                keyBoardHandlingService.CopyInProgress = true;
                            }
                            dragComponents = DesignerUtils.CopyDragObjects(dragComponents, dragItem.Site) as ArrayList;
                            if (keyBoardHandlingService != null)
                            {
                                keyBoardHandlingService.CopyInProgress = false;
                            }
                            if (index != -1)
                            {
                                primarySelection = dragComponents[index] as ToolStripItem;
                            }
                        }
                        if ((e.Effect == DragDropEffects.Move) || flag)
                        {
                            ISelectionService selectionService = this.GetSelectionService(dragItem);
                            if (selectionService != null)
                            {
                                if (currentParent is ToolStripOverflow)
                                {
                                    currentParent = ((ToolStripOverflow)currentParent).OwnerItem.Owner;
                                }
                                int num2 = currentParent.Items.IndexOf(ToolStripDesigner.dragItem);
                                if (num2 != -1)
                                {
                                    int num3 = 0;
                                    if (primarySelection != null)
                                    {
                                        num3 = currentParent.Items.IndexOf(primarySelection);
                                    }
                                    if ((num3 != -1) && (num2 > num3))
                                    {
                                        num2--;
                                    }
                                    foreach (ToolStripItem item4 in dragComponents)
                                    {
                                        currentParent.Items.Insert(num2, item4);
                                    }
                                }
                                selectionService.SetSelectedComponents(new IComponent[] { primarySelection }, SelectionTypes.Click | SelectionTypes.Replace);
                            }
                        }
                        if (service != null)
                        {
                            ToolStripDropDown down2 = currentParent as ToolStripDropDown;
                            if (down2 != null)
                            {
                                ToolStripItem component = down2.OwnerItem;
                                service.OnComponentChanged(component, TypeDescriptor.GetProperties(component)["DropDownItems"], null, null);
                            }
                            else
                            {
                                service.OnComponentChanged(currentParent, TypeDescriptor.GetProperties(currentParent)["Items"], null, null);
                            }
                            if (flag)
                            {
                                if (down2 != null)
                                {
                                    ToolStripItem item6 = down2.OwnerItem;
                                    service.OnComponentChanging(item6, TypeDescriptor.GetProperties(item6)["DropDownItems"]);
                                    service.OnComponentChanged(item6, TypeDescriptor.GetProperties(item6)["DropDownItems"], null, null);
                                }
                                else
                                {
                                    service.OnComponentChanging(currentParent, TypeDescriptor.GetProperties(currentParent)["Items"]);
                                    service.OnComponentChanged(currentParent, TypeDescriptor.GetProperties(currentParent)["Items"], null, null);
                                }
                            }
                        }
                        foreach (ToolStripItem item7 in dragComponents)
                        {
                            if (item7 is ToolStripDropDownItem)
                            {
                                ToolStripMenuItemDesigner designer = host.GetDesigner(item7) as ToolStripMenuItemDesigner;
                                if (designer != null)
                                {
                                    designer.InitializeDropDown();
                                }
                            }
                            ToolStripDropDown down3 = item7.GetCurrentParent() as ToolStripDropDown;
                            if ((down3 != null) && !(down3 is ToolStripOverflow))
                            {
                                ToolStripDropDownItem item8 = down3.OwnerItem as ToolStripDropDownItem;
                                if (item8 != null)
                                {
                                    ToolStripMenuItemDesigner designer2 = host.GetDesigner(item8) as ToolStripMenuItemDesigner;
                                    if (designer2 != null)
                                    {
                                        designer2.InitializeBodyGlyphsForItems(false, item8);
                                        designer2.InitializeBodyGlyphsForItems(true, item8);
                                    }
                                }
                            }
                        }
                        BehaviorService behaviorService = this.GetBehaviorService(dragItem);
                        if (behaviorService != null)
                        {
                            behaviorService.SyncSelection();
                        }
                    }
                    catch (Exception exception)
                    {
                        if (transaction != null)
                        {
                            transaction.Cancel();
                            transaction = null;
                        }
                        if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                        {
                            throw;
                        }
                    }
                    finally
                    {
                        if (transaction != null)
                        {
                            transaction.Commit();
                            transaction = null;
                        }
                    }
                }
            }
        }
コード例 #2
0
 public void ShowMenu()
 {
     if (this.menuItem != null)
     {
         Control parent    = this.designMenu.Parent;
         Form    component = parent as Form;
         if (component != null)
         {
             this.parentFormDesigner = this.host.GetDesigner(component) as FormDocumentDesigner;
             if ((this.parentFormDesigner != null) && (this.parentFormDesigner.Menu != null))
             {
                 this.parentMenu = this.parentFormDesigner.Menu;
                 this.parentFormDesigner.Menu = null;
             }
         }
         this.selected           = true;
         this.designMenu.Visible = true;
         this.designMenu.BringToFront();
         this.menuItem.Visible = true;
         if ((this.currentParent != null) && (this.currentParent != this.menuItem))
         {
             ToolStripMenuItemDesigner designer = this.host.GetDesigner(this.currentParent) as ToolStripMenuItemDesigner;
             if (designer != null)
             {
                 designer.RemoveTypeHereNode(this.currentParent);
             }
         }
         this.menuItem.DropDown           = this.dropDown;
         this.menuItem.DropDown.OwnerItem = this.menuItem;
         if (this.dropDown.Items.Count > 0)
         {
             ToolStripItem[] array = new ToolStripItem[this.dropDown.Items.Count];
             this.dropDown.Items.CopyTo(array, 0);
             foreach (ToolStripItem item in array)
             {
                 if (item is DesignerToolStripControlHost)
                 {
                     this.dropDown.Items.Remove(item);
                 }
             }
         }
         ToolStripMenuItemDesigner designer2 = (ToolStripMenuItemDesigner)this.host.GetDesigner(this.menuItem);
         BehaviorService           service   = (BehaviorService)this.GetService(typeof(BehaviorService));
         if (service != null)
         {
             if ((designer2 != null) && (parent != null))
             {
                 Rectangle parentBounds = service.ControlRectInAdornerWindow(parent);
                 if (ToolStripDesigner.IsGlyphTotallyVisible(service.ControlRectInAdornerWindow(this.designMenu), parentBounds))
                 {
                     designer2.InitializeDropDown();
                 }
             }
             if (this.dummyToolStripGlyph == null)
             {
                 Point     pos    = service.ControlToAdornerWindow(this.designMenu);
                 Rectangle bounds = this.designMenu.Bounds;
                 bounds.Offset(pos);
                 this.dummyToolStripGlyph = new ControlBodyGlyph(bounds, Cursor.Current, this.menuItem, new ContextMenuStripBehavior(this.menuItem));
                 SelectionManager manager = (SelectionManager)this.GetService(typeof(SelectionManager));
                 if (manager != null)
                 {
                     manager.BodyGlyphAdorner.Glyphs.Insert(0, this.dummyToolStripGlyph);
                 }
             }
             ToolStripKeyboardHandlingService service2 = (ToolStripKeyboardHandlingService)this.GetService(typeof(ToolStripKeyboardHandlingService));
             if (service2 != null)
             {
                 int num = this.dropDown.Items.Count - 1;
                 if (num >= 0)
                 {
                     service2.SelectedDesignerControl = this.dropDown.Items[num];
                 }
             }
         }
     }
 }
コード例 #3
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();
                                }
                            }
                        }
                    }
                }
            }
        }