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