- wxCHECK_RET( m_widget != NULL, "invalid combobox" );
-
- GtkWidget *list = GTK_COMBO(m_widget)->list;
- gtk_list_select_item( GTK_LIST(list), n );
+ wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+
+ DisableEvents();
+
+ GtkComboBox* combobox = GTK_COMBO_BOX( m_widget );
+ gtk_combo_box_set_active( combobox, n );
+
+ EnableEvents();
+}
+
+void wxComboBox::OnChar( wxKeyEvent &event )
+{
+ switch ( event.GetKeyCode() )
+ {
+ case WXK_RETURN:
+ if ( HasFlag(wxTE_PROCESS_ENTER) )
+ {
+ // GTK automatically selects an item if its in the list
+ wxCommandEvent eventEnter(wxEVT_COMMAND_TEXT_ENTER, GetId());
+ eventEnter.SetString( GetValue() );
+ eventEnter.SetInt( GetSelection() );
+ eventEnter.SetEventObject( this );
+
+ if ( HandleWindowEvent(eventEnter) )
+ {
+ // Catch GTK event so that GTK doesn't open the drop
+ // down list upon RETURN.
+ return;
+ }
+ }
+
+ // On enter key press, we must give a signal to default control,
+ // Otherwise, nothing happens when pressing Enter from inside a
+ // combo box in a dialog.
+ wxWindow *top_frame = wxGetTopLevelParent(this);
+ if( top_frame && GTK_IS_WINDOW(top_frame->m_widget) )
+ {
+ GtkWindow *window = GTK_WINDOW(top_frame->m_widget);
+ if ( window->default_widget )
+ gtk_widget_activate( window->default_widget );
+ }
+ break;
+ }
+
+ event.Skip();