]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix wxGTK wxListBox::Append() to return correct
authorRobert Roebling <robert@roebling.de>
Sun, 11 Feb 2007 14:31:40 +0000 (14:31 +0000)
committerRobert Roebling <robert@roebling.de>
Sun, 11 Feb 2007 14:31:40 +0000 (14:31 +0000)
    index (also for sorted list).
  Use wxControlWithItems::Insert(..) methods from
    wxListBox (can probably be removed).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44467 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/listbox.h
src/gtk/listbox.cpp

index d61560bdb4ea9bb0fe382c0119fd55713123e44c..fb219e1ba547c9670c90c0e43cb05063af82c561 100644 (file)
@@ -45,11 +45,11 @@ public:
     // all generic methods are in wxControlWithItems, except for the following
     // ones which are not yet implemented by wxChoice/wxComboBox
     void Insert(const wxString& item, unsigned int pos)
-        { DoInsert(item, pos); }
+        { /* return*/ wxControlWithItems::Insert(item,pos); }
     void Insert(const wxString& item, unsigned int pos, void *clientData)
-        { DoInsert(item, pos); SetClientData(pos, clientData); }
+        { /* return*/ wxControlWithItems::Insert(item,pos,clientData); }
     void Insert(const wxString& item, unsigned int pos, wxClientData *clientData)
-        { DoInsert(item, pos); SetClientObject(pos, clientData); }
+        { /* return*/ wxControlWithItems::Insert(item,pos,clientData); }
 
     void InsertItems(unsigned int nItems, const wxString *items, unsigned int pos);
     void InsertItems(const wxArrayString& items, unsigned int pos)
index 6c63afc9a5d62d9c0d9809b76551ccf7eaa4fa16..95636a79d5d4a0d31d3bbcbb39c914995ddd9cea 100644 (file)
@@ -552,12 +552,50 @@ void wxListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
 
 int wxListBox::DoAppend( const wxString& item )
 {
-    // Call DoInsertItems
-    unsigned int nWhere = wxListBox::GetCount();
-    wxArrayString aItems;
-    aItems.Add(item);
-    wxListBox::DoInsertItems(aItems, nWhere);
-    return nWhere;
+    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 );
+
+#if wxUSE_CHECKLISTBOX
+    if (m_hasCheckBoxes)
+    {
+            gtk_list_store_set(  m_liststore, &itercur,
+                                 0, FALSE, //FALSE == not toggled
+                                 1, entry, -1);
+    }
+    else
+#endif
+        gtk_list_store_set(m_liststore, &itercur,
+                                 0, entry, -1);
+
+    g_object_unref (entry); //liststore always refs :)
+
+    GtkTreePath* path = gtk_tree_model_get_path(
+                                GTK_TREE_MODEL(m_liststore),
+                                &itercur);
+
+    gint* pIntPath = gtk_tree_path_get_indices(path);
+
+    if (pIntPath == NULL)
+    {
+        wxLogSysError(wxT("internal wxListBox error in insertion"));
+        return wxNOT_FOUND;
+    }
+
+    int index = pIntPath[0];
+
+    gtk_tree_path_free( path );
+
+    return index;
 }
 
 void wxListBox::DoSetItems( const wxArrayString& items,