]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/combobox.cpp
Fix item selection/focus drawing in generic wxListCtrl.
[wxWidgets.git] / src / gtk / combobox.cpp
index 30a9824ea49893c9403ce72fb59aff8b10e47135..1743505cac3c8d00db5c888469d38b84fe2a83d1 100644 (file)
@@ -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);
 }
@@ -191,7 +222,7 @@ void wxComboBox::OnChar( wxKeyEvent &event )
     event.Skip();
 }
 
-void wxComboBox::DisableEvents()
+void wxComboBox::GTKDisableEvents()
 {
     if ( GetEntry() )
         g_signal_handlers_block_by_func(GTK_BIN(m_widget)->child,
@@ -199,9 +230,11 @@ 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()
+void wxComboBox::GTKEnableEvents()
 {
     if ( GetEntry() )
         g_signal_handlers_unblock_by_func(GTK_BIN(m_widget)->child,
@@ -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()
@@ -216,10 +251,8 @@ GtkWidget* wxComboBox::GetConnectWidget()
     return GTK_WIDGET( GetEntry() );
 }
 
-GdkWindow *wxComboBox::GTKGetWindow(wxArrayGdkWindows& windows) const
+GdkWindow* wxComboBox::GTKGetWindow(wxArrayGdkWindows& /* windows */) const
 {
-    wxUnusedVar(windows);
-
     return GetEntry()->text_area;
 }
 
@@ -304,4 +337,13 @@ void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
     event.Enable(!wxTextEntry::IsEmpty());
 }
 
+void wxComboBox::Popup()
+{
+     gtk_combo_box_popup( GTK_COMBO_BOX(m_widget) );
+}
+
+void wxComboBox::Dismiss()
+{
+    gtk_combo_box_popdown( GTK_COMBO_BOX(m_widget) );
+}
 #endif // wxUSE_COMBOBOX