X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e40298d54ecd5b109222a7c60aa2ef084a304d69..f65d4b83d13187f8e1838abf48831d9f044efa67:/src/mac/carbon/dc.cpp diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp index 9dff84e4d3..989cc238a8 100644 --- a/src/mac/carbon/dc.cpp +++ b/src/mac/carbon/dc.cpp @@ -17,6 +17,7 @@ #include "wx/app.h" #include "wx/mac/uma.h" #include "wx/dcmemory.h" +#include "wx/dcprint.h" #include "wx/region.h" #include "wx/image.h" #include "wx/log.h" @@ -25,10 +26,12 @@ #include "math.h" using namespace std ; #endif + #include "wx/mac/private.h" #include "ATSUnicode.h" #include "TextCommon.h" #include "TextEncodingConverter.h" +#include "FixMath.h" #if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) #endif @@ -43,9 +46,11 @@ 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 ; @@ -87,13 +92,13 @@ wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) OffsetRgn( m_newClip , x , y ) ; SetClip( m_newClip ) ; DisposeRgn( insidergn ) ; -#endif - RgnHandle insidergn = NewRgn() ; +#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 } } @@ -234,7 +239,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 ; @@ -249,8 +258,10 @@ wxDC::~wxDC(void) void wxDC::MacSetupPort(wxMacPortStateHelper* help) const { +#ifdef __WXDEBUG__ wxASSERT( m_macCurrentPortStateHelper == NULL ) ; m_macCurrentPortStateHelper = help ; +#endif SetClip( (RgnHandle) m_macCurrentClipRgn); m_macFontInstalled = false ; m_macBrushInstalled = false ; @@ -259,8 +270,10 @@ void wxDC::MacSetupPort(wxMacPortStateHelper* help) const void wxDC::MacCleanupPort(wxMacPortStateHelper* help) const { +#ifdef __WXDEBUG__ wxASSERT( m_macCurrentPortStateHelper == help ) ; m_macCurrentPortStateHelper = NULL ; +#endif if( m_macATSUIStyle ) { ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle); @@ -410,12 +423,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; } + wxMacPortSetter helper(this) ; wxCoord x, y, w, h; region.GetBox( x, y, w, h ); wxCoord xx, yy, ww, hh; @@ -462,12 +475,6 @@ void wxDC::DestroyClippingRegion() 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; @@ -1054,7 +1061,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, switch ( logical_func ) { case wxAND: // src AND dst - mode = srcOr ; // ok + mode = adMin ; // ok break ; case wxAND_INVERT: // (NOT src) AND dst mode = notSrcOr ; // ok @@ -1110,7 +1117,7 @@ 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 ; @@ -1273,6 +1280,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); @@ -1282,29 +1291,25 @@ 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) ; MacInstallFont() ; - wxString text ; - if ( wxApp::s_macDefaultEncodingIsPC ) - { - text = wxMacMakeMacStringFromPC( str ) ; - } - else - { - text = str ; - } + wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; if ( 0 ) { @@ -1313,23 +1318,33 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, m_macAliasWasEnabled = true ; } OSStatus status = noErr ; + ATSUTextLayout atsuLayout ; + UniCharCount chars = str.Length() ; +#if wxUSE_UNICODE + status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.Length() , str.Length() , 1 , + &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; +#else TECObjectRef ec; - status = TECCreateConverter(&ec, kTextEncodingMacRoman, kTextEncodingUnicodeDefault); - wxASSERT_MSG( status == noErr , "couldn't start converter" ) ; + status = TECCreateConverter(&ec, + wxApp::s_macDefaultEncodingIsPC + ? (int)kTextEncodingWindowsLatin1 + : (int)kTextEncodingMacRoman, + kTextEncodingUnicodeDefault); + + wxASSERT_MSG( status == noErr , wxT("couldn't start converter") ) ; ByteCount byteOutLen ; - ByteCount byteInLen = text.Length() ; + ByteCount byteInLen = str.Length() ; ByteCount byteBufferLen = byteInLen *2 ; char* buf = new char[byteBufferLen] ; - status = TECConvertText(ec, (ConstTextPtr)text.c_str() , byteInLen, &byteInLen, + status = TECConvertText(ec, (ConstTextPtr)str.c_str() , byteInLen, &byteInLen, (TextPtr)buf, byteBufferLen, &byteOutLen); - wxASSERT_MSG( status == noErr , "couldn't convert text" ) ; + wxASSERT_MSG( status == noErr , wxT("couldn't convert text") ) ; status = TECDisposeConverter(ec); - wxASSERT_MSG( status == noErr , "couldn't dispose converter" ) ; - ATSUTextLayout atsuLayout ; - UniCharCount chars = byteOutLen / 2 ; + wxASSERT_MSG( status == noErr , wxT("couldn't dispose converter") ) ; status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 , &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ; - wxASSERT_MSG( status == noErr , "couldn't create the layout of the rotated text" ); +#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) ; @@ -1361,31 +1376,36 @@ 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); +#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) ; long xx = XLOG2DEVMAC(x); long yy = YLOG2DEVMAC(y); #if TARGET_CARBON + bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ; - if ( m_font.GetNoAntiAliasing() ) + if ( IsKindOf(CLASSINFO( wxPrinterDC ) ) || m_font.GetNoAntiAliasing() ) useDrawThemeText = false ; #endif MacInstallFont() ; @@ -1410,33 +1430,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 ) ; if ( m_backgroundMode != wxTRANSPARENT ) { Point bounds={0,0} ; @@ -1459,13 +1468,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 = wxMacStringToCString(linetext) ; + ::DrawText( text , 0 , strlen(text) ) ; line++ ; ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) ); } @@ -1473,11 +1482,13 @@ 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 ) ; + if ( m_backgroundMode != wxTRANSPARENT ) { Point bounds={0,0} ; @@ -1500,13 +1511,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 = wxMacStringToCString(linetext) ; + ::DrawText( text , 0 , strlen(text) ) ; + } } ::TextMode( srcOr ) ; } @@ -1517,7 +1528,7 @@ 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 { @@ -1534,7 +1545,7 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he ::GetFontInfo( &fi ) ; #if TARGET_CARBON bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ; - if ( ((wxFont*)&m_font)->GetNoAntiAliasing() ) + if ( IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() ) useGetThemeText = false ; #endif if ( height ) @@ -1543,8 +1554,9 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he *descent =YDEV2LOGREL( fi.descent ); if ( externalLeading ) *externalLeading = YDEV2LOGREL( fi.leading ) ; + int length = strtext.Length() ; + /* const char *text = NULL ; - int length = 0 ; wxString macText ; if ( wxApp::s_macDefaultEncodingIsPC ) { @@ -1557,6 +1569,7 @@ void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *he text = string ; length = string.Length() ; } + */ int laststop = 0 ; int i = 0 ; int curwidth = 0 ; @@ -1565,8 +1578,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 @@ -1574,20 +1588,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 ) ; ::GetThemeTextDimensions( mString, kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); - CFRelease( mString ) ; curwidth = bounds.h ; } else #endif { - curwidth = ::TextWidth( text , laststop , i - laststop ) ; + wxCharBuffer text = wxMacStringToCString(linetext) ; + curwidth = ::TextWidth( text , 0 , strlen(text) ) ; } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; @@ -1596,25 +1610,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 ) ; ::GetThemeTextDimensions( mString, kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); - CFRelease( mString ) ; curwidth = bounds.h ; } else #endif { - curwidth = ::TextWidth( text , laststop , i - laststop ) ; + wxCharBuffer text = wxMacStringToCString(linetext) ; + curwidth = ::TextWidth( text , 0 , strlen(text) ) ; } if ( curwidth > *width ) *width = XDEV2LOGREL( curwidth ) ; @@ -1747,10 +1762,12 @@ void wxDC::MacInstallFont() const case wxSRC_INVERT: // (NOT src) mode = notPatCopy ; break ; + case wxAND: // src AND dst + mode = adMin ; + break ; // unsupported TODO case wxCLEAR: // 0 case wxAND_REVERSE:// src AND (NOT dst) - case wxAND: // src AND dst case wxAND_INVERT: // (NOT src) AND dst case wxNO_OP: // dst case wxNOR: // (NOT src) AND (NOT dst) @@ -1768,8 +1785,8 @@ void wxDC::MacInstallFont() const 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" ) ; + status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUIStyle) ; + wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ) ; ATSUAttributeTag atsuTags[] = { kATSUFontTag , @@ -1798,7 +1815,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)] = { @@ -1813,50 +1830,46 @@ 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 @@ -1870,67 +1883,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 ) @@ -1951,10 +1930,12 @@ void wxDC::MacInstallPen() const case wxSRC_INVERT: // (NOT src) mode = notPatCopy ; break ; + case wxAND: // src AND dst + mode = adMin ; + break ; // unsupported TODO case wxCLEAR: // 0 case wxAND_REVERSE:// src AND (NOT dst) - case wxAND: // src AND dst case wxAND_INVERT: // (NOT src) AND dst case wxNO_OP: // dst case wxNOR: // (NOT src) AND (NOT dst) @@ -1978,28 +1959,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 @@ -2029,7 +2010,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 ) @@ -2131,10 +2112,12 @@ void wxDC::MacInstallBrush() const case wxSRC_INVERT: // (NOT src) mode = notPatCopy ; break ; + case wxAND: // src AND dst + mode = adMin ; + break ; // unsupported TODO case wxCLEAR: // 0 case wxAND_REVERSE:// src AND (NOT dst) - case wxAND: // src AND dst case wxAND_INVERT: // (NOT src) AND dst case wxNO_OP: // dst case wxNOR: // (NOT src) AND (NOT dst) @@ -2195,4 +2178,4 @@ wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const { return ((wxDC *)this)->YLOG2DEVREL(y); -} \ No newline at end of file +}