X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b1c162e227574deaa255bd66f6c14d10be870f2..3f263f4542f0288a9aa2228f27f43e12a888e5a4:/src/gtk1/menu.cpp diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 424da9aa7e..aff2211922 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -26,6 +26,32 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow) +wxMenuBar::wxMenuBar( long style ) +{ + m_needParent = FALSE; // hmmm + + PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" ); + + m_menus.DeleteContents( TRUE ); + + m_menubar = gtk_menu_bar_new(); + + if (style & wxMB_DOCKABLE) + { + m_widget = gtk_handle_box_new(); + gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) ); + gtk_widget_show( GTK_WIDGET(m_menubar) ); + } + else + { + m_widget = GTK_WIDGET(m_menubar); + } + + PostCreation(); + + Show( TRUE ); +} + wxMenuBar::wxMenuBar() { m_needParent = FALSE; // hmmm @@ -36,7 +62,7 @@ wxMenuBar::wxMenuBar() m_menubar = gtk_menu_bar_new(); - m_widget = GTK_WIDGET(m_menubar); + m_widget = GTK_WIDGET(m_menubar); PostCreation(); @@ -152,6 +178,7 @@ bool wxMenuBar::Enabled( int id ) const { wxMenuItem* item = FindMenuItemById( id ); if (item) return item->IsEnabled(); + return FALSE; } @@ -161,14 +188,14 @@ wxString wxMenuBar::GetLabel( int id ) const if (item) return item->GetText(); - return ""; + return wxString(""); } void wxMenuBar::SetLabel( int id, const wxString &label ) { wxMenuItem* item = FindMenuItemById( id ); - if (item) return item->SetText( label ); + if (item) item->SetText( label ); } void wxMenuBar::EnableTop( int pos, bool flag ) @@ -204,6 +231,23 @@ void wxMenuBar::SetLabelTop( int pos, const wxString& label ) menu->SetTitle( label ); } +void wxMenuBar::SetHelpString( int id, const wxString& helpString ) +{ + wxMenuItem* item = FindMenuItemById( id ); + + if (item) item->SetHelp( helpString ); +} + +wxString wxMenuBar::GetHelpString( int id ) const +{ + wxMenuItem* item = FindMenuItemById( id ); + + if (item) + return item->GetHelp(); + else + return wxString(""); +} + //----------------------------------------------------------------------------- // "activate" //----------------------------------------------------------------------------- @@ -262,9 +306,8 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) if (!menu->IsEnabled(id)) return; - wxCommandEvent event( wxEVT_MENU_HIGHLIGHT, id ); + wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id ); event.SetEventObject( menu ); - event.SetInt(id ); /* wxMSW doesn't call callback here either @@ -281,6 +324,27 @@ static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) if (win) win->GetEventHandler()->ProcessEvent( event ); } +//----------------------------------------------------------------------------- +// "deselect" +//----------------------------------------------------------------------------- + +static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu ) +{ + int id = menu->FindMenuIdByMenuItem(widget); + + wxASSERT( id != -1 ); // should find it! + + if (!menu->IsEnabled(id)) return; + + wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 ); + event.SetEventObject( menu ); + + if (menu->GetEventHandler()->ProcessEvent(event)) return; + + wxWindow *win = menu->GetInvokingWindow(); + if (win) win->GetEventHandler()->ProcessEvent( event ); +} + //----------------------------------------------------------------------------- // wxMenuItem //----------------------------------------------------------------------------- @@ -416,6 +480,10 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool GTK_SIGNAL_FUNC(gtk_menu_hilight_callback), (gpointer*)this ); + gtk_signal_connect( GTK_OBJECT(menuItem), "deselect", + GTK_SIGNAL_FUNC(gtk_menu_nolight_callback), + (gpointer*)this ); + gtk_menu_append( GTK_MENU(m_menu), menuItem ); gtk_widget_show( menuItem ); m_items.Append( mitem ); @@ -432,6 +500,14 @@ void wxMenu::Append( int id, const wxString &text, wxMenu *subMenu, const wxStri mitem->SetMenuItem(menuItem); mitem->SetSubMenu(subMenu); + gtk_signal_connect( GTK_OBJECT(menuItem), "select", + GTK_SIGNAL_FUNC(gtk_menu_hilight_callback), + (gpointer*)this ); + + gtk_signal_connect( GTK_OBJECT(menuItem), "deselect", + GTK_SIGNAL_FUNC(gtk_menu_nolight_callback), + (gpointer*)this ); + gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), subMenu->m_menu ); gtk_menu_append( GTK_MENU(m_menu), menuItem ); gtk_widget_show( menuItem ); @@ -592,4 +668,44 @@ wxWindow *wxMenu::GetInvokingWindow() return m_invokingWindow; } +// Update a menu and all submenus recursively. +// source is the object that has the update event handlers +// defined for it. If NULL, the menu or associated window +// will be used. +void wxMenu::UpdateUI(wxEvtHandler* source) +{ + if (!source && GetInvokingWindow()) + source = GetInvokingWindow()->GetEventHandler(); + if (!source) + source = GetEventHandler(); + if (!source) + source = this; + + wxNode* node = GetItems().First(); + while (node) + { + wxMenuItem* item = (wxMenuItem*) node->Data(); + if ( !item->IsSeparator() ) + { + wxWindowID id = item->GetId(); + wxUpdateUIEvent event(id); + event.SetEventObject( source ); + + if (source->ProcessEvent(event)) + { + if (event.GetSetText()) + SetLabel(id, event.GetText()); + if (event.GetSetChecked()) + Check(id, event.GetChecked()); + if (event.GetSetEnabled()) + Enable(id, event.GetEnabled()); + } + + if (item->GetSubMenu()) + item->GetSubMenu()->UpdateUI(source); + } + node = node->Next(); + } +} +