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