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