- SetWidgetStyle();
-
- GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
-
- gtk_widget_set_style( m_widget, m_widgetStyle );
- gtk_widget_set_style( GTK_WIDGET( menu_shell ), m_widgetStyle );
-
- GList *child = menu_shell->children;
- while (child)
- {
- gtk_widget_set_style( GTK_WIDGET( child->data ), m_widgetStyle );
-
- GtkBin *bin = GTK_BIN( child->data );
- GtkWidget *label = (GtkWidget *) NULL;
- if (bin->child) label = bin->child;
- if (!label) label = GTK_BUTTON(m_widget)->child;
-
- gtk_widget_set_style( label, m_widgetStyle );
-
- child = child->next;
- }
+ wxCHECK_MSG(pos<=m_clientData.GetCount(), -1, wxT("invalid index"));
+
+ GtkWidget *menu_item = gtk_menu_item_new_with_label( wxGTK_CONV( item ) );
+
+ if ( m_strings )
+ {
+ // sorted control, need to insert at the correct index
+ pos = m_strings->Add(item);
+ }
+
+ // don't call wxChoice::GetCount() from here because it doesn't work
+ // if we're called from ctor (and GtkMenuShell is still NULL)
+ if (pos == m_clientData.GetCount())
+ gtk_menu_shell_append( GTK_MENU_SHELL(menu), menu_item );
+ else
+ gtk_menu_shell_insert( GTK_MENU_SHELL(menu), menu_item, pos );
+
+ m_clientData.Insert( NULL, pos );
+
+ if (GTK_WIDGET_REALIZED(m_widget))
+ {
+ gtk_widget_realize( menu_item );
+ gtk_widget_realize( GTK_BIN(menu_item)->child );
+
+ ApplyWidgetStyle();
+ }
+
+ // The best size of a wxChoice should probably
+ // be changed everytime the control has been
+ // changed, but at least after adding an item
+ // it has to change. Adapted from Matt Ownby.
+ InvalidateBestSize();
+
+ g_signal_connect_after (menu_item, "activate",
+ G_CALLBACK (gtk_choice_clicked_callback),
+ this);
+
+ gtk_widget_show( menu_item );
+
+ // return the index of the item in the control
+ return pos;