- 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) && (listbox->m_oldSelection.GetCount() == 0))
- {
- // nothing changed, just leave
- return;
- }
-
- if (selections.GetCount() == listbox->m_oldSelection.GetCount())
- {
- bool changed = false;
- size_t idx;
- for (idx = 0; idx < selections.GetCount(); idx++)
- {
- if (selections[idx] != listbox->m_oldSelection[idx])
- {
- changed = true;
- break;
- }
- }
-
- // nothing changed, just leave
- if (!changed)
- return;
- }
-
- if (selections.GetCount() == 0)
- {
- // indicate that this is a deselection
- event.SetExtraLong( 0 );
- int item = listbox->m_oldSelection[0];
- listbox->m_oldSelection = selections;
- SendEvent( event, listbox, item );
- return;
- }
-
- int item;
- // Now test if any new item is selected
- bool any_new_selected = false;
- size_t idx;
- for (idx = 0; idx < selections.GetCount(); idx++)
- {
- item = selections[idx];
- if (listbox->m_oldSelection.Index(item) == wxNOT_FOUND)
- {
- any_new_selected = true;
- break;
- }
- }
-
- if (any_new_selected)
- {
- // indicate that this is a selection
- event.SetExtraLong( 1 );
- listbox->m_oldSelection = selections;
- SendEvent( event, listbox, item );
- return;
- }
-
- // Now test if any new item is deselected
- bool any_new_deselected = false;
- for (idx = 0; idx < listbox->m_oldSelection.GetCount(); idx++)
- {
- item = listbox->m_oldSelection[idx];
- if (selections.Index(item) == wxNOT_FOUND)
- {
- any_new_deselected = true;
- break;
- }
- }
-
- if (any_new_deselected)
- {
- // indicate that this is a selection
- event.SetExtraLong( 0 );
- listbox->m_oldSelection = selections;
- SendEvent( event, listbox, item );
- return;
- }
-
- wxLogError( wxT("Wrong wxListBox selection") );
- }
- 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);
- }
- }