]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dc.cpp
switching to safe yields, because we got into loops when handling print document...
[wxWidgets.git] / src / mac / carbon / dc.cpp
CommitLineData
2ac013b1 1/////////////////////////////////////////////////////////////////////////////
e9576ca5
SC
2// Name: dc.cpp
3// Purpose: wxDC class
4// Author: AUTHOR
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
e9576ca5
SC
11#ifdef __GNUG__
12#pragma implementation "dc.h"
13#endif
e9576ca5 14#include "wx/dc.h"
03e11df5 15#include "wx/app.h"
2f1ae414 16#include "wx/mac/uma.h"
3dec57ad
SC
17#include "wx/dcmemory.h"
18#include "wx/region.h"
19#include "wx/image.h"
b1699cd3 20#include "wx/log.h"
e9576ca5 21
5b781a67
SC
22#if __MSL__ >= 0x6000
23#include "math.h"
b34039cf 24using namespace std ;
5b781a67 25#endif
b34039cf 26#include "wx/mac/private.h"
66a09d47
SC
27#include "ATSUnicode.h"
28#include "TextCommon.h"
29#include "TextEncodingConverter.h"
2f1ae414 30#if !USE_SHARED_LIBRARY
e9576ca5 31IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
2f1ae414 32#endif
e9576ca5
SC
33//-----------------------------------------------------------------------------
34// constants
35//-----------------------------------------------------------------------------
e9576ca5
SC
36#define mm2inches 0.0393700787402
37#define inches2mm 25.4
38#define mm2twips 56.6929133859
39#define twips2mm 0.0176388888889
40#define mm2pt 2.83464566929
41#define pt2mm 0.352777777778
f5c6eb5c 42#ifndef __DARWIN__
3dec57ad 43const double M_PI = 3.14159265358979 ;
2461b2e7 44#endif
3dec57ad 45const double RAD2DEG = 180.0 / M_PI;
76a5e5d2
SC
46const short kEmulatedMode = -1 ;
47const short kUnsupportedMode = -2 ;
66a09d47 48wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) :
99030bdf 49 m_ph( (GrafPtr) dc->m_macPort )
66a09d47
SC
50{
51 wxASSERT( dc->Ok() ) ;
52 m_dc = dc ;
53 dc->MacSetupPort(&m_ph) ;
54}
99030bdf 55wxMacPortSetter::~wxMacPortSetter()
66a09d47
SC
56{
57 m_dc->MacCleanupPort(&m_ph) ;
58}
15cae9eb
SC
59wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win )
60{
61 m_formerClip = NewRgn() ;
62 m_newClip = NewRgn() ;
63 GetClip( m_formerClip ) ;
64
65 if ( win )
66 {
67 RgnHandle insidergn = NewRgn() ;
68 int x = 0 , y = 0;
69 wxWindow *parent = win->GetParent() ;
70 parent->MacWindowToRootWindow( &x,&y ) ;
15cae9eb
SC
71 wxSize size = parent->GetSize() ;
72 SetRectRgn( insidergn , parent->MacGetLeftBorderSize() , parent->MacGetTopBorderSize() ,
f1872c18
SC
73 size.x - parent->MacGetRightBorderSize(),
74 size.y - parent->MacGetBottomBorderSize()) ;
15cae9eb
SC
75 CopyRgn( (RgnHandle) parent->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip ) ;
76 SectRgn( m_newClip , insidergn , m_newClip ) ;
77 OffsetRgn( m_newClip , x , y ) ;
78 SetClip( m_newClip ) ;
79 DisposeRgn( insidergn ) ;
80 }
81}
15cae9eb
SC
82wxMacWindowClipper::~wxMacWindowClipper()
83{
84 SetClip( m_formerClip ) ;
85 DisposeRgn( m_newClip ) ;
86 DisposeRgn( m_formerClip ) ;
87}
3dec57ad
SC
88//-----------------------------------------------------------------------------
89// Local functions
90//-----------------------------------------------------------------------------
3dec57ad
SC
91static inline double dmin(double a, double b) { return a < b ? a : b; }
92static inline double dmax(double a, double b) { return a > b ? a : b; }
93static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
e9576ca5
SC
94//-----------------------------------------------------------------------------
95// wxDC
96//-----------------------------------------------------------------------------
76a5e5d2
SC
97// this function emulates all wx colour manipulations, used to verify the implementation
98// by setting the mode in the blitting functions to kEmulatedMode
76a5e5d2
SC
99void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor ) ;
100void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor )
101{
102 switch ( logical_func )
103 {
104 case wxAND: // src AND dst
105 dstColor.red = dstColor.red & srcColor.red ;
106 dstColor.green = dstColor.green & srcColor.green ;
107 dstColor.blue = dstColor.blue & srcColor.blue ;
108 break ;
109 case wxAND_INVERT: // (NOT src) AND dst
110 dstColor.red = dstColor.red & ~srcColor.red ;
111 dstColor.green = dstColor.green & ~srcColor.green ;
112 dstColor.blue = dstColor.blue & ~srcColor.blue ;
113 break ;
114 case wxAND_REVERSE:// src AND (NOT dst)
115 dstColor.red = ~dstColor.red & srcColor.red ;
116 dstColor.green = ~dstColor.green & srcColor.green ;
117 dstColor.blue = ~dstColor.blue & srcColor.blue ;
118 break ;
119 case wxCLEAR: // 0
120 dstColor.red = 0 ;
121 dstColor.green = 0 ;
122 dstColor.blue = 0 ;
123 break ;
124 case wxCOPY: // src
125 dstColor.red = srcColor.red ;
126 dstColor.green = srcColor.green ;
127 dstColor.blue = srcColor.blue ;
128 break ;
129 case wxEQUIV: // (NOT src) XOR dst
130 dstColor.red = dstColor.red ^ ~srcColor.red ;
131 dstColor.green = dstColor.green ^ ~srcColor.green ;
132 dstColor.blue = dstColor.blue ^ ~srcColor.blue ;
133 break ;
134 case wxINVERT: // NOT dst
135 dstColor.red = ~dstColor.red ;
136 dstColor.green = ~dstColor.green ;
137 dstColor.blue = ~dstColor.blue ;
138 break ;
139 case wxNAND: // (NOT src) OR (NOT dst)
140 dstColor.red = ~dstColor.red | ~srcColor.red ;
141 dstColor.green = ~dstColor.green | ~srcColor.green ;
142 dstColor.blue = ~dstColor.blue | ~srcColor.blue ;
143 break ;
144 case wxNOR: // (NOT src) AND (NOT dst)
145 dstColor.red = ~dstColor.red & ~srcColor.red ;
146 dstColor.green = ~dstColor.green & ~srcColor.green ;
147 dstColor.blue = ~dstColor.blue & ~srcColor.blue ;
148 break ;
149 case wxNO_OP: // dst
150 break ;
151 case wxOR: // src OR dst
152 dstColor.red = dstColor.red | srcColor.red ;
153 dstColor.green = dstColor.green | srcColor.green ;
154 dstColor.blue = dstColor.blue | srcColor.blue ;
155 break ;
156 case wxOR_INVERT: // (NOT src) OR dst
157 dstColor.red = dstColor.red | ~srcColor.red ;
158 dstColor.green = dstColor.green | ~srcColor.green ;
159 dstColor.blue = dstColor.blue | ~srcColor.blue ;
160 break ;
161 case wxOR_REVERSE: // 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 ;
165 break ;
166 case wxSET: // 1
167 dstColor.red = 0xFFFF ;
168 dstColor.green = 0xFFFF ;
169 dstColor.blue = 0xFFFF ;
170 break ;
171 case wxSRC_INVERT: // (NOT src)
172 dstColor.red = ~srcColor.red ;
173 dstColor.green = ~srcColor.green ;
174 dstColor.blue = ~srcColor.blue ;
175 break ;
176 case wxXOR: // src XOR dst
177 dstColor.red = dstColor.red ^ srcColor.red ;
178 dstColor.green = dstColor.green ^ srcColor.green ;
179 dstColor.blue = dstColor.blue ^ srcColor.blue ;
180 break ;
181 }
76a5e5d2 182}
2f1ae414 183wxDC::wxDC()
e9576ca5
SC
184{
185 m_ok = FALSE;
e9576ca5 186 m_colour = TRUE;
2f1ae414
SC
187 m_mm_to_pix_x = mm2pt;
188 m_mm_to_pix_y = mm2pt;
e9576ca5
SC
189 m_internalDeviceOriginX = 0;
190 m_internalDeviceOriginY = 0;
191 m_externalDeviceOriginX = 0;
192 m_externalDeviceOriginY = 0;
e9576ca5
SC
193 m_logicalScaleX = 1.0;
194 m_logicalScaleY = 1.0;
195 m_userScaleX = 1.0;
196 m_userScaleY = 1.0;
197 m_scaleX = 1.0;
198 m_scaleY = 1.0;
e9576ca5
SC
199 m_needComputeScaleX = FALSE;
200 m_needComputeScaleY = FALSE;
519cb848 201 m_macPort = NULL ;
8208e181 202 m_macMask = NULL ;
519cb848 203 m_ok = FALSE ;
519cb848
SC
204 m_macFontInstalled = false ;
205 m_macBrushInstalled = false ;
206 m_macPenInstalled = false ;
76a5e5d2 207 m_macLocalOrigin.x = m_macLocalOrigin.y = 0 ;
ffba56ed
SC
208 m_macBoundaryClipRgn = NewRgn() ;
209 m_macCurrentClipRgn = NewRgn() ;
76a5e5d2
SC
210 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
211 SetRectRgn( (RgnHandle) m_macCurrentClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
9ff647cf
SC
212 m_pen = *wxBLACK_PEN;
213 m_font = *wxNORMAL_FONT;
214 m_brush = *wxWHITE_BRUSH;
66a09d47
SC
215 m_macCurrentPortStateHelper = NULL ;
216 m_macATSUIStyle = NULL ;
217 m_macAliasWasEnabled = false;
218 m_macForegroundPixMap = NULL ;
219 m_macBackgroundPixMap = NULL ;
0eaa1d68 220}
e9576ca5
SC
221wxDC::~wxDC(void)
222{
76a5e5d2
SC
223 DisposeRgn( (RgnHandle) m_macBoundaryClipRgn ) ;
224 DisposeRgn( (RgnHandle) m_macCurrentClipRgn ) ;
3dec57ad 225}
76a5e5d2 226void wxDC::MacSetupPort(wxMacPortStateHelper* help) const
519cb848 227{
66a09d47
SC
228 wxASSERT( m_macCurrentPortStateHelper == NULL ) ;
229 m_macCurrentPortStateHelper = help ;
76a5e5d2 230 SetClip( (RgnHandle) m_macCurrentClipRgn);
519cb848
SC
231 m_macFontInstalled = false ;
232 m_macBrushInstalled = false ;
99030bdf 233 m_macPenInstalled = false ;
519cb848 234}
66a09d47
SC
235void wxDC::MacCleanupPort(wxMacPortStateHelper* help) const
236{
237 wxASSERT( m_macCurrentPortStateHelper == help ) ;
238 m_macCurrentPortStateHelper = NULL ;
239 if( m_macATSUIStyle )
240 {
241 ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle);
242 m_macATSUIStyle = NULL ;
243 }
244 if ( m_macAliasWasEnabled )
245 {
246 SetAntiAliasedTextEnabled(m_macFormerAliasState, m_macFormerAliasSize);
247 m_macAliasWasEnabled = false ;
248 }
249 if ( m_macForegroundPixMap )
250 {
251 Pattern blackColor ;
252 ::PenPat(GetQDGlobalsBlack(&blackColor));
c99d6f99 253 DisposePixPat( (PixPatHandle) m_macForegroundPixMap ) ;
66a09d47
SC
254 m_macForegroundPixMap = NULL ;
255 }
256 if ( m_macBackgroundPixMap )
257 {
258 Pattern whiteColor ;
259 ::BackPat(GetQDGlobalsWhite(&whiteColor));
c99d6f99 260 DisposePixPat( (PixPatHandle) m_macBackgroundPixMap ) ;
66a09d47
SC
261 m_macBackgroundPixMap = NULL ;
262 }
263}
2f1ae414 264void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
519cb848 265{
3dec57ad 266 wxCHECK_RET( Ok(), wxT("invalid window dc") );
3dec57ad 267 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
3dec57ad 268 wxMacPortSetter helper(this) ;
7d9d1fd7
SC
269 wxCoord xx = XLOG2DEVMAC(x);
270 wxCoord yy = YLOG2DEVMAC(y);
3dec57ad
SC
271 wxCoord w = bmp.GetWidth();
272 wxCoord h = bmp.GetHeight();
273 wxCoord ww = XLOG2DEVREL(w);
274 wxCoord hh = YLOG2DEVREL(h);
3dec57ad
SC
275 // Set up drawing mode
276 short mode = (m_logicalFunction == wxCOPY ? srcCopy :
277 //m_logicalFunction == wxCLEAR ? WHITENESS :
278 //m_logicalFunction == wxSET ? BLACKNESS :
279 m_logicalFunction == wxINVERT ? hilite :
280 //m_logicalFunction == wxAND ? MERGECOPY :
281 m_logicalFunction == wxOR ? srcOr :
282 m_logicalFunction == wxSRC_INVERT ? notSrcCopy :
283 m_logicalFunction == wxXOR ? srcXor :
284 m_logicalFunction == wxOR_REVERSE ? notSrcOr :
285 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
286 //m_logicalFunction == wxSRC_OR ? srcOr :
287 //m_logicalFunction == wxSRC_AND ? SRCAND :
288 srcCopy );
3dec57ad
SC
289 if ( bmp.GetBitmapType() == kMacBitmapTypePict ) {
290 Rect bitmaprect = { 0 , 0 , hh, ww };
291 ::OffsetRect( &bitmaprect, xx, yy ) ;
76a5e5d2 292 ::DrawPicture( (PicHandle) bmp.GetPict(), &bitmaprect ) ;
519cb848 293 }
3dec57ad
SC
294 else if ( bmp.GetBitmapType() == kMacBitmapTypeGrafWorld )
295 {
76a5e5d2 296 GWorldPtr bmapworld = MAC_WXHBITMAP( bmp.GetHBITMAP() );
3dec57ad 297 PixMapHandle bmappixels ;
3dec57ad
SC
298 // Set foreground and background colours (for bitmaps depth = 1)
299 if(bmp.GetDepth() == 1)
300 {
76a5e5d2
SC
301 RGBColor fore = MAC_WXCOLORREF(m_textForegroundColour.GetPixel());
302 RGBColor back = MAC_WXCOLORREF(m_textBackgroundColour.GetPixel());
3dec57ad
SC
303 RGBForeColor(&fore);
304 RGBBackColor(&back);
305 }
306 else
307 {
308 RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ;
309 RGBColor black = { 0,0,0} ;
310 RGBForeColor( &black ) ;
311 RGBBackColor( &white ) ;
312 }
3dec57ad 313 bmappixels = GetGWorldPixMap( bmapworld ) ;
3dec57ad
SC
314 wxCHECK_RET(LockPixels(bmappixels),
315 wxT("DoDrawBitmap: Unable to lock pixels"));
3dec57ad
SC
316 Rect source = { 0, 0, h, w };
317 Rect dest = { yy, xx, yy + hh, xx + ww };
3dec57ad
SC
318 if ( useMask && bmp.GetMask() )
319 {
76a5e5d2 320 if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap()))))
3dec57ad
SC
321 {
322 CopyDeepMask
323 (
324 GetPortBitMapForCopyBits(bmapworld),
76a5e5d2
SC
325 GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())),
326 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
3dec57ad
SC
327 &source, &source, &dest, mode, NULL
328 );
76a5e5d2 329 UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())));
3dec57ad
SC
330 }
331 }
332 else {
333 CopyBits( GetPortBitMapForCopyBits( bmapworld ),
76a5e5d2 334 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
3dec57ad
SC
335 &source, &dest, mode, NULL ) ;
336 }
337 UnlockPixels( bmappixels ) ;
338 }
339 else if ( bmp.GetBitmapType() == kMacBitmapTypeIcon )
340 {
341 Rect bitmaprect = { 0 , 0 , bmp.GetHeight(), bmp.GetWidth() } ;
342 OffsetRect( &bitmaprect, xx, yy ) ;
76a5e5d2 343 PlotCIconHandle( &bitmaprect , atNone , ttNone , MAC_WXHICON(bmp.GetHICON()) ) ;
3dec57ad
SC
344 }
345 m_macPenInstalled = false ;
346 m_macBrushInstalled = false ;
347 m_macFontInstalled = false ;
519cb848 348}
2f1ae414 349void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
e9576ca5 350{
3dec57ad 351 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
3dec57ad 352 wxCHECK_RET(icon.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
a2f94f40 353 DoDrawBitmap( icon , x , y , icon.GetMask() != NULL ) ;
3dec57ad 354}
2f1ae414 355void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
e9576ca5 356{
3dec57ad
SC
357 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
358 wxCoord xx, yy, ww, hh;
7d9d1fd7
SC
359 xx = XLOG2DEVMAC(x);
360 yy = YLOG2DEVMAC(y);
3dec57ad
SC
361 ww = XLOG2DEVREL(width);
362 hh = YLOG2DEVREL(height);
76a5e5d2
SC
363 SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
364 SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
3dec57ad
SC
365 if( m_clipping )
366 {
367 m_clipX1 = wxMax( m_clipX1 , xx );
368 m_clipY1 = wxMax( m_clipY1 , yy );
369 m_clipX2 = wxMin( m_clipX2, (xx + ww));
370 m_clipY2 = wxMin( m_clipY2, (yy + hh));
371 }
372 else
373 {
374 m_clipping = TRUE;
375 m_clipX1 = xx;
376 m_clipY1 = yy;
377 m_clipX2 = xx + ww;
378 m_clipY2 = yy + hh;
379 }
3dec57ad 380}
2f1ae414
SC
381void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region )
382{
3dec57ad 383 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
0eaa1d68 384 wxMacPortSetter helper(this) ;
2f1ae414
SC
385 if (region.Empty())
386 {
387 DestroyClippingRegion();
388 return;
389 }
ffba56ed
SC
390 wxCoord x, y, w, h;
391 region.GetBox( x, y, w, h );
2f1ae414 392 wxCoord xx, yy, ww, hh;
7d9d1fd7
SC
393 xx = XLOG2DEVMAC(x);
394 yy = YLOG2DEVMAC(y);
ffba56ed
SC
395 ww = XLOG2DEVREL(w);
396 hh = YLOG2DEVREL(h);
ffba56ed
SC
397 // if we have a scaling that we cannot map onto native regions
398 // we must use the box
ffba56ed
SC
399 if ( ww != w || hh != h )
400 {
401 wxDC::DoSetClippingRegion( x, y, w, h );
402 }
403 else
404 {
76a5e5d2 405 CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ;
ffba56ed
SC
406 if ( xx != x || yy != y )
407 {
76a5e5d2 408 OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ;
ffba56ed 409 }
76a5e5d2 410 SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
ffba56ed
SC
411 if( m_clipping )
412 {
413 m_clipX1 = wxMax( m_clipX1 , xx );
414 m_clipY1 = wxMax( m_clipY1 , yy );
415 m_clipX2 = wxMin( m_clipX2, (xx + ww));
416 m_clipY2 = wxMin( m_clipY2, (yy + hh));
417 }
418 else
419 {
420 m_clipping = TRUE;
421 m_clipX1 = xx;
422 m_clipY1 = yy;
423 m_clipX2 = xx + ww;
424 m_clipY2 = yy + hh;
425 }
426 }
ee41971c 427}
3dec57ad 428void wxDC::DestroyClippingRegion()
e9576ca5 429{
0eaa1d68 430 wxMacPortSetter helper(this) ;
76a5e5d2 431 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
e9576ca5 432 m_clipping = FALSE;
99030bdf 433}
2f1ae414 434void wxDC::DoGetSize( int* width, int* height ) const
e9576ca5
SC
435{
436 *width = m_maxX-m_minX;
437 *height = m_maxY-m_minY;
3dec57ad 438}
2f1ae414 439void wxDC::DoGetSizeMM( int* width, int* height ) const
e9576ca5
SC
440{
441 int w = 0;
442 int h = 0;
443 GetSize( &w, &h );
444 *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) );
445 *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) );
3dec57ad 446}
e9576ca5
SC
447void wxDC::SetTextForeground( const wxColour &col )
448{
3dec57ad
SC
449 wxCHECK_RET(Ok(), wxT("Invalid DC"));
450 m_textForegroundColour = col;
451 m_macFontInstalled = false ;
452}
e9576ca5
SC
453void wxDC::SetTextBackground( const wxColour &col )
454{
3dec57ad
SC
455 wxCHECK_RET(Ok(), wxT("Invalid DC"));
456 m_textBackgroundColour = col;
457 m_macFontInstalled = false ;
458}
e9576ca5
SC
459void wxDC::SetMapMode( int mode )
460{
99030bdf 461 switch (mode)
e9576ca5 462 {
e3065973 463 case wxMM_TWIPS:
e9576ca5
SC
464 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
465 break;
e3065973 466 case wxMM_POINTS:
e9576ca5
SC
467 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
468 break;
e3065973 469 case wxMM_METRIC:
e9576ca5
SC
470 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
471 break;
e3065973 472 case wxMM_LOMETRIC:
e9576ca5
SC
473 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
474 break;
475 default:
e3065973 476 case wxMM_TEXT:
e9576ca5
SC
477 SetLogicalScale( 1.0, 1.0 );
478 break;
3dec57ad 479 }
e3065973 480 if (mode != wxMM_TEXT)
e9576ca5
SC
481 {
482 m_needComputeScaleX = TRUE;
483 m_needComputeScaleY = TRUE;
3dec57ad
SC
484 }
485}
e9576ca5
SC
486void wxDC::SetUserScale( double x, double y )
487{
488 // allow negative ? -> no
489 m_userScaleX = x;
490 m_userScaleY = y;
491 ComputeScaleAndOrigin();
3dec57ad 492}
e9576ca5
SC
493void wxDC::SetLogicalScale( double x, double y )
494{
495 // allow negative ?
496 m_logicalScaleX = x;
497 m_logicalScaleY = y;
498 ComputeScaleAndOrigin();
3dec57ad 499}
2f1ae414 500void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
e9576ca5
SC
501{
502 m_logicalOriginX = x * m_signX; // is this still correct ?
503 m_logicalOriginY = y * m_signY;
504 ComputeScaleAndOrigin();
3dec57ad 505}
2f1ae414 506void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
e9576ca5
SC
507{
508 m_externalDeviceOriginX = x;
509 m_externalDeviceOriginY = y;
510 ComputeScaleAndOrigin();
3dec57ad 511}
3dec57ad 512#if 0
e9576ca5
SC
513void wxDC::SetInternalDeviceOrigin( long x, long y )
514{
515 m_internalDeviceOriginX = x;
516 m_internalDeviceOriginY = y;
517 ComputeScaleAndOrigin();
3dec57ad 518}
e9576ca5
SC
519void wxDC::GetInternalDeviceOrigin( long *x, long *y )
520{
521 if (x) *x = m_internalDeviceOriginX;
522 if (y) *y = m_internalDeviceOriginY;
3dec57ad
SC
523}
524#endif
e9576ca5
SC
525void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
526{
527 m_signX = (xLeftRight ? 1 : -1);
528 m_signY = (yBottomUp ? -1 : 1);
529 ComputeScaleAndOrigin();
76a5e5d2 530}
2f1ae414
SC
531wxSize wxDC::GetPPI() const
532{
533 return wxSize(72, 72);
534}
2f1ae414
SC
535int wxDC::GetDepth() const
536{
c99d6f99
SC
537 if ( IsPortColor( (CGrafPtr) m_macPort ) )
538 {
539 return ( (**GetPortPixMap( (CGrafPtr) m_macPort)).pixelSize ) ;
540 }
541 return 1 ;
2f1ae414 542}
3dec57ad 543void wxDC::ComputeScaleAndOrigin()
e9576ca5
SC
544{
545 // CMB: copy scale to see if it changes
546 double origScaleX = m_scaleX;
547 double origScaleY = m_scaleY;
e9576ca5
SC
548 m_scaleX = m_logicalScaleX * m_userScaleX;
549 m_scaleY = m_logicalScaleY * m_userScaleY;
e9576ca5
SC
550 m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX;
551 m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY;
99030bdf 552 // CMB: if scale has changed call SetPen to recalulate the line width
e9576ca5
SC
553 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
554 {
5b781a67
SC
555 // this is a bit artificial, but we need to force wxDC to think
556 // the pen has changed
557 wxPen* pen = & GetPen();
558 wxPen tempPen;
559 m_pen = tempPen;
560 SetPen(* pen);
e9576ca5 561 }
3dec57ad 562}
519cb848
SC
563void wxDC::SetPalette( const wxPalette& palette )
564{
565}
519cb848
SC
566void wxDC::SetBackgroundMode( int mode )
567{
568 m_backgroundMode = mode ;
569}
519cb848
SC
570void wxDC::SetFont( const wxFont &font )
571{
3dec57ad
SC
572 m_font = font;
573 m_macFontInstalled = false ;
519cb848 574}
519cb848
SC
575void wxDC::SetPen( const wxPen &pen )
576{
519cb848
SC
577 if ( m_pen == pen )
578 return ;
519cb848 579 m_pen = pen;
519cb848
SC
580 m_macPenInstalled = false ;
581}
519cb848
SC
582void wxDC::SetBrush( const wxBrush &brush )
583{
99030bdf 584 if (m_brush == brush)
519cb848 585 return;
519cb848
SC
586 m_brush = brush;
587 m_macBrushInstalled = false ;
588}
519cb848
SC
589void wxDC::SetBackground( const wxBrush &brush )
590{
99030bdf 591 if (m_backgroundBrush == brush)
519cb848 592 return;
519cb848 593 m_backgroundBrush = brush;
99030bdf 594 if (!m_backgroundBrush.Ok())
519cb848
SC
595 return;
596 m_macBrushInstalled = false ;
597}
519cb848
SC
598void wxDC::SetLogicalFunction( int function )
599{
99030bdf 600 if (m_logicalFunction == function)
519cb848 601 return;
519cb848
SC
602 m_logicalFunction = function ;
603 m_macFontInstalled = false ;
604 m_macBrushInstalled = false ;
605 m_macPenInstalled = false ;
606}
99030bdf 607extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
3a0a5ada 608 const wxColour & col, int style);
387ebd3e 609bool wxDC::DoFloodFill(wxCoord x, wxCoord y,
3a0a5ada
VS
610 const wxColour& col, int style)
611{
387ebd3e 612 return wxDoFloodFill(this, x, y, col, style);
71110b40 613}
99030bdf 614bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const
519cb848 615{
3dec57ad
SC
616 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
617 wxMacPortSetter helper(this) ;
3dec57ad 618 RGBColor colour;
7d9d1fd7 619 GetCPixel( XLOG2DEVMAC(x), YLOG2DEVMAC(y), &colour );
3dec57ad
SC
620 // Convert from Mac colour to wx
621 col->Set( colour.red >> 8,
622 colour.green >> 8,
623 colour.blue >> 8);
3dec57ad 624 return true ;
519cb848 625}
2f1ae414 626void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
519cb848 627{
3dec57ad 628 wxCHECK_RET(Ok(), wxT("Invalid DC"));
0eaa1d68 629 wxMacPortSetter helper(this) ;
519cb848
SC
630 if (m_pen.GetStyle() != wxTRANSPARENT)
631 {
632 MacInstallPen() ;
3dec57ad
SC
633 wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 :
634 m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2;
7d9d1fd7
SC
635 wxCoord xx1 = XLOG2DEVMAC(x1) - offset;
636 wxCoord yy1 = YLOG2DEVMAC(y1) - offset;
637 wxCoord xx2 = XLOG2DEVMAC(x2) - offset;
638 wxCoord yy2 = YLOG2DEVMAC(y2) - offset;
2301e281
RR
639 if ((m_pen.GetCap() == wxCAP_ROUND) &&
640 (m_pen.GetWidth() <= 1))
641 {
642 // Implement LAST_NOT for MAC at least for
643 // orthogonal lines. RR.
644 if (xx1 == xx2)
645 {
646 if (yy1 < yy2)
647 yy2--;
648 if (yy1 > yy2)
649 yy2++;
650 }
651 if (yy1 == yy2)
652 {
653 if (xx1 < xx2)
654 xx2--;
655 if (xx1 > xx2)
656 xx2++;
657 }
658 }
2301e281
RR
659 ::MoveTo(xx1, yy1);
660 ::LineTo(xx2, yy2);
3dec57ad 661 }
519cb848 662}
2f1ae414 663void wxDC::DoCrossHair( wxCoord x, wxCoord y )
519cb848 664{
3dec57ad 665 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
c1cddfe8 666 wxMacPortSetter helper(this) ;
3dec57ad
SC
667 if (m_pen.GetStyle() != wxTRANSPARENT)
668 {
669 int w = 0;
670 int h = 0;
671 GetSize( &w, &h );
7d9d1fd7
SC
672 wxCoord xx = XLOG2DEVMAC(x);
673 wxCoord yy = YLOG2DEVMAC(y);
3dec57ad 674 MacInstallPen();
7d9d1fd7
SC
675 ::MoveTo( XLOG2DEVMAC(0), yy );
676 ::LineTo( XLOG2DEVMAC(w), yy );
677 ::MoveTo( xx, YLOG2DEVMAC(0) );
678 ::LineTo( xx, YLOG2DEVMAC(h) );
66a09d47
SC
679 CalcBoundingBox(x, y);
680 CalcBoundingBox(x+w, y+h);
3dec57ad
SC
681 }
682}
3dec57ad
SC
683/*
684 * To draw arcs properly the angles need to be converted from the WX style:
685 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
686 * a normal axis on paper).
687 * TO
688 * the Mac style:
689 * Angles start on the +ve y axis and go clockwise.
3dec57ad
SC
690 */
691static double wxConvertWXangleToMACangle(double angle)
692{
2beae4b5
SC
693 double newAngle = 90 - angle ;
694 if ( newAngle < 0 )
695 newAngle += 360 ;
696 return newAngle ;
519cb848 697}
2f1ae414
SC
698void wxDC::DoDrawArc( wxCoord x1, wxCoord y1,
699 wxCoord x2, wxCoord y2,
700 wxCoord xc, wxCoord yc )
519cb848 701{
3dec57ad 702 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
c1cddfe8 703 wxMacPortSetter helper(this) ;
7d9d1fd7
SC
704 wxCoord xx1 = XLOG2DEVMAC(x1);
705 wxCoord yy1 = YLOG2DEVMAC(y1);
706 wxCoord xx2 = XLOG2DEVMAC(x2);
707 wxCoord yy2 = YLOG2DEVMAC(y2);
708 wxCoord xxc = XLOG2DEVMAC(xc);
709 wxCoord yyc = YLOG2DEVMAC(yc);
3dec57ad
SC
710 double dx = xx1 - xxc;
711 double dy = yy1 - yyc;
712 double radius = sqrt((double)(dx*dx+dy*dy));
713 wxCoord rad = (wxCoord)radius;
714 double radius1, radius2;
3dec57ad
SC
715 if (xx1 == xx2 && yy1 == yy2)
716 {
717 radius1 = 0.0;
718 radius2 = 360.0;
719 }
720 else if (radius == 0.0)
721 {
722 radius1 = radius2 = 0.0;
723 }
724 else
725 {
726 radius1 = (xx1 - xxc == 0) ?
727 (yy1 - yyc < 0) ? 90.0 : -90.0 :
728 -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
729 radius2 = (xx2 - xxc == 0) ?
730 (yy2 - yyc < 0) ? 90.0 : -90.0 :
731 -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
732 }
733 wxCoord alpha2 = wxCoord(radius2 - radius1);
734 wxCoord alpha1 = wxCoord(wxConvertWXangleToMACangle(radius1));
735 if( (xx1 > xx2) || (yy1 > yy2) ) {
736 alpha2 *= -1;
737 }
3dec57ad 738 Rect r = { yyc - rad, xxc - rad, yyc + rad, xxc + rad };
3dec57ad
SC
739 if(m_brush.GetStyle() != wxTRANSPARENT) {
740 MacInstallBrush();
741 PaintArc(&r, alpha1, alpha2);
742 }
743 if(m_pen.GetStyle() != wxTRANSPARENT) {
744 MacInstallPen();
745 FrameArc(&r, alpha1, alpha2);
746 }
519cb848 747}
2f1ae414
SC
748void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
749 double sa, double ea )
519cb848 750{
3dec57ad 751 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
c1cddfe8 752 wxMacPortSetter helper(this) ;
3dec57ad
SC
753 Rect r;
754 double angle = sa - ea; // Order important Mac in opposite direction to wx
2beae4b5
SC
755 // we have to make sure that the filling is always counter-clockwise
756 if ( angle > 0 )
757 angle -= 360 ;
7d9d1fd7
SC
758 wxCoord xx = XLOG2DEVMAC(x);
759 wxCoord yy = YLOG2DEVMAC(y);
3dec57ad
SC
760 wxCoord ww = m_signX * XLOG2DEVREL(w);
761 wxCoord hh = m_signY * YLOG2DEVREL(h);
3dec57ad
SC
762 // handle -ve width and/or height
763 if (ww < 0) { ww = -ww; xx = xx - ww; }
764 if (hh < 0) { hh = -hh; yy = yy - hh; }
3dec57ad 765 sa = wxConvertWXangleToMACangle(sa);
3dec57ad
SC
766 r.top = yy;
767 r.left = xx;
768 r.bottom = yy + hh;
769 r.right = xx + ww;
3dec57ad
SC
770 if(m_brush.GetStyle() != wxTRANSPARENT) {
771 MacInstallBrush();
772 PaintArc(&r, (short)sa, (short)angle);
773 }
774 if(m_pen.GetStyle() != wxTRANSPARENT) {
775 MacInstallPen();
776 FrameArc(&r, (short)sa, (short)angle);
777 }
519cb848 778}
2f1ae414 779void wxDC::DoDrawPoint( wxCoord x, wxCoord y )
519cb848 780{
3dec57ad 781 wxCHECK_RET(Ok(), wxT("Invalid DC"));
0eaa1d68 782 wxMacPortSetter helper(this) ;
99030bdf 783 if (m_pen.GetStyle() != wxTRANSPARENT)
519cb848 784 {
99030bdf 785 wxCoord xx1 = XLOG2DEVMAC(x);
7d9d1fd7 786 wxCoord yy1 = YLOG2DEVMAC(y);
5e420341
SC
787 RGBColor pencolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
788 ::SetCPixel( xx1,yy1,&pencolor) ;
789 CalcBoundingBox(x, y);
3dec57ad 790 }
519cb848 791}
2f1ae414
SC
792void wxDC::DoDrawLines(int n, wxPoint points[],
793 wxCoord xoffset, wxCoord yoffset)
519cb848 794{
3dec57ad 795 wxCHECK_RET(Ok(), wxT("Invalid DC"));
0eaa1d68 796 wxMacPortSetter helper(this) ;
99030bdf 797 if (m_pen.GetStyle() == wxTRANSPARENT)
519cb848 798 return;
03e11df5 799 MacInstallPen() ;
3dec57ad
SC
800 wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 :
801 m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2 ;
3dec57ad 802 wxCoord x1, x2 , y1 , y2 ;
7d9d1fd7 803 x1 = XLOG2DEVMAC(points[0].x + xoffset);
99030bdf 804 y1 = YLOG2DEVMAC(points[0].y + yoffset);
3dec57ad 805 ::MoveTo(x1 - offset, y1 - offset );
519cb848
SC
806 for (int i = 0; i < n-1; i++)
807 {
7d9d1fd7
SC
808 x2 = XLOG2DEVMAC(points[i+1].x + xoffset);
809 y2 = YLOG2DEVMAC(points[i+1].y + yoffset);
3dec57ad 810 ::LineTo( x2 - offset, y2 - offset );
519cb848
SC
811 }
812}
2f1ae414 813void wxDC::DoDrawPolygon(int n, wxPoint points[],
d84afea9
GD
814 wxCoord xoffset, wxCoord yoffset,
815 int fillStyle )
519cb848 816{
32ea1f98
RR
817 wxCHECK_RET(Ok(), wxT("Invalid DC"));
818 wxMacPortSetter helper(this) ;
32ea1f98 819 wxCoord x1, x2 , y1 , y2 ;
75f7bc3b
SC
820 if ( m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT )
821 return ;
75f7bc3b 822 PolyHandle polygon = OpenPoly();
3340066a
SC
823 x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset);
824 y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset);
75f7bc3b 825 ::MoveTo(x1,y1);
76a5e5d2 826 for (int i = 1; i < n; i++)
75f7bc3b 827 {
76a5e5d2
SC
828 x2 = XLOG2DEVMAC(points[i].x + xoffset);
829 y2 = YLOG2DEVMAC(points[i].y + yoffset);
75f7bc3b
SC
830 ::LineTo(x2, y2);
831 }
76a5e5d2
SC
832 // close the polyline if necessary
833 if ( x1 != x2 || y1 != y2 )
834 {
835 ::LineTo(x1,y1 ) ;
836 }
75f7bc3b 837 ClosePoly();
32ea1f98
RR
838 if (m_brush.GetStyle() != wxTRANSPARENT)
839 {
32ea1f98
RR
840 MacInstallBrush();
841 ::PaintPoly( polygon );
3dec57ad 842 }
99030bdf 843 if (m_pen.GetStyle() != wxTRANSPARENT)
519cb848
SC
844 {
845 MacInstallPen() ;
846 ::FramePoly( polygon ) ;
3dec57ad 847 }
75f7bc3b 848 KillPoly( polygon );
519cb848 849}
3dec57ad 850void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
519cb848 851{
3dec57ad
SC
852 wxCHECK_RET(Ok(), wxT("Invalid DC"));
853 wxMacPortSetter helper(this) ;
7d9d1fd7
SC
854 wxCoord xx = XLOG2DEVMAC(x);
855 wxCoord yy = YLOG2DEVMAC(y);
3dec57ad
SC
856 wxCoord ww = m_signX * XLOG2DEVREL(width);
857 wxCoord hh = m_signY * YLOG2DEVREL(height);
519cb848 858 // CMB: draw nothing if transformed w or h is 0
99030bdf 859 if (ww == 0 || hh == 0)
519cb848 860 return;
519cb848 861 // CMB: handle -ve width and/or height
99030bdf
RD
862 if (ww < 0)
863 {
864 ww = -ww;
865 xx = xx - ww;
519cb848 866 }
99030bdf
RD
867 if (hh < 0)
868 {
869 hh = -hh;
870 yy = yy - hh;
519cb848 871 }
519cb848 872 Rect rect = { yy , xx , yy + hh , xx + ww } ;
99030bdf 873 if (m_brush.GetStyle() != wxTRANSPARENT)
519cb848
SC
874 {
875 MacInstallBrush() ;
876 ::PaintRect( &rect ) ;
3dec57ad 877 }
99030bdf 878 if (m_pen.GetStyle() != wxTRANSPARENT)
519cb848
SC
879 {
880 MacInstallPen() ;
881 ::FrameRect( &rect ) ;
3dec57ad 882 }
519cb848 883}
2f1ae414
SC
884void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
885 wxCoord width, wxCoord height,
886 double radius)
519cb848 887{
3dec57ad
SC
888 wxCHECK_RET(Ok(), wxT("Invalid DC"));
889 wxMacPortSetter helper(this) ;
99030bdf 890 if (radius < 0.0)
3dec57ad 891 radius = - radius * ((width < height) ? width : height);
7d9d1fd7
SC
892 wxCoord xx = XLOG2DEVMAC(x);
893 wxCoord yy = YLOG2DEVMAC(y);
3dec57ad
SC
894 wxCoord ww = m_signX * XLOG2DEVREL(width);
895 wxCoord hh = m_signY * YLOG2DEVREL(height);
519cb848 896 // CMB: draw nothing if transformed w or h is 0
99030bdf 897 if (ww == 0 || hh == 0)
519cb848 898 return;
519cb848 899 // CMB: handle -ve width and/or height
99030bdf
RD
900 if (ww < 0)
901 {
902 ww = -ww;
903 xx = xx - ww;
519cb848 904 }
99030bdf
RD
905 if (hh < 0)
906 {
907 hh = -hh;
908 yy = yy - hh;
519cb848 909 }
519cb848 910 Rect rect = { yy , xx , yy + hh , xx + ww } ;
99030bdf 911 if (m_brush.GetStyle() != wxTRANSPARENT)
519cb848
SC
912 {
913 MacInstallBrush() ;
03e11df5 914 ::PaintRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ;
3dec57ad 915 }
99030bdf 916 if (m_pen.GetStyle() != wxTRANSPARENT)
519cb848
SC
917 {
918 MacInstallPen() ;
03e11df5 919 ::FrameRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ;
3dec57ad 920 }
519cb848 921}
2f1ae414 922void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
519cb848 923{
3dec57ad
SC
924 wxCHECK_RET(Ok(), wxT("Invalid DC"));
925 wxMacPortSetter helper(this) ;
7d9d1fd7
SC
926 wxCoord xx = XLOG2DEVMAC(x);
927 wxCoord yy = YLOG2DEVMAC(y);
3dec57ad
SC
928 wxCoord ww = m_signX * XLOG2DEVREL(width);
929 wxCoord hh = m_signY * YLOG2DEVREL(height);
519cb848
SC
930 // CMB: draw nothing if transformed w or h is 0
931 if (ww == 0 || hh == 0)
932 return;
519cb848
SC
933 // CMB: handle -ve width and/or height
934 if (ww < 0)
935 {
936 ww = -ww;
937 xx = xx - ww;
938 }
519cb848
SC
939 if (hh < 0)
940 {
941 hh = -hh;
942 yy = yy - hh;
943 }
519cb848 944 Rect rect = { yy , xx , yy + hh , xx + ww } ;
519cb848
SC
945 if (m_brush.GetStyle() != wxTRANSPARENT)
946 {
947 MacInstallBrush() ;
948 ::PaintOval( &rect ) ;
3dec57ad 949 }
519cb848
SC
950 if (m_pen.GetStyle() != wxTRANSPARENT)
951 {
952 MacInstallPen() ;
953 ::FrameOval( &rect ) ;
3dec57ad 954 }
519cb848
SC
955}
956
519cb848 957
99030bdf 958bool wxDC::CanDrawBitmap(void) const
519cb848
SC
959{
960 return true ;
961}
962
2f1ae414 963bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
0cbff120
JS
964 wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask,
965 wxCoord xsrcMask, wxCoord ysrcMask )
519cb848 966{
3dec57ad
SC
967 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
968 wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
76a5e5d2
SC
969 if ( logical_func == wxNO_OP )
970 return TRUE ;
0cbff120
JS
971 if (xsrcMask == -1 && ysrcMask == -1)
972 {
973 xsrcMask = xsrc; ysrcMask = ysrc;
974 }
76a5e5d2 975 // correct the parameter in case this dc does not have a mask at all
76a5e5d2
SC
976 if ( useMask && !source->m_macMask )
977 useMask = false ;
76a5e5d2
SC
978 Rect srcrect , dstrect ;
979 srcrect.top = source->YLOG2DEVMAC(ysrc) ;
980 srcrect.left = source->XLOG2DEVMAC(xsrc) ;
981 srcrect.right = source->XLOG2DEVMAC(xsrc + width ) ;
982 srcrect.bottom = source->YLOG2DEVMAC(ysrc + height) ;
983 dstrect.top = YLOG2DEVMAC(ydest) ;
984 dstrect.left = XLOG2DEVMAC(xdest) ;
985 dstrect.bottom = YLOG2DEVMAC(ydest + height ) ;
986 dstrect.right = XLOG2DEVMAC(xdest + width ) ;
76a5e5d2
SC
987 short mode = kUnsupportedMode ;
988 bool invertDestinationFirst = false ;
989 switch ( logical_func )
990 {
991 case wxAND: // src AND dst
992 mode = srcOr ; // ok
993 break ;
994 case wxAND_INVERT: // (NOT src) AND dst
995 mode = notSrcOr ; // ok
996 break ;
997 case wxAND_REVERSE:// src AND (NOT dst)
998 invertDestinationFirst = true ;
99030bdf 999 mode = srcOr ;
76a5e5d2
SC
1000 break ;
1001 case wxCLEAR: // 0
99030bdf 1002 mode = kEmulatedMode ;
76a5e5d2
SC
1003 break ;
1004 case wxCOPY: // src
1005 mode = srcCopy ; // ok
1006 break ;
1007 case wxEQUIV: // (NOT src) XOR dst
1008 mode = srcXor ; // ok
1009 break ;
1010 case wxINVERT: // NOT dst
1011 mode = kEmulatedMode ; //or hilite ;
1012 break ;
1013 case wxNAND: // (NOT src) OR (NOT dst)
1014 invertDestinationFirst = true ;
99030bdf 1015 mode = srcBic ;
76a5e5d2
SC
1016 break ;
1017 case wxNOR: // (NOT src) AND (NOT dst)
1018 invertDestinationFirst = true ;
99030bdf 1019 mode = notSrcOr ;
76a5e5d2
SC
1020 break ;
1021 case wxNO_OP: // dst
1022 mode = kEmulatedMode ; // this has already been handled upon entry
1023 break ;
1024 case wxOR: // src OR dst
1025 mode = notSrcBic ;
1026 break ;
1027 case wxOR_INVERT: // (NOT src) OR dst
99030bdf 1028 mode = srcBic ;
76a5e5d2
SC
1029 break ;
1030 case wxOR_REVERSE: // src OR (NOT dst)
1031 invertDestinationFirst = true ;
1032 mode = notSrcBic ;
1033 break ;
1034 case wxSET: // 1
99030bdf 1035 mode = kEmulatedMode ;
76a5e5d2
SC
1036 break ;
1037 case wxSRC_INVERT: // (NOT src)
1038 mode = notSrcCopy ; // ok
1039 break ;
1040 case wxXOR: // src XOR dst
1041 mode = notSrcXor ; // ok
1042 break ;
76a5e5d2
SC
1043 default :
1044 break ;
76a5e5d2 1045 }
76a5e5d2
SC
1046 if ( mode == kUnsupportedMode )
1047 {
99030bdf 1048 wxFAIL_MSG("unsupported blitting mode" );
76a5e5d2
SC
1049 return FALSE ;
1050 }
519cb848 1051 CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ;
99030bdf 1052 PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ;
519cb848
SC
1053 if ( LockPixels(bmappixels) )
1054 {
76a5e5d2 1055 wxMacPortSetter helper(this) ;
76a5e5d2
SC
1056 if ( source->GetDepth() == 1 )
1057 {
1058 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ;
1059 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour.GetPixel()) ) ;
1060 }
1061 else
1062 {
1063 // the modes need this, otherwise we'll end up having really nice colors...
1064 RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ;
1065 RGBColor black = { 0,0,0} ;
1066 RGBForeColor( &black ) ;
1067 RGBBackColor( &white ) ;
1068 }
8208e181
SC
1069 if ( useMask && source->m_macMask )
1070 {
1dcbbdcf
SC
1071 if ( mode == srcCopy )
1072 {
76a5e5d2 1073 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) )
1dcbbdcf 1074 {
99030bdf
RD
1075 CopyMask( GetPortBitMapForCopyBits( sourcePort ) ,
1076 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source->m_macMask) ) ,
76a5e5d2 1077 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
1dcbbdcf 1078 &srcrect, &srcrect , &dstrect ) ;
76a5e5d2 1079 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
1dcbbdcf
SC
1080 }
1081 }
1082 else
1083 {
1084 RgnHandle clipRgn = NewRgn() ;
76a5e5d2
SC
1085 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
1086 BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
1087 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
1dcbbdcf 1088 OffsetRgn( clipRgn , -srcrect.left + dstrect.left, -srcrect.top + dstrect.top ) ;
76a5e5d2
SC
1089 if ( mode == kEmulatedMode )
1090 {
1091 Pattern pat ;
1092 ::PenPat(GetQDGlobalsBlack(&pat));
1093 if ( logical_func == wxSET )
1094 {
1095 RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1096 ::RGBForeColor( &col ) ;
1097 ::PaintRgn( clipRgn ) ;
1098 }
1099 else if ( logical_func == wxCLEAR )
1100 {
1101 RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
1102 ::RGBForeColor( &col ) ;
1103 ::PaintRgn( clipRgn ) ;
1104 }
1105 else if ( logical_func == wxINVERT )
1106 {
1107 MacInvertRgn( clipRgn ) ;
1108 }
1109 else
1110 {
1111 for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
1112 {
1113 for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
1114 {
1115 Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
1116 Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
1117 if ( PtInRgn( dstPoint , clipRgn ) )
1118 {
1119 RGBColor srcColor ;
1120 RGBColor dstColor ;
76a5e5d2
SC
1121 SetPort( (GrafPtr) sourcePort ) ;
1122 GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ;
1123 SetPort( (GrafPtr) m_macPort ) ;
1124 GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
76a5e5d2
SC
1125 wxMacCalculateColour( logical_func , srcColor , dstColor ) ;
1126 SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
1127 }
1128 }
1129 }
76a5e5d2
SC
1130 }
1131 }
1132 else
1133 {
1134 if ( invertDestinationFirst )
1135 {
1136 MacInvertRgn( clipRgn ) ;
1137 }
99030bdf 1138 CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,
76a5e5d2
SC
1139 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
1140 &srcrect, &dstrect, mode, clipRgn ) ;
1141 }
1dcbbdcf
SC
1142 DisposeRgn( clipRgn ) ;
1143 }
8208e181
SC
1144 }
1145 else
1146 {
0d54461f
SC
1147 RgnHandle clipRgn = NewRgn() ;
1148 SetRectRgn( clipRgn , dstrect.left , dstrect.top , dstrect.right , dstrect.bottom ) ;
76a5e5d2
SC
1149 if ( mode == kEmulatedMode )
1150 {
0d54461f
SC
1151 Pattern pat ;
1152 ::PenPat(GetQDGlobalsBlack(&pat));
1153 if ( logical_func == wxSET )
1154 {
1155 RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
1156 ::RGBForeColor( &col ) ;
1157 ::PaintRgn( clipRgn ) ;
1158 }
1159 else if ( logical_func == wxCLEAR )
1160 {
1161 RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
1162 ::RGBForeColor( &col ) ;
1163 ::PaintRgn( clipRgn ) ;
1164 }
1165 else if ( logical_func == wxINVERT )
1166 {
1167 MacInvertRgn( clipRgn ) ;
1168 }
1169 else
1170 {
1171 for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
1172 {
1173 for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
1174 {
1175 Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
1176 Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
0d54461f
SC
1177 {
1178 RGBColor srcColor ;
1179 RGBColor dstColor ;
0d54461f
SC
1180 SetPort( (GrafPtr) sourcePort ) ;
1181 GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ;
1182 SetPort( (GrafPtr) m_macPort ) ;
1183 GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
0d54461f
SC
1184 wxMacCalculateColour( logical_func , srcColor , dstColor ) ;
1185 SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
1186 }
1187 }
1188 }
1189 }
76a5e5d2
SC
1190 }
1191 else
1192 {
0d54461f
SC
1193 if ( invertDestinationFirst )
1194 {
1195 MacInvertRgn( clipRgn ) ;
1196 }
99030bdf 1197 CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,
0d54461f
SC
1198 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
1199 &srcrect, &dstrect, mode, NULL ) ;
76a5e5d2 1200 }
0d54461f 1201 DisposeRgn( clipRgn ) ;
8208e181 1202 }
519cb848 1203 UnlockPixels( bmappixels ) ;
99030bdf 1204 }
519cb848
SC
1205 m_macPenInstalled = false ;
1206 m_macBrushInstalled = false ;
1207 m_macFontInstalled = false ;
519cb848
SC
1208 return TRUE;
1209}
66a09d47
SC
1210inline Fixed IntToFixed( int inInt )
1211 {
1212 return (((SInt32) inInt) << 16);
1213 }
2beae4b5
SC
1214inline int FixedToInt( Fixed inFixed )
1215 {
1216 return (((SInt32) inFixed) >> 16);
1217 }
1218
66a09d47 1219void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
3dec57ad 1220 double angle)
2f1ae414 1221{
3dec57ad 1222 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
32907dbd 1223 if (angle == 0.0 )
3dec57ad 1224 {
66a09d47 1225 DrawText(str, x, y);
3dec57ad
SC
1226 return;
1227 }
32907dbd
SC
1228 if ( str.Length() == 0 )
1229 return ;
3dec57ad 1230 wxMacPortSetter helper(this) ;
66a09d47 1231 MacInstallFont() ;
66a09d47
SC
1232 wxString text ;
1233 if ( wxApp::s_macDefaultEncodingIsPC )
1234 {
1235 text = wxMacMakeMacStringFromPC( str ) ;
1236 }
1237 else
1238 {
1239 text = str ;
1240 }
66a09d47
SC
1241 wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
1242 if ( 0 )
3dec57ad 1243 {
66a09d47 1244 m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);
3340066a 1245 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * font->m_macFontSize));
66a09d47 1246 m_macAliasWasEnabled = true ;
3dec57ad 1247 }
66a09d47 1248 OSStatus status = noErr ;
66a09d47
SC
1249 TECObjectRef ec;
1250 status = TECCreateConverter(&ec, kTextEncodingMacRoman, kTextEncodingUnicodeDefault);
1251 wxASSERT_MSG( status == noErr , "couldn't start converter" ) ;
66a09d47
SC
1252 ByteCount byteOutLen ;
1253 ByteCount byteInLen = text.Length() ;
1254 ByteCount byteBufferLen = byteInLen *2 ;
1255 char* buf = new char[byteBufferLen] ;
99030bdf 1256 status = TECConvertText(ec, (ConstTextPtr)text.c_str() , byteInLen, &byteInLen,
66a09d47 1257 (TextPtr)buf, byteBufferLen, &byteOutLen);
66a09d47
SC
1258 wxASSERT_MSG( status == noErr , "couldn't convert text" ) ;
1259 status = TECDisposeConverter(ec);
1260 wxASSERT_MSG( status == noErr , "couldn't dispose converter" ) ;
66a09d47
SC
1261 ATSUTextLayout atsuLayout ;
1262 UniCharCount chars = byteOutLen / 2 ;
1263 status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 ,
1264 &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
1265 wxASSERT_MSG( status == noErr , "couldn't create the layout of the rotated text" );
3340066a 1266 int iAngle = int( angle );
2beae4b5
SC
1267 int drawX = XLOG2DEVMAC(x) ;
1268 int drawY = YLOG2DEVMAC(y) ;
1269
1270 ATSUTextMeasurement textBefore ;
1271 ATSUTextMeasurement textAfter ;
1272 ATSUTextMeasurement ascent ;
1273 ATSUTextMeasurement descent ;
1274
1275
3340066a 1276 if ( abs(iAngle) > 0 )
32907dbd 1277 {
3340066a 1278 Fixed atsuAngle = IntToFixed( iAngle ) ;
2beae4b5
SC
1279 ATSUAttributeTag atsuTags[] =
1280 {
1281 kATSULineRotationTag ,
1282 } ;
2beae4b5
SC
1283 ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1284 {
1285 sizeof( Fixed ) ,
1286 } ;
2beae4b5
SC
1287 ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1288 {
1289 &atsuAngle ,
1290 } ;
2beae4b5
SC
1291 status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag),
1292 atsuTags, atsuSizes, atsuValues ) ;
32907dbd 1293 }
2beae4b5
SC
1294 status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
1295 &textBefore , &textAfter, &ascent , &descent );
1296
1297 drawX += sin(angle/RAD2DEG) * FixedToInt(ascent) ;
1298 drawY += cos(angle/RAD2DEG) * FixedToInt(ascent) ;
32907dbd 1299 status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
2beae4b5 1300 IntToFixed(drawX) , IntToFixed(drawY) );
66a09d47
SC
1301 wxASSERT_MSG( status == noErr , "couldn't draw the rotated text" );
1302 Rect rect ;
1303 status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
2beae4b5 1304 IntToFixed(drawX) , IntToFixed(drawY) , &rect );
66a09d47 1305 wxASSERT_MSG( status == noErr , "couldn't measure the rotated text" );
66a09d47
SC
1306 OffsetRect( &rect , -m_macLocalOrigin.x , -m_macLocalOrigin.y ) ;
1307 CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) );
1308 CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) );
1309 ::ATSUDisposeTextLayout(atsuLayout);
1310 delete[] buf ;
2f1ae414
SC
1311}
1312void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
99030bdf 1313{
3dec57ad
SC
1314 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1315 wxMacPortSetter helper(this) ;
7d9d1fd7
SC
1316 long xx = XLOG2DEVMAC(x);
1317 long yy = YLOG2DEVMAC(y);
99030bdf 1318#if TARGET_CARBON
32907dbd 1319 bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ;
2beae4b5
SC
1320 if ( m_font.GetNoAntiAliasing() )
1321 useDrawThemeText = false ;
6606ecac 1322#endif
66a09d47 1323 MacInstallFont() ;
99030bdf 1324 if ( 0 )
66a09d47
SC
1325 {
1326 m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);
1327 SetAntiAliasedTextEnabled(true, 8);
1328 m_macAliasWasEnabled = true ;
1329 }
66a09d47
SC
1330 FontInfo fi ;
1331 ::GetFontInfo( &fi ) ;
99030bdf 1332#if TARGET_CARBON
32907dbd 1333 if ( !useDrawThemeText )
6606ecac 1334#endif
32907dbd 1335 yy += fi.ascent ;
66a09d47
SC
1336 ::MoveTo( xx , yy );
1337 if ( m_backgroundMode == wxTRANSPARENT )
519cb848 1338 {
66a09d47
SC
1339 ::TextMode( srcOr) ;
1340 }
1341 else
1342 {
1343 ::TextMode( srcCopy ) ;
1344 }
66a09d47
SC
1345 const char *text = NULL ;
1346 int length = 0 ;
1347 wxString macText ;
66a09d47
SC
1348 if ( wxApp::s_macDefaultEncodingIsPC )
1349 {
1350 macText = wxMacMakeMacStringFromPC( strtext ) ;
1351 text = macText ;
1352 length = macText.Length() ;
1353 }
1354 else
1355 {
1356 text = strtext ;
1357 length = strtext.Length() ;
1358 }
66a09d47
SC
1359 int laststop = 0 ;
1360 int i = 0 ;
1361 int line = 0 ;
32907dbd 1362 {
32907dbd
SC
1363 while( i < length )
1364 {
1365 if( text[i] == 13 || text[i] == 10)
1366 {
6606ecac 1367#if TARGET_CARBON
32907dbd
SC
1368 if ( useDrawThemeText )
1369 {
2beae4b5 1370 Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ;
32907dbd
SC
1371 CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ;
1372 ::DrawThemeTextBox( mString,
1373 kThemeCurrentPortFont,
1374 kThemeStateActive,
b2a08015 1375 false,
32907dbd
SC
1376 &frame,
1377 teJustLeft,
1378 nil );
1379 CFRelease( mString ) ;
1380 line++ ;
1381 }
1382 else
6606ecac 1383#endif
32907dbd
SC
1384 {
1385 ::DrawText( text , laststop , i - laststop ) ;
1386 line++ ;
1387 ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) );
1388 }
1389 laststop = i+1 ;
1390 }
1391 i++ ;
1392 }
6606ecac 1393#if TARGET_CARBON
32907dbd
SC
1394 if ( useDrawThemeText )
1395 {
2beae4b5 1396 Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ;
32907dbd
SC
1397 CFStringRef mString = CFStringCreateWithCString( NULL , text + laststop , kCFStringEncodingMacRoman ) ;
1398 ::DrawThemeTextBox( mString,
1399 kThemeCurrentPortFont,
1400 kThemeStateActive,
b2a08015 1401 false,
32907dbd
SC
1402 &frame,
1403 teJustLeft,
1404 nil );
1405 CFRelease( mString ) ;
1406 }
1407 else
6606ecac 1408#endif
99030bdf 1409 {
32907dbd
SC
1410 ::DrawText( text , laststop , i - laststop ) ;
1411 }
519cb848 1412 }
66a09d47 1413 ::TextMode( srcOr ) ;
519cb848 1414}
99030bdf 1415bool wxDC::CanGetTextExtent() const
519cb848 1416{
3dec57ad 1417 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
519cb848
SC
1418 return true ;
1419}
2f1ae414
SC
1420void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height,
1421 wxCoord *descent, wxCoord *externalLeading ,
1422 wxFont *theFont ) const
519cb848 1423{
3dec57ad 1424 wxCHECK_RET(Ok(), wxT("Invalid DC"));
0eaa1d68 1425 wxMacPortSetter helper(this) ;
99030bdf 1426 wxFont formerFont = m_font ;
519cb848
SC
1427 if ( theFont )
1428 {
f52640f3
SC
1429 // work around the constness
1430 *((wxFont*)(&m_font)) = *theFont ;
519cb848 1431 }
f52640f3 1432 MacInstallFont() ;
519cb848
SC
1433 FontInfo fi ;
1434 ::GetFontInfo( &fi ) ;
f52640f3
SC
1435#if TARGET_CARBON
1436 bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ;
2beae4b5
SC
1437 if ( ((wxFont*)&m_font)->GetNoAntiAliasing() )
1438 useGetThemeText = false ;
f52640f3 1439#endif
2f1ae414
SC
1440 if ( height )
1441 *height = YDEV2LOGREL( fi.descent + fi.ascent ) ;
1442 if ( descent )
1443 *descent =YDEV2LOGREL( fi.descent );
1444 if ( externalLeading )
1445 *externalLeading = YDEV2LOGREL( fi.leading ) ;
519cb848
SC
1446 const char *text = NULL ;
1447 int length = 0 ;
1448 wxString macText ;
1449 if ( wxApp::s_macDefaultEncodingIsPC )
1450 {
1451 macText = wxMacMakeMacStringFromPC( string ) ;
1452 text = macText ;
1453 length = macText.Length() ;
5715cc1b 1454 }
519cb848
SC
1455 else
1456 {
1457 text = string ;
1458 length = string.Length() ;
1459 }
519cb848
SC
1460 int laststop = 0 ;
1461 int i = 0 ;
1462 int curwidth = 0 ;
2f1ae414 1463 if ( width )
519cb848 1464 {
2f1ae414 1465 *width = 0 ;
2f1ae414 1466 while( i < length )
519cb848 1467 {
2f1ae414
SC
1468 if( text[i] == 13 || text[i] == 10)
1469 {
1470 if ( height )
1471 *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ;
f52640f3
SC
1472#if TARGET_CARBON
1473 if ( useGetThemeText )
1474 {
1475 Point bounds={0,0} ;
aee9fe73 1476 SInt16 baseline ;
f52640f3
SC
1477 CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ;
1478 ::GetThemeTextDimensions( mString,
1479 kThemeCurrentPortFont,
1480 kThemeStateActive,
aee9fe73 1481 false,
f52640f3 1482 &bounds,
aee9fe73 1483 &baseline );
f52640f3
SC
1484 CFRelease( mString ) ;
1485 curwidth = bounds.h ;
1486 }
1487 else
1488#endif
1489 {
1490 curwidth = ::TextWidth( text , laststop , i - laststop ) ;
1491 }
2f1ae414
SC
1492 if ( curwidth > *width )
1493 *width = XDEV2LOGREL( curwidth ) ;
1494 laststop = i+1 ;
1495 }
1496 i++ ;
519cb848 1497 }
f52640f3
SC
1498
1499#if TARGET_CARBON
1500 if ( useGetThemeText )
1501 {
1502 Point bounds={0,0} ;
aee9fe73 1503 SInt16 baseline ;
f52640f3
SC
1504 CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text + laststop , i - laststop , CFStringGetSystemEncoding(), false ) ;
1505 ::GetThemeTextDimensions( mString,
1506 kThemeCurrentPortFont,
1507 kThemeStateActive,
aee9fe73 1508 false,
f52640f3 1509 &bounds,
aee9fe73 1510 &baseline );
f52640f3
SC
1511 CFRelease( mString ) ;
1512 curwidth = bounds.h ;
1513 }
1514 else
1515#endif
1516 {
1517 curwidth = ::TextWidth( text , laststop , i - laststop ) ;
1518 }
2f1ae414
SC
1519 if ( curwidth > *width )
1520 *width = XDEV2LOGREL( curwidth ) ;
519cb848 1521 }
519cb848
SC
1522 if ( theFont )
1523 {
f52640f3
SC
1524 // work around the constness
1525 *((wxFont*)(&m_font)) = formerFont ;
519cb848
SC
1526 m_macFontInstalled = false ;
1527 }
1528}
ee41971c 1529wxCoord wxDC::GetCharWidth(void) const
519cb848 1530{
3dec57ad 1531 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
0eaa1d68 1532 wxMacPortSetter helper(this) ;
519cb848 1533 MacInstallFont() ;
2beae4b5
SC
1534 int width = 0 ;
1535#if TARGET_CARBON
1536 bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ;
1537 if ( ((wxFont*)&m_font)->GetNoAntiAliasing() )
1538 useGetThemeText = false ;
1539#endif
2beae4b5
SC
1540 char text[] = "H" ;
1541#if TARGET_CARBON
1542 if ( useGetThemeText )
1543 {
1544 Point bounds={0,0} ;
1545 SInt16 baseline ;
1546 CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text , 1 , CFStringGetSystemEncoding(), false ) ;
1547 ::GetThemeTextDimensions( mString,
1548 kThemeCurrentPortFont,
1549 kThemeStateActive,
1550 false,
1551 &bounds,
1552 &baseline );
1553 CFRelease( mString ) ;
1554 width = bounds.h ;
1555 }
1556 else
1557#endif
1558 {
1559 width = ::TextWidth( text , 0 , 1 ) ;
1560 }
c257d44d 1561 return YDEV2LOGREL(width) ;
519cb848 1562}
ee41971c 1563wxCoord wxDC::GetCharHeight(void) const
519cb848 1564{
3dec57ad 1565 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
3dec57ad 1566 wxMacPortSetter helper(this) ;
519cb848 1567 MacInstallFont() ;
519cb848
SC
1568 FontInfo fi ;
1569 ::GetFontInfo( &fi ) ;
2f1ae414 1570 return YDEV2LOGREL( fi.descent + fi.ascent );
519cb848 1571}
519cb848
SC
1572void wxDC::Clear(void)
1573{
99030bdf 1574 wxCHECK_RET(Ok(), wxT("Invalid DC"));
3dec57ad 1575 wxMacPortSetter helper(this) ;
32907dbd 1576 Rect rect = { -31000 , -31000 , 31000 , 31000 } ;
99030bdf 1577 if (m_backgroundBrush.GetStyle() != wxTRANSPARENT)
519cb848 1578 {
66a09d47
SC
1579 ::PenNormal() ;
1580 //MacInstallBrush() ;
76a5e5d2 1581 MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ;
519cb848 1582 ::EraseRect( &rect ) ;
3dec57ad 1583 }
519cb848 1584}
519cb848
SC
1585void wxDC::MacInstallFont() const
1586{
3dec57ad 1587 wxCHECK_RET(Ok(), wxT("Invalid DC"));
0eaa1d68
SC
1588// if ( m_macFontInstalled )
1589// return ;
2f1ae414 1590 Pattern blackColor ;
32907dbd 1591 MacSetupBackgroundForCurrentPort(m_backgroundBrush) ;
519cb848 1592 wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
519cb848
SC
1593 if ( font )
1594 {
1595 ::TextFont( font->m_macFontNum ) ;
03e11df5 1596 ::TextSize( short(m_scaleY * font->m_macFontSize) ) ;
519cb848 1597 ::TextFace( font->m_macFontStyle ) ;
519cb848
SC
1598 m_macFontInstalled = true ;
1599 m_macBrushInstalled = false ;
1600 m_macPenInstalled = false ;
76a5e5d2
SC
1601 RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
1602 RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
03e11df5
GD
1603 ::RGBForeColor( &forecolor );
1604 ::RGBBackColor( &backcolor );
519cb848
SC
1605 }
1606 else
1607 {
32907dbd
SC
1608 FontFamilyID fontId ;
1609 Str255 fontName ;
1610 SInt16 fontSize ;
1611 Style fontStyle ;
1612 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
1613 GetFNum( fontName, &fontId );
32907dbd
SC
1614 ::TextFont( fontId ) ;
1615 ::TextSize( short(m_scaleY * fontSize) ) ;
1616 ::TextFace( fontStyle ) ;
519cb848 1617 // todo reset after spacing changes - or store the current spacing somewhere
519cb848
SC
1618 m_macFontInstalled = true ;
1619 m_macBrushInstalled = false ;
1620 m_macPenInstalled = false ;
76a5e5d2
SC
1621 RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
1622 RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
03e11df5
GD
1623 ::RGBForeColor( &forecolor );
1624 ::RGBBackColor( &backcolor );
1625 }
519cb848 1626 short mode = patCopy ;
519cb848 1627 // todo :
519cb848
SC
1628 switch( m_logicalFunction )
1629 {
1630 case wxCOPY: // src
1631 mode = patCopy ;
1632 break ;
1633 case wxINVERT: // NOT dst
2f1ae414 1634 ::PenPat(GetQDGlobalsBlack(&blackColor));
519cb848
SC
1635 mode = patXor ;
1636 break ;
1637 case wxXOR: // src XOR dst
1638 mode = patXor ;
1639 break ;
1640 case wxOR_REVERSE: // src OR (NOT dst)
1641 mode = notPatOr ;
1642 break ;
1643 case wxSRC_INVERT: // (NOT src)
1644 mode = notPatCopy ;
1645 break ;
519cb848 1646 // unsupported TODO
519cb848
SC
1647 case wxCLEAR: // 0
1648 case wxAND_REVERSE:// src AND (NOT dst)
1649 case wxAND: // src AND dst
1650 case wxAND_INVERT: // (NOT src) AND dst
1651 case wxNO_OP: // dst
1652 case wxNOR: // (NOT src) AND (NOT dst)
1653 case wxEQUIV: // (NOT src) XOR dst
1654 case wxOR_INVERT: // (NOT src) OR dst
1655 case wxNAND: // (NOT src) OR (NOT dst)
1656 case wxOR: // src OR dst
1657 case wxSET: // 1
2f1ae414
SC
1658// case wxSRC_OR: // source _bitmap_ OR destination
1659// case wxSRC_AND: // source _bitmap_ AND destination
519cb848
SC
1660 break ;
1661 }
1662 ::PenMode( mode ) ;
66a09d47 1663 OSStatus status = noErr ;
3340066a 1664 Fixed atsuSize = IntToFixed( int(m_scaleY * font->m_macFontSize) ) ;
66a09d47
SC
1665 Style qdStyle = font->m_macFontStyle ;
1666 ATSUFontID atsuFont = font->m_macATSUFontID ;
66a09d47
SC
1667 status = ::ATSUCreateStyle(&(ATSUStyle)m_macATSUIStyle) ;
1668 wxASSERT_MSG( status == noErr , "couldn't create ATSU style" ) ;
66a09d47
SC
1669 ATSUAttributeTag atsuTags[] =
1670 {
1671 kATSUFontTag ,
1672 kATSUSizeTag ,
32907dbd 1673// kATSUColorTag ,
2beae4b5 1674// kATSUBaselineClassTag ,
32907dbd 1675 kATSUVerticalCharacterTag,
66a09d47
SC
1676 kATSUQDBoldfaceTag ,
1677 kATSUQDItalicTag ,
1678 kATSUQDUnderlineTag ,
1679 kATSUQDCondensedTag ,
1680 kATSUQDExtendedTag ,
66a09d47 1681 } ;
66a09d47
SC
1682 ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1683 {
1684 sizeof( ATSUFontID ) ,
1685 sizeof( Fixed ) ,
32907dbd 1686// sizeof( RGBColor ) ,
2beae4b5 1687// sizeof( BslnBaselineClass ) ,
32907dbd 1688 sizeof( ATSUVerticalCharacterType),
66a09d47
SC
1689 sizeof( Boolean ) ,
1690 sizeof( Boolean ) ,
1691 sizeof( Boolean ) ,
1692 sizeof( Boolean ) ,
1693 sizeof( Boolean ) ,
1694 } ;
66a09d47
SC
1695 Boolean kTrue = true ;
1696 Boolean kFalse = false ;
32907dbd 1697 BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
32907dbd 1698 ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
66a09d47
SC
1699 ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1700 {
1701 &atsuFont ,
1702 &atsuSize ,
32907dbd 1703// &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
2beae4b5 1704// &kBaselineDefault ,
32907dbd 1705 &kHorizontal,
66a09d47
SC
1706 (qdStyle & bold) ? &kTrue : &kFalse ,
1707 (qdStyle & italic) ? &kTrue : &kFalse ,
1708 (qdStyle & underline) ? &kTrue : &kFalse ,
1709 (qdStyle & condense) ? &kTrue : &kFalse ,
1710 (qdStyle & extend) ? &kTrue : &kFalse ,
1711 } ;
99030bdf 1712 status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag),
66a09d47
SC
1713 atsuTags, atsuSizes, atsuValues);
1714 wxASSERT_MSG( status == noErr , "couldn't set create ATSU style" ) ;
519cb848 1715}
ffd67837 1716Pattern gHatchPatterns[] =
99030bdf 1717{
3340066a
SC
1718 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } },
1719 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } },
1720 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } },
1721 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } },
1722 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } },
1723 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } },
1724 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } }
ffd67837 1725} ;
519cb848
SC
1726static void wxMacGetHatchPattern(int hatchStyle, Pattern *pattern)
1727{
ffd67837 1728 int theIndex = 1 ;
519cb848
SC
1729 switch(hatchStyle)
1730 {
1731 case wxBDIAGONAL_HATCH:
99030bdf 1732 theIndex = 2;
519cb848
SC
1733 break;
1734 case wxFDIAGONAL_HATCH:
75f7bc3b 1735 theIndex = 3;
519cb848
SC
1736 break;
1737 case wxCROSS_HATCH:
75f7bc3b 1738 theIndex = 4;
519cb848
SC
1739 break;
1740 case wxHORIZONTAL_HATCH:
75f7bc3b 1741 theIndex = 5;
519cb848
SC
1742 break;
1743 case wxVERTICAL_HATCH:
1744 theIndex = 6;
1745 break;
1746 case wxCROSSDIAG_HATCH:
99030bdf 1747 theIndex = 7;
519cb848
SC
1748 break;
1749 default:
1750 theIndex = 1; // solid pattern
1751 break;
1752 }
99030bdf 1753 *pattern = gHatchPatterns[theIndex-1] ;
519cb848 1754}
519cb848
SC
1755void wxDC::MacInstallPen() const
1756{
3dec57ad 1757 wxCHECK_RET(Ok(), wxT("Invalid DC"));
2f1ae414 1758 Pattern blackColor;
0eaa1d68
SC
1759// if ( m_macPenInstalled )
1760// return ;
76a5e5d2
SC
1761 RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
1762 RGBColor backcolor = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel());
03e11df5
GD
1763 ::RGBForeColor( &forecolor );
1764 ::RGBBackColor( &backcolor );
519cb848 1765 ::PenNormal() ;
3dec57ad 1766 int penWidth = m_pen.GetWidth() * (int) m_scaleX ;
0b014ec7
SC
1767 // null means only one pixel, at whatever resolution
1768 if ( penWidth == 0 )
99030bdf 1769 penWidth = 1 ;
519cb848 1770 ::PenSize(penWidth, penWidth);
519cb848 1771 int penStyle = m_pen.GetStyle();
519cb848 1772 if (penStyle == wxSOLID)
03e11df5 1773 {
2f1ae414 1774 ::PenPat(GetQDGlobalsBlack(&blackColor));
03e11df5 1775 }
519cb848
SC
1776 else if (IS_HATCH(penStyle))
1777 {
1778 Pattern pat ;
1779 wxMacGetHatchPattern(penStyle, &pat);
1780 ::PenPat(&pat);
1781 }
1782 else
1783 {
1ff301c4
SC
1784 Pattern pat = *GetQDGlobalsBlack(&blackColor) ;
1785 switch( penStyle )
1786 {
1787 case wxDOT :
1788 for ( int i = 0 ; i < 8 ; ++i )
1789 {
1790 pat.pat[i] = 0xCC ;
1791 }
1792 break ;
1793 case wxLONG_DASH :
1794 for ( int i = 0 ; i < 8 ; ++i )
1795 {
1796 pat.pat[i] = 0xFE ;
1797 }
1798 break ;
1799 case wxSHORT_DASH :
1800 for ( int i = 0 ; i < 8 ; ++i )
1801 {
1802 pat.pat[i] = 0xEE ;
1803 }
1804 break ;
1805 case wxDOT_DASH :
1806 for ( int i = 0 ; i < 8 ; ++i )
1807 {
1808 pat.pat[i] = 0x6F ;
1809 }
1810 break ;
1811 case wxUSER_DASH :
1812 {
1813 wxDash* dash ;
2b5f62a0 1814 m_pen.GetDashes(&dash) ;
1ff301c4 1815 // right now we don't allocate larger pixmaps
5715cc1b
SC
1816 // int number =
1817 m_pen.GetDashes(&dash) ;
1ff301c4
SC
1818 for ( int i = 0 ; i < 8 ; ++i )
1819 {
1820 pat.pat[i] = dash[0] ;
1821 }
1822 }
1823 break ;
1824 }
1825 ::PenPat(&pat);
519cb848 1826 }
519cb848 1827 short mode = patCopy ;
519cb848 1828 // todo :
519cb848
SC
1829 switch( m_logicalFunction )
1830 {
1ff301c4
SC
1831 case wxCOPY: // only foreground color, leave background (thus not patCopy)
1832 mode = patOr ;
519cb848
SC
1833 break ;
1834 case wxINVERT: // NOT dst
1ff301c4 1835// ::PenPat(GetQDGlobalsBlack(&blackColor));
519cb848
SC
1836 mode = patXor ;
1837 break ;
1838 case wxXOR: // src XOR dst
1839 mode = patXor ;
1840 break ;
1841 case wxOR_REVERSE: // src OR (NOT dst)
1842 mode = notPatOr ;
1843 break ;
1844 case wxSRC_INVERT: // (NOT src)
1845 mode = notPatCopy ;
1846 break ;
519cb848 1847 // unsupported TODO
519cb848
SC
1848 case wxCLEAR: // 0
1849 case wxAND_REVERSE:// src AND (NOT dst)
1850 case wxAND: // src AND dst
1851 case wxAND_INVERT: // (NOT src) AND dst
1852 case wxNO_OP: // dst
1853 case wxNOR: // (NOT src) AND (NOT dst)
1854 case wxEQUIV: // (NOT src) XOR dst
1855 case wxOR_INVERT: // (NOT src) OR dst
1856 case wxNAND: // (NOT src) OR (NOT dst)
1857 case wxOR: // src OR dst
1858 case wxSET: // 1
2f1ae414
SC
1859// case wxSRC_OR: // source _bitmap_ OR destination
1860// case wxSRC_AND: // source _bitmap_ AND destination
519cb848
SC
1861 break ;
1862 }
1863 ::PenMode( mode ) ;
1864 m_macPenInstalled = true ;
1865 m_macBrushInstalled = false ;
1866 m_macFontInstalled = false ;
1867}
99030bdf 1868void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background )
1dcbbdcf
SC
1869{
1870 Pattern whiteColor ;
7d9d1fd7
SC
1871 switch( background.MacGetBrushKind() )
1872 {
1873 case kwxMacBrushTheme :
1874 {
1875 ::SetThemeBackground( background.GetMacTheme() , wxDisplayDepth() , true ) ;
1876 break ;
1877 }
1878 case kwxMacBrushThemeBackground :
1879 {
1880 Rect extent ;
1881 ThemeBackgroundKind bg = background.GetMacThemeBackground( &extent ) ;
1882 ::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ;
1883 break ;
1884 }
1885 case kwxMacBrushColour :
1886 {
66a09d47 1887 ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) );
7d9d1fd7
SC
1888 int brushStyle = background.GetStyle();
1889 if (brushStyle == wxSOLID)
1890 ::BackPat(GetQDGlobalsWhite(&whiteColor));
1891 else if (IS_HATCH(brushStyle))
1892 {
1893 Pattern pat ;
1894 wxMacGetHatchPattern(brushStyle, &pat);
1895 ::BackPat(&pat);
1896 }
1897 else
1898 {
1899 ::BackPat(GetQDGlobalsWhite(&whiteColor));
1900 }
1901 break ;
1902 }
1903 }
1dcbbdcf 1904}
519cb848
SC
1905void wxDC::MacInstallBrush() const
1906{
3dec57ad 1907 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1dcbbdcf 1908 Pattern blackColor ;
0eaa1d68
SC
1909// if ( m_macBrushInstalled )
1910// return ;
519cb848 1911 // foreground
76a5e5d2 1912 bool backgroundTransparent = (GetBackgroundMode() == wxTRANSPARENT) ;
76a5e5d2 1913 ::RGBForeColor( &MAC_WXCOLORREF( m_brush.GetColour().GetPixel()) );
0d54461f 1914 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()) );
519cb848
SC
1915 int brushStyle = m_brush.GetStyle();
1916 if (brushStyle == wxSOLID)
0d54461f 1917 {
2f1ae414 1918 ::PenPat(GetQDGlobalsBlack(&blackColor));
0d54461f 1919 }
519cb848
SC
1920 else if (IS_HATCH(brushStyle))
1921 {
1922 Pattern pat ;
1923 wxMacGetHatchPattern(brushStyle, &pat);
1924 ::PenPat(&pat);
1925 }
1ff301c4 1926 else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
519cb848 1927 {
76a5e5d2
SC
1928 // we force this in order to be compliant with wxMSW
1929 backgroundTransparent = false ;
1ff301c4
SC
1930 // for these the text fore (and back for MASK_OPAQUE) colors are used
1931 wxBitmap* bitmap = m_brush.GetStipple() ;
1932 int width = bitmap->GetWidth() ;
1933 int height = bitmap->GetHeight() ;
76a5e5d2 1934 GWorldPtr gw = NULL ;
1ff301c4 1935 if ( m_brush.GetStyle() == wxSTIPPLE )
76a5e5d2 1936 gw = MAC_WXHBITMAP(bitmap->GetHBITMAP()) ;
99030bdf 1937 else
76a5e5d2 1938 gw = MAC_WXHBITMAP(bitmap->GetMask()->GetMaskBitmap()) ;
76a5e5d2
SC
1939 PixMapHandle gwpixmaphandle = GetGWorldPixMap( gw ) ;
1940 LockPixels( gwpixmaphandle ) ;
76a5e5d2 1941 bool isMonochrome = !IsPortColor( gw ) ;
76a5e5d2
SC
1942 if ( !isMonochrome )
1943 {
1944 if ( (**gwpixmaphandle).pixelSize == 1 )
1945 isMonochrome = true ;
1946 }
66a09d47 1947 if ( isMonochrome && width == 8 && height == 8 )
1ff301c4 1948 {
76a5e5d2 1949 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) );
0d54461f 1950 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) );
76a5e5d2
SC
1951 BitMap* gwbitmap = (BitMap*) *gwpixmaphandle ; // since the color depth is 1 it is a BitMap
1952 UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ;
1953 int alignment = gwbitmap->rowBytes & 0x7FFF ;
66a09d47
SC
1954 Pattern pat ;
1955 for ( int i = 0 ; i < 8 ; ++i )
1956 {
1957 pat.pat[i] = gwbits[i*alignment+0] ;
1958 }
1959 UnlockPixels( GetGWorldPixMap( gw ) ) ;
1960 ::PenPat( &pat ) ;
1961 }
1962 else
1963 {
76a5e5d2
SC
1964 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
1965 // caching scheme before putting this into production
66a09d47
SC
1966 Handle image;
1967 long imageSize;
1968 PixPatHandle pixpat = NewPixPat() ;
66a09d47
SC
1969 CopyPixMap(gwpixmaphandle, (**pixpat).patMap);
1970 imageSize = GetPixRowBytes((**pixpat).patMap) *
1971 ((**(**pixpat).patMap).bounds.bottom -
1972 (**(**pixpat).patMap).bounds.top);
66a09d47
SC
1973 PtrToHand( (**gwpixmaphandle).baseAddr, &image, imageSize );
1974 (**pixpat).patData = image;
1975 if ( isMonochrome )
1976 {
76a5e5d2
SC
1977 CTabHandle ctable = ((**((**pixpat).patMap)).pmTable) ;
1978 ColorSpecPtr ctspec = (ColorSpecPtr) &(**ctable).ctTable ;
1979 if ( ctspec[0].rgb.red == 0x0000 )
1980 {
1981 ctspec[1].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
1982 ctspec[0].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
1983 }
1984 else
1985 {
1986 ctspec[0].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
1987 ctspec[1].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
1988 }
1989 ::CTabChanged( ctable ) ;
66a09d47
SC
1990 }
1991 ::PenPixPat(pixpat);
1992 m_macForegroundPixMap = pixpat ;
1ff301c4 1993 }
76a5e5d2 1994 UnlockPixels( gwpixmaphandle ) ;
1ff301c4
SC
1995 }
1996 else
1997 {
1998 ::PenPat(GetQDGlobalsBlack(&blackColor));
519cb848 1999 }
1dcbbdcf 2000 short mode = patCopy ;
519cb848
SC
2001 switch( m_logicalFunction )
2002 {
2003 case wxCOPY: // src
76a5e5d2
SC
2004 if ( backgroundTransparent )
2005 mode = patOr ;
2006 else
2007 mode = patCopy ;
519cb848
SC
2008 break ;
2009 case wxINVERT: // NOT dst
76a5e5d2
SC
2010 if ( !backgroundTransparent )
2011 {
2012 ::PenPat(GetQDGlobalsBlack(&blackColor));
2013 }
519cb848
SC
2014 mode = patXor ;
2015 break ;
2016 case wxXOR: // src XOR dst
2017 mode = patXor ;
2018 break ;
2019 case wxOR_REVERSE: // src OR (NOT dst)
2020 mode = notPatOr ;
2021 break ;
2022 case wxSRC_INVERT: // (NOT src)
2023 mode = notPatCopy ;
2024 break ;
519cb848 2025 // unsupported TODO
519cb848
SC
2026 case wxCLEAR: // 0
2027 case wxAND_REVERSE:// src AND (NOT dst)
2028 case wxAND: // src AND dst
2029 case wxAND_INVERT: // (NOT src) AND dst
2030 case wxNO_OP: // dst
2031 case wxNOR: // (NOT src) AND (NOT dst)
2032 case wxEQUIV: // (NOT src) XOR dst
2033 case wxOR_INVERT: // (NOT src) OR dst
2034 case wxNAND: // (NOT src) OR (NOT dst)
2035 case wxOR: // src OR dst
2036 case wxSET: // 1
2f1ae414
SC
2037// case wxSRC_OR: // source _bitmap_ OR destination
2038// case wxSRC_AND: // source _bitmap_ AND destination
519cb848
SC
2039 break ;
2040 }
2041 ::PenMode( mode ) ;
2042 m_macBrushInstalled = true ;
2043 m_macPenInstalled = false ;
2044 m_macFontInstalled = false ;
2045}
2f1ae414
SC
2046// ---------------------------------------------------------------------------
2047// coordinates transformations
2048// ---------------------------------------------------------------------------
519cb848 2049
2f1ae414
SC
2050wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
2051{
2052 return ((wxDC *)this)->XDEV2LOG(x);
2053}
2f1ae414
SC
2054wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
2055{
2056 return ((wxDC *)this)->YDEV2LOG(y);
2057}
2f1ae414
SC
2058wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
2059{
2060 return ((wxDC *)this)->XDEV2LOGREL(x);
2061}
2f1ae414
SC
2062wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
2063{
2064 return ((wxDC *)this)->YDEV2LOGREL(y);
2065}
2f1ae414
SC
2066wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
2067{
2068 return ((wxDC *)this)->XLOG2DEV(x);
2069}
2f1ae414
SC
2070wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
2071{
2072 return ((wxDC *)this)->YLOG2DEV(y);
2073}
2f1ae414
SC
2074wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
2075{
2076 return ((wxDC *)this)->XLOG2DEVREL(x);
2077}
2f1ae414
SC
2078wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
2079{
2080 return ((wxDC *)this)->YLOG2DEVREL(y);
2ac013b1 2081}