]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/listbox.cpp
allow using multiple wxBufferedDCs at once (patch 1589441)
[wxWidgets.git] / src / gtk / listbox.cpp
index a6ec6583647beaf0a500ec95fa39e7f5eefe4921..e4bbf51aaecb47aab8877746d2c229f43502d405 100644 (file)
@@ -83,7 +83,7 @@ gtk_listbox_row_activated_callback(GtkTreeView        *treeview,
     if (listbox->IsSelected(sel))
     {
         GtkTreeEntry* entry = listbox->GtkGetEntry(sel);
-        
+
         if (entry)
         {
             event.SetInt(sel);
@@ -93,7 +93,7 @@ gtk_listbox_row_activated_callback(GtkTreeView        *treeview,
                 event.SetClientObject( (wxClientData*) gtk_tree_entry_get_userdata(entry) );
             else if ( listbox->HasClientUntypedData() )
                 event.SetClientData( gtk_tree_entry_get_userdata(entry) );
-                
+
             g_object_unref (entry);
         }
         else
@@ -148,9 +148,9 @@ static void
 gtk_listitem_changed_callback( GtkTreeSelection* selection, wxListBox *listbox )
 {
     if (g_blockEventsOnDrag) return;
-    
+
     if (listbox->m_blockEvent) return;
-    
+
     wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
     event.SetEventObject( listbox );
 
@@ -158,15 +158,15 @@ gtk_listitem_changed_callback( GtkTreeSelection* selection, wxListBox *listbox )
     {
         wxArrayInt selections;
         listbox->GetSelections( selections );
-        
+
         if (selections.GetCount() == 0)
         {
             // indicate that this is a deselection
             event.SetExtraLong( 0 );
             event.SetInt( -1 );
-        
+
             listbox->GetEventHandler()->ProcessEvent( event );
-        
+
             return;
         }
         else
@@ -174,7 +174,7 @@ gtk_listitem_changed_callback( GtkTreeSelection* selection, wxListBox *listbox )
             // indicate that this is a selection
             event.SetExtraLong( 1 );
             event.SetInt( selections[0] );
-        
+
             listbox->GetEventHandler()->ProcessEvent( event );
         }
     }
@@ -186,9 +186,9 @@ gtk_listitem_changed_callback( GtkTreeSelection* selection, wxListBox *listbox )
             // indicate that this is a deselection
             event.SetExtraLong( 0 );
             event.SetInt( -1 );
-        
+
             listbox->GetEventHandler()->ProcessEvent( event );
-        
+
             return;
         }
         else
@@ -406,7 +406,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
 
 
     GtkTreeSelection* selection = gtk_tree_view_get_selection( m_treeview );
-    
+
     g_signal_connect_after (selection, "changed",
                             G_CALLBACK (gtk_listitem_changed_callback), this);
 
@@ -516,7 +516,7 @@ void wxListBox::GtkInsertItems(const wxArrayString& items,
         wxString label = items[i];
 
         GtkTreeEntry* entry = gtk_tree_entry_new();
-        gtk_tree_entry_set_label(entry, wxConvUTF8.cWX2MB(label));
+        gtk_tree_entry_set_label(entry, wxGTK_CONV(label));
         gtk_tree_entry_set_destroy_func(entry,
                 (GtkTreeEntryDestroy)gtk_tree_entry_destroy_cb,
                             this);
@@ -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,