X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e78c1d7855d1fefcdbff0e093e21e5cf101ca604..115eded74f98a265636f0d484f821638b3e2c146:/src/gtk/combobox.cpp?ds=sidebyside diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 30a9824ea4..fb9623a2ba 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -44,6 +44,20 @@ gtkcombobox_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) { combo->SendSelectionChangedEvent(wxEVT_COMMAND_COMBOBOX_SELECTED); } + +static void +gtkcombobox_popupshown_callback(GObject *WXUNUSED(gobject), + GParamSpec *WXUNUSED(param_spec), + wxComboBox *combo) +{ + gboolean isShown; + g_object_get( combo->m_widget, "popup-shown", &isShown, NULL ); + wxCommandEvent event( isShown ? wxEVT_COMMAND_COMBOBOX_DROPDOWN + : wxEVT_COMMAND_COMBOBOX_CLOSEUP, + combo->GetId() ); + event.SetEventObject( combo ); + combo->HandleWindowEvent( event ); +} } //----------------------------------------------------------------------------- @@ -136,10 +150,20 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, if ( entry ) { - gtk_entry_set_text( entry, wxGTK_CONV(value) ); - if (style & wxCB_READONLY) + { + // this will assert and do nothing if the value is not in our list + // of strings which is the desired behaviour (for consistency with + // wxMSW and also because it doesn't make sense to have a string + // which is not a possible choice in a read-only combobox) + SetStringSelection(value); gtk_entry_set_editable( entry, FALSE ); + } + else // editable combobox + { + // any value is accepted, even if it's not in our list + gtk_entry_set_text( entry, wxGTK_CONV(value) ); + } g_signal_connect_after (entry, "changed", G_CALLBACK (gtkcombobox_text_changed_callback), this); @@ -148,6 +172,12 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, g_signal_connect_after (m_widget, "changed", G_CALLBACK (gtkcombobox_changed_callback), this); + if ( gtk_check_version(2,10,0) ) + { + g_signal_connect (m_widget, "notify::popup-shown", + G_CALLBACK (gtkcombobox_popupshown_callback), this); + } + SetInitialSize(size); // need this too because this is a wxControlWithItems return true; @@ -156,6 +186,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, void wxComboBox::GTKCreateComboBoxWidget() { m_widget = gtk_combo_box_entry_new_text(); + g_object_ref(m_widget); m_entry = GTK_ENTRY(GTK_BIN(m_widget)->child); } @@ -199,6 +230,8 @@ void wxComboBox::DisableEvents() g_signal_handlers_block_by_func(m_widget, (gpointer)gtkcombobox_changed_callback, this); + g_signal_handlers_block_by_func(m_widget, + (gpointer)gtkcombobox_popupshown_callback, this); } void wxComboBox::EnableEvents() @@ -209,6 +242,8 @@ void wxComboBox::EnableEvents() g_signal_handlers_unblock_by_func(m_widget, (gpointer)gtkcombobox_changed_callback, this); + g_signal_handlers_unblock_by_func(m_widget, + (gpointer)gtkcombobox_popupshown_callback, this); } GtkWidget* wxComboBox::GetConnectWidget()