+ GtkWidget *menuItem;
+
+ if ( mitem->IsSeparator() )
+ {
+#ifdef __WXGTK20__
+ menuItem = gtk_separator_menu_item_new();
+#else
+ // TODO
+ menuItem = gtk_menu_item_new();
+#endif
+ if (pos == -1)
+ gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem);
+ else
+ gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos);
+ }
+ else if ( mitem->IsSubMenu() )
+ {
+ // text has "_" instead of "&" after mitem->SetText()
+ wxString text( mitem->GetText() );
+
+#ifdef __WXGTK20__
+ menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+#else
+ menuItem = gtk_menu_item_new_with_label( wxGTK_CONV( text ) );
+ GtkLabel *label = GTK_LABEL( GTK_BIN(menuItem)->child );
+ // set new text
+ gtk_label_set_text( label, wxGTK_CONV( text ) );
+ // reparse key accel
+ guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( text ) );
+ if (accel_key != GDK_VoidSymbol)
+ {
+ gtk_widget_add_accelerator (menuItem,
+ "activate_item",
+ gtk_menu_ensure_uline_accel_group(GTK_MENU(m_menu)),
+ accel_key,
+ GDK_MOD1_MASK,
+ GTK_ACCEL_LOCKED);
+ }
+#endif
+
+ gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
+ if (pos == -1)
+ gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem);
+ else
+ gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos);
+
+ gtk_widget_show( mitem->GetSubMenu()->m_menu );
+
+ // if adding a submenu to a menu already existing in the menu bar, we
+ // must set invoking window to allow processing events from this
+ // submenu
+ if ( m_invokingWindow )
+ wxMenubarSetInvokingWindow(mitem->GetSubMenu(), m_invokingWindow);
+
+ m_prevRadio = NULL;
+ }
+ else if (mitem->GetBitmap().Ok())
+ {
+ wxString text = mitem->GetText();
+ const wxBitmap *bitmap = &mitem->GetBitmap();
+
+#ifdef __WXGTK20__
+ menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+
+ GtkWidget *image;
+ if (bitmap->HasPixbuf())
+ {
+ image = gtk_image_new_from_pixbuf(bitmap->GetPixbuf());
+ }
+ else
+ {
+ GdkPixmap *gdk_pixmap = bitmap->GetPixmap();
+ GdkBitmap *gdk_bitmap = bitmap->GetMask() ?
+ bitmap->GetMask()->GetBitmap() :
+ (GdkBitmap*) NULL;
+ image = gtk_image_new_from_pixmap( gdk_pixmap, gdk_bitmap );
+ }
+
+ gtk_widget_show(image);
+
+ gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem), image );
+
+ gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
+ GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
+ (gpointer)this );
+
+ if (pos == -1)
+ gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem);
+ else
+ gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos);
+#else
+ GdkPixmap *gdk_pixmap = bitmap->GetPixmap();
+ GdkBitmap *gdk_bitmap = bitmap->GetMask() ? bitmap->GetMask()->GetBitmap() : (GdkBitmap*) NULL;
+
+ menuItem = gtk_pixmap_menu_item_new ();
+ GtkWidget *label = gtk_accel_label_new ( wxGTK_CONV( text ) );
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_container_add (GTK_CONTAINER (menuItem), label);
+
+ gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), menuItem);
+ guint accel_key;
+ GdkModifierType accel_mods;
+
+ // accelerator for the item, as specified by its label
+ // (ex. Ctrl+O for open)
+ gtk_accelerator_parse(GetHotKey(*mitem).c_str(), &accel_key,
+ &accel_mods);
+ if (accel_key != GDK_VoidSymbol)
+ {
+ gtk_widget_add_accelerator (menuItem,
+ "activate_item",
+ m_accel,
+ accel_key, accel_mods,
+ GTK_ACCEL_VISIBLE);
+ }
+
+ // accelerator for the underlined char (ex ALT+F for the File menu)
+ accel_key = gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( text ) );
+ if (accel_key != GDK_VoidSymbol)
+ {
+ gtk_widget_add_accelerator (menuItem,
+ "activate_item",
+ gtk_menu_ensure_uline_accel_group(GTK_MENU (m_menu)),
+ accel_key,
+ GDK_MOD1_MASK,
+ GTK_ACCEL_LOCKED);
+ }
+
+ gtk_widget_show (label);
+
+ mitem->SetLabelWidget(label);
+
+ GtkWidget* pixmap = gtk_pixmap_new( gdk_pixmap, gdk_bitmap );
+ gtk_widget_show(pixmap);
+ gtk_pixmap_menu_item_set_pixmap(GTK_PIXMAP_MENU_ITEM( menuItem ), pixmap);
+
+ gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
+ GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
+ (gpointer)this );
+
+ if (pos == -1)
+ gtk_menu_append( GTK_MENU(m_menu), menuItem );
+ else
+ gtk_menu_insert( GTK_MENU(m_menu), menuItem, pos );
+ gtk_widget_show( menuItem );
+#endif
+
+ m_prevRadio = NULL;
+ }
+ else // a normal item
+ {
+ // text has "_" instead of "&" after mitem->SetText() so don't use it
+ wxString text( mitem->GetText() );
+
+ switch ( mitem->GetKind() )
+ {
+ case wxITEM_CHECK:
+ {
+#ifdef __WXGTK20__
+ menuItem = gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+#else
+ menuItem = gtk_check_menu_item_new_with_label( wxGTK_CONV( text ) );
+ GtkLabel *label = GTK_LABEL( GTK_BIN(menuItem)->child );
+ // set new text
+ gtk_label_set_text( label, wxGTK_CONV( text ) );
+ // reparse key accel
+ guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( text ) );
+ if (accel_key != GDK_VoidSymbol)
+ {
+ gtk_widget_add_accelerator (menuItem,
+ "activate_item",
+ gtk_menu_ensure_uline_accel_group(GTK_MENU(m_menu)),
+ accel_key,
+ GDK_MOD1_MASK,
+ GTK_ACCEL_LOCKED);
+ }
+#endif
+ m_prevRadio = NULL;
+ break;
+ }
+
+ case wxITEM_RADIO:
+ {
+ GSList *group = NULL;
+ if ( m_prevRadio == NULL )
+ {
+ // start of a new radio group
+#ifdef __WXGTK20__
+ m_prevRadio = menuItem = gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV( text ) );
+#else
+ m_prevRadio = menuItem = gtk_radio_menu_item_new_with_label( group, wxGTK_CONV( text ) );
+ GtkLabel *label = GTK_LABEL( GTK_BIN(menuItem)->child );
+ // set new text
+ gtk_label_set_text( label, wxGTK_CONV( text ) );
+ // reparse key accel
+ guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( text ) );
+ if (accel_key != GDK_VoidSymbol)
+ {
+ gtk_widget_add_accelerator (menuItem,
+ "activate_item",
+ gtk_menu_ensure_uline_accel_group(GTK_MENU(m_menu)),
+ accel_key,
+ GDK_MOD1_MASK,
+ GTK_ACCEL_LOCKED);
+ }
+#endif
+ }
+ else // continue the radio group
+ {
+#ifdef __WXGTK20__
+ group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio));
+ m_prevRadio = menuItem = gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV( text ) );
+#else
+ group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (m_prevRadio));
+ m_prevRadio = menuItem = gtk_radio_menu_item_new_with_label( group, wxGTK_CONV( text ) );
+ GtkLabel *label = GTK_LABEL( GTK_BIN(menuItem)->child );
+ // set new text
+ gtk_label_set_text( label, wxGTK_CONV( text ) );
+ // reparse key accel
+ guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( text ) );
+ if (accel_key != GDK_VoidSymbol)
+ {
+ gtk_widget_add_accelerator (menuItem,
+ "activate_item",
+ gtk_menu_ensure_uline_accel_group(GTK_MENU(m_menu)),
+ accel_key,
+ GDK_MOD1_MASK,
+ GTK_ACCEL_LOCKED);
+ }
+#endif
+ }
+ break;
+ }
+
+ default:
+ wxFAIL_MSG( _T("unexpected menu item kind") );
+ // fall through
+
+ case wxITEM_NORMAL:
+ {
+#ifdef __WXGTK20__
+ menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+#else
+ menuItem = gtk_menu_item_new_with_label( wxGTK_CONV( text ) );
+ GtkLabel *label = GTK_LABEL( GTK_BIN(menuItem)->child );
+ // set new text
+ gtk_label_set_text( label, wxGTK_CONV( text ) );
+ // reparse key accel
+ guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( text ) );
+ if (accel_key != GDK_VoidSymbol)
+ {
+ gtk_widget_add_accelerator (menuItem,
+ "activate_item",
+ gtk_menu_ensure_uline_accel_group(GTK_MENU(m_menu)),
+ accel_key,
+ GDK_MOD1_MASK,
+ GTK_ACCEL_LOCKED);
+ }
+#endif
+ m_prevRadio = NULL;
+ break;
+ }
+ }
+
+ gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
+ GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
+ (gpointer)this );
+
+ if (pos == -1)
+ gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem);
+ else
+ gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos);
+ }
+
+ guint accel_key;
+ GdkModifierType accel_mods;
+ wxCharBuffer buf = wxGTK_CONV( GetHotKey(*mitem) );
+
+ // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetHotKey(*mitem).c_str() );
+
+ gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
+ if (accel_key != 0)
+ {
+ gtk_widget_add_accelerator (GTK_WIDGET(menuItem),
+ "activate",
+ m_accel,
+ accel_key,
+ accel_mods,
+ GTK_ACCEL_VISIBLE);
+ }
+
+ gtk_widget_show( menuItem );
+
+ if ( !mitem->IsSeparator() )
+ {
+ wxASSERT_MSG( menuItem, wxT("invalid menuitem") );
+
+ 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 );
+ }
+
+ mitem->SetMenuItem(menuItem);
+
+ if (ms_locked)
+ {
+ // This doesn't even exist!
+ // gtk_widget_lock_accelerators(mitem->GetMenuItem());
+ }
+
+ return TRUE;