1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:       wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "dc.h" 
  18 #include "wx/mac/uma.h" 
  19 #include "wx/dcmemory.h" 
  20 #include "wx/dcprint.h" 
  21 #include "wx/region.h" 
  30 #include "wx/mac/private.h" 
  31 #include "ATSUnicode.h" 
  32 #include "TextCommon.h" 
  33 #include "TextEncodingConverter.h" 
  34 #if !USE_SHARED_LIBRARY 
  35 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
) 
  38 //----------------------------------------------------------------------------- 
  40 //----------------------------------------------------------------------------- 
  42 #define mm2inches        0.0393700787402 
  43 #define inches2mm        25.4 
  44 #define mm2twips        56.6929133859 
  45 #define twips2mm        0.0176388888889 
  46 #define mm2pt            2.83464566929 
  47 #define pt2mm            0.352777777778 
  48 #if !defined( __DARWIN__ ) || defined(__MWERKS__) 
  49 const double M_PI 
= 3.14159265358979 ; 
  51 const double RAD2DEG  
= 180.0 / M_PI
; 
  52 const short kEmulatedMode 
= -1 ; 
  53 const short kUnsupportedMode 
= -2 ; 
  55 wxMacPortSetter::wxMacPortSetter( const wxDC
* dc 
) : 
  56     m_ph( (GrafPtr
) dc
->m_macPort 
) 
  58     wxASSERT( dc
->Ok() ) ; 
  60     dc
->MacSetupPort(&m_ph
) ; 
  63 wxMacPortSetter::~wxMacPortSetter() 
  65     m_dc
->MacCleanupPort(&m_ph
) ; 
  68 wxMacWindowClipper::wxMacWindowClipper( const wxWindow
* win 
)  
  70     m_formerClip 
= NewRgn() ; 
  71     m_newClip 
= NewRgn() ; 
  72     GetClip( m_formerClip 
) ; 
  77         // this clipping area was set to the parent window's drawing area, lead to problems 
  78         // with MacOSX controls drawing outside their wx' rectangle 
  79         RgnHandle insidergn 
= NewRgn() ; 
  81         wxWindow 
*parent 
= win
->GetParent() ; 
  82         parent
->MacWindowToRootWindow( &x
,&y 
) ; 
  83         wxSize size 
= parent
->GetSize() ; 
  84         SetRectRgn( insidergn 
, parent
->MacGetLeftBorderSize() , parent
->MacGetTopBorderSize() ,  
  85             size
.x 
- parent
->MacGetRightBorderSize(),  
  86             size
.y 
- parent
->MacGetBottomBorderSize()) ; 
  87         CopyRgn( (RgnHandle
) parent
->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip 
) ; 
  88         SectRgn( m_newClip 
, insidergn 
, m_newClip 
) ; 
  89         OffsetRgn( m_newClip 
, x 
, y 
) ; 
  90         SetClip( m_newClip 
) ; 
  91         DisposeRgn( insidergn 
) ; 
  94         win
->MacWindowToRootWindow( &x
,&y 
) ; 
  95         CopyRgn( (RgnHandle
) ((wxWindow
*)win
)->MacGetVisibleRegion().GetWXHRGN() , m_newClip 
) ; 
  96         OffsetRgn( m_newClip 
, x 
, y 
) ; 
  97         SetClip( m_newClip 
) ; 
 101 wxMacWindowClipper::~wxMacWindowClipper()  
 103     SetClip( m_formerClip 
) ; 
 104     DisposeRgn( m_newClip 
) ; 
 105     DisposeRgn( m_formerClip 
) ; 
 108 //----------------------------------------------------------------------------- 
 110 //----------------------------------------------------------------------------- 
 111 static inline double dmin(double a
, double b
) { return a 
< b 
? a 
: b
; } 
 112 static inline double dmax(double a
, double b
) { return a 
> b 
? a 
: b
; } 
 113 static inline double DegToRad(double deg
) { return (deg 
* M_PI
) / 180.0; } 
 115 //----------------------------------------------------------------------------- 
 117 //----------------------------------------------------------------------------- 
 118 // this function emulates all wx colour manipulations, used to verify the implementation 
 119 // by setting the mode in the blitting functions to kEmulatedMode 
 120 void wxMacCalculateColour( int logical_func 
, const RGBColor 
&srcColor 
, RGBColor 
&dstColor 
) ; 
 122 void wxMacCalculateColour( int logical_func 
, const RGBColor 
&srcColor 
, RGBColor 
&dstColor 
) 
 124     switch ( logical_func 
) 
 126         case wxAND
:        // src AND dst 
 127             dstColor
.red 
= dstColor
.red 
& srcColor
.red 
; 
 128             dstColor
.green 
= dstColor
.green 
& srcColor
.green 
; 
 129             dstColor
.blue 
= dstColor
.blue 
& srcColor
.blue 
; 
 131         case wxAND_INVERT
: // (NOT src) AND dst 
 132             dstColor
.red 
= dstColor
.red 
& ~srcColor
.red 
; 
 133             dstColor
.green 
= dstColor
.green 
& ~srcColor
.green 
; 
 134             dstColor
.blue 
= dstColor
.blue 
& ~srcColor
.blue 
; 
 136         case wxAND_REVERSE
:// src AND (NOT dst) 
 137             dstColor
.red 
= ~dstColor
.red 
& srcColor
.red 
; 
 138             dstColor
.green 
= ~dstColor
.green 
& srcColor
.green 
; 
 139             dstColor
.blue 
= ~dstColor
.blue 
& srcColor
.blue 
; 
 147             dstColor
.red 
= srcColor
.red 
; 
 148             dstColor
.green 
= srcColor
.green 
; 
 149             dstColor
.blue 
= srcColor
.blue 
; 
 151         case wxEQUIV
:      // (NOT src) XOR dst 
 152             dstColor
.red 
= dstColor
.red 
^ ~srcColor
.red 
; 
 153             dstColor
.green 
= dstColor
.green 
^ ~srcColor
.green 
; 
 154             dstColor
.blue 
= dstColor
.blue 
^ ~srcColor
.blue 
; 
 156         case wxINVERT
:     // NOT dst 
 157             dstColor
.red 
= ~dstColor
.red 
; 
 158             dstColor
.green 
= ~dstColor
.green 
; 
 159             dstColor
.blue 
= ~dstColor
.blue 
; 
 161         case wxNAND
:       // (NOT src) OR (NOT dst) 
 162             dstColor
.red 
= ~dstColor
.red 
| ~srcColor
.red 
; 
 163             dstColor
.green 
= ~dstColor
.green 
| ~srcColor
.green 
; 
 164             dstColor
.blue 
= ~dstColor
.blue 
| ~srcColor
.blue 
; 
 166         case wxNOR
:        // (NOT src) AND (NOT dst) 
 167             dstColor
.red 
= ~dstColor
.red 
& ~srcColor
.red 
; 
 168             dstColor
.green 
= ~dstColor
.green 
& ~srcColor
.green 
; 
 169             dstColor
.blue 
= ~dstColor
.blue 
& ~srcColor
.blue 
; 
 173         case wxOR
:         // src OR dst 
 174             dstColor
.red 
= dstColor
.red 
| srcColor
.red 
; 
 175             dstColor
.green 
= dstColor
.green 
| srcColor
.green 
; 
 176             dstColor
.blue 
= dstColor
.blue 
| srcColor
.blue 
; 
 178         case wxOR_INVERT
:  // (NOT src) OR dst 
 179             dstColor
.red 
= dstColor
.red 
| ~srcColor
.red 
; 
 180             dstColor
.green 
= dstColor
.green 
| ~srcColor
.green 
; 
 181             dstColor
.blue 
= dstColor
.blue 
| ~srcColor
.blue 
; 
 183         case wxOR_REVERSE
: // src OR (NOT dst) 
 184             dstColor
.red 
= ~dstColor
.red 
| srcColor
.red 
; 
 185             dstColor
.green 
= ~dstColor
.green 
| srcColor
.green 
; 
 186             dstColor
.blue 
= ~dstColor
.blue 
| srcColor
.blue 
; 
 189             dstColor
.red 
= 0xFFFF ; 
 190             dstColor
.green 
= 0xFFFF ; 
 191             dstColor
.blue 
= 0xFFFF ; 
 193         case wxSRC_INVERT
: // (NOT src) 
 194             dstColor
.red 
= ~srcColor
.red 
; 
 195             dstColor
.green 
= ~srcColor
.green 
; 
 196             dstColor
.blue 
= ~srcColor
.blue 
; 
 198         case wxXOR
:        // src XOR dst 
 199             dstColor
.red 
= dstColor
.red 
^ srcColor
.red 
; 
 200             dstColor
.green 
= dstColor
.green 
^ srcColor
.green 
; 
 201             dstColor
.blue 
= dstColor
.blue 
^ srcColor
.blue 
; 
 210     m_mm_to_pix_x 
= mm2pt
; 
 211     m_mm_to_pix_y 
= mm2pt
; 
 212     m_internalDeviceOriginX 
= 0; 
 213     m_internalDeviceOriginY 
= 0; 
 214     m_externalDeviceOriginX 
= 0; 
 215     m_externalDeviceOriginY 
= 0; 
 216     m_logicalScaleX 
= 1.0; 
 217     m_logicalScaleY 
= 1.0; 
 222     m_needComputeScaleX 
= FALSE
; 
 223     m_needComputeScaleY 
= FALSE
; 
 227     m_macFontInstalled 
= false ; 
 228     m_macBrushInstalled 
= false ; 
 229     m_macPenInstalled 
= false ; 
 230     m_macLocalOrigin
.x 
= m_macLocalOrigin
.y 
= 0 ; 
 231     m_macBoundaryClipRgn 
= NewRgn() ; 
 232     m_macCurrentClipRgn 
= NewRgn() ; 
 233     SetRectRgn( (RgnHandle
) m_macBoundaryClipRgn 
, -32000 , -32000 , 32000 , 32000 ) ; 
 234     SetRectRgn( (RgnHandle
) m_macCurrentClipRgn 
, -32000 , -32000 , 32000 , 32000 ) ; 
 235     m_pen 
