]> git.saurik.com Git - wxWidgets.git/commitdiff
don't allow setting readonly combobox value to a string which is not one of the valid...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 6 Mar 2009 16:31:26 +0000 (16:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 6 Mar 2009 16:31:26 +0000 (16:31 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59372 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/combobox.h
src/gtk/combobox.cpp

index ca08253bf4d1f7597115979c564c20861d197656..c3ac2859d0216e9f543ebfc2317d078a7c70fbbf 100644 (file)
@@ -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
index b94d1f983b341429a83def8e8e4f1bc54ca5e408..7b0fe35ba7d01987b94d94cd3cc6983bfefdce70 100644 (file)
@@ -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);