/// <summary> /// Displays the sub-items on popup toolbar. /// </summary> /// <param name="x">Horizontal coordinate in pixels of the upper left corner of a popup.</param> /// <param name="y">Vertical coordinate in pixels of the upper left corner of a popup.</param> public virtual void PopupBar(int x, int y) { //DotNetBarManager owner=this.GetOwner(); IOwnerMenuSupport ownerMenu=this.GetIOwnerMenuSupport(); //if(ownerMenu==null) // throw(new InvalidOperationException("Current owner is not assigned or it does not have popup bar support.")); System.Windows.Forms.Control objCtrl=this.ContainerControl as System.Windows.Forms.Control; if(ownerMenu!=null) { PopupOpenEventArgs args=new PopupOpenEventArgs(); if(PopupOpen!=null) PopupOpen(this,args); if(!args.Cancel) ownerMenu.InvokePopupOpen(this,args); if(args.Cancel) { this.Expanded=false; return; } } foreach(BaseItem objItem in this.SubItems) objItem.Orientation=eOrientation.Horizontal; if(m_PopupBar==null) { m_PopupBar=new Bar(); if(m_PopupFont!=null) m_PopupBar.Font=m_PopupFont; else if(objCtrl!=null && objCtrl.Font!=null) m_PopupBar.Font=(System.Drawing.Font)objCtrl.Font.Clone(); if(objCtrl is Bar && ((Bar)objCtrl).ColorScheme!=null) m_PopupBar.ColorScheme=((Bar)objCtrl).ColorScheme; else if(objCtrl is MenuPanel && ((MenuPanel)objCtrl).ColorScheme!=null) m_PopupBar.ColorScheme=((MenuPanel)objCtrl).ColorScheme; else if (objCtrl is ItemControl && ((ItemControl)objCtrl).ColorScheme != null) m_PopupBar.ColorScheme = ((ItemControl)objCtrl).ColorScheme; else if (objCtrl is ButtonX && ((ButtonX)objCtrl).ColorScheme != null) m_PopupBar.ColorScheme = ((ButtonX)objCtrl).ColorScheme; else m_PopupBar.ColorScheme = new ColorScheme(this.EffectiveStyle); m_PopupBar.SetBarState(eBarState.Popup); m_PopupBar.PopupAnimation=m_PopupAnimation; m_PopupBar.Owner=this.GetOwner(); m_PopupBar.ParentItem=this; if(objCtrl!=null) m_PopupBar.RightToLeft = objCtrl.RightToLeft; m_PopupBar.CreateControl(); m_PopupBar.SetDesignMode(this.DesignMode); m_PopupBar.ThemeAware=this.ThemeAware; if(objCtrl is IBarImageSize) m_PopupBar.ImageSize=((IBarImageSize)objCtrl).ImageSize; m_PopupBar.PopupWidth=m_PopupWidth; m_PopupBar.RecalcSize(); } // Make sure that menu is on-screen ScreenInformation objScreen=null; if(IsHandleValid(objCtrl)) { objScreen=BarFunctions.ScreenFromControl(objCtrl); } else { objScreen=BarFunctions.ScreenFromPoint(new Point(x,y)); } if(this.IsRightHanded) x-=m_PopupBar.Width; if(objScreen!=null && x+m_PopupBar.Width>objScreen.WorkingArea.Right) { // Push it to the right side x=objScreen.WorkingArea.Right-m_PopupBar.Width; } else if(objScreen!=null && x<objScreen.WorkingArea.Left) x=objScreen.WorkingArea.Left; // Try to fit whole popup menu "nicely" if(objScreen!=null && y+m_PopupBar.Height>objScreen.WorkingArea.Bottom) { // If this container is displayed then try to put it above the menu item if(this.Displayed && objCtrl!=null) { Point p=new Point(m_Rect.Left,m_Rect.Bottom), ps; ps=objCtrl.PointToScreen(p); ps.Y+=2; if(ps.Y-m_PopupBar.Height>=objScreen.WorkingArea.Top) y=ps.Y-m_PopupBar.Height; } } x += _PopupOffset.X; y += _PopupOffset.Y; // If it still does not fit at this point, container will scale itself properly // And allow item scrolling m_PopupBar.Location=new Point(x,y); if(ownerMenu!=null) ownerMenu.InvokePopupShowing(this,new EventArgs()); m_PopupBar.ShowBar(); this.Expanded=true; if(ownerMenu!=null) { if(!(objCtrl is Bar) && !(objCtrl is MenuPanel)) { ownerMenu.RegisterPopup(this); m_FilterInstalled=true; } else if(objCtrl is Bar) { Bar bar=objCtrl as Bar; if(bar.BarState!=eBarState.Popup) { ownerMenu.RegisterPopup(this); m_FilterInstalled=true; } bar=null; } } }