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