X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/83624f79609f0d5e240c1f7d77d044bfff9702fc..9f3362c440ef4c780d9a4bc8089de60a21d108bd:/src/gtk/menu.cpp?ds=sidebyside diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index ff038197a8..27173bba72 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -15,6 +15,7 @@ #include "wx/menu.h" #include "wx/log.h" #include "wx/intl.h" +#include "wx/app.h" #include "gdk/gdk.h" #include "gtk/gtk.h" @@ -54,12 +55,11 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) if (pos != -1) menu->m_title.Remove( pos, 1 ); } while (pos != -1); - GtkWidget *root_menu; - root_menu = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) ); - gtk_widget_show( root_menu ); - gtk_menu_item_set_submenu( GTK_MENU_ITEM(root_menu), menu->m_menu ); + menu->m_owner = gtk_menu_item_new_with_label( WXSTRINGCAST(menu->m_title) ); + gtk_widget_show( menu->m_owner ); + gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); - gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), root_menu ); + gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner ); } static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) @@ -76,6 +76,7 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString wxMenuItem *item = (wxMenuItem*)node->Data(); if (item->IsSubMenu()) return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString); + node = node->Next(); } @@ -154,6 +155,55 @@ bool wxMenuBar::Enabled( int id ) const return FALSE; } +wxString wxMenuBar::GetLabel( int id ) const +{ + wxMenuItem* item = FindMenuItemById( id ); + + if (item) return item->GetText(); + + return ""; +} + +void wxMenuBar::SetLabel( int id, const wxString &label ) +{ + wxMenuItem* item = FindMenuItemById( id ); + + if (item) item->SetText( label ); +} + +void wxMenuBar::EnableTop( int pos, bool flag ) +{ + wxNode *node = m_menus.Nth( pos ); + + wxCHECK_RET( node, "menu not found" ); + + wxMenu* menu = (wxMenu*)node->Data(); + + if (menu->m_owner) gtk_widget_set_sensitive( menu->m_owner, flag ); +} + +wxString wxMenuBar::GetLabelTop( int pos ) const +{ + wxNode *node = m_menus.Nth( pos ); + + wxCHECK_MSG( node, "invalid", "menu not found" ); + + wxMenu* menu = (wxMenu*)node->Data(); + + return menu->GetTitle(); +} + +void wxMenuBar::SetLabelTop( int pos, const wxString& label ) +{ + wxNode *node = m_menus.Nth( pos ); + + wxCHECK_RET( node, "menu not found" ); + + wxMenu* menu = (wxMenu*)node->Data(); + + menu->SetTitle( label ); +} + //----------------------------------------------------------------------------- // "activate" //----------------------------------------------------------------------------- @@ -167,6 +217,23 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) if (!menu->IsEnabled(id)) return; + wxMenuItem* item = menu->FindItem( id ); + wxCHECK_RET( item, "error in menu item callback" ); + + if (item->m_isCheckMenu) + { + if (item->m_isChecked == item->IsChecked()) + { + /* the menu item has been checked by calling wxMenuItem->Check() */ + return; + } + else + { + /* the user pressed on the menu item -> report */ + item->m_isChecked = item->IsChecked(); /* make consistent again */ + } + } + wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, id ); event.SetEventObject( menu ); event.SetInt(id ); @@ -253,6 +320,8 @@ void wxMenuItem::Check( bool check ) wxCHECK_RET( IsCheckable(), "Can't check uncheckable item!" ) + if (check == m_isChecked) return; + m_isChecked = check; gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check ); } @@ -273,8 +342,6 @@ bool wxMenuItem::IsChecked() const bool bIsChecked = ((GtkCheckMenuItem*)m_menuItem)->active != 0; - wxASSERT( bIsChecked == m_isChecked ); // consistency check - return bIsChecked; } @@ -301,6 +368,8 @@ wxMenu::wxMenu( const wxString& title, const wxFunction func ) Append(-2, m_title); AppendSeparator(); } + + m_owner = (GtkWidget*) NULL; } void wxMenu::SetTitle( const wxString& title )