reworked font handling for osx

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59644 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2009-03-20 13:56:57 +00:00
parent 0cc860a2ab
commit f1c40652a0
19 changed files with 1066 additions and 748 deletions

View File

@@ -65,6 +65,7 @@ enum wxXLFDField
// functions, the user code can only get the objects of this type from // functions, the user code can only get the objects of this type from
// somewhere and pass it somewhere else (possibly save them somewhere using // somewhere and pass it somewhere else (possibly save them somewhere using
// ToString() and restore them using FromString()) // ToString() and restore them using FromString())
class WXDLLIMPEXP_CORE wxNativeFontInfo class WXDLLIMPEXP_CORE wxNativeFontInfo
{ {
public: public:
@@ -113,6 +114,77 @@ public:
FATTRS fa; FATTRS fa;
FONTMETRICS fm; FONTMETRICS fm;
FACENAMEDESC fn; FACENAMEDESC fn;
#elif defined(__WXOSX__)
public:
wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
wxNativeFontInfo( int size,
wxFontFamily family,
wxFontStyle style,
wxFontWeight weight,
bool underlined,
const wxString& faceName,
wxFontEncoding encoding)
{ Init(size,family,style,weight,underlined,faceName,encoding); }
~wxNativeFontInfo() { Free(); }
wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
{
if (this != &info)
{
Free();
Init(info);
}
return *this;
}
#if wxOSX_USE_CORE_TEXT
void Init(CTFontDescriptorRef descr);
#endif
void Init(const wxNativeFontInfo& info);
void Init(int size,
wxFontFamily family,
wxFontStyle style,
wxFontWeight weight,
bool underlined,
const wxString& faceName ,
wxFontEncoding encoding);
void Free();
void EnsureValid();
bool m_descriptorValid;
#if wxOSX_USE_CORE_TEXT
CTFontDescriptorRef m_ctFontDescriptor;
#endif
#if wxOSX_USE_ATSU_TEXT
bool m_atsuFontValid;
// the atsu font ID
wxUint32 m_atsuFontID;
// the qd styles that are not intrinsic to the font above
wxInt16 m_atsuAdditionalQDStyles;
#if wxOSX_USE_CARBON
wxInt16 m_qdFontFamily;
wxInt16 m_qdFontStyle;
#endif
#endif
#if wxOSX_USE_COCOA
WX_NSFontDescriptor m_nsFontDescriptor;
void ValidateNSFontDescriptor();
#endif
#if wxOSX_USE_IPHONE
#endif
int m_pointSize;
wxFontFamily m_family;
wxFontStyle m_style;
wxFontWeight m_weight;
bool m_underlined;
wxString m_faceName;
wxFontEncoding m_encoding;
public :
#else // other platforms #else // other platforms
// //
// This is a generic implementation that should work on all ports // This is a generic implementation that should work on all ports

View File

@@ -726,7 +726,7 @@ private :
void wxMacCocoaRelease( void* obj ); void wxMacCocoaRelease( void* obj );
void wxMacCocoaAutorelease( void* obj ); void wxMacCocoaAutorelease( void* obj );
void wxMacCocoaRetain( void* obj ); void* wxMacCocoaRetain( void* obj );
#endif #endif

View File

@@ -16,6 +16,21 @@
// wxFont // wxFont
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// font styles
enum wxOSXSystemFont
{
wxOSX_SYSTEM_FONT_NONE = 0,
wxOSX_SYSTEM_FONT_NORMAL,
wxOSX_SYSTEM_FONT_BOLD,
wxOSX_SYSTEM_FONT_SMALL,
wxOSX_SYSTEM_FONT_SMALL_BOLD,
wxOSX_SYSTEM_FONT_MINI,
wxOSX_SYSTEM_FONT_MINI_BOLD,
wxOSX_SYSTEM_FONT_LABELS,
wxOSX_SYSTEM_FONT_VIEWS
};
class WXDLLIMPEXP_CORE wxFont : public wxFontBase class WXDLLIMPEXP_CORE wxFont : public wxFontBase
{ {
public: public:
@@ -75,15 +90,8 @@ public:
bool Create(const wxNativeFontInfo& info); bool Create(const wxNativeFontInfo& info);
#if wxOSX_USE_ATSU_TEXT bool CreateSystemFont(wxOSXSystemFont font);
bool MacCreateFromThemeFont( wxUint16 themeFontID ) ;
#endif
#if wxOSX_USE_CORE_TEXT
bool MacCreateFromUIFont( wxUint32 coreTextFontType );
bool MacCreateFromCTFontDescriptor( const void * ctFontDescriptor, int pointSize = 0 );
bool MacCreateFromCTFont( const void * ctFont );
#endif
virtual ~wxFont(); virtual ~wxFont();
// implement base class pure virtuals // implement base class pure virtuals
@@ -118,32 +126,42 @@ public:
// Mac-specific, risks to change, don't use in portable code // Mac-specific, risks to change, don't use in portable code
#if wxOSX_USE_ATSU_TEXT #if wxOSX_USE_CARBON && wxOSX_USE_ATSU_TEXT
wxUint16 MacGetThemeFontID() const ;
// 'old' Quickdraw accessors // 'old' Quickdraw accessors
short MacGetFontNum() const; short MacGetFontNum() const;
short MacGetFontSize() const;
wxByte MacGetFontStyle() const; wxByte MacGetFontStyle() const;
// 'new' ATSUI accessors
wxUint32 MacGetATSUFontID() const;
wxUint32 MacGetATSUAdditionalQDStyles() const;
wxUint16 MacGetThemeFontID() const ;
// Returns an ATSUStyle not ATSUStyle*
#endif #endif
#if wxOSX_USE_COCOA_OR_CARBON
CGFontRef GetCGFont() const;
#endif
#if wxOSX_USE_CORE_TEXT #if wxOSX_USE_CORE_TEXT
const void * MacGetCTFont() const; CTFontRef GetCTFont() const;
#endif #endif
#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT #if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
// Returns an ATSUStyle not ATSUStyle*
void* MacGetATSUStyle() const ; void* MacGetATSUStyle() const ;
#endif #endif
#if wxOSX_USE_COCOA
WX_NSFont GetNSFont() const;
static WX_NSFont CreateNSFont(wxOSXSystemFont font, wxNativeFontInfo* info);
static WX_NSFont CreateNSFont(const wxNativeFontInfo* info);
#endif
#if wxOSX_USE_IPHONE
WX_UIFont GetUIFont() const;
static WX_NSFont CreateUIFont(wxOSXSystemFont font, wxNativeFontInfo* info);
#endif
protected: protected:
virtual wxGDIRefData *CreateGDIRefData() const; virtual wxGDIRefData *CreateGDIRefData() const;
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
private: private:
void Unshare();
DECLARE_DYNAMIC_CLASS(wxFont) DECLARE_DYNAMIC_CLASS(wxFont)
}; };

View File

@@ -586,7 +586,7 @@ void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding_)
// format there anyhow (but there is a well-defined standard for X11 fonts used // format there anyhow (but there is a well-defined standard for X11 fonts used
// by wxGTK and wxMotif) // by wxGTK and wxMotif)
#if defined(wxNO_NATIVE_FONTINFO) || defined(__WXMSW__) || defined (__WXPM__) #if defined(wxNO_NATIVE_FONTINFO) || defined(__WXMSW__) || defined (__WXPM__) || defined(__WXOSX__)
wxString wxNativeFontInfo::ToUserString() const wxString wxNativeFontInfo::ToUserString() const
{ {

View File

@@ -692,7 +692,7 @@ wxCairoFontData::wxCairoFontData( wxGraphicsRenderer* renderer, const wxFont &fo
m_underlined = font.GetUnderlined(); m_underlined = font.GetUnderlined();
#ifdef __WXMAC__ #ifdef __WXMAC__
m_font = cairo_atsui_font_face_create_for_atsu_font_id( font.MacGetATSUFontID() ); m_font = cairo_quartz_font_face_create_for_cgfont( font.GetCGFont() );
#elif defined(__WXGTK__) #elif defined(__WXGTK__)
m_font = pango_font_description_copy( font.GetNativeFontInfo()->description ); m_font = pango_font_description_copy( font.GetNativeFontInfo()->description );
#else #else

View File

@@ -4305,13 +4305,9 @@ void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
wxTAB_TRAVERSAL wxTAB_TRAVERSAL
); );
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON #if defined( __WXMAC__ )
wxFont font; wxFont font;
#if wxOSX_USE_ATSU_TEXT font.CreateSystemFont( wxOSX_SYSTEM_FONT_SMALL );
font.MacCreateFromThemeFont( kThemeSmallSystemFont );
#else
font.MacCreateFromUIFont( kCTFontSystemFontType );
#endif
m_headerWin->SetFont( font ); m_headerWin->SetFont( font );
#endif #endif

View File

@@ -973,11 +973,7 @@ void wxGenericTreeCtrl::Init()
m_lastOnSame = false; m_lastOnSame = false;
#if defined( __WXMAC__ ) #if defined( __WXMAC__ )
#if wxOSX_USE_ATSU_TEXT m_normalFont.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS);
m_normalFont.MacCreateFromThemeFont( kThemeViewsFont ) ;
#else
m_normalFont.MacCreateFromUIFont( kCTFontViewsFontType ) ;
#endif
#else #else
m_normalFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); m_normalFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
#endif #endif

View File

@@ -1043,7 +1043,7 @@ wxVisualAttributes wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant var
attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
//attr.font.MacCreateFromThemeFont(kThemeViewsFont); //attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS);
return attr; return attr;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -41,6 +41,7 @@
#endif #endif
#include "wx/fontdlg.h" #include "wx/fontdlg.h"
#include "wx/fontutil.h"
#if wxOSX_USE_EXPERIMENTAL_FONTDIALOG #if wxOSX_USE_EXPERIMENTAL_FONTDIALOG
@@ -82,7 +83,9 @@ wxMacCarbonFontPanelHandler(EventHandlerCallRef WXUNUSED(nextHandler),
if ( cEvent.GetParameter<CTFontDescriptorRef>( kEventParamCTFontDescriptor, typeCTFontDescriptorRef, &descr ) == noErr ) if ( cEvent.GetParameter<CTFontDescriptorRef>( kEventParamCTFontDescriptor, typeCTFontDescriptorRef, &descr ) == noErr )
{ {
wxFont font; wxFont font;
font.MacCreateFromCTFontDescriptor(descr); wxNativeFontInfo fontinfo;
fontinfo.Init(descr);
font.Create(fontinfo);
fontdata.SetChosenFont( font ) ; fontdata.SetChosenFont( font ) ;
setup = true; setup = true;
} }
@@ -229,7 +232,7 @@ int wxFontDialog::ShowModal()
#if wxOSX_USE_CORE_TEXT #if wxOSX_USE_CORE_TEXT
if ( UMAGetSystemVersion() >= 0x1050 ) if ( UMAGetSystemVersion() >= 0x1050 )
{ {
CTFontDescriptorRef descr = (CTFontDescriptorRef) CTFontCopyFontDescriptor( (CTFontRef) font.MacGetCTFont() ); CTFontDescriptorRef descr = (CTFontDescriptorRef) CTFontCopyFontDescriptor( (CTFontRef) font.GetCTFont() );
err = SetFontInfoForSelection (kFontSelectionCoreTextType,1, &descr , NULL); err = SetFontInfoForSelection (kFontSelectionCoreTextType,1, &descr , NULL);
CFRelease( descr ); CFRelease( descr );
setup = true; setup = true;

View File

@@ -51,9 +51,6 @@ void wxStockGDIMac::OnExit()
{ {
} }
extern wxFont* CreateNormalFont();
extern wxFont* CreateSmallFont();
const wxFont* wxStockGDIMac::GetFont(Item item) const wxFont* wxStockGDIMac::GetFont(Item item)
{ {
wxFont* font = static_cast<wxFont*>(ms_stockObject[item]); wxFont* font = static_cast<wxFont*>(ms_stockObject[item]);
@@ -61,31 +58,14 @@ const wxFont* wxStockGDIMac::GetFont(Item item)
{ {
switch (item) switch (item)
{ {
#if wxOSX_USE_COCOA_OR_CARBON
case FONT_NORMAL: case FONT_NORMAL:
font = new wxFont; font = new wxFont;
#if wxOSX_USE_ATSU_TEXT font->CreateSystemFont(wxOSX_SYSTEM_FONT_NORMAL);
font->MacCreateFromThemeFont(kThemeSystemFont);
#else
font->MacCreateFromUIFont(kCTFontSystemFontType);
#endif
break; break;
case FONT_SMALL: case FONT_SMALL:
font = new wxFont; font = new wxFont;
#if wxOSX_USE_ATSU_TEXT font->CreateSystemFont(wxOSX_SYSTEM_FONT_SMALL);
font->MacCreateFromThemeFont(kThemeSmallSystemFont);
#else
font->MacCreateFromUIFont(kCTFontSmallSystemFontType);
#endif
break; break;
#else
case FONT_NORMAL:
font = CreateNormalFont() ;
break;
case FONT_SMALL:
font = CreateSmallFont();
break;
#endif
default: default:
font = const_cast<wxFont*>(super::GetFont(item)); font = const_cast<wxFont*>(super::GetFont(item));
break; break;

View File

@@ -171,7 +171,7 @@ CGColorRef wxMacCreateCGColor( const wxColour& col )
CTFontRef wxMacCreateCTFont( const wxFont& font ) CTFontRef wxMacCreateCTFont( const wxFont& font )
{ {
#ifdef __WXMAC__ #ifdef __WXMAC__
return wxCFRetain((CTFontRef) font.MacGetCTFont()); return wxCFRetain((CTFontRef) font.GetCTFont());
#else #else
return CTFontCreateWithName( wxCFStringRef( font.GetFaceName(), wxLocale::GetSystemEncoding() ) , font.GetPointSize() , NULL ); return CTFontCreateWithName( wxCFStringRef( font.GetFaceName(), wxLocale::GetSystemEncoding() ) , font.GetPointSize() , NULL );
#endif #endif
@@ -859,7 +859,7 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere
// we need the scale here ... // we need the scale here ...
Fixed atsuSize = IntToFixed( int( 1 * font.MacGetFontSize()) ); Fixed atsuSize = IntToFixed( int( 1 * font.GetPointSize()) );
RGBColor atsuColor ; RGBColor atsuColor ;
col.GetRGBColor( &atsuColor ); col.GetRGBColor( &atsuColor );
ATSUAttributeTag atsuTags[] = ATSUAttributeTag atsuTags[] =

View File

@@ -783,11 +783,7 @@ wxListCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
#if wxOSX_USE_ATSU_TEXT attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS);
attr.font.MacCreateFromThemeFont( kThemeViewsFont ) ;
#else
attr.font.MacCreateFromUIFont( kCTFontViewsFontType ) ;
#endif
return attr; return attr;
} }
@@ -2857,7 +2853,7 @@ void wxMacDataBrowserListCtrlControl::DrawItem(
if (font.Ok()) if (font.Ok())
{ {
info.fontID = kThemeSpecifiedFont; info.fontID = kThemeSpecifiedFont;
info.font = (CTFontRef) font.MacGetCTFont(); info.font = (CTFontRef) font.GetCTFont();
setup = true; setup = true;
} }
} }
@@ -2872,7 +2868,7 @@ void wxMacDataBrowserListCtrlControl::DrawItem(
{ {
info.fontID = font.MacGetThemeFontID(); info.fontID = font.MacGetThemeFontID();
::TextSize( (short)(font.MacGetFontSize()) ) ; ::TextSize( (short)(font.GetPointSize()) ) ;
::TextFace( font.MacGetFontStyle() ) ; ::TextFace( font.MacGetFontStyle() ) ;
} }
} }

View File

@@ -21,6 +21,8 @@
#include "wx/osx/private.h" #include "wx/osx/private.h"
#endif #endif
#include "wx/fontutil.h"
#ifdef __WXMAC__ #ifdef __WXMAC__
#if wxOSX_USE_CARBON #if wxOSX_USE_CARBON
@@ -79,17 +81,113 @@ void wxMacCocoaAutorelease( void* obj )
[(NSObject*)obj autorelease]; [(NSObject*)obj autorelease];
} }
void wxMacCocoaRetain( void* obj ) void* wxMacCocoaRetain( void* obj )
{ {
[(NSObject*)obj retain]; [(NSObject*)obj retain];
return obj;
} }
// ----------------------------------------------------------------------------
// NSFont Utils
// ----------------------------------------------------------------------------
#if wxOSX_USE_COCOA #if wxOSX_USE_COCOA
WX_NSFont wxFont::CreateNSFont(wxOSXSystemFont font, wxNativeFontInfo* info)
{
NSFont* nsfont;
switch( font )
{
case wxOSX_SYSTEM_FONT_NORMAL:
nsfont = [NSFont systemFontOfSize:[NSFont systemFontSize]];
break;
case wxOSX_SYSTEM_FONT_BOLD:
nsfont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]];
break;
case wxOSX_SYSTEM_FONT_SMALL:
nsfont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
break;
case wxOSX_SYSTEM_FONT_SMALL_BOLD:
nsfont = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]];
break;
case wxOSX_SYSTEM_FONT_MINI:
nsfont = [NSFont systemFontOfSize:[NSFont systemFontSize]];
break;
case wxOSX_SYSTEM_FONT_MINI_BOLD:
nsfont = [NSFont boldSystemFontOfSize:
[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
break;
case wxOSX_SYSTEM_FONT_LABELS:
nsfont = [NSFont labelFontOfSize:
[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
break;
case wxOSX_SYSTEM_FONT_VIEWS:
nsfont = [NSFont controlContentFontOfSize:0];
break;
default:
break;
}
[nsfont retain];
NSFontDescriptor*desc = [[nsfont fontDescriptor] retain];
if ( info->m_faceName.empty())
{
wxFontStyle fontstyle = wxFONTSTYLE_NORMAL;
wxFontWeight fontweight = wxFONTWEIGHT_NORMAL;
bool underlined = false;
int size = (int) ([desc pointSize]+0.5);
NSFontSymbolicTraits traits = [desc symbolicTraits];
if ( traits & NSFontBoldTrait )
fontweight = wxFONTWEIGHT_BOLD ;
else
fontweight = wxFONTWEIGHT_NORMAL ;
if ( traits & NSFontItalicTrait )
fontstyle = wxFONTSTYLE_ITALIC ;
wxCFStringRef fontname( [desc postscriptName] );
info->Init(size,wxFONTFAMILY_DEFAULT,fontstyle,fontweight,underlined,
fontname.AsString(), wxFONTENCODING_DEFAULT);
}
info->m_nsFontDescriptor = desc;
return nsfont;
}
void wxNativeFontInfo::ValidateNSFontDescriptor()
{
NSFontDescriptor* desc = [NSFont fontWithName:wxCFStringRef(m_faceName).AsNSString() size:m_pointSize];
NSFontSymbolicTraits traits = 0;
if (m_weight == wxFONTWEIGHT_BOLD)
traits |= NSFontBoldTrait;
if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT)
traits |= NSFontItalicTrait;
if ( traits != 0 )
{
[desc autorelease];
desc = [desc fontDescriptorWithSymbolicTraits:traits];
}
m_nsFontDescriptor = desc;
}
WX_NSFont wxFont::CreateNSFont(const wxNativeFontInfo* info)
{
NSFont* nsFont;
nsFont = [NSFont fontWithDescriptor:info->m_nsFontDescriptor size:info->m_pointSize];
return nsFont;
}
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// NSImage Utils // NSImage Utils
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if wxOSX_USE_COCOA
// From "Cocoa Drawing Guide:Working with Images" // From "Cocoa Drawing Guide:Working with Images"
WX_NSImage wxOSXCreateNSImageFromCGImage( CGImageRef image ) WX_NSImage wxOSXCreateNSImageFromCGImage( CGImageRef image )
{ {

View File

@@ -1228,7 +1228,7 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l
flush = kHIThemeTextHorizontalFlushCenter; flush = kHIThemeTextHorizontalFlushCenter;
else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT ) else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
flush = kHIThemeTextHorizontalFlushRight; flush = kHIThemeTextHorizontalFlushRight;
HIViewSetTextFont( m_controlRef , part , (CTFontRef) font.MacGetCTFont() ); HIViewSetTextFont( m_controlRef , part , (CTFontRef) font.GetCTFont() );
HIViewSetTextHorizontalFlush( m_controlRef, part, flush ); HIViewSetTextHorizontalFlush( m_controlRef, part, flush );
if ( foreground != *wxBLACK || ignoreBlack == false ) if ( foreground != *wxBLACK || ignoreBlack == false )
@@ -1269,7 +1269,7 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l
{ {
fontStyle.font = font.MacGetFontNum(); fontStyle.font = font.MacGetFontNum();
fontStyle.style = font.MacGetFontStyle(); fontStyle.style = font.MacGetFontStyle();
fontStyle.size = font.MacGetFontSize(); fontStyle.size = font.GetPointSize();
fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask; fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask;
} }

View File

@@ -27,14 +27,12 @@
#include <stdio.h> #include <stdio.h>
@interface wxNSStaticTextView : NSTextView @interface wxNSStaticTextView : NSTextField
{ {
wxWidgetCocoaImpl* impl; wxWidgetCocoaImpl* impl;
} }
- (void) setImplementation:(wxWidgetCocoaImpl*) item;
- (wxWidgetCocoaImpl*) implementation;
@end @end
@implementation wxNSStaticTextView @implementation wxNSStaticTextView
+ (void)initialize + (void)initialize
@@ -47,83 +45,46 @@
} }
} }
- (wxWidgetCocoaImpl*) implementation
{
return impl;
}
- (void) setImplementation:(wxWidgetCocoaImpl*) item
{
impl = item;
}
@end @end
class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl class wxStaticTextCocoaImpl : public wxWidgetCocoaImpl
{ {
public: public:
wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w ) : wxWidgetCocoaImpl(peer, w) wxStaticTextCocoaImpl( wxWindowMac* peer , WXWidget w , NSLineBreakMode lineBreak) : wxWidgetCocoaImpl(peer, w)
{ {
m_lineBreak = lineBreak;
} }
virtual void SetLabel(const wxString& title, wxFontEncoding encoding) virtual void SetLabel(const wxString& title, wxFontEncoding encoding)
{ {
wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget(); wxNSStaticTextView* v = (wxNSStaticTextView*)GetWXWidget();
wxWindow* wxpeer = GetWXPeer(); wxWindow* wxpeer = GetWXPeer();
[v setString: wxCFStringRef( title , wxpeer->GetFont().GetEncoding() ).AsNSString()]; NSCell* cell = [v cell];
wxCFStringRef text( title , wxpeer->GetFont().GetEncoding() );
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineBreakMode:m_lineBreak];
int style = wxpeer->GetWindowStyleFlag(); int style = wxpeer->GetWindowStyleFlag();
NSRange allText = NSMakeRange(0, title.length());
if (style & wxALIGN_CENTER) if (style & wxALIGN_CENTER)
[v setAlignment: NSCenterTextAlignment range: allText]; [paragraphStyle setAlignment: NSCenterTextAlignment];
else if (style & wxALIGN_RIGHT) else if (style & wxALIGN_RIGHT)
[v setAlignment: NSRightTextAlignment range: allText]; [paragraphStyle setAlignment: NSRightTextAlignment];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:paragraphStyle, NSParagraphStyleAttributeName, nil];
NSAttributedString *attrstring = [[NSAttributedString alloc] initWithString:text.AsNSString() attributes:dict];
[cell setAttributedStringValue:attrstring];
[attrstring release];
[paragraphStyle release];
} }
private :
NSLineBreakMode m_lineBreak;
}; };
wxSize wxStaticText::DoGetBestSize() const wxSize wxStaticText::DoGetBestSize() const
{ {
Point bounds; return wxWindowMac::DoGetBestSize() ;
#if wxOSX_USE_ATSU_TEXT
OSStatus err = noErr;
wxCFStringRef str( m_label, GetFont().GetEncoding() );
SInt16 baseline;
if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
{
err = GetThemeTextDimensions(
(!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, &baseline );
verify_noerr( err );
}
else
#endif
{
wxClientDC dc(const_cast<wxStaticText*>(this));
wxCoord width, height ;
dc.GetMultiLineTextExtent( m_label , &width, &height);
// FIXME: The calculations returned by this function are too small
// for some strings, so we adjust manually.
bounds.h = width+12;
bounds.v = height+4;
}
if ( m_label.empty() )
bounds.h = 0;
bounds.h += MacGetLeftBorderSize() + MacGetRightBorderSize();
bounds.v += MacGetTopBorderSize() + MacGetBottomBorderSize();
return wxSize( bounds.h, bounds.v );
} }
// for wxST_ELLIPSIZE_* support:
/*
FIXME: UpdateLabel() should be called on size events when wxST_ELLIPSIZE_START is set
to allow correct dynamic ellipsizing of the label
*/
wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
wxWindowMac* parent, wxWindowMac* parent,
wxWindowID id, wxWindowID id,
@@ -139,29 +100,26 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticText( wxWindowMac* wxpeer,
[v setEditable:NO]; [v setEditable:NO];
[v setDrawsBackground:NO]; [v setDrawsBackground:NO];
[v setSelectable: NO]; [v setSelectable: NO];
[v setBezeled:NO];
wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v ); [v setBordered:NO];
return c;
/* NSLineBreakMode linebreak = NSLineBreakByWordWrapping;
Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); if ( ((wxStaticText*)wxpeer)->IsEllipsized() )
wxMacControl* peer = new wxMacControl( wxpeer );
OSStatus err = CreateStaticTextControl(
MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
&bounds, NULL, NULL, peer->GetControlRefAddr() );
verify_noerr( err );
if ( ( style & wxST_ELLIPSIZE_END ) || ( style & wxST_ELLIPSIZE_MIDDLE ) )
{ {
TruncCode tCode = truncEnd;
if ( style & wxST_ELLIPSIZE_MIDDLE ) if ( style & wxST_ELLIPSIZE_MIDDLE )
tCode = truncMiddle; linebreak = NSLineBreakByTruncatingMiddle;
else if (style & wxST_ELLIPSIZE_END )
err = peer->SetData( kControlStaticTextTruncTag, tCode ); linebreak = NSLineBreakByTruncatingTail;
err = peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 ); else if (style & wxST_ELLIPSIZE_START )
linebreak = NSLineBreakByTruncatingHead;
} }
return peer; else
*/ {
[[v cell] setWraps:YES];
}
wxWidgetCocoaImpl* c = new wxStaticTextCocoaImpl( wxpeer, v, linebreak );
return c;
} }
#endif //if wxUSE_STATTEXT #endif //if wxUSE_STATTEXT

