+ if (listbox->HasFlag(wxLB_MULTIPLE) || listbox->HasFlag(wxLB_EXTENDED))
+ {
+ 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
+ {
+ // indicate that this is a selection
+ event.SetExtraLong( 1 );
+ event.SetInt( selections[0] );
+
+ listbox->GetEventHandler()->ProcessEvent( event );
+ }
+ }
+ else
+ {
+ int index = listbox->GetSelection();
+ if (index == wxNOT_FOUND)
+ {
+ // indicate that this is a deselection
+ event.SetExtraLong( 0 );
+ event.SetInt( -1 );
+
+ listbox->GetEventHandler()->ProcessEvent( event );
+
+ return;
+ }
+ else
+ {
+ GtkTreeEntry* entry = listbox->GtkGetEntry( index );
+
+ // indicate that this is a selection
+ event.SetExtraLong( 1 );
+
+ event.SetInt( index );
+ event.SetString(wxConvUTF8.cMB2WX(gtk_tree_entry_get_label(entry)));
+
+ if ( listbox->HasClientObjectData() )
+ event.SetClientObject(
+ (wxClientData*) gtk_tree_entry_get_userdata(entry)
+ );
+ else if ( listbox->HasClientUntypedData() )
+ event.SetClientData( gtk_tree_entry_get_userdata(entry) );
+
+ listbox->GetEventHandler()->ProcessEvent( event );
+
+ g_object_unref (entry);
+ }
+ }
+}
+}
+
+//-----------------------------------------------------------------------------
+// GtkTreeEntry destruction (to destroy client data)
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static void gtk_tree_entry_destroy_cb(GtkTreeEntry* entry,
+ wxListBox* listbox)
+{
+ if (listbox->HasClientObjectData())
+ {
+ gpointer userdata = gtk_tree_entry_get_userdata(entry);
+ if (userdata)
+ delete (wxClientData *)userdata;
+ }
+}
+}
+
+//-----------------------------------------------------------------------------
+// Sorting callback (standard CmpNoCase return value)
+//-----------------------------------------------------------------------------
+#include <iostream>
+
+extern "C" {
+static gint gtk_listbox_sort_callback(GtkTreeModel *model,
+ GtkTreeIter *a,
+ GtkTreeIter *b,
+ wxListBox *listbox)
+{
+ GtkTreeEntry* entry;
+ GtkTreeEntry* entry2;
+
+ gtk_tree_model_get(GTK_TREE_MODEL(listbox->m_liststore),
+ a,
+ WXLISTBOX_DATACOLUMN_ARG(listbox),
+ &entry, -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(listbox->m_liststore),
+ b,
+ WXLISTBOX_DATACOLUMN_ARG(listbox),
+ &entry2, -1);
+ wxCHECK_MSG(entry, 0, wxT("Could not get entry"));
+ wxCHECK_MSG(entry2, 0, wxT("Could not get entry2"));
+
+ //We compare collate keys here instead of calling g_utf8_collate
+ //as it is rather slow (and even the docs reccommend this)
+ int ret = strcmp(gtk_tree_entry_get_collate_key(entry),
+ gtk_tree_entry_get_collate_key(entry2));
+
+ g_object_unref (entry);
+ g_object_unref (entry2);
+
+ return ret;
+}
+}
+
+//-----------------------------------------------------------------------------
+// Searching callback (TRUE == not equal, FALSE == equal)
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static gboolean gtk_listbox_searchequal_callback(GtkTreeModel* model,
+ gint column,
+ const gchar* key,
+ GtkTreeIter* iter,
+ wxListBox* listbox)
+{
+ GtkTreeEntry* entry;
+
+ gtk_tree_model_get(GTK_TREE_MODEL(listbox->m_liststore),
+ iter,
+ WXLISTBOX_DATACOLUMN_ARG(listbox),
+ &entry, -1);
+ wxCHECK_MSG(entry, 0, wxT("Could not get entry"));
+ wxGtkString keycollatekey(g_utf8_collate_key(key, -1));
+
+ int ret = strcmp(keycollatekey,
+ gtk_tree_entry_get_collate_key(entry));
+
+ g_object_unref (entry);
+
+ return ret != 0;
+}