switched drawing algorithm, since apparently DrawThemeTextBox has some problems not squeezing the text under certain OS versions. also added the OS Truncating algorithm which does add ellipsis (...) when the text does not fit

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17962 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2002-11-24 17:03:35 +00:00
parent 50c7b3cd58
commit 4d9bcf27a8
2 changed files with 124 additions and 80 deletions

View File

@@ -105,16 +105,34 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
ClipRect( drawRect ); ClipRect( drawRect );
EraseRect( drawRect ); EraseRect( drawRect );
wxFontRefData * font = (wxFontRefData*) list->GetFont().GetRefData() ;
if ( font )
{
::TextFont( font->m_macFontNum ) ;
::TextSize( short(font->m_macFontSize) ) ;
::TextFace( font->m_macFontStyle ) ;
}
else
{
::TextFont( kFontIDMonaco ) ;
::TextSize( 9 );
::TextFace( 0 ) ;
}
#if TARGET_CARBON #if TARGET_CARBON
bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ; bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ;
if ( useDrawThemeText ) if ( useDrawThemeText )
{ {
Rect frame = { drawRect->top, drawRect->left + 4, Rect frame = { drawRect->top, drawRect->left + 4,
drawRect->top + kwxMacListItemHeight, drawRect->right} ; drawRect->top + kwxMacListItemHeight, drawRect->right + 10000 } ;
CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text.c_str(), text.Length(), CFStringGetSystemEncoding(), false ) ; CFStringRef sString = CFStringCreateWithBytes( NULL , (UInt8*) text.c_str(), text.Length(), CFStringGetSystemEncoding(), false ) ;
CFMutableStringRef mString = CFStringCreateMutableCopy( NULL , 0 , sString ) ;
CFRelease( sString ) ;
::TruncateThemeText( mString , kThemeCurrentPortFont, kThemeStateActive, drawRect->right - drawRect->left , truncEnd , NULL ) ;
::DrawThemeTextBox( mString, ::DrawThemeTextBox( mString,
kThemeViewsFont, kThemeCurrentPortFont,
kThemeStateActive, kThemeStateActive,
false, false,
&frame, &frame,
@@ -126,9 +144,6 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
#endif #endif
{ {
MoveTo(drawRect->left + 4 , drawRect->top + 10 ); MoveTo(drawRect->left + 4 , drawRect->top + 10 );
::TextFont( kFontIDMonaco ) ;
::TextSize( 9 );
::TextFace( 0 ) ;
DrawText(text, 0 , text.Length()); DrawText(text, 0 , text.Length());
} }
@@ -206,6 +221,19 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
} }
listDef.u.userProc = macListDefUPP ; listDef.u.userProc = macListDefUPP ;
Str255 fontName ;
SInt16 fontSize ;
Style fontStyle ;
SInt16 fontNum ;
#if TARGET_CARBON
GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
#else
GetFontName( kFontIDMonaco , fontName ) ;
fontSize = 9 ;
fontStyle = normal ;
#endif
CopyPascalStringToC( fontName , (char*) fontName ) ;
SetFont( wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , fontName ) ) ;
#if TARGET_CARBON #if TARGET_CARBON
Size asize; Size asize;
@@ -623,47 +651,40 @@ wxSize wxListBox::DoGetBestSize() const
{ {
wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ; wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ;
Rect drawRect ; Rect drawRect ;
#if TARGET_CARBON
int sizeFont = 12;
Str255 fontName ; wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
SInt16 fontSize ;
Style fontStyle ;
SInt16 fontNum ;
GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; if ( font )
GetFNum(fontName , &fontNum ) ; {
if ( 1 ) ::TextFont( font->m_macFontNum ) ;
{ ::TextSize( short(font->m_macFontSize) ) ;
::TextFont( fontNum ) ; ::TextFace( font->m_macFontStyle ) ;
::TextSize( fontSize ); }
::TextFace( fontStyle ) ; else
} {
else
#endif
{
::TextFont( kFontIDMonaco ) ; ::TextFont( kFontIDMonaco ) ;
::TextSize( 9 ); ::TextSize( 9 );
::TextFace( 0 ) ; ::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);
} }
// Find the widest line // Add room for the scrollbar
for(int i = 0; i < GetCount(); i++) { lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
wxString str(GetString(i));
wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ;
lbWidth = wxMax(lbWidth, wLine);
}
// Add room for the scrollbar // And just a bit more
lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); int cy = 12 ;
int cx = ::TextWidth( "X" , 0 , 1 ) ;
// And just a bit more lbWidth += cx ;
int cy = 12 ;
// don't make the listbox too tall (limit height to around 10 items) but don't
// don't make the listbox too tall (limit height to around 10 items) but don't // make it too small neither
// make it too small neither lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10);
lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10);
} }
return wxSize(lbWidth, lbHeight); return wxSize(lbWidth, lbHeight);
} }
@@ -710,6 +731,7 @@ wxOwnerDrawn *wxListBox::CreateItem(size_t n)
// list box control implementation // list box control implementation
// ============================================================================ // ============================================================================
/*
void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
{ {
wxListBox* list; wxListBox* list;
@@ -724,7 +746,7 @@ void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refC
DrawText(text, 0 , text.Length()); DrawText(text, 0 , text.Length());
} }
*/
void wxListBox::MacDelete( int N ) void wxListBox::MacDelete( int N )
{ {
LDelRow( 1 , N , (ListHandle)m_macList) ; LDelRow( 1 , N , (ListHandle)m_macList) ;

View File

@@ -105,16 +105,34 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
ClipRect( drawRect ); ClipRect( drawRect );
EraseRect( drawRect ); EraseRect( drawRect );
wxFontRefData * font = (wxFontRefData*) list->GetFont().GetRefData() ;
if ( font )
{
::TextFont( font->m_macFontNum ) ;
::TextSize( short(font->m_macFontSize) ) ;
::TextFace( font->m_macFontStyle ) ;
}
else
{
::TextFont( kFontIDMonaco ) ;
::TextSize( 9 );
::TextFace( 0 ) ;
}
#if TARGET_CARBON #if TARGET_CARBON
bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ; bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ;
if ( useDrawThemeText ) if ( useDrawThemeText )
{ {
Rect frame = { drawRect->top, drawRect->left + 4, Rect frame = { drawRect->top, drawRect->left + 4,
drawRect->top + kwxMacListItemHeight, drawRect->right} ; drawRect->top + kwxMacListItemHeight, drawRect->right + 10000 } ;
CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text.c_str(), text.Length(), CFStringGetSystemEncoding(), false ) ; CFStringRef sString = CFStringCreateWithBytes( NULL , (UInt8*) text.c_str(), text.Length(), CFStringGetSystemEncoding(), false ) ;
CFMutableStringRef mString = CFStringCreateMutableCopy( NULL , 0 , sString ) ;
CFRelease( sString ) ;
::TruncateThemeText( mString , kThemeCurrentPortFont, kThemeStateActive, drawRect->right - drawRect->left , truncEnd , NULL ) ;
::DrawThemeTextBox( mString, ::DrawThemeTextBox( mString,
kThemeViewsFont, kThemeCurrentPortFont,
kThemeStateActive, kThemeStateActive,
false, false,
&frame, &frame,
@@ -126,9 +144,6 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
#endif #endif
{ {
MoveTo(drawRect->left + 4 , drawRect->top + 10 ); MoveTo(drawRect->left + 4 , drawRect->top + 10 );
::TextFont( kFontIDMonaco ) ;
::TextSize( 9 );
::TextFace( 0 ) ;
DrawText(text, 0 , text.Length()); DrawText(text, 0 , text.Length());
} }
@@ -206,6 +221,19 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
} }
listDef.u.userProc = macListDefUPP ; listDef.u.userProc = macListDefUPP ;
Str255 fontName ;
SInt16 fontSize ;
Style fontStyle ;
SInt16 fontNum ;
#if TARGET_CARBON
GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
#else
GetFontName( kFontIDMonaco , fontName ) ;
fontSize = 9 ;
fontStyle = normal ;
#endif
CopyPascalStringToC( fontName , (char*) fontName ) ;
SetFont( wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , fontName ) ) ;
#if TARGET_CARBON #if TARGET_CARBON
Size asize; Size asize;
@@ -623,47 +651,40 @@ wxSize wxListBox::DoGetBestSize() const
{ {
wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ; wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ;
Rect drawRect ; Rect drawRect ;
#if TARGET_CARBON
int sizeFont = 12;
Str255 fontName ; wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
SInt16 fontSize ;
Style fontStyle ;
SInt16 fontNum ;
GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; if ( font )
GetFNum(fontName , &fontNum ) ; {
if ( 1 ) ::TextFont( font->m_macFontNum ) ;
{ ::TextSize( short(font->m_macFontSize) ) ;
::TextFont( fontNum ) ; ::TextFace( font->m_macFontStyle ) ;
::TextSize( fontSize ); }
::TextFace( fontStyle ) ; else
} {
else
#endif
{
::TextFont( kFontIDMonaco ) ; ::TextFont( kFontIDMonaco ) ;
::TextSize( 9 ); ::TextSize( 9 );
::TextFace( 0 ) ; ::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);
} }
// Find the widest line // Add room for the scrollbar
for(int i = 0; i < GetCount(); i++) { lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
wxString str(GetString(i));
wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ;
lbWidth = wxMax(lbWidth, wLine);
}
// Add room for the scrollbar // And just a bit more
lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); int cy = 12 ;
int cx = ::TextWidth( "X" , 0 , 1 ) ;
// And just a bit more lbWidth += cx ;
int cy = 12 ;
// don't make the listbox too tall (limit height to around 10 items) but don't
// don't make the listbox too tall (limit height to around 10 items) but don't // make it too small neither
// make it too small neither lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10);
lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10);
} }
return wxSize(lbWidth, lbHeight); return wxSize(lbWidth, lbHeight);
} }
@@ -710,6 +731,7 @@ wxOwnerDrawn *wxListBox::CreateItem(size_t n)
// list box control implementation // list box control implementation
// ============================================================================ // ============================================================================
/*
void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
{ {
wxListBox* list; wxListBox* list;
@@ -724,7 +746,7 @@ void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refC
DrawText(text, 0 , text.Length()); DrawText(text, 0 , text.Length());
} }
*/
void wxListBox::MacDelete( int N ) void wxListBox::MacDelete( int N )
{ {
LDelRow( 1 , N , (ListHandle)m_macList) ; LDelRow( 1 , N , (ListHandle)m_macList) ;