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