From: Robin Dunn Date: Thu, 3 Apr 2003 21:01:52 +0000 (+0000) Subject: Correction to my new menu code: handle submenus on menubar menus X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/02822c8cdfad75d044faed32f3103b6935ed01c5?ds=sidebyside Correction to my new menu code: handle submenus on menubar menus git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19970 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index dc12c62e98..88eb8cf728 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -701,11 +701,23 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) if (!menu->IsEnabled(id)) return; - if ( menu->IsAttached() ) // is this menu on a menubar? + // Is this menu on a menubar? (possibly nested) + wxFrame* frame = NULL; + wxMenu* pm = menu; + while ( pm && !frame ) + { + if ( pm->IsAttached() ) + frame = pm->GetMenuBar()->GetFrame(); + else + pm = pm->GetParent(); + } + + // If it is then let the frame send the event + if (frame) { - wxFrame* frame = menu->GetMenuBar()->GetFrame(); frame->ProcessCommand(id); } + // otherwise let the menu have it else { wxMenuItem* item = menu->FindChildItem( id ); diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index dc12c62e98..88eb8cf728 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -701,11 +701,23 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) if (!menu->IsEnabled(id)) return; - if ( menu->IsAttached() ) // is this menu on a menubar? + // Is this menu on a menubar? (possibly nested) + wxFrame* frame = NULL; + wxMenu* pm = menu; + while ( pm && !frame ) + { + if ( pm->IsAttached() ) + frame = pm->GetMenuBar()->GetFrame(); + else + pm = pm->GetParent(); + } + + // If it is then let the frame send the event + if (frame) { - wxFrame* frame = menu->GetMenuBar()->GetFrame(); frame->ProcessCommand(id); } + // otherwise let the menu have it else { wxMenuItem* item = menu->FindChildItem( id );