= *wxBLACK_PEN
; 
 236     m_font 
= *wxNORMAL_FONT
; 
 237     m_brush 
= *wxWHITE_BRUSH
; 
 238     m_macCurrentPortStateHelper 
= NULL 
; 
 239     m_macATSUIStyle 
= NULL 
; 
 240     m_macAliasWasEnabled 
= false; 
 241     m_macForegroundPixMap 
= NULL 
; 
 242     m_macBackgroundPixMap 
= NULL 
; 
 247     DisposeRgn( (RgnHandle
) m_macBoundaryClipRgn 
) ; 
 248     DisposeRgn( (RgnHandle
) m_macCurrentClipRgn 
) ; 
 251 void wxDC::MacSetupPort(wxMacPortStateHelper
* help
) const 
 253     wxASSERT( m_macCurrentPortStateHelper 
== NULL 
) ; 
 254     m_macCurrentPortStateHelper 
= help 
; 
 255     SetClip( (RgnHandle
) m_macCurrentClipRgn
); 
 256     m_macFontInstalled 
= false ; 
 257     m_macBrushInstalled 
= false ; 
 258     m_macPenInstalled 
= false ; 
 261 void wxDC::MacCleanupPort(wxMacPortStateHelper
* help
) const 
 263     wxASSERT( m_macCurrentPortStateHelper 
== help 
) ; 
 264     m_macCurrentPortStateHelper 
= NULL 
; 
 265     if( m_macATSUIStyle 
) 
 267         ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
); 
 268         m_macATSUIStyle 
= NULL 
; 
 270     if ( m_macAliasWasEnabled 
) 
 272         SetAntiAliasedTextEnabled(m_macFormerAliasState
, m_macFormerAliasSize
); 
 273         m_macAliasWasEnabled 
= false ; 
 275     if ( m_macForegroundPixMap 
) 
 278         ::PenPat(GetQDGlobalsBlack(&blackColor
)); 
 279         DisposePixPat( (PixPatHandle
) m_macForegroundPixMap 
) ; 
 280         m_macForegroundPixMap 
= NULL 
; 
 282     if ( m_macBackgroundPixMap 
) 
 285         ::BackPat(GetQDGlobalsWhite(&whiteColor
)); 
 286         DisposePixPat( (PixPatHandle
) m_macBackgroundPixMap 
) ; 
 287         m_macBackgroundPixMap 
= NULL 
; 
 291 void wxDC::DoDrawBitmap( const wxBitmap 
&bmp
, wxCoord x
, wxCoord y
, bool useMask 
) 
 293      wxCHECK_RET( Ok(), wxT("invalid window dc") ); 
 294      wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") ); 
 295      wxMacPortSetter 
helper(this) ; 
 296      wxCoord xx 
= XLOG2DEVMAC(x
); 
 297      wxCoord yy 
= YLOG2DEVMAC(y
); 
 298      wxCoord w 
= bmp
.GetWidth(); 
 299      wxCoord h 
= bmp
.GetHeight(); 
 300      wxCoord ww 
= XLOG2DEVREL(w
); 
 301      wxCoord hh 
= YLOG2DEVREL(h
); 
 302      // Set up drawing mode 
 303      short  mode 
= (m_logicalFunction 
== wxCOPY 
? srcCopy 
: 
 304                     //m_logicalFunction == wxCLEAR ? WHITENESS : 
 305                     //m_logicalFunction == wxSET ? BLACKNESS : 
 306                     m_logicalFunction 
== wxINVERT 
? hilite 
: 
 307                    //m_logicalFunction == wxAND ? MERGECOPY : 
 308                     m_logicalFunction 
== wxOR 
? srcOr 
: 
 309                     m_logicalFunction 
== wxSRC_INVERT 
? notSrcCopy 
: 
 310                     m_logicalFunction 
== wxXOR 
? srcXor 
: 
 311                     m_logicalFunction 
== wxOR_REVERSE 
? notSrcOr 
: 
 312                     //m_logicalFunction == wxAND_REVERSE ? SRCERASE : 
 313                     //m_logicalFunction == wxSRC_OR ? srcOr : 
 314                     //m_logicalFunction == wxSRC_AND ? SRCAND : 
 316      if ( bmp
.GetBitmapType() == kMacBitmapTypePict 
) { 
 317          Rect bitmaprect 
= { 0 , 0 , hh
, ww 
}; 
 318          ::OffsetRect( &bitmaprect
, xx
, yy 
) ; 
 319          ::DrawPicture( (PicHandle
) bmp
.GetPict(), &bitmaprect 
) ; 
 321      else if ( bmp
.GetBitmapType() == kMacBitmapTypeGrafWorld 
) 
 323          GWorldPtr    bmapworld 
= MAC_WXHBITMAP( bmp
.GetHBITMAP() ); 
 324          PixMapHandle bmappixels 
; 
 325          // Set foreground and background colours (for bitmaps depth = 1) 
 326          if(bmp
.GetDepth() == 1) 
 328              RGBColor fore 
= MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()); 
 329              RGBColor back 
= MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()); 
 335              RGBColor white 
= { 0xFFFF, 0xFFFF,0xFFFF} ; 
 336              RGBColor black 
= { 0,0,0} ; 
 337              RGBForeColor( &black 
) ; 
 338              RGBBackColor( &white 
) ; 
 340          bmappixels 
= GetGWorldPixMap( bmapworld 
) ; 
 341          wxCHECK_RET(LockPixels(bmappixels
), 
 342                      wxT("DoDrawBitmap:  Unable to lock pixels")); 
 343          Rect source 
= { 0, 0, h
, w 
}; 
 344          Rect dest   
= { yy
, xx
, yy 
+ hh
, xx 
+ ww 
}; 
 345          if ( useMask 
&& bmp
.GetMask() ) 
 347              if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())))) 
 351                       GetPortBitMapForCopyBits(bmapworld
), 
 352                       GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap())), 
 353                       GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ), 
 354                       &source
, &source
, &dest
, mode
, NULL
 
 356                  UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp
.GetMask()->GetMaskBitmap()))); 
 360              CopyBits( GetPortBitMapForCopyBits( bmapworld 
), 
 361                        GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ), 
 362                        &source
, &dest
, mode
, NULL 
) ; 
 364          UnlockPixels( bmappixels 
) ; 
 366      else if ( bmp
.GetBitmapType() == kMacBitmapTypeIcon 
) 
 368         Rect bitmaprect 
= { 0 , 0 , bmp
.GetHeight(), bmp
.GetWidth() } ; 
 369         OffsetRect( &bitmaprect
, xx
, yy 
) ; 
 370         PlotCIconHandle( &bitmaprect 
, atNone 
, ttNone 
, MAC_WXHICON(bmp
.GetHICON()) ) ; 
 372      m_macPenInstalled 
= false ; 
 373      m_macBrushInstalled 
= false ; 
 374      m_macFontInstalled 
= false ; 
 377 void wxDC::DoDrawIcon( const wxIcon 
&icon
, wxCoord x
, wxCoord y 
) 
 379     wxCHECK_RET(Ok(), wxT("Invalid dc  wxDC::DoDrawIcon")); 
 380     wxCHECK_RET(icon
.Ok(), wxT("Invalid icon wxDC::DoDrawIcon")); 
 381     DoDrawBitmap( icon 
, x 
, y 
, icon
.GetMask() != NULL 
) ; 
 384 void wxDC::DoSetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height 
) 
 386     wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion  Invalid DC")); 
 387     wxCoord xx
, yy
, ww
, hh
; 
 390     ww 
= XLOG2DEVREL(width
); 
 391     hh 
= YLOG2DEVREL(height
); 
 392     SetRectRgn( (RgnHandle
) m_macCurrentClipRgn 
, xx 
, yy 
, xx 
+ ww 
, yy 
+ hh 
) ; 
 393     SectRgn( (RgnHandle
) m_macCurrentClipRgn 
, (RgnHandle
) m_macBoundaryClipRgn 
, (RgnHandle
) m_macCurrentClipRgn 
) ; 
 396         m_clipX1 
= wxMax( m_clipX1 
, xx 
); 
 397         m_clipY1 
= wxMax( m_clipY1 
, yy 
); 
 398         m_clipX2 
= wxMin( m_clipX2
, (xx 
+ ww
)); 
 399         m_clipY2 
= wxMin( m_clipY2
, (yy 
+ hh
)); 
 411 void wxDC::DoSetClippingRegionAsRegion( const wxRegion 
®ion  
) 
 413     wxCHECK_RET( Ok(), wxT("invalid window dc") ) ; 
 414       wxMacPortSetter 
helper(this) ; 
 417         DestroyClippingRegion(); 
 421     region
.GetBox( x
, y
, w
, h 
); 
 422     wxCoord xx
, yy
, ww
, hh
; 
 427     // if we have a scaling that we cannot map onto native regions 
 428     // we must use the box 
 429     if ( ww 
!= w 
|| hh 
!= h 
) 
 431         wxDC::DoSetClippingRegion( x
, y
, w
, h 
); 
 435         CopyRgn( (RgnHandle
) region
.GetWXHRGN() , (RgnHandle
) m_macCurrentClipRgn 
) ; 
 436         if ( xx 
!= x 
|| yy 
!= y 
) 
 438             OffsetRgn( (RgnHandle
) m_macCurrentClipRgn 
, xx 
- x 
, yy 
- y 
) ; 
 440         SectRgn( (RgnHandle
) m_macCurrentClipRgn 
, (RgnHandle
) m_macBoundaryClipRgn 
, (RgnHandle
) m_macCurrentClipRgn 
) ; 
 443             m_clipX1 
= wxMax( m_clipX1 
, xx 
); 
 444             m_clipY1 
= wxMax( m_clipY1 
, yy 
); 
 445             m_clipX2 
= wxMin( m_clipX2
, (xx 
+ ww
)); 
 446             m_clipY2 
= wxMin( m_clipY2
, (yy 
+ hh
)); 
 459 void wxDC::DestroyClippingRegion() 
 461     wxMacPortSetter 
