+ gtk_object_unref( GTK_OBJECT(m_factory) );
+}
+
+bool wxMenu::GtkAppend(wxMenuItem *mitem)
+{
+ GtkWidget *menuItem;
+
+ bool appended = FALSE;
+
+ if ( mitem->IsSeparator() )
+ {
+#if (GTK_MINOR_VERSION > 0)
+ GtkItemFactoryEntry entry;
+ entry.path = "/sep";
+ entry.callback = (GtkItemFactoryCallback) NULL;
+ entry.callback_action = 0;
+ entry.item_type = "<Separator>";
+ entry.accelerator = (gchar*) NULL;
+
+ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
+
+ /* this will be wrong for more than one separator. do we care? */
+ menuItem = gtk_item_factory_get_widget( m_factory, "<main>/sep" );
+#else // GTK+ 1.0
+ menuItem = gtk_menu_item_new();
+#endif // GTK 1.2/1.0
+ }
+ else if ( mitem->IsSubMenu() )
+ {
+#if (GTK_MINOR_VERSION > 0)
+ /* text has "_" instead of "&" after mitem->SetText() */
+ wxString text( mitem->GetText() );
+
+ /* local buffer in multibyte form */
+ char buf[200];
+ strcpy( buf, "/" );
+ strcat( buf, text.mb_str() );
+
+ GtkItemFactoryEntry entry;
+ entry.path = buf;
+ entry.callback = (GtkItemFactoryCallback) 0;
+ entry.callback_action = 0;
+ entry.item_type = "<Branch>";
+ entry.accelerator = (gchar*) NULL;
+
+ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
+
+ wxString path( mitem->GetFactoryPath() );
+ menuItem = gtk_item_factory_get_item( m_factory, path.mb_str() );
+#else // GTK+ 1.0
+ menuItem = gtk_menu_item_new_with_label(mitem->GetText().mbc_str());
+#endif // GTK 1.2/1.0
+
+ gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), 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);
+ }
+ else if (mitem->GetBitmap().Ok()) // An item with bitmap
+ {
+ wxString text( mitem->GetText() );
+ const wxBitmap *bitmap = &mitem->GetBitmap();
+
+ menuItem = gtk_pixmap_menu_item_new ();
+ GtkWidget *label = gtk_accel_label_new (text.mb_str());
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_container_add (GTK_CONTAINER (menuItem), label);
+ guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), text.mb_str() );
+ gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), menuItem);
+ if (accel_key != GDK_VoidSymbol)
+ {
+ gtk_widget_add_accelerator (menuItem,
+ "activate_item",
+ gtk_menu_ensure_uline_accel_group (GTK_MENU (m_menu)),
+ accel_key, 0,
+ GTK_ACCEL_LOCKED);
+ }
+ gtk_widget_show (label);
+
+ mitem->SetLabelWidget(label);
+
+ GtkWidget* pixmap = gtk_pixmap_new( bitmap->GetPixmap(), bitmap->GetMask() ? bitmap->GetMask()->GetBitmap() : (GdkBitmap* )NULL);
+ 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 );
+ gtk_menu_append( GTK_MENU(m_menu), menuItem );
+ gtk_widget_show( menuItem );
+
+ appended = TRUE; // We've done this, don't do it again
+ }
+ else // a normal item
+ {
+#if (GTK_MINOR_VERSION > 0)
+ /* text has "_" instead of "&" after mitem->SetText() */
+ wxString text( mitem->GetText() );
+
+ /* local buffer in multibyte form */
+ char buf[200];
+ strcpy( buf, "/" );
+ strcat( buf, text.mb_str() );
+
+ GtkItemFactoryEntry entry;
+ entry.path = buf;
+ entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback;
+ entry.callback_action = 0;
+ if ( mitem->IsCheckable() )
+ entry.item_type = "<CheckItem>";
+ else
+ entry.item_type = "<Item>";
+ entry.accelerator = (gchar*) NULL;
+
+#if wxUSE_ACCEL
+ // due to an apparent bug in GTK+, we have to use a static buffer here -
+ // otherwise GTK+ 1.2.2 manages to override the memory we pass to it
+ // somehow! (VZ)
+ static char s_accel[50]; // must be big enougg
+ wxString tmp( GetHotKey(*mitem) );
+ strncpy(s_accel, tmp.mb_str(), WXSIZEOF(s_accel));
+ entry.accelerator = s_accel;
+#else // !wxUSE_ACCEL
+ entry.accelerator = (char*) NULL;
+#endif // wxUSE_ACCEL/!wxUSE_ACCEL
+
+ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
+
+ wxString path( mitem->GetFactoryPath() );
+ menuItem = gtk_item_factory_get_widget( m_factory, path.mb_str() );
+#else // GTK+ 1.0
+ menuItem = checkable ? gtk_check_menu_item_new_with_label( mitem->GetText().mb_str() )
+ : gtk_menu_item_new_with_label( mitem->GetText().mb_str() );
+
+ gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
+ GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
+ (gpointer)this );
+#endif // GTK+ 1.2/1.0
+ }
+
+ if ( !mitem->IsSeparator() )
+ {
+ 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 );
+ }
+
+#if GTK_MINOR_VERSION == 0
+ if (!appended)
+ {
+ gtk_menu_append( GTK_MENU(m_menu), menuItem );
+ gtk_widget_show( menuItem );
+ }
+#endif // GTK+ 1.0
+
+ mitem->SetMenuItem(menuItem);
+
+ return TRUE;
+}