* Makefile: Build the make-map.exe in Mono.Unix.Native; add /nowarn:0618 to
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / MenuAPI.cs
index 05891b4a21a4e9e22510490074f625bee28d7aaf..34c4c48aabd40805048456bca87caeb721db08b5 100644 (file)
@@ -210,9 +210,10 @@ namespace System.Windows.Forms
                // 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;                            
@@ -229,16 +230,6 @@ namespace System.Windows.Forms
                                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) {                                
@@ -247,10 +238,19 @@ namespace System.Windows.Forms
                                ((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 ();
@@ -435,8 +435,10 @@ namespace System.Windows.Forms
                        ((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;
@@ -850,6 +852,7 @@ namespace System.Windows.Forms
                {
                        Show ();
                        Capture = true;                 
+                       RefreshItems ();
                        Refresh ();
                }
                
@@ -865,11 +868,7 @@ namespace System.Windows.Forms
 
                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 ()
@@ -968,14 +967,16 @@ namespace System.Windows.Forms
                        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);
-               }
        }
 
 }