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