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