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