]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dccg.cpp
respect styles during creation as well
[wxWidgets.git] / src / mac / carbon / dccg.cpp
CommitLineData
613a24f7
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.cpp
3// Purpose: wxDC class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "dc.h"
14#endif
15
20b69855
SC
16#include "wx/wxprec.h"
17
613a24f7 18#include "wx/dc.h"
20b69855
SC
19
20#if wxMAC_USE_CORE_GRAPHICS
21
613a24f7
SC
22#include "wx/app.h"
23#include "wx/mac/uma.h"
24#include "wx/dcmemory.h"
25#include "wx/dcprint.h"
26#include "wx/region.h"
27#include "wx/image.h"
28#include "wx/log.h"
29
20b69855 30
613a24f7
SC
31#if __MSL__ >= 0x6000
32#include "math.h"
33using namespace std ;
34#endif
35
36#include "wx/mac/private.h"
37#include <ATSUnicode.h>
38#include <TextCommon.h>
39#include <TextEncodingConverter.h>
40#include <FixMath.h>
41#include <CGContext.h>
42
613a24f7 43IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
613a24f7
SC
44
45//-----------------------------------------------------------------------------
46// constants
47//-----------------------------------------------------------------------------
48
49#if !defined( __DARWIN__ ) || defined(__MWERKS__)
50#ifndef M_PI
51const double M_PI = 3.14159265358979 ;
52#endif
53#endif
54const double RAD2DEG = 180.0 / M_PI;
55const short kEmulatedMode = -1 ;
56const short kUnsupportedMode = -2 ;
57
58extern TECObjectRef s_TECNativeCToUnicode ;
59
20b69855
SC
60// TODO Update
61// The text ctrl implementation still needs that for the non hiview implementation
613a24f7
SC
62
63wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) :
64 wxMacPortSaver( (GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) )
65{
66 m_newPort =(GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) ;
67 m_formerClip = NewRgn() ;
68 m_newClip = NewRgn() ;
69 GetClip( m_formerClip ) ;
70
71 if ( win )
72 {
bcbbfab8
SC
73 // guard against half constructed objects, this just leads to a empty clip
74 if( win->GetPeer() )
75 {
76 int x = 0 , y = 0;
77 win->MacWindowToRootWindow( &x,&y ) ;
78 // get area including focus rect
79 CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip ) ;
80 if ( !EmptyRgn( m_newClip ) )
81 OffsetRgn( m_newClip , x , y ) ;
82 }
613a24f7
SC
83
84 SetClip( m_newClip ) ;
85 }
86}
87
88wxMacWindowClipper::~wxMacWindowClipper()
89{
90 SetPort( m_newPort ) ;
91 SetClip( m_formerClip ) ;
92 DisposeRgn( m_newClip ) ;
93 DisposeRgn( m_formerClip ) ;
94}
95
96wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow* win ) :
97 wxMacWindowClipper( win )
98{
99 // the port is already set at this point
100 m_newPort =(GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) ;
101 GetThemeDrawingState( &m_themeDrawingState ) ;
102}
103
104wxMacWindowStateSaver::~wxMacWindowStateSaver()
105{
106 SetPort( m_newPort ) ;
107 SetThemeDrawingState( m_themeDrawingState , true ) ;
108}
109
a8f234d2
SC
110// minimal implementation only used for appearance drawing < 10.3
111
112wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) :
113 m_ph( (GrafPtr) dc->m_macPort )
114{
115 wxASSERT( dc->Ok() ) ;
116 m_dc = dc ;
117// dc->MacSetupPort(&m_ph) ;
118}
119wxMacPortSetter::~wxMacPortSetter()
120{
121// m_dc->MacCleanupPort(&m_ph) ;
122}
123
613a24f7
SC
124//-----------------------------------------------------------------------------
125// Local functions
126//-----------------------------------------------------------------------------
20b69855 127
613a24f7
SC
128static inline double dmin(double a, double b) { return a < b ? a : b; }
129static inline double dmax(double a, double b) { return a > b ? a : b; }
130static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
131
132//-----------------------------------------------------------------------------
20b69855
SC
133// device context implementation
134//
135// more and more of the dc functionality should be implemented by calling
136// the appropricate wxMacCGContext, but we will have to do that step by step
137// also coordinate conversions should be moved to native matrix ops
613a24f7 138//-----------------------------------------------------------------------------
613a24f7 139
20b69855 140wxMacCGPath::wxMacCGPath()
613a24f7 141{
20b69855 142 m_path = CGPathCreateMutable() ;
613a24f7
SC
143}
144
20b69855 145wxMacCGPath::~wxMacCGPath()
613a24f7 146{
20b69855
SC
147 CGPathRelease( m_path ) ;
148}
613a24f7 149
20b69855
SC
150// Starts a new subpath at
151void wxMacCGPath::MoveToPoint( wxCoord x1 , wxCoord y1 )
152{
153 CGPathMoveToPoint( m_path , NULL , x1 , y1 ) ;
154}
613a24f7 155
20b69855
SC
156void wxMacCGPath::AddLineToPoint( wxCoord x1 , wxCoord y1 )
157{
158 CGPathAddLineToPoint( m_path , NULL , x1 , y1 ) ;
159}
613a24f7 160
20b69855 161void wxMacCGPath::AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
613a24f7 162{
20b69855
SC
163 CGRect cgRect = { { x , y } , { w , h } } ;
164 CGPathAddRect( m_path , NULL , cgRect ) ;
165}
613a24f7 166
20b69855
SC
167void wxMacCGPath::AddCircle( wxCoord x, wxCoord y , wxCoord r )
168{
169 CGPathAddArc( m_path , NULL , x , y , r , 0.0 , 2 * M_PI , true ) ;
170}
613a24f7 171
20b69855
SC
172// closes the current subpath
173void wxMacCGPath::CloseSubpath()
174{
175 CGPathCloseSubpath( m_path ) ;
176}
613a24f7 177
20b69855 178CGPathRef wxMacCGPath::GetPath() const
613a24f7 179{
20b69855
SC
180 return m_path ;
181}
182
b014adcc
SC
183// we always stock two context states, one at entry, the other one after
184// changing to HI Graphics orientation (this one is used for getting back clippings etc)
613a24f7 185
20b69855
SC
186wxMacCGContext::wxMacCGContext( CGrafPtr port )
187{
188 m_qdPort = port ;
cb4b0966 189 m_cgContext = NULL ;
20b69855
SC
190}
191
192wxMacCGContext::wxMacCGContext( CGContextRef cgcontext )
193{
194 m_qdPort = NULL ;
195 m_cgContext = cgcontext ;
b014adcc
SC
196 CGContextSaveGState( m_cgContext ) ;
197 CGContextSaveGState( m_cgContext ) ;
20b69855
SC
198}
199
200wxMacCGContext::wxMacCGContext()
201{
202 m_qdPort = NULL ;
203 m_cgContext = NULL ;
204}
613a24f7 205
20b69855
SC
206wxMacCGContext::~wxMacCGContext()
207{
b014adcc
SC
208 if ( m_cgContext )
209 {
68654a82 210 CGContextSynchronize( m_cgContext ) ;
b014adcc
SC
211 CGContextRestoreGState( m_cgContext ) ;
212 CGContextRestoreGState( m_cgContext ) ;
213 }
20b69855 214 if ( m_qdPort )
68654a82 215 CGContextRelease( m_cgContext ) ;
20b69855
SC
216}
217
218
219void wxMacCGContext::Clip( const wxRegion &region )
220{
221// ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
222}
223
224void wxMacCGContext::StrokePath( const wxGraphicPath *p )
225{
226 const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ;
227 CGContextBeginPath( m_cgContext ) ;
228 CGContextAddPath( m_cgContext , path->GetPath() ) ;
229 CGContextClosePath( m_cgContext ) ;
230 CGContextStrokePath( m_cgContext ) ;
231}
232
233void wxMacCGContext::DrawPath( const wxGraphicPath *p , int fillStyle )
234{
235 const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ;
236 CGPathDrawingMode mode = m_mode ;
237 if ( fillStyle == wxODDEVEN_RULE )
238 {
239 if ( mode == kCGPathFill )
240 mode = kCGPathEOFill ;
241 else if ( mode == kCGPathFillStroke )
242 mode = kCGPathEOFillStroke ;
243 }
244 CGContextBeginPath( m_cgContext ) ;
245 CGContextAddPath( m_cgContext , path->GetPath() ) ;
246 CGContextClosePath( m_cgContext ) ;
247 CGContextDrawPath( m_cgContext , mode ) ;
613a24f7
SC
248}
249
20b69855 250void wxMacCGContext::FillPath( const wxGraphicPath *p , const wxColor &fillColor , int fillStyle )
613a24f7 251{
20b69855
SC
252 const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ;
253 CGContextSaveGState( m_cgContext ) ;
254
255 RGBColor col = MAC_WXCOLORREF( fillColor.GetPixel() ) ;
256 CGContextSetRGBFillColor( m_cgContext , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
257 CGPathDrawingMode mode = kCGPathFill ;
258
259 if ( fillStyle == wxODDEVEN_RULE )
260 mode = kCGPathEOFill ;
261
262 CGContextBeginPath( m_cgContext ) ;
263 CGContextAddPath( m_cgContext , path->GetPath() ) ;
264 CGContextClosePath( m_cgContext ) ;
265 CGContextDrawPath( m_cgContext , mode ) ;
266
267 CGContextRestoreGState( m_cgContext ) ;
268}
613a24f7 269
cb4b0966
SC
270wxGraphicPath* wxMacCGContext::CreatePath()
271{
cb4b0966
SC
272 // make sure that we now have a real cgref, before doing
273 // anything with paths
a63b4755
SC
274 CGContextRef cg = GetNativeContext() ;
275 cg = NULL ;
cb4b0966
SC
276 return new wxMacCGPath() ;
277}
278
279// in case we only got a QDPort only create a cgref now
280
281CGContextRef wxMacCGContext::GetNativeContext()
282{
283 if( m_cgContext == NULL )
284 {
285 Rect bounds ;
286 GetPortBounds( (CGrafPtr) m_qdPort , &bounds ) ;
68654a82 287 OSStatus status = CreateCGContextForPort((CGrafPtr) m_qdPort , &m_cgContext) ;
b014adcc 288 CGContextSaveGState( m_cgContext ) ;
cb4b0966
SC
289
290 wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ;
291 CGContextTranslateCTM( m_cgContext , 0 , bounds.bottom - bounds.top ) ;
292 CGContextScaleCTM( m_cgContext , 1 , -1 ) ;
293
b014adcc 294 CGContextSaveGState( m_cgContext ) ;
cb4b0966
SC
295 SetPen( m_pen ) ;
296 SetBrush( m_brush ) ;
297 }
298 return m_cgContext ;
299}
300
301void wxMacCGContext::SetNativeContext( CGContextRef cg )
302{
b014adcc 303 wxASSERT( m_cgContext == NULL ) ;
cb4b0966 304 m_cgContext = cg ;
b014adcc 305 CGContextSaveGState( m_cgContext ) ;
cb4b0966 306}
20b69855
SC
307
308void wxMacCGContext::SetPen( const wxPen &pen )
309{
cb4b0966
SC
310 m_pen = pen ;
311 if ( m_cgContext == NULL )
312 return ;
20b69855
SC
313 bool fill = m_brush.GetStyle() != wxTRANSPARENT ;
314 bool stroke = pen.GetStyle() != wxTRANSPARENT ;
cb4b0966 315
20b69855
SC
316#if 0
317 // we can benchmark performance, should go into a setting later
318 CGContextSetShouldAntialias( m_cgContext , false ) ;
319#endif
613a24f7
SC
320 if ( fill | stroke )
321 {
613a24f7
SC
322 // setup brushes
323 m_mode = kCGPathFill ; // just a default
324
325 if ( fill )
326 {
613a24f7
SC
327 m_mode = kCGPathFill ;
328 }
329 if ( stroke )
330 {
20b69855 331 RGBColor col = MAC_WXCOLORREF( pen.GetColour().GetPixel() ) ;
613a24f7
SC
332 CGContextSetRGBStrokeColor( m_cgContext , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
333
334 CGLineCap cap ;
20b69855 335 switch( pen.GetCap() )
613a24f7
SC
336 {
337 case wxCAP_ROUND :
338 cap = kCGLineCapRound ;
339 break ;
340 case wxCAP_PROJECTING :
341 cap = kCGLineCapSquare ;
342 break ;
343 case wxCAP_BUTT :
344 cap = kCGLineCapButt ;
345 break ;
346 default :
347 cap = kCGLineCapButt ;
348 break ;
349 }
350 CGContextSetLineCap( m_cgContext , cap ) ;
351
352 CGLineJoin join ;
20b69855 353 switch( pen.GetJoin() )
613a24f7
SC
354 {
355 case wxJOIN_BEVEL :
356 join = kCGLineJoinBevel ;
357 break ;
358 case wxJOIN_MITER :
359 join = kCGLineJoinMiter ;
360 break ;
361 case wxJOIN_ROUND :
362 join = kCGLineJoinRound ;
363 break ;
364 default :
365 join = kCGLineJoinMiter ;
366 break;
367 }
368 CGContextSetLineJoin( m_cgContext , join ) ;
369
20b69855 370 CGContextSetLineWidth( m_cgContext , pen.GetWidth() == 0 ? 0.1 : pen.GetWidth() /* TODO * m_dc->m_scaleX */ ) ;
613a24f7
SC
371
372 m_mode = kCGPathStroke ;
373 int count = 0 ;
374 const float *lengths = NULL ;
375 float *userLengths = NULL ;
376
20b69855
SC
377 const float dotted[] = { 3 , 3 };
378 const float dashed[] = { 19 , 9 };
379 const float short_dashed[] = { 9 , 6 };
380 const float dotted_dashed[] = { 9 , 6 , 3 , 3 };
381
382 switch( pen.GetStyle() )
613a24f7
SC
383 {
384 case wxSOLID :
385 break ;
386 case wxDOT :
613a24f7
SC
387 lengths = dotted ;
388 count = WXSIZEOF(dotted);
389 break ;
390 case wxLONG_DASH :
613a24f7
SC
391 lengths = dashed ;
392 count = WXSIZEOF(dashed) ;
393 break ;
394 case wxSHORT_DASH :
613a24f7
SC
395 lengths = short_dashed ;
396 count = WXSIZEOF(short_dashed) ;
397 break ;
398 case wxDOT_DASH :
613a24f7
SC
399 lengths = dotted_dashed ;
400 count = WXSIZEOF(dotted_dashed);
401 break ;
402 case wxUSER_DASH :
403 wxDash *dashes ;
20b69855 404 count = pen.GetDashes( &dashes ) ;
613a24f7
SC
405 if ( count >0 )
406 {
407 userLengths = new float[count] ;
408 for( int i = 0 ; i < count ; ++i )
409 userLengths[i] = dashes[i] ;
410 }
411 lengths = userLengths ;
412 break ;
413 default :
414 break ;
415 }
416
417 CGContextSetLineDash( m_cgContext , 0 , lengths , count ) ;
418 delete[] userLengths ;
419 // we need to change the cap, otherwise everything overlaps
420 // and we get solid lines
421 if ( count > 0 )
422 CGContextSetLineCap( m_cgContext , kCGLineCapButt ) ;
423 }
424 if ( fill && stroke )
425 {
426 m_mode = kCGPathFillStroke ;
427 }
428
429 }
430}
20b69855
SC
431void wxMacCGContext::SetBrush( const wxBrush &brush )
432{
cb4b0966
SC
433 m_brush = brush ;
434 if ( m_cgContext == NULL )
435 return ;
436
20b69855
SC
437 bool fill = brush.GetStyle() != wxTRANSPARENT ;
438 bool stroke = m_pen.GetStyle() != wxTRANSPARENT ;
613a24f7 439
20b69855
SC
440#if 0
441 // we can benchmark performance, should go into a setting later
442 CGContextSetShouldAntialias( m_cgContext , false ) ;
443#endif
444 if ( fill | stroke )
445 {
446
447 // setup brushes
448 m_mode = kCGPathFill ; // just a default
449
450 if ( fill )
451 {
452 RGBColor col = MAC_WXCOLORREF( brush.GetColour().GetPixel() ) ;
453 CGContextSetRGBFillColor( m_cgContext , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
454 m_mode = kCGPathFill ;
455 }
456 if ( stroke )
457 {
458 m_mode = kCGPathStroke ;
459 }
460 if ( fill && stroke )
461 {
462 m_mode = kCGPathFillStroke ;
463 }
464
465 }
466}
467
613a24f7
SC
468void AddEllipticArcToPath(CGContextRef c, CGPoint center, float a, float b, float fromDegree , float toDegree )
469{
470 CGContextSaveGState(c);
471 CGContextTranslateCTM(c, center.x, center.y);
472 CGContextScaleCTM(c, a, b);
473 CGContextMoveToPoint(c, 1, 0);
474 CGContextAddArc(c, 0, 0, 1, DegToRad(fromDegree), DegToRad(toDegree), 0);
475 CGContextClosePath(c);
476 CGContextRestoreGState(c);
477}
478
479void AddRoundedRectToPath(CGContextRef c, CGRect rect, float ovalWidth,
480 float ovalHeight)
481{
482 float fw, fh;
483 if (ovalWidth == 0 || ovalHeight == 0)
484 {
485 CGContextAddRect(c, rect);
486 return;
487 }
488 CGContextSaveGState(c);
489 CGContextTranslateCTM(c, CGRectGetMinX(rect), CGRectGetMinY(rect));
490 CGContextScaleCTM(c, ovalWidth, ovalHeight);
491 fw = CGRectGetWidth(rect) / ovalWidth;
492 fh = CGRectGetHeight(rect) / ovalHeight;
493 CGContextMoveToPoint(c, fw, fh/2);
494 CGContextAddArcToPoint(c, fw, fh, fw/2, fh, 1);
495 CGContextAddArcToPoint(c, 0, fh, 0, fh/2, 1);
496 CGContextAddArcToPoint(c, 0, 0, fw/2, 0, 1);
497 CGContextAddArcToPoint(c, fw, 0, fw, fh/2, 1);
498 CGContextClosePath(c);
499 CGContextRestoreGState(c);
500}
501
502wxDC::wxDC()
503{
504 m_ok = FALSE;
505 m_colour = TRUE;
506 m_mm_to_pix_x = mm2pt;
507 m_mm_to_pix_y = mm2pt;
508 m_internalDeviceOriginX = 0;
509 m_internalDeviceOriginY = 0;
510 m_externalDeviceOriginX = 0;
511 m_externalDeviceOriginY = 0;
512 m_logicalScaleX = 1.0;
513 m_logicalScaleY = 1.0;
514 m_userScaleX = 1.0;
515 m_userScaleY = 1.0;
516 m_scaleX = 1.0;
517 m_scaleY = 1.0;
518 m_needComputeScaleX = FALSE;
519 m_needComputeScaleY = FALSE;
20b69855 520
613a24f7 521 m_ok = FALSE ;
a63b4755 522 m_macPort = 0 ;
613a24f7 523 m_macLocalOrigin.x = m_macLocalOrigin.y = 0 ;
20b69855 524
613a24f7
SC
525 m_pen = *wxBLACK_PEN;
526 m_font = *wxNORMAL_FONT;
527 m_brush = *wxWHITE_BRUSH;
613a24f7 528
20b69855 529 m_macATSUIStyle = NULL ;
613a24f7 530
20b69855 531 m_graphicContext = NULL ;
613a24f7
SC
532}
533
20b69855 534wxDC::~wxDC(void)
613a24f7 535{
613a24f7
SC
536 if( m_macATSUIStyle )
537 {
538 ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle);
539 m_macATSUIStyle = NULL ;
540 }
20b69855
SC
541
542 delete m_graphicContext ;
613a24f7
SC
543}
544
545void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
546{
20b69855
SC
547 wxCHECK_RET( Ok(), wxT("invalid window dc") );
548 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
549 wxCoord xx = XLOG2DEVMAC(x);
550 wxCoord yy = YLOG2DEVMAC(y);
551 wxCoord w = bmp.GetWidth();
552 wxCoord h = bmp.GetHeight();
553 wxCoord ww = XLOG2DEVREL(w);
554 wxCoord hh = YLOG2DEVREL(h);
555
b60f5ca5 556 CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
20b69855
SC
557 CGImageRef image = (CGImageRef)( bmp.CGImageCreate() ) ;
558 HIRect r = CGRectMake( xx , yy , ww , hh ) ;
559 HIViewDrawCGImage( cg , &r , image ) ;
560 CGImageRelease( image ) ;
613a24f7
SC
561}
562
563void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
564{
565 wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
566 wxCHECK_RET(icon.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
20b69855
SC
567
568 wxCoord xx = XLOG2DEVMAC(x);
569 wxCoord yy = YLOG2DEVMAC(y);
570 wxCoord w = icon.GetWidth();
571 wxCoord h = icon.GetHeight();
572 wxCoord ww = XLOG2DEVREL(w);
573 wxCoord hh = YLOG2DEVREL(h);
574
b60f5ca5 575 CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
20b69855
SC
576 CGRect r = CGRectMake( 00 , 00 , ww , hh ) ;
577 CGContextSaveGState(cg);
578 CGContextTranslateCTM(cg, xx , yy + hh );
579 CGContextScaleCTM(cg, 1, -1);
580 PlotIconRefInContext( cg , &r , kAlignNone , kTransformNone ,
581 NULL , kPlotIconRefNormalFlags , MAC_WXHICON( icon.GetHICON() ) ) ;
582 CGContextRestoreGState( cg ) ;
613a24f7
SC
583}
584
585void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
586{
587 wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
588 wxCoord xx, yy, ww, hh;
589 xx = XLOG2DEVMAC(x);
590 yy = YLOG2DEVMAC(y);
591 ww = XLOG2DEVREL(width);
592 hh = YLOG2DEVREL(height);
b014adcc 593
b60f5ca5 594 CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
b014adcc
SC
595 CGRect clipRect = CGRectMake( xx ,yy , ww, hh ) ;
596 CGContextClipToRect( cgContext , clipRect ) ;
597
20b69855
SC
598// SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
599// SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
613a24f7
SC
600 if( m_clipping )
601 {
602 m_clipX1 = wxMax( m_clipX1 , xx );
603 m_clipY1 = wxMax( m_clipY1 , yy );
604 m_clipX2 = wxMin( m_clipX2, (xx + ww));
605 m_clipY2 = wxMin( m_clipY2, (yy + hh));
606 }
607 else
608 {
609 m_clipping = TRUE;
610 m_clipX1 = xx;
611 m_clipY1 = yy;
612 m_clipX2 = xx + ww;
613 m_clipY2 = yy + hh;
614 }
615 // TODO as soon as we don't reset the context for each operation anymore
616 // we have to update the context as well
617}
618
619void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region )
620{
621 wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
622 if (region.Empty())
623 {
624 DestroyClippingRegion();
625 return;
626 }
627 wxCoord x, y, w, h;
628 region.GetBox( x, y, w, h );
629 wxCoord xx, yy, ww, hh;
630 xx = XLOG2DEVMAC(x);
631 yy = YLOG2DEVMAC(y);
632 ww = XLOG2DEVREL(w);
633 hh = YLOG2DEVREL(h);
634 // if we have a scaling that we cannot map onto native regions
635 // we must use the box
636 if ( ww != w || hh != h )
637 {
638 wxDC::DoSetClippingRegion( x, y, w, h );
639 }
640 else
641 {
20b69855 642 /*
613a24f7
SC
643 CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ;
644 if ( xx != x || yy != y )
645 {
646 OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ;
647 }
648 SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
20b69855 649 */
613a24f7
SC
650 if( m_clipping )
651 {
652 m_clipX1 = wxMax( m_clipX1 , xx );
653 m_clipY1 = wxMax( m_clipY1 , yy );
654 m_clipX2 = wxMin( m_clipX2, (xx + ww));
655 m_clipY2 = wxMin( m_clipY2, (yy + hh));
656 }
657 else
658 {
659 m_clipping = TRUE;
660 m_clipX1 = xx;
661 m_clipY1 = yy;
662 m_clipX2 = xx + ww;
663 m_clipY2 = yy + hh;
664 }
665 }
666}
667
668void wxDC::DestroyClippingRegion()
669{
20b69855 670// CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
b60f5ca5 671 CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
b014adcc
SC
672 CGContextRestoreGState( cgContext );
673 CGContextSaveGState( cgContext );
674 SetPen( m_pen ) ;
675 SetBrush( m_brush ) ;
613a24f7
SC
676 m_clipping = FALSE;
677}
678
679void wxDC::DoGetSizeMM( int* width, int* height ) const
680{
681 int w = 0;
682 int h = 0;
683 GetSize( &w, &h );
684 *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) );
685 *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) );
686}
687
688void wxDC::SetTextForeground( const wxColour &col )
689{
690 wxCHECK_RET(Ok(), wxT("Invalid DC"));
20b69855
SC
691 if ( col != m_textForegroundColour )
692 {
693 m_textForegroundColour = col;
694 MacInstallFont() ;
695 }
613a24f7
SC
696}
697
698void wxDC::SetTextBackground( const wxColour &col )
699{
700 wxCHECK_RET(Ok(), wxT("Invalid DC"));
701 m_textBackgroundColour = col;
613a24f7
SC
702}
703
704void wxDC::SetMapMode( int mode )
705{
706 switch (mode)
707 {
708 case wxMM_TWIPS:
709 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
710 break;
711 case wxMM_POINTS:
712 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
713 break;
714 case wxMM_METRIC:
715 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
716 break;
717 case wxMM_LOMETRIC:
718 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
719 break;
720 default:
721 case wxMM_TEXT:
722 SetLogicalScale( 1.0, 1.0 );
723 break;
724 }
725 if (mode != wxMM_TEXT)
726 {
727 m_needComputeScaleX = TRUE;
728 m_needComputeScaleY = TRUE;
729 }
730}
731
732void wxDC::SetUserScale( double x, double y )
733{
734 // allow negative ? -> no
735 m_userScaleX = x;
736 m_userScaleY = y;
737 ComputeScaleAndOrigin();
738}
739
740void wxDC::SetLogicalScale( double x, double y )
741{
742 // allow negative ?
743 m_logicalScaleX = x;
744 m_logicalScaleY = y;
745 ComputeScaleAndOrigin();
746}
747
748void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
749{
750 m_logicalOriginX = x * m_signX; // is this still correct ?
751 m_logicalOriginY = y * m_signY;
752 ComputeScaleAndOrigin();
753}
754
755void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
756{
757 m_externalDeviceOriginX = x;
758 m_externalDeviceOriginY = y;
759 ComputeScaleAndOrigin();
760}
761
762void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
763{
764 m_signX = (xLeftRight ? 1 : -1);
765 m_signY = (yBottomUp ? -1 : 1);
766 ComputeScaleAndOrigin();
767}
768
769wxSize wxDC::GetPPI() const
770{
771 return wxSize(72, 72);
772}
773
774int wxDC::GetDepth() const
775{
20b69855 776 return 32 ;
613a24f7
SC
777}
778
779void wxDC::ComputeScaleAndOrigin()
780{
781 // CMB: copy scale to see if it changes
782 double origScaleX = m_scaleX;
783 double origScaleY = m_scaleY;
784 m_scaleX = m_logicalScaleX * m_userScaleX;
785 m_scaleY = m_logicalScaleY * m_userScaleY;
786 m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX;
787 m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY;
788 // CMB: if scale has changed call SetPen to recalulate the line width
789 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
790 {
791 // this is a bit artificial, but we need to force wxDC to think
792 // the pen has changed
793 wxPen pen(GetPen());
794 m_pen = wxNullPen;
795 SetPen(pen);
796 }
797}
798
799void wxDC::SetPalette( const wxPalette& palette )
800{
801}
802
803void wxDC::SetBackgroundMode( int mode )
804{
805 m_backgroundMode = mode ;
806}
807
808void wxDC::SetFont( const wxFont &font )
809{
810 m_font = font;
20b69855 811 MacInstallFont() ;
613a24f7
SC
812}
813
814void wxDC::SetPen( const wxPen &pen )
815{
816 if ( m_pen == pen )
817 return ;
818 m_pen = pen;
20b69855
SC
819 if ( m_graphicContext )
820 {
821 m_graphicContext->SetPen( m_pen ) ;
822 }
613a24f7
SC
823}
824
825void wxDC::SetBrush( const wxBrush &brush )
826{
827 if (m_brush == brush)
828 return;
829 m_brush = brush;
20b69855
SC
830 if ( m_graphicContext )
831 {
832 m_graphicContext->SetBrush( m_brush ) ;
833 }
613a24f7
SC
834}
835
836void wxDC::SetBackground( const wxBrush &brush )
837{
838 if (m_backgroundBrush == brush)
839 return;
840 m_backgroundBrush = brush;
841 if (!m_backgroundBrush.Ok())
842 return;
613a24f7
SC
843}
844
845void wxDC::SetLogicalFunction( int function )
846{
847 if (m_logicalFunction == function)
848 return;
849 m_logicalFunction = function ;
613a24f7
SC
850}
851
852extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
853 const wxColour & col, int style);
854
855bool wxDC::DoFloodFill(wxCoord x, wxCoord y,
856 const wxColour& col, int style)
857{
858 return wxDoFloodFill(this, x, y, col, style);
859}
860
861bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const
862{
863 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
880f5369
SC
864 wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
865 wxMacPortSaver helper((CGrafPtr)m_macPort) ;
866 RGBColor colour;
867 GetCPixel(
868 XLOG2DEVMAC(x) + m_macLocalOriginInPort.x - m_macLocalOrigin.x,
869 YLOG2DEVMAC(y) + m_macLocalOriginInPort.y - m_macLocalOrigin.y, &colour );
870 // Convert from Mac colour to wx
871 col->Set( colour.red >> 8,
872 colour.green >> 8,
873 colour.blue >> 8);
874 return true ;
613a24f7
SC
875}
876
877void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
878{
879 wxCHECK_RET(Ok(), wxT("Invalid DC"));
880
08c8555e
SC
881 if ( m_logicalFunction != wxCOPY )
882 return ;
883
613a24f7
SC
884 wxCoord xx1 = XLOG2DEVMAC(x1) ;
885 wxCoord yy1 = YLOG2DEVMAC(y1) ;
886 wxCoord xx2 = XLOG2DEVMAC(x2) ;
887 wxCoord yy2 = YLOG2DEVMAC(y2) ;
888
20b69855
SC
889 wxGraphicPath* path = m_graphicContext->CreatePath() ;
890 path->MoveToPoint( xx1 , yy1 ) ;
891 path->AddLineToPoint( xx2 , yy2 ) ;
892 path->CloseSubpath() ;
893 m_graphicContext->StrokePath( path ) ;
894 delete path ;
613a24f7
SC
895
896 CalcBoundingBox(x1, y1);
897 CalcBoundingBox(x2, y2);
898}
899
900void wxDC::DoCrossHair( wxCoord x, wxCoord y )
901{
902 wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") );
903
08c8555e
SC
904 if ( m_logicalFunction != wxCOPY )
905 return ;
613a24f7
SC
906
907 int w = 0;
908 int h = 0;
909 GetSize( &w, &h );
910 wxCoord xx = XLOG2DEVMAC(x);
911 wxCoord yy = YLOG2DEVMAC(y);
912
20b69855
SC
913 wxGraphicPath* path = m_graphicContext->CreatePath() ;
914 path->MoveToPoint( XLOG2DEVMAC(0), yy ) ;
915 path->AddLineToPoint( XLOG2DEVMAC(w), yy ) ;
916 path->CloseSubpath() ;
917 path->MoveToPoint( xx, YLOG2DEVMAC(0) ) ;
918 path->AddLineToPoint( xx, YLOG2DEVMAC(h) ) ;
919 path->CloseSubpath() ;
920 m_graphicContext->StrokePath( path ) ;
921 delete path ;
613a24f7
SC
922
923 CalcBoundingBox(x, y);
924 CalcBoundingBox(x+w, y+h);
925}
926
927/*
928* To draw arcs properly the angles need to be converted from the WX style:
929* Angles start on the +ve X axis and go anti-clockwise (As you would draw on
930* a normal axis on paper).
931* TO
932* the Mac style:
933* Angles start on the +ve y axis and go clockwise.
934*/
935
936static double wxConvertWXangleToMACangle(double angle)
937{
938 double newAngle = 90 - angle ;
939 if ( newAngle < 0 )
940 newAngle += 360 ;
941 return newAngle ;
942}
943
944void wxDC::DoDrawArc( wxCoord x1, wxCoord y1,
945 wxCoord x2, wxCoord y2,
946 wxCoord xc, wxCoord yc )
947{
948 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC"));
08c8555e
SC
949
950 if ( m_logicalFunction != wxCOPY )
951 return ;
952
613a24f7
SC
953 wxCoord xx1 = XLOG2DEVMAC(x1);
954 wxCoord yy1 = YLOG2DEVMAC(y1);
955 wxCoord xx2 = XLOG2DEVMAC(x2);
956 wxCoord yy2 = YLOG2DEVMAC(y2);
957 wxCoord xxc = XLOG2DEVMAC(xc);
958 wxCoord yyc = YLOG2DEVMAC(yc);
959 double dx = xx1 - xxc;
960 double dy = yy1 - yyc;
961 double radius = sqrt((double)(dx*dx+dy*dy));
962 wxCoord rad = (wxCoord)radius;
963 double radius1, radius2;
964 if (xx1 == xx2 && yy1 == yy2)
965 {
966 radius1 = 0.0;
967 radius2 = 360.0;
968 }
969 else if (radius == 0.0)
970 {
971 radius1 = radius2 = 0.0;
972 }
973 else
974 {
975 radius1 = (xx1 - xxc == 0) ?
976 (yy1 - yyc < 0) ? 90.0 : -90.0 :
977 -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG;
978 radius2 = (xx2 - xxc == 0) ?
979 (yy2 - yyc < 0) ? 90.0 : -90.0 :
980 -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG;
981 }
982 wxCoord alpha2 = wxCoord(radius2 - radius1);
8e475be4 983 wxCoord alpha1 = wxCoord(wxConvertWXangleToMACangle(radius1));
613a24f7
SC
984 if( (xx1 > xx2) || (yy1 > yy2) ) {
985 alpha2 *= -1;
986 }
20b69855
SC
987 wxMacCGContext* mctx = ((wxMacCGContext*) m_graphicContext) ;
988 CGContextRef ctx = mctx->GetNativeContext() ;
a63b4755 989 AddEllipticArcToPath( ctx , CGPointMake( xxc , yyc ) , rad , rad , alpha1 , alpha2 ) ;
20b69855 990 CGContextDrawPath( ctx , mctx->GetDrawingMode() ) ;
613a24f7
SC
991}
992
993void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
994 double sa, double ea )
995{
996 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC"));
20b69855 997
08c8555e
SC
998 if ( m_logicalFunction != wxCOPY )
999 return ;
1000
613a24f7
SC
1001 double angle = sa - ea; // Order important Mac in opposite direction to wx
1002 // we have to make sure that the filling is always counter-clockwise
1003 if ( angle > 0 )
1004 angle -= 360 ;
1005 wxCoord xx = XLOG2DEVMAC(x);
1006 wxCoord yy = YLOG2DEVMAC(y);
1007 wxCoord ww = m_signX * XLOG2DEVREL(w);
1008 wxCoord hh = m_signY * YLOG2DEVREL(h);
1009 // handle -ve width and/or height
1010 if (ww < 0) { ww = -ww; xx = xx - ww; }
1011 if (hh < 0) { hh = -hh; yy = yy - hh; }
1012 sa = wxConvertWXangleToMACangle(sa);
20b69855
SC
1013 wxMacCGContext* mctx = ((wxMacCGContext*) m_graphicContext) ;
1014 CGContextRef ctx = mctx->GetNativeContext() ;
1015 AddEllipticArcToPath( ctx , CGPointMake( xx + ww / 2 , yy + hh / 2 ) , ww / 2 , hh / 2 , sa , angle) ;
1016 CGContextDrawPath( ctx , mctx->GetDrawingMode() ) ;
613a24f7
SC
1017}
1018
1019void wxDC::DoDrawPoint( wxCoord x, wxCoord y )
1020{
1021 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1022 DoDrawLine( x , y , x + 1 , y + 1 ) ;
1023}
1024
1025void wxDC::DoDrawLines(int n, wxPoint points[],
1026 wxCoord xoffset, wxCoord yoffset)
1027{
1028 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1029
08c8555e
SC
1030 if ( m_logicalFunction != wxCOPY )
1031 return ;
1032
613a24f7
SC
1033 wxCoord x1, x2 , y1 , y2 ;
1034 x1 = XLOG2DEVMAC(points[0].x + xoffset);
1035 y1 = YLOG2DEVMAC(points[0].y + yoffset);
20b69855
SC
1036 wxGraphicPath* path = m_graphicContext->CreatePath() ;
1037 path->MoveToPoint( x1 , y1 ) ;
613a24f7
SC
1038 for (int i = 1; i < n; i++)
1039 {
1040 x2 = XLOG2DEVMAC(points[i].x + xoffset);
1041 y2 = YLOG2DEVMAC(points[i].y + yoffset);
1042
20b69855 1043 path->AddLineToPoint( x2 , y2 ) ;
613a24f7 1044 }
20b69855
SC
1045 m_graphicContext->StrokePath( path ) ;
1046 delete path ;
613a24f7
SC
1047}
1048
1049void wxDC::DoDrawPolygon(int n, wxPoint points[],
1050 wxCoord xoffset, wxCoord yoffset,
1051 int fillStyle )
1052{
1053 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1054 wxCoord x1, x2 , y1 , y2 ;
1055 if ( n== 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) )
1056 return ;
1057
08c8555e
SC
1058 if ( m_logicalFunction != wxCOPY )
1059 return ;
1060
613a24f7
SC
1061 x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset);
1062 y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset);
1063
20b69855
SC
1064 wxGraphicPath* path = m_graphicContext->CreatePath() ;
1065 path->MoveToPoint( x1 , y1 ) ;
613a24f7
SC
1066 for (int i = 1; i < n; i++)
1067 {
1068 x2 = XLOG2DEVMAC(points[i].x + xoffset);
1069 y2 = YLOG2DEVMAC(points[i].y + yoffset);
1070
20b69855 1071 path->AddLineToPoint( x2 , y2 ) ;
613a24f7
SC
1072 }
1073 if ( x1 != x2 || y1 != y2 )
1074 {
20b69855 1075 path->AddLineToPoint( x1,y1 ) ;
613a24f7 1076 }
20b69855
SC
1077 path->CloseSubpath() ;
1078 m_graphicContext->DrawPath( path , fillStyle ) ;
1079 delete path ;
613a24f7
SC
1080}
1081
1082void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1083{
1084 wxCHECK_RET(Ok(), wxT("Invalid DC"));
08c8555e
SC
1085
1086 if ( m_logicalFunction != wxCOPY )
1087 return ;
1088
613a24f7
SC
1089 wxCoord xx = XLOG2DEVMAC(x);
1090 wxCoord yy = YLOG2DEVMAC(y);
1091 wxCoord ww = m_signX * XLOG2DEVREL(width);
1092 wxCoord hh = m_signY * YLOG2DEVREL(height);
1093 // CMB: draw nothing if transformed w or h is 0
1094 if (ww == 0 || hh == 0)
1095 return;
1096 // CMB: handle -ve width and/or height
1097 if (ww < 0)
1098 {
1099 ww = -ww;
1100 xx = xx - ww;
1101 }
1102 if (hh < 0)
1103 {
1104 hh = -hh;
1105 yy = yy - hh;
1106 }
20b69855
SC
1107 wxGraphicPath* path = m_graphicContext->CreatePath() ;
1108 path->AddRectangle(xx ,yy , ww , hh ) ;
20b69855
SC
1109 m_graphicContext->DrawPath( path ) ;
1110 delete path ;
613a24f7
SC
1111}
1112
1113void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
1114 wxCoord width, wxCoord height,
1115 double radius)
1116{
1117 wxCHECK_RET(Ok(), wxT("Invalid DC"));
08c8555e
SC
1118
1119 if ( m_logicalFunction != wxCOPY )
1120 return ;
1121
1122
613a24f7
SC
1123 if (radius < 0.0)
1124 radius = - radius * ((width < height) ? width : height);
1125 wxCoord xx = XLOG2DEVMAC(x);
1126 wxCoord yy = YLOG2DEVMAC(y);
1127 wxCoord ww = m_signX * XLOG2DEVREL(width);
1128 wxCoord hh = m_signY * YLOG2DEVREL(height);
1129 // CMB: draw nothing if transformed w or h is 0
1130 if (ww == 0 || hh == 0)
1131 return;
1132 // CMB: handle -ve width and/or height
1133 if (ww < 0)
1134 {
1135 ww = -ww;
1136 xx = xx - ww;
1137 }
1138 if (hh < 0)
1139 {
1140 hh = -hh;
1141 yy = yy - hh;
1142 }
20b69855
SC
1143 wxMacCGContext* mctx = ((wxMacCGContext*) m_graphicContext) ;
1144 CGContextRef ctx = mctx->GetNativeContext() ;
1145 AddRoundedRectToPath( ctx , CGRectMake( xx , yy , ww , hh ) , 16 ,16 ) ;
1146 CGContextDrawPath( ctx , mctx->GetDrawingMode() ) ;
613a24f7
SC
1147}
1148
1149void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1150{
1151 wxCHECK_RET(Ok(), wxT("Invalid DC"));
08c8555e
SC
1152
1153 if ( m_logicalFunction != wxCOPY )
1154 return ;
1155
613a24f7
SC
1156 wxCoord xx = XLOG2DEVMAC(x);
1157 wxCoord yy = YLOG2DEVMAC(y);
1158 wxCoord ww = m_signX * XLOG2DEVREL(width);
1159 wxCoord hh = m_signY * YLOG2DEVREL(height);
1160 // CMB: draw nothing if transformed w or h is 0
1161 if (ww == 0 || hh == 0)
1162 return;
1163 // CMB: handle -ve width and/or height
1164 if (ww < 0)
1165 {
1166 ww = -ww;
1167 xx = xx - ww;
1168 }
1169 if (hh < 0)
1170 {
1171 hh = -hh;
1172 yy = yy - hh;
1173 }
20b69855
SC
1174
1175 wxMacCGContext* mctx = ((wxMacCGContext*) m_graphicContext) ;
1176 CGContextRef ctx = mctx->GetNativeContext() ;
613a24f7 1177 if ( width == height )
20b69855
SC
1178 {
1179 CGContextBeginPath(ctx);
1180 CGContextAddArc(ctx ,
1181 xx + ww / 2,
1182 yy + hh / 2,
1183 ww / 2,
1184 0,
1185 2 * M_PI,
1186 0 ) ;
1187 CGContextClosePath(ctx);
613a24f7 1188
0d5eaa50 1189 CGContextDrawPath( ctx , mctx->GetDrawingMode() ) ;
20b69855
SC
1190 }
1191 else
1192 {
1193 AddEllipticArcToPath( ctx , CGPointMake( xx + ww / 2 , yy + hh / 2 ) , ww / 2 , hh / 2 , 0 , 360) ;
1194 CGContextDrawPath( ctx , mctx->GetDrawingMode() ) ;
1195 }
613a24f7
SC
1196}
1197
1198bool wxDC::CanDrawBitmap(void) const
1199{
1200 return true ;
1201}
1202
1203bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
1204 wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask,
1205 wxCoord xsrcMask, wxCoord ysrcMask )
1206{
1207 wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
1208 wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
1209 if ( logical_func == wxNO_OP )
1210 return TRUE ;
1211 if (xsrcMask == -1 && ysrcMask == -1)
1212 {
1213 xsrcMask = xsrc; ysrcMask = ysrc;
1214 }
20b69855 1215
68654a82
SC
1216 wxCoord yysrc = source->YLOG2DEVMAC(ysrc) ;
1217 wxCoord xxsrc = source->XLOG2DEVMAC(xsrc) ;
1218 wxCoord wwsrc = source->XLOG2DEVREL(width ) ;
1219 wxCoord hhsrc = source->YLOG2DEVREL(height) ;
1220
1221 wxCoord yydest = YLOG2DEVMAC(ydest) ;
1222 wxCoord xxdest = XLOG2DEVMAC(xdest) ;
1223 wxCoord wwdest = XLOG2DEVREL(width ) ;
1224 wxCoord hhdest = YLOG2DEVREL(height) ;
1225
20b69855 1226 wxMemoryDC* memdc = dynamic_cast<wxMemoryDC*>(source) ;
a8f234d2 1227 if ( memdc && logical_func == wxCOPY )
613a24f7 1228 {
20b69855
SC
1229 wxBitmap blit = memdc->GetSelectedObject() ;
1230 wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") ) ;
1231
20b69855
SC
1232 wxCoord bmpwidth = blit.GetWidth();
1233 wxCoord bmpheight = blit.GetHeight();
1234
68654a82
SC
1235 if ( xxsrc != 0 || yysrc != 0 || bmpwidth != wwsrc || bmpheight != hhsrc )
1236 {
1237 wwsrc = wxMin( wwsrc , bmpwidth - xxsrc ) ;
1238 hhsrc = wxMin( hhsrc , bmpheight - yysrc ) ;
1239 if ( wwsrc > 0 && hhsrc > 0 )
1240 {
1241 if ( xxsrc >= 0 && yysrc >= 0 )
1242 {
1243 wxRect subrect( xxsrc, yysrc, wwsrc , hhsrc ) ;
1244 blit = blit.GetSubBitmap( subrect ) ;
1245 }
1246 else
1247 {
1248 // in this case we'd probably have to adjust the different coordinates, but
1249 // we have to find out proper contract first
1250 blit = wxNullBitmap ;
1251 }
1252 }
1253 else
1254 {
1255 blit = wxNullBitmap ;
1256 }
1257 }
1258 if ( blit.Ok() )
613a24f7 1259 {
b60f5ca5 1260 CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
68654a82
SC
1261 CGImageRef image = (CGImageRef)( blit.CGImageCreate() ) ;
1262 HIRect r = CGRectMake( xxdest , yydest , wwdest , hhdest ) ;
1263 HIViewDrawCGImage( cg , &r , image ) ;
1264 CGImageRelease( image ) ;
613a24f7 1265 }
20b69855
SC
1266
1267 }
1268 else
1269 {
68654a82 1270 /*
bc8f7aee 1271 CGContextRef cg = (wxMacCGContext*)(source->GetGraphicContext())->GetNativeContext() ;
68654a82
SC
1272 void *data = CGBitmapContextGetData( cg ) ;
1273 */
a8f234d2 1274 return FALSE ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
613a24f7 1275 }
613a24f7
SC
1276 return TRUE;
1277}
1278
613a24f7
SC
1279void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
1280 double angle)
1281{
1282 wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
1283
1284 if ( str.Length() == 0 )
1285 return ;
1286
08c8555e
SC
1287 if ( m_logicalFunction != wxCOPY )
1288 return ;
1289
20b69855
SC
1290 wxCHECK_RET( m_macATSUIStyle != NULL , wxT("No valid font set") ) ;
1291
613a24f7
SC
1292 OSStatus status = noErr ;
1293 ATSUTextLayout atsuLayout ;
1294 UniCharCount chars = str.Length() ;
1295 UniChar* ubuf = NULL ;
1296#if SIZEOF_WCHAR_T == 4
d9d488cf 1297 wxMBConvUTF16 converter ;
613a24f7
SC
1298#if wxUSE_UNICODE
1299 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
1300 ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
1301 converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ;
1302#else
1303 const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
1304 size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
1305 ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
1306 converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
1307#endif
1308 chars = unicharlen / 2 ;
1309#else
1310#if wxUSE_UNICODE
1311 ubuf = (UniChar*) str.wc_str() ;
1312#else
1313 wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
1314 chars = wxWcslen( wchar.data() ) ;
1315 ubuf = (UniChar*) wchar.data() ;
1316#endif
1317#endif
1318
1319 int drawX = XLOG2DEVMAC(x) ;
1320 int drawY = YLOG2DEVMAC(y) ;
1321
613a24f7
SC
1322 status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
1323 &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
1324
1325 wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") );
613a24f7 1326
28dd2407
SC
1327 status = ::ATSUSetTransientFontMatching( atsuLayout , true ) ;
1328 wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
613a24f7 1329
28dd2407 1330 int iAngle = int( angle );
613a24f7
SC
1331 if ( abs(iAngle) > 0 )
1332 {
1333 Fixed atsuAngle = IntToFixed( iAngle ) ;
1334 ATSUAttributeTag atsuTags[] =
1335 {
1336 kATSULineRotationTag ,
1337 } ;
1338 ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1339 {
1340 sizeof( Fixed ) ,
1341 } ;
1342 ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1343 {
1344 &atsuAngle ,
1345 } ;
1346 status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag),
1347 atsuTags, atsuSizes, atsuValues ) ;
1348 }
1349 {
b60f5ca5 1350 CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
613a24f7
SC
1351 ATSUAttributeTag atsuTags[] =
1352 {
1353 kATSUCGContextTag ,
1354 } ;
1355 ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1356 {
1357 sizeof( CGContextRef ) ,
1358 } ;
1359 ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1360 {
1361 &cgContext ,
1362 } ;
1363 status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag),
1364 atsuTags, atsuSizes, atsuValues ) ;
1365 }
1366
1367 ATSUTextMeasurement textBefore ;
1368 ATSUTextMeasurement textAfter ;
1369 ATSUTextMeasurement ascent ;
1370 ATSUTextMeasurement descent ;
1371
1372 status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
1373 &textBefore , &textAfter, &ascent , &descent );
1374 wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
1375
1376 Rect rect ;
1377
1378 if ( m_backgroundMode == wxSOLID )
1379 {
20b69855
SC
1380 wxGraphicPath* path = m_graphicContext->CreatePath() ;
1381 path->MoveToPoint(
613a24f7
SC
1382 drawX ,
1383 drawY ) ;
20b69855 1384 path->AddLineToPoint(
6cac01a6
RN
1385 (int) (drawX + sin(angle/RAD2DEG) * FixedToInt(ascent + descent)) ,
1386 (int) (drawY + cos(angle/RAD2DEG) * FixedToInt(ascent + descent)) ) ;
20b69855 1387 path->AddLineToPoint(
6cac01a6
RN
1388 (int) (drawX + sin(angle/RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle/RAD2DEG) * FixedToInt(textAfter)) ,
1389 (int) (drawY + cos(angle/RAD2DEG) * FixedToInt(ascent + descent) - sin(angle/RAD2DEG) * FixedToInt(textAfter)) ) ;
20b69855 1390 path->AddLineToPoint(
6cac01a6
RN
1391 (int) (drawX + cos(angle/RAD2DEG) * FixedToInt(textAfter)) ,
1392 (int) (drawY - sin(angle/RAD2DEG) * FixedToInt(textAfter)) ) ;
613a24f7 1393
20b69855
SC
1394 m_graphicContext->FillPath( path , m_textBackgroundColour ) ;
1395 delete path ;
613a24f7
SC
1396 }
1397
1398 drawX += (int)(sin(angle/RAD2DEG) * FixedToInt(ascent));
1399 drawY += (int)(cos(angle/RAD2DEG) * FixedToInt(ascent));
20b69855 1400
613a24f7
SC
1401 status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
1402 IntToFixed(drawX) , IntToFixed(drawY) , &rect );
1403 wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
1404
b60f5ca5
SC
1405 CGContextSaveGState(((wxMacCGContext*)(m_graphicContext))->GetNativeContext());
1406 CGContextTranslateCTM(((wxMacCGContext*)(m_graphicContext))->GetNativeContext(), drawX, drawY);
1407 CGContextScaleCTM(((wxMacCGContext*)(m_graphicContext))->GetNativeContext(), 1, -1);
613a24f7
SC
1408 status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
1409 IntToFixed(0) , IntToFixed(0) );
1410 wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") );
b60f5ca5 1411 CGContextRestoreGState( ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ) ;
613a24f7
SC
1412
1413 CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) );
1414 CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) );
1415
1416 ::ATSUDisposeTextLayout(atsuLayout);
1417#if SIZEOF_WCHAR_T == 4
1418 free( ubuf ) ;
1419#endif
613a24f7
SC
1420}
1421
1422void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
1423{
1424 wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
1425 DoDrawRotatedText( strtext , x , y , 0.0 ) ;
1426}
1427
1428bool wxDC::CanGetTextExtent() const
1429{
1430 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1431 return true ;
1432}
1433
1434void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
1435 wxCoord *descent, wxCoord *externalLeading ,
1436 wxFont *theFont ) const
1437{
1438 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1439 wxFont formerFont = m_font ;
1440 if ( theFont )
1441 {
1442 // work around the constness
1443 *((wxFont*)(&m_font)) = *theFont ;
20b69855 1444 MacInstallFont() ;
613a24f7
SC
1445 }
1446
613a24f7
SC
1447 if ( str.Length() == 0 )
1448 return ;
1449
20b69855
SC
1450 wxCHECK_RET( m_macATSUIStyle != NULL , wxT("No valid font set") ) ;
1451
613a24f7
SC
1452 OSStatus status = noErr ;
1453 ATSUTextLayout atsuLayout ;
1454 UniCharCount chars = str.Length() ;
1455 UniChar* ubuf = NULL ;
1456#if SIZEOF_WCHAR_T == 4
d9d488cf 1457 wxMBConvUTF16 converter ;
613a24f7
SC
1458#if wxUSE_UNICODE
1459 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
1460 ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
1461 converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ;
1462#else
1463 const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
1464 size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
1465 ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
1466 converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
1467#endif
1468 chars = unicharlen / 2 ;
1469#else
1470#if wxUSE_UNICODE
1471 ubuf = (UniChar*) str.wc_str() ;
1472#else
1473 wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
1474 chars = wxWcslen( wchar.data() ) ;
1475 ubuf = (UniChar*) wchar.data() ;
1476#endif
1477#endif
1478
613a24f7
SC
1479
1480 status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
1481 &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
1482
1483 wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") );
1484
1485 ATSUTextMeasurement textBefore ;
1486 ATSUTextMeasurement textAfter ;
1487 ATSUTextMeasurement textAscent ;
1488 ATSUTextMeasurement textDescent ;
1489
1490 status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
1491 &textBefore , &textAfter, &textAscent , &textDescent );
1492
1493 if ( height )
1494 *height = YDEV2LOGREL( FixedToInt(textAscent + textDescent) ) ;
1495 if ( descent )
1496 *descent =YDEV2LOGREL( FixedToInt(textDescent) );
1497 if ( externalLeading )
1498 *externalLeading = 0 ;
1499 if ( width )
1500 *width = XDEV2LOGREL( FixedToInt(textAfter - textBefore) ) ;
1501
1502 ::ATSUDisposeTextLayout(atsuLayout);
1503#if SIZEOF_WCHAR_T == 4
1504 free( ubuf ) ;
1505#endif
1506 if ( theFont )
1507 {
1508 // work around the constness
1509 *((wxFont*)(&m_font)) = formerFont ;
20b69855 1510 MacInstallFont() ;
613a24f7
SC
1511 }
1512}
1513
1514
1515bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
1516{
1517 wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
1518
1519 widths.Empty();
1520 widths.Add(0, text.Length());
1521
1522 if (text.Length() == 0)
1523 return false;
1524
764e6694
KO
1525 ATSUTextLayout atsuLayout ;
1526 UniCharCount chars = text.Length() ;
1527 UniChar* ubuf = NULL ;
1528#if SIZEOF_WCHAR_T == 4
d9d488cf 1529 wxMBConvUTF16 converter ;
764e6694
KO
1530#if wxUSE_UNICODE
1531 size_t unicharlen = converter.WC2MB( NULL , text.wc_str() , 0 ) ;
1532 ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
1533 converter.WC2MB( (char*) ubuf , text.wc_str(), unicharlen + 2 ) ;
1534#else
1535 const wxWCharBuffer wchar = text.wc_str( wxConvLocal ) ;
1536 size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
1537 ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
1538 converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
1539#endif
1540 chars = unicharlen / 2 ;
1541#else
1542#if wxUSE_UNICODE
1543 ubuf = (UniChar*) text.wc_str() ;
1544#else
1545 wxWCharBuffer wchar = text.wc_str( wxConvLocal ) ;
1546 chars = wxWcslen( wchar.data() ) ;
1547 ubuf = (UniChar*) wchar.data() ;
1548#endif
1549#endif
1550
1551 OSStatus status;
1552 status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
1553 &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
1554
1555 for ( int pos = 0; pos < chars; pos ++ ) {
1556 unsigned long actualNumberOfBounds = 0;
1557 ATSTrapezoid glyphBounds;
1558
1559 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1560 OSStatus result;
1561 result = ATSUGetGlyphBounds( atsuLayout, 0, 0, kATSUFromTextBeginning, pos + 1, kATSUseDeviceOrigins, 1, &glyphBounds, &actualNumberOfBounds );
1562 if (result != noErr || actualNumberOfBounds != 1 )
1563 {
1564 return false;
1565 }
1566
1567 widths[pos] = XDEV2LOGREL(FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x ));
1568 //unsigned char uch = s[i];
1569
1570 }
1571 ::ATSUDisposeTextLayout(atsuLayout);
1572 return true;
613a24f7
SC
1573}
1574
613a24f7
SC
1575wxCoord wxDC::GetCharWidth(void) const
1576{
1577 wxCoord width ;
1578 DoGetTextExtent(wxT("g") , &width , NULL , NULL , NULL , NULL ) ;
1579 return width ;
1580}
1581
1582wxCoord wxDC::GetCharHeight(void) const
1583{
1584 wxCoord height ;
1585 DoGetTextExtent(wxT("g") , NULL , &height , NULL , NULL , NULL ) ;
1586 return height ;
1587}
1588
1589void wxDC::Clear(void)
1590{
1591 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1592
1593 if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT)
1594 {
b014adcc 1595 HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
b60f5ca5 1596 CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
613a24f7
SC
1597 switch( m_backgroundBrush.MacGetBrushKind() )
1598 {
1599 case kwxMacBrushTheme :
1600 {
a63b4755
SC
1601#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1602 if ( HIThemeSetFill != 0 )
1603 {
67308c21 1604 HIThemeSetFill( m_backgroundBrush.MacGetTheme() , NULL , cg , kHIThemeOrientationNormal ) ;
a63b4755
SC
1605 CGContextFillRect(cg, rect);
1606
1607 }
1608 else
1609#endif
1610 {
1611 RGBColor color;
1612 GetThemeBrushAsColor( m_backgroundBrush.MacGetTheme() , 32, true, &color );
1613 CGContextSetRGBFillColor( cg , (float) color.red / 65536,
1614 (float) color.green / 65536, (float) color.blue / 65536, 1 );
1615 CGContextFillRect( cg, rect );
1616 }
1617 // reset to normal value
1618 RGBColor col = MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
1619 CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
613a24f7
SC
1620 }
1621 break ;
1622 case kwxMacBrushThemeBackground :
1623 {
a63b4755 1624 wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
b014adcc 1625#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1688bb38 1626 if ( UMAGetSystemVersion() >= 0x1030 )
b014adcc
SC
1627 {
1628 HIThemeBackgroundDrawInfo drawInfo ;
1629 drawInfo.version = 0 ;
1630 drawInfo.state = kThemeStateActive ;
1631 drawInfo.kind = m_backgroundBrush.MacGetThemeBackground(NULL) ;
1632 if ( drawInfo.kind == kThemeBackgroundMetal )
a63b4755 1633 HIThemeDrawBackground( &rect , &drawInfo, cg ,
b014adcc 1634 kHIThemeOrientationNormal) ;
a63b4755 1635 HIThemeApplyBackground( &rect , &drawInfo, cg ,
b014adcc
SC
1636 kHIThemeOrientationNormal) ;
1637 }
a63b4755 1638 else
b014adcc 1639#endif
a63b4755
SC
1640 {
1641 }
613a24f7
SC
1642 }
1643 break ;
1644 case kwxMacBrushColour :
1645 {
1646 RGBColor col = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()) ;
a63b4755
SC
1647 CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
1648 CGContextFillRect(cg, rect);
613a24f7
SC
1649
1650 // reset to normal value
1651 col = MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
a63b4755 1652 CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
613a24f7
SC
1653 }
1654 break ;
1655 }
1656 }
1657}
1658
1659void wxDC::MacInstallFont() const
1660{
1661 wxCHECK_RET(Ok(), wxT("Invalid DC"));
1662
20b69855 1663 if( m_macATSUIStyle )
613a24f7 1664 {
20b69855
SC
1665 ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle);
1666 m_macATSUIStyle = NULL ;
613a24f7 1667 }
20b69855 1668
68654a82 1669 if ( m_font.Ok() )
613a24f7 1670 {
68654a82
SC
1671 OSStatus status = noErr ;
1672 status = ATSUCreateAndCopyStyle( (ATSUStyle) m_font.MacGetATSUStyle() , (ATSUStyle*) &m_macATSUIStyle ) ;
1673 wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ;
20b69855 1674
68654a82
SC
1675 Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.MacGetFontSize()) ) ;
1676 RGBColor atsuColor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ;
1677 ATSUAttributeTag atsuTags[] =
1678 {
1679 kATSUSizeTag ,
1680 kATSUColorTag ,
1681 } ;
1682 ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1683 {
1684 sizeof( Fixed ) ,
1685 sizeof( RGBColor ) ,
1686 } ;
1687 // Boolean kTrue = true ;
1688 // Boolean kFalse = false ;
613a24f7 1689
68654a82
SC
1690 // ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
1691 ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
1692 {
1693 &atsuSize ,
1694 &atsuColor ,
1695 } ;
1696 status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
1697 atsuTags, atsuSizes, atsuValues);
1698
1699 wxASSERT_MSG( status == noErr , wxT("couldn't Modify ATSU style") ) ;
1700 }
613a24f7
SC
1701}
1702
1703// ---------------------------------------------------------------------------
1704// coordinates transformations
1705// ---------------------------------------------------------------------------
1706
1707wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
1708{
1709 return ((wxDC *)this)->XDEV2LOG(x);
1710}
1711
1712wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
1713{
1714 return ((wxDC *)this)->YDEV2LOG(y);
1715}
1716
1717wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
1718{
1719 return ((wxDC *)this)->XDEV2LOGREL(x);
1720}
1721
1722wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
1723{
1724 return ((wxDC *)this)->YDEV2LOGREL(y);
1725}
1726
1727wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
1728{
1729 return ((wxDC *)this)->XLOG2DEV(x);
1730}
1731
1732wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
1733{
1734 return ((wxDC *)this)->YLOG2DEV(y);
1735}
1736
1737wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
1738{
1739 return ((wxDC *)this)->XLOG2DEVREL(x);
1740}
1741
1742wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
1743{
1744 return ((wxDC *)this)->YLOG2DEVREL(y);
1745}
20b69855
SC
1746
1747#endif // wxMAC_USE_CORE_GRAPHICS
1748