]> git.saurik.com Git - wxWidgets.git/commitdiff
Pretend that the window showing popup menu has focus in wxGTK.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 7 Dec 2011 00:59:48 +0000 (00:59 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 7 Dec 2011 00:59:48 +0000 (00:59 +0000)
This is necessary for compatibility with wxMSW as the focus remains on the
window which had it before the popup menu was shown there and existing code
relies on it, while in wxGTK the popup steals the focus when it's shown.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69938 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/window.cpp

index 9e62caac35d661e00311424f4ffb8b73758e2c19..74ba1ce2b7b6995d04a8da4f7cb372bea22b9d80 100644 (file)
@@ -31,6 +31,7 @@
 #include "wx/tooltip.h"
 #include "wx/caret.h"
 #include "wx/fontutil.h"
+#include "wx/scopeguard.h"
 #include "wx/sysopt.h"
 
 #include <ctype.h>
@@ -4018,6 +4019,14 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
 {
     wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
 
+    // For compatibility with other ports, pretend that the window showing the
+    // menu has focus while the menu is shown. This is needed because the popup
+    // menu actually steals the focus from the window it's associated it in
+    // wxGTK unlike, say, wxMSW.
+    wxWindowGTK* const oldPendingFocus = gs_pendingFocus;
+    gs_pendingFocus = this;
+    wxON_BLOCK_EXIT_SET( gs_pendingFocus, oldPendingFocus );
+
     menu->UpdateUI();
 
     wxPoint pos;