+ 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;
+ }
+ }
+ break;
+ }
+
+ event.Skip();
+}
+
+void wxComboBox::DisableEvents()
+{
+ g_signal_handlers_block_by_func(GTK_BIN(m_widget)->child,
+ (gpointer)gtkcombobox_text_changed_callback, this);
+
+ g_signal_handlers_block_by_func(m_widget,
+ (gpointer)gtkcombobox_changed_callback, this);
+}
+
+void wxComboBox::EnableEvents()
+{
+ g_signal_handlers_unblock_by_func(GTK_BIN(m_widget)->child,
+ (gpointer)gtkcombobox_text_changed_callback, this);
+
+ g_signal_handlers_unblock_by_func(m_widget,
+ (gpointer)gtkcombobox_changed_callback, this);
+}
+
+GtkWidget* wxComboBox::GetConnectWidget()
+{
+ return GTK_WIDGET( GetEntry() );
+}
+
+GdkWindow *wxComboBox::GTKGetWindow(wxArrayGdkWindows& windows) const
+{
+ wxUnusedVar(windows);
+
+ return GetEntry()->text_area;
+}
+
+wxSize wxComboBox::DoGetBestSize() const
+{
+ // strangely, this returns a width of 188 pixels from GTK+ (?)
+ wxSize ret( wxControl::DoGetBestSize() );
+
+ // we know better our horizontal extent: it depends on the longest string
+ // in the combobox
+ if ( m_widget )
+ {
+ ret.x = 60; // start with something "sensible"
+ int width;
+ unsigned int count = GetCount();
+ for ( unsigned int n = 0; n < count; n++ )
+ {
+ GetTextExtent(GetString(n), &width, NULL, NULL, NULL );
+ if ( width + 40 > ret.x ) // 40 for drop down arrow and space around text
+ ret.x = width + 40;
+ }
+ }
+
+ // empty combobox should have some reasonable default size too
+ if ((GetCount() == 0) && (ret.x < 80))
+ ret.x = 80;
+
+ CacheBestSize(ret);
+ return ret;
+}
+
+// static
+wxVisualAttributes
+wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
+{
+ return GetDefaultAttributesFromGTKWidget(gtk_combo_box_entry_new, true);
+}
+
+// ----------------------------------------------------------------------------
+// standard event handling
+// ----------------------------------------------------------------------------
+
+void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event))
+{
+ Cut();
+}