// forward declare it as it's used by wxMenuBar too when using Hildon
extern "C"
{
- static void gtk_menu_clicked_callback(GtkWidget *widget, wxMenu *menu);
+ static void menuitem_activate(GtkWidget*, wxMenuItem* item);
}
#if wxUSE_ACCEL
menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) );
g_signal_connect(menu->m_owner, "activate",
- G_CALLBACK(gtk_menu_clicked_callback), menu);
+ G_CALLBACK(menuitem_activate), item);
item->SetMenuItem(menu->m_owner);
}
else
//-----------------------------------------------------------------------------
extern "C" {
-static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
+static void menuitem_activate(GtkWidget*, wxMenuItem* item)
{
- int id = menu->FindMenuIdByMenuItem(widget);
-
- /* should find it for normal (not popup) menu */
- wxASSERT_MSG( (id != -1) || (menu->GetInvokingWindow() != NULL),
- _T("menu item not found in gtk_menu_clicked_callback") );
-
- if (!menu->IsEnabled(id))
+ if (!item->IsEnabled())
return;
- wxMenuItem* item = menu->FindChildItem( id );
- wxCHECK_RET( item, wxT("error in menu item callback") );
-
- if ( item->GetId() == wxGTK_TITLE_ID )
+ int id = item->GetId();
+ if (id == wxGTK_TITLE_ID)
{
// ignore events from the menu title
return;
}
}
-
- // Is this menu on a menubar? (possibly nested)
- wxFrame* frame = NULL;
- if(menu->IsAttached())
- frame = menu->GetMenuBar()->GetFrame();
-
- // 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.
- // Don't call frame->ProcessCommand(id) because it toggles
- // checkable items and we've already done that above.
- wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
- commandEvent.SetEventObject(frame);
- if (item->IsCheckable())
- commandEvent.SetInt(item->IsChecked());
-
- frame->HandleWindowEvent(commandEvent);
- }
- else
- {
- // otherwise let the menu have it
- menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
- }
+ wxMenu* menu = item->GetMenu();
+ menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
}
}
//-----------------------------------------------------------------------------
extern "C" {
-static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
+static void menuitem_select(GtkWidget*, wxMenuItem* item)
{
- int id = menu->FindMenuIdByMenuItem(widget);
-
- wxASSERT( id != -1 ); // should find it!
-
- if (!menu->IsEnabled(id))
+ if (!item->IsEnabled())
return;
- wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
+ wxMenu* menu = item->GetMenu();
+ wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item->GetId());
event.SetEventObject( menu );
wxEvtHandler* handler = menu->GetEventHandler();
//-----------------------------------------------------------------------------
extern "C" {
-static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu )
+static void menuitem_deselect(GtkWidget*, wxMenuItem* item)
{
- int id = menu->FindMenuIdByMenuItem(widget);
-
- wxASSERT( id != -1 ); // should find it!
-
- if (!menu->IsEnabled(id))
+ if (!item->IsEnabled())
return;
+ wxMenu* menu = item->GetMenu();
wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 );
event.SetEventObject( menu );
// don't delete menu items, the menus take care of that
}
-// return the menu item text without any menu accels
-/* static */
-
-wxString wxMenuItemBase::GetLabelText(const wxString& text)
-{
- // The argument to this function will now always be in wxWidgets standard label
- // format, not GTK+ format, so we do what the other ports do.
-
- return wxStripMenuCodes(text);
-}
-
void wxMenuItem::SetItemLabel( const wxString& str )
{
#if wxUSE_ACCEL
{
mitem->SetGtkLabel();
g_signal_connect (menuItem, "select",
- G_CALLBACK (gtk_menu_hilight_callback), this);
+ G_CALLBACK(menuitem_select), mitem);
g_signal_connect (menuItem, "deselect",
- G_CALLBACK (gtk_menu_nolight_callback), this);
+ G_CALLBACK(menuitem_deselect), mitem);
if ( mitem->IsSubMenu() && mitem->GetKind() != wxITEM_RADIO && mitem->GetKind() != wxITEM_CHECK )
{
else
{
g_signal_connect (menuItem, "activate",
- G_CALLBACK (gtk_menu_clicked_callback),
- this);
+ G_CALLBACK(menuitem_activate),
+ mitem);
}
}
return item;
}
-int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
-{
- wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
- while (node)
- {
- wxMenuItem *item = node->GetData();
- if (item->GetMenuItem() == menuItem)
- return item->GetId();
- node = node->GetNext();
- }
-
- return wxNOT_FOUND;
-}
-
void wxMenu::Attach(wxMenuBarBase *menubar)
{
wxMenuBase::Attach(menubar);