void wxListBox::DoSetSelection( int n, bool select ) { wxCHECK_RET( m_list != NULL, wxT("invalid listbox") ); m_blockEvent = true; if (select) { if ((m_windowStyle & wxLB_SINGLE) != 0) gtk_list_unselect_item( m_list, m_prevSelection ); gtk_list_select_item( m_list, n ); m_prevSelection = n; } else gtk_list_unselect_item( m_list, n ); m_blockEvent = false; }
void wxComboBox::SetSelection( int n ) { wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); DisableEvents(); GtkWidget *list = GTK_COMBO(m_widget)->list; gtk_list_unselect_item( GTK_LIST(list), m_prevSelection ); gtk_list_select_item( GTK_LIST(list), n ); m_prevSelection = n; EnableEvents(); }
/* Unselects the child number item of the list. Nothing happens if item * is out of bounds. The signal GtkList::unselect-child will be emitted. */ int clip_GTK_LISTUNSELECTITEM(ClipMachine * ClipMachineMemory) { C_widget *clst = _fetch_cw_arg(ClipMachineMemory); gint item = INT_OPTION(ClipMachineMemory, 2, 1); CHECKCWID(clst, GTK_IS_LIST); CHECKOPT(2, NUMERIC_type_of_ClipVarType); gtk_list_unselect_item(GTK_LIST(clst->widget), item - 1); return 0; err: return 1; }
static void gtk_listitem_select_cb( GtkWidget *widget, wxListBox *listbox, bool is_selection ) { if (g_isIdle) wxapp_install_idle_handler(); if (!listbox->m_hasVMT) return; if (g_blockEventsOnDrag) return; if (listbox->m_blockEvent) return; wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); event.SetEventObject( listbox ); // indicate whether this is a selection or a deselection event.SetExtraLong( is_selection ); if ((listbox->GetWindowStyleFlag() & wxLB_SINGLE) != 0) { int sel = listbox->GtkGetIndex( widget ); if (listbox->m_prevSelection != sel) gtk_list_unselect_item( listbox->m_list, listbox->m_prevSelection ); listbox->m_prevSelection = sel; } wxArrayInt aSelections; int n, count = listbox->GetSelections(aSelections); if ( count > 0 ) { n = aSelections[0]; if ( listbox->HasClientObjectData() ) event.SetClientObject( listbox->GetClientObject(n) ); else if ( listbox->HasClientUntypedData() ) event.SetClientData( listbox->GetClientData(n) ); event.SetString( listbox->GetString(n) ); } else { n = -1; } event.SetInt(n); // No longer required with new code in wxLB_SINGLE // listbox->GetEventHandler()->AddPendingEvent( event ); listbox->GetEventHandler()->ProcessEvent( event ); }
static gint gtk_listbox_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxListBox *listbox ) { if (g_isIdle) wxapp_install_idle_handler(); if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnScroll) return FALSE; if (!listbox->m_hasVMT) return FALSE; int sel = listbox->GtkGetIndex( widget ); #if wxUSE_CHECKLISTBOX if ((listbox->m_hasCheckBoxes) && (gdk_event->x < 15) && (gdk_event->type != GDK_2BUTTON_PRESS)) { wxCheckListBox *clb = (wxCheckListBox *)listbox; clb->Check( sel, !clb->IsChecked(sel) ); wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); event.SetEventObject( listbox ); event.SetInt( sel ); listbox->GetEventHandler()->ProcessEvent( event ); } #endif // wxUSE_CHECKLISTBOX if ((gdk_event->state == 0) && (((listbox->GetWindowStyleFlag() & wxLB_MULTIPLE) != 0) || ((listbox->GetWindowStyleFlag() & wxLB_EXTENDED) != 0)) ) { listbox->m_blockEvent = true; int i; for (i = 0; i < (int)listbox->GetCount(); i++) if (i != sel) gtk_list_unselect_item( GTK_LIST(listbox->m_list), i ); listbox->m_blockEvent = false; return false; } /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */ g_hasDoubleClicked = (gdk_event->type == GDK_2BUTTON_PRESS); return FALSE; }
static void gtkcombo_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(widget), wxComboBox *combo ) { if (g_isIdle) wxapp_install_idle_handler(); if (!combo->m_hasVMT) return; if (g_blockEventsOnDrag) return; int curSelection = combo->GetCurrentSelection(); if (combo->m_prevSelection == curSelection) return; GtkWidget *list = GTK_COMBO(combo->m_widget)->list; gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection ); combo->m_prevSelection = curSelection; // Quickly set the value of the combo box // as GTK+ does that only AFTER the event // is sent. g_signal_handlers_disconnect_by_func (GTK_COMBO (combo->GetHandle())->entry, (gpointer) gtkcombo_text_changed_callback, combo); combo->SetValue( combo->GetStringSelection() ); g_signal_connect_after (GTK_COMBO (combo->GetHandle())->entry, "changed", G_CALLBACK (gtkcombo_text_changed_callback), combo); // throw a SELECTED event only if the combobox popup is hidden (wxID_NONE) // because when combobox popup is shown, gtkcombo_combo_select_child_callback is // called each times the mouse is over an item with a pressed button so a lot // of SELECTED event could be generated if the user keep the mouse button down // and select other items ... if (g_SelectionBeforePopup == wxID_NONE) { wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() ); event.SetInt( curSelection ); event.SetString( combo->GetStringSelection() ); event.SetEventObject( combo ); combo->GetEventHandler()->ProcessEvent( event ); // for consistency with the other ports, don't generate text update // events while the user is browsing the combobox neither wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); event2.SetString( combo->GetValue() ); event2.SetEventObject( combo ); combo->GetEventHandler()->ProcessEvent( event2 ); } }
void wxComboBox::SetSelection( int n ) { wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); DisableEvents(); #ifdef __WXGTK24__ if (!gtk_check_version(2,4,0)) { GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); gtk_combo_box_set_active( combobox, n ); } else #endif { GtkWidget *list = GTK_COMBO(m_widget)->list; gtk_list_unselect_item( GTK_LIST(list), m_prevSelection ); gtk_list_select_item( GTK_LIST(list), n ); m_prevSelection = n; } EnableEvents(); }
static gint gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox ) { if (g_isIdle) wxapp_install_idle_handler(); if (g_blockEventsOnDrag) return FALSE; bool ret = false; if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) { wxNavigationKeyEvent new_event; /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ new_event.SetDirection( (gdk_event->keyval == GDK_Tab) ); /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); new_event.SetCurrentFocus( listbox ); ret = listbox->GetEventHandler()->ProcessEvent( new_event ); } if ((gdk_event->keyval == GDK_Return) && (!ret)) { // eat return in all modes ret = true; } #if wxUSE_CHECKLISTBOX if ((gdk_event->keyval == ' ') && (listbox->m_hasCheckBoxes) && (!ret)) { int sel = listbox->GtkGetIndex( widget ); wxCheckListBox *clb = (wxCheckListBox *)listbox; clb->Check( sel, !clb->IsChecked(sel) ); wxCommandEvent new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); new_event.SetEventObject( listbox ); new_event.SetInt( sel ); ret = listbox->GetEventHandler()->ProcessEvent( new_event ); } #endif // wxUSE_CHECKLISTBOX // Check or uncheck item with SPACE if ((gdk_event->keyval == ' ') && (!ret) && (((listbox->GetWindowStyleFlag() & wxLB_MULTIPLE) != 0) || ((listbox->GetWindowStyleFlag() & wxLB_EXTENDED) != 0)) ) { int sel = listbox->GtkGetIndex( widget ); if (sel != -1) { ret = true; if (listbox->IsSelected( sel )) gtk_list_unselect_item( listbox->m_list, sel ); else gtk_list_select_item( listbox->m_list, sel ); wxCommandEvent new_event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); new_event.SetEventObject( listbox ); wxArrayInt aSelections; int n, count = listbox->GetSelections(aSelections); if ( count > 0 ) { n = aSelections[0]; if ( listbox->HasClientObjectData() ) new_event.SetClientObject( listbox->GetClientObject(n) ); else if ( listbox->HasClientUntypedData() ) new_event.SetClientData( listbox->GetClientData(n) ); new_event.SetString( listbox->GetString(n) ); } else { n = -1; } new_event.SetInt(n); listbox->GetEventHandler()->ProcessEvent( new_event ); } } if (ret) { gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); return TRUE; } return FALSE; }