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