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