]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dc.cpp
debug handling. More broken Apple 'goodness'
[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
SC
783 double newAngle = 90 - angle ;
784 if ( newAngle < 0 )
785 newAngle += 360 ;
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));
e40298d5 826 if( (xx1 > xx2) || (yy1 > yy2) ) {
3dec57ad
SC
827 alpha2 *= -1;
828 }
3dec57ad 829 Rect r = { yyc - rad, xxc - rad, yyc + rad, xxc + rad };
3dec57ad
SC
830 if(m_brush.GetStyle() != wxTRANSPARENT) {
831 MacInstallBrush();
832 PaintArc(&r, alpha1, alpha2);
833 }
834 if(m_pen.GetStyle() != wxTRANSPARENT) {
835 MacInstallPen();
836 FrameArc(&r, alpha1, alpha2);
837 }
519cb848 838}
e40298d5 839
2f1ae414 840void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
e40298d5 841 double sa, double ea )
519cb848 842{
3dec57ad 843 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
8bebc229 844 wxMacFastPortSetter helper(this) ;
3dec57ad
SC
845 Rect r;
846 double angle = sa - ea; // Order important Mac in opposite direction to wx
2beae4b5
SC
847 // we have to make sure that the filling is always counter-clockwise
848 if ( angle > 0 )
849 angle -= 360 ;
7d9d1fd7
SC
850 wxCoord xx = XLOG2DEVMAC(x);
851 wxCoord yy = YLOG2DEVMAC(y);
3dec57ad
SC
852 wxCoord ww = m_signX * XLOG2DEVREL(w);
853 wxCoord hh = m_signY * YLOG2DEVREL(h);
3dec57ad
SC
854 // handle -ve width and/or height
855 if (ww < 0) { ww = -ww; xx = xx - ww; }
856 if (hh < 0) { hh = -hh; yy = yy - hh; }
3dec57ad 857 sa = wxConvertWXangleToMACangle(sa);
3dec57ad
SC
858 r.top = yy;
859 r.left = xx;
860 r.bottom = yy + hh;
861 r.right = xx + ww;
3dec57ad
SC
862 if(m_brush.GetStyle() != wxTRANSPARENT) {
863 MacInstallBrush();
864 PaintArc(&r, (short)sa, (short)angle);
865 }
866 if(m_pen.GetStyle() != wxTRANSPARENT) {
867 MacInstallPen();
868 FrameArc(&r, (short)sa, (short)angle);
869 }
519cb848 870}
e40298d5 871
2f1ae414 872void wxDC::DoDrawPoint( wxCoord x, wxCoord y )
519cb848 873{
e40298d5 874 wxCHECK_RET(Ok(), wxT("Invalid DC"));
8bebc229 875 wxMacFastPortSetter helper(this) ;
e40298d5
JS
876 if (m_pen.GetStyle() != wxTRANSPARENT)
877 {
99030bdf 878 wxCoord xx1 = XLOG2DEVMAC(x);
7d9d1fd7 879 wxCoord yy1 = YLOG2DEVMAC(y);
5e420341
SC
880 RGBColor pencolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
881 ::SetCPixel( xx1,yy1,&pencolor) ;
882 CalcBoundingBox(x, y);
e40298d5 883 }
519cb848 884}
e40298d5 885
2f1ae414 886void wxDC::DoDrawLines(int n, wxPoint points[],
e40298d5
JS
887 wxCoord xoffset, wxCoord yoffset)
888{
889 wxCHECK_RET(Ok(), wxT("Invalid DC"));
8bebc229 890 wxMacFastPortSetter helper(this) ;
e40298d5
JS
891 if (m_pen.GetStyle() == wxTRANSPARENT)
892 return;
893 MacInstallPen() ;
894 wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 :
895 m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2 ;
896 wxCoord x1, x2 , y1 , y2 ;
897 x1 = XLOG2DEVMAC(points[0].x + xoffset);
898 y1 = YLOG2DEVMAC(points[0].y + yoffset);
899 ::MoveTo(x1 - offset, y1 - offset );
900 for (int i = 0; i < n-1; i++)
901 {
902 x2 = XLOG2DEVMAC(points[i+1].x + xoffset);
903 y2 = YLOG2DEVMAC(points[i+1].y + yoffset);
904 ::LineTo( x2 - offset, y2 - offset );
905 }
519cb848 906}
e40298d5 907
2f1ae414 908void wxDC::DoDrawPolygon(int n, wxPoint points[],
d84afea9
GD
909 wxCoord xoffset, wxCoord yoffset,
910 int fillStyle )
519cb848 911{
e40298d5 912 wxCHECK_RET(Ok(), wxT("Invalid DC"));
8bebc229 913 wxMacFastPortSetter helper(this) ;
e40298d5 914 wxCoord x1, x2 , y1 , y2 ;
75f7bc3b
SC
915 if ( m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT )
916 return ;
e40298d5
JS
917 PolyHandle polygon = OpenPoly();
918 x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset);
919 y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset);
920 ::MoveTo(x1,y1);
921 for (int i = 1; i < n; i++)
922 {
923 x2 = XLOG2DEVMAC(points[i].x + xoffset);
924 y2 = YLOG2DEVMAC(points[i].y + yoffset);
925 ::LineTo(x2, y2);
926 }
76a5e5d2
SC
927 // close the polyline if necessary
928 if ( x1 != x2 || y1 != y2 )
929 {
930 ::LineTo(x1,y1 ) ;
931 }
e40298d5
JS
932 ClosePoly();
933 if (m_brush.GetStyle() != wxTRANSPARENT)
934 {
935 MacInstallBrush();
936 ::PaintPoly( polygon );
937 }
938 if (m_pen.GetStyle() != wxTRANSPARENT)
939 {
940 MacInstallPen() ;
941 ::FramePoly( polygon ) ;
942 }
943 KillPoly( polygon );
519cb848 944}
e40298d5 945
3dec57ad 946void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
519cb848 947{
3dec57ad 948 wxCHECK_RET(Ok(), wxT("Invalid DC"));
8bebc229 949 wxMacFastPortSetter helper(this) ;
e40298d5
JS
950 wxCoord xx = XLOG2DEVMAC(x);
951 wxCoord yy = YLOG2DEVMAC(y);
952 wxCoord ww = m_signX * XLOG2DEVREL(width);
953 wxCoord hh = m_signY * YLOG2DEVREL(height);
954 // CMB: draw nothing if transformed w or h is 0
955 if (ww == 0 || hh == 0)
956 return;
957 // CMB: handle -ve width and/or height
958 if (ww < 0)
959 {
960 ww = -ww;
961 xx = xx - ww;
962 }
963 if (hh < 0)
964 {
965 hh = -hh;
966 yy = yy - hh;
967 }
968 Rect rect = { yy , xx , yy + hh , xx + ww } ;
969 if (m_brush.GetStyle() != wxTRANSPARENT)
970 {
971 MacInstallBrush() ;
972 ::PaintRect( &rect ) ;
973 }
974 if (m_pen.GetStyle() != wxTRANSPARENT)
975 {
976 MacInstallPen() ;
977 ::FrameRect( &rect ) ;
978 }
519cb848 979}
e40298d5 980
2f1ae414 981void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
e40298d5
JS
982 wxCoord width, wxCoord height,
983 double radius)
519cb848 984{
3dec57ad 985 wxCHECK_RET(Ok(), wxT("Invalid DC"));
8bebc229 986 wxMacFastPortSetter helper(this) ;
99030bdf 987 if (radius < 0.0)
e40298d5
JS
988 radius = - radius * ((width < height) ? width : height);
989 wxCoord xx = XLOG2DEVMAC(x);
990 wxCoord yy = YLOG2DEVMAC(y);
991 wxCoord ww = m_signX * XLOG2DEVREL(width);
992 wxCoord hh = m_signY * YLOG2DEVREL(height);
993 // CMB: draw nothing if transformed w or h is 0
994 if (ww == 0 || hh == 0)
995 return;
996 // CMB: handle -ve width and/or height
997 if (ww < 0)
998 {
999 ww = -ww;
1000 xx = xx - ww;
1001 }
1002 if (hh < 0)
1003 {
1004 hh = -hh;
1005 yy = yy - hh;
1006 }
1007 Rect rect = { yy , xx , yy + hh , xx + ww } ;
1008 if (m_brush.GetStyle() != wxTRANSPARENT)
1009 {
1010 MacInstallBrush() ;
1011 ::PaintRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ;
1012 }
1013 if (m_pen.GetStyle() != wxTRANSPARENT)
1014 {
1015 MacInstallPen() ;
1016 ::FrameRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ;
1017 }
519cb848 1018}
e40298d5 1019
2f1ae414 1020void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
519cb848 1021{
3dec57ad 1022 wxCHECK_RET(Ok(), wxT("Invalid DC"));
8bebc229 1023 wxMacFastPortSetter helper(this) ;
e40298d5
JS
1024 wxCoord xx = XLOG2DEVMAC(x);
1025 wxCoord yy = YLOG2DEVMAC(y);
1026 wxCoord ww = m_signX * XLOG2DEVREL(width);
1027 wxCoord hh = m_signY * YLOG2DEVREL(height);
1028 // CMB: draw nothing if transformed w or h is 0
1029 if (ww == 0 || hh == 0)
1030 return;
1031 // CMB: handle -ve width and/or height
1032 if (ww < 0)
1033 {
1034 ww = -ww;
1035 xx = xx - ww;
1036 }
1037 if (hh < 0)
1038 {
1039 hh = -hh;
1040 yy = yy - hh;
1041 }
1042 Rect rect = { yy , xx , yy + hh , xx + ww } ;
1043 if (m_brush.GetStyle() != wxTRANSPARENT)
1044 {
1045 MacInstallBrush() ;
1046 ::PaintOval( &rect ) ;
1047 }
1048 if (m_pen.GetStyle() != wxTRANSPARENT)
1049 {
1050 MacInstallPen() ;
1051 ::FrameOval( &rect ) ;
1052 }
519cb848
SC
1053}
1054
99030bdf 1055bool wxDC::CanDrawBitmap(void) const
519cb848 1056{
e40298d5 1057 return true ;
519cb848
SC
1058}
1059
2f1ae414 1060bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
e40298d5
JS
1061 wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask,
1062 wxCoord xsrcMask, wxCoord ysrcMask )
519cb848 1063{
3dec57ad
SC
1064 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1065 wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
76a5e5d2
SC
1066 if ( logical_func == wxNO_OP )
1067 return TRUE ;
0cbff120
JS
1068 if (xsrcMask == -1 && ysrcMask == -1)
1069 {
1070 xsrcMask = xsrc; ysrcMask = ysrc;
1071 }
76a5e5d2 1072 // correct the parameter in case this dc does not have a mask at all
76a5e5d2
SC
1073 if ( useMask && !source->m_macMask )
1074 useMask = false ;
e40298d5
JS
1075 Rect srcrect , dstrect ;
1076 srcrect.top = source->YLOG2DEVMAC(ysrc) ;
1077 srcrect.left = source->XLOG2DEVMAC(xsrc) ;
1078 srcrect.right = source->XLOG2DEVMAC(xsrc + width ) ;
1079 srcrect.bottom = source->YLOG2DEVMAC(ysrc + height) ;
1080 dstrect.top = YLOG2DEVMAC(ydest) ;
1081 dstrect.left = XLOG2DEVMAC(xdest) ;
1082 dstrect.bottom = YLOG2DEVMAC(ydest + height ) ;
1083 dstrect.right = XLOG2DEVMAC(xdest + width ) ;
76a5e5d2
SC
1084 short mode = kUnsupportedMode ;
1085 bool invertDestinationFirst = false ;
1086 switch ( logical_func )
1087 {
e40298d5 1088 case wxAND: // src AND dst
4a95c885 1089 mode = adMin ; // ok
e40298d5
JS
1090 break ;
1091 case wxAND_INVERT: // (NOT src) AND dst
1092 mode = notSrcOr ; // ok
1093 break ;
1094 case wxAND_REVERSE:// src AND (NOT dst)
1095 invertDestinationFirst = true ;
1096 mode = srcOr ;
1097 break ;
1098 case wxCLEAR: // 0
1099 mode = kEmulatedMode ;
1100 break ;
1101 case wxCOPY: // src
1102 mode = srcCopy ; // ok
1103 break ;
1104 case wxEQUIV: // (NOT src) XOR dst
1105 mode = srcXor ; // ok
1106 break ;
1107 case wxINVERT: // NOT dst
1108 mode = kEmulatedMode ; //or hilite ;
1109 break ;
1110 case wxNAND: // (NOT src) OR (NOT dst)
1111 invertDestinationFirst = true ;
1112 mode = srcBic ;
1113 break ;
1114 case wxNOR: // (NOT src) AND (NOT dst)
1115 invertDestinationFirst = true ;
1116 mode = notSrcOr ;
1117 break ;
1118 case wxNO_OP: // dst
1119 mode = kEmulatedMode ; // this has already been handled upon entry
1120 break ;
1121 case wxOR: // src OR dst
1122 mode = notSrcBic ;
1123 break ;
1124 case wxOR_INVERT: // (NOT src) OR dst
1125 mode = srcBic ;
1126 break ;
1127 case wxOR_REVERSE: // src OR (NOT dst)
1128 invertDestinationFirst = true ;
1129 mode = notSrcBic ;
1130 break ;
1131 case wxSET: // 1
1132 mode = kEmulatedMode ;
1133 break ;
1134 case wxSRC_INVERT: // (NOT src)
1135 mode = notSrcCopy ; // ok
1136 break ;
1137 case wxXOR: // src XOR dst
1138 mode = notSrcXor ; // ok
1139 break ;
1140 default :
1141 break ;
76a5e5d2 1142 }
76a5e5d2
SC
1143 if ( mode == kUnsupportedMode )
1144 {
427ff662 1145 wxFAIL_MSG(wxT("unsupported blitting mode" ));
76a5e5d2
SC
1146 return FALSE ;
1147 }
e40298d5
JS
1148 CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ;
1149 PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ;
1150 if ( LockPixels(bmappixels) )
1151 {
8bebc229 1152 wxMacFastPortSetter helper(this) ;
e40298d5
JS
1153 if ( source->GetDepth() == 1 )
1154 {
1155 RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ;
1156 RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour.GetPixel()) ) ;
76a5e5d2
SC
1157 }
1158 else
1159 {
1160 // the modes need this, otherwise we'll end up having really nice colors...
e40298d5
JS
1161 RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ;
1162 RGBColor black = { 0,0,0} ;
1163 RGBForeColor( &black ) ;
1164 RGBBackColor( &white ) ;
76a5e5d2 1165 }
e40298d5
JS
1166 if ( useMask && source->m_macMask )
1167 {
1168 if ( mode == srcCopy )
1169 {
1170 if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) )
1171 {
1172 CopyMask( GetPortBitMapForCopyBits( sourcePort ) ,
1173 GetPortBitMapForCopyBits( MAC_WXHBITMAP(source->m_macMask) ) ,
1174 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
1175 &srcrect, &srcrect , &dstrect ) ;
1176 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
1177 }
1178 }
1179 else
1180 {
1dcbbdcf 1181 RgnHandle clipRgn = NewRgn() ;
76a5e5d2
SC
1182 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
1183 BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
1184 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
1dcbbdcf 1185 OffsetRgn( clipRgn , -srcrect.left + dstrect.left, -srcrect.top + dstrect.top ) ;
76a5e5d2
SC
1186 if ( mode == kEmulatedMode )
1187 {
1188 Pattern pat ;
e40298d5 1189 ::PenPat(GetQDGlobalsBlack(&pat));
76a5e5d2
SC
1190 if ( logical_func == wxSET )
1191 {
1192 RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
e40298d5 1193 ::RGBForeColor( &col ) ;
76a5e5d2
SC
1194 ::PaintRgn( clipRgn ) ;
1195 }
1196 else if ( logical_func == wxCLEAR )
1197 {
1198 RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
e40298d5 1199 ::RGBForeColor( &col ) ;
76a5e5d2
SC
1200 ::PaintRgn( clipRgn ) ;
1201 }
1202 else if ( logical_func == wxINVERT )
1203 {
1204 MacInvertRgn( clipRgn ) ;
1205 }
1206 else
1207 {
1208 for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
1209 {
1210 for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
1211 {
1212 Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
1213 Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
1214 if ( PtInRgn( dstPoint , clipRgn ) )
1215 {
1216 RGBColor srcColor ;
1217 RGBColor dstColor ;
76a5e5d2
SC
1218 SetPort( (GrafPtr) sourcePort ) ;
1219 GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ;
1220 SetPort( (GrafPtr) m_macPort ) ;
1221 GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
76a5e5d2
SC
1222 wxMacCalculateColour( logical_func , srcColor , dstColor ) ;
1223 SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
1224 }
1225 }
1226 }
76a5e5d2
SC
1227 }
1228 }
1229 else
1230 {
1231 if ( invertDestinationFirst )
1232 {
1233 MacInvertRgn( clipRgn ) ;
1234 }
e40298d5
JS
1235 CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,
1236 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
1237 &srcrect, &dstrect, mode, clipRgn ) ;
1238 }
1239 DisposeRgn( clipRgn ) ;
1240 }
1241 }
1242 else
1243 {
0d54461f
SC
1244 RgnHandle clipRgn = NewRgn() ;
1245 SetRectRgn( clipRgn , dstrect.left , dstrect.top , dstrect.right , dstrect.bottom ) ;
e40298d5
JS
1246 if ( mode == kEmulatedMode )
1247 {
0d54461f 1248 Pattern pat ;
e40298d5 1249 ::PenPat(GetQDGlobalsBlack(&pat));
0d54461f
SC
1250 if ( logical_func == wxSET )
1251 {
1252 RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
e40298d5 1253 ::RGBForeColor( &col ) ;
0d54461f
SC
1254 ::PaintRgn( clipRgn ) ;
1255 }
1256 else if ( logical_func == wxCLEAR )
1257 {
1258 RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
e40298d5 1259 ::RGBForeColor( &col ) ;
0d54461f
SC
1260 ::PaintRgn( clipRgn ) ;
1261 }
1262 else if ( logical_func == wxINVERT )
1263 {
1264 MacInvertRgn( clipRgn ) ;
1265 }
1266 else
1267 {
1268 for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
1269 {
1270 for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
1271 {
1272 Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
1273 Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
0d54461f
SC
1274 {
1275 RGBColor srcColor ;
1276 RGBColor dstColor ;
0d54461f
SC
1277 SetPort( (GrafPtr) sourcePort ) ;
1278 GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ;
1279 SetPort( (GrafPtr) m_macPort ) ;
1280 GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
0d54461f
SC
1281 wxMacCalculateColour( logical_func , srcColor , dstColor ) ;
1282 SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
1283 }
1284 }
1285 }
1286 }
e40298d5
JS
1287 }
1288 else
1289 {
0d54461f
SC
1290 if ( invertDestinationFirst )
1291 {
1292 MacInvertRgn( clipRgn ) ;
1293 }
e40298d5
JS
1294 CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,
1295 GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
1296 &srcrect, &dstrect, mode, NULL ) ;
1297 }
1298 DisposeRgn( clipRgn ) ;
1299 }
1300 UnlockPixels( bmappixels ) ;
1301 }
1302 m_macPenInstalled = false ;
1303 m_macBrushInstalled = false ;
1304 m_macFontInstalled = false ;
1305 return TRUE;
1306}
1307
42800de6
SC
1308#ifndef FixedToInt
1309// as macro in FixMath.h for 10.3
e40298d5
JS
1310inline Fixed IntToFixed( int inInt )
1311{
1312 return (((SInt32) inInt) << 16);
1313}
1314
1315inline int FixedToInt( Fixed inFixed )
1316{
1317 return (((SInt32) inFixed) >> 16);
1318}
42800de6 1319#endif
2beae4b5 1320
66a09d47 1321void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
3dec57ad 1322 double angle)
2f1ae414 1323{
3dec57ad 1324 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
facd6764 1325/*
32907dbd 1326 if (angle == 0.0 )
3dec57ad 1327 {
66a09d47 1328 DrawText(str, x, y);
3dec57ad
SC
1329 return;
1330 }
26b9b4e1 1331
32907dbd
SC
1332 if ( str.Length() == 0 )
1333 return ;
facd6764 1334*/
8bebc229 1335 wxMacFastPortSetter helper(this) ;
66a09d47 1336 MacInstallFont() ;
427ff662 1337
66a09d47 1338 if ( 0 )
3dec57ad 1339 {
66a09d47 1340 m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);
facd6764 1341 SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * m_font.MacGetFontSize()));
66a09d47 1342 m_macAliasWasEnabled = true ;
3dec57ad 1343 }
66a09d47 1344 OSStatus status = noErr ;
427ff662
SC
1345 ATSUTextLayout atsuLayout ;
1346 UniCharCount chars = str.Length() ;
96cadce3
SC
1347 UniChar* ubuf = NULL ;
1348#if SIZEOF_WCHAR_T == 4
1349 wxMBConvUTF16BE converter ;
427ff662 1350#if wxUSE_UNICODE
96cadce3
SC
1351 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
1352 ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
1353 converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ;
1354#else
1355 const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
1356 size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
1357 ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
1358 converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
1359#endif
1360 chars = unicharlen / 2 ;
1361#else
1362#if wxUSE_UNICODE
1363 ubuf = (UniChar*) str.wc_str() ;
427ff662 1364#else
939fba6c 1365 wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
96cadce3
SC
1366 chars = wxWcslen( wchar.data() ) ;
1367 ubuf = (UniChar*) wchar.data() ;
427ff662 1368#endif
96cadce3
SC
1369#endif
1370
1371 status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
1372 &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
1373
427ff662 1374 wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") );
3340066a 1375 int iAngle = int( angle );
2beae4b5
SC
1376 int drawX = XLOG2DEVMAC(x) ;
1377 int drawY = YLOG2DEVMAC(y) ;
1378
1379 ATSUTextMeasurement textBefore ;
1380 ATSUTextMeasurement textAfter ;
1381 ATSUTextMeasurement ascent ;
1382 ATSUTextMeasurement descent ;
1383
1384
3340066a 1385 if ( abs(iAngle) > 0 )
32907dbd 1386 {
3340066a 1387 Fixed atsuAngle = IntToFixed( iAngle ) ;
e40298d5
JS
1388 ATSUAttributeTag atsuTags[] =
1389 {
1390 kATSULineRotationTag ,
1391 } ;
1392 ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1393 {
1394 sizeof( Fixed ) ,
1395 } ;
1396 ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1397 {
1398 &atsuAngle ,
1399 } ;
1400 status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag),
1401 atsuTags, atsuSizes, atsuValues ) ;
1402 }
1403 status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
1404 &textBefore , &textAfter, &ascent , &descent );
2beae4b5 1405
5be55d56
VZ
1406 drawX += (int)(sin(angle/RAD2DEG) * FixedToInt(ascent));
1407 drawY += (int)(cos(angle/RAD2DEG) * FixedToInt(ascent));
32907dbd 1408 status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
e40298d5 1409 IntToFixed(drawX) , IntToFixed(drawY) );
427ff662 1410 wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") );
66a09d47 1411 Rect rect ;
e40298d5
JS
1412 status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
1413 IntToFixed(drawX) , IntToFixed(drawY) , &rect );
427ff662 1414 wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
66a09d47
SC
1415 OffsetRect( &rect , -m_macLocalOrigin.x , -m_macLocalOrigin.y ) ;
1416 CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) );
1417 CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) );
1418 ::ATSUDisposeTextLayout(atsuLayout);
96cadce3
SC
1419#if SIZEOF_WCHAR_T == 4
1420 free( ubuf ) ;
1421#endif
2f1ae414 1422}
e40298d5 1423
2f1ae414 1424void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
99030bdf 1425{
3dec57ad 1426 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
26b9b4e1 1427
8bebc229 1428 wxMacFastPortSetter helper(this) ;
e40298d5
JS
1429 long xx = XLOG2DEVMAC(x);
1430 long yy = YLOG2DEVMAC(y);
99030bdf 1431#if TARGET_CARBON
e40298d5 1432 bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ;
b7047aa5 1433 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || m_font.GetNoAntiAliasing() )
e40298d5 1434 useDrawThemeText = false ;
6606ecac 1435#endif
e40298d5 1436 MacInstallFont() ;
99030bdf 1437 if ( 0 )
66a09d47
SC
1438 {
1439 m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);
1440 SetAntiAliasedTextEnabled(true, 8);
1441 m_macAliasWasEnabled = true ;
1442 }
e40298d5
JS
1443 FontInfo fi ;
1444 ::GetFontInfo( &fi ) ;
99030bdf 1445#if TARGET_CARBON
e40298d5 1446 if ( !useDrawThemeText )
6606ecac 1447#endif
e40298d5
JS
1448 yy += fi.ascent ;
1449 ::MoveTo( xx , yy );
1450 if ( m_backgroundMode == wxTRANSPARENT )
1451 {
1452 ::TextMode( srcOr) ;
1453 }
1454 else
1455 {
1456 ::TextMode( srcCopy ) ;
1457 }
e40298d5
JS
1458 int line = 0 ;
1459 {
b93f3832 1460 wxString linetext = strtext ;
6606ecac 1461#if TARGET_CARBON
32907dbd 1462 if ( useDrawThemeText )
e40298d5
JS
1463 {
1464 Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ;
a9412f8f 1465 wxMacCFStringHolder mString( linetext , m_font.GetEncoding()) ;
4a95c885 1466
5fa00d24
SC
1467 if ( m_backgroundMode != wxTRANSPARENT )
1468 {
e40298d5
JS
1469 Point bounds={0,0} ;
1470 Rect background = frame ;
1471 SInt16 baseline ;
1472 ::GetThemeTextDimensions( mString,
facd6764 1473 m_font.MacGetThemeFontID() ,
e40298d5
JS
1474 kThemeStateActive,
1475 false,
1476 &bounds,
1477 &baseline );
1478 background.right = background.left + bounds.h ;
1479 background.bottom = background.top + bounds.v ;
1480 ::EraseRect( &background ) ;
5fa00d24 1481 }
e40298d5 1482 ::DrawThemeTextBox( mString,
facd6764 1483 m_font.MacGetThemeFontID() ,
e40298d5
JS
1484 kThemeStateActive,
1485 false,
1486 &frame,
1487 teJustLeft,
1488 nil );
32907dbd
SC
1489 }
1490 else
6606ecac 1491#endif
99030bdf 1492 {
939fba6c 1493 wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
b93f3832
SC
1494 if ( m_backgroundMode != wxTRANSPARENT )
1495 {
1496 Rect frame = { yy - fi.ascent + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy - fi.ascent + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ;
1497 short width = ::TextWidth( text , 0 , strlen(text) ) ;
1498 frame.right = frame.left + width ;
1499
1500 ::EraseRect( &frame ) ;
1501 }
427ff662
SC
1502 ::DrawText( text , 0 , strlen(text) ) ;
1503 }
e40298d5
JS
1504 }
1505 ::TextMode( srcOr ) ;
519cb848 1506}
e40298d5 1507
99030bdf 1508bool wxDC::CanGetTextExtent() const
519cb848 1509{
e40298d5
JS
1510 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1511 return true ;
519cb848 1512}
e40298d5 1513
427ff662 1514void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *height,
e40298d5
JS
1515 wxCoord *descent, wxCoord *externalLeading ,
1516 wxFont *theFont ) const
1517{
1518 wxCHECK_RET(Ok(), wxT("Invalid DC"));
8bebc229 1519 wxMacFastPortSetter helper(this) ;
e40298d5
JS
1520 wxFont formerFont = m_font ;
1521 if ( theFont )
1522 {
1523 // work around the constness
1524 *((wxFont*)(&m_font)) = *theFont ;
1525 }
1526 MacInstallFont() ;
1527 FontInfo fi ;
1528 ::GetFontInfo( &fi ) ;
1529#if TARGET_CARBON
1530 bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ;
b7047aa5 1531 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() )
e40298d5 1532 useGetThemeText = false ;
f52640f3 1533#endif
e40298d5
JS
1534 if ( height )
1535 *height = YDEV2LOGREL( fi.descent + fi.ascent ) ;
1536 if ( descent )
1537 *descent =YDEV2LOGREL( fi.descent );
1538 if ( externalLeading )
1539 *externalLeading = YDEV2LOGREL( fi.leading ) ;
939fba6c 1540
e40298d5
JS
1541 int curwidth = 0 ;
1542 if ( width )
1543 {
1544 *width = 0 ;
b93f3832 1545 wxString linetext = strtext ;
facd6764 1546
f52640f3
SC
1547 if ( useGetThemeText )
1548 {
1549 Point bounds={0,0} ;
aee9fe73 1550 SInt16 baseline ;
a9412f8f 1551 wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ;
facd6764 1552 ThemeFontID themeFont = m_font.MacGetThemeFontID() ;
e40298d5 1553 ::GetThemeTextDimensions( mString,
facd6764 1554 themeFont ,
e40298d5
JS
1555 kThemeStateActive,
1556 false,
1557 &bounds,
1558 &baseline );
e40298d5 1559 curwidth = bounds.h ;
f52640f3
SC
1560 }
1561 else
f52640f3 1562 {
939fba6c 1563 wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
427ff662 1564 curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
e40298d5
JS
1565 }
1566 if ( curwidth > *width )
1567 *width = XDEV2LOGREL( curwidth ) ;
1568 }
1569 if ( theFont )
1570 {
1571 // work around the constness
1572 *((wxFont*)(&m_font)) = formerFont ;
1573 m_macFontInstalled = false ;
1574 }
519cb848 1575}
e40298d5 1576
0919e93e
RD
1577
1578bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
1579{
1580 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1581
1582 widths.Empty();
1583 widths.Add(0, text.Length());
1584
1585 if (text.Length() == 0)
1586 return false;
1587
1588 wxMacFastPortSetter helper(this) ;
1589 MacInstallFont() ;
1590#if TARGET_CARBON
1591 bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ;
1592 if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() )
1593 useGetThemeText = false ;
1594
1595 if ( useGetThemeText )
1596 {
1597 // If anybody knows how to do this more efficiently yet still handle
1598 // the fractional glyph widths that may be present when using AA
1599 // fonts, please change it. Currently it is measuring from the
1600 // begining of the string for each succeding substring, which is much
1601 // slower than this should be.
1602 for (size_t i=0; i<text.Length(); i++)
1603 {
1604 wxString str(text.Left(i+1));
1605 Point bounds = {0,0};
1606 SInt16 baseline ;
1607 wxMacCFStringHolder mString(str, m_font.GetEncoding());
1608 ::GetThemeTextDimensions( mString,
facd6764 1609 m_font.MacGetThemeFontID(),
0919e93e
RD
1610 kThemeStateActive,
1611 false,
1612 &bounds,
1613 &baseline );
1614 widths[i] = XDEV2LOGREL(bounds.h);
1615 }
1616 }
1617 else
1618#endif
1619 {
1620 wxCharBuffer buff = text.mb_str(wxConvLocal);
1621 size_t len = strlen(buff);
1622 short* measurements = new short[len+1];
1623 MeasureText(len, buff.data(), measurements);
1624
1625 // Copy to widths, starting at measurements[1]
1626 // NOTE: this doesn't take into account any multi-byte characters
1627 // in buff, it probabkly should...
1628 for (size_t i=0; i<text.Length(); i++)
1629 widths[i] = XDEV2LOGREL(measurements[i+1]);
1630
1631 delete [] measurements;
1632 }
1633
1634 return true;
1635}
1636
1637
1638
ee41971c 1639wxCoord wxDC::GetCharWidth(void) const
519cb848 1640{
3dec57ad 1641 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
8bebc229 1642 wxMacFastPortSetter helper(this) ;
e40298d5 1643 MacInstallFont() ;
2beae4b5
SC
1644 int width = 0 ;
1645#if TARGET_CARBON
e40298d5 1646 bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ;
b7047aa5 1647 if ( UMAGetSystemVersion() < 0x1000 || ((wxFont*)&m_font)->GetNoAntiAliasing() )
e40298d5 1648 useGetThemeText = false ;
2beae4b5 1649#endif
95c430aa 1650 char text[] = "g" ;
2beae4b5
SC
1651#if TARGET_CARBON
1652 if ( useGetThemeText )
1653 {
1654 Point bounds={0,0} ;
1655 SInt16 baseline ;
1656 CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text , 1 , CFStringGetSystemEncoding(), false ) ;
e40298d5 1657 ::GetThemeTextDimensions( mString,
facd6764 1658 m_font.MacGetThemeFontID(),
e40298d5
JS
1659 kThemeStateActive,
1660 false,
1661 &bounds,
1662 &baseline );
1663 CFRelease( mString ) ;
1664 width = bounds.h ;
2beae4b5
SC
1665 }
1666 else
1667#endif
1668 {
e40298d5
JS
1669 width = ::TextWidth( text , 0 , 1 ) ;
1670 }
1671 return YDEV2LOGREL(width) ;
519cb848 1672}
e40298d5 1673
ee41971c 1674wxCoord wxDC::GetCharHeight(void) const
519cb848 1675{
3dec57ad 1676 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
8bebc229 1677 wxMacFastPortSetter helper(this) ;
e40298d5
JS
1678 MacInstallFont() ;
1679 FontInfo fi ;
1680 ::GetFontInfo( &fi ) ;
1681 return YDEV2LOGREL( fi.descent + fi.ascent );
519cb848 1682}
e40298d5 1683
519cb848
SC
1684void wxDC::Clear(void)
1685{
99030bdf 1686 wxCHECK_RET(Ok(), wxT("Invalid DC"));
8bebc229 1687 wxMacFastPortSetter helper(this) ;
e40298d5 1688 Rect rect = { -31000 , -31000 , 31000 , 31000 } ;
f6809556 1689 if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT)
e40298d5
JS
1690 {
1691 ::PenNormal() ;
76a5e5d2 1692 MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ;
e40298d5
JS
1693 ::EraseRect( &rect ) ;
1694 }
519cb848 1695}
e40298d5 1696
519cb848
SC
1697void wxDC::MacInstallFont() const
1698{
3dec57ad 1699 wxCHECK_RET(Ok(), wxT("Invalid DC"));
e40298d5
JS
1700 // if ( m_macFontInstalled )
1701 // return ;
1702 Pattern blackColor ;
1703 MacSetupBackgroundForCurrentPort(m_backgroundBrush) ;
fcb35beb 1704 if ( m_font.Ok() )
e40298d5 1705 {
facd6764
SC
1706 ::TextFont( m_font.MacGetFontNum() ) ;
1707 ::TextSize( (short)(m_scaleY * m_font.MacGetFontSize()) ) ;
1708 ::TextFace( m_font.MacGetFontStyle() ) ;
e40298d5
JS
1709 m_macFontInstalled = true ;
1710 m_macBrushInstalled = false ;
1711 m_macPenInstalled = false ;
1712 RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
1713 RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
1714 ::RGBForeColor( &forecolor );
1715 ::RGBBackColor( &backcolor );
1716 }
1717 else
1718 {
32907dbd 1719 FontFamilyID fontId ;
e40298d5
JS
1720 Str255 fontName ;
1721 SInt16 fontSize ;
1722 Style fontStyle ;
1723 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
32907dbd 1724 GetFNum( fontName, &fontId );
e40298d5
JS
1725 ::TextFont( fontId ) ;
1726 ::TextSize( short(m_scaleY * fontSize) ) ;
1727 ::TextFace( fontStyle ) ;
1728 // todo reset after spacing changes - or store the current spacing somewhere
1729 m_macFontInstalled = true ;
1730 m_macBrushInstalled = false ;
1731 m_macPenInstalled = false ;
1732 RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
1733 RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
1734 ::RGBForeColor( &forecolor );
1735 ::RGBBackColor( &backcolor );
1736 }
1737 short mode = patCopy ;
1738 // todo :
1739 switch( m_logicalFunction )
1740 {
1741 case wxCOPY: // src
1742 mode = patCopy ;
1743 break ;
1744 case wxINVERT: // NOT dst
1745 ::PenPat(GetQDGlobalsBlack(&blackColor));
1746 mode = patXor ;
1747 break ;
1748 case wxXOR: // src XOR dst
1749 mode = patXor ;
1750 break ;
1751 case wxOR_REVERSE: // src OR (NOT dst)
1752 mode = notPatOr ;
1753 break ;
1754 case wxSRC_INVERT: // (NOT src)
1755 mode = notPatCopy ;
1756 break ;
4a95c885
SC
1757 case wxAND: // src AND dst
1758 mode = adMin ;
1759 break ;
e40298d5
JS
1760 // unsupported TODO
1761 case wxCLEAR: // 0
1762 case wxAND_REVERSE:// src AND (NOT dst)
e40298d5
JS
1763 case wxAND_INVERT: // (NOT src) AND dst
1764 case wxNO_OP: // dst
1765 case wxNOR: // (NOT src) AND (NOT dst)
1766 case wxEQUIV: // (NOT src) XOR dst
1767 case wxOR_INVERT: // (NOT src) OR dst
1768 case wxNAND: // (NOT src) OR (NOT dst)
1769 case wxOR: // src OR dst
1770 case wxSET: // 1
1771 // case wxSRC_OR: // source _bitmap_ OR destination
1772 // case wxSRC_AND: // source _bitmap_ AND destination
1773 break ;
1774 }
1775 ::PenMode( mode ) ;
66a09d47 1776 OSStatus status = noErr ;
facd6764
SC
1777 Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.MacGetFontSize()) ) ;
1778 Style qdStyle = m_font.MacGetATSUAdditionalQDStyles() ;
1779 ATSUFontID atsuFont = m_font.MacGetATSUFontID() ;
73bdd73a 1780 status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUIStyle) ;
427ff662 1781 wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ) ;
e40298d5
JS
1782 ATSUAttributeTag atsuTags[] =
1783 {
1784 kATSUFontTag ,
1785 kATSUSizeTag ,
1786 // kATSUColorTag ,
1787 // kATSUBaselineClassTag ,
1788 kATSUVerticalCharacterTag,
1789 kATSUQDBoldfaceTag ,
1790 kATSUQDItalicTag ,
1791 kATSUQDUnderlineTag ,
1792 kATSUQDCondensedTag ,
1793 kATSUQDExtendedTag ,
1794 } ;
66a09d47
SC
1795 ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1796 {
1797 sizeof( ATSUFontID ) ,
e40298d5
JS
1798 sizeof( Fixed ) ,
1799 // sizeof( RGBColor ) ,
1800 // sizeof( BslnBaselineClass ) ,
1801 sizeof( ATSUVerticalCharacterType),
1802 sizeof( Boolean ) ,
1803 sizeof( Boolean ) ,
1804 sizeof( Boolean ) ,
1805 sizeof( Boolean ) ,
1806 sizeof( Boolean ) ,
66a09d47 1807 } ;
66a09d47
SC
1808 Boolean kTrue = true ;
1809 Boolean kFalse = false ;
5be55d56 1810 //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
32907dbd 1811 ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
e40298d5
JS
1812 ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1813 {
1814 &atsuFont ,
1815 &atsuSize ,
1816 // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
1817 // &kBaselineDefault ,
1818 &kHorizontal,
1819 (qdStyle & bold) ? &kTrue : &kFalse ,
1820 (qdStyle & italic) ? &kTrue : &kFalse ,
1821 (qdStyle & underline) ? &kTrue : &kFalse ,
1822 (qdStyle & condense) ? &kTrue : &kFalse ,
1823 (qdStyle & extend) ? &kTrue : &kFalse ,
1824 } ;
26b9b4e1 1825 status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
e40298d5 1826 atsuTags, atsuSizes, atsuValues);
427ff662 1827 wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ;
519cb848 1828}
e40298d5 1829
411bdf74
RR
1830Pattern gPatterns[] =
1831{ // hatch patterns
a47ae718
VZ
1832 { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
1833 { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
1834 { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
1835 { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1836 { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
1837 { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
1838 { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
411bdf74 1839 // dash patterns
a47ae718
VZ
1840 { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
1841 { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
1842 { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
1843 { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
ffd67837 1844} ;
e40298d5 1845
411bdf74
RR
1846static void wxMacGetPattern(int penStyle, Pattern *pattern)
1847{
1848 int index = 0; // solid pattern by default
1849 switch(penStyle)
1850 {
1851 // hatches
1852 case wxBDIAGONAL_HATCH: index = 1; break;
1853 case wxFDIAGONAL_HATCH: index = 2; break;
1854 case wxCROSS_HATCH: index = 3; break;
1855 case wxHORIZONTAL_HATCH: index = 4; break;
1856 case wxVERTICAL_HATCH: index = 5; break;
1857 case wxCROSSDIAG_HATCH: index = 6; break;
1858 // dashes
1859 case wxDOT: index = 7; break;
1860 case wxLONG_DASH: index = 8; break;
1861 case wxSHORT_DASH: index = 9; break;
1862 case wxDOT_DASH: index = 10; break;
1863 }
1864 *pattern = gPatterns[index];
519cb848 1865}
e40298d5 1866
519cb848
SC
1867void wxDC::MacInstallPen() const
1868{
3dec57ad 1869 wxCHECK_RET(Ok(), wxT("Invalid DC"));
a47ae718 1870 //Pattern blackColor;
e40298d5
JS
1871 // if ( m_macPenInstalled )
1872 // return ;
1873 RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
1874 RGBColor backcolor = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel());
1875 ::RGBForeColor( &forecolor );
1876 ::RGBBackColor( &backcolor );
1877 ::PenNormal() ;
669b65b9 1878 int penWidth = (int) (m_pen.GetWidth() * m_scaleX) ; ;
e40298d5
JS
1879 // null means only one pixel, at whatever resolution
1880 if ( penWidth == 0 )
1881 penWidth = 1 ;
1882 ::PenSize(penWidth, penWidth);
411bdf74 1883
e40298d5 1884 int penStyle = m_pen.GetStyle();
411bdf74
RR
1885 Pattern pat;
1886 if (penStyle == wxUSER_DASH)
1887 {
1888 // FIXME: there should be exactly 8 items in the dash
1889 wxDash* dash ;
1890 int number = m_pen.GetDashes(&dash) ;
1891 int index = 0;
1892 for ( int i = 0 ; i < 8 ; ++i )
1893 {
1894 pat.pat[i] = dash[index] ;
1895 if (index < number - 1)
1896 index++;
1897 }
e40298d5
JS
1898 }
1899 else
1900 {
411bdf74 1901 wxMacGetPattern(penStyle, &pat);
e40298d5 1902 }
411bdf74
RR
1903 ::PenPat(&pat);
1904
e40298d5
JS
1905 short mode = patCopy ;
1906 // todo :
1907 switch( m_logicalFunction )
1908 {
1909 case wxCOPY: // only foreground color, leave background (thus not patCopy)
1910 mode = patOr ;
1911 break ;
1912 case wxINVERT: // NOT dst
1913 // ::PenPat(GetQDGlobalsBlack(&blackColor));
1914 mode = patXor ;
1915 break ;
1916 case wxXOR: // src XOR dst
1917 mode = patXor ;
1918 break ;
1919 case wxOR_REVERSE: // src OR (NOT dst)
1920 mode = notPatOr ;
1921 break ;
1922 case wxSRC_INVERT: // (NOT src)
1923 mode = notPatCopy ;
1924 break ;
4a95c885
SC
1925 case wxAND: // src AND dst
1926 mode = adMin ;
1927 break ;
e40298d5
JS
1928 // unsupported TODO
1929 case wxCLEAR: // 0
1930 case wxAND_REVERSE:// src AND (NOT dst)
e40298d5
JS
1931 case wxAND_INVERT: // (NOT src) AND dst
1932 case wxNO_OP: // dst
1933 case wxNOR: // (NOT src) AND (NOT dst)
1934 case wxEQUIV: // (NOT src) XOR dst
1935 case wxOR_INVERT: // (NOT src) OR dst
1936 case wxNAND: // (NOT src) OR (NOT dst)
1937 case wxOR: // src OR dst
1938 case wxSET: // 1
1939 // case wxSRC_OR: // source _bitmap_ OR destination
1940 // case wxSRC_AND: // source _bitmap_ AND destination
1941 break ;
1942 }
1943 ::PenMode( mode ) ;
1944 m_macPenInstalled = true ;
1945 m_macBrushInstalled = false ;
1946 m_macFontInstalled = false ;
519cb848 1947}
e40298d5 1948
99030bdf 1949void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background )
1dcbbdcf
SC
1950{
1951 Pattern whiteColor ;
f6809556 1952 if ( background.Ok() )
7d9d1fd7 1953 {
f6809556 1954 switch( background.MacGetBrushKind() )
7d9d1fd7 1955 {
f6809556 1956 case kwxMacBrushTheme :
e40298d5 1957 {
f6809556
SC
1958 ::SetThemeBackground( background.MacGetTheme() , wxDisplayDepth() , true ) ;
1959 break ;
e40298d5 1960 }
f6809556 1961 case kwxMacBrushThemeBackground :
e40298d5 1962 {
f6809556
SC
1963 Rect extent ;
1964 ThemeBackgroundKind bg = background.MacGetThemeBackground( &extent ) ;
1965 ::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ;
1966 break ;
1967 }
1968 case kwxMacBrushColour :
1969 {
1970 ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) );
1971 int brushStyle = background.GetStyle();
1972 if (brushStyle == wxSOLID)
1973 ::BackPat(GetQDGlobalsWhite(&whiteColor));
1974 else if (IS_HATCH(brushStyle))
1975 {
1976 Pattern pat ;
1977 wxMacGetPattern(brushStyle, &pat);
1978 ::BackPat(&pat);
1979 }
1980 else
1981 {
1982 ::BackPat(GetQDGlobalsWhite(&whiteColor));
1983 }
1984 break ;
e40298d5 1985 }
7d9d1fd7
SC
1986 }
1987 }
1dcbbdcf 1988}
e40298d5 1989
519cb848
SC
1990void wxDC::MacInstallBrush() const
1991{
3dec57ad 1992 wxCHECK_RET(Ok(), wxT("Invalid DC"));
e40298d5
JS
1993 Pattern blackColor ;
1994 // if ( m_macBrushInstalled )
1995 // return ;
1996 // foreground
1997 bool backgroundTransparent = (GetBackgroundMode() == wxTRANSPARENT) ;
1998 ::RGBForeColor( &MAC_WXCOLORREF( m_brush.GetColour().GetPixel()) );
1999 ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()) );
2000 int brushStyle = m_brush.GetStyle();
2001 if (brushStyle == wxSOLID)
2002 {
2003 ::PenPat(GetQDGlobalsBlack(&blackColor));
2004 }
2005 else if (IS_HATCH(brushStyle))
2006 {
2007 Pattern pat ;
411bdf74 2008 wxMacGetPattern(brushStyle, &pat);
e40298d5
JS
2009 ::PenPat(&pat);
2010 }
2011 else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
2012 {
2013 // we force this in order to be compliant with wxMSW
2014 backgroundTransparent = false ;
2015 // for these the text fore (and back for MASK_OPAQUE) colors are used
2016 wxBitmap* bitmap = m_brush.GetStipple() ;
2017 int width = bitmap->GetWidth() ;
2018 int height = bitmap->GetHeight() ;
76a5e5d2 2019 GWorldPtr gw = NULL ;
e40298d5
JS
2020 if ( m_brush.GetStyle() == wxSTIPPLE )
2021 gw = MAC_WXHBITMAP(bitmap->GetHBITMAP()) ;
2022 else
2023 gw = MAC_WXHBITMAP(bitmap->GetMask()->GetMaskBitmap()) ;
76a5e5d2
SC
2024 PixMapHandle gwpixmaphandle = GetGWorldPixMap( gw ) ;
2025 LockPixels( gwpixmaphandle ) ;
e40298d5 2026 bool isMonochrome = !IsPortColor( gw ) ;
76a5e5d2
SC
2027 if ( !isMonochrome )
2028 {
2029 if ( (**gwpixmaphandle).pixelSize == 1 )
2030 isMonochrome = true ;
2031 }
66a09d47 2032 if ( isMonochrome && width == 8 && height == 8 )
e40298d5
JS
2033 {
2034 ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) );
2035 ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) );
76a5e5d2
SC
2036 BitMap* gwbitmap = (BitMap*) *gwpixmaphandle ; // since the color depth is 1 it is a BitMap
2037 UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ;
2038 int alignment = gwbitmap->rowBytes & 0x7FFF ;
66a09d47
SC
2039 Pattern pat ;
2040 for ( int i = 0 ; i < 8 ; ++i )
2041 {
2042 pat.pat[i] = gwbits[i*alignment+0] ;
2043 }
2044 UnlockPixels( GetGWorldPixMap( gw ) ) ;
2045 ::PenPat( &pat ) ;
e40298d5
JS
2046 }
2047 else
2048 {
2049 // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
2050 // caching scheme before putting this into production
2051 Handle image;
2052 long imageSize;
2053 PixPatHandle pixpat = NewPixPat() ;
2054 CopyPixMap(gwpixmaphandle, (**pixpat).patMap);
66a09d47 2055 imageSize = GetPixRowBytes((**pixpat).patMap) *
e40298d5
JS
2056 ((**(**pixpat).patMap).bounds.bottom -
2057 (**(**pixpat).patMap).bounds.top);
66a09d47
SC
2058 PtrToHand( (**gwpixmaphandle).baseAddr, &image, imageSize );
2059 (**pixpat).patData = image;
2060 if ( isMonochrome )
2061 {
e40298d5
JS
2062 CTabHandle ctable = ((**((**pixpat).patMap)).pmTable) ;
2063 ColorSpecPtr ctspec = (ColorSpecPtr) &(**ctable).ctTable ;
2064 if ( ctspec[0].rgb.red == 0x0000 )
2065 {
2066 ctspec[1].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
2067 ctspec[0].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
2068 }
2069 else
2070 {
2071 ctspec[0].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
2072 ctspec[1].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
2073 }
2074 ::CTabChanged( ctable ) ;
66a09d47
SC
2075 }
2076 ::PenPixPat(pixpat);
2077 m_macForegroundPixMap = pixpat ;
e40298d5
JS
2078 }
2079 UnlockPixels( gwpixmaphandle ) ;
2080 }
1ff301c4
SC
2081 else
2082 {
e40298d5
JS
2083 ::PenPat(GetQDGlobalsBlack(&blackColor));
2084 }
2085 short mode = patCopy ;
2086 switch( m_logicalFunction )
2087 {
2088 case wxCOPY: // src
2089 if ( backgroundTransparent )
2090 mode = patOr ;
2091 else
2092 mode = patCopy ;
2093 break ;
2094 case wxINVERT: // NOT dst
2095 if ( !backgroundTransparent )
2096 {
2097 ::PenPat(GetQDGlobalsBlack(&blackColor));
2098 }
2099 mode = patXor ;
2100 break ;
2101 case wxXOR: // src XOR dst
2102 mode = patXor ;
2103 break ;
2104 case wxOR_REVERSE: // src OR (NOT dst)
2105 mode = notPatOr ;
2106 break ;
2107 case wxSRC_INVERT: // (NOT src)
2108 mode = notPatCopy ;
2109 break ;
4a95c885
SC
2110 case wxAND: // src AND dst
2111 mode = adMin ;
2112 break ;
e40298d5
JS
2113 // unsupported TODO
2114 case wxCLEAR: // 0
2115 case wxAND_REVERSE:// src AND (NOT dst)
e40298d5
JS
2116 case wxAND_INVERT: // (NOT src) AND dst
2117 case wxNO_OP: // dst
2118 case wxNOR: // (NOT src) AND (NOT dst)
2119 case wxEQUIV: // (NOT src) XOR dst
2120 case wxOR_INVERT: // (NOT src) OR dst
2121 case wxNAND: // (NOT src) OR (NOT dst)
2122 case wxOR: // src OR dst
2123 case wxSET: // 1
2124 // case wxSRC_OR: // source _bitmap_ OR destination
2125 // case wxSRC_AND: // source _bitmap_ AND destination
2126 break ;
2127 }
2128 ::PenMode( mode ) ;
2129 m_macBrushInstalled = true ;
2130 m_macPenInstalled = false ;
2131 m_macFontInstalled = false ;
519cb848 2132}
e40298d5 2133
2f1ae414
SC
2134// ---------------------------------------------------------------------------
2135// coordinates transformations
2136// ---------------------------------------------------------------------------
519cb848 2137
2f1ae414
SC
2138wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
2139{
2140 return ((wxDC *)this)->XDEV2LOG(x);
2141}
e40298d5 2142
2f1ae414
SC
2143wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
2144{
2145 return ((wxDC *)this)->YDEV2LOG(y);
2146}
e40298d5 2147
2f1ae414
SC
2148wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
2149{
2150 return ((wxDC *)this)->XDEV2LOGREL(x);
2151}
e40298d5 2152
2f1ae414
SC
2153wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
2154{
2155 return ((wxDC *)this)->YDEV2LOGREL(y);
2156}
e40298d5 2157
2f1ae414
SC
2158wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
2159{
2160 return ((wxDC *)this)->XLOG2DEV(x);
2161}
e40298d5 2162
2f1ae414
SC
2163wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
2164{
2165 return ((wxDC *)this)->YLOG2DEV(y);
2166}
e40298d5 2167
2f1ae414
SC
2168wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
2169{
2170 return ((wxDC *)this)->XLOG2DEVREL(x);
2171}
e40298d5 2172
2f1ae414
SC
2173wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
2174{
2175 return ((wxDC *)this)->YLOG2DEVREL(y);
a7390348 2176}