From a5235cf098c871d0e555faca91336f3fad76d0c2 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 16 Nov 2002 21:47:22 +0000 Subject: [PATCH] copied DoGetBestSize from gtk git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17879 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/listbox.cpp | 55 +++++++++++++++++++++++++++++++++++--- src/mac/listbox.cpp | 55 +++++++++++++++++++++++++++++++++++--- 2 files changed, 104 insertions(+), 6 deletions(-) diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index 8f90b0fa4c..1ae079f300 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -259,13 +259,13 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, } SetListSelectionFlags((ListHandle)m_macList, options); - MacPostControlCreate() ; - for ( int i = 0 ; i < n ; i++ ) { Append( choices[i] ) ; } + MacPostControlCreate() ; + LSetDrawingMode( true , (ListHandle)m_macList ) ; return TRUE; @@ -616,7 +616,56 @@ void wxListBox::SetString(int N, const wxString& s) wxSize wxListBox::DoGetBestSize() const { - return wxSize(100, 100); + int lbWidth = 100; // some defaults + int lbHeight = 110; + int wLine; + + { + wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ; + Rect drawRect ; +#if TARGET_CARBON + int sizeFont = 12; + + Str255 fontName ; + SInt16 fontSize ; + Style fontStyle ; + SInt16 fontNum ; + + GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; + GetFNum(fontName , &fontNum ) ; + if ( 1 ) + { + ::TextFont( fontNum ) ; + ::TextSize( fontSize ); + ::TextFace( fontStyle ) ; + } + else + +#endif + { + ::TextFont( kFontIDMonaco ) ; + ::TextSize( 9 ); + ::TextFace( 0 ) ; + } + + // Find the widest line + for(int i = 0; i < GetCount(); i++) { + wxString str(GetString(i)); + wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; + lbWidth = wxMax(lbWidth, wLine); + } + + // Add room for the scrollbar + lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + + // And just a bit more + int cy = 12 ; + + // don't make the listbox too tall (limit height to around 10 items) but don't + // make it too small neither + lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10); + } + return wxSize(lbWidth, lbHeight); } int wxListBox::GetCount() const diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp index 8f90b0fa4c..1ae079f300 100644 --- a/src/mac/listbox.cpp +++ b/src/mac/listbox.cpp @@ -259,13 +259,13 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, } SetListSelectionFlags((ListHandle)m_macList, options); - MacPostControlCreate() ; - for ( int i = 0 ; i < n ; i++ ) { Append( choices[i] ) ; } + MacPostControlCreate() ; + LSetDrawingMode( true , (ListHandle)m_macList ) ; return TRUE; @@ -616,7 +616,56 @@ void wxListBox::SetString(int N, const wxString& s) wxSize wxListBox::DoGetBestSize() const { - return wxSize(100, 100); + int lbWidth = 100; // some defaults + int lbHeight = 110; + int wLine; + + { + wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ; + Rect drawRect ; +#if TARGET_CARBON + int sizeFont = 12; + + Str255 fontName ; + SInt16 fontSize ; + Style fontStyle ; + SInt16 fontNum ; + + GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; + GetFNum(fontName , &fontNum ) ; + if ( 1 ) + { + ::TextFont( fontNum ) ; + ::TextSize( fontSize ); + ::TextFace( fontStyle ) ; + } + else + +#endif + { + ::TextFont( kFontIDMonaco ) ; + ::TextSize( 9 ); + ::TextFace( 0 ) ; + } + + // Find the widest line + for(int i = 0; i < GetCount(); i++) { + wxString str(GetString(i)); + wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; + lbWidth = wxMax(lbWidth, wLine); + } + + // Add room for the scrollbar + lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + + // And just a bit more + int cy = 12 ; + + // don't make the listbox too tall (limit height to around 10 items) but don't + // make it too small neither + lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10); + } + return wxSize(lbWidth, lbHeight); } int wxListBox::GetCount() const