// The Point object contains screen coordinates
static public bool TrackPopupMenu (IntPtr hTopMenu, IntPtr hMenu, Point pnt, bool bMenubar, Control Wnd)
{
- TRACKER tracker = new TRACKER ();
- MENU top_menu = GetMenuFromID (hTopMenu);
+ TRACKER tracker = new TRACKER ();
MENU menu = null;
+ MSG msg = new MSG();
+ bool no_quit = true;
if (hMenu == IntPtr.Zero) // No submenus to track
return true;
MenuAPI.SelectItem (hMenu, select_item, false, tracker);
}
- // Make sure the menu is always visible and does not 'leave' the screen
- // What is menu.Width/Height? It seemed to be 0/0
- if ((pnt.X + menu.Wnd.Width) > SystemInformation.WorkingArea.Width) {
- pnt.X -= menu.Wnd.Width;
- }
-
- if ((pnt.X + menu.Wnd.Height) > SystemInformation.WorkingArea.Height) {
- pnt.Y -= menu.Wnd.Height;
- }
-
menu.Wnd.Location = menu.Wnd.PointToClient (pnt);
if (menu.menu.IsDirty) {
((PopUpWindow)menu.Wnd).RefreshItems ();
menu.menu.IsDirty = false;
}
-
((PopUpWindow)menu.Wnd).ShowWindow ();
+
+ while ((menu.Wnd != null) && menu.Wnd.Visible && no_quit) {
+ no_quit = XplatUI.GetMessage(ref msg, IntPtr.Zero, 0, 0);
+ if ((msg.hwnd == menu.Wnd.Handle) || (msg.message == Msg.WM_PAINT)) {
+ XplatUI.TranslateMessage(ref msg);
+ XplatUI.DispatchMessage(ref msg);
+ }
+ }
- Application.Run ();
+ if (!no_quit) {
+ XplatUI.Exit();
+ }
if (menu.Wnd == null) {
menu.Wnd.Dispose ();
((PopUpWindow)menu_parent.Wnd).LostFocus ();
tracker.hCurrentMenu = hMenu;
- if (menu.Wnd == null)
- menu.Wnd = new PopUpWindow (hMenu, tracker);
+ if (menu.Wnd != null)
+ menu.Wnd.Dispose ();
+
+ menu.Wnd = new PopUpWindow (hMenu, tracker);
pnt.X = item.rect.X + item.rect.Width;
pnt.Y = item.rect.Y + 1;
{
Show ();
Capture = true;
+ RefreshItems ();
Refresh ();
}
private void OnPaintPUW (Object o, PaintEventArgs pevent)
{
- if (Width <= 0 || Height <= 0 || Visible == false)
- return;
-
- Draw (pevent.ClipRectangle);
- pevent.Graphics.DrawImage (ImageBuffer, pevent.ClipRectangle, pevent.ClipRectangle, GraphicsUnit.Pixel);
+ ThemeEngine.Current.DrawPopupMenu (pevent.Graphics, hMenu, pevent.ClipRectangle, ClientRectangle);
}
public void HideWindow ()
MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
ThemeEngine.Current.CalcPopupMenuSize (DeviceContext, hMenu);
+ if ((Location.X + menu.Width) > SystemInformation.WorkingArea.Width) {
+ Location = new Point (Location.X - menu.Width, Location.Y);
+ }
+ if ((Location.Y + menu.Height) > SystemInformation.WorkingArea.Height) {
+ Location = new Point (Location.X, Location.Y - menu.Height);
+ }
+
Width = menu.Width;
Height = menu.Height;
}
-
- private void Draw (Rectangle clip)
- {
- ThemeEngine.Current.DrawPopupMenu (DeviceContext, hMenu, clip, ClientRectangle);
- }
}
}