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