helper(this) ; 
 462     CopyRgn( (RgnHandle
) m_macBoundaryClipRgn 
, (RgnHandle
) m_macCurrentClipRgn 
) ; 
 466 void wxDC::DoGetSize( int* width
, int* height 
) const 
 468     *width 
= m_maxX
-m_minX
; 
 469     *height 
= m_maxY
-m_minY
; 
 472 void wxDC::DoGetSizeMM( int* width
, int* height 
) const 
 477     *width 
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) ); 
 478     *height 
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) ); 
 481 void wxDC::SetTextForeground( const wxColour 
&col 
) 
 483     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
 484     m_textForegroundColour 
= col
; 
 485     m_macFontInstalled 
= false ; 
 488 void wxDC::SetTextBackground( const wxColour 
&col 
) 
 490     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
 491     m_textBackgroundColour 
= col
; 
 492     m_macFontInstalled 
= false ; 
 495 void wxDC::SetMapMode( int mode 
) 
 500         SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y 
); 
 503         SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y 
); 
 506         SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y 
); 
 509         SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 ); 
 513         SetLogicalScale( 1.0, 1.0 ); 
 516     if (mode 
!= wxMM_TEXT
) 
 518         m_needComputeScaleX 
= TRUE
; 
 519         m_needComputeScaleY 
= TRUE
; 
 523 void wxDC::SetUserScale( double x
, double y 
) 
 525     // allow negative ? -> no 
 528     ComputeScaleAndOrigin(); 
 531 void wxDC::SetLogicalScale( double x
, double y 
) 
 536     ComputeScaleAndOrigin(); 
 539 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y 
) 
 541     m_logicalOriginX 
= x 
* m_signX
;   // is this still correct ? 
 542     m_logicalOriginY 
= y 
* m_signY
; 
 543     ComputeScaleAndOrigin(); 
 546 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y 
) 
 548     m_externalDeviceOriginX 
= x
; 
 549     m_externalDeviceOriginY 
= y
; 
 550     ComputeScaleAndOrigin(); 
 554 void wxDC::SetInternalDeviceOrigin( long x
, long y 
) 
 556     m_internalDeviceOriginX 
= x
; 
 557     m_internalDeviceOriginY 
= y
; 
 558     ComputeScaleAndOrigin(); 
 560 void wxDC::GetInternalDeviceOrigin( long *x
, long *y 
) 
 562     if (x
) *x 
= m_internalDeviceOriginX
; 
 563     if (y
) *y 
= m_internalDeviceOriginY
; 
 567 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp 
) 
 569     m_signX 
= (xLeftRight 
?  1 : -1); 
 570     m_signY 
= (yBottomUp  
? -1 :  1); 
 571     ComputeScaleAndOrigin(); 
 574 wxSize 
wxDC::GetPPI() const 
 576     return wxSize(72, 72); 
 579 int wxDC::GetDepth() const 
 581     if ( IsPortColor( (CGrafPtr
) m_macPort 
) ) 
 583         return ( (**GetPortPixMap( (CGrafPtr
) m_macPort
)).pixelSize 
) ; 
 588 void wxDC::ComputeScaleAndOrigin() 
 590     // CMB: copy scale to see if it changes 
 591     double origScaleX 
= m_scaleX
; 
 592     double origScaleY 
= m_scaleY
; 
 593     m_scaleX 
= m_logicalScaleX 
* m_userScaleX
; 
 594     m_scaleY 
= m_logicalScaleY 
* m_userScaleY
; 
 595     m_deviceOriginX 
= m_internalDeviceOriginX 
+ m_externalDeviceOriginX
; 
 596     m_deviceOriginY 
= m_internalDeviceOriginY 
+ m_externalDeviceOriginY
; 
 597     // CMB: if scale has changed call SetPen to recalulate the line width 
 598     if (m_scaleX 
!= origScaleX 
|| m_scaleY 
!= origScaleY
) 
 600         // this is a bit artificial, but we need to force wxDC to think 
 601         // the pen has changed 
 602         wxPen
* pen 
= & GetPen(); 
 609 void  wxDC::SetPalette( const wxPalette
& palette 
) 
 613 void  wxDC::SetBackgroundMode( int mode 
) 
 615     m_backgroundMode 
= mode 
; 
 618 void  wxDC::SetFont( const wxFont 
&font 
) 
 621     m_macFontInstalled 
= false ; 
 624 void  wxDC::SetPen( const wxPen 
&pen 
) 
 629     m_macPenInstalled 
= false ; 
 632 void  wxDC::SetBrush( const wxBrush 
&brush 
) 
 634     if (m_brush 
== brush
) 
 637     m_macBrushInstalled 
= false ; 
 640 void  wxDC::SetBackground( const wxBrush 
&brush 
) 
 642     if (m_backgroundBrush 
== brush
) 
 644     m_backgroundBrush 
= brush
; 
 645     if (!m_backgroundBrush
.Ok()) 
 647     m_macBrushInstalled 
= false ; 
 650 void  wxDC::SetLogicalFunction( int function 
) 
 652     if (m_logicalFunction 
== function
) 
 654     m_logicalFunction 
= function 
; 
 655     m_macFontInstalled 
= false ; 
 656     m_macBrushInstalled 
= false ; 
 657     m_macPenInstalled 
= false ; 
 660 extern bool wxDoFloodFill(wxDC 
*dc
, wxCoord x
, wxCoord y
, 
 661                           const wxColour 
& col
, int style
); 
 663 bool wxDC::DoFloodFill(wxCoord x
, wxCoord y
, 
 664                        const wxColour
& col
, int style
) 
 666     return wxDoFloodFill(this, x
, y
, col
, style
); 
 669 bool  wxDC::DoGetPixel( wxCoord x
, wxCoord y
, wxColour 
*col 
) const 
 671     wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel  Invalid DC") ); 
 672     wxMacPortSetter 
helper(this) ; 
 674     GetCPixel( XLOG2DEVMAC(x
), YLOG2DEVMAC(y
), &colour 
); 
 675     // Convert from Mac colour to wx 
 676     col
->Set( colour
.red   
>> 8, 
 682 void  wxDC::DoDrawLine( wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2 
) 
 684     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
 685     wxMacPortSetter 
helper(this) ; 
 686     if (m_pen
.GetStyle() != wxTRANSPARENT
) 
 689         wxCoord offset 
= ( (m_pen
.GetWidth() == 0 ? 1 : 
 690         m_pen
.GetWidth() ) * (wxCoord
)m_scaleX 
- 1) / 2; 
 691         wxCoord xx1 
= XLOG2DEVMAC(x1
) - offset
; 
 692         wxCoord yy1 
= YLOG2DEVMAC(y1
) - offset
; 
 693         wxCoord xx2 
= XLOG2DEVMAC(x2
) - offset
; 
 694         wxCoord yy2 
= YLOG2DEVMAC(y2
) - offset
; 
 695         if ((m_pen
.GetCap() == wxCAP_ROUND
) && 
 696             (m_pen
.GetWidth() <= 1)) 
 698             // Implement LAST_NOT for MAC at least for 
 699             // orthogonal lines. RR. 
 720 void  wxDC::DoCrossHair( wxCoord x
, wxCoord y 
) 
 722     wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair  Invalid window dc") ); 
 723     wxMacPortSetter 
helper(this) ; 
 724     if (m_pen
.GetStyle() != wxTRANSPARENT
) 
 729         wxCoord xx 
= XLOG2DEVMAC(x
); 
 730         wxCoord yy 
= YLOG2DEVMAC(y
); 
 732         ::MoveTo( XLOG2DEVMAC(0), yy 
); 
 733         ::LineTo( XLOG2DEVMAC(w
), yy 
); 
 734         ::MoveTo( xx
, YLOG2DEVMAC(0) ); 
 735         ::LineTo( xx
, YLOG2DEVMAC(h
) ); 
 736         CalcBoundingBox(x
, y
); 
 737         CalcBoundingBox(x
+w
, y
+h
); 
 742 * To draw arcs properly the angles need to be converted from the WX style: 
 743 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on 
 744 * a normal axis on paper). 
 747 * Angles start on the +ve y axis and go clockwise. 
 750 static double wxConvertWXangleToMACangle(double angle
) 
 752     double newAngle 
= 90 - angle 
; 
 758 void  wxDC::DoDrawArc( wxCoord x1
, wxCoord y1
, 
 759                       wxCoord x2
, wxCoord y2
, 
 760                       wxCoord xc
, wxCoord yc 
) 
 762     wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc  Invalid DC")); 
 763     wxMacPortSetter 
helper(this) ; 
 764     wxCoord xx1 
= XLOG2DEVMAC(x1
); 
 765     wxCoord yy1 
= YLOG2DEVMAC(y1
); 
 766     wxCoord xx2 
= XLOG2DEVMAC(x2
); 
 767     wxCoord yy2 
= YLOG2DEVMAC(y2
); 
 768     wxCoord xxc 
= XLOG2DEVMAC(xc
); 
 769     wxCoord yyc 
= YLOG2DEVMAC(yc
); 
 770     double dx 
= xx1 
- xxc
; 
 771     double dy 
= yy1 
- yyc
; 
 772     double radius 
= sqrt((double)(dx
*dx
+dy
*dy
)); 
 773     wxCoord rad   
= (wxCoord
)radius
; 
 774     double radius1
, radius2
; 
 775     if (xx1 
== xx2 
&& yy1 
== yy2
) 
 780     else if (radius 
== 0.0) 
 782         radius1 
= radius2 
= 0.0; 
 786         radius1 
= (xx1 
- xxc 
== 0) ? 
 787             (yy1 
- yyc 
< 0) ? 90.0 : -90.0 : 
 788         -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
; 
 789         radius2 
= (xx2 
- xxc 
== 0) ? 
 790             (yy2 
- yyc 
< 0) ? 90.0 : -90.0 : 
 791         -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
; 
 793     wxCoord alpha2 
= wxCoord(radius2 
- radius1
); 
 794     wxCoord alpha1 
