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