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