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