]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/dc.cpp
added a preImage of the selection in order to avoid unnecessary events being triggered
[wxWidgets.git] / src / mac / carbon / dc.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.cpp
3// Purpose: wxDC class
4// Author: AUTHOR
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "dc.h"
14#endif
15
16#include "wx/dc.h"
17#include "wx/app.h"
18#include "wx/mac/uma.h"
19#include "wx/dcmemory.h"
20#include "wx/region.h"
21#include "wx/image.h"
22
23#if __MSL__ >= 0x6000
24#include "math.h"
25#endif
26
27#if !USE_SHARED_LIBRARY
28IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
29#endif
30
31//-----------------------------------------------------------------------------
32// constants
33//-----------------------------------------------------------------------------
34
35#define mm2inches 0.0393700787402
36#define inches2mm 25.4
37#define mm2twips 56.6929133859
38#define twips2mm 0.0176388888889
39#define mm2pt 2.83464566929
40#define pt2mm 0.352777777778
41#ifndef __DARWIN__
42const double M_PI = 3.14159265358979 ;
43#endif
44const double RAD2DEG = 180.0 / M_PI;
45
46//-----------------------------------------------------------------------------
47// Local functions
48//-----------------------------------------------------------------------------
49
50static inline double dmin(double a, double b) { return a < b ? a : b; }
51static inline double dmax(double a, double b) { return a > b ? a : b; }
52static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
53
54//-----------------------------------------------------------------------------
55// wxDC
56//-----------------------------------------------------------------------------
57
58wxDC::wxDC()
59{
60 m_ok = FALSE;
61 m_colour = TRUE;
62
63 m_mm_to_pix_x = mm2pt;
64 m_mm_to_pix_y = mm2pt;
65
66 m_internalDeviceOriginX = 0;
67 m_internalDeviceOriginY = 0;
68 m_externalDeviceOriginX = 0;
69 m_externalDeviceOriginY = 0;
70
71 m_logicalScaleX = 1.0;
72 m_logicalScaleY = 1.0;
73 m_userScaleX = 1.0;
74 m_userScaleY = 1.0;
75 m_scaleX = 1.0;
76 m_scaleY = 1.0;
77
78 m_needComputeScaleX = FALSE;
79 m_needComputeScaleY = FALSE;
80
81 m_maxX = m_maxY = -100000;
82 m_minY = m_minY = 100000;
83
84 m_macPort = NULL ;
85 m_macMask = NULL ;
86 m_ok = FALSE ;
87
88 m_macFontInstalled = false ;
89 m_macBrushInstalled = false ;
90 m_macPenInstalled = false ;
91
92 m_macLocalOrigin.h = m_macLocalOrigin.v = 0 ;
93 m_macClipRect.left = -32000 ;
94 m_macClipRect.top = -32000 ;
95 m_macClipRect.right = 32000 ;
96 m_macClipRect.bottom = 32000 ;
97
98 m_pen = *wxBLACK_PEN;
99 m_font = *wxNORMAL_FONT;
100 m_brush = *wxWHITE_BRUSH;
101}
102wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) :
103 m_ph( dc->m_macPort )
104{
105 wxASSERT( dc->Ok() ) ;
106
107 dc->MacSetupPort(&m_ph) ;
108}
109
110wxMacPortSetter::~wxMacPortSetter()
111{
112}
113
114wxDC::~wxDC(void)
115{
116}
117void wxDC::MacSetupPort(AGAPortHelper* help) const
118{
119// help->Setup( m_macPort ) ;
120 ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v);
121
122 if ( m_clipping )
123 {
124 Rect clip = { m_clipY1 , m_clipX1 , m_clipY2 , m_clipX2 } ;
125 ::SectRect( &clip , &m_macClipRect , &clip ) ;
126 ::ClipRect( &clip ) ;
127 }
128 else
129 {
130 ::ClipRect(&m_macClipRect);
131 }
132
133
134 m_macFontInstalled = false ;
135 m_macBrushInstalled = false ;
136 m_macPenInstalled = false ;
137}
138
139void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
140{
141 wxCHECK_RET( Ok(), wxT("invalid window dc") );
142
143 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
144
145 wxMacPortSetter helper(this) ;
146
147 wxCoord xx = XLOG2DEV(x);
148 wxCoord yy = YLOG2DEV(y);
149 wxCoord w = bmp.GetWidth();
150 wxCoord h = bmp.GetHeight();
151 wxCoord ww = XLOG2DEVREL(w);
152 wxCoord hh = YLOG2DEVREL(h);
153
154 // Set up drawing mode
155 short mode = (m_logicalFunction == wxCOPY ? srcCopy :
156 //m_logicalFunction == wxCLEAR ? WHITENESS :
157 //m_logicalFunction == wxSET ? BLACKNESS :
158 m_logicalFunction == wxINVERT ? hilite :
159 //m_logicalFunction == wxAND ? MERGECOPY :
160 m_logicalFunction == wxOR ? srcOr :
161 m_logicalFunction == wxSRC_INVERT ? notSrcCopy :
162 m_logicalFunction == wxXOR ? srcXor :
163 m_logicalFunction == wxOR_REVERSE ? notSrcOr :
164 //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
165 //m_logicalFunction == wxSRC_OR ? srcOr :
166 //m_logicalFunction == wxSRC_AND ? SRCAND :
167 srcCopy );
168
169 if ( bmp.GetBitmapType() == kMacBitmapTypePict ) {
170 Rect bitmaprect = { 0 , 0 , hh, ww };
171 ::OffsetRect( &bitmaprect, xx, yy ) ;
172 ::DrawPicture( bmp.GetPict(), &bitmaprect ) ;
173 }
174 else if ( bmp.GetBitmapType() == kMacBitmapTypeGrafWorld )
175 {
176 GWorldPtr bmapworld = bmp.GetHBITMAP();
177 PixMapHandle bmappixels ;
178
179 // Set foreground and background colours (for bitmaps depth = 1)
180 if(bmp.GetDepth() == 1)
181 {
182 RGBColor fore = m_textForegroundColour.GetPixel();
183 RGBColor back = m_textBackgroundColour.GetPixel();
184 RGBForeColor(&fore);
185 RGBBackColor(&back);
186 }
187 else
188 {
189 RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ;
190 RGBColor black = { 0,0,0} ;
191 RGBForeColor( &black ) ;
192 RGBBackColor( &white ) ;
193 }
194
195 bmappixels = GetGWorldPixMap( bmapworld ) ;
196
197 wxCHECK_RET(LockPixels(bmappixels),
198 wxT("DoDrawBitmap: Unable to lock pixels"));
199
200 Rect source = { 0, 0, h, w };
201 Rect dest = { yy, xx, yy + hh, xx + ww };
202
203 if ( useMask && bmp.GetMask() )
204 {
205 if( LockPixels(GetGWorldPixMap(bmp.GetMask()->GetMaskBitmap())))
206 {
207 CopyDeepMask
208 (
209 GetPortBitMapForCopyBits(bmapworld),
210 GetPortBitMapForCopyBits(bmp.GetMask()->GetMaskBitmap()),
211 GetPortBitMapForCopyBits( m_macPort ),
212 &source, &source, &dest, mode, NULL
213 );
214 UnlockPixels(GetGWorldPixMap(bmp.GetMask()->GetMaskBitmap()));
215 }
216 }
217 else {
218 CopyBits( GetPortBitMapForCopyBits( bmapworld ),
219 GetPortBitMapForCopyBits( m_macPort ),
220 &source, &dest, mode, NULL ) ;
221 }
222 UnlockPixels( bmappixels ) ;
223 }
224 else if ( bmp.GetBitmapType() == kMacBitmapTypeIcon )
225 {
226 Rect bitmaprect = { 0 , 0 , bmp.GetHeight(), bmp.GetWidth() } ;
227 OffsetRect( &bitmaprect, xx, yy ) ;
228 PlotCIconHandle( &bitmaprect , atNone , ttNone , bmp.GetHICON() ) ;
229 }
230 m_macPenInstalled = false ;
231 m_macBrushInstalled = false ;
232 m_macFontInstalled = false ;
233
234}
235
236void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
237{
238 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
239
240 wxCHECK_RET(icon.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
241
242 DoDrawBitmap( icon , x , y , icon.GetMask() != NULL ) ;
243}
244void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
245{
246 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
247 wxCoord xx, yy, ww, hh;
248
249 xx = XLOG2DEV(x);
250 yy = YLOG2DEV(y);
251 ww = XLOG2DEVREL(width);
252 hh = YLOG2DEVREL(height);
253
254 if( m_clipping )
255 {
256 m_clipX1 = wxMax( m_clipX1 , xx );
257 m_clipY1 = wxMax( m_clipY1 , yy );
258 m_clipX2 = wxMin( m_clipX2, (xx + ww));
259 m_clipY2 = wxMin( m_clipY2, (yy + hh));
260 }
261 else
262 {
263 m_clipping = TRUE;
264 m_clipX1 = xx;
265 m_clipY1 = yy;
266 m_clipX2 = xx + ww;
267 m_clipY2 = yy + hh;
268 }
269
270}
271void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region )
272{
273 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
274
275 wxMacPortSetter helper(this) ;
276 if (region.Empty())
277 {
278 DestroyClippingRegion();
279 return;
280 }
281
282 wxCoord xx, yy, ww, hh;
283 region.GetBox( xx, yy, ww, hh );
284 wxDC::DoSetClippingRegion( xx, yy, ww, hh );
285}
286
287void wxDC::DestroyClippingRegion()
288{
289 wxMacPortSetter helper(this) ;
290 m_clipping = FALSE;
291}
292void wxDC::DoGetSize( int* width, int* height ) const
293{
294 *width = m_maxX-m_minX;
295 *height = m_maxY-m_minY;
296}
297void wxDC::DoGetSizeMM( int* width, int* height ) const
298{
299 int w = 0;
300 int h = 0;
301 GetSize( &w, &h );
302 *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) );
303 *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) );
304}
305void wxDC::SetTextForeground( const wxColour &col )
306{
307 wxCHECK_RET(Ok(), wxT("Invalid DC"));
308 m_textForegroundColour = col;
309 m_macFontInstalled = false ;
310}
311void wxDC::SetTextBackground( const wxColour &col )
312{
313 wxCHECK_RET(Ok(), wxT("Invalid DC"));
314 m_textBackgroundColour = col;
315 m_macFontInstalled = false ;
316}
317void wxDC::SetMapMode( int mode )
318{
319 switch (mode)
320 {
321 case wxMM_TWIPS:
322 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
323 break;
324 case wxMM_POINTS:
325 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
326 break;
327 case wxMM_METRIC:
328 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
329 break;
330 case wxMM_LOMETRIC:
331 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
332 break;
333 default:
334 case wxMM_TEXT:
335 SetLogicalScale( 1.0, 1.0 );
336 break;
337 }
338 if (mode != wxMM_TEXT)
339 {
340 m_needComputeScaleX = TRUE;
341 m_needComputeScaleY = TRUE;
342 }
343}
344void wxDC::SetUserScale( double x, double y )
345{
346 // allow negative ? -> no
347 m_userScaleX = x;
348 m_userScaleY = y;
349 ComputeScaleAndOrigin();
350}
351void wxDC::SetLogicalScale( double x, double y )
352{
353 // allow negative ?
354 m_logicalScaleX = x;
355 m_logicalScaleY = y;
356 ComputeScaleAndOrigin();
357}
358void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
359{
360 m_logicalOriginX = x * m_signX; // is this still correct ?
361 m_logicalOriginY = y * m_signY;
362 ComputeScaleAndOrigin();
363}
364void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
365{
366 m_externalDeviceOriginX = x;
367 m_externalDeviceOriginY = y;
368 ComputeScaleAndOrigin();
369}
370
371#if 0
372void wxDC::SetInternalDeviceOrigin( long x, long y )
373{
374 m_internalDeviceOriginX = x;
375 m_internalDeviceOriginY = y;
376 ComputeScaleAndOrigin();
377}
378void wxDC::GetInternalDeviceOrigin( long *x, long *y )
379{
380 if (x) *x = m_internalDeviceOriginX;
381 if (y) *y = m_internalDeviceOriginY;
382}
383#endif
384void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
385{
386 m_signX = (xLeftRight ? 1 : -1);
387 m_signY = (yBottomUp ? -1 : 1);
388 ComputeScaleAndOrigin();
389}/*
390
391void wxDC::CalcBoundingBox( long x, long y )
392{
393 if (x < m_minX) m_minX = x;
394 if (y < m_minY) m_minY = y;
395 if (x > m_maxX) m_maxX = x;
396 if (y > m_maxY) m_maxY = y;
397}*/
398wxSize wxDC::GetPPI() const
399{
400 return wxSize(72, 72);
401}
402
403int wxDC::GetDepth() const
404{
405 return wxDisplayDepth() ;
406}
407
408void wxDC::ComputeScaleAndOrigin()
409{
410 // CMB: copy scale to see if it changes
411 double origScaleX = m_scaleX;
412 double origScaleY = m_scaleY;
413
414 m_scaleX = m_logicalScaleX * m_userScaleX;
415 m_scaleY = m_logicalScaleY * m_userScaleY;
416
417 m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX;
418 m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY;
419
420 // CMB: if scale has changed call SetPen to recalulate the line width
421 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
422 {
423 // this is a bit artificial, but we need to force wxDC to think
424 // the pen has changed
425 wxPen* pen = & GetPen();
426 wxPen tempPen;
427 m_pen = tempPen;
428 SetPen(* pen);
429 }
430}
431void wxDC::SetPalette( const wxPalette& palette )
432{
433}
434
435void wxDC::SetBackgroundMode( int mode )
436{
437 m_backgroundMode = mode ;
438}
439
440void wxDC::SetFont( const wxFont &font )
441{
442 wxCHECK_RET(Ok(), wxT("Invalid DC"));
443
444 m_font = font;
445 m_macFontInstalled = false ;
446}
447
448void wxDC::SetPen( const wxPen &pen )
449{
450 wxCHECK_RET(Ok(), wxT("Invalid DC"));
451
452 if ( m_pen == pen )
453 return ;
454
455 m_pen = pen;
456
457 m_macPenInstalled = false ;
458}
459
460void wxDC::SetBrush( const wxBrush &brush )
461{
462 wxCHECK_RET(Ok(), wxT("Invalid DC"));
463
464 if (m_brush == brush)
465 return;
466
467 m_brush = brush;
468 m_macBrushInstalled = false ;
469}
470
471void wxDC::SetBackground( const wxBrush &brush )
472{
473 wxCHECK_RET(Ok(), wxT("Invalid DC"));
474
475 if (m_backgroundBrush == brush)
476 return;
477
478 m_backgroundBrush = brush;
479
480 if (!m_backgroundBrush.Ok())
481 return;
482 m_macBrushInstalled = false ;
483}
484
485void wxDC::SetLogicalFunction( int function )
486{
487 if (m_logicalFunction == function)
488 return;
489
490 m_logicalFunction = function ;
491 m_macFontInstalled = false ;
492 m_macBrushInstalled = false ;
493 m_macPenInstalled = false ;
494}
495
496void wxDC::DoFloodFill( wxCoord x, wxCoord y, const wxColour& col,
497 int style )
498{
499}
500
501bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const
502{
503 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
504 wxMacPortSetter helper(this) ;
505
506 RGBColor colour;
507
508 GetCPixel( XLOG2DEV(x), YLOG2DEV(y), &colour );
509
510 // Convert from Mac colour to wx
511 col->Set( colour.red >> 8,
512 colour.green >> 8,
513 colour.blue >> 8);
514
515 return true ;
516}
517
518void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
519{
520 wxCHECK_RET(Ok(), wxT("Invalid DC"));
521
522 wxMacPortSetter helper(this) ;
523
524 if (m_pen.GetStyle() != wxTRANSPARENT)
525 {
526 MacInstallPen() ;
527 wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 :
528 m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2;
529
530 wxCoord xx1 = XLOG2DEV(x1) - offset;
531 wxCoord yy1 = YLOG2DEV(y1) - offset;
532 wxCoord xx2 = XLOG2DEV(x2) - offset;
533 wxCoord yy2 = YLOG2DEV(y2) - offset;
534
535 if ((m_pen.GetCap() == wxCAP_ROUND) &&
536 (m_pen.GetWidth() <= 1))
537 {
538 // Implement LAST_NOT for MAC at least for
539 // orthogonal lines. RR.
540 if (xx1 == xx2)
541 {
542 if (yy1 < yy2)
543 yy2--;
544 if (yy1 > yy2)
545 yy2++;
546 }
547 if (yy1 == yy2)
548 {
549 if (xx1 < xx2)
550 xx2--;
551 if (xx1 > xx2)
552 xx2++;
553 }
554 }
555
556 ::MoveTo(xx1, yy1);
557 ::LineTo(xx2, yy2);
558 }
559}
560
561void wxDC::DoCrossHair( wxCoord x, wxCoord y )
562{
563 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
564
565 if (m_pen.GetStyle() != wxTRANSPARENT)
566 {
567 int w = 0;
568 int h = 0;
569 GetSize( &w, &h );
570 wxCoord xx = XLOG2DEV(x);
571 wxCoord yy = YLOG2DEV(y);
572
573 MacInstallPen();
574 ::MoveTo( 0, yy );
575 ::LineTo( XLOG2DEVREL(w), yy );
576 ::MoveTo( xx, 0 );
577 ::LineTo( xx, YLOG2DEVREL(h) );
578 }
579}
580
581/*
582 * To draw arcs properly the angles need to be converted from the WX style:
583 * Angles start on the +ve X axis and go anti-clockwise (As you would draw on
584 * a normal axis on paper).
585 * TO
586 * the Mac style:
587 * Angles start on the +ve y axis and go clockwise.
588 * To achive this I work out which quadrant the angle lies in then map this to
589 * the equivalent quadrant on the Mac. (Sin and Cos values reveal which
590 * quadrant you are in).
591 */
592static double wxConvertWXangleToMACangle(double angle)
593{
594 double sin_a, cos_a;
595
596 sin_a = sin(angle / RAD2DEG);
597 cos_a = cos(angle / RAD2DEG);
598
599 if( (sin_a >= 0.0) && (cos_a >= 0.0) ) {
600 angle = acos(sin_a) * RAD2DEG;
601 }
602 else if( (sin_a >= 0.0) && (cos_a <= 0.0) ) {
603 sin_a *= -1;
604 angle = acos(sin_a) * RAD2DEG + 180;
605 }
606 else if( (sin_a <= 0.0) && (cos_a >= 0.0) ) {
607 angle = acos(sin_a) * RAD2DEG + 180;
608 }
609 else if( (sin_a < 0.0) && (cos_a < 0.0) ) {
610 sin_a *= -1;
611 angle = acos(sin_a) * RAD2DEG + 180;
612 }
613 return angle;
614}
615
616void wxDC::DoDrawArc( wxCoord x1, wxCoord y1,
617 wxCoord x2, wxCoord y2,
618 wxCoord xc, wxCoord yc )
619{
620 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
621
622 wxCoord xx1 = XLOG2DEV(x1);
623 wxCoord yy1 = YLOG2DEV(y1);
624 wxCoord xx2 = XLOG2DEV(x2);
625 wxCoord yy2 = YLOG2DEV(y2);
626 wxCoord xxc = XLOG2DEV(xc);
627 wxCoord yyc = YLOG2DEV(yc);
628 double dx = xx1 - xxc;
629 double dy = yy1 - yyc;
630 double radius = sqrt((double)(dx*dx+dy*dy));
631 wxCoord rad = (wxCoord)radius;
632 double radius1, radius2;
633
634 if (xx1 == xx2 && yy1 == yy2)
635 {
636 radius1 = 0.0;
637 radius2 = 360.0;
638 }
639 else if (radius == 0.0)
640 {
641 radius1 = radius2 = 0.0;
642 }
643 else
644 {
645 radius1 = (xx1 - xxc == 0) ?
646 (yy1 - yyc < 0) ? 90.0 : -90.0 :
647 -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
648 radius2 = (xx2 - xxc == 0) ?
649 (yy2 - yyc < 0) ? 90.0 : -90.0 :
650 -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
651 }
652 wxCoord alpha2 = wxCoord(radius2 - radius1);
653 wxCoord alpha1 = wxCoord(wxConvertWXangleToMACangle(radius1));
654 if( (xx1 > xx2) || (yy1 > yy2) ) {
655 alpha2 *= -1;
656 }
657
658 Rect r = { yyc - rad, xxc - rad, yyc + rad, xxc + rad };
659
660 if(m_brush.GetStyle() != wxTRANSPARENT) {
661 MacInstallBrush();
662 PaintArc(&r, alpha1, alpha2);
663 }
664 if(m_pen.GetStyle() != wxTRANSPARENT) {
665 MacInstallPen();
666 FrameArc(&r, alpha1, alpha2);
667 }
668}
669
670void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
671 double sa, double ea )
672{
673 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
674
675 Rect r;
676 double angle = sa - ea; // Order important Mac in opposite direction to wx
677
678 wxCoord xx = XLOG2DEV(x);
679 wxCoord yy = YLOG2DEV(y);
680 wxCoord ww = m_signX * XLOG2DEVREL(w);
681 wxCoord hh = m_signY * YLOG2DEVREL(h);
682
683 // handle -ve width and/or height
684 if (ww < 0) { ww = -ww; xx = xx - ww; }
685 if (hh < 0) { hh = -hh; yy = yy - hh; }
686
687 sa = wxConvertWXangleToMACangle(sa);
688
689 r.top = yy;
690 r.left = xx;
691 r.bottom = yy + hh;
692 r.right = xx + ww;
693
694 if(m_brush.GetStyle() != wxTRANSPARENT) {
695 MacInstallBrush();
696 PaintArc(&r, (short)sa, (short)angle);
697 }
698 if(m_pen.GetStyle() != wxTRANSPARENT) {
699 MacInstallPen();
700 FrameArc(&r, (short)sa, (short)angle);
701 }
702}
703
704void wxDC::DoDrawPoint( wxCoord x, wxCoord y )
705{
706 wxCHECK_RET(Ok(), wxT("Invalid DC"));
707
708 wxMacPortSetter helper(this) ;
709
710 if (m_pen.GetStyle() != wxTRANSPARENT)
711 {
712 MacInstallPen() ;
713 wxCoord xx1 = XLOG2DEV(x);
714 wxCoord yy1 = YLOG2DEV(y);
715
716 ::MoveTo(xx1,yy1);
717 ::LineTo(xx1+1, yy1+1);
718 }
719}
720
721void wxDC::DoDrawLines(int n, wxPoint points[],
722 wxCoord xoffset, wxCoord yoffset)
723{
724 wxCHECK_RET(Ok(), wxT("Invalid DC"));
725 wxMacPortSetter helper(this) ;
726
727 if (m_pen.GetStyle() == wxTRANSPARENT)
728 return;
729
730 MacInstallPen() ;
731
732 wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 :
733 m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2 ;
734
735 wxCoord x1, x2 , y1 , y2 ;
736 x1 = XLOG2DEV(points[0].x + xoffset);
737 y1 = YLOG2DEV(points[0].y + yoffset);
738 ::MoveTo(x1 - offset, y1 - offset );
739
740 for (int i = 0; i < n-1; i++)
741 {
742 x2 = XLOG2DEV(points[i+1].x + xoffset);
743 y2 = YLOG2DEV(points[i+1].y + yoffset);
744 ::LineTo( x2 - offset, y2 - offset );
745 }
746}
747
748void wxDC::DoDrawPolygon(int n, wxPoint points[],
749 wxCoord xoffset, wxCoord yoffset,
750 int fillStyle )
751{
752 wxCHECK_RET(Ok(), wxT("Invalid DC"));
753 wxMacPortSetter helper(this) ;
754
755 wxCoord x1, x2 , y1 , y2 ;
756
757 if (m_brush.GetStyle() != wxTRANSPARENT)
758 {
759 PolyHandle polygon = OpenPoly();
760
761 x1 = XLOG2DEV(points[0].x + xoffset);
762 y1 = YLOG2DEV(points[0].y + yoffset);
763 ::MoveTo(x1,y1);
764
765 for (int i = 0; i < n-1; i++)
766 {
767 x2 = XLOG2DEV(points[i+1].x + xoffset);
768 y2 = YLOG2DEV(points[i+1].y + yoffset);
769 ::LineTo(x2, y2);
770 }
771
772 ClosePoly();
773
774 MacInstallBrush();
775 ::PaintPoly( polygon );
776
777 KillPoly( polygon );
778 }
779
780 if (m_pen.GetStyle() != wxTRANSPARENT)
781 {
782 PolyHandle polygon = OpenPoly();
783
784 x1 = XLOG2DEV(points[0].x + xoffset);
785 y1 = YLOG2DEV(points[0].y + yoffset);
786 ::MoveTo(x1,y1);
787
788 for (int i = 0; i < n-1; i++)
789 {
790 x2 = XLOG2DEV(points[i+1].x + xoffset);
791 y2 = YLOG2DEV(points[i+1].y + yoffset);
792 ::LineTo(x2, y2);
793 }
794
795 // return to origin to close path
796 ::LineTo(x1,y1);
797
798 ClosePoly();
799
800 MacInstallPen() ;
801 ::FramePoly( polygon ) ;
802
803 KillPoly( polygon );
804 }
805}
806
807void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
808{
809 wxCHECK_RET(Ok(), wxT("Invalid DC"));
810 wxMacPortSetter helper(this) ;
811
812 wxCoord xx = XLOG2DEV(x);
813 wxCoord yy = YLOG2DEV(y);
814 wxCoord ww = m_signX * XLOG2DEVREL(width);
815 wxCoord hh = m_signY * YLOG2DEVREL(height);
816
817 // CMB: draw nothing if transformed w or h is 0
818 if (ww == 0 || hh == 0)
819 return;
820
821 // CMB: handle -ve width and/or height
822 if (ww < 0)
823 {
824 ww = -ww;
825 xx = xx - ww;
826 }
827
828 if (hh < 0)
829 {
830 hh = -hh;
831 yy = yy - hh;
832 }
833
834 Rect rect = { yy , xx , yy + hh , xx + ww } ;
835
836 if (m_brush.GetStyle() != wxTRANSPARENT)
837 {
838 MacInstallBrush() ;
839 ::PaintRect( &rect ) ;
840 }
841
842 if (m_pen.GetStyle() != wxTRANSPARENT)
843 {
844 MacInstallPen() ;
845 ::FrameRect( &rect ) ;
846 }
847}
848
849void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
850 wxCoord width, wxCoord height,
851 double radius)
852{
853 wxCHECK_RET(Ok(), wxT("Invalid DC"));
854 wxMacPortSetter helper(this) ;
855
856 if (radius < 0.0)
857 radius = - radius * ((width < height) ? width : height);
858
859 wxCoord xx = XLOG2DEV(x);
860 wxCoord yy = YLOG2DEV(y);
861 wxCoord ww = m_signX * XLOG2DEVREL(width);
862 wxCoord hh = m_signY * YLOG2DEVREL(height);
863
864 // CMB: draw nothing if transformed w or h is 0
865 if (ww == 0 || hh == 0)
866 return;
867
868 // CMB: handle -ve width and/or height
869 if (ww < 0)
870 {
871 ww = -ww;
872 xx = xx - ww;
873 }
874
875 if (hh < 0)
876 {
877 hh = -hh;
878 yy = yy - hh;
879 }
880
881 Rect rect = { yy , xx , yy + hh , xx + ww } ;
882
883 if (m_brush.GetStyle() != wxTRANSPARENT)
884 {
885 MacInstallBrush() ;
886 ::PaintRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ;
887 }
888
889 if (m_pen.GetStyle() != wxTRANSPARENT)
890 {
891 MacInstallPen() ;
892 ::FrameRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ;
893 }
894}
895
896void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
897{
898 wxCHECK_RET(Ok(), wxT("Invalid DC"));
899 wxMacPortSetter helper(this) ;
900
901 wxCoord xx = XLOG2DEV(x);
902 wxCoord yy = YLOG2DEV(y);
903 wxCoord ww = m_signX * XLOG2DEVREL(width);
904 wxCoord hh = m_signY * YLOG2DEVREL(height);
905
906 // CMB: draw nothing if transformed w or h is 0
907 if (ww == 0 || hh == 0)
908 return;
909
910 // CMB: handle -ve width and/or height
911 if (ww < 0)
912 {
913 ww = -ww;
914 xx = xx - ww;
915 }
916
917 if (hh < 0)
918 {
919 hh = -hh;
920 yy = yy - hh;
921 }
922
923 Rect rect = { yy , xx , yy + hh , xx + ww } ;
924
925 if (m_brush.GetStyle() != wxTRANSPARENT)
926 {
927 MacInstallBrush() ;
928 ::PaintOval( &rect ) ;
929 }
930
931 if (m_pen.GetStyle() != wxTRANSPARENT)
932 {
933 MacInstallPen() ;
934 ::FrameOval( &rect ) ;
935 }
936}
937
938
939
940bool wxDC::CanDrawBitmap(void) const
941{
942 return true ;
943}
944
945
946bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
947 wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask,
948 wxCoord xsrcMask, wxCoord ysrcMask )
949{
950 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
951 wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
952 wxMacPortSetter helper(this) ;
953
954 /* TODO: use the mask origin when drawing transparently */
955 if (xsrcMask == -1 && ysrcMask == -1)
956 {
957 xsrcMask = xsrc; ysrcMask = ysrc;
958 }
959
960 CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ;
961 PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ;
962 RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ;
963 RGBColor black = { 0,0,0} ;
964 RGBColor forecolor = m_textForegroundColour.GetPixel();
965 RGBColor backcolor = m_textBackgroundColour.GetPixel();
966 RGBForeColor( &forecolor ) ;
967 RGBBackColor( &backcolor ) ;
968
969 if ( LockPixels(bmappixels) )
970 {
971 Rect srcrect , dstrect ;
972 srcrect.top = source->YLOG2DEV(ysrc) ;
973 srcrect.left = source->XLOG2DEV(xsrc) ;
974 srcrect.right = source->XLOG2DEV(xsrc + width ) ;
975 srcrect.bottom = source->YLOG2DEV(ysrc + height) ;
976 dstrect.top = YLOG2DEV(ydest) ;
977 dstrect.left = XLOG2DEV(xdest) ;
978 dstrect.bottom = YLOG2DEV(ydest + height ) ;
979 dstrect.right = XLOG2DEV(xdest + width ) ;
980
981 short mode = (logical_func == wxCOPY ? srcCopy :
982 // logical_func == wxCLEAR ? WHITENESS :
983 // logical_func == wxSET ? BLACKNESS :
984 logical_func == wxINVERT ? hilite :
985 // logical_func == wxAND ? MERGECOPY :
986 logical_func == wxOR ? srcOr :
987 logical_func == wxSRC_INVERT ? notSrcCopy :
988 logical_func == wxXOR ? srcXor :
989 // logical_func == wxOR_REVERSE ? MERGEPAINT :
990 // logical_func == wxAND_REVERSE ? SRCERASE :
991 // logical_func == wxSRC_OR ? srcOr :
992 // logical_func == wxSRC_AND ? SRCAND :
993 srcCopy );
994
995 if ( useMask && source->m_macMask )
996 {
997 wxASSERT( mode == srcCopy ) ;
998 if ( LockPixels( GetGWorldPixMap( source->m_macMask ) ) )
999 {
1000 CopyMask( GetPortBitMapForCopyBits( sourcePort ) ,
1001 GetPortBitMapForCopyBits( source->m_macMask ) ,
1002 GetPortBitMapForCopyBits( m_macPort ) ,
1003 &srcrect, &srcrect , &dstrect ) ;
1004 UnlockPixels( GetGWorldPixMap( source->m_macMask ) ) ;
1005 }
1006 }
1007 else
1008 {
1009 CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,
1010 GetPortBitMapForCopyBits( m_macPort ) ,
1011 &srcrect, &dstrect, mode, NULL ) ;
1012 }
1013 UnlockPixels( bmappixels ) ;
1014 }
1015
1016 m_macPenInstalled = false ;
1017 m_macBrushInstalled = false ;
1018 m_macFontInstalled = false ;
1019
1020 return TRUE;
1021}
1022
1023void wxDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
1024 double angle)
1025{
1026 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1027
1028 if (angle == 0.0)
1029 {
1030 DrawText(text, x, y);
1031 return;
1032 }
1033
1034 MacInstallFont();
1035
1036 // the size of the text
1037 wxCoord w, h;
1038 GetTextExtent(text, &w, &h);
1039
1040 // draw the string normally
1041 wxBitmap src(w, h);
1042 wxMemoryDC dc;
1043 dc.SelectObject(src);
1044 dc.SetFont(GetFont());
1045 dc.SetBackground(*wxWHITE_BRUSH);
1046 dc.SetBrush(*wxBLACK_BRUSH);
1047 dc.Clear();
1048 dc.DrawText(text, 0, 0);
1049 dc.SetFont(wxNullFont);
1050 dc.SelectObject(wxNullBitmap);
1051
1052 wxMacPortSetter helper(this) ;
1053
1054 // Calculate the size of the rotated bounding box.
1055 double rad = DegToRad(angle);
1056 double dx = cos(rad);
1057 double dy = sin(rad);
1058
1059 // the rectngle vertices are counted clockwise with the first one being at
1060 // (0, 0) (or, rather, at (x, y))
1061 double x2 = w * dx;
1062 double y2 = -w * dy; // y axis points to the bottom, hence minus
1063 double x4 = h * dy;
1064 double y4 = h * dx;
1065 double x3 = x4 + x2;
1066 double y3 = y4 + y2;
1067
1068 // calc max and min
1069 wxCoord maxX = (wxCoord)(dmax(x2, dmax(x3, x4)) + 0.5);
1070 wxCoord maxY = (wxCoord)(dmax(y2, dmax(y3, y4)) + 0.5);
1071 wxCoord minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5);
1072 wxCoord minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5);
1073
1074 // prepare to blit-with-rotate the bitmap to the DC
1075 wxImage image(src);
1076
1077 RGBColor colText = m_textForegroundColour.GetPixel();
1078 RGBColor colBack = m_textBackgroundColour.GetPixel();
1079
1080 unsigned char *data = image.GetData();
1081
1082 wxCoord dstX, dstY;
1083 double r, angleOrig;
1084 bool textPixel;
1085
1086 // paint pixel by pixel
1087 for ( wxCoord srcX = 0; srcX < w; srcX++ )
1088 {
1089 for ( wxCoord srcY = 0; srcY < h; srcY++ )
1090 {
1091 // transform source coords to dest coords
1092 r = sqrt( (double)(srcX * srcX + srcY * srcY) );
1093 angleOrig = atan2((double)srcY, (double)srcX) - rad;
1094 dstX = (wxCoord)(r * cos(angleOrig) + 0.5);
1095 dstY = (wxCoord)(r * sin(angleOrig) + 0.5);
1096
1097 // black pixel?
1098 textPixel = data[(srcY*w + srcX)*3] == 0;
1099 if ( textPixel || (m_backgroundMode == wxSOLID) )
1100 {
1101 SetCPixel(XLOG2DEV(x + dstX), YLOG2DEV(y + dstY),
1102 textPixel ? &colText : &colBack);
1103 }
1104 }
1105 }
1106
1107 // it would be better to draw with non underlined font and draw the line
1108 // manually here (it would be more straight...)
1109#if 0
1110 if ( m_font.GetUnderlined() )
1111 {
1112 ::MoveTo(XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent));
1113 ::LineTo(XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent));
1114 }
1115#endif // 0
1116
1117 // update the bounding box
1118 CalcBoundingBox(x + minX, y + minY);
1119 CalcBoundingBox(x + maxX, y + maxY);
1120}
1121void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
1122{
1123 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1124 wxMacPortSetter helper(this) ;
1125
1126 long xx = XLOG2DEV(x);
1127 long yy = YLOG2DEV(y);
1128
1129// if (m_pen.GetStyle() != wxTRANSPARENT)
1130 {
1131 MacInstallFont() ;
1132 /*
1133 Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
1134
1135 ::ClipRect( &clip ) ;
1136 */
1137
1138 FontInfo fi ;
1139 ::GetFontInfo( &fi ) ;
1140
1141 yy += fi.ascent ;
1142 ::MoveTo( xx , yy );
1143 if ( m_backgroundMode == wxTRANSPARENT )
1144 {
1145 ::TextMode( srcOr) ;
1146 }
1147 else
1148 {
1149 ::TextMode( srcCopy ) ;
1150 }
1151
1152 const char *text = NULL ;
1153 int length = 0 ;
1154 wxString macText ;
1155
1156 if ( wxApp::s_macDefaultEncodingIsPC )
1157 {
1158 macText = wxMacMakeMacStringFromPC( strtext ) ;
1159 text = macText ;
1160 length = macText.Length() ;
1161 }
1162 else
1163 {
1164 text = strtext ;
1165 length = strtext.Length() ;
1166 }
1167
1168 int laststop = 0 ;
1169 int i = 0 ;
1170 int line = 0 ;
1171
1172 while( i < length )
1173 {
1174 if( text[i] == 13 || text[i] == 10)
1175 {
1176 ::DrawText( text , laststop , i - laststop ) ;
1177 line++ ;
1178 ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) );
1179 laststop = i+1 ;
1180 }
1181 i++ ;
1182 }
1183
1184 ::DrawText( text , laststop , i - laststop ) ;
1185 ::TextMode( srcOr ) ;
1186 }
1187}
1188
1189bool wxDC::CanGetTextExtent() const
1190{
1191 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1192
1193 return true ;
1194}
1195
1196void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height,
1197 wxCoord *descent, wxCoord *externalLeading ,
1198 wxFont *theFont ) const
1199{
1200 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1201 wxMacPortSetter helper(this) ;
1202
1203 wxFont formerFont = m_font ;
1204
1205 if ( theFont )
1206 {
1207 wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
1208
1209 if ( font )
1210 {
1211 ::TextFont( font->m_macFontNum ) ;
1212 ::TextSize( YLOG2DEVREL( font->m_macFontSize) ) ;
1213 ::TextFace( font->m_macFontStyle ) ;
1214 }
1215 }
1216 else
1217 {
1218 MacInstallFont() ;
1219 }
1220
1221 FontInfo fi ;
1222 ::GetFontInfo( &fi ) ;
1223
1224 if ( height )
1225 *height = YDEV2LOGREL( fi.descent + fi.ascent ) ;
1226 if ( descent )
1227 *descent =YDEV2LOGREL( fi.descent );
1228 if ( externalLeading )
1229 *externalLeading = YDEV2LOGREL( fi.leading ) ;
1230
1231 const char *text = NULL ;
1232 int length = 0 ;
1233 wxString macText ;
1234 if ( wxApp::s_macDefaultEncodingIsPC )
1235 {
1236 macText = wxMacMakeMacStringFromPC( string ) ;
1237 text = macText ;
1238 length = macText.Length() ;
1239 }
1240 else
1241 {
1242 text = string ;
1243 length = string.Length() ;
1244 }
1245
1246 int laststop = 0 ;
1247 int i = 0 ;
1248 int curwidth = 0 ;
1249 if ( width )
1250 {
1251 *width = 0 ;
1252
1253 while( i < length )
1254 {
1255 if( text[i] == 13 || text[i] == 10)
1256 {
1257 if ( height )
1258 *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ;
1259 curwidth = ::TextWidth( text , laststop , i - laststop ) ;
1260 if ( curwidth > *width )
1261 *width = XDEV2LOGREL( curwidth ) ;
1262 laststop = i+1 ;
1263 }
1264 i++ ;
1265 }
1266
1267 curwidth = ::TextWidth( text , laststop , i - laststop ) ;
1268 if ( curwidth > *width )
1269 *width = XDEV2LOGREL( curwidth ) ;
1270 }
1271
1272 if ( theFont )
1273 {
1274 m_macFontInstalled = false ;
1275 }
1276}
1277
1278wxCoord wxDC::GetCharWidth(void) const
1279{
1280 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1281
1282 wxMacPortSetter helper(this) ;
1283
1284 MacInstallFont() ;
1285
1286 int width = ::TextWidth( "n" , 0 , 1 ) ;
1287
1288 return YDEV2LOGREL(width) ;
1289}
1290
1291wxCoord wxDC::GetCharHeight(void) const
1292{
1293 wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
1294
1295 wxMacPortSetter helper(this) ;
1296
1297 MacInstallFont() ;
1298
1299 FontInfo fi ;
1300 ::GetFontInfo( &fi ) ;
1301
1302 return YDEV2LOGREL( fi.descent + fi.ascent );
1303}
1304
1305void wxDC::Clear(void)
1306{
1307 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1308 wxMacPortSetter helper(this) ;
1309 Rect rect = { -32767 , -32767 , 32767 , 32767 } ;
1310
1311 if (m_backgroundBrush.GetStyle() != wxTRANSPARENT)
1312 {
1313 MacInstallBrush() ;
1314 ::EraseRect( &rect ) ;
1315 }
1316}
1317
1318void wxDC::MacInstallFont() const
1319{
1320 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1321// if ( m_macFontInstalled )
1322// return ;
1323 Pattern blackColor ;
1324
1325 wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
1326
1327 if ( font )
1328 {
1329 ::TextFont( font->m_macFontNum ) ;
1330 ::TextSize( short(m_scaleY * font->m_macFontSize) ) ;
1331 ::TextFace( font->m_macFontStyle ) ;
1332
1333 m_macFontInstalled = true ;
1334 m_macBrushInstalled = false ;
1335 m_macPenInstalled = false ;
1336
1337 RGBColor forecolor = m_textForegroundColour.GetPixel();
1338 RGBColor backcolor = m_textBackgroundColour.GetPixel();
1339 ::RGBForeColor( &forecolor );
1340 ::RGBBackColor( &backcolor );
1341 }
1342 else
1343 {
1344 short fontnum ;
1345
1346 GetFNum( "\pGeneva" , &fontnum ) ;
1347 ::TextFont( fontnum ) ;
1348 ::TextSize( short(m_scaleY * 10) ) ;
1349 ::TextFace( 0 ) ;
1350
1351 // todo reset after spacing changes - or store the current spacing somewhere
1352
1353 m_macFontInstalled = true ;
1354 m_macBrushInstalled = false ;
1355 m_macPenInstalled = false ;
1356
1357 RGBColor forecolor = m_textForegroundColour.GetPixel();
1358 RGBColor backcolor = m_textBackgroundColour.GetPixel();
1359 ::RGBForeColor( &forecolor );
1360 ::RGBBackColor( &backcolor );
1361 }
1362
1363 short mode = patCopy ;
1364
1365 // todo :
1366
1367 switch( m_logicalFunction )
1368 {
1369 case wxCOPY: // src
1370 mode = patCopy ;
1371 break ;
1372 case wxINVERT: // NOT dst
1373 ::PenPat(GetQDGlobalsBlack(&blackColor));
1374 mode = patXor ;
1375 break ;
1376 case wxXOR: // src XOR dst
1377 mode = patXor ;
1378 break ;
1379 case wxOR_REVERSE: // src OR (NOT dst)
1380 mode = notPatOr ;
1381 break ;
1382 case wxSRC_INVERT: // (NOT src)
1383 mode = notPatCopy ;
1384 break ;
1385
1386 // unsupported TODO
1387
1388 case wxCLEAR: // 0
1389 case wxAND_REVERSE:// src AND (NOT dst)
1390 case wxAND: // src AND dst
1391 case wxAND_INVERT: // (NOT src) AND dst
1392 case wxNO_OP: // dst
1393 case wxNOR: // (NOT src) AND (NOT dst)
1394 case wxEQUIV: // (NOT src) XOR dst
1395 case wxOR_INVERT: // (NOT src) OR dst
1396 case wxNAND: // (NOT src) OR (NOT dst)
1397 case wxOR: // src OR dst
1398 case wxSET: // 1
1399// case wxSRC_OR: // source _bitmap_ OR destination
1400// case wxSRC_AND: // source _bitmap_ AND destination
1401 break ;
1402 }
1403 ::PenMode( mode ) ;
1404}
1405
1406static void wxMacGetHatchPattern(int hatchStyle, Pattern *pattern)
1407{
1408 int thePatListID = sysPatListID;
1409 int theIndex;
1410 switch(hatchStyle)
1411 {
1412 case wxBDIAGONAL_HATCH:
1413 theIndex = 34; // WCH: this is not good
1414 break;
1415 case wxFDIAGONAL_HATCH:
1416 theIndex = 26;
1417 break;
1418 case wxCROSS_HATCH:
1419 theIndex = 5;
1420 break;
1421 case wxHORIZONTAL_HATCH:
1422 theIndex = 25;
1423 break;
1424 case wxVERTICAL_HATCH:
1425 theIndex = 6;
1426 break;
1427 case wxCROSSDIAG_HATCH:
1428 theIndex = 4; // WCH: this is not good
1429 break;
1430 default:
1431 theIndex = 1; // solid pattern
1432 break;
1433 }
1434 GetIndPattern( pattern, thePatListID, theIndex);
1435}
1436
1437void wxDC::MacInstallPen() const
1438{
1439 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1440
1441 Pattern blackColor;
1442
1443// if ( m_macPenInstalled )
1444// return ;
1445
1446 RGBColor forecolor = m_pen.GetColour().GetPixel();
1447 RGBColor backcolor = m_backgroundBrush.GetColour().GetPixel();
1448 ::RGBForeColor( &forecolor );
1449 ::RGBBackColor( &backcolor );
1450
1451 ::PenNormal() ;
1452 int penWidth = m_pen.GetWidth() * (int) m_scaleX ;
1453
1454 // null means only one pixel, at whatever resolution
1455 if ( penWidth == 0 )
1456 penWidth = 1 ;
1457 ::PenSize(penWidth, penWidth);
1458
1459 int penStyle = m_pen.GetStyle();
1460
1461 if (penStyle == wxSOLID)
1462 {
1463 ::PenPat(GetQDGlobalsBlack(&blackColor));
1464 }
1465 else if (IS_HATCH(penStyle))
1466 {
1467 Pattern pat ;
1468 wxMacGetHatchPattern(penStyle, &pat);
1469 ::PenPat(&pat);
1470 }
1471 else
1472 {
1473 ::PenPat(GetQDGlobalsBlack(&blackColor));
1474 }
1475
1476 short mode = patCopy ;
1477
1478 // todo :
1479
1480 switch( m_logicalFunction )
1481 {
1482 case wxCOPY: // src
1483 mode = patCopy ;
1484 break ;
1485 case wxINVERT: // NOT dst
1486 ::PenPat(GetQDGlobalsBlack(&blackColor));
1487 mode = patXor ;
1488 break ;
1489 case wxXOR: // src XOR dst
1490 mode = patXor ;
1491 break ;
1492 case wxOR_REVERSE: // src OR (NOT dst)
1493 mode = notPatOr ;
1494 break ;
1495 case wxSRC_INVERT: // (NOT src)
1496 mode = notPatCopy ;
1497 break ;
1498
1499 // unsupported TODO
1500
1501 case wxCLEAR: // 0
1502 case wxAND_REVERSE:// src AND (NOT dst)
1503 case wxAND: // src AND dst
1504 case wxAND_INVERT: // (NOT src) AND dst
1505 case wxNO_OP: // dst
1506 case wxNOR: // (NOT src) AND (NOT dst)
1507 case wxEQUIV: // (NOT src) XOR dst
1508 case wxOR_INVERT: // (NOT src) OR dst
1509 case wxNAND: // (NOT src) OR (NOT dst)
1510 case wxOR: // src OR dst
1511 case wxSET: // 1
1512// case wxSRC_OR: // source _bitmap_ OR destination
1513// case wxSRC_AND: // source _bitmap_ AND destination
1514 break ;
1515 }
1516 ::PenMode( mode ) ;
1517 m_macPenInstalled = true ;
1518 m_macBrushInstalled = false ;
1519 m_macFontInstalled = false ;
1520}
1521
1522void wxDC::MacInstallBrush() const
1523{
1524 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1525
1526 Pattern blackColor, whiteColor ;
1527// if ( m_macBrushInstalled )
1528// return ;
1529
1530 // foreground
1531
1532 RGBColor forecolor = m_brush.GetColour().GetPixel();
1533 RGBColor backcolor = m_backgroundBrush.GetColour().GetPixel();
1534 ::RGBForeColor( &forecolor );
1535 ::RGBBackColor( &backcolor );
1536
1537 int brushStyle = m_brush.GetStyle();
1538 if (brushStyle == wxSOLID)
1539 ::PenPat(GetQDGlobalsBlack(&blackColor));
1540 else if (IS_HATCH(brushStyle))
1541 {
1542 Pattern pat ;
1543 wxMacGetHatchPattern(brushStyle, &pat);
1544 ::PenPat(&pat);
1545 }
1546 else
1547 {
1548 ::PenPat(GetQDGlobalsBlack(&blackColor));
1549 }
1550
1551
1552 // background
1553
1554 brushStyle = m_backgroundBrush.GetStyle();
1555 if (brushStyle == wxSOLID)
1556 ::BackPat(GetQDGlobalsWhite(&whiteColor));
1557 else if (IS_HATCH(brushStyle))
1558 {
1559 Pattern pat ;
1560 wxMacGetHatchPattern(brushStyle, &pat);
1561 ::BackPat(&pat);
1562 }
1563 else
1564 {
1565 ::BackPat(GetQDGlobalsWhite(&whiteColor));
1566 }
1567
1568 short mode = patCopy ;
1569
1570 // todo :
1571
1572 switch( m_logicalFunction )
1573 {
1574 case wxCOPY: // src
1575 mode = patCopy ;
1576 break ;
1577 case wxINVERT: // NOT dst
1578 ::PenPat(GetQDGlobalsBlack(&blackColor));
1579 mode = patXor ;
1580 break ;
1581 case wxXOR: // src XOR dst
1582 mode = patXor ;
1583 break ;
1584 case wxOR_REVERSE: // src OR (NOT dst)
1585 mode = notPatOr ;
1586 break ;
1587 case wxSRC_INVERT: // (NOT src)
1588 mode = notPatCopy ;
1589 break ;
1590
1591 // unsupported TODO
1592
1593 case wxCLEAR: // 0
1594 case wxAND_REVERSE:// src AND (NOT dst)
1595 case wxAND: // src AND dst
1596 case wxAND_INVERT: // (NOT src) AND dst
1597 case wxNO_OP: // dst
1598 case wxNOR: // (NOT src) AND (NOT dst)
1599 case wxEQUIV: // (NOT src) XOR dst
1600 case wxOR_INVERT: // (NOT src) OR dst
1601 case wxNAND: // (NOT src) OR (NOT dst)
1602 case wxOR: // src OR dst
1603 case wxSET: // 1
1604// case wxSRC_OR: // source _bitmap_ OR destination
1605// case wxSRC_AND: // source _bitmap_ AND destination
1606 break ;
1607 }
1608 ::PenMode( mode ) ;
1609 m_macBrushInstalled = true ;
1610 m_macPenInstalled = false ;
1611 m_macFontInstalled = false ;
1612}
1613
1614// ---------------------------------------------------------------------------
1615// coordinates transformations
1616// ---------------------------------------------------------------------------
1617
1618
1619wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
1620{
1621 return ((wxDC *)this)->XDEV2LOG(x);
1622}
1623
1624wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
1625{
1626 return ((wxDC *)this)->YDEV2LOG(y);
1627}
1628
1629wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
1630{
1631 return ((wxDC *)this)->XDEV2LOGREL(x);
1632}
1633
1634wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
1635{
1636 return ((wxDC *)this)->YDEV2LOGREL(y);
1637}
1638
1639wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
1640{
1641 return ((wxDC *)this)->XLOG2DEV(x);
1642}
1643
1644wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
1645{
1646 return ((wxDC *)this)->YLOG2DEV(y);
1647}
1648
1649wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
1650{
1651 return ((wxDC *)this)->XLOG2DEVREL(x);
1652}
1653
1654wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
1655{
1656 return ((wxDC *)this)->YLOG2DEVREL(y);
1657}