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