X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/837904f2627957e99283378ccd41c2e3fc7a4a5e..d3a9f4afd904aa7e58ba065434e7fca3e37f6e01:/src/gtk/menu.cpp diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index dd9d764291..46b158cce4 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -37,7 +37,8 @@ wxMenuBar::wxMenuBar( long style ) { /* the parent window is known after wxFrame::SetMenu() */ m_needParent = FALSE; - + m_style = style; + PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" ); m_menus.DeleteContents( TRUE ); @@ -63,15 +64,14 @@ wxMenuBar::wxMenuBar( long style ) } PostCreation(); - - Show( TRUE ); } wxMenuBar::wxMenuBar() { /* the parent window is known after wxFrame::SetMenu() */ m_needParent = FALSE; - + m_style = 0; + PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" ); m_menus.DeleteContents( TRUE ); @@ -88,8 +88,6 @@ wxMenuBar::wxMenuBar() m_widget = GTK_WIDGET(m_menubar); PostCreation(); - - Show( TRUE ); } wxMenuBar::~wxMenuBar() @@ -97,6 +95,91 @@ wxMenuBar::~wxMenuBar() // how to destroy a GtkItemFactory ? } +static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win ) +{ + menu->SetInvokingWindow( (wxWindow*) NULL ); + +#if (GTK_MINOR_VERSION > 0) + wxWindow *top_frame = win; + while (top_frame->GetParent()) top_frame = top_frame->GetParent(); + + /* support for native hot keys */ + gtk_accel_group_detach( menu->m_accel, GTK_OBJECT(top_frame->m_widget) ); +#endif + + wxNode *node = menu->GetItems().First(); + while (node) + { + wxMenuItem *menuitem = (wxMenuItem*)node->Data(); + if (menuitem->IsSubMenu()) + wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu(), win ); + node = node->Next(); + } +} + +static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) +{ + menu->SetInvokingWindow( win ); + +#if (GTK_MINOR_VERSION > 0) + wxWindow *top_frame = win; + while (top_frame->GetParent()) + top_frame = top_frame->GetParent(); + + /* support for native hot keys */ + gtk_accel_group_attach( menu->m_accel, GTK_OBJECT(top_frame->m_widget) ); +#endif + + wxNode *node = menu->GetItems().First(); + while (node) + { + wxMenuItem *menuitem = (wxMenuItem*)node->Data(); + if (menuitem->IsSubMenu()) + wxMenubarSetInvokingWindow( menuitem->GetSubMenu(), win ); + node = node->Next(); + } +} + +void wxMenuBar::SetInvokingWindow( wxWindow *win ) +{ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + wxWindow *top_frame = win; + while (top_frame->GetParent()) + top_frame = top_frame->GetParent(); + + /* support for native key accelerators indicated by underscroes */ + gtk_accel_group_attach( m_accel, GTK_OBJECT(top_frame->m_widget) ); +#endif + + wxNode *node = m_menus.First(); + while (node) + { + wxMenu *menu = (wxMenu*)node->Data(); + wxMenubarSetInvokingWindow( menu, win ); + node = node->Next(); + } +} + +void wxMenuBar::UnsetInvokingWindow( wxWindow *win ) +{ +#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) + wxWindow *top_frame = win; + while (top_frame->GetParent()) + top_frame = top_frame->GetParent(); + + /* support for native key accelerators indicated by underscroes */ + gtk_accel_group_detach( m_accel, GTK_OBJECT(top_frame->m_widget) ); +#endif + + wxNode *node = m_menus.First(); + while (node) + { + wxMenu *menu = (wxMenu*)node->Data(); + wxMenubarUnsetInvokingWindow( menu, win ); + node = node->Next(); + } +} + void wxMenuBar::Append( wxMenu *menu, const wxString &title ) { m_menus.Append( menu ); @@ -135,7 +218,13 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) entry.accelerator = (gchar*) NULL; entry.callback = (GtkItemFactoryCallback) NULL; entry.callback_action = 0; - entry.item_type = ""; + +/* + if ((m_style & wxMB_TEAROFF) || (menu->GetStyle() & wxMENU_TEAROFF)) + entry.item_type = ""; + else +*/ + entry.item_type = ""; gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ @@ -151,6 +240,16 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); +/* + if ((m_style & wxMB_TEAROFF) || (menu->GetStyle() & wxMENU_TEAROFF)) + { + entry.item_type = ""; + tmp.Remove( 0, 6 ); + tmp.Append( _T("/tearoff") ); + strcpy( buf, tmp.mb_str() ); + gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); + } +*/ #else menu->m_owner = gtk_menu_item_new_with_label( str.mb_str() ); @@ -551,11 +650,23 @@ bool wxMenuItem::IsChecked() const IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler) -wxMenu::wxMenu( const wxString& title, const wxFunction func ) +wxMenu::wxMenu( const wxString& title, const wxFunction func, long style ) +{ + Init(title, func, style); +} + +wxMenu::wxMenu(long style) +{ + Init(wxEmptyString, (wxFunction) NULL, style); +} + +void +wxMenu::Init( const wxString& title, const wxFunction func, long style ) { m_title = title; m_items.DeleteContents( TRUE ); m_invokingWindow = (wxWindow *) NULL; + m_style = style; #if (GTK_MINOR_VERSION > 0) m_accel = gtk_accel_group_new(); @@ -748,7 +859,13 @@ void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxStri entry.path = buf; entry.callback = (GtkItemFactoryCallback) 0; entry.callback_action = 0; - entry.item_type = ""; + +/* + if (m_style & wxMENU_TEAROFF) + entry.item_type = ""; + else +*/ + entry.item_type = ""; gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */