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