+ n = pos + i;
+ // If sorted, use this wxSortedArrayStrings to determine
+ // the right insertion point
+ if (m_strings)
+ n = m_strings->Add(items[i]);
+
+ GTKInsertComboBoxTextItem( n, items[i] );
+
+ m_clientData.Insert( NULL, n );
+ AssignNewItemClientData(n, clientData, i, type);
+ }
+
+ InvalidateBestSize();
+
+ return n;
+}
+
+void wxChoice::DoSetItemClientData(unsigned int n, void* clientData)
+{
+ m_clientData[n] = clientData;
+}
+
+void* wxChoice::DoGetItemClientData(unsigned int n) const
+{
+ return m_clientData[n];
+}
+
+void wxChoice::DoClear()
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid control") );
+
+ GTKDisableEvents();
+
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ GtkTreeModel* model = gtk_combo_box_get_model( combobox );
+ gtk_list_store_clear(GTK_LIST_STORE(model));
+
+ m_clientData.Clear();
+
+ if (m_strings)
+ m_strings->Clear();
+
+ GTKEnableEvents();
+
+ InvalidateBestSize();
+}
+
+void wxChoice::DoDeleteOneItem(unsigned int n)
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid control") );
+ wxCHECK_RET( IsValid(n), wxT("invalid index in wxChoice::Delete") );
+
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ GtkTreeModel* model = gtk_combo_box_get_model( combobox );
+ GtkListStore* store = GTK_LIST_STORE(model);
+ GtkTreeIter iter;
+ gtk_tree_model_iter_nth_child( model, &iter,
+ NULL, (gint) n );
+ gtk_list_store_remove( store, &iter );
+
+ m_clientData.RemoveAt( n );
+ if ( m_strings )
+ m_strings->RemoveAt( n );
+
+ InvalidateBestSize();
+}
+
+int wxChoice::FindString( const wxString &item, bool bCase ) const
+{
+ wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid control") );
+
+ 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, m_stringCellIndex, &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) );
+
+ return wxNOT_FOUND;
+}
+
+int wxChoice::GetSelection() const
+{
+ return gtk_combo_box_get_active( GTK_COMBO_BOX( m_widget ) );
+}
+
+void wxChoice::SetString(unsigned int n, const wxString &text)
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid control") );
+
+ 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, m_stringCellIndex, &value );
+ g_value_unset( &value );
+ }
+
+ InvalidateBestSize();
+}
+
+wxString wxChoice::GetString(unsigned int n) const
+{
+ wxCHECK_MSG( m_widget != NULL, wxEmptyString, wxT("invalid control") );
+
+ wxString str;
+
+ 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, m_stringCellIndex, &value );
+ wxString tmp = wxGTK_CONV_BACK( g_value_get_string( &value ) );
+ g_value_unset( &value );
+ return tmp;
+ }
+
+ return str;
+}
+
+unsigned int wxChoice::GetCount() const
+{
+ wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid control") );
+
+ 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;
+}