X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/33caa9948d5f06abf9e2e62f58a8ef4dedc6b207..d4b73b1b8e585418459362c9bf9173aa21da8c41:/src/gtk/menu.cpp?ds=inline diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index dea54b9e72..a287ee3439 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -7,11 +7,14 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "menu.h" -#pragma implementation "menuitem.h" +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) + #pragma implementation "menu.h" + #pragma implementation "menuitem.h" #endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + #include "wx/log.h" #include "wx/intl.h" #include "wx/app.h" @@ -169,7 +172,7 @@ static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu ) { if (g_isIdle) wxapp_install_idle_handler(); - wxMenuEvent event( wxEVT_MENU_OPEN, -1 ); + wxMenuEvent event( wxEVT_MENU_OPEN, -1, menu ); event.SetEventObject( menu ); wxEvtHandler* handler = menu->GetEventHandler(); @@ -200,8 +203,6 @@ wxMenuBar::wxMenuBar( long style ) return; } - m_menus.DeleteContents( TRUE ); - /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ #if GTK_CHECK_VERSION(1, 2, 1) m_accel = gtk_accel_group_new(); @@ -241,8 +242,6 @@ wxMenuBar::wxMenuBar() return; } - m_menus.DeleteContents( TRUE ); - /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ #if GTK_CHECK_VERSION(1, 2, 1) m_accel = gtk_accel_group_new(); @@ -275,7 +274,7 @@ static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win ) /* support for native hot keys */ gtk_accel_group_detach( menu->m_accel, ACCEL_OBJ_CAST(top_frame->m_widget) ); - wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); + wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); while (node) { wxMenuItem *menuitem = node->GetData(); @@ -300,7 +299,7 @@ static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) gtk_accel_group_attach( menu->m_accel, obj ); #endif // GTK+ 1.2.1+ - wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); + wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); while (node) { wxMenuItem *menuitem = node->GetData(); @@ -324,7 +323,7 @@ void wxMenuBar::SetInvokingWindow( wxWindow *win ) gtk_accel_group_attach( m_accel, obj ); #endif // GTK+ 1.2.1+ - wxMenuList::Node *node = m_menus.GetFirst(); + wxMenuList::compatibility_iterator node = m_menus.GetFirst(); while (node) { wxMenu *menu = node->GetData(); @@ -345,7 +344,7 @@ void wxMenuBar::UnsetInvokingWindow( wxWindow *win ) gtk_accel_group_detach( m_accel, ACCEL_OBJ_CAST(top_frame->m_widget) ); #endif // GTK+ 1.2.1+ - wxMenuList::Node *node = m_menus.GetFirst(); + wxMenuList::compatibility_iterator node = m_menus.GetFirst(); while (node) { wxMenu *menu = node->GetData(); @@ -474,7 +473,7 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) static wxMenu *CopyMenu (wxMenu *menu) { wxMenu *menucopy = new wxMenu (); - wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); + wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); while (node) { wxMenuItem *item = node->GetData(); @@ -552,7 +551,7 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString return res; } - wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); + wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); while (node) { wxMenuItem *item = node->GetData(); @@ -567,7 +566,7 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const { - wxMenuList::Node *node = m_menus.GetFirst(); + wxMenuList::compatibility_iterator node = m_menus.GetFirst(); while (node) { wxMenu *menu = node->GetData(); @@ -585,7 +584,7 @@ static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id) { wxMenuItem* result = menu->FindChildItem(id); - wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); + wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst(); while ( node && result == NULL ) { wxMenuItem *item = node->GetData(); @@ -602,7 +601,7 @@ static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id) wxMenuItem* wxMenuBar::FindItem( int id, wxMenu **menuForItem ) const { wxMenuItem* result = 0; - wxMenuList::Node *node = m_menus.GetFirst(); + wxMenuList::compatibility_iterator node = m_menus.GetFirst(); while (node && result == 0) { wxMenu *menu = node->GetData(); @@ -620,7 +619,7 @@ wxMenuItem* wxMenuBar::FindItem( int id, wxMenu **menuForItem ) const void wxMenuBar::EnableTop( size_t pos, bool flag ) { - wxMenuList::Node *node = m_menus.Item( pos ); + wxMenuList::compatibility_iterator node = m_menus.Item( pos ); wxCHECK_RET( node, wxT("menu not found") ); @@ -632,7 +631,7 @@ void wxMenuBar::EnableTop( size_t pos, bool flag ) wxString wxMenuBar::GetLabelTop( size_t pos ) const { - wxMenuList::Node *node = m_menus.Item( pos ); + wxMenuList::compatibility_iterator node = m_menus.Item( pos ); wxCHECK_MSG( node, wxT("invalid"), wxT("menu not found") ); @@ -659,7 +658,7 @@ wxString wxMenuBar::GetLabelTop( size_t pos ) const void wxMenuBar::SetLabelTop( size_t pos, const wxString& label ) { - wxMenuList::Node *node = m_menus.Item( pos ); + wxMenuList::compatibility_iterator node = m_menus.Item( pos ); wxCHECK_RET( node, wxT("menu not found") ); @@ -733,6 +732,10 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) pm = pm->GetParent(); } + // FIXME: why do we have to call wxFrame::GetEventHandler() directly here? + // normally wxMenu::SendEvent() should be enough, if it doesn't work + // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which + // should be fixed instead of working around it here... if (frame) { // If it is attached then let the frame send the event. @@ -742,6 +745,7 @@ static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) commandEvent.SetEventObject(frame); if (item->IsCheckable()) commandEvent.SetInt(item->IsChecked()); + commandEvent.SetEventObject(menu); frame->GetEventHandler()->ProcessEvent(commandEvent); } @@ -1122,7 +1126,7 @@ void wxMenu::Init() wxMenu::~wxMenu() { - m_items.Clear(); + WX_CLEAR_LIST(wxMenuItemList, m_items); if ( GTK_IS_WIDGET( m_menu )) gtk_widget_destroy( m_menu ); @@ -1398,7 +1402,7 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const { - wxMenuItemList::Node *node = m_items.GetFirst(); + wxMenuItemList::compatibility_iterator node = m_items.GetFirst(); while (node) { wxMenuItem *item = node->GetData();