+ wxCHECK_MSG( m_treeview != NULL, -1, wxT("invalid listbox") );
+
+ InvalidateBestSize();
+
+ GtkTreeEntry* entry = gtk_tree_entry_new();
+ gtk_tree_entry_set_label( entry, wxGTK_CONV(item) );
+ gtk_tree_entry_set_destroy_func(entry,
+ (GtkTreeEntryDestroy)gtk_tree_entry_destroy_cb,
+ this);
+
+ GtkTreeIter itercur;
+ gtk_list_store_insert_before( m_liststore, &itercur, NULL );
+
+ GtkSetItem(itercur, entry);
+
+ g_object_unref (entry);
+
+ return GtkGetIndexFor(itercur);
+}
+
+void wxListBox::DoSetItems( const wxArrayString& items,
+ void **clientData)
+{
+ Clear();
+ GtkInsertItems(items, clientData, 0);
+}
+
+// ----------------------------------------------------------------------------
+// deleting items
+// ----------------------------------------------------------------------------
+
+void wxListBox::Clear()
+{
+ wxCHECK_RET( m_treeview != NULL, wxT("invalid listbox") );
+
+ InvalidateBestSize();
+
+ gtk_list_store_clear( m_liststore ); /* well, THAT was easy :) */
+}
+
+void wxListBox::Delete(unsigned int n)
+{
+ wxCHECK_RET( m_treeview != NULL, wxT("invalid listbox") );
+
+ InvalidateBestSize();
+
+ GtkTreeIter iter;
+ wxCHECK_RET( GtkGetIteratorFor(n, &iter), wxT("wrong listbox index") );
+
+ // this returns false if iter is invalid (e.g. deleting item at end) but
+ // since we don't use iter, we ignore the return value
+ gtk_list_store_remove(m_liststore, &iter);
+}
+
+// ----------------------------------------------------------------------------
+// helper functions for working with iterators
+// ----------------------------------------------------------------------------
+
+bool wxListBox::GtkGetIteratorFor(unsigned pos, GtkTreeIter *iter) const
+{
+ if ( !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_liststore),
+ iter, NULL, pos) )
+ {
+ wxLogDebug(wxT("gtk_tree_model_iter_nth_child(%u) failed"), pos);
+ return false;
+ }
+
+ return true;
+}
+
+int wxListBox::GtkGetIndexFor(GtkTreeIter& iter) const
+{
+ GtkTreePath *path =
+ gtk_tree_model_get_path(GTK_TREE_MODEL(m_liststore), &iter);
+
+ gint* pIntPath = gtk_tree_path_get_indices(path);
+
+ wxCHECK_MSG( pIntPath, wxNOT_FOUND, _T("failed to get iterator path") );
+
+ int idx = pIntPath[0];
+
+ gtk_tree_path_free( path );
+
+ return idx;
+}
+
+// get GtkTreeEntry from position (note: you need to g_unref it if valid)
+GtkTreeEntry *wxListBox::GtkGetEntry(unsigned n) const
+{
+ GtkTreeIter iter;
+ if ( !GtkGetIteratorFor(n, &iter) )
+ return NULL;
+
+
+ GtkTreeEntry* entry = NULL;
+ gtk_tree_model_get(GTK_TREE_MODEL(m_liststore), &iter,
+ WXLISTBOX_DATACOLUMN, &entry, -1);
+
+ return entry;
+}
+
+void wxListBox::GtkSetItem(GtkTreeIter& iter, const GtkTreeEntry *entry)
+{
+#if wxUSE_CHECKLISTBOX
+ if ( m_hasCheckBoxes )
+ {
+ gtk_list_store_set(m_liststore, &iter,
+ 0, FALSE, // FALSE == not toggled
+ 1, entry,
+ -1);
+ }
+ else
+#endif // wxUSE_CHECKLISTBOX
+ {
+ gtk_list_store_set(m_liststore, &iter, 0, entry, -1);
+ }
+}
+
+// ----------------------------------------------------------------------------
+// client data
+// ----------------------------------------------------------------------------
+
+void* wxListBox::DoGetItemClientData(unsigned int n) const
+{
+ wxCHECK_MSG( IsValid(n), NULL,
+ wxT("Invalid index passed to GetItemClientData") );
+
+ GtkTreeEntry* entry = GtkGetEntry(n);
+ wxCHECK_MSG(entry, NULL, wxT("could not get entry"));
+
+ void* userdata = gtk_tree_entry_get_userdata( entry );
+ g_object_unref (entry);
+ return userdata;
+}
+
+wxClientData* wxListBox::DoGetItemClientObject(unsigned int n) const
+{
+ return (wxClientData*) wxListBox::DoGetItemClientData(n);
+}
+
+void wxListBox::DoSetItemClientData(unsigned int n, void* clientData)
+{
+ wxCHECK_RET( IsValid(n),
+ wxT("Invalid index passed to SetItemClientData") );
+
+ GtkTreeEntry* entry = GtkGetEntry(n);
+ wxCHECK_RET(entry, wxT("could not get entry"));
+
+ gtk_tree_entry_set_userdata( entry, clientData );
+ g_object_unref (entry);
+}
+
+void wxListBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
+{
+ // wxItemContainer already deletes data for us
+ wxListBox::DoSetItemClientData(n, (void*) clientData);
+}
+
+// ----------------------------------------------------------------------------
+// string list access
+// ----------------------------------------------------------------------------
+
+void wxListBox::SetString(unsigned int n, const wxString& label)
+{
+ wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::SetString") );
+ wxCHECK_RET( m_treeview != NULL, wxT("invalid listbox") );
+
+ GtkTreeEntry* entry = GtkGetEntry(n);
+ wxCHECK_RET( entry, wxT("wrong listbox index") );
+
+ // update the item itself
+ gtk_tree_entry_set_label(entry, wxGTK_CONV(label));
+
+ // and update the model which will refresh the tree too
+ GtkTreeIter iter;
+ wxCHECK_RET( GtkGetIteratorFor(n, &iter), _T("failed to get iterator") );
+
+ // FIXME: this resets the checked status of a wxCheckListBox item
+
+ GtkSetItem(iter, entry);
+}
+
+wxString wxListBox::GetString(unsigned int n) const
+{
+ wxCHECK_MSG( m_treeview != NULL, wxEmptyString, wxT("invalid listbox") );
+
+ GtkTreeEntry* entry = GtkGetEntry(n);
+ wxCHECK_MSG( entry, wxEmptyString, wxT("wrong listbox index") );
+
+ wxString label = wxGTK_CONV_BACK( gtk_tree_entry_get_label(entry) );
+
+ g_object_unref (entry);
+ return label;
+}
+
+unsigned int wxListBox::GetCount() const
+{
+ wxCHECK_MSG( m_treeview != NULL, 0, wxT("invalid listbox") );
+
+ return (unsigned int)gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_liststore), NULL);
+}
+
+int wxListBox::FindString( const wxString &item, bool bCase ) const
+{
+ wxCHECK_MSG( m_treeview != NULL, wxNOT_FOUND, wxT("invalid listbox") );
+
+ //Sort of hackish - maybe there is a faster way
+ unsigned int nCount = wxListBox::GetCount();
+
+ for(unsigned int i = 0; i < nCount; ++i)