+#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"
+#include "wx/bitmap.h"
+#include "wx/menu.h"
+
+#if wxUSE_ACCEL
+ #include "wx/accel.h"
+#endif // wxUSE_ACCEL
+
+#include "wx/gtk/private.h"
+
+#include <gdk/gdkkeysyms.h>
+
+// FIXME: is this right? somehow I don't think so (VZ)
+#ifdef __WXGTK20__
+ #include <glib-object.h>
+
+ #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
+ #define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
+ #define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
+
+ #define ACCEL_OBJECT GtkWindow
+ #define ACCEL_OBJECTS(a) (a)->acceleratables
+ #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
+#else // GTK+ 1.x
+ #define ACCEL_OBJECT GtkObject
+ #define ACCEL_OBJECTS(a) (a)->attach_objects
+ #define ACCEL_OBJ_CAST(obj) GTK_OBJECT(obj)
+#endif
+
+//-----------------------------------------------------------------------------
+// idle system
+//-----------------------------------------------------------------------------
+
+extern void wxapp_install_idle_handler();
+extern bool g_isIdle;
+
+#if wxUSE_ACCEL
+static wxString GetHotKey( const wxMenuItem& item );
+#endif
+
+//-----------------------------------------------------------------------------
+// substitute for missing GtkPixmapMenuItem
+//-----------------------------------------------------------------------------
+
+#ifndef __WXGTK20__
+
+#define GTK_TYPE_PIXMAP_MENU_ITEM (gtk_pixmap_menu_item_get_type ())
+#define GTK_PIXMAP_MENU_ITEM(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_PIXMAP_MENU_ITEM, GtkPixmapMenuItem))
+#define GTK_PIXMAP_MENU_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_PIXMAP_MENU_ITEM, GtkPixmapMenuItemClass))
+#define GTK_IS_PIXMAP_MENU_ITEM(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_PIXMAP_MENU_ITEM))
+#define GTK_IS_PIXMAP_MENU_ITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PIXMAP_MENU_ITEM))
+//#define GTK_PIXMAP_MENU_ITEM_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_PIXMAP_MENU_ITEM))
+#define GTK_PIXMAP_MENU_ITEM_GET_CLASS(obj) (GTK_PIXMAP_MENU_ITEM_CLASS( GTK_OBJECT_GET_CLASS(obj)))
+
+#ifndef GTK_MENU_ITEM_GET_CLASS
+#define GTK_MENU_ITEM_GET_CLASS(obj) (GTK_MENU_ITEM_CLASS( GTK_OBJECT_GET_CLASS(obj)))
+#endif
+
+typedef struct _GtkPixmapMenuItem GtkPixmapMenuItem;
+typedef struct _GtkPixmapMenuItemClass GtkPixmapMenuItemClass;
+
+struct _GtkPixmapMenuItem
+{
+ GtkMenuItem menu_item;
+
+ GtkWidget *pixmap;
+};
+
+struct _GtkPixmapMenuItemClass
+{
+ GtkMenuItemClass parent_class;
+
+ guint orig_toggle_size;
+ guint have_pixmap_count;
+};
+
+
+GtkType gtk_pixmap_menu_item_get_type (void);
+GtkWidget* gtk_pixmap_menu_item_new (void);
+void gtk_pixmap_menu_item_set_pixmap (GtkPixmapMenuItem *menu_item,
+ GtkWidget *pixmap);
+#endif // GTK 2.0
+
+//-----------------------------------------------------------------------------
+// idle system
+//-----------------------------------------------------------------------------
+
+static wxString wxReplaceUnderscore( const wxString& title )
+{
+ const wxChar *pc;
+
+ // GTK 1.2 wants to have "_" instead of "&" for accelerators
+ wxString str;
+ pc = title;
+ while (*pc != wxT('\0'))
+ {
+ if ((*pc == wxT('&')) && (*(pc+1) == wxT('&')))
+ {
+ // "&" is doubled to indicate "&" instead of accelerator
+ ++pc;
+ str << wxT('&');
+ }
+ else if (*pc == wxT('&'))
+ {
+ str << wxT('_');
+ }
+ else
+ {
+ if ( *pc == wxT('_') )
+ {
+ // underscores must be doubled to prevent them from being
+ // interpreted as accelerator character prefix by GTK
+ str << *pc;
+ }
+
+ str << *pc;
+ }
+ ++pc;
+ }
+
+ // wxPrintf( wxT("before %s after %s\n"), title.c_str(), str.c_str() );
+
+ return str;
+}
+
+//-----------------------------------------------------------------------------
+// activate message from GTK
+//-----------------------------------------------------------------------------
+
+static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu )
+{
+ if (g_isIdle) wxapp_install_idle_handler();
+
+ wxMenuEvent event( wxEVT_MENU_OPEN, -1, menu );
+ event.SetEventObject( menu );
+
+ wxEvtHandler* handler = menu->GetEventHandler();
+ if (handler && handler->ProcessEvent(event))
+ return;
+
+ wxWindow *win = menu->GetInvokingWindow();
+ if (win) win->GetEventHandler()->ProcessEvent( event );
+}
+
+//-----------------------------------------------------------------------------
+// wxMenuBar
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
+
+wxMenuBar::wxMenuBar( long style )
+{
+ // the parent window is known after wxFrame::SetMenu()
+ m_needParent = FALSE;
+ m_style = style;
+ m_invokingWindow = (wxWindow*) NULL;
+
+ if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) ||
+ !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") ))
+ {
+ wxFAIL_MSG( wxT("wxMenuBar creation failed") );
+ return;
+ }
+
+ m_menubar = gtk_menu_bar_new();
+#ifndef __WXGTK20__
+ m_accel = gtk_accel_group_new();
+#endif
+
+ 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();
+
+ ApplyWidgetStyle();
+}
+
+wxMenuBar::wxMenuBar()
+{
+ // the parent window is known after wxFrame::SetMenu()
+ m_needParent = FALSE;
+ m_style = 0;
+ m_invokingWindow = (wxWindow*) NULL;
+
+ if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) ||
+ !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT("menubar") ))
+ {
+ wxFAIL_MSG( wxT("wxMenuBar creation failed") );
+ return;
+ }
+
+ m_menubar = gtk_menu_bar_new();
+#ifndef __WXGTK20__
+ m_accel = gtk_accel_group_new();
+#endif
+
+ m_widget = GTK_WIDGET(m_menubar);
+
+ PostCreation();
+
+ ApplyWidgetStyle();
+}
+
+wxMenuBar::~wxMenuBar()
+{
+}
+
+static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win )
+{
+ menu->SetInvokingWindow( (wxWindow*) NULL );
+
+ wxWindow *top_frame = win;
+ while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
+ top_frame = top_frame->GetParent();
+
+#ifndef __WXGTK20__
+ // support for native hot keys
+ gtk_accel_group_detach( menu->m_accel, ACCEL_OBJ_CAST(top_frame->m_widget) );
+#endif
+
+ wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
+ while (node)
+ {
+ wxMenuItem *menuitem = node->GetData();
+ if (menuitem->IsSubMenu())
+ wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu(), win );
+ node = node->GetNext();
+ }
+}
+
+static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win )
+{
+ menu->SetInvokingWindow( win );
+
+ wxWindow *top_frame = win;
+ while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
+ top_frame = top_frame->GetParent();
+
+ // support for native hot keys
+ ACCEL_OBJECT *obj = ACCEL_OBJ_CAST(top_frame->m_widget);
+ if ( !g_slist_find( ACCEL_OBJECTS(menu->m_accel), obj ) )
+ gtk_accel_group_attach( menu->m_accel, obj );
+
+ wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
+ while (node)
+ {
+ wxMenuItem *menuitem = node->GetData();
+ if (menuitem->IsSubMenu())
+ wxMenubarSetInvokingWindow( menuitem->GetSubMenu(), win );
+ node = node->GetNext();
+ }
+}
+
+void wxMenuBar::SetInvokingWindow( wxWindow *win )
+{
+ m_invokingWindow = win;
+ wxWindow *top_frame = win;
+ while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
+ top_frame = top_frame->GetParent();
+
+#ifndef __WXGTK20__
+ // support for native key accelerators indicated by underscroes
+ ACCEL_OBJECT *obj = ACCEL_OBJ_CAST(top_frame->m_widget);
+ if ( !g_slist_find( ACCEL_OBJECTS(m_accel), obj ) )
+ gtk_accel_group_attach( m_accel, obj );
+#endif
+
+ wxMenuList::compatibility_iterator node = m_menus.GetFirst();
+ while (node)
+ {
+ wxMenu *menu = node->GetData();
+ wxMenubarSetInvokingWindow( menu, win );
+ node = node->GetNext();
+ }
+}
+
+void wxMenuBar::UnsetInvokingWindow( wxWindow *win )
+{
+ m_invokingWindow = (wxWindow*) NULL;
+ wxWindow *top_frame = win;
+ while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
+ top_frame = top_frame->GetParent();
+
+#ifndef __WXGTK20__
+ // support for native key accelerators indicated by underscroes
+ gtk_accel_group_detach( m_accel, ACCEL_OBJ_CAST(top_frame->m_widget) );
+#endif
+
+ wxMenuList::compatibility_iterator node = m_menus.GetFirst();
+ while (node)
+ {
+ wxMenu *menu = node->GetData();
+ wxMenubarUnsetInvokingWindow( menu, win );
+ node = node->GetNext();
+ }
+}
+
+bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
+{
+ if ( !wxMenuBarBase::Append( menu, title ) )
+ return FALSE;
+
+ return GtkAppend(menu, title);
+}
+
+bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title)
+{
+ wxString str( wxReplaceUnderscore( title ) );
+
+ // This doesn't have much effect right now.
+ menu->SetTitle( str );
+
+ // The "m_owner" is the "menu item"
+#ifdef __WXGTK20__
+ menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) );
+#else
+ menu->m_owner = gtk_menu_item_new_with_label( wxGTK_CONV( str ) );
+ GtkLabel *label = GTK_LABEL( GTK_BIN(menu->m_owner)->child );
+ // set new text
+ gtk_label_set_text( label, wxGTK_CONV( str ) );
+ // reparse key accel
+ guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( str ) );
+ if (accel_key != GDK_VoidSymbol)
+ {
+ gtk_widget_add_accelerator (menu->m_owner,
+ "activate_item",
+ m_accel,//gtk_menu_ensure_uline_accel_group(GTK_MENU(m_menubar)),
+ accel_key,
+ GDK_MOD1_MASK,
+ GTK_ACCEL_LOCKED);
+ }
+#endif
+
+ gtk_widget_show( menu->m_owner );
+
+ gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
+
+ gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar), menu->m_owner );
+
+ gtk_signal_connect( GTK_OBJECT(menu->m_owner), "activate",
+ GTK_SIGNAL_FUNC(gtk_menu_open_callback),
+ (gpointer)menu );
+
+ // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
+ // addings menu later on.
+ if (m_invokingWindow)
+ {
+ wxMenubarSetInvokingWindow( menu, m_invokingWindow );
+
+ // OPTIMISE ME: we should probably cache this, or pass it
+ // directly, but for now this is a minimal
+ // change to validate the new dynamic sizing.
+ // see (and refactor :) similar code in Remove
+ // below.
+
+ wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
+
+ if( frame )
+ frame->UpdateMenuBarSize();
+ }
+
+ return TRUE;
+}
+
+bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
+{
+ if ( !wxMenuBarBase::Insert(pos, menu, title) )
+ return FALSE;
+
+ // TODO
+
+ if ( !GtkAppend(menu, title) )
+ return FALSE;
+
+ return TRUE;
+}
+
+wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
+{
+ // remove the old item and insert a new one
+ wxMenu *menuOld = Remove(pos);
+ if ( menuOld && !Insert(pos, menu, title) )
+ {
+ return (wxMenu*) NULL;
+ }
+
+ // either Insert() succeeded or Remove() failed and menuOld is NULL
+ return menuOld;
+}
+
+static wxMenu *CopyMenu (wxMenu *menu)
+{
+ wxMenu *menucopy = new wxMenu ();
+ wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
+ while (node)
+ {
+ wxMenuItem *item = node->GetData();
+ int itemid = item->GetId();
+ wxString text = item->GetText();
+ text.Replace(wxT("_"), wxT("&"));
+ wxMenu *submenu = item->GetSubMenu();
+ if (!submenu)
+ {
+ wxMenuItem* itemcopy = new wxMenuItem(menucopy,
+ itemid, text,
+ menu->GetHelpString(itemid));
+ itemcopy->SetBitmap(item->GetBitmap());
+ itemcopy->SetCheckable(item->IsCheckable());
+ menucopy->Append(itemcopy);
+ }
+ else
+ menucopy->Append (itemid, text, CopyMenu(submenu),
+ menu->GetHelpString(itemid));
+
+ node = node->GetNext();
+ }
+
+ return menucopy;
+}
+
+wxMenu *wxMenuBar::Remove(size_t pos)
+{
+ wxMenu *menu = wxMenuBarBase::Remove(pos);
+ if ( !menu )
+ return (wxMenu*) NULL;
+
+ wxMenu *menucopy = CopyMenu( menu );
+
+ // unparent calls unref() and that would delete the widget so we raise
+ // the ref count to 2 artificially before invoking unparent.
+ gtk_widget_ref( menu->m_menu );
+ gtk_widget_unparent( menu->m_menu );
+
+ gtk_widget_destroy( menu->m_owner );
+ delete menu;
+
+ menu = menucopy;
+
+ if (m_invokingWindow)
+ {
+ // OPTIMISE ME: see comment in GtkAppend
+ wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame );
+
+ if( frame )
+ frame->UpdateMenuBarSize();
+ }
+
+ return menu;
+}
+
+static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
+{
+ if (wxMenuItem::GetLabelFromText(menu->GetTitle()) == wxMenuItem::GetLabelFromText(menuString))
+ {
+ int res = menu->FindItem( itemString );
+ if (res != wxNOT_FOUND)
+ return res;
+ }
+
+ wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
+ while (node)
+ {
+ wxMenuItem *item = node->GetData();
+ if (item->IsSubMenu())
+ return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
+
+ node = node->GetNext();
+ }
+
+ return wxNOT_FOUND;
+}
+
+int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const
+{
+ wxMenuList::compatibility_iterator node = m_menus.GetFirst();
+ while (node)
+ {
+ wxMenu *menu = node->GetData();
+ int res = FindMenuItemRecursive( menu, menuString, itemString);
+ if (res != -1)
+ return res;
+ node = node->GetNext();
+ }
+
+ return wxNOT_FOUND;
+}
+
+// Find a wxMenuItem using its id. Recurses down into sub-menus
+static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id)
+{
+ wxMenuItem* result = menu->FindChildItem(id);
+
+ wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
+ while ( node && result == NULL )
+ {
+ wxMenuItem *item = node->GetData();
+ if (item->IsSubMenu())
+ {
+ result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
+ }
+ node = node->GetNext();
+ }
+
+ return result;
+}
+
+wxMenuItem* wxMenuBar::FindItem( int id, wxMenu **menuForItem ) const
+{
+ wxMenuItem* result = 0;
+ wxMenuList::compatibility_iterator node = m_menus.GetFirst();
+ while (node && result == 0)
+ {
+ wxMenu *menu = node->GetData();
+ result = FindMenuItemByIdRecursive( menu, id );
+ node = node->GetNext();
+ }
+
+ if ( menuForItem )
+ {
+ *menuForItem = result ? result->GetMenu() : (wxMenu *)NULL;
+ }
+
+ return result;
+}
+
+void wxMenuBar::EnableTop( size_t pos, bool flag )
+{
+ wxMenuList::compatibility_iterator node = m_menus.Item( pos );
+
+ wxCHECK_RET( node, wxT("menu not found") );
+
+ wxMenu* menu = node->GetData();
+
+ if (menu->m_owner)
+ gtk_widget_set_sensitive( menu->m_owner, flag );
+}
+
+wxString wxMenuBar::GetLabelTop( size_t pos ) const
+{
+ wxMenuList::compatibility_iterator node = m_menus.Item( pos );
+
+ wxCHECK_MSG( node, wxT("invalid"), wxT("menu not found") );
+
+ wxMenu* menu = node->GetData();
+
+ wxString label;
+ wxString text( menu->GetTitle() );
+ for ( const wxChar *pc = text.c_str(); *pc; pc++ )
+ {
+ if ( *pc == wxT('_') )
+ {
+ // '_' is the escape character for GTK+
+ continue;
+ }
+
+ // don't remove ampersands '&' since if we have them in the menu title
+ // it means that they were doubled to indicate "&" instead of accelerator
+
+ label += *pc;
+ }
+
+ return label;
+}
+
+void wxMenuBar::SetLabelTop( size_t pos, const wxString& label )
+{
+ wxMenuList::compatibility_iterator node = m_menus.Item( pos );
+
+ wxCHECK_RET( node, wxT("menu not found") );
+
+ wxMenu* menu = node->GetData();
+
+ wxString str( wxReplaceUnderscore( label ) );
+
+ menu->SetTitle( str );
+
+ if (menu->m_owner)
+ {
+ GtkLabel *label = GTK_LABEL( GTK_BIN(menu->m_owner)->child );
+
+ /* set new text */
+ gtk_label_set( label, wxGTK_CONV( str ) );
+
+ /* reparse key accel */
+ (void)gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( str ) );
+ gtk_accel_label_refetch( GTK_ACCEL_LABEL(label) );
+ }
+
+}
+
+//-----------------------------------------------------------------------------
+// "activate"
+//-----------------------------------------------------------------------------
+
+static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
+{
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ 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))
+ return;
+
+ wxMenuItem* item = menu->FindChildItem( id );
+ wxCHECK_RET( item, wxT("error in menu item callback") );
+
+ if (item->IsCheckable())
+ {
+ bool isReallyChecked = item->IsChecked(),
+ isInternallyChecked = item->wxMenuItemBase::IsChecked();
+
+ // ensure that the internal state is always consistent with what is
+ // shown on the screen
+ item->wxMenuItemBase::Check(isReallyChecked);
+
+ // we must not report the events for the radio button going up nor the
+ // events resulting from the calls to wxMenuItem::Check()
+ if ( (item->GetKind() == wxITEM_RADIO && !isReallyChecked) ||
+ (isInternallyChecked == isReallyChecked) )
+ {
+ return;
+ }
+ }
+
+
+ // Is this menu on a menubar? (possibly nested)
+ wxFrame* frame = NULL;
+ wxMenu* pm = menu;
+ while ( pm && !frame )
+ {
+ if ( pm->IsAttached() )
+ frame = pm->GetMenuBar()->GetFrame();
+ 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.
+ // 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());
+ commandEvent.SetEventObject(menu);
+
+ frame->GetEventHandler()->ProcessEvent(commandEvent);
+ }
+ else
+ {
+ // otherwise let the menu have it
+ menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
+ }
+}
+
+//-----------------------------------------------------------------------------
+// "select"
+//-----------------------------------------------------------------------------
+
+static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
+{
+ if (g_isIdle) wxapp_install_idle_handler();
+
+ int id = menu->FindMenuIdByMenuItem(widget);
+
+ wxASSERT( id != -1 ); // should find it!
+
+ if (!menu->IsEnabled(id))
+ return;
+
+ wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
+ event.SetEventObject( menu );
+
+ wxEvtHandler* handler = menu->GetEventHandler();
+ if (handler && handler->ProcessEvent(event))
+ return;
+
+ wxWindow *win = menu->GetInvokingWindow();
+ if (win) win->GetEventHandler()->ProcessEvent( event );
+}
+
+//-----------------------------------------------------------------------------
+// "deselect"
+//-----------------------------------------------------------------------------
+
+static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu )
+{
+ if (g_isIdle) wxapp_install_idle_handler();
+
+ 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 );
+
+ wxEvtHandler* handler = menu->GetEventHandler();
+ if (handler && handler->ProcessEvent(event))
+ return;
+
+ wxWindow *win = menu->GetInvokingWindow();
+ if (win)
+ win->GetEventHandler()->ProcessEvent( event );
+}
+
+//-----------------------------------------------------------------------------
+// wxMenuItem
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
+
+wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
+ int id,
+ const wxString& name,
+ const wxString& help,
+ wxItemKind kind,
+ wxMenu *subMenu)
+{
+ return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
+}
+
+wxMenuItem::wxMenuItem(wxMenu *parentMenu,
+ int id,
+ const wxString& text,
+ const wxString& help,
+ wxItemKind kind,
+ wxMenu *subMenu)
+ : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
+{
+ Init(text);
+}
+
+wxMenuItem::wxMenuItem(wxMenu *parentMenu,
+ int id,
+ const wxString& text,
+ const wxString& help,
+ bool isCheckable,
+ wxMenu *subMenu)
+ : wxMenuItemBase(parentMenu, id, text, help,
+ isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu)
+{
+ Init(text);
+}
+
+void wxMenuItem::Init(const wxString& text)
+{
+ m_labelWidget = (GtkWidget *) NULL;
+ m_menuItem = (GtkWidget *) NULL;
+
+ DoSetText(text);
+}