X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a73903480fd533fcac58fc42262db95f2bf704f8..e71800ba3a40711f6c6c2461ed10cd6f2502c1d1:/src/mac/carbon/dc.cpp diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp index ed0648f9dc..7b95aef88a 100644 --- a/src/mac/carbon/dc.cpp +++ b/src/mac/carbon/dc.cpp @@ -31,6 +31,7 @@ using namespace std ; #include "ATSUnicode.h" #include "TextCommon.h" #include "TextEncodingConverter.h" +#include "FixMath.h" #if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) #endif @@ -45,13 +46,20 @@ IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) #define twips2mm 0.0176388888889 #define mm2pt 2.83464566929 #define pt2mm 0.352777777778 -#ifndef __DARWIN__ +#if !defined( __DARWIN__ ) || defined(__MWERKS__) +#ifndef M_PI const double M_PI = 3.14159265358979 ; #endif +#endif 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 ) { @@ -59,12 +67,67 @@ wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) : m_dc = dc ; dc->MacSetupPort(&m_ph) ; } - wxMacPortSetter::~wxMacPortSetter() { m_dc->MacCleanupPort(&m_ph) ; } +#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 + +#if 0 + +// start moving to a dual implementation for QD and CGContextRef + +class wxMacGraphicsContext +{ +public : + void DrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) = 0 ; + void SetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) = 0 ; + void SetClippingRegion( const wxRegion ®ion ) = 0 ; + void DestroyClippingRegion() = 0 ; + void SetTextForeground( const wxColour &col ) = 0 ; + void SetTextBackground( const wxColour &col ) = 0 ; + void SetLogicalScale( double x , double y ) = 0 ; + void SetUserScale( double x , double y ) = 0; +} ; + +class wxMacQuickDrawContext : public wxMacGraphicsContext +{ +public : +} ; + +#endif + wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) { m_formerClip = NewRgn() ; @@ -89,12 +152,13 @@ wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) OffsetRgn( m_newClip , x , y ) ; SetClip( m_newClip ) ; DisposeRgn( insidergn ) ; -#endif +#else int x = 0 , y = 0; win->MacWindowToRootWindow( &x,&y ) ; CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion().GetWXHRGN() , m_newClip ) ; OffsetRgn( m_newClip , x , y ) ; SetClip( m_newClip ) ; +#endif } } @@ -235,7 +299,11 @@ wxDC::wxDC() m_pen = *wxBLACK_PEN; m_font = *wxNORMAL_FONT; m_brush = *wxWHITE_BRUSH; +#ifdef __WXDEBUG__ + // needed to debug possible errors with two active drawing methods at the same time on + // the same DC m_macCurrentPortStateHelper = NULL ; +#endif m_macATSUIStyle = NULL ; m_macAliasWasEnabled = false; m_macForegroundPixMap = NULL ; @@ -250,18 +318,23 @@ wxDC::~wxDC(void) void wxDC::MacSetupPort(wxMacPortStateHelper* help) const { +#ifdef __WXDEBUG__ wxASSERT( m_macCurrentPortStateHelper == NULL ) ; 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__ wxASSERT( m_macCurrentPortStateHelper == help ) ; m_macCurrentPortStateHelper = NULL ; +#endif if( m_macATSUIStyle ) { ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle); @@ -292,7 +365,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(); @@ -411,12 +484,12 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord hei void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) { wxCHECK_RET( Ok(), wxT("invalid window dc") ) ; - wxMacPortSetter helper(this) ; if (region.Empty()) { DestroyClippingRegion(); return; } + wxMacFastPortSetter helper(this) ; wxCoord x, y, w, h; region.GetBox( x, y, w, h ); wxCoord xx, yy, ww, hh; @@ -458,17 +531,11 @@ 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; } -void wxDC::DoGetSize( int* width, int* height ) const -{ - *width = m_maxX-m_minX; - *height = m_maxY-m_minY; -} - void wxDC::DoGetSizeMM( int* width, int* height ) const { int w = 0; @@ -669,7 +736,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 @@ -682,7 +749,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() ; @@ -720,7 +787,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; @@ -760,7 +827,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); @@ -810,7 +877,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 @@ -841,7 +908,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); @@ -856,7 +923,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() ; @@ -879,7 +946,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 ; @@ -915,7 +982,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); @@ -952,7 +1019,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); @@ -989,7 +1056,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); @@ -1111,14 +1178,14 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, } if ( mode == kUnsupportedMode ) { - wxFAIL_MSG("unsupported blitting mode" ); + wxFAIL_MSG(wxT("unsupported blitting mode" )); return FALSE ; } CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ; PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ; if ( LockPixels(bmappixels) ) { - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; if ( source->GetDepth() == 1 ) { RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ; @@ -1274,6 +1341,8 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, return TRUE; } +#ifndef FixedToInt +// as macro in FixMath.h for 10.3 inline Fixed IntToFixed( int inInt ) { return (((SInt32) inInt) << 16); @@ -1283,54 +1352,44 @@ inline int FixedToInt( Fixed inFixed ) { return (((SInt32) inFixed) >> 16); } +#endif 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); return; } + if ( str.Length() == 0 ) return ; - wxMacPortSetter helper(this) ; + + wxMacFastPortSetter helper(this) ; MacInstallFont() ; - wxString text ; - if ( wxApp::s_macDefaultEncodingIsPC ) - { - text = wxMacMakeMacStringFromPC( str ) ; - } - else - { - text = str ; - } - 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.GetMacFontSize())); m_macAliasWasEnabled = true ; } OSStatus status = noErr ; - TECObjectRef ec; - status = TECCreateConverter(&ec, kTextEncodingMacRoman, kTextEncodingUnicodeDefault); - wxASSERT_MSG( status == noErr , "couldn't start converter" ) ; - ByteCount byteOutLen ; - ByteCount byteInLen = text.Length() ; - ByteCount byteBufferLen = byteInLen *2 ; - char* buf = new char[byteBufferLen] ; - status = TECConvertText(ec, (ConstTextPtr)text.c_str() , byteInLen, &byteInLen, - (TextPtr)buf, byteBufferLen, &byteOutLen); - wxASSERT_MSG( status == noErr , "couldn't convert text" ) ; - status = TECDisposeConverter(ec); - wxASSERT_MSG( status == noErr , "couldn't dispose converter" ) ; ATSUTextLayout atsuLayout ; - UniCharCount chars = byteOutLen / 2 ; - status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 , + UniCharCount chars = str.Length() ; +#if wxUSE_UNICODE + status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.Length() , str.Length() , 1 , &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; - wxASSERT_MSG( status == noErr , "couldn't create the layout of the rotated text" ); +#else + 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") ); int iAngle = int( angle ); int drawX = XLOG2DEVMAC(x) ; int drawY = YLOG2DEVMAC(y) ; @@ -1362,31 +1421,31 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, &textBefore , &textAfter, &ascent , &descent ); - drawX += sin(angle/RAD2DEG) * FixedToInt(ascent) ; - drawY += cos(angle/RAD2DEG) * FixedToInt(ascent) ; + drawX += (int)(sin(angle/RAD2DEG) * FixedToInt(ascent)); + drawY += (int)(cos(angle/RAD2DEG) * FixedToInt(ascent)); status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, IntToFixed(drawX) , IntToFixed(drawY) ); - wxASSERT_MSG( status == noErr , "couldn't draw the rotated text" ); + wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") ); Rect rect ; status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, IntToFixed(drawX) , IntToFixed(drawY) , &rect ); - wxASSERT_MSG( status == noErr , "couldn't measure the rotated text" ); + wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); OffsetRect( &rect , -m_macLocalOrigin.x , -m_macLocalOrigin.y ) ; CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) ); CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) ); ::ATSUDisposeTextLayout(atsuLayout); - delete[] buf ; } 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 bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ; - if ( IsKindOf(CLASSINFO( wxPrinterDC ) ) || m_font.GetNoAntiAliasing() ) + if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || m_font.GetNoAntiAliasing() ) useDrawThemeText = false ; #endif MacInstallFont() ; @@ -1411,33 +1470,22 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) { ::TextMode( srcCopy ) ; } - const char *text = NULL ; - int length = 0 ; - wxString macText ; - if ( wxApp::s_macDefaultEncodingIsPC ) - { - macText = wxMacMakeMacStringFromPC( strtext ) ; - text = macText ; - length = macText.Length() ; - } - else - { - text = strtext ; - length = strtext.Length() ; - } + int length = strtext.Length() ; + int laststop = 0 ; int i = 0 ; int line = 0 ; { while( i < length ) { - if( text[i] == 13 || text[i] == 10) + 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 } ; - CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ; if ( m_backgroundMode != wxTRANSPARENT ) { Point bounds={0,0} ; @@ -1460,13 +1508,13 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) &frame, teJustLeft, nil ); - CFRelease( mString ) ; line++ ; } else #endif { - ::DrawText( text , laststop , i - laststop ) ; + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; + ::DrawText( text , 0 , strlen(text) ) ; line++ ; ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) ); } @@ -1474,11 +1522,12 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) } i++ ; } + 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 } ; - CFStringRef mString = CFStringCreateWithCString( NULL , text + laststop , kCFStringEncodingMacRoman ) ; + wxMacCFStringHolder mString( linetext , m_font.GetEncoding()) ; if ( m_backgroundMode != wxTRANSPARENT ) { @@ -1502,13 +1551,13 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) &frame, teJustLeft, nil ); - CFRelease( mString ) ; } else #endif { - ::DrawText( text , laststop , i - laststop ) ; - } + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; + ::DrawText( text , 0 , strlen(text) ) ; + } } ::TextMode( srcOr ) ; } @@ -1519,12 +1568,12 @@ bool wxDC::CanGetTextExtent() const return true ; } -void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height, +void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *height, wxCoord *descent, wxCoord *externalLeading , wxFont *theFont ) const { wxCHECK_RET(Ok(), wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; wxFont formerFont = m_font ; if ( theFont ) { @@ -1536,7 +1585,7 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he ::GetFontInfo( &fi ) ; #if TARGET_CARBON bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ; - if ( IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() ) + if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() ) useGetThemeText = false ; #endif if ( height ) @@ -1545,20 +1594,8 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he *descent =YDEV2LOGREL( fi.descent ); if ( externalLeading ) *externalLeading = YDEV2LOGREL( fi.leading ) ; - const char *text = NULL ; - int length = 0 ; - wxString macText ; - if ( wxApp::s_macDefaultEncodingIsPC ) - { - macText = wxMacMakeMacStringFromPC( string ) ; - text = macText ; - length = macText.Length() ; - } - else - { - text = string ; - length = string.Length() ; - } + int length = strtext.Length() ; + int laststop = 0 ; int i = 0 ; int curwidth = 0 ; @@ -1567,8 +1604,9 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he *width = 0 ; while( i < length ) { - if( text[i] == 13 || text[i] == 10) + 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 @@ -1576,20 +1614,20 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he { Point bounds={0,0} ; SInt16 baseline ; - CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ; ::GetThemeTextDimensions( mString, kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); - CFRelease( mString ) ; curwidth = bounds.h ; } else #endif { - curwidth = ::TextWidth( text , laststop , i - laststop ) ; + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; + curwidth = ::TextWidth( text , 0 , strlen(text) ) ; } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; @@ -1598,25 +1636,26 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he i++ ; } + wxString linetext = strtext.Mid( laststop , i - laststop ) ; #if TARGET_CARBON if ( useGetThemeText ) { Point bounds={0,0} ; SInt16 baseline ; - CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ; + wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ; ::GetThemeTextDimensions( mString, kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); - CFRelease( mString ) ; curwidth = bounds.h ; } else #endif { - curwidth = ::TextWidth( text , laststop , i - laststop ) ; + wxCharBuffer text = linetext.mb_str(wxConvLocal) ; + curwidth = ::TextWidth( text , 0 , strlen(text) ) ; } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; @@ -1632,15 +1671,15 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he wxCoord wxDC::GetCharWidth(void) const { wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); - wxMacPortSetter helper(this) ; + wxMacFastPortSetter helper(this) ; MacInstallFont() ; int width = 0 ; #if TARGET_CARBON bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ; - if ( ((wxFont*)&m_font)->GetNoAntiAliasing() ) + if ( UMAGetSystemVersion() < 0x1000 || ((wxFont*)&m_font)->GetNoAntiAliasing() ) useGetThemeText = false ; #endif - char text[] = "H" ; + char text[] = "g" ; #if TARGET_CARBON if ( useGetThemeText ) { @@ -1667,7 +1706,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 ) ; @@ -1677,7 +1716,7 @@ 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) { @@ -1695,12 +1734,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.GetMacFontNum() ) ; + ::TextSize( (short)(m_scaleY * m_font.GetMacFontSize()) ) ; + ::TextFace( m_font.GetMacFontStyle() ) ; m_macFontInstalled = true ; m_macBrushInstalled = false ; m_macPenInstalled = false ; @@ -1769,11 +1807,11 @@ 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 ; - status = ::ATSUCreateStyle(&(ATSUStyle)m_macATSUIStyle) ; - wxASSERT_MSG( status == noErr , "couldn't create ATSU style" ) ; + Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.GetMacFontSize()) ) ; + Style qdStyle = m_font.GetMacFontStyle() ; + ATSUFontID atsuFont = m_font.GetMacATSUFontID() ; + status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUIStyle) ; + wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ) ; ATSUAttributeTag atsuTags[] = { kATSUFontTag , @@ -1802,7 +1840,7 @@ void wxDC::MacInstallFont() const } ; Boolean kTrue = true ; Boolean kFalse = false ; - BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ; + //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ; ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = { @@ -1817,56 +1855,52 @@ void wxDC::MacInstallFont() const (qdStyle & condense) ? &kTrue : &kFalse , (qdStyle & extend) ? &kTrue : &kFalse , } ; - status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag), + status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) , atsuTags, atsuSizes, atsuValues); - wxASSERT_MSG( status == noErr , "couldn't set create ATSU style" ) ; -} - -Pattern gHatchPatterns[] = -{ - { { 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 } } + wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ; +} + +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 } } , + // 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 } ; -static void wxMacGetHatchPattern(int hatchStyle, Pattern *pattern) +static void wxMacGetPattern(int penStyle, Pattern *pattern) { - int theIndex = 1 ; - switch(hatchStyle) - { - case wxBDIAGONAL_HATCH: - theIndex = 2; - break; - case wxFDIAGONAL_HATCH: - theIndex = 3; - break; - case wxCROSS_HATCH: - theIndex = 4; - break; - case wxHORIZONTAL_HATCH: - theIndex = 5; - break; - case wxVERTICAL_HATCH: - theIndex = 6; - break; - case wxCROSSDIAG_HATCH: - theIndex = 7; - break; - default: - theIndex = 1; // solid pattern - break; + int index = 0; // solid pattern by default + switch(penStyle) + { + // hatches + case wxBDIAGONAL_HATCH: index = 1; break; + case wxFDIAGONAL_HATCH: index = 2; break; + case wxCROSS_HATCH: index = 3; break; + case wxHORIZONTAL_HATCH: index = 4; break; + case wxVERTICAL_HATCH: index = 5; break; + case wxCROSSDIAG_HATCH: index = 6; break; + // dashes + case wxDOT: index = 7; break; + case wxLONG_DASH: index = 8; break; + case wxSHORT_DASH: index = 9; break; + case wxDOT_DASH: index = 10; break; } - *pattern = gHatchPatterns[theIndex-1] ; + *pattern = gPatterns[index]; } 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()); @@ -1874,67 +1908,33 @@ void wxDC::MacInstallPen() const ::RGBForeColor( &forecolor ); ::RGBBackColor( &backcolor ); ::PenNormal() ; - int penWidth = m_pen.GetWidth() * (int) m_scaleX ; + int penWidth = (int) (m_pen.GetWidth() * m_scaleX) ; ; // null means only one pixel, at whatever resolution if ( penWidth == 0 ) penWidth = 1 ; ::PenSize(penWidth, penWidth); + int penStyle = m_pen.GetStyle(); - if (penStyle == wxSOLID) - { - ::PenPat(GetQDGlobalsBlack(&blackColor)); - } - else if (IS_HATCH(penStyle)) - { - Pattern pat ; - wxMacGetHatchPattern(penStyle, &pat); - ::PenPat(&pat); + Pattern pat; + if (penStyle == wxUSER_DASH) + { + // FIXME: there should be exactly 8 items in the dash + wxDash* dash ; + int number = m_pen.GetDashes(&dash) ; + int index = 0; + for ( int i = 0 ; i < 8 ; ++i ) + { + pat.pat[i] = dash[index] ; + if (index < number - 1) + index++; + } } else { - Pattern pat = *GetQDGlobalsBlack(&blackColor) ; - switch( penStyle ) - { - case wxDOT : - for ( int i = 0 ; i < 8 ; ++i ) - { - pat.pat[i] = 0xCC ; - } - break ; - case wxLONG_DASH : - for ( int i = 0 ; i < 8 ; ++i ) - { - pat.pat[i] = 0xFE ; - } - break ; - case wxSHORT_DASH : - for ( int i = 0 ; i < 8 ; ++i ) - { - pat.pat[i] = 0xEE ; - } - break ; - case wxDOT_DASH : - for ( int i = 0 ; i < 8 ; ++i ) - { - pat.pat[i] = 0x6F ; - } - break ; - case wxUSER_DASH : - { - wxDash* dash ; - m_pen.GetDashes(&dash) ; - // right now we don't allocate larger pixmaps - // int number = - m_pen.GetDashes(&dash) ; - for ( int i = 0 ; i < 8 ; ++i ) - { - pat.pat[i] = dash[0] ; - } - } - break ; - } - ::PenPat(&pat); + wxMacGetPattern(penStyle, &pat); } + ::PenPat(&pat); + short mode = patCopy ; // todo : switch( m_logicalFunction ) @@ -1984,28 +1984,28 @@ void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background ) Pattern whiteColor ; switch( background.MacGetBrushKind() ) { - case kwxMacBrushTheme : + case kwxMacBrushTheme : { ::SetThemeBackground( background.GetMacTheme() , wxDisplayDepth() , true ) ; break ; } - case kwxMacBrushThemeBackground : + case kwxMacBrushThemeBackground : { Rect extent ; ThemeBackgroundKind bg = background.GetMacThemeBackground( &extent ) ; ::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ; break ; } - case kwxMacBrushColour : + case kwxMacBrushColour : { - ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) ); + ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) ); int brushStyle = background.GetStyle(); if (brushStyle == wxSOLID) ::BackPat(GetQDGlobalsWhite(&whiteColor)); else if (IS_HATCH(brushStyle)) { Pattern pat ; - wxMacGetHatchPattern(brushStyle, &pat); + wxMacGetPattern(brushStyle, &pat); ::BackPat(&pat); } else @@ -2035,7 +2035,7 @@ void wxDC::MacInstallBrush() const else if (IS_HATCH(brushStyle)) { Pattern pat ; - wxMacGetHatchPattern(brushStyle, &pat); + wxMacGetPattern(brushStyle, &pat); ::PenPat(&pat); } else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )