-IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl)
-
-bool wxComboBox::Create(wxWindow *parent, wxWindowID id, const wxString& value,
- const wxPoint& pos, const wxSize& size,
- int n, const wxString choices[],
- long style, const wxString& name )
-{
- m_alreadySent = FALSE;
- m_needParent = TRUE;
-
- PreCreation( parent, id, pos, size, style, name );
-
- m_widget = gtk_combo_new();
-
- wxSize newSize = size;
- if (newSize.x == -1) newSize.x = 100;
- if (newSize.y == -1) newSize.y = 26;
- SetSize( newSize.x, newSize.y );
-
- GtkWidget *list = GTK_COMBO(m_widget)->list;
-
- for (int i = 0; i < n; i++)
- {
- GtkWidget *list_item;
- list_item = gtk_list_item_new_with_label( choices[i] );
-
- gtk_container_add( GTK_CONTAINER(list), list_item );
-
- m_clientData.Append( (wxObject*)NULL );
-
- gtk_widget_show( list_item );
-
- gtk_signal_connect( GTK_OBJECT(list_item), "select",
- GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
- };
-
- PostCreation();
-
-/*
- gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
- GTK_SIGNAL_FUNC(gtk_combo_size_callback), (gpointer)this );
-*/
-
- if (!value.IsNull()) SetValue( value );
-
- Show( TRUE );
-
- return TRUE;
-};
-
-void wxComboBox::Clear(void)
-{
- GtkWidget *list = GTK_COMBO(m_widget)->list;
- gtk_list_clear_items( GTK_LIST(list), 0, Number() );
-
- m_clientData.Clear();
-};
-
-void wxComboBox::Append( const wxString &item )
-{
- Append( item, (char*)NULL );
-};
-
-void wxComboBox::Append( const wxString &item, char *clientData )
-{
- GtkWidget *list = GTK_COMBO(m_widget)->list;
-
- GtkWidget *list_item;
- list_item = gtk_list_item_new_with_label( item );
-
- gtk_signal_connect( GTK_OBJECT(list_item), "select",
- GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
-
- gtk_container_add( GTK_CONTAINER(list), list_item );
-
- gtk_widget_show( list_item );
-
- m_clientData.Append( (wxObject*)clientData );
-};
-
-void wxComboBox::Delete( int n )
-{
- GtkWidget *list = GTK_COMBO(m_widget)->list;
- gtk_list_clear_items( GTK_LIST(list), n, n );
-
- wxNode *node = m_clientData.Nth( n );
- if (!node)
- {
- wxFAIL_MSG(_("wxComboBox::Delete wrong index"));
- }
- else
- m_clientData.DeleteNode( node );
-};
-
-int wxComboBox::FindString( const wxString &item )
-{
- GtkWidget *list = GTK_COMBO(m_widget)->list;
-
- GList *child = GTK_LIST(list)->children;
- int count = 0;
- while (child)
- {
- GtkBin *bin = GTK_BIN( child->data );
- GtkLabel *label = GTK_LABEL( bin->child );
- if (item == label->label) return count;
- count++;
- child = child->next;
- };
- return -1;
-};
-
-char* wxComboBox::GetClientData( int n )
-{
- wxNode *node = m_clientData.Nth( n );
- if (node) return (char*)node->Data();
- return NULL;
-};
-
-void wxComboBox::SetClientData( int n, char * clientData )
-{
- wxNode *node = m_clientData.Nth( n );
- if (node) node->SetData( (wxObject*) clientData );
-};
-
-int wxComboBox::GetSelection(void) const
-{
- GtkWidget *list = GTK_COMBO(m_widget)->list;
-
- GList *selection = GTK_LIST(list)->selection;
- if (selection)
- {
- GList *child = GTK_LIST(list)->children;
- int count = 0;
- while (child)
+ if ( entry )
+ m_focusWidget = GTK_WIDGET( entry );
+
+ PostCreation(size);
+
+ if ( entry )
+ {
+ 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_editable_set_editable(GTK_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);
+ }
+
+ 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;
+}
+
+void wxComboBox::GTKCreateComboBoxWidget()
+{
+ m_widget = gtk_combo_box_entry_new_text();
+ g_object_ref(m_widget);
+
+ m_entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(m_widget)));
+}
+
+GtkEditable *wxComboBox::GetEditable() const
+{
+ return GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(m_widget)));
+}
+
+void wxComboBox::OnChar( wxKeyEvent &event )
+{
+ switch ( event.GetKeyCode() )
+ {
+ case WXK_RETURN:
+ if ( HasFlag(wxTE_PROCESS_ENTER) && GetEntry() )
+ {
+ // 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::EnableTextChangedEvents(bool enable)
+{
+ if ( !GetEntry() )
+ return;
+
+ if ( enable )
+ {
+ g_signal_handlers_unblock_by_func(gtk_bin_get_child(GTK_BIN(m_widget)),
+ (gpointer)gtkcombobox_text_changed_callback, this);
+ }
+ else // disable