Update the text part of combobox when changing text of selected item in wxGTK.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 11 Mar 2012 23:55:19 +0000 (23:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 11 Mar 2012 23:55:19 +0000 (23:55 +0000)
Add a call to SetValue() to wxComboBox::SetString() in wxGTK if the item being
changed is the currently selected one. The new behaviour is consistent with
wxMSW and also makes more sense.

Document it too to remove any doubts about what is supposed to happen in this
case.

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

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

index 02ae7e481a996a1c9e3a39f38c09516604d908af..e31a347c8ec2bf3f053e110684a9512f615b3ec4 100644 (file)
@@ -88,6 +88,9 @@ public:
     {
         return wxItemContainer::GetStringSelection();
     }
+
+    virtual void SetString(unsigned int n, const wxString& string);
+
     virtual void Popup();
     virtual void Dismiss();
 
index f692cc578b795ffbe69048e720026905a3a7d63d..8a78e9c4c83ad0b507d1602a3fa837d52187dcc2 100644 (file)
@@ -314,7 +314,15 @@ public:
     virtual int FindString(const wxString& s, bool bCase = false) const;
     virtual wxString GetString(unsigned int n) const;
     virtual wxString GetStringSelection() const;
-    virtual void SetString(unsigned int n, const wxString& s);
+
+    /**
+        Changes the text of the specified combobox item.
+
+        Notice that if the item is the currently selected one, i.e. if its text
+        is displayed in the text part of the combobox, then the text is also
+        replaced with the new @a text.
+     */
+    virtual void SetString(unsigned int n, const wxString& text);
 
     virtual unsigned int GetCount() const;
 };
index 045c6166ba478c697e6651a2bee894aafd52d198..445a6cddb130b7354ddfbceabe041f8608b364c9 100644 (file)
@@ -282,6 +282,19 @@ void wxComboBox::SetValue(const wxString& value)
         wxTextEntry::SetValue(value);
 }
 
+void wxComboBox::SetString(unsigned int n, const wxString& text)
+{
+    wxChoice::SetString(n, text);
+
+    if ( static_cast<int>(n) == GetSelection() )
+    {
+        // We also need to update the currently shown text, for consistency
+        // with wxMSW and also because it makes sense as leaving the old string
+        // in the text but not in the list would be confusing to the user.
+        SetValue(text);
+    }
+}
+
 // ----------------------------------------------------------------------------
 // standard event handling
 // ----------------------------------------------------------------------------