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