- {
- wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ;
-
- wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
-
- if ( font )
- {
- ::TextFont( font->m_macFontNum ) ;
- ::TextSize( short(font->m_macFontSize) ) ;
- ::TextFace( font->m_macFontStyle ) ;
- }
- else
- {
- ::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 ;
- int cx = ::TextWidth( "X" , 0 , 1 ) ;
- lbWidth += cx ;
-
- // 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);
+ {
+ wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef)MacGetTopLevelWindowRef() ) ) ;
+
+ // TODO: clean this up
+ if ( m_font.Ok() )
+ {
+ ::TextFont( m_font.MacGetFontNum() ) ;
+ ::TextSize( m_font.MacGetFontSize() ) ;
+ ::TextFace( m_font.MacGetFontStyle() ) ;
+ }
+ else
+ {
+ ::TextFont( kFontIDMonaco ) ;
+ ::TextSize( 9 );
+ ::TextFace( 0 ) ;
+ }
+
+ // Find the widest line
+ for (int i = 0; i < GetCount(); i++)
+ {
+ wxString str( GetString( i ) );
+
+#if wxUSE_UNICODE
+ Point bounds = {0, 0} ;
+ SInt16 baseline ;
+
+ // NB: what if m_font.Ok() == false ???
+ ::GetThemeTextDimensions(
+ wxMacCFStringHolder( str , m_font.GetEncoding() ) ,
+ kThemeCurrentPortFont,
+ kThemeStateActive,
+ false,
+ &bounds,
+ &baseline );
+ wLine = bounds.h ;
+#else
+ wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ;
+#endif
+
+ lbWidth = wxMax( lbWidth, wLine );
+ }
+
+ // Add room for the scrollbar
+ lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
+
+ // And just a bit more
+ int cy = 12 ;
+ int cx = ::TextWidth( "X" , 0 , 1 ) ;
+ lbWidth += cx ;
+
+ // 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 );