X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0ecd03525b34edba886ca83ff724265cd912dbbd..11a23db53128bf244a089123b7fd27deb577a889:/src/gtk/menu.cpp diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 51e23212bc..f5194b89f0 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -2,7 +2,6 @@ // Name: src/gtk/menu.cpp // Purpose: implementation of wxMenuBar and wxMenu classes for wxGTK // Author: Robert Roebling -// Id: $Id$ // Copyright: (c) 1998 Robert Roebling // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -152,6 +151,18 @@ wxMenuBar::wxMenuBar() namespace { +// This should be called when detaching menus to ensure that they don't keep +// focus grab, because if they do, they continue getting all GTK+ messages +// which they can't process any more in their (soon to be) unrealized state. +void +EnsureNoGrab(GtkWidget* widget) +{ +#if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 + gtk_widget_hide(widget); + gtk_grab_remove(widget); +#endif // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 +} + void DetachFromFrame(wxMenu* menu, wxFrame* frame) { @@ -173,6 +184,8 @@ DetachFromFrame(wxMenu* menu, wxFrame* frame) DetachFromFrame(menuitem->GetSubMenu(), frame); node = node->GetNext(); } + + EnsureNoGrab(menu->m_menu); } void @@ -260,6 +273,8 @@ void wxMenuBar::Detach() node = node->GetNext(); } + EnsureNoGrab(m_widget); + wxMenuBarBase::Detach(); } @@ -302,11 +317,10 @@ void wxMenuBar::GtkAppend(wxMenu* menu, const wxString& title, int pos) else #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 { - const wxString str(wxConvertMnemonicsToGTK(title)); - // This doesn't have much effect right now. - menu->SetTitle( str ); + menu->SetTitle( title ); + const wxString str(wxConvertMnemonicsToGTK(title)); // The "m_owner" is the "menu item" menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) ); @@ -489,10 +503,9 @@ void wxMenuBar::SetMenuLabel( size_t pos, const wxString& label ) wxMenu* menu = node->GetData(); - const wxString str(wxConvertMnemonicsToGTK(label)); - - menu->SetTitle( str ); + menu->SetTitle( label ); + const wxString str(wxConvertMnemonicsToGTK(label)); if (menu->m_owner) gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menu->m_owner))), wxGTK_CONV(str)); } @@ -537,6 +550,14 @@ static void menuitem_activate(GtkWidget*, wxMenuItem* item) wxMenu* menu = item->GetMenu(); menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1); + + // A lot of existing code, including any program that closes its main + // window from a menu handler and expects the program to exit -- as our own + // minimal sample -- relies on getting an idle event after a menu event. + // But when using Ubuntu Unity detached menus, we get called from a DBUS + // handler called from g_timeout_dispatch() and Glib doesn't send us any + // idle events after it. So ask explicitly for an idle event to get one. + wxWakeUpIdle(); } } @@ -820,6 +841,11 @@ wxString wxMenu::GetTitle() const return wxConvertMnemonicsFromGTK(wxMenuBase::GetTitle()); } +void wxMenu::SetTitle(const wxString& title) +{ + wxMenuBase::SetTitle(wxConvertMnemonicsToGTK(title)); +} + void wxMenu::GtkAppend(wxMenuItem* mitem, int pos) { GtkWidget *menuItem;