From: Stefan Csomor Date: Mon, 21 Jun 2010 14:00:59 +0000 (+0000) Subject: adding bestsize for osx_cocoa combobox X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5bd77105934934cf38145e036d7072c2ca0b0456 adding bestsize for osx_cocoa combobox git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64668 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/combobox.h b/include/wx/osx/combobox.h index 81be73fbb4..ca2d448cd6 100644 --- a/include/wx/osx/combobox.h +++ b/include/wx/osx/combobox.h @@ -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 diff --git a/src/osx/cocoa/combobox.mm b/src/osx/cocoa/combobox.mm index a6c9e9b7c4..16876eef2e 100644 --- a/src/osx/cocoa/combobox.mm +++ b/src/osx/cocoa/combobox.mm @@ -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(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