View File

@@ -1352,11 +1352,7 @@ void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool) void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
{ {
if ([m_osxView respondsToSelector:@selector(setFont:)]) if ([m_osxView respondsToSelector:@selector(setFont:)])
#if wxOSX_USE_CORE_TEXT [m_osxView setFont: font.GetNSFont()];
[m_osxView setFont: (NSFont*)font.MacGetCTFont()];
#else
#endif
} }
void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control ) void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )

View File

@@ -272,11 +272,7 @@ wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
#if wxOSX_USE_ATSU_TEXT attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS);
attr.font.MacCreateFromThemeFont(kThemeViewsFont);
#else
attr.font.MacCreateFromUIFont(kCTFontViewsFontType);
#endif
return attr; return attr;
} }

View File

@@ -57,7 +57,11 @@ void wxStaticText::SetLabel(const wxString& label)
m_labelOrig = label; m_labelOrig = label;
// middle/end ellipsization is handled by the OS: // middle/end ellipsization is handled by the OS:
if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE) ) if ( HasFlag(wxST_ELLIPSIZE_END) || HasFlag(wxST_ELLIPSIZE_MIDDLE)
#if wxOSX_USE_COCOA // Cocoa has all three modes
|| HasFlag(wxST_ELLIPSIZE_START)
#endif
)
{ {
// remove markup // remove markup
wxString str(label); wxString str(label);