]> git.saurik.com Git - wxWidgets.git/commitdiff
add back wxChoice::DoGetBestSize() removed by the previous refactoring, it's still...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 22 May 2008 00:55:59 +0000 (00:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 22 May 2008 00:55:59 +0000 (00:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53698 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/choice.h
src/gtk/choice.cpp

index 478a15ce09e8f7117f52735923193346ed435881..6da310248b8cfd6d625cd3c9133fc8aca3af56bd 100644 (file)
@@ -85,6 +85,7 @@ protected:
     // contains the client data for the items
     wxArrayPtrVoid m_clientData;
 
+    virtual wxSize DoGetBestSize() const;
     virtual int DoInsertItems(const wxArrayStringsAdapter& items,
                               unsigned int pos,
                               void **clientData, wxClientDataType type);
index 9eefcf06da0e0cbe1a4bd071cc3b94413043cad2..4fbc3417c03113abc5d4b5fbfee3f087725bab6a 100644 (file)
@@ -314,6 +314,37 @@ GdkWindow *wxChoice::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
     return m_widget->window;
 }
 
+// Notice that this method shouldn't be necessary, because GTK calculates
+// properly size of the combobox but for unknown reasons it doesn't work
+// correctly in wx without this.
+wxSize wxChoice::DoGetBestSize() const
+{
+    // strangely, this returns a width of 188 pixels from GTK+ (?)
+    wxSize ret( wxControl::DoGetBestSize() );
+
+    // we know better our horizontal extent: it depends on the longest string
+    // in the combobox
+    if ( m_widget )
+    {
+        ret.x = 60;  // start with something "sensible"
+        int width;
+        unsigned int count = GetCount();
+        for ( unsigned int n = 0; n < count; n++ )
+        {
+            GetTextExtent(GetString(n), &width, NULL, NULL, NULL );
+            if ( width + 40 > ret.x ) // 40 for drop down arrow and space around text
+                ret.x = width + 40;
+        }
+    }
+
+    // empty combobox should have some reasonable default size too
+    if ((GetCount() == 0) && (ret.x < 80))
+        ret.x = 80;
+
+    CacheBestSize(ret);
+    return ret;
+}
+
 // static
 wxVisualAttributes
 wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))