+ wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ wxCHECK_RET( IsValid(n), wxT("invalid index") );
+
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ gtk_combo_box_remove_text( combobox, n );
+ }
+ else
+#endif
+ {
+ GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
+
+ GList *child = g_list_nth( listbox->children, n );
+
+ if (!child)
+ {
+ wxFAIL_MSG(wxT("wrong index"));
+ return;
+ }
+
+ DisableEvents();
+
+ GList *list = g_list_append( (GList*) NULL, child->data );
+ gtk_list_remove_items( listbox, list );
+ g_list_free( list );
+
+ EnableEvents();
+ }
+
+ wxList::compatibility_iterator node = m_clientObjectList.Item( n );
+ if (node)
+ {
+ wxClientData *cd = (wxClientData*)node->GetData();
+ if (cd) delete cd;
+ m_clientObjectList.Erase( node );
+ }
+
+ node = m_clientDataList.Item( n );
+ if (node)
+ m_clientDataList.Erase( node );
+
+ InvalidateBestSize();
+}
+
+void wxComboBox::SetString(unsigned int n, const wxString &text)
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ wxCHECK_RET( IsValid(n), wxT("invalid index") );
+
+ GtkTreeModel *model = gtk_combo_box_get_model( combobox );
+ GtkTreeIter iter;
+ if (gtk_tree_model_iter_nth_child (model, &iter, NULL, n))
+ {
+ GValue value = { 0, };
+ g_value_init( &value, G_TYPE_STRING );
+ g_value_set_string( &value, wxGTK_CONV( text ) );
+ gtk_list_store_set_value( GTK_LIST_STORE(model), &iter, 0, &value );
+ g_value_unset( &value );
+ }
+ }
+ else
+#endif
+ {
+ GtkWidget *list = GTK_COMBO(m_widget)->list;
+
+ GList *child = g_list_nth( GTK_LIST(list)->children, n );
+ if (child)
+ {
+ GtkBin *bin = GTK_BIN( child->data );
+ GtkLabel *label = GTK_LABEL( bin->child );
+ gtk_label_set_text(label, wxGTK_CONV(text));
+ }
+ else
+ {
+ wxFAIL_MSG( wxT("wxComboBox: wrong index") );
+ }
+ }
+
+ InvalidateBestSize();
+}
+
+int wxComboBox::FindString( const wxString &item, bool bCase ) const
+{
+ wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid combobox") );
+
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ GtkTreeModel* model = gtk_combo_box_get_model( combobox );
+ GtkTreeIter iter;
+ gtk_tree_model_get_iter_first( model, &iter );
+ if (!gtk_list_store_iter_is_valid(GTK_LIST_STORE(model), &iter ))
+ return -1;
+ int count = 0;
+ do
+ {
+ GValue value = { 0, };
+ gtk_tree_model_get_value( model, &iter, 0, &value );
+ wxString str = wxGTK_CONV_BACK( g_value_get_string( &value ) );
+ g_value_unset( &value );
+
+ if (item.IsSameAs( str, bCase ) )
+ return count;
+
+ count++;
+
+ } while (gtk_tree_model_iter_next( model, &iter ));
+ }
+ else
+#endif
+ {
+ GtkWidget *list = GTK_COMBO(m_widget)->list;
+
+ GList *child = GTK_LIST(list)->children;
+ int count = 0;
+ while (child)
+ {
+ GtkBin *bin = GTK_BIN( child->data );
+ GtkLabel *label = GTK_LABEL( bin->child );
+ wxString str( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
+
+ if (item.IsSameAs( str , bCase ) )
+ return count;
+
+ count++;
+ child = child->next;
+ }
+ }
+
+ return wxNOT_FOUND;
+}
+
+int wxComboBox::GetSelection() const
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ return gtk_combo_box_get_active( combobox );
+ }
+ else
+#endif
+ // if the popup is currently opened, use the selection as it had been
+ // before it dropped down
+ return g_SelectionBeforePopup == wxID_NONE ? GetCurrentSelection()
+ : g_SelectionBeforePopup;
+}
+
+int wxComboBox::GetCurrentSelection() const
+{
+ wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
+
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ return gtk_combo_box_get_active( combobox );
+ }
+ else
+#endif
+ {
+ GtkWidget *list = GTK_COMBO(m_widget)->list;
+
+ GList *selection = GTK_LIST(list)->selection;
+ if (selection)
+ {
+ GList *child = GTK_LIST(list)->children;
+ int count = 0;
+ while (child)
+ {
+ if (child->data == selection->data) return count;
+ count++;
+ child = child->next;
+ }
+ }
+ }
+
+ return -1;
+}
+
+wxString wxComboBox::GetString(unsigned int n) const
+{
+ wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") );
+
+ wxString str;
+
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ GtkTreeModel *model = gtk_combo_box_get_model( combobox );
+ GtkTreeIter iter;
+ if (gtk_tree_model_iter_nth_child (model, &iter, NULL, n))
+ {
+ GValue value = { 0, };
+ gtk_tree_model_get_value( model, &iter, 0, &value );
+ wxString tmp = wxGTK_CONV_BACK( g_value_get_string( &value ) );
+ g_value_unset( &value );
+ return tmp;
+ }
+ }
+ else
+#endif
+ {
+ GtkWidget *list = GTK_COMBO(m_widget)->list;
+
+ GList *child = g_list_nth( GTK_LIST(list)->children, n );
+ if (child)
+ {
+ GtkBin *bin = GTK_BIN( child->data );
+ GtkLabel *label = GTK_LABEL( bin->child );
+ str = wxGTK_CONV_BACK( gtk_label_get_text(label) );
+ }
+ else
+ {
+ wxFAIL_MSG( wxT("wxComboBox: wrong index") );
+ }
+ }
+
+ return str;
+}
+
+wxString wxComboBox::GetStringSelection() const
+{
+ wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid combobox") );
+
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ int sel = gtk_combo_box_get_active( combobox );
+ if (sel == -1)
+ return wxEmptyString;
+ return GetString(sel);
+ }
+ else
+#endif
+ {
+ GtkWidget *list = GTK_COMBO(m_widget)->list;
+
+ GList *selection = GTK_LIST(list)->selection;
+ if (selection)
+ {
+ GtkBin *bin = GTK_BIN( selection->data );
+ GtkLabel *label = GTK_LABEL( bin->child );
+ wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text(label) ) );
+ return tmp;
+ }
+
+ wxFAIL_MSG( wxT("wxComboBox: no selection") );
+ }
+
+ return wxEmptyString;
+}
+
+unsigned int wxComboBox::GetCount() const
+{
+ wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") );
+
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ GtkTreeModel* model = gtk_combo_box_get_model( combobox );
+ GtkTreeIter iter;
+ gtk_tree_model_get_iter_first( model, &iter );
+ if (!gtk_list_store_iter_is_valid(GTK_LIST_STORE(model), &iter ))
+ return 0;
+ unsigned int ret = 1;
+ while (gtk_tree_model_iter_next( model, &iter ))
+ ret++;
+ return ret;
+ }
+ else
+#endif
+ {
+ GtkWidget *list = GTK_COMBO(m_widget)->list;
+
+ GList *child = GTK_LIST(list)->children;
+ unsigned int count = 0;
+ while (child)
+ {
+ count++;
+ child = child->next;
+ }
+ return count;
+ }
+
+ return 0;
+}
+
+void wxComboBox::SetSelection( int n )
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+
+ DisableEvents();
+
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ gtk_combo_box_set_active( combobox, n );
+ }
+ else
+#endif
+ {
+ GtkWidget *list = GTK_COMBO(m_widget)->list;
+ gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
+ gtk_list_select_item( GTK_LIST(list), n );
+ m_prevSelection = n;
+ }
+
+ EnableEvents();
+}
+
+wxString wxComboBox::GetValue() const
+{
+ GtkEntry *entry = NULL;
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ entry = GTK_ENTRY( GTK_BIN(m_widget)->child );
+ else
+#endif
+ entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry );
+
+ wxString tmp( wxGTK_CONV_BACK( gtk_entry_get_text( entry ) ) );
+
+#if 0
+ for (int i = 0; i < wxStrlen(tmp.c_str()) +1; i++)
+ {
+ wxChar c = tmp[i];
+ printf( "%d ", (int) (c) );
+ }
+ printf( "\n" );
+#endif
+
+ return tmp;
+}