+#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_accel_group_attach((g), (o))
+ #define gtk_accel_group_detach(g, o) _gtk_accel_group_detach((g), (o))
+ #define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
+
+ #define ACCEL_OBJECT GObject
+ #define ACCEL_OBJECTS(a) (a)->acceleratables
+ #define ACCEL_OBJ_CAST(obj) G_OBJECT(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 GTK_CHECK_VERSION(1, 2, 0) && wxUSE_ACCEL
+ static wxString GetHotKey( const wxMenuItem& item );
+#endif
+
+//-----------------------------------------------------------------------------
+// substitute for missing GtkPixmapMenuItem
+//-----------------------------------------------------------------------------
+
+// FIXME: I can't make this compile with GTK+ 2.0, disabling for now (VZ)
+#ifndef __WXGTK20__
+ #define USE_MENU_BITMAPS
+#endif
+
+#ifdef USE_MENU_BITMAPS
+
+#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 // USE_MENU_BITMAPS
+
+//-----------------------------------------------------------------------------
+// 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('&'))
+ {
+#if GTK_CHECK_VERSION(1, 2, 0)
+ str << wxT('_');
+#endif
+ }
+#if GTK_CHECK_VERSION(2, 0, 0)
+ else if (*pc == wxT('/'))
+ {
+ str << wxT("\\/");
+ }
+ else if (*pc == wxT('\\'))
+ {
+ str << wxT("\\\\");
+ }
+#elif GTK_CHECK_VERSION(1, 2, 0)
+ else if (*pc == wxT('/'))
+ {
+ str << wxT('\\');
+ }
+#endif
+ else
+ {
+#ifdef __WXGTK12__
+ if ( *pc == wxT('_') )
+ {
+ // underscores must be doubled to prevent them from being
+ // interpreted as accelerator character prefix by GTK
+ str << *pc;
+ }
+#endif // GTK+ 1.2
+
+ str << *pc;
+ }
+ ++pc;
+ }
+ 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 );
+ event.SetEventObject( menu );
+
+ wxEvtHandler* handler = menu->GetEventHandler();
+ if (handler && handler->ProcessEvent(event))
+ return;