]> git.saurik.com Git - wxWidgets.git/commitdiff
use current mouse position as default position in wxWindow::PopupMenu (works better...
authorVáclav Slavík <vslavik@fastmail.fm>
Thu, 3 Jun 2004 14:05:30 +0000 (14:05 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Thu, 3 Jun 2004 14:05:30 +0000 (14:05 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27599 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/window.tex
include/wx/window.h
src/gtk/window.cpp
src/gtk1/window.cpp
src/mac/carbon/window.cpp
src/mac/classic/window.cpp
src/motif/window.cpp
src/msw/window.cpp
src/os2/window.cpp
src/unix/taskbarx11.cpp

index 7174076d68d29719497a28695f07535ba5e8cfa5..ecd5b6798c2ee96be3ce099ba8a06b380972b370 100644 (file)
@@ -1987,6 +1987,8 @@ default value is {\tt false}.}
 
 \membersection{wxWindow::PopupMenu}\label{wxwindowpopupmenu}
 
 
 \membersection{wxWindow::PopupMenu}\label{wxwindowpopupmenu}
 
+\func{bool}{PopupMenu}{\param{wxMenu* }{menu}}
+
 \func{bool}{PopupMenu}{\param{wxMenu* }{menu}, \param{const wxPoint\& }{pos}}
 
 \func{bool}{PopupMenu}{\param{wxMenu* }{menu}, \param{int }{x}, \param{int }{y}}
 \func{bool}{PopupMenu}{\param{wxMenu* }{menu}, \param{const wxPoint\& }{pos}}
 
 \func{bool}{PopupMenu}{\param{wxMenu* }{menu}, \param{int }{x}, \param{int }{y}}
@@ -1994,7 +1996,8 @@ default value is {\tt false}.}
 Pops up the given menu at the specified coordinates, relative to this
 window, and returns control when the user has dismissed the menu. If a
 menu item is selected, the corresponding menu event is generated and will be
 Pops up the given menu at the specified coordinates, relative to this
 window, and returns control when the user has dismissed the menu. If a
 menu item is selected, the corresponding menu event is generated and will be
-processed as usually.
+processed as usually. If the coordinates are not specified, current mouse
+cursor position is used.
 
 \wxheading{Parameters}
 
 
 \wxheading{Parameters}
 
@@ -2012,9 +2015,13 @@ processed as usually.
 
 \wxheading{Remarks}
 
 
 \wxheading{Remarks}
 
-Just before the menu is popped up, \helpref{wxMenu::UpdateUI}{wxmenuupdateui} is called
-to ensure that the menu items are in the correct state. The menu does not get deleted
-by the window.
+Just before the menu is popped up, \helpref{wxMenu::UpdateUI}{wxmenuupdateui}
+is called to ensure that the menu items are in the correct state. The menu does
+not get deleted by the window.
+
+It is recommended to not explicitly specify coordinates when calling PopupMenu
+in response to mouse click, because some of the ports (namely, wxGTK) can do
+a better job of positioning the menu in that case.
 
 \pythonnote{In place of a single overloaded method name, wxPython
 implements the following methods:\par
 
 \pythonnote{In place of a single overloaded method name, wxPython
 implements the following methods:\par
index bf670b3b3250b320c97d41ee8e19ef24580618fd..67e839fd66db80ad4353312a513736a31b602962 100644 (file)
@@ -804,9 +804,11 @@ public:
     virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
 
 #if wxUSE_MENUS
     virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
 
 #if wxUSE_MENUS
-    bool PopupMenu( wxMenu *menu, const wxPoint& pos )
+    bool PopupMenu(wxMenu *menu)
+        { return DoPopupMenu(menu, -1, -1); }
+    bool PopupMenu(wxMenu *menu, const wxPoint& pos)
         { return DoPopupMenu(menu, pos.x, pos.y); }
         { return DoPopupMenu(menu, pos.x, pos.y); }
-    bool PopupMenu( wxMenu *menu, int x, int y )
+    bool PopupMenu(wxMenu *menu, int x, int y)
         { return DoPopupMenu(menu, x, y); }
 #endif // wxUSE_MENUS
 
         { return DoPopupMenu(menu, x, y); }
 #endif // wxUSE_MENUS
 
@@ -1203,7 +1205,7 @@ protected:
 #endif // wxUSE_TOOLTIPS
 
 #if wxUSE_MENUS
 #endif // wxUSE_TOOLTIPS
 
 #if wxUSE_MENUS
-    virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0;
+    virtual bool DoPopupMenu(wxMenu *menu, int x, int y) = 0;
 #endif // wxUSE_MENUS
 
     // Makes an adjustment to the window position to make it relative to the
 #endif // wxUSE_MENUS
 
     // Makes an adjustment to the window position to make it relative to the
index d468e1b8e80de38db5848f694654bf343f29e5f3..e5fd4654409b96791b75d3ab2134783744c0d293 100644 (file)
@@ -4285,30 +4285,44 @@ extern "C" void wxPopupMenuPositionCallback( GtkMenu *menu,
 
 bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
 {
 
 bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
 {
-    wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") );
+    wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
 
 
-    wxCHECK_MSG( menu != NULL, FALSE, wxT("invalid popup-menu") );
+    wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
 
     SetInvokingWindow( menu, this );
 
     menu->UpdateUI();
 
 
     SetInvokingWindow( menu, this );
 
     menu->UpdateUI();
 
-    wxPoint pos(ClientToScreen(wxPoint(x, y)));
-
-    bool is_waiting = TRUE;
+    bool is_waiting = true;
 
     gtk_signal_connect( GTK_OBJECT(menu->m_menu),
                         "hide",
                         GTK_SIGNAL_FUNC(gtk_pop_hide_callback),
                         (gpointer)&is_waiting );
 
 
     gtk_signal_connect( GTK_OBJECT(menu->m_menu),
                         "hide",
                         GTK_SIGNAL_FUNC(gtk_pop_hide_callback),
                         (gpointer)&is_waiting );
 
+    wxPoint pos;
+    gpointer userdata;
+    GtkMenuPositionFunc posfunc;
+    if ( x == -1 && y == -1 )
+    {
+        // use GTK's default positioning algorithm
+        userdata = NULL;
+        posfunc = NULL;
+    }
+    else
+    {
+        pos = ClientToScreen(wxPoint(x, y));
+        userdata = &pos;
+        posfunc = wxPopupMenuPositionCallback;
+    }
+
     gtk_menu_popup(
                   GTK_MENU(menu->m_menu),
                   (GtkWidget *) NULL,           // parent menu shell
                   (GtkWidget *) NULL,           // parent menu item
     gtk_menu_popup(
                   GTK_MENU(menu->m_menu),
                   (GtkWidget *) NULL,           // parent menu shell
                   (GtkWidget *) NULL,           // parent menu item
-                  wxPopupMenuPositionCallback,  // function to position it
-                  &pos,                         // client data
-                  0 /* FIXME! */,               // button used to activate it
+                  posfunc,                      // function to position it
+                  userdata,                     // client data
+                  0,                            // button used to activate it
 #ifdef __WXGTK20__
                   gtk_get_current_event_time()
 #else
 #ifdef __WXGTK20__
                   gtk_get_current_event_time()
 #else
@@ -4321,7 +4335,7 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
         gtk_main_iteration();
     }
 
         gtk_main_iteration();
     }
 
-    return TRUE;
+    return true;
 }
 
 #endif // wxUSE_MENUS_NATIVE
 }
 
 #endif // wxUSE_MENUS_NATIVE
index d468e1b8e80de38db5848f694654bf343f29e5f3..e5fd4654409b96791b75d3ab2134783744c0d293 100644 (file)
@@ -4285,30 +4285,44 @@ extern "C" void wxPopupMenuPositionCallback( GtkMenu *menu,
 
 bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
 {
 
 bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
 {
-    wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") );
+    wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
 
 
-    wxCHECK_MSG( menu != NULL, FALSE, wxT("invalid popup-menu") );
+    wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
 
     SetInvokingWindow( menu, this );
 
     menu->UpdateUI();
 
 
     SetInvokingWindow( menu, this );
 
     menu->UpdateUI();
 
-    wxPoint pos(ClientToScreen(wxPoint(x, y)));
-
-    bool is_waiting = TRUE;
+    bool is_waiting = true;
 
     gtk_signal_connect( GTK_OBJECT(menu->m_menu),
                         "hide",
                         GTK_SIGNAL_FUNC(gtk_pop_hide_callback),
                         (gpointer)&is_waiting );
 
 
     gtk_signal_connect( GTK_OBJECT(menu->m_menu),
                         "hide",
                         GTK_SIGNAL_FUNC(gtk_pop_hide_callback),
                         (gpointer)&is_waiting );
 
+    wxPoint pos;
+    gpointer userdata;
+    GtkMenuPositionFunc posfunc;
+    if ( x == -1 && y == -1 )
+    {
+        // use GTK's default positioning algorithm
+        userdata = NULL;
+        posfunc = NULL;
+    }
+    else
+    {
+        pos = ClientToScreen(wxPoint(x, y));
+        userdata = &pos;
+        posfunc = wxPopupMenuPositionCallback;
+    }
+
     gtk_menu_popup(
                   GTK_MENU(menu->m_menu),
                   (GtkWidget *) NULL,           // parent menu shell
                   (GtkWidget *) NULL,           // parent menu item
     gtk_menu_popup(
                   GTK_MENU(menu->m_menu),
                   (GtkWidget *) NULL,           // parent menu shell
                   (GtkWidget *) NULL,           // parent menu item
-                  wxPopupMenuPositionCallback,  // function to position it
-                  &pos,                         // client data
-                  0 /* FIXME! */,               // button used to activate it
+                  posfunc,                      // function to position it
+                  userdata,                     // client data
+                  0,                            // button used to activate it
 #ifdef __WXGTK20__
                   gtk_get_current_event_time()
 #else
 #ifdef __WXGTK20__
                   gtk_get_current_event_time()
 #else
@@ -4321,7 +4335,7 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
         gtk_main_iteration();
     }
 
         gtk_main_iteration();
     }
 
-    return TRUE;
+    return true;
 }
 
 #endif // wxUSE_MENUS_NATIVE
 }
 
 #endif // wxUSE_MENUS_NATIVE
index 90e55a094b7c97152f10bc606ceaf2e45d9fc1a2..c2a4d8fe40b7700bb73cf19ec49e12d4eb2ada0c 100644 (file)
@@ -1439,7 +1439,16 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
 {
     menu->SetInvokingWindow(this);
     menu->UpdateUI();
 {
     menu->SetInvokingWindow(this);
     menu->UpdateUI();
-    ClientToScreen( &x , &y ) ;
+    
+    if ( x == -1 && y == -1 )
+    {
+        wxPoint mouse = wxGetMousePosition();
+        x = mouse.x; y = mouse.y;
+    }
+    else
+    {
+        ClientToScreen( &x , &y ) ;
+    }
 
     menu->MacBeforeDisplay( true ) ;
     long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
 
     menu->MacBeforeDisplay( true ) ;
     long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
index a5c56e42028dabb7f72c35d08e9370bf3808bb47..4af9bf6ce22fc9f4c1419c9ea75619430dcac078 100644 (file)
@@ -364,7 +364,16 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
 {
     menu->SetInvokingWindow(this);
     menu->UpdateUI();
 {
     menu->SetInvokingWindow(this);
     menu->UpdateUI();
-    ClientToScreen( &x , &y ) ;
+    
+    if ( x == -1 && y == -1 )
+    {
+        wxPoint mouse = wxGetMousePosition();
+        x = mouse.x; y = mouse.y;
+    }
+    else
+    {
+        ClientToScreen( &x , &y ) ;
+    }
 
     menu->MacBeforeDisplay( true ) ;
     long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
 
     menu->MacBeforeDisplay( true ) ;
     long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
index b1fc9b524e0f86b6b2e910721a31bc27bcd2e656..207afc3ed056f31ce74a1d30f2b327fb8730f23e 100644 (file)
@@ -1075,6 +1075,12 @@ void wxWindow::DoSetToolTip(wxToolTip * WXUNUSED(tooltip))
 
 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
 {
 
 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
 {
+    if ( x == -1 && y == -1 )
+    {
+        wxPoint mouse = ScreenToClient(wxGetMousePosition());
+        x = mouse.x; y = mouse.y;
+    }
+
     Widget widget = (Widget) GetMainWidget();
 
     /* The menuId field seems to be usused, so we'll use it to
     Widget widget = (Widget) GetMainWidget();
 
     /* The menuId field seems to be usused, so we'll use it to
index 6a4ffb7334591f6b0d09d742325fb9dff794b269..5c826bf7bca6513ce6b2cd504774404f8c77251e 100644 (file)
@@ -1737,6 +1737,12 @@ bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y)
     menu->SetInvokingWindow(this);
     menu->UpdateUI();
 
     menu->SetInvokingWindow(this);
     menu->UpdateUI();
 
+    if ( x == -1 && y == -1 )
+    {
+        wxPoint mouse = ScreenToClient(wxGetMousePosition());
+        x = mouse.x; y = mouse.y;
+    }
+
     HWND hWnd = GetHwnd();
     HMENU hMenu = GetHmenuOf(menu);
     POINT point;
     HWND hWnd = GetHwnd();
     HMENU hMenu = GetHmenuOf(menu);
     POINT point;
index fb3aee34a1116bd11bcc6a55c5af68b54e98ec87..0c448ce6f5a53462b371a0857d4a20e1ad11ef47 100644 (file)
@@ -1955,10 +1955,18 @@ bool wxWindowOS2::DoPopupMenu(
 
     pMenu->SetInvokingWindow(this);
     pMenu->UpdateUI();
 
     pMenu->SetInvokingWindow(this);
     pMenu->UpdateUI();
-
-    DoClientToScreen( &nX
-                     ,&nY
-                    );
+    
+    if ( x == -1 && y == -1 )
+    {
+        wxPoint mouse = wxGetMousePosition();
+        nX = mouse.x; nY = mouse.y;
+    }
+    else
+    {
+        DoClientToScreen( &nX
+                         ,&nY
+                        );
+    }
     wxCurrentPopupMenu = pMenu;
 
     ::WinPopupMenu( hWndParent
     wxCurrentPopupMenu = pMenu;
 
     ::WinPopupMenu( hWndParent
index 5ec54ac876dd660dc3f4ff5b0a41dfa3f970a7a2..759be00a01e04cc204b18d8d031ea081b054cfcf 100644 (file)
@@ -314,6 +314,6 @@ bool wxTaskBarIcon::PopupMenu(wxMenu *menu)
     if (!m_iconWnd)
         return false;
     wxSize size(m_iconWnd->GetClientSize());
     if (!m_iconWnd)
         return false;
     wxSize size(m_iconWnd->GetClientSize());
-    m_iconWnd->PopupMenu(menu, size.x/2, size.y/2);
+    m_iconWnd->PopupMenu(menu);
     return true;
 }
     return true;
 }