X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1ecffbff714ff707ded9266bf27c3347946cbcd9..3372145d9daa42f680fc5aab7eb00e82d587c5a0:/src/gtk/menu.cpp diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 10656f39f4..8ba0eb2033 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -38,8 +38,14 @@ wxMenuBar::wxMenuBar( long style ) /* the parent window is known after wxFrame::SetMenu() */ m_needParent = FALSE; m_style = style; + m_invokingWindow = (wxWindow*) NULL; - PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" ); + if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) || + !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, _T("menubar") )) + { + wxFAIL_MSG( _T("wxMenuBar creation failed") ); + return; + } m_menus.DeleteContents( TRUE ); @@ -71,9 +77,15 @@ wxMenuBar::wxMenuBar() /* the parent window is known after wxFrame::SetMenu() */ m_needParent = FALSE; m_style = 0; + m_invokingWindow = (wxWindow*) NULL; - PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" ); - + if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) || + !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("menubar") )) + { + wxFAIL_MSG( _T("wxMenuBar creation failed") ); + return; + } + m_menus.DeleteContents( TRUE ); /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ @@ -142,6 +154,7 @@ static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) void wxMenuBar::SetInvokingWindow( wxWindow *win ) { + m_invokingWindow = win; #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) wxWindow *top_frame = win; while (top_frame->GetParent()) @@ -162,6 +175,7 @@ void wxMenuBar::SetInvokingWindow( wxWindow *win ) void wxMenuBar::UnsetInvokingWindow( wxWindow *win ) { + m_invokingWindow = (wxWindow*) NULL; #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) wxWindow *top_frame = win; while (top_frame->GetParent()) @@ -214,7 +228,7 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) wxString buf; buf << _T('/') << str.c_str(); - char *cbuf = new char[buf.Length()]; + char *cbuf = new char[buf.Length()+1]; strcpy(cbuf, buf.mbc_str()); GtkItemFactoryEntry entry; @@ -244,6 +258,11 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner ); #endif + + // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables + // adding menu later on. + if (m_invokingWindow) + wxMenubarSetInvokingWindow( menu, m_invokingWindow ); } static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) @@ -628,11 +647,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler) void wxMenu::Init( const wxString& title, - long style -#ifdef WXWIN_COMPATIBILITY - , const wxFunction func -#endif - ) + long style, + const wxFunction func + ) { m_title = title; m_items.DeleteContents( TRUE ); @@ -647,9 +664,7 @@ wxMenu::Init( const wxString& title, m_menu = gtk_menu_new(); // Do not show! #endif -#ifdef WXWIN_COMPATIBILITY m_callback = func; -#endif m_eventHandler = this; m_clientData = (void*) NULL; @@ -683,7 +698,9 @@ wxMenu::Init( const wxString& title, wxMenu::~wxMenu() { - /* how do we delete an item-factory ? */ + /* how do we delete an item-factory ? */ + gtk_widget_destroy( m_menu ); + } void wxMenu::SetTitle( const wxString& title ) @@ -724,6 +741,7 @@ void wxMenu::AppendSeparator() m_items.Append( mitem ); } +#if (GTK_MINOR_VERSION > 0) static char* GetHotKey( const wxString &hotkey, char *hotbuf ) { if (hotkey.IsEmpty()) return (char*) NULL; @@ -761,6 +779,7 @@ static char* GetHotKey( const wxString &hotkey, char *hotbuf ) } return (char*) NULL; } +#endif void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool checkable ) {