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