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