+ GtkItemFactoryEntry entry;
+ entry.path = buf;
+ entry.callback = (GtkItemFactoryCallback) 0;
+ entry.callback_action = 0;
+ entry.item_type = (char *)"<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, wxGTK_CONV( path ) );
+
+ 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);
+ }
+#ifndef __WXGTK20__
+ else if (mitem->GetBitmap().Ok())
+ {
+ // Our extra code for Bitmaps in GTK 1.2
+ wxString text( mitem->GetText() );
+ const wxBitmap *bitmap = &mitem->GetBitmap();
+
+ 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",
+ gtk_menu_get_accel_group(
+ GTK_MENU(m_menu)),
+ 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, (GdkModifierType) 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 );
+ }
+#endif
+ else // a normal item
+ {
+ // text has "_" instead of "&" after mitem->SetText() so don't use it
+ wxString text( mitem->GetText() );
+
+ // buffers containing the menu item path and type in multibyte form
+ char bufPath[256],
+ bufType[256];
+
+ strcpy( bufPath, "/" );
+ strncat( bufPath, wxGTK_CONV(text), WXSIZEOF(bufPath) - 2 );
+ bufPath[WXSIZEOF(bufPath) - 1] = '\0';
+
+ GtkItemFactoryEntry entry;
+ entry.path = bufPath;
+ entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback;
+ entry.callback_action = 0;
+
+ wxString pathRadio;
+ const char *item_type;
+ switch ( mitem->GetKind() )
+ {
+ case wxITEM_CHECK:
+ item_type = "<CheckItem>";
+ break;
+
+ case wxITEM_RADIO:
+ if ( m_pathLastRadio.empty() )
+ {
+ // start of a new radio group
+ item_type = "<RadioItem>";
+ wxString tmp( wxGTK_CONV_BACK( bufPath ) );
+ tmp.Remove(0,1);
+ m_pathLastRadio = tmp;
+ }
+ else // continue the radio group
+ {
+ pathRadio = m_pathLastRadio;
+ pathRadio.Replace(wxT("_"), wxT(""));
+ pathRadio.Prepend(wxT("<main>/"));
+
+ strncpy(bufType, wxGTK_CONV(pathRadio), WXSIZEOF(bufType));
+ bufType[WXSIZEOF(bufType) - 1] = '\0';
+ item_type = bufType;
+ }
+
+ // continue the existing radio group, if any
+ endOfRadioGroup = FALSE;
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unexpected menu item kind") );
+ // fall through
+
+ case wxITEM_NORMAL:
+ item_type = "<Item>";
+#if defined(__WXGTK20__) && wxUSE_IMAGE
+ if (mitem->GetBitmap().Ok())
+ {
+ item_type = "<ImageItem>";
+ // GTK2's image factory know about image items, but they need to
+ // get a GdkPixbuf structure, which we need to create on the fly.
+ // This Pixbuf structure needs to be static so we create it and
+ // just make it a memory leak...
+ wxImage image( mitem->GetBitmap().ConvertToImage() );
+ size_t size = 4 + // magic
+ 20 + // header
+ image.GetHeight() * image.GetWidth() * 4; // RGBA
+
+ unsigned char *dest = new unsigned char[size];
+ entry.extra_data = dest;
+
+ unsigned char *source = image.GetData();
+ bool has_mask = image.HasMask();
+ unsigned char mask_r = image.GetMaskRed();
+ unsigned char mask_b = image.GetMaskBlue();
+ unsigned char mask_g = image.GetMaskGreen();
+ wxUint32 tmp;
+
+ // Magic
+ *dest = 'G'; dest++; *dest = 'd'; dest++; *dest = 'k'; dest++; *dest = 'P'; dest++;
+ // Data size
+ tmp = size;
+ *dest = tmp >> 24; dest++; *dest = tmp >> 16; dest++; *dest = tmp >> 8; dest++; *dest = tmp; dest++;
+ // Pixdata type
+ *dest = 1; dest++; *dest = 1; dest++; *dest = 0; dest++; *dest = 2; dest++;
+ // Rowstride
+ tmp = image.GetWidth()*4;
+ *dest = tmp >> 24; dest++; *dest = tmp >> 16; dest++; *dest = tmp >> 8; dest++; *dest = tmp; dest++;
+ // Width
+ tmp = image.GetWidth();
+ *dest = tmp >> 24; dest++; *dest = tmp >> 16; dest++; *dest = tmp >> 8; dest++; *dest = tmp; dest++;
+ // Height
+ tmp = image.GetHeight();
+ *dest = tmp >> 24; dest++; *dest = tmp >> 16; dest++; *dest = tmp >> 8; dest++; *dest = tmp; dest++;
+
+ for (int i = 0; i < image.GetWidth()*image.GetHeight(); i++)
+ {
+ unsigned char r = *source; source++;
+ unsigned char g = *source; source++;
+ unsigned char b = *source; source++;
+ *dest = r; dest++;
+ *dest = g; dest++;
+ *dest = b; dest++;
+ if (has_mask && (r == mask_r) && (g == mask_g) && (b == mask_b))
+ *dest = 0;
+ else
+ *dest = 255;
+ dest++;
+ }
+ break;
+ }
+#endif // GTK 2.0+
+ break;
+ }
+
+ entry.item_type = (char *)item_type; // cast needed for GTK+
+ 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)
+ char s_accel[50]; // should be big enough, we check for overruns
+ wxString tmp( GetHotKey(*mitem) );
+ strncpy(s_accel, wxGTK_CONV( tmp ), WXSIZEOF(s_accel));
+ s_accel[WXSIZEOF(s_accel) - 1] = '\0';
+ 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, wxGTK_CONV( path ) );
+
+ if (!menuItem)
+ wxLogError( wxT("Wrong menu path: %s\n"), path.c_str() );
+ }
+
+ 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 ( endOfRadioGroup )
+ {
+ m_pathLastRadio.clear();
+ }
+
+ return TRUE;