Ignore menu events while modal dialogs are shown in wxGTK.

Normally menus are disabled in this case but not when running under Ubuntu
Unity, so add an explicit test for this to avoid breaking the program expected
flow of control by allowing the user to show the same modal dialog twice, for
example.

This is not ideal, it would be better to visually disable the menu while the
modal dialogs are shown but is better than nothing.

Closes #14823.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73007 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-11-25 00:15:03 +00:00
parent 288de46cb2
commit 6bc9f42c3d

View File

@@ -30,6 +30,9 @@
#include "wx/gtk/private/gtk2-compat.h" #include "wx/gtk/private/gtk2-compat.h"
#include "wx/gtk/private/mnemonics.h" #include "wx/gtk/private/mnemonics.h"
// Number of currently open modal dialogs, defined in src/gtk/toplevel.cpp.
extern int wxOpenModalDialogsCount;
// we use normal item but with a special id for the menu title // we use normal item but with a special id for the menu title
static const int wxGTK_TITLE_ID = -3; static const int wxGTK_TITLE_ID = -3;
@@ -45,6 +48,10 @@ static void wxGetGtkAccel(const wxMenuItem*, guint*, GdkModifierType*);
static void DoCommonMenuCallbackCode(wxMenu *menu, wxMenuEvent& event) static void DoCommonMenuCallbackCode(wxMenu *menu, wxMenuEvent& event)
{ {
// See the comment about Ubuntu Unity in menuitem_activate().
if ( wxOpenModalDialogsCount )
return;
event.SetEventObject( menu ); event.SetEventObject( menu );
wxEvtHandler* handler = menu->GetEventHandler(); wxEvtHandler* handler = menu->GetEventHandler();
@@ -480,6 +487,16 @@ static void menuitem_activate(GtkWidget*, wxMenuItem* item)
if (!item->IsEnabled()) if (!item->IsEnabled())
return; return;
// Unity hack: under Ubuntu Unity the global menu bar is not affected by a
// modal dialog being shown, so the user can select a menu item before
// hiding the dialog and, in particular, a new instance of the same dialog
// can be shown again, breaking a lot of programs not expecting this.
//
// So explicitly ignore any menu events generated while any modal dialogs
// are opened.
if ( wxOpenModalDialogsCount )
return;
int id = item->GetId(); int id = item->GetId();
if (id == wxGTK_TITLE_ID) if (id == wxGTK_TITLE_ID)
{ {