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