]> git.saurik.com Git - wxWidgets.git/commitdiff
modify the listbox item in place instead of deleting and inserting it back in SetStri...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 12 Apr 2007 14:28:36 +0000 (14:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 12 Apr 2007 14:28:36 +0000 (14:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45427 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/listbox.cpp

index 1502a4f4f791257af3d78d9629cb09bb460411a9..9d23c77735b0a7d75d640529e506edc94ae60804 100644 (file)
@@ -709,7 +709,7 @@ void wxListBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
 // string list access
 // ----------------------------------------------------------------------------
 
-void wxListBox::SetString(unsigned int n, const wxString &string)
+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") );
@@ -717,23 +717,28 @@ void wxListBox::SetString(unsigned int n, const wxString &string)
     GtkTreeEntry* entry = GtkGetEntry(n);
     wxCHECK_RET( entry, wxT("wrong listbox index") );
 
-    wxString label = string;
+    // update the item itself
+    gtk_tree_entry_set_label(entry, wxGTK_CONV(label));
 
-    // RN: This may look wierd but the problem is that the TreeView
-    // doesn't resort or update when changed above and there is no real
-    // notification function...
-    void* userdata = gtk_tree_entry_get_userdata(entry);
-    gtk_tree_entry_set_userdata(entry, NULL); //don't delete on destroy
-    g_object_unref (entry);
-
-    bool bWasSelected = wxListBox::IsSelected(n);
-    wxListBox::Delete(n);
+    // and update the model which will refresh the tree too
+    GtkTreeIter iter;
+    if ( !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_liststore),
+                                        &iter, NULL, n) )
+    {
+        wxFAIL_MSG( wxT("failed to get iterator") );
+        return;
+    }
 
-    wxArrayString aItems;
-    aItems.Add(label);
-    GtkInsertItems(aItems, &userdata, n);
-    if (bWasSelected)
-        wxListBox::GtkSetSelection(n, true, true);
+#if wxUSE_CHECKLISTBOX
+    if (m_hasCheckBoxes)
+    {
+        gtk_list_store_set(m_liststore, &iter,
+                             0, FALSE, //FALSE == not toggled
+                             1, entry, -1);
+    }
+    else
+#endif
+        gtk_list_store_set(m_liststore, &iter, 0, entry, -1);
 }
 
 wxString wxListBox::GetString(unsigned int n) const