+ listbox->HandleWindowEvent( event );
+}
+}
+
+//-----------------------------------------------------------------------------
+// "changed"
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static void
+gtk_listitem_changed_callback(GtkTreeSelection * WXUNUSED(selection),
+ wxListBox *listbox )
+{
+ if (g_blockEventsOnDrag) return;
+
+ if (listbox->m_blockEvent) return;
+
+ wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
+ event.SetEventObject( listbox );
+
+ 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->HandleWindowEvent( event );
+
+ return;
+ }
+ else
+ {
+ // indicate that this is a selection
+ event.SetExtraLong( 1 );
+ event.SetInt( selections[0] );
+
+ listbox->HandleWindowEvent( event );
+ }
+ }
+ else
+ {
+ int index = listbox->GetSelection();
+ if (index == wxNOT_FOUND)
+ {
+ // indicate that this is a deselection
+ event.SetExtraLong( 0 );
+ event.SetInt( -1 );
+
+ listbox->HandleWindowEvent( 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->HandleWindowEvent( event );
+
+ g_object_unref (entry);
+ }
+ }
+}
+}
+
+//-----------------------------------------------------------------------------
+// "key_press_event"
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static gint
+gtk_listbox_key_press_callback( GtkWidget *WXUNUSED(widget),
+ GdkEventKey *gdk_event,
+ wxListBox *listbox )
+{
+ if ((gdk_event->keyval == GDK_Return) ||
+ (gdk_event->keyval == GDK_ISO_Enter) ||
+ (gdk_event->keyval == GDK_KP_Enter))
+ {
+ int index = listbox->GetSelection();
+ if (index != wxNOT_FOUND)
+ {
+
+ wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, listbox->GetId() );
+ event.SetEventObject( listbox );
+
+ 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) );
+
+ /* bool ret = */ listbox->HandleWindowEvent( event );
+
+ g_object_unref (entry);
+
+// wxMac and wxMSW always invoke default action
+// if (!ret)
+ {
+ // DClick not handled -> invoke default action
+ wxWindow *tlw = wxGetTopLevelParent( listbox );
+ if (tlw)
+ {
+ GtkWindow *gtk_window = GTK_WINDOW( tlw->GetHandle() );
+ if (gtk_window)
+ gtk_window_activate_default( gtk_window );
+ }
+ }
+
+ // Always intercept, otherwise we'd get another dclick
+ // event from row_activated
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+}
+
+//-----------------------------------------------------------------------------
+// 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)
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static gint gtk_listbox_sort_callback(GtkTreeModel * WXUNUSED(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 * WXUNUSED(model),
+ gint WXUNUSED(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));