= wxCoord(wxConvertWXangleToMACangle(radius1
)); 
 795     if( (xx1 
> xx2
) || (yy1 
> yy2
) ) { 
 798     Rect r 
= { yyc 
- rad
, xxc 
- rad
, yyc 
+ rad
, xxc 
+ rad 
}; 
 799     if(m_brush
.GetStyle() != wxTRANSPARENT
) { 
 801         PaintArc(&r
, alpha1
, alpha2
); 
 803     if(m_pen
.GetStyle() != wxTRANSPARENT
) { 
 805         FrameArc(&r
, alpha1
, alpha2
); 
 809 void  wxDC::DoDrawEllipticArc( wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
, 
 810                               double sa
, double ea 
) 
 812     wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc  Invalid DC")); 
 813     wxMacPortSetter 
helper(this) ; 
 815     double angle 
= sa 
- ea
;  // Order important Mac in opposite direction to wx 
 816     // we have to make sure that the filling is always counter-clockwise 
 819     wxCoord xx 
= XLOG2DEVMAC(x
); 
 820     wxCoord yy 
= YLOG2DEVMAC(y
); 
 821     wxCoord ww 
= m_signX 
* XLOG2DEVREL(w
); 
 822     wxCoord hh 
= m_signY 
* YLOG2DEVREL(h
); 
 823     // handle -ve width and/or height 
 824     if (ww 
< 0) { ww 
= -ww
; xx 
= xx 
- ww
; } 
 825     if (hh 
< 0) { hh 
= -hh
; yy 
= yy 
- hh
; } 
 826     sa 
= wxConvertWXangleToMACangle(sa
); 
 831     if(m_brush
.GetStyle() != wxTRANSPARENT
) { 
 833         PaintArc(&r
, (short)sa
, (short)angle
); 
 835     if(m_pen
.GetStyle() != wxTRANSPARENT
) { 
 837         FrameArc(&r
, (short)sa
, (short)angle
); 
 841 void  wxDC::DoDrawPoint( wxCoord x
, wxCoord y 
) 
 843     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
 844     wxMacPortSetter 
helper(this) ; 
 845     if (m_pen
.GetStyle() != wxTRANSPARENT
) 
 847         wxCoord xx1 
= XLOG2DEVMAC(x
); 
 848         wxCoord yy1 
= YLOG2DEVMAC(y
); 
 849         RGBColor pencolor 
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel()); 
 850         ::SetCPixel( xx1
,yy1
,&pencolor
) ; 
 851         CalcBoundingBox(x
, y
); 
 855 void  wxDC::DoDrawLines(int n
, wxPoint points
[], 
 856                         wxCoord xoffset
, wxCoord yoffset
) 
 858     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
 859     wxMacPortSetter 
helper(this) ; 
 860     if (m_pen
.GetStyle() == wxTRANSPARENT
) 
 863     wxCoord offset 
= ( (m_pen
.GetWidth() == 0 ? 1 : 
 864     m_pen
.GetWidth() ) * (wxCoord
)m_scaleX 
- 1) / 2 ; 
 865     wxCoord x1
, x2 
, y1 
, y2 
; 
 866     x1 
= XLOG2DEVMAC(points
[0].x 
+ xoffset
); 
 867     y1 
= YLOG2DEVMAC(points
[0].y 
+ yoffset
); 
 868     ::MoveTo(x1 
- offset
, y1 
- offset 
); 
 869     for (int i 
= 0; i 
< n
-1; i
++) 
 871         x2 
= XLOG2DEVMAC(points
[i
+1].x 
+ xoffset
); 
 872         y2 
= YLOG2DEVMAC(points
[i
+1].y 
+ yoffset
); 
 873         ::LineTo( x2 
- offset
, y2 
- offset 
); 
 877 void  wxDC::DoDrawPolygon(int n
, wxPoint points
[], 
 878                           wxCoord xoffset
, wxCoord yoffset
, 
 881     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
 882     wxMacPortSetter 
helper(this) ; 
 883     wxCoord x1
, x2 
, y1 
, y2 
; 
 884     if ( m_brush
.GetStyle() == wxTRANSPARENT 
&& m_pen
.GetStyle() == wxTRANSPARENT 
) 
 886     PolyHandle polygon 
= OpenPoly(); 
 887     x2 
= x1 
= XLOG2DEVMAC(points
[0].x 
+ xoffset
); 
 888     y2 
= y1 
= YLOG2DEVMAC(points
[0].y 
+ yoffset
); 
 890     for (int i 
= 1; i 
< n
; i
++) 
 892         x2 
= XLOG2DEVMAC(points
[i
].x 
+ xoffset
); 
 893         y2 
= YLOG2DEVMAC(points
[i
].y 
+ yoffset
); 
 896     // close the polyline if necessary 
 897     if ( x1 
!= x2 
|| y1 
!= y2 
) 
 902     if (m_brush
.GetStyle() != wxTRANSPARENT
) 
 905         ::PaintPoly( polygon 
); 
 907     if (m_pen
.GetStyle() != wxTRANSPARENT
) 
 910         ::FramePoly( polygon 
) ; 
 915 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) 
 917     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
 918     wxMacPortSetter 
helper(this) ; 
 919     wxCoord xx 
= XLOG2DEVMAC(x
); 
 920     wxCoord yy 
= YLOG2DEVMAC(y
); 
 921     wxCoord ww 
= m_signX 
* XLOG2DEVREL(width
); 
 922     wxCoord hh 
= m_signY 
* YLOG2DEVREL(height
); 
 923     // CMB: draw nothing if transformed w or h is 0 
 924     if (ww 
== 0 || hh 
== 0) 
 926     // CMB: handle -ve width and/or height 
 937     Rect rect 
= { yy 
, xx 
, yy 
+ hh 
, xx 
+ ww 
} ; 
 938     if (m_brush
.GetStyle() != wxTRANSPARENT
) 
 941         ::PaintRect( &rect 
) ; 
 943     if (m_pen
.GetStyle() != wxTRANSPARENT
) 
 946         ::FrameRect( &rect 
) ; 
 950 void  wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, 
 951                                    wxCoord width
, wxCoord height
, 
 954     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
 955     wxMacPortSetter 
helper(this) ; 
 957         radius 
= - radius 
* ((width 
< height
) ? width 
: height
); 
 958     wxCoord xx 
= XLOG2DEVMAC(x
); 
 959     wxCoord yy 
= YLOG2DEVMAC(y
); 
 960     wxCoord ww 
= m_signX 
* XLOG2DEVREL(width
); 
 961     wxCoord hh 
= m_signY 
* YLOG2DEVREL(height
); 
 962     // CMB: draw nothing if transformed w or h is 0 
 963     if (ww 
== 0 || hh 
== 0) 
 965     // CMB: handle -ve width and/or height 
 976     Rect rect 
= { yy 
, xx 
, yy 
+ hh 
, xx 
+ ww 
} ; 
 977     if (m_brush
.GetStyle() != wxTRANSPARENT
) 
 980         ::PaintRoundRect( &rect 
, int(radius 
* 2) , int(radius 
* 2) ) ; 
 982     if (m_pen
.GetStyle() != wxTRANSPARENT
) 
 985         ::FrameRoundRect( &rect 
, int(radius 
* 2) , int(radius 
* 2) ) ; 
 989 void  wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) 
 991     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
 992     wxMacPortSetter 
helper(this) ; 
 993     wxCoord xx 
= XLOG2DEVMAC(x
); 
 994     wxCoord yy 
= YLOG2DEVMAC(y
); 
 995     wxCoord ww 
= m_signX 
* XLOG2DEVREL(width
); 
 996     wxCoord hh 
= m_signY 
* YLOG2DEVREL(height
); 
 997     // CMB: draw nothing if transformed w or h is 0 
 998     if (ww 
== 0 || hh 
== 0) 
1000     // CMB: handle -ve width and/or height 
1011     Rect rect 
= { yy 
, xx 
, yy 
+ hh 
, xx 
+ ww 
} ; 
1012     if (m_brush
.GetStyle() != wxTRANSPARENT
) 
1015         ::PaintOval( &rect 
) ; 
1017     if (m_pen
.GetStyle() != wxTRANSPARENT
) 
1020         ::FrameOval( &rect 
) ; 
1024 bool  wxDC::CanDrawBitmap(void) const 
1029 bool  wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
, 
1030                    wxDC 
*source
, wxCoord xsrc
, wxCoord ysrc
, int logical_func 
, bool useMask
, 
1031                    wxCoord xsrcMask
,  wxCoord ysrcMask 
) 
1033     wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc")); 
1034     wxCHECK_MSG(source
->Ok(), false, wxT("wxDC::DoBlit  Illegal source DC")); 
1035     if ( logical_func 
== wxNO_OP 
) 
1037     if (xsrcMask 
== -1 && ysrcMask 
== -1) 
1039         xsrcMask 
= xsrc
; ysrcMask 
= ysrc
; 
1041     // correct the parameter in case this dc does not have a mask at all 
1042     if ( useMask 
&& !source
->m_macMask 
) 
1044     Rect srcrect 
, dstrect 
; 
1045     srcrect
.top 
= source
->YLOG2DEVMAC(ysrc
) ; 
1046     srcrect
.left 
= source
->XLOG2DEVMAC(xsrc
)  ; 
1047     srcrect
.right 
= source
->XLOG2DEVMAC(xsrc 
+ width 
) ; 
1048     srcrect
.bottom 
= source
->YLOG2DEVMAC(ysrc 
+ height
) ; 
1049     dstrect
.top 
= YLOG2DEVMAC(ydest
) ; 
1050     dstrect
.left 
= XLOG2DEVMAC(xdest
) ; 
1051     dstrect
.bottom 
= YLOG2DEVMAC(ydest 
+ height 
)  ; 
1052     dstrect
.right 
= XLOG2DEVMAC(xdest 
+ width 
) ; 
1053     short mode 
= kUnsupportedMode 
; 
1054     bool invertDestinationFirst 
= false ; 
1055     switch ( logical_func 
) 
1057     case wxAND
:        // src AND dst 
1058         mode 
= adMin 
; // ok 
1060     case wxAND_INVERT
: // (NOT src) AND dst 
1061         mode 
= notSrcOr  
; // ok 
1063     case wxAND_REVERSE
:// src AND (NOT dst) 
1064         invertDestinationFirst 
= true ; 
1068         mode 
= kEmulatedMode 
; 
1071         mode 
= srcCopy 
; // ok 
1073     case wxEQUIV
:      // (NOT src) XOR dst 
1074         mode 
= srcXor 
; // ok 
1076     case wxINVERT
:     // NOT dst 
1077         mode 
= kEmulatedMode 
; //or hilite ; 
1079     case wxNAND
:       // (NOT src) OR (NOT dst) 
1080         invertDestinationFirst 
= true ; 
1083     case wxNOR
:        // (NOT src) AND (NOT dst) 
1084         invertDestinationFirst 
= true ; 
1087     case wxNO_OP
:      // dst 
1088         mode 
= kEmulatedMode 
; // this has already been handled upon entry 
1090     case wxOR
:         // src OR dst 
1093     case wxOR_INVERT
:  // (NOT src) OR dst 
1096     case wxOR_REVERSE
: // src OR (NOT dst) 
1097         invertDestinationFirst 
= true ; 
1101         mode 
= kEmulatedMode 
; 
1103     case wxSRC_INVERT
: // (NOT src) 
1104         mode 
= notSrcCopy 
; // ok 
1106     case wxXOR
:        // src XOR dst 
1107         mode 
= notSrcXor 
; // ok 
1112     if ( mode 
== kUnsupportedMode 
) 
1114         wxFAIL_MSG(wxT("unsupported blitting mode" )); 
1117     CGrafPtr            sourcePort 
= (CGrafPtr
) source
->m_macPort 
; 
1118     PixMapHandle    bmappixels 
=  GetGWorldPixMap( sourcePort 
) ; 
1119     if ( LockPixels(bmappixels
) ) 
1121         wxMacPortSetter 
helper(this) ; 
1122         if ( source
->GetDepth() == 1 ) 
1124             RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour
.GetPixel()) ) ; 
1125             RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour
.GetPixel()) ) ; 
1129             // the modes need this, otherwise we'll end up having really nice colors... 
1130             RGBColor    white 
= { 0xFFFF, 0xFFFF,0xFFFF} ; 
1131             RGBColor    black 
= { 0,0,0} ; 
1132             RGBForeColor( &black 
) ; 
1133             RGBBackColor( &white 
) ; 
1135         if ( useMask 
&& source
->m_macMask 
) 
1137             if ( mode 
== srcCopy 
) 
1139                 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ) 
1141                     CopyMask( GetPortBitMapForCopyBits( sourcePort 
) , 
1142                         GetPortBitMapForCopyBits( MAC_WXHBITMAP(source
->m_macMask
) ) , 
1143                         GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) , 
1144                         &srcrect
, &srcrect 
, &dstrect 
) ; 
1145                     UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) )  ) ; 
1150                 RgnHandle clipRgn 
= NewRgn() ; 
1151                 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ; 
1152                 BitMapToRegion( clipRgn 
, (BitMap
*) *GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ; 
1153                 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source
->m_macMask
) ) ) ; 
1154                 OffsetRgn( clipRgn 
, -srcrect
.left 
+ dstrect
.left
, -srcrect
.top 
+  dstrect
.top 
) ; 
1155                 if ( mode 
== kEmulatedMode 
) 
1158                     ::PenPat(GetQDGlobalsBlack(&pat
)); 
1159                     if ( logical_func 
== wxSET 
) 
1161                         RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ; 
1162                         ::RGBForeColor( &col  
) ; 
1163                         ::PaintRgn( clipRgn 
) ; 
1165                     else if ( logical_func 
== wxCLEAR 
) 
1167                         RGBColor col
= { 0x0000, 0x0000, 0x0000 } ; 
1168                         ::RGBForeColor( &col  
) ; 
1169                         ::PaintRgn( clipRgn 
) ; 
1171                     else if ( logical_func 
== wxINVERT 
) 
1173                         MacInvertRgn( clipRgn 
) ; 
1177                         for ( int y 
= 0 ; y 
< srcrect
.right 
- srcrect
.left 
; ++y 
) 
1179                             for ( int x 
= 0 ; x 
< srcrect
.bottom 
- srcrect
.top 
; ++x 
) 
1181                                 Point dstPoint 
= { dstrect
.top 
+ y 
, dstrect
.left 
+ x 
} ; 
1182                                 Point srcPoint 
= { srcrect
.top 
+ y 
, srcrect
.left 
+ x 
} ; 
1183                                 if ( PtInRgn( dstPoint 
, clipRgn 
) ) 
1187                                     SetPort( (GrafPtr
) sourcePort 
) ; 
1188                                     GetCPixel(  srcPoint
.h 
, srcPoint
.v 
, &srcColor
) ; 
1189                                     SetPort( (GrafPtr
) m_macPort 
) ; 
1190                                     GetCPixel( dstPoint
.h 
, dstPoint
.v 
, &dstColor 
) ; 
1191                                     wxMacCalculateColour( logical_func 
, srcColor 
,  dstColor 
) ; 
1192                                     SetCPixel( dstPoint
.h 
, dstPoint
.v 
, &dstColor 
) ; 
1200                     if ( invertDestinationFirst 
) 
1202                         MacInvertRgn( clipRgn 
) ; 
1204                     CopyBits( GetPortBitMapForCopyBits( sourcePort 
) , 
1205                         GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) , 
1206                         &srcrect
, &dstrect
, mode
, clipRgn 
) ; 
1208                 DisposeRgn( clipRgn 
) ; 
1213             RgnHandle clipRgn 
= NewRgn() ; 
1214             SetRectRgn( clipRgn 
, dstrect
.left 
, dstrect
.top 
, dstrect
.right 
, dstrect
.bottom 
) ; 
1215             if ( mode 
== kEmulatedMode 
) 
1218                 ::PenPat(GetQDGlobalsBlack(&pat
)); 
1219                 if ( logical_func 
== wxSET 
) 
1221                     RGBColor col
= { 0xFFFF, 0xFFFF, 0xFFFF } ; 
1222                     ::RGBForeColor( &col  
) ; 
1223                     ::PaintRgn( clipRgn 
) ; 
1225                 else if ( logical_func 
== wxCLEAR 
) 
1227                     RGBColor col
= { 0x0000, 0x0000, 0x0000 } ; 
1228                     ::RGBForeColor( &col  
) ; 
1229                     ::PaintRgn( clipRgn 
) ; 
1231                 else if ( logical_func 
== wxINVERT 
) 
1233                     MacInvertRgn( clipRgn 
) ; 
1237                     for ( int y 
= 0 ; y 
< srcrect
.right 
- srcrect
.left 
; ++y 
) 
1239                         for ( int x 
= 0 ; x 
< srcrect
.bottom 
- srcrect
.top 
; ++x 
) 
1241                             Point dstPoint 
= { dstrect
.top 
+ y 
, dstrect
.left 
+ x 
} ; 
1242                             Point srcPoint 
= { srcrect
.top 
+ y 
, srcrect
.left 
+ x 
} ; 
1246                                 SetPort( (GrafPtr
) sourcePort 
) ; 
1247                                 GetCPixel(  srcPoint
.h 
, srcPoint
.v 
, &srcColor
) ; 
1248                                 SetPort( (GrafPtr
) m_macPort 
) ; 
1249                                 GetCPixel( dstPoint
.h 
, dstPoint
.v 
, &dstColor 
) ; 
1250                                 wxMacCalculateColour( logical_func 
, srcColor 
,  dstColor 
) ; 
1251                                 SetCPixel( dstPoint
.h 
, dstPoint
.v 
, &dstColor 
) ; 
1259                 if ( invertDestinationFirst 
) 
1261                     MacInvertRgn( clipRgn 
) ; 
1263                 CopyBits( GetPortBitMapForCopyBits( sourcePort 
) , 
1264                     GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort
) ) , 
1265                     &srcrect
, &dstrect
, mode
, NULL 
) ; 
1267             DisposeRgn( clipRgn 
) ; 
1269         UnlockPixels( bmappixels 
) ; 
1271     m_macPenInstalled 
= false ; 
1272     m_macBrushInstalled 
= false ; 
1273     m_macFontInstalled 
= false ; 
1277 inline Fixed    
IntToFixed( int inInt 
) 
1279     return (((SInt32
) inInt
) << 16); 
1282 inline int    FixedToInt( Fixed inFixed 
) 
1284     return (((SInt32
) inFixed
) >> 16); 
1287 void  wxDC::DoDrawRotatedText(const wxString
& str
, wxCoord x
, wxCoord y
, 
1290     wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText  Invalid window dc") ); 
1293         DrawText(str
, x
, y
); 
1296     if ( str
.Length() == 0 ) 
1299     wxMacPortSetter 
helper(this) ; 
1302     wxFontRefData 
* font 
= (wxFontRefData
*) m_font
.GetRefData() ; 
1305         m_macFormerAliasState 
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
); 
1306         SetAntiAliasedTextEnabled(true, SInt16(m_scaleY 
* font
->m_macFontSize
)); 
1307         m_macAliasWasEnabled 
= true ; 
1309     OSStatus status 
= noErr 
; 
1310     ATSUTextLayout atsuLayout 
; 
1311     UniCharCount chars 
= str
.Length() ; 
1313     status 
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) (const wxChar
*) str 
, 0 , str
.Length() , str
.Length() , 1 , 
1314         &chars 
, (ATSUStyle
*) &m_macATSUIStyle 
, &atsuLayout 
) ; 
1317     status 
= TECCreateConverter(&ec
,  
1318         wxApp::s_macDefaultEncodingIsPC 
? kTextEncodingWindowsLatin1 
: kTextEncodingMacRoman
, kTextEncodingUnicodeDefault
); 
1320     wxASSERT_MSG( status 
== noErr 
, wxT("couldn't start converter") ) ; 
1321     ByteCount byteOutLen 
; 
1322     ByteCount byteInLen 
= str
.Length() ; 
1323     ByteCount byteBufferLen 
= byteInLen 
*2 ; 
1324     char* buf 
= new char[byteBufferLen
] ; 
1325     status 
= TECConvertText(ec
, (ConstTextPtr
)str
.c_str() , byteInLen
, &byteInLen
, 
1326         (TextPtr
)buf
, byteBufferLen
, &byteOutLen
); 
1327     wxASSERT_MSG( status 
== noErr 
, wxT("couldn't convert text") ) ; 
1328     status 
= TECDisposeConverter(ec
); 
1329     wxASSERT_MSG( status 
== noErr 
, wxT("couldn't dispose converter") ) ; 
1330     status 
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) buf 
, 0 , byteOutLen 
/ 2 , byteOutLen 
/ 2 , 1 , 
1331         &chars 
, (ATSUStyle
*) &m_macATSUIStyle 
, &atsuLayout 
) ; 
1333     wxASSERT_MSG( status 
== noErr 
, wxT("couldn't create the layout of the rotated text") ); 
1334     int iAngle 
= int( angle 
); 
1335     int drawX 
= XLOG2DEVMAC(x
) ; 
1336     int drawY 
= YLOG2DEVMAC(y
) ; 
1338     ATSUTextMeasurement textBefore 
; 
1339     ATSUTextMeasurement textAfter 
; 
1340     ATSUTextMeasurement ascent 
; 
1341     ATSUTextMeasurement descent 
; 
1344     if ( abs(iAngle
) > 0 ) 
1346         Fixed atsuAngle 
= IntToFixed( iAngle 
) ; 
1347         ATSUAttributeTag atsuTags
[] = 
1349             kATSULineRotationTag 
, 
1351         ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] = 
1355         ATSUAttributeValuePtr    atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] = 
1359         status 
= ::ATSUSetLayoutControls(atsuLayout 
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
), 
1360             atsuTags
, atsuSizes
, atsuValues 
) ; 
1362     status 
= ::ATSUMeasureText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
, 
1363         &textBefore 
, &textAfter
, &ascent 
, &descent 
); 
1365     drawX 
+= sin(angle
/RAD2DEG
) * FixedToInt(ascent
) ; 
1366     drawY 
+= cos(angle
/RAD2DEG
) * FixedToInt(ascent
) ; 
1367     status 
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
, 
1368         IntToFixed(drawX
) , IntToFixed(drawY
) ); 
1369     wxASSERT_MSG( status 
== noErr 
, wxT("couldn't draw the rotated text") ); 
1371     status 
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
, 
1372         IntToFixed(drawX
) , IntToFixed(drawY
) , &rect 
); 
1373     wxASSERT_MSG( status 
== noErr 
, wxT("couldn't measure the rotated text") ); 
1374     OffsetRect( &rect 
, -m_macLocalOrigin
.x 
, -m_macLocalOrigin
.y 
) ; 
1375     CalcBoundingBox(XDEV2LOG(rect
.left
), YDEV2LOG(rect
.top
) ); 
1376     CalcBoundingBox(XDEV2LOG(rect
.right
), YDEV2LOG(rect
.bottom
) ); 
1377     ::ATSUDisposeTextLayout(atsuLayout
); 
1384 void  wxDC::DoDrawText(const wxString
& strtext
, wxCoord x
, wxCoord y
) 
1386     wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText  Invalid DC")); 
1387     wxMacPortSetter 
helper(this) ; 
1388     long xx 
= XLOG2DEVMAC(x
); 
1389     long yy 
= YLOG2DEVMAC(y
); 
1391     bool useDrawThemeText 
= ( DrawThemeTextBox 
!= (void*) kUnresolvedCFragSymbolAddress 
) ; 
1392     if ( IsKindOf(CLASSINFO( wxPrinterDC 
) ) || m_font
.GetNoAntiAliasing() ) 
1393         useDrawThemeText 
= false ; 
1398         m_macFormerAliasState 
= IsAntiAliasedTextEnabled(&m_macFormerAliasSize
); 
1399         SetAntiAliasedTextEnabled(true, 8); 
1400         m_macAliasWasEnabled 
= true ; 
1403     ::GetFontInfo( &fi 
) ; 
1405     if ( !useDrawThemeText 
) 
1408     ::MoveTo( xx 
, yy 
); 
1409     if (  m_backgroundMode 
== wxTRANSPARENT 
) 
1411         ::TextMode( srcOr
) ; 
1415         ::TextMode( srcCopy 
) ; 
1417     int length 
= strtext
.Length() ; 
1425             if( strtext
[i
] == 13 || strtext
[i
] == 10) 
1427                 wxString linetext 
= strtext
.Mid( laststop 
, i 
- laststop 
) ; 
1429                 if ( useDrawThemeText 
) 
1431                     Rect frame 
= { yy 
+ line
*(fi
.descent 
+ fi
.ascent 
+ fi
.leading
)  ,xx 
, yy 
+ (line
+1)*(fi
.descent 
+ fi
.ascent 
+ fi
.leading
) , xx 
+ 10000 } ; 
1432                     wxMacCFStringHolder 
mString( linetext 
) ; 
1433                     if ( m_backgroundMode 
!= wxTRANSPARENT 
) 
1435                         Point bounds
={0,0} ; 
1436                         Rect background 
= frame 
; 
1438                         ::GetThemeTextDimensions( mString
, 
1439                             kThemeCurrentPortFont
, 
1444                         background
.right 
= background
.left 
+ bounds
.h 
; 
1445                         background
.bottom 
= background
.top 
+ bounds
.v 
; 
1446                         ::EraseRect( &background 
) ; 
1448                     ::DrawThemeTextBox( mString
, 
1449                         kThemeCurrentPortFont
, 
1460                                         wxCharBuffer text 
= wxMacStringToCString(linetext
) ;  
1461                     ::DrawText( text 
, 0 , strlen(text
) ) ; 
1463                     ::MoveTo( xx 
, yy 
+ line
*(fi
.descent 
+ fi
.ascent 
+ fi
.leading
) ); 
1469         wxString linetext 
= strtext
.Mid( laststop 
, i 
- laststop 
) ; 
1471         if ( useDrawThemeText 
) 
1473             Rect frame 
= { yy 
+ line
*(fi
.descent 
+ fi
.ascent 
+ fi
.leading
)  ,xx 
, yy 
+ (line
+1)*(fi
.descent 
+ fi
.ascent 
+ fi
.leading
) , xx 
+ 10000 } ; 
1474             wxMacCFStringHolder 
mString( linetext 
) ; 
1476             if ( m_backgroundMode 
!= wxTRANSPARENT 
) 
1478                 Point bounds
={0,0} ; 
1479                 Rect background 
= frame 
; 
1481                 ::GetThemeTextDimensions( mString
, 
1482                     kThemeCurrentPortFont
, 
1487                 background
.right 
= background
.left 
+ bounds
.h 
; 
1488                 background
.bottom 
= background
.top 
+ bounds
.v 
; 
1489                 ::EraseRect( &background 
) ; 
1491             ::DrawThemeTextBox( mString
, 
1492                 kThemeCurrentPortFont
, 
1502                         wxCharBuffer text 
= wxMacStringToCString(linetext
) ;  
1503             ::DrawText( text 
, 0 , strlen(text
) ) ; 
1506     ::TextMode( srcOr 
) ; 
1509 bool  wxDC::CanGetTextExtent() const 
1511     wxCHECK_MSG(Ok(), false, wxT("Invalid DC")); 
1515 void  wxDC::DoGetTextExtent( const wxString 
&strtext
, wxCoord 
*width
, wxCoord 
*height
, 
1516                             wxCoord 
*descent
, wxCoord 
*externalLeading 
, 
1517                             wxFont 
*theFont 
) const 
1519     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
1520     wxMacPortSetter 
helper(this) ; 
1521     wxFont formerFont 
= m_font 
; 
1524         // work around the constness 
1525         *((wxFont
*)(&m_font
)) = *theFont 
; 
1529     ::GetFontInfo( &fi 
) ; 
1531     bool useGetThemeText 
= ( GetThemeTextDimensions 
!= (void*) kUnresolvedCFragSymbolAddress 
) ; 
1532         if ( IsKindOf(CLASSINFO( wxPrinterDC 
) ) || ((wxFont
*)&m_font
)->GetNoAntiAliasing() ) 
1533         useGetThemeText 
= false ; 
1536         *height 
= YDEV2LOGREL( fi
.descent 
+ fi
.ascent 
) ; 
1538         *descent 
=YDEV2LOGREL( fi
.descent 
); 
1539     if ( externalLeading 
) 
1540         *externalLeading 
= YDEV2LOGREL( fi
.leading 
) ; 
1541     int length 
= strtext
.Length() ; 
1543     const char *text = NULL ; 
1545     if ( wxApp::s_macDefaultEncodingIsPC ) 
1547         macText = wxMacMakeMacStringFromPC( string ) ; 
1549         length = macText.Length() ; 
1554         length = string.Length() ; 
1565             if( strtext
[i
] == 13 || strtext
[i
] == 10) 
1567                 wxString linetext 
= strtext
.Mid( laststop 
, i 
- laststop 
) ; 
1569                     *height 
+= YDEV2LOGREL( fi
.descent 
+ fi
.ascent 
+ fi
.leading 
) ; 
1571                 if ( useGetThemeText 
) 
1573                     Point bounds
={0,0} ; 
1575                     wxMacCFStringHolder 
mString( linetext 
) ; 
1576                     ::GetThemeTextDimensions( mString
, 
1577                         kThemeCurrentPortFont
, 
1582                     curwidth 
= bounds
.h 
; 
1587                                         wxCharBuffer text 
= wxMacStringToCString(linetext
) ;  
1588                         curwidth 
= ::TextWidth( text 
, 0 , strlen(text
) ) ; 
1590                 if ( curwidth 
> *width 
) 
1591                     *width 
= XDEV2LOGREL( curwidth 
) ; 
1597         wxString linetext 
= strtext
.Mid( laststop 
, i 
- laststop 
) ; 
1599         if ( useGetThemeText 
) 
1601             Point bounds
={0,0} ; 
1603             wxMacCFStringHolder 
mString( linetext 
) ; 
1604             ::GetThemeTextDimensions( mString
, 
1605                 kThemeCurrentPortFont
, 
1610             curwidth 
= bounds
.h 
; 
1615                         wxCharBuffer text 
= wxMacStringToCString(linetext
) ;  
1616             curwidth 
= ::TextWidth( text 
, 0 , strlen(text
) ) ; 
1618         if ( curwidth 
> *width 
) 
1619             *width 
= XDEV2LOGREL( curwidth 
) ; 
1623         // work around the constness 
1624         *((wxFont
*)(&m_font
)) = formerFont 
; 
1625         m_macFontInstalled 
= false ; 
1629 wxCoord   
wxDC::GetCharWidth(void) const 
1631     wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); 
1632     wxMacPortSetter 
helper(this) ; 
1636     bool useGetThemeText 
= ( GetThemeTextDimensions 
!= (void*) kUnresolvedCFragSymbolAddress 
) ; 
1637     if ( ((wxFont
*)&m_font
)->GetNoAntiAliasing() ) 
1638         useGetThemeText 
= false ; 
1642     if ( useGetThemeText 
) 
1644         Point bounds
={0,0} ; 
1646         CFStringRef mString 
= CFStringCreateWithBytes( NULL 
, (UInt8
*) text 
, 1 , CFStringGetSystemEncoding(), false ) ; 
1647         ::GetThemeTextDimensions( mString
, 
1648             kThemeCurrentPortFont
, 
1653         CFRelease( mString 
) ; 
1659         width 
= ::TextWidth( text 
, 0 , 1 ) ; 
1661     return YDEV2LOGREL(width
) ; 
1664 wxCoord   
wxDC::GetCharHeight(void) const 
1666     wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); 
1667     wxMacPortSetter 
helper(this) ; 
1670     ::GetFontInfo( &fi 
) ; 
1671     return YDEV2LOGREL( fi
.descent 
+ fi
.ascent 
); 
1674 void  wxDC::Clear(void) 
1676     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
1677     wxMacPortSetter 
helper(this) ; 
1678     Rect rect 
= { -31000 , -31000 , 31000 , 31000 } ; 
1679     if (m_backgroundBrush
.GetStyle() != wxTRANSPARENT
) 
1682         //MacInstallBrush() ; 
1683         MacSetupBackgroundForCurrentPort( m_backgroundBrush 
) ; 
1684         ::EraseRect( &rect 
) ; 
1688 void wxDC::MacInstallFont() const 
1690     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
1691     //    if ( m_macFontInstalled ) 
1693     Pattern blackColor 
; 
1694     MacSetupBackgroundForCurrentPort(m_backgroundBrush
) ; 
1695     wxFontRefData 
* font 
= (wxFontRefData
*) m_font
.GetRefData() ; 
1698         ::TextFont( font
->m_macFontNum 
) ; 
1699         ::TextSize( short(m_scaleY 
* font
->m_macFontSize
) ) ; 
1700         ::TextFace( font
->m_macFontStyle 
) ; 
1701         m_macFontInstalled 
= true ; 
1702         m_macBrushInstalled 
= false ; 
1703         m_macPenInstalled 
= false ; 
1704         RGBColor forecolor 
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()); 
1705         RGBColor backcolor 
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()); 
1706         ::RGBForeColor( &forecolor 
); 
1707         ::RGBBackColor( &backcolor 
); 
1711         FontFamilyID fontId 
; 
1715         GetThemeFont(kThemeSmallSystemFont 
, GetApplicationScript() , fontName 
, &fontSize 
, &fontStyle 
) ; 
1716         GetFNum( fontName
, &fontId 
); 
1717         ::TextFont( fontId 
) ; 
1718         ::TextSize( short(m_scaleY 
* fontSize
) ) ; 
1719         ::TextFace( fontStyle 
) ; 
1720         // todo reset after spacing changes - or store the current spacing somewhere 
1721         m_macFontInstalled 
= true ; 
1722         m_macBrushInstalled 
= false ; 
1723         m_macPenInstalled 
= false ; 
1724         RGBColor forecolor 
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()); 
1725         RGBColor backcolor 
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()); 
1726         ::RGBForeColor( &forecolor 
); 
1727         ::RGBBackColor( &backcolor 
); 
1729     short mode 
= patCopy 
; 
1731     switch( m_logicalFunction 
) 
1736     case wxINVERT
:     // NOT dst 
1737         ::PenPat(GetQDGlobalsBlack(&blackColor
)); 
1740     case wxXOR
:        // src XOR dst 
1743     case wxOR_REVERSE
: // src OR (NOT dst) 
1746     case wxSRC_INVERT
: // (NOT src) 
1749     case wxAND
: // src AND dst 
1754     case wxAND_REVERSE
:// src AND (NOT dst) 
1755     case wxAND_INVERT
: // (NOT src) AND dst 
1756     case wxNO_OP
:      // dst 
1757     case wxNOR
:        // (NOT src) AND (NOT dst) 
1758     case wxEQUIV
:      // (NOT src) XOR dst 
1759     case wxOR_INVERT
:  // (NOT src) OR dst 
1760     case wxNAND
:       // (NOT src) OR (NOT dst) 
1761     case wxOR
:         // src OR dst 
1763         //        case wxSRC_OR:     // source _bitmap_ OR destination 
1764         //        case wxSRC_AND:     // source _bitmap_ AND destination 
1768     OSStatus status 
= noErr 
; 
1769     Fixed atsuSize 
= IntToFixed( int(m_scaleY 
* font
->m_macFontSize
) ) ; 
1770     Style qdStyle 
= font
->m_macFontStyle 
; 
1771     ATSUFontID    atsuFont 
= font
->m_macATSUFontID 
; 
1772     status 
= ::ATSUCreateStyle(&(ATSUStyle
)m_macATSUIStyle
) ; 
1773     wxASSERT_MSG( status 
== noErr 
, wxT("couldn't create ATSU style") ) ; 
1774     ATSUAttributeTag atsuTags
[] = 
1779             //        kATSUBaselineClassTag , 
1780             kATSUVerticalCharacterTag
, 
1781             kATSUQDBoldfaceTag 
, 
1783             kATSUQDUnderlineTag 
, 
1784             kATSUQDCondensedTag 
, 
1785             kATSUQDExtendedTag 
, 
1787     ByteCount atsuSizes
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] = 
1789         sizeof( ATSUFontID 
) , 
1791             //        sizeof( RGBColor ) , 
1792             //        sizeof( BslnBaselineClass ) , 
1793             sizeof( ATSUVerticalCharacterType
), 
1800     Boolean kTrue 
= true ; 
1801     Boolean kFalse 
= false ; 
1802     BslnBaselineClass kBaselineDefault 
= kBSLNHangingBaseline 
; 
1803     ATSUVerticalCharacterType kHorizontal 
= kATSUStronglyHorizontal
; 
1804     ATSUAttributeValuePtr    atsuValues
[sizeof(atsuTags
)/sizeof(ATSUAttributeTag
)] = 
1808             //        &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) , 
1809             //        &kBaselineDefault , 
1811             (qdStyle 
& bold
) ? &kTrue 
: &kFalse 
, 
1812             (qdStyle 
& italic
) ? &kTrue 
: &kFalse 
, 
1813             (qdStyle 
& underline
) ? &kTrue 
: &kFalse 
, 
1814             (qdStyle 
& condense
) ? &kTrue 
: &kFalse 
, 
1815             (qdStyle 
& extend
) ? &kTrue 
: &kFalse 
, 
1817     status 
= ::ATSUSetAttributes((ATSUStyle
)m_macATSUIStyle
, sizeof(atsuTags
)/sizeof(ATSUAttributeTag
), 
1818         atsuTags
, atsuSizes
, atsuValues
); 
1819     wxASSERT_MSG( status 
== noErr 
, wxT("couldn't set create ATSU style") ) ; 
1822 Pattern gHatchPatterns
[] = 
1824     { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } }, 
1825     { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } }, 
1826     { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } }, 
1827     { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } }, 
1828     { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } }, 
1829     { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } }, 
1830     { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } }  
1833 static void wxMacGetHatchPattern(int hatchStyle
, Pattern 
*pattern
) 
1838     case wxBDIAGONAL_HATCH
: 
1841     case wxFDIAGONAL_HATCH
: 
1847     case wxHORIZONTAL_HATCH
: 
1850     case wxVERTICAL_HATCH
: 
1853     case wxCROSSDIAG_HATCH
: 
1857         theIndex 
= 1; // solid pattern 
1860     *pattern 
= gHatchPatterns
[theIndex
-1] ; 
1863 void wxDC::MacInstallPen() const 
1865     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
1867     //    if ( m_macPenInstalled ) 
1869     RGBColor forecolor 
= MAC_WXCOLORREF( m_pen
.GetColour().GetPixel()); 
1870     RGBColor backcolor 
= MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()); 
1871     ::RGBForeColor( &forecolor 
); 
1872     ::RGBBackColor( &backcolor 
); 
1874     int penWidth 
= m_pen
.GetWidth() * (int) m_scaleX 
; 
1875     // null means only one pixel, at whatever resolution 
1876     if ( penWidth 
== 0 ) 
1878     ::PenSize(penWidth
, penWidth
); 
1879     int penStyle 
= m_pen
.GetStyle(); 
1880     if (penStyle 
== wxSOLID
) 
1882         ::PenPat(GetQDGlobalsBlack(&blackColor
)); 
1884     else if (IS_HATCH(penStyle
)) 
1887         wxMacGetHatchPattern(penStyle
, &pat
); 
1892         Pattern pat 
= *GetQDGlobalsBlack(&blackColor
) ; 
1896             for ( int i 
= 0 ; i 
< 8 ; ++i 
) 
1902             for ( int i 
= 0 ; i 
< 8 ; ++i 
) 
1908             for ( int i 
= 0 ; i 
< 8 ; ++i 
) 
1914             for ( int i 
= 0 ; i 
< 8 ; ++i 
) 
1922                 m_pen
.GetDashes(&dash
) ; 
1923                 // right now we don't allocate larger pixmaps 
1925                 m_pen
.GetDashes(&dash
) ; 
1926                 for ( int i 
= 0 ; i 
< 8 ; ++i 
) 
1928                     pat
.pat
[i
] = dash
[0] ; 
1935     short mode 
= patCopy 
; 
1937     switch( m_logicalFunction 
) 
1939     case wxCOPY
:       // only foreground color, leave background (thus not patCopy) 
1942     case wxINVERT
:     // NOT dst 
1943         //            ::PenPat(GetQDGlobalsBlack(&blackColor)); 
1946     case wxXOR
:        // src XOR dst 
1949     case wxOR_REVERSE
: // src OR (NOT dst) 
1952     case wxSRC_INVERT
: // (NOT src) 
1955     case wxAND
: // src AND dst 
1960     case wxAND_REVERSE
:// src AND (NOT dst) 
1961     case wxAND_INVERT
: // (NOT src) AND dst 
1962     case wxNO_OP
:      // dst 
1963     case wxNOR
:        // (NOT src) AND (NOT dst) 
1964     case wxEQUIV
:      // (NOT src) XOR dst 
1965     case wxOR_INVERT
:  // (NOT src) OR dst 
1966     case wxNAND
:       // (NOT src) OR (NOT dst) 
1967     case wxOR
:         // src OR dst 
1969         //        case wxSRC_OR:     // source _bitmap_ OR destination 
1970         //        case wxSRC_AND:     // source _bitmap_ AND destination 
1974     m_macPenInstalled 
= true ; 
1975     m_macBrushInstalled 
= false ; 
1976     m_macFontInstalled 
= false ; 
1979 void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush
& background 
) 
1981     Pattern whiteColor 
; 
1982     switch( background
.MacGetBrushKind() ) 
1984     case kwxMacBrushTheme 
: 
1986             ::SetThemeBackground( background
.GetMacTheme() , wxDisplayDepth() , true ) ; 
1989     case kwxMacBrushThemeBackground 
: 
1992             ThemeBackgroundKind bg 
= background
.GetMacThemeBackground( &extent 
) ; 
1993             ::ApplyThemeBackground( bg 
, &extent 
,kThemeStateActive 
, wxDisplayDepth() , true ) ; 
1996     case kwxMacBrushColour 
: 
1998                ::RGBBackColor( &MAC_WXCOLORREF( background
.GetColour().GetPixel()) ); 
1999             int brushStyle 
= background
.GetStyle(); 
2000             if (brushStyle 
== wxSOLID
) 
2001                 ::BackPat(GetQDGlobalsWhite(&whiteColor
)); 
2002             else if (IS_HATCH(brushStyle
)) 
2005                 wxMacGetHatchPattern(brushStyle
, &pat
); 
2010                 ::BackPat(GetQDGlobalsWhite(&whiteColor
)); 
2017 void wxDC::MacInstallBrush() const 
2019     wxCHECK_RET(Ok(), wxT("Invalid DC")); 
2020     Pattern     blackColor 
; 
2021     //    if ( m_macBrushInstalled ) 
2024     bool backgroundTransparent 
= (GetBackgroundMode() == wxTRANSPARENT
) ; 
2025     ::RGBForeColor( &MAC_WXCOLORREF( m_brush
.GetColour().GetPixel()) ); 
2026     ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush
.GetColour().GetPixel()) ); 
2027     int brushStyle 
= m_brush
.GetStyle(); 
2028     if (brushStyle 
== wxSOLID
) 
2030         ::PenPat(GetQDGlobalsBlack(&blackColor
)); 
2032     else if (IS_HATCH(brushStyle
)) 
2035         wxMacGetHatchPattern(brushStyle
, &pat
); 
2038     else if ( m_brush
.GetStyle() == wxSTIPPLE 
|| m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE 
) 
2040         // we force this in order to be compliant with wxMSW 
2041         backgroundTransparent 
= false ; 
2042         // for these the text fore (and back for MASK_OPAQUE) colors are used 
2043         wxBitmap
* bitmap 
= m_brush
.GetStipple() ; 
2044         int width 
= bitmap
->GetWidth() ; 
2045         int height 
= bitmap
->GetHeight() ; 
2046         GWorldPtr gw 
= NULL 
; 
2047         if ( m_brush
.GetStyle() == wxSTIPPLE 
) 
2048             gw 
= MAC_WXHBITMAP(bitmap
->GetHBITMAP())  ; 
2050             gw 
= MAC_WXHBITMAP(bitmap
->GetMask()->GetMaskBitmap()) ; 
2051         PixMapHandle gwpixmaphandle 
= GetGWorldPixMap( gw 
) ; 
2052         LockPixels( gwpixmaphandle 
) ; 
2053         bool isMonochrome 
= !IsPortColor( gw 
) ; 
2054         if ( !isMonochrome 
) 
2056             if ( (**gwpixmaphandle
).pixelSize 
== 1 ) 
2057                 isMonochrome 
= true ; 
2059         if ( isMonochrome 
&& width 
== 8 && height 
== 8 ) 
2061             ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ); 
2062             ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ); 
2063             BitMap
* gwbitmap 
= (BitMap
*) *gwpixmaphandle 
; // since the color depth is 1 it is a BitMap 
2064             UInt8 
*gwbits 
= (UInt8
*) gwbitmap
->baseAddr 
; 
2065             int alignment 
= gwbitmap
->rowBytes 
& 0x7FFF ; 
2067             for ( int i 
= 0 ; i 
< 8 ; ++i 
) 
2069                 pat
.pat
[i
] = gwbits
[i
*alignment
+0] ; 
2071             UnlockPixels( GetGWorldPixMap( gw 
) ) ; 
2076             // this will be the code to handle power of 2 patterns, we will have to arrive at a nice 
2077             // caching scheme before putting this into production 
2080             PixPatHandle pixpat 
= NewPixPat() ; 
2081             CopyPixMap(gwpixmaphandle
, (**pixpat
).patMap
); 
2082             imageSize 
= GetPixRowBytes((**pixpat
).patMap
) * 
2083                 ((**(**pixpat
).patMap
).bounds
.bottom 
- 
2084                 (**(**pixpat
).patMap
).bounds
.top
); 
2085             PtrToHand( (**gwpixmaphandle
).baseAddr
, &image
, imageSize 
); 
2086             (**pixpat
).patData 
= image
; 
2089                 CTabHandle ctable 
= ((**((**pixpat
).patMap
)).pmTable
) ; 
2090                 ColorSpecPtr ctspec 
= (ColorSpecPtr
) &(**ctable
).ctTable 
; 
2091                 if ( ctspec
[0].rgb
.red 
== 0x0000 ) 
2093                     ctspec
[1].rgb 
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ; 
2094                     ctspec
[0].rgb 
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ; 
2098                     ctspec
[0].rgb 
= MAC_WXCOLORREF( m_textBackgroundColour
.GetPixel()) ; 
2099                     ctspec
[1].rgb 
= MAC_WXCOLORREF( m_textForegroundColour
.GetPixel()) ; 
2101                 ::CTabChanged( ctable 
) ; 
2103             ::PenPixPat(pixpat
); 
2104             m_macForegroundPixMap 
= pixpat 
; 
2106         UnlockPixels( gwpixmaphandle 
) ; 
2110         ::PenPat(GetQDGlobalsBlack(&blackColor
)); 
2112     short mode 
= patCopy 
; 
2113     switch( m_logicalFunction 
) 
2116         if ( backgroundTransparent 
) 
2121     case wxINVERT
:     // NOT dst 
2122         if ( !backgroundTransparent 
) 
2124             ::PenPat(GetQDGlobalsBlack(&blackColor
)); 
2128     case wxXOR
:        // src XOR dst 
2131     case wxOR_REVERSE
: // src OR (NOT dst) 
2134     case wxSRC_INVERT
: // (NOT src) 
2137     case wxAND
: // src AND dst 
2142     case wxAND_REVERSE
:// src AND (NOT dst) 
2143     case wxAND_INVERT
: // (NOT src) AND dst 
2144     case wxNO_OP
:      // dst 
2145     case wxNOR
:        // (NOT src) AND (NOT dst) 
2146     case wxEQUIV
:      // (NOT src) XOR dst 
2147     case wxOR_INVERT
:  // (NOT src) OR dst 
2148     case wxNAND
:       // (NOT src) OR (NOT dst) 
2149     case wxOR
:         // src OR dst 
2151         //        case wxSRC_OR:     // source _bitmap_ OR destination 
2152         //        case wxSRC_AND:     // source _bitmap_ AND destination 
2156     m_macBrushInstalled 
= true ; 
2157     m_macPenInstalled 
= false ; 
2158     m_macFontInstalled 
= false ; 
2161 // --------------------------------------------------------------------------- 
2162 // coordinates transformations 
2163 // --------------------------------------------------------------------------- 
2165 wxCoord 
wxDCBase::DeviceToLogicalX(wxCoord x
) const 
2167     return ((wxDC 
*)this)->XDEV2LOG(x
); 
2170 wxCoord 
wxDCBase::DeviceToLogicalY(wxCoord y
) const 
2172     return ((wxDC 
*)this)->YDEV2LOG(y
); 
2175 wxCoord 
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const 
2177     return ((wxDC 
*)this)->XDEV2LOGREL(x
); 
2180 wxCoord 
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const 
2182     return ((wxDC 
*)this)->YDEV2LOGREL(y
); 
2185 wxCoord 
wxDCBase::LogicalToDeviceX(wxCoord x
) const 
2187     return ((wxDC 
*)this)->XLOG2DEV(x
); 
2190 wxCoord 
wxDCBase::LogicalToDeviceY(wxCoord y
) const 
2192     return ((wxDC 
*)this)->YLOG2DEV(y
); 
2195 wxCoord 
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const 
2197     return ((wxDC 
*)this)->XLOG2DEVREL(x
); 
2200 wxCoord 
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const 
2202     return ((wxDC 
*)this)->YLOG2DEVREL(y
);