+int wxChoice::GtkAddHelper(GtkWidget *menu, unsigned int pos, const wxString& item)
+{
+ 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;
+}
+
+wxSize wxChoice::DoGetBestSize() const
+{
+ wxSize ret( wxControl::DoGetBestSize() );
+
+ // we know better our horizontal extent: it depends on the longest string
+ // we have
+ ret.x = 0;
+ if ( m_widget )
+ {
+ int width;
+ unsigned int count = GetCount();
+ for ( unsigned int n = 0; n < count; n++ )
+ {
+ GetTextExtent( GetString(n), &width, NULL, NULL, NULL );
+ if ( width > ret.x )
+ ret.x = width;
+ }
+
+ // add extra for the choice "=" button
+
+ // VZ: I don't know how to get the right value, it seems to be in
+ // GtkOptionMenuProps struct from gtkoptionmenu.c but we can't get
+ // to it - maybe we can use gtk_option_menu_size_request() for this
+ // somehow?
+ //
+ // This default value works only for the default GTK+ theme (i.e.
+ // no theme at all) (FIXME)
+ static const int widthChoiceIndicator = 35;
+ ret.x += widthChoiceIndicator;
+ }
+
+ // but not less than the minimal width
+ if ( ret.x < 80 )
+ ret.x = 80;
+
+ // If this request_size is called with no entries then
+ // the returned height is wrong. Give it a reasonable
+ // default value.
+ if (ret.y <= 18)
+ ret.y = 8 + GetCharHeight();
+
+ CacheBestSize(ret);
+ return ret;
+}
+
+GdkWindow *wxChoice::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
+{
+ return GTK_BUTTON(m_widget)->event_window;
+}
+
+// static
+wxVisualAttributes
+wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
+{
+ return GetDefaultAttributesFromGTKWidget(gtk_option_menu_new);
+}
+
+
+#endif // wxUSE_CHOICE