]> git.saurik.com Git - wxWidgets.git/commitdiff
adding bestsize for osx_cocoa combobox
authorStefan Csomor <csomor@advancedconcepts.ch>
Mon, 21 Jun 2010 14:00:59 +0000 (14:00 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Mon, 21 Jun 2010 14:00:59 +0000 (14:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64668 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/combobox.h
src/osx/cocoa/combobox.mm

index 81be73fbb4b266b869c8967892cd16f8ddef9bc5..ca2d448cd69ac4894b4e73d35f3a52cf5efb50e8 100644 (file)
@@ -165,9 +165,9 @@ protected:
 #endif
     virtual wxWindow *GetEditableWindow() { return this; }
 
-#if wxOSX_USE_CARBON
     // override the base class virtuals involved in geometry calculations
     virtual wxSize DoGetBestSize() const;
+#if wxOSX_USE_CARBON
     virtual void DoMoveWindow(int x, int y, int width, int height);
 #endif
 
index a6c9e9b7c47883a0898f0ff3f3ba24a18a6b4bc3..16876eef2e568f288450c9ba188c45582b392d32 100644 (file)
@@ -154,4 +154,33 @@ wxWidgetImplType* wxWidgetImpl::CreateComboBox( wxWindowMac* wxpeer,
     return c;
 }
 
+wxSize wxComboBox::DoGetBestSize() const
+{
+    int lbWidth = GetCount() > 0 ? 20 : 100;  // some defaults
+    wxSize baseSize = wxWindow::DoGetBestSize();
+    int lbHeight = baseSize.y;
+    int wLine;
+    
+    {
+        wxClientDC dc(const_cast<wxComboBox*>(this));
+        
+        // Find the widest line
+        for(unsigned int i = 0; i < GetCount(); i++)
+        {
+            wxString str(GetString(i));
+            
+            wxCoord width, height ;
+            dc.GetTextExtent( str , &width, &height);
+            wLine = width ;
+            
+            lbWidth = wxMax( lbWidth, wLine ) ;
+        }
+        
+        // Add room for the popup arrow
+        lbWidth += 2 * lbHeight ;
+    }
+    
+    return wxSize( lbWidth, lbHeight );
+}
+
 #endif // wxUSE_COMBOBOX
\ No newline at end of file