X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b7047aa5cbf974ebcf004df7b9b57bc35295032d..5fc01d1326a34223746546326a7f616df8bfa991:/src/mac/carbon/dc.cpp diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp index a07b02f6df..49de162c0a 100644 --- a/src/mac/carbon/dc.cpp +++ b/src/mac/carbon/dc.cpp @@ -28,10 +28,10 @@ using namespace std ; #endif #include "wx/mac/private.h" -#include "ATSUnicode.h" -#include "TextCommon.h" -#include "TextEncodingConverter.h" -#include "FixMath.h" +#include +#include +#include +#include #if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) #endif @@ -55,6 +55,11 @@ const double RAD2DEG = 180.0 / M_PI; const short kEmulatedMode = -1 ; const short kUnsupportedMode = -2 ; +extern TECObjectRef s_TECNativeCToUnicode ; + +// set to 0 if problems arise +#define wxMAC_EXPERIMENTAL_DC 1 + wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) : m_ph( (GrafPtr) dc->m_macPort ) { @@ -62,53 +67,86 @@ wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) : m_dc = dc ; dc->MacSetupPort(&m_ph) ; } - wxMacPortSetter::~wxMacPortSetter() { m_dc->MacCleanupPort(&m_ph) ; } -wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) +#if wxMAC_EXPERIMENTAL_DC +class wxMacFastPortSetter { +public : + wxMacFastPortSetter( const wxDC *dc ) + { + wxASSERT( dc->Ok() ) ; + GetPort( &m_oldPort ) ; + SetPort( (GrafPtr) dc->m_macPort ) ; + m_clipRgn = NewRgn() ; + GetClip( m_clipRgn ) ; + m_dc = dc ; + dc->MacSetupPort( NULL ) ; + } + ~wxMacFastPortSetter() + { + SetPort( (GrafPtr) m_dc->m_macPort ) ; + SetClip( m_clipRgn ) ; + SetPort( m_oldPort ) ; + m_dc->MacCleanupPort( NULL ) ; + DisposeRgn( m_clipRgn ) ; + } +private : + RgnHandle m_clipRgn ; + GrafPtr m_oldPort ; + const wxDC* m_dc ; +} ; + +#else +typedef wxMacPortSetter wxMacFastPortSetter ; +#endif + +wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) : + wxMacPortSaver( (GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) ) +{ + m_newPort =(GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) ; m_formerClip = NewRgn() ; m_newClip = NewRgn() ; GetClip( m_formerClip ) ; if ( win ) { -#if 0 - // this clipping area was set to the parent window's drawing area, lead to problems - // with MacOSX controls drawing outside their wx' rectangle - RgnHandle insidergn = NewRgn() ; - int x = 0 , y = 0; - wxWindow *parent = win->GetParent() ; - parent->MacWindowToRootWindow( &x,&y ) ; - wxSize size = parent->GetSize() ; - SetRectRgn( insidergn , parent->MacGetLeftBorderSize() , parent->MacGetTopBorderSize() , - size.x - parent->MacGetRightBorderSize(), - size.y - parent->MacGetBottomBorderSize()) ; - CopyRgn( (RgnHandle) parent->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip ) ; - SectRgn( m_newClip , insidergn , m_newClip ) ; - OffsetRgn( m_newClip , x , y ) ; - SetClip( m_newClip ) ; - DisposeRgn( insidergn ) ; -#else int x = 0 , y = 0; win->MacWindowToRootWindow( &x,&y ) ; - CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion().GetWXHRGN() , m_newClip ) ; - OffsetRgn( m_newClip , x , y ) ; + // get area including focus rect + CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip ) ; + if ( !EmptyRgn( m_newClip ) ) + OffsetRgn( m_newClip , x , y ) ; + SetClip( m_newClip ) ; -#endif } } wxMacWindowClipper::~wxMacWindowClipper() { + SetPort( m_newPort ) ; SetClip( m_formerClip ) ; DisposeRgn( m_newClip ) ; DisposeRgn( m_formerClip ) ; } +wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow* win ) : + wxMacWindowClipper( win ) +{ + // the port is already set at this point + m_newPort =(GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) ; + GetThemeDrawingState( &m_themeDrawingState ) ; +} + +wxMacWindowStateSaver::~wxMacWindowStateSaver() +{ + SetPort( m_newPort ) ; + SetThemeDrawingState( m_themeDrawingState , true ) ; +} + //----------------------------------------------------------------------------- // Local functions //----------------------------------------------------------------------------- @@ -263,11 +301,12 @@ void wxDC::MacSetupPort(wxMacPortStateHelper* help) const m_macCurrentPortStateHelper = help ; #endif SetClip( (RgnHandle) m_macCurrentClipRgn); +#if ! wxMAC_EXPERIMENTAL_DC m_macFontInstalled = false ; m_macBrushInstalled = false ; m_macPenInstalled = false ; +#endif } - void wxDC::MacCleanupPort(wxMacPortStateHelper* help) const { #ifdef __WXDEBUG__ @@ -304,7 +343,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask { wxCHECK_RET( Ok(), wxT("invalid window dc") ); wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; wxCoord xx = XLOG2DEVMAC(x); wxCoord yy = YLOG2DEVMAC(y); wxCoord w = bmp.GetWidth(); @@ -428,7 +467,7 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) DestroyClippingRegion(); return; } - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; wxCoord x, y, w, h; region.GetBox( x, y, w, h ); wxCoord xx, yy, ww, hh; @@ -470,7 +509,7 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) void wxDC::DestroyClippingRegion() { - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; m_clipping = FALSE; } @@ -556,20 +595,6 @@ void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) ComputeScaleAndOrigin(); } -#if 0 -void wxDC::SetInternalDeviceOrigin( long x, long y ) -{ - m_internalDeviceOriginX = x; - m_internalDeviceOriginY = y; - ComputeScaleAndOrigin(); -} -void wxDC::GetInternalDeviceOrigin( long *x, long *y ) -{ - if (x) *x = m_internalDeviceOriginX; - if (y) *y = m_internalDeviceOriginY; -} -#endif - void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { m_signX = (xLeftRight ? 1 : -1); @@ -675,7 +700,7 @@ bool wxDC::DoFloodFill(wxCoord x, wxCoord y, bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const { wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") ); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; RGBColor colour; GetCPixel( XLOG2DEVMAC(x), YLOG2DEVMAC(y), &colour ); // Convert from Mac colour to wx @@ -688,7 +713,7 @@ bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; if (m_pen.GetStyle() != wxTRANSPARENT) { MacInstallPen() ; @@ -726,7 +751,7 @@ void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) void wxDC::DoCrossHair( wxCoord x, wxCoord y ) { wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") ); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; if (m_pen.GetStyle() != wxTRANSPARENT) { int w = 0; @@ -766,7 +791,7 @@ void wxDC::DoDrawArc( wxCoord x1, wxCoord y1, wxCoord xc, wxCoord yc ) { wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; wxCoord xx1 = XLOG2DEVMAC(x1); wxCoord yy1 = YLOG2DEVMAC(y1); wxCoord xx2 = XLOG2DEVMAC(x2); @@ -816,7 +841,7 @@ void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea ) { wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; Rect r; double angle = sa - ea; // Order important Mac in opposite direction to wx // we have to make sure that the filling is always counter-clockwise @@ -847,7 +872,7 @@ void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, void wxDC::DoDrawPoint( wxCoord x, wxCoord y ) { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; if (m_pen.GetStyle() != wxTRANSPARENT) { wxCoord xx1 = XLOG2DEVMAC(x); @@ -862,7 +887,7 @@ void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; if (m_pen.GetStyle() == wxTRANSPARENT) return; MacInstallPen() ; @@ -885,7 +910,7 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[], int fillStyle ) { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; wxCoord x1, x2 , y1 , y2 ; if ( m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) return ; @@ -921,7 +946,7 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[], void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; wxCoord xx = XLOG2DEVMAC(x); wxCoord yy = YLOG2DEVMAC(y); wxCoord ww = m_signX * XLOG2DEVREL(width); @@ -958,7 +983,7 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, double radius) { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; if (radius < 0.0) radius = - radius * ((width < height) ? width : height); wxCoord xx = XLOG2DEVMAC(x); @@ -995,7 +1020,7 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; wxCoord xx = XLOG2DEVMAC(x); wxCoord yy = YLOG2DEVMAC(y); wxCoord ww = m_signX * XLOG2DEVREL(width); @@ -1124,7 +1149,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ; if ( LockPixels(bmappixels) ) { - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; if ( source->GetDepth() == 1 ) { RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ; @@ -1297,7 +1322,7 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, double angle) { wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") ); - +/* if (angle == 0.0 ) { DrawText(str, x, y); @@ -1306,15 +1331,14 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, if ( str.Length() == 0 ) return ; - - wxMacPortSetter helper(this) ; +*/ + wxMacFastPortSetter helper(this) ; MacInstallFont() ; - wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; if ( 0 ) { m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize); - SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * font->m_macFontSize)); + SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * m_font.MacGetFontSize())); m_macAliasWasEnabled = true ; } OSStatus status = noErr ; @@ -1324,24 +1348,9 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.Length() , str.Length() , 1 , &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; #else - TECObjectRef ec; - status = TECCreateConverter(&ec, - wxApp::s_macDefaultEncodingIsPC - ? (int)kTextEncodingWindowsLatin1 - : (int)kTextEncodingMacRoman, - kTextEncodingUnicodeDefault); - - wxASSERT_MSG( status == noErr , wxT("couldn't start converter") ) ; - ByteCount byteOutLen ; - ByteCount byteInLen = str.Length() ; - ByteCount byteBufferLen = byteInLen *2 ; - char* buf = new char[byteBufferLen] ; - status = TECConvertText(ec, (ConstTextPtr)str.c_str() , byteInLen, &byteInLen, - (TextPtr)buf, byteBufferLen, &byteOutLen); - wxASSERT_MSG( status == noErr , wxT("couldn't convert text") ) ; - status = TECDisposeConverter(ec); - wxASSERT_MSG( status == noErr , wxT("couldn't dispose converter") ) ; - status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 , + wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; + int wlen = wxWcslen( wchar.data() ) ; + status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) wchar.data() , 0 , wlen , wlen , 1 , &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; #endif wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") ); @@ -1389,17 +1398,13 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) ); CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) ); ::ATSUDisposeTextLayout(atsuLayout); -#if wxUSE_UNICODE -#else - delete[] buf ; -#endif } void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) { wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; long xx = XLOG2DEVMAC(x); long yy = YLOG2DEVMAC(y); #if TARGET_CARBON @@ -1429,64 +1434,14 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) { ::TextMode( srcCopy ) ; } - int length = strtext.Length() ; - - int laststop = 0 ; - int i = 0 ; int line = 0 ; { - while( i < length ) - { - if( strtext[i] == 13 || strtext[i] == 10) - { - wxString linetext = strtext.Mid( laststop , i - laststop ) ; -#if TARGET_CARBON - if ( useDrawThemeText ) - { - Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ; - wxMacCFStringHolder mString( linetext ) ; - if ( m_backgroundMode != wxTRANSPARENT ) - { - Point bounds={0,0} ; - Rect background = frame ; - SInt16 baseline ; - ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, - kThemeStateActive, - false, - &bounds, - &baseline ); - background.right = background.left + bounds.h ; - background.bottom = background.top + bounds.v ; - ::EraseRect( &background ) ; - } - ::DrawThemeTextBox( mString, - kThemeCurrentPortFont, - kThemeStateActive, - false, - &frame, - teJustLeft, - nil ); - line++ ; - } - else -#endif - { - wxCharBuffer text = wxMacStringToCString(linetext) ; - ::DrawText( text , 0 , strlen(text) ) ; - line++ ; - ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) ); - } - laststop = i+1 ; - } - i++ ; - } - wxString linetext = strtext.Mid( laststop , i - laststop ) ; + wxString linetext = strtext ; #if TARGET_CARBON if ( useDrawThemeText ) { Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ; - wxMacCFStringHolder mString( linetext ) ; + wxMacCFStringHolder mString( linetext , m_font.GetEncoding()) ; if ( m_backgroundMode != wxTRANSPARENT ) { @@ -1494,7 +1449,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) Rect background = frame ; SInt16 baseline ; ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, + m_font.MacGetThemeFontID() , kThemeStateActive, false, &bounds, @@ -1504,7 +1459,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) ::EraseRect( &background ) ; } ::DrawThemeTextBox( mString, - kThemeCurrentPortFont, + m_font.MacGetThemeFontID() , kThemeStateActive, false, &frame, @@ -1514,7 +1469,15 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) else #endif { - wxCharBuffer text = wxMacStringToCString(linetext) ; + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; + if ( m_backgroundMode != wxTRANSPARENT ) + { + Rect frame = { yy - fi.ascent + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy - fi.ascent + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ; + short width = ::TextWidth( text , 0 , strlen(text) ) ; + frame.right = frame.left + width ; + + ::EraseRect( &frame ) ; + } ::DrawText( text , 0 , strlen(text) ) ; } } @@ -1532,7 +1495,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h wxFont *theFont ) const { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; wxFont formerFont = m_font ; if ( theFont ) { @@ -1553,71 +1516,21 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h *descent =YDEV2LOGREL( fi.descent ); if ( externalLeading ) *externalLeading = YDEV2LOGREL( fi.leading ) ; - int length = strtext.Length() ; - /* - const char *text = NULL ; - wxString macText ; - if ( wxApp::s_macDefaultEncodingIsPC ) - { - macText = wxMacMakeMacStringFromPC( string ) ; - text = macText ; - length = macText.Length() ; - } - else - { - text = string ; - length = string.Length() ; - } - */ - int laststop = 0 ; - int i = 0 ; + int curwidth = 0 ; if ( width ) { *width = 0 ; - while( i < length ) - { - if( strtext[i] == 13 || strtext[i] == 10) - { - wxString linetext = strtext.Mid( laststop , i - laststop ) ; - if ( height ) - *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; -#if TARGET_CARBON - if ( useGetThemeText ) - { - Point bounds={0,0} ; - SInt16 baseline ; - wxMacCFStringHolder mString( linetext ) ; - ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, - kThemeStateActive, - false, - &bounds, - &baseline ); - curwidth = bounds.h ; - } - else -#endif - { - wxCharBuffer text = wxMacStringToCString(linetext) ; - curwidth = ::TextWidth( text , 0 , strlen(text) ) ; - } - if ( curwidth > *width ) - *width = XDEV2LOGREL( curwidth ) ; - laststop = i+1 ; - } - i++ ; - } - - wxString linetext = strtext.Mid( laststop , i - laststop ) ; -#if TARGET_CARBON + wxString linetext = strtext ; + if ( useGetThemeText ) { Point bounds={0,0} ; SInt16 baseline ; - wxMacCFStringHolder mString( linetext ) ; + wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ; + ThemeFontID themeFont = m_font.MacGetThemeFontID() ; ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, + themeFont , kThemeStateActive, false, &bounds, @@ -1625,9 +1538,8 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h curwidth = bounds.h ; } else -#endif { - wxCharBuffer text = wxMacStringToCString(linetext) ; + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; curwidth = ::TextWidth( text , 0 , strlen(text) ) ; } if ( curwidth > *width ) @@ -1641,10 +1553,72 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h } } + +bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const +{ + wxCHECK_MSG(Ok(), false, wxT("Invalid DC")); + + widths.Empty(); + widths.Add(0, text.Length()); + + if (text.Length() == 0) + return false; + + wxMacFastPortSetter helper(this) ; + MacInstallFont() ; +#if TARGET_CARBON + bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ; + if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() ) + useGetThemeText = false ; + + if ( useGetThemeText ) + { + // If anybody knows how to do this more efficiently yet still handle + // the fractional glyph widths that may be present when using AA + // fonts, please change it. Currently it is measuring from the + // begining of the string for each succeding substring, which is much + // slower than this should be. + for (size_t i=0; iGetNoAntiAliasing() ) useGetThemeText = false ; #endif - char text[] = "H" ; + char text[] = "g" ; #if TARGET_CARBON if ( useGetThemeText ) { @@ -1660,7 +1634,7 @@ wxCoord wxDC::GetCharWidth(void) const SInt16 baseline ; CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text , 1 , CFStringGetSystemEncoding(), false ) ; ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, + m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, @@ -1679,7 +1653,7 @@ wxCoord wxDC::GetCharWidth(void) const wxCoord wxDC::GetCharHeight(void) const { wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; MacInstallFont() ; FontInfo fi ; ::GetFontInfo( &fi ) ; @@ -1689,12 +1663,11 @@ wxCoord wxDC::GetCharHeight(void) const void wxDC::Clear(void) { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; Rect rect = { -31000 , -31000 , 31000 , 31000 } ; - if (m_backgroundBrush.GetStyle() != wxTRANSPARENT) + if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT) { ::PenNormal() ; - //MacInstallBrush() ; MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ; ::EraseRect( &rect ) ; } @@ -1707,12 +1680,11 @@ void wxDC::MacInstallFont() const // return ; Pattern blackColor ; MacSetupBackgroundForCurrentPort(m_backgroundBrush) ; - wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; - if ( font ) + if ( m_font.Ok() ) { - ::TextFont( font->m_macFontNum ) ; - ::TextSize( short(m_scaleY * font->m_macFontSize) ) ; - ::TextFace( font->m_macFontStyle ) ; + ::TextFont( m_font.MacGetFontNum() ) ; + ::TextSize( (short)(m_scaleY * m_font.MacGetFontSize()) ) ; + ::TextFace( m_font.MacGetFontStyle() ) ; m_macFontInstalled = true ; m_macBrushInstalled = false ; m_macPenInstalled = false ; @@ -1781,9 +1753,9 @@ void wxDC::MacInstallFont() const } ::PenMode( mode ) ; OSStatus status = noErr ; - Fixed atsuSize = IntToFixed( int(m_scaleY * font->m_macFontSize) ) ; - Style qdStyle = font->m_macFontStyle ; - ATSUFontID atsuFont = font->m_macATSUFontID ; + Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.MacGetFontSize()) ) ; + Style qdStyle = m_font.MacGetATSUAdditionalQDStyles() ; + ATSUFontID atsuFont = m_font.MacGetATSUFontID() ; status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUIStyle) ; wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ) ; ATSUAttributeTag atsuTags[] = @@ -1836,18 +1808,18 @@ void wxDC::MacInstallFont() const Pattern gPatterns[] = { // hatch patterns - { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } , - { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } , - { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } , - { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } , - { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } , - { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } , - { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } , + { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } , + { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } , + { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } , + { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } , + { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } , + { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } , + { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } , // dash patterns - { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } , // DOT - { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } , // LONG_DASH - { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } , // SHORT_DASH - { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } , // DOT_DASH + { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT + { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH + { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH + { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH } ; static void wxMacGetPattern(int penStyle, Pattern *pattern) @@ -1874,7 +1846,7 @@ static void wxMacGetPattern(int penStyle, Pattern *pattern) void wxDC::MacInstallPen() const { wxCHECK_RET(Ok(), wxT("Invalid DC")); - Pattern blackColor; + //Pattern blackColor; // if ( m_macPenInstalled ) // return ; RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel()); @@ -1956,37 +1928,40 @@ void wxDC::MacInstallPen() const void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background ) { Pattern whiteColor ; - switch( background.MacGetBrushKind() ) + if ( background.Ok() ) { - case kwxMacBrushTheme : - { - ::SetThemeBackground( background.GetMacTheme() , wxDisplayDepth() , true ) ; - break ; - } - case kwxMacBrushThemeBackground : + switch( background.MacGetBrushKind() ) { - Rect extent ; - ThemeBackgroundKind bg = background.GetMacThemeBackground( &extent ) ; - ::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ; - break ; - } - case kwxMacBrushColour : - { - ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) ); - int brushStyle = background.GetStyle(); - if (brushStyle == wxSOLID) - ::BackPat(GetQDGlobalsWhite(&whiteColor)); - else if (IS_HATCH(brushStyle)) + case kwxMacBrushTheme : { - Pattern pat ; - wxMacGetPattern(brushStyle, &pat); - ::BackPat(&pat); + ::SetThemeBackground( background.MacGetTheme() , wxDisplayDepth() , true ) ; + break ; } - else + case kwxMacBrushThemeBackground : { - ::BackPat(GetQDGlobalsWhite(&whiteColor)); + Rect extent ; + ThemeBackgroundKind bg = background.MacGetThemeBackground( &extent ) ; + ::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ; + break ; + } + case kwxMacBrushColour : + { + ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) ); + int brushStyle = background.GetStyle(); + if (brushStyle == wxSOLID) + ::BackPat(GetQDGlobalsWhite(&whiteColor)); + else if (IS_HATCH(brushStyle)) + { + Pattern pat ; + wxMacGetPattern(brushStyle, &pat); + ::BackPat(&pat); + } + else + { + ::BackPat(GetQDGlobalsWhite(&whiteColor)); + } + break ; } - break ; } } }