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