From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Fri, 6 Mar 2009 16:31:26 +0000 (+0000)
Subject: don't allow setting readonly combobox value to a string which is not one of the valid... 
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a3281dbc1c102de5b2dc081392d1a315e0739b6a

don't allow setting readonly combobox value to a string which is not one of the valid choices in wxGTK neither and document this behaviour (closes #10549)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59372 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/interface/wx/combobox.h b/interface/wx/combobox.h
index ca08253bf4..c3ac2859d0 100644
--- a/interface/wx/combobox.h
+++ b/interface/wx/combobox.h
@@ -82,6 +82,8 @@ public:
             Window identifier. The value wxID_ANY indicates a default value.
         @param value
             Initial selection string. An empty string indicates no selection.
+            Notice that for the controls with @c wxCB_READONLY style this
+            string must be one of the valid choices if it is not empty.
         @param pos
             Window position.
         @param size
diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp
index b94d1f983b..7b0fe35ba7 100644
--- a/src/gtk/combobox.cpp
+++ b/src/gtk/combobox.cpp
@@ -136,10 +136,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);