From 8ef9a526cea6ecc3853f327a76da14561b36f82a Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Fri, 14 Mar 2008 16:51:14 +0000 Subject: [PATCH] minimize searching for tlw parent, remove useless code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52503 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/menu.cpp | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index f7b037efd4..133442129f 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -155,46 +155,50 @@ wxMenuBar::~wxMenuBar() { } -static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win ) +static void +wxMenubarUnsetInvokingWindow(wxMenu* menu, wxWindow* win, GtkWindow* tlw = NULL) { menu->SetInvokingWindow( (wxWindow*) NULL ); - wxWindow *top_frame = win; - while (top_frame->GetParent() && !(top_frame->IsTopLevel())) - top_frame = top_frame->GetParent(); - // support for native hot keys - if (menu->m_accel && g_slist_find(menu->m_accel->acceleratables, top_frame->m_widget)) - gtk_window_remove_accel_group(GTK_WINDOW(top_frame->m_widget), menu->m_accel); + if (menu->m_accel) + { + if (tlw == NULL) + tlw = GTK_WINDOW(wxGetTopLevelParent(win)->m_widget); + if (g_slist_find(menu->m_accel->acceleratables, tlw)) + gtk_window_remove_accel_group(tlw, menu->m_accel); + } wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); while (node) { wxMenuItem *menuitem = node->GetData(); if (menuitem->IsSubMenu()) - wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu(), win ); + wxMenubarUnsetInvokingWindow(menuitem->GetSubMenu(), win, tlw); node = node->GetNext(); } } -static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) +static void +wxMenubarSetInvokingWindow(wxMenu* menu, wxWindow* win, GtkWindow* tlw = NULL) { menu->SetInvokingWindow( win ); - wxWindow *top_frame = win; - while (top_frame->GetParent() && !(top_frame->IsTopLevel())) - top_frame = top_frame->GetParent(); - // support for native hot keys - if (menu->m_accel && !g_slist_find(menu->m_accel->acceleratables, top_frame->m_widget)) - gtk_window_add_accel_group(GTK_WINDOW(top_frame->m_widget), menu->m_accel); + if (menu->m_accel) + { + if (tlw == NULL) + tlw = GTK_WINDOW(wxGetTopLevelParent(win)->m_widget); + if (!g_slist_find(menu->m_accel->acceleratables, tlw)) + gtk_window_add_accel_group(tlw, menu->m_accel); + } wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); while (node) { wxMenuItem *menuitem = node->GetData(); if (menuitem->IsSubMenu()) - wxMenubarSetInvokingWindow( menuitem->GetSubMenu(), win ); + wxMenubarSetInvokingWindow(menuitem->GetSubMenu(), win, tlw); node = node->GetNext(); } } @@ -202,9 +206,6 @@ static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) void wxMenuBar::SetInvokingWindow( wxWindow *win ) { m_invokingWindow = win; - wxWindow *top_frame = win; - while (top_frame->GetParent() && !(top_frame->IsTopLevel())) - top_frame = top_frame->GetParent(); wxMenuList::compatibility_iterator node = m_menus.GetFirst(); while (node) @@ -262,9 +263,6 @@ void wxMenuBar::Attach(wxFrame *frame) void wxMenuBar::UnsetInvokingWindow( wxWindow *win ) { m_invokingWindow = (wxWindow*) NULL; - wxWindow *top_frame = win; - while (top_frame->GetParent() && !(top_frame->IsTopLevel())) - top_frame = top_frame->GetParent(); wxMenuList::compatibility_iterator node = m_menus.GetFirst(); while (node) -- 2.45.2