private void toolStripDropDown_Closing(object sender, ToolStripDropDownClosingEventArgs e)
 {
     if (this.cancelClose || e.Cancel)
     {
         e.Cancel = true;
     }
     else
     {
         if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
         {
             e.Cancel = true;
         }
         if (e.CloseReason == ToolStripDropDownCloseReason.Keyboard)
         {
             e.Cancel = false;
         }
         if (!e.Cancel && (this.lastPanelComponent != null))
         {
             Point lastCursorPoint     = DesignerUtils.LastCursorPoint;
             DesignerActionGlyph glyph = this.componentToGlyph[this.lastPanelComponent] as DesignerActionGlyph;
             if (glyph != null)
             {
                 Rectangle rectangle3 = new Rectangle(this.GetGlyphLocationScreenCoord(this.lastPanelComponent, glyph), new Size(glyph.Bounds.Width, glyph.Bounds.Height));
                 if (rectangle3.Contains(lastCursorPoint))
                 {
                     DesignerActionBehavior behavior = glyph.Behavior as DesignerActionBehavior;
                     behavior.IgnoreNextMouseUp = true;
                 }
                 glyph.InvalidateOwnerLocation();
             }
             this.lastPanelComponent = null;
             this.behaviorService.PopBehavior(this.dapkb);
         }
     }
 }
        internal Point UpdateDAPLocation(IComponent component, DesignerActionGlyph glyph)
        {
            DockStyle style;

            if (component == null)
            {
                component = this.lastPanelComponent;
            }
            if (this.designerActionHost == null)
            {
                return(Point.Empty);
            }
            if ((component == null) || (glyph == null))
            {
                return(this.designerActionHost.Location);
            }
            if ((this.behaviorService != null) && !this.behaviorService.AdornerWindowControl.DisplayRectangle.IntersectsWith(glyph.Bounds))
            {
                this.HideDesignerActionPanel();
                return(this.designerActionHost.Location);
            }
            Point     glyphLocationScreenCoord = this.GetGlyphLocationScreenCoord(component, glyph);
            Rectangle rectangleAnchor          = new Rectangle(glyphLocationScreenCoord, glyph.Bounds.Size);
            Point     point2 = DesignerActionPanel.ComputePreferredDesktopLocation(rectangleAnchor, this.designerActionHost.Size, out style);

            glyph.DockEdge = style;
            this.designerActionHost.Location = point2;
            return(point2);
        }
        private void OnInvokedDesignerActionChanged(object sender, DesignerActionListsChangedEventArgs e)
        {
            IComponent          relatedObject       = e.RelatedObject as IComponent;
            DesignerActionGlyph designerActionGlyph = null;

            if (e.ChangeType == DesignerActionListsChangedType.ActionListsAdded)
            {
                if (relatedObject == null)
                {
                    return;
                }
                IComponent primarySelection = this.selSvc.PrimarySelection as IComponent;
                if (primarySelection == e.RelatedObject)
                {
                    designerActionGlyph = this.GetDesignerActionGlyph(relatedObject, e.ActionLists);
                    if (designerActionGlyph != null)
                    {
                        this.VerifyGlyphIsInAdorner(designerActionGlyph);
                    }
                    else
                    {
                        this.RemoveActionGlyph(e.RelatedObject);
                    }
                }
            }
            if ((e.ChangeType == DesignerActionListsChangedType.ActionListsRemoved) && (e.ActionLists.Count == 0))
            {
                this.RemoveActionGlyph(e.RelatedObject);
            }
            else if (designerActionGlyph != null)
            {
                this.RecreatePanel(relatedObject);
            }
        }
 internal bool ShowDesignerActionPanelForPrimarySelection()
 {
     if (this.selSvc != null)
     {
         object primarySelection = this.selSvc.PrimarySelection;
         if ((primarySelection == null) || !this.componentToGlyph.Contains(primarySelection))
         {
             return(false);
         }
         DesignerActionGlyph g = (DesignerActionGlyph)this.componentToGlyph[primarySelection];
         if ((g != null) && (g.Behavior is DesignerActionBehavior))
         {
             DesignerActionBehavior behavior = g.Behavior as DesignerActionBehavior;
             if (behavior != null)
             {
                 if (!this.IsDesignerActionPanelVisible)
                 {
                     behavior.ShowUI(g);
                     return(true);
                 }
                 behavior.HideUI();
                 return(false);
             }
         }
     }
     return(false);
 }
 internal void RemoveActionGlyph(object relatedObject)
 {
     if (relatedObject != null)
     {
         if (this.IsDesignerActionPanelVisible && (relatedObject == this.lastPanelComponent))
         {
             this.HideDesignerActionPanel();
         }
         DesignerActionGlyph glyph = (DesignerActionGlyph)this.componentToGlyph[relatedObject];
         if (glyph != null)
         {
             ComponentTray service = this.serviceProvider.GetService(typeof(ComponentTray)) as ComponentTray;
             if (((service != null) && (service.SelectionGlyphs != null)) && ((service != null) && service.SelectionGlyphs.Contains(glyph)))
             {
                 service.SelectionGlyphs.Remove(glyph);
             }
             if (this.designerActionAdorner.Glyphs.Contains(glyph))
             {
                 this.designerActionAdorner.Glyphs.Remove(glyph);
             }
             this.componentToGlyph.Remove(relatedObject);
             IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;
             if ((host != null) && host.InTransaction)
             {
                 host.TransactionClosed      += new DesignerTransactionCloseEventHandler(this.InvalidateGlyphOnLastTransaction);
                 this.relatedGlyphTransaction = glyph;
             }
         }
     }
 }
        internal DesignerActionGlyph GetDesignerActionGlyph(IComponent comp, DesignerActionListCollection dalColl)
        {
            InheritanceAttribute attribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(comp)[typeof(InheritanceAttribute)];

            if (attribute != InheritanceAttribute.InheritedReadOnly)
            {
                if (dalColl == null)
                {
                    dalColl = this.designerActionService.GetComponentActions(comp);
                }
                if ((dalColl != null) && (dalColl.Count > 0))
                {
                    DesignerActionGlyph glyph = null;
                    if (this.componentToGlyph[comp] == null)
                    {
                        DesignerActionBehavior behavior = new DesignerActionBehavior(this.serviceProvider, comp, dalColl, this);
                        if (!(comp is Control) || (comp is ToolStripDropDown))
                        {
                            ComponentTray service = this.serviceProvider.GetService(typeof(ComponentTray)) as ComponentTray;
                            if (service != null)
                            {
                                ComponentTray.TrayControl trayControlFromComponent = service.GetTrayControlFromComponent(comp);
                                if (trayControlFromComponent != null)
                                {
                                    Rectangle bounds = trayControlFromComponent.Bounds;
                                    glyph = new DesignerActionGlyph(behavior, bounds, service);
                                }
                            }
                        }
                        if (glyph == null)
                        {
                            glyph = new DesignerActionGlyph(behavior, this.designerActionAdorner);
                        }
                        if (glyph != null)
                        {
                            this.componentToGlyph.Add(comp, glyph);
                        }
                        return(glyph);
                    }
                    glyph = this.componentToGlyph[comp] as DesignerActionGlyph;
                    if (glyph != null)
                    {
                        DesignerActionBehavior behavior2 = glyph.Behavior as DesignerActionBehavior;
                        if (behavior2 != null)
                        {
                            behavior2.ActionLists = dalColl;
                        }
                        glyph.Invalidate();
                    }
                    return(glyph);
                }
                this.RemoveActionGlyph(comp);
            }
            return(null);
        }
        private void RecreateInternal(IComponent comp)
        {
            DesignerActionGlyph designerActionGlyph = this.GetDesignerActionGlyph(comp);

            if (designerActionGlyph != null)
            {
                this.VerifyGlyphIsInAdorner(designerActionGlyph);
                this.RecreatePanel(designerActionGlyph);
                this.UpdateDAPLocation(comp, designerActionGlyph);
            }
        }
 private void VerifyGlyphIsInAdorner(DesignerActionGlyph glyph)
 {
     if (glyph.IsInComponentTray)
     {
         ComponentTray service = this.serviceProvider.GetService(typeof(ComponentTray)) as ComponentTray;
         if ((service.SelectionGlyphs != null) && !service.SelectionGlyphs.Contains(glyph))
         {
             service.SelectionGlyphs.Insert(0, glyph);
         }
     }
     else if (((this.designerActionAdorner != null) && (this.designerActionAdorner.Glyphs != null)) && !this.designerActionAdorner.Glyphs.Contains(glyph))
     {
         this.designerActionAdorner.Glyphs.Insert(0, glyph);
     }
     glyph.InvalidateOwnerLocation();
 }
 private void InvalidateGlyphOnLastTransaction(object sender, DesignerTransactionCloseEventArgs e)
 {
     if (e.LastTransaction)
     {
         IDesignerHost host = (this.serviceProvider != null) ? (this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost) : null;
         if (host != null)
         {
             host.TransactionClosed -= new DesignerTransactionCloseEventHandler(this.InvalidateGlyphOnLastTransaction);
         }
         if (this.relatedGlyphTransaction != null)
         {
             this.relatedGlyphTransaction.InvalidateOwnerLocation();
         }
         this.relatedGlyphTransaction = null;
     }
 }
        private void OnDesignerActionUIStateChange(object sender, DesignerActionUIStateChangeEventArgs e)
        {
            IComponent relatedObject = e.RelatedObject as IComponent;

            if (relatedObject != null)
            {
                DesignerActionGlyph designerActionGlyph = this.GetDesignerActionGlyph(relatedObject);
                if (designerActionGlyph != null)
                {
                    if (e.ChangeType != DesignerActionUIStateChangeType.Show)
                    {
                        if (e.ChangeType != DesignerActionUIStateChangeType.Hide)
                        {
                            if (e.ChangeType == DesignerActionUIStateChangeType.Refresh)
                            {
                                designerActionGlyph.Invalidate();
                                this.RecreatePanel((IComponent)e.RelatedObject);
                            }
                        }
                        else
                        {
                            DesignerActionBehavior behavior2 = designerActionGlyph.Behavior as DesignerActionBehavior;
                            if (behavior2 != null)
                            {
                                behavior2.HideUI();
                            }
                        }
                    }
                    else
                    {
                        DesignerActionBehavior behavior = designerActionGlyph.Behavior as DesignerActionBehavior;
                        if (behavior != null)
                        {
                            behavior.ShowUI(designerActionGlyph);
                        }
                    }
                }
            }
            else if (e.ChangeType == DesignerActionUIStateChangeType.Hide)
            {
                this.HideDesignerActionPanel();
            }
        }
 private void OnComponentChanged(object source, ComponentChangedEventArgs ce)
 {
     if ((((ce.Component != null) && (ce.Member != null)) && this.IsDesignerActionPanelVisible) && ((this.lastPanelComponent == null) || this.lastPanelComponent.Equals(ce.Component)))
     {
         DesignerActionGlyph glyph = this.componentToGlyph[ce.Component] as DesignerActionGlyph;
         if (glyph != null)
         {
             glyph.Invalidate();
             if (ce.Member.Name.Equals("Dock"))
             {
                 this.RecreatePanel(ce.Component as IComponent);
             }
             if ((ce.Member.Name.Equals("Location") || ce.Member.Name.Equals("Width")) || ce.Member.Name.Equals("Height"))
             {
                 this.UpdateDAPLocation(ce.Component as IComponent, glyph);
             }
         }
     }
 }
        internal void ShowDesignerActionPanel(IComponent relatedComponent, DesignerActionPanel panel, DesignerActionGlyph glyph)
        {
            if (this.designerActionHost == null)
            {
                this.designerActionHost          = new DesignerActionToolStripDropDown(this, this.mainParentWindow);
                this.designerActionHost.AutoSize = false;
                this.designerActionHost.Padding  = Padding.Empty;
                this.designerActionHost.Renderer = new NoBorderRenderer();
                this.designerActionHost.Text     = "DesignerActionTopLevelForm";
                this.designerActionHost.Closing += new ToolStripDropDownClosingEventHandler(this.toolStripDropDown_Closing);
            }
            this.designerActionHost.AccessibleName = System.Design.SR.GetString("DesignerActionPanel_DefaultPanelTitle", new object[] { relatedComponent.GetType().Name });
            panel.AccessibleName = System.Design.SR.GetString("DesignerActionPanel_DefaultPanelTitle", new object[] { relatedComponent.GetType().Name });
            this.designerActionHost.SetDesignerActionPanel(panel, glyph);
            Point screenLocation = this.UpdateDAPLocation(relatedComponent, glyph);

            if ((this.behaviorService != null) && this.behaviorService.AdornerWindowControl.DisplayRectangle.IntersectsWith(glyph.Bounds))
            {
                if ((this.mainParentWindow != null) && (this.mainParentWindow.Handle != IntPtr.Zero))
                {
                    System.Design.UnsafeNativeMethods.SetWindowLong(new HandleRef(this.designerActionHost, this.designerActionHost.Handle), -8, new HandleRef(this.mainParentWindow, this.mainParentWindow.Handle));
                }
                this.cancelClose = true;
                this.designerActionHost.Show(screenLocation);
                this.designerActionHost.Focus();
                this.designerActionHost.BeginInvoke(new EventHandler(this.OnShowComplete));
                glyph.InvalidateOwnerLocation();
                this.lastPanelComponent = relatedComponent;
                this.dapkb = new DesignerActionKeyboardBehavior(this.designerActionHost.CurrentPanel, this.serviceProvider, this.behaviorService);
                this.behaviorService.PushBehavior(this.dapkb);
            }
        }