]> git.saurik.com Git - wxWidgets.git/blame - src/common/dcgraph.cpp
Enable variadic macros for VC9 and later.
[wxWidgets.git] / src / common / dcgraph.cpp
CommitLineData
1b89a5cd 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/common/dcgraph.cpp
1b89a5cd
SC
3// Purpose: graphics context methods common to all platforms
4// Author: Stefan Csomor
5// Modified by:
6c0aace2 6// Created:
1b89a5cd
SC
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#if defined(__BORLANDC__)
16 #pragma hdrstop
17#endif
18
19#if wxUSE_GRAPHICS_CONTEXT
20
21#include "wx/graphics.h"
888dde65 22#include "wx/dcgraph.h"
1b89a5cd
SC
23
24#ifndef WX_PRECOMP
25 #include "wx/icon.h"
26 #include "wx/bitmap.h"
27 #include "wx/dcmemory.h"
28 #include "wx/region.h"
29#endif
30
b02d4340
VZ
31#include "wx/dcclient.h"
32
0b6a49c2 33#ifdef __WXOSX_OR_COCOA__
c933e267
SC
34#ifdef __WXOSX_IPHONE__
35 #include <CoreGraphics/CoreGraphics.h>
36#else
37 #include <ApplicationServices/ApplicationServices.h>
38#endif
fcaea2fa 39#endif
b02d4340 40
1b89a5cd
SC
41//-----------------------------------------------------------------------------
42// constants
43//-----------------------------------------------------------------------------
44
45static const double RAD2DEG = 180.0 / M_PI;
46
47//-----------------------------------------------------------------------------
48// Local functions
49//-----------------------------------------------------------------------------
50
51static inline double DegToRad(double deg)
52{
53 return (deg * M_PI) / 180.0;
54}
55
fec4e458 56static wxCompositionMode TranslateRasterOp(wxRasterOperationMode function)
bf02a7f9
SC
57{
58 switch ( function )
59 {
954c66fa
SC
60 case wxCOPY: // src
61 // since we are supporting alpha, _OVER is closer to the intention than _SOURCE
d13b34d3 62 // since the latter would overwrite even when alpha is not set to opaque
fec4e458
VZ
63 return wxCOMPOSITION_OVER;
64
bf02a7f9 65 case wxOR: // src OR dst
fec4e458
VZ
66 return wxCOMPOSITION_ADD;
67
bf02a7f9 68 case wxNO_OP: // dst
fec4e458
VZ
69 return wxCOMPOSITION_DEST; // ignore the source
70
bf02a7f9 71 case wxCLEAR: // 0
fec4e458
VZ
72 return wxCOMPOSITION_CLEAR;// clear dst
73
bf02a7f9 74 case wxXOR: // src XOR dst
fec4e458 75 return wxCOMPOSITION_XOR;
03647350 76
bf02a7f9
SC
77 case wxAND: // src AND dst
78 case wxAND_INVERT: // (NOT src) AND dst
79 case wxAND_REVERSE:// src AND (NOT dst)
80 case wxEQUIV: // (NOT src) XOR dst
81 case wxINVERT: // NOT dst
82 case wxNAND: // (NOT src) OR (NOT dst)
83 case wxNOR: // (NOT src) AND (NOT dst)
84 case wxOR_INVERT: // (NOT src) OR dst
85 case wxOR_REVERSE: // src OR (NOT dst)
86 case wxSET: // 1
87 case wxSRC_INVERT: // NOT src
fec4e458 88 break;
bf02a7f9 89 }
fec4e458
VZ
90
91 return wxCOMPOSITION_INVALID;
bf02a7f9
SC
92}
93
1b89a5cd
SC
94//-----------------------------------------------------------------------------
95// wxDC bridge class
96//-----------------------------------------------------------------------------
97
1b89a5cd 98IMPLEMENT_DYNAMIC_CLASS(wxGCDC, wxDC)
888dde65 99
7b1a66bb
RR
100wxGCDC::wxGCDC(const wxWindowDC& dc) :
101 wxDC( new wxGCDCImpl( this, dc ) )
888dde65 102{
888dde65
RR
103}
104
7b1a66bb
RR
105wxGCDC::wxGCDC( const wxMemoryDC& dc) :
106 wxDC( new wxGCDCImpl( this, dc ) )
888dde65 107{
888dde65 108}
1b89a5cd 109
6d0d8455 110#if wxUSE_PRINTING_ARCHITECTURE
b25c34aa
RR
111wxGCDC::wxGCDC( const wxPrinterDC& dc) :
112 wxDC( new wxGCDCImpl( this, dc ) )
113{
114}
6d0d8455 115#endif
b25c34aa 116
2d770c4f
VZ
117#if defined(__WXMSW__) && wxUSE_ENH_METAFILE
118wxGCDC::wxGCDC(const wxEnhMetaFileDC& dc)
119 : wxDC(new wxGCDCImpl(this, dc))
120{
121}
122#endif
123
932d0768
RD
124wxGCDC::wxGCDC(wxGraphicsContext* context) :
125 wxDC( new wxGCDCImpl( this ) )
126{
127 SetGraphicsContext(context);
128}
129
7b1a66bb
RR
130wxGCDC::wxGCDC() :
131 wxDC( new wxGCDCImpl( this ) )
1b89a5cd 132{
888dde65
RR
133}
134
9412ee9a
SC
135wxGCDC::~wxGCDC()
136{
137}
138
6c0e710f 139wxGraphicsContext* wxGCDC::GetGraphicsContext() const
888dde65
RR
140{
141 if (!m_pimpl) return NULL;
142 wxGCDCImpl *gc_impl = (wxGCDCImpl*) m_pimpl;
143 return gc_impl->GetGraphicsContext();
1b89a5cd
SC
144}
145
146void wxGCDC::SetGraphicsContext( wxGraphicsContext* ctx )
888dde65
RR
147{
148 if (!m_pimpl) return;
149 wxGCDCImpl *gc_impl = (wxGCDCImpl*) m_pimpl;
150 gc_impl->SetGraphicsContext( ctx );
151}
152
153IMPLEMENT_ABSTRACT_CLASS(wxGCDCImpl, wxDCImpl)
154
155wxGCDCImpl::wxGCDCImpl( wxDC *owner ) :
156 wxDCImpl( owner )
157{
158 Init();
159}
160
161void wxGCDCImpl::SetGraphicsContext( wxGraphicsContext* ctx )
6c0aace2 162{
1b89a5cd
SC
163 delete m_graphicContext;
164 m_graphicContext = ctx;
914fd3f1
SC
165 if ( m_graphicContext )
166 {
167 m_matrixOriginal = m_graphicContext->GetTransform();
168 m_ok = true;
fd791571
SC
169 // apply the stored transformations to the passed in context
170 ComputeScaleAndOrigin();
ad667945
SC
171 m_graphicContext->SetFont( m_font , m_textForegroundColour );
172 m_graphicContext->SetPen( m_pen );
173 m_graphicContext->SetBrush( m_brush);
914fd3f1 174 }
1b89a5cd
SC
175}
176
888dde65
RR
177wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxWindowDC& dc ) :
178 wxDCImpl( owner )
1b89a5cd
SC
179{
180 Init();
914fd3f1 181 SetGraphicsContext( wxGraphicsContext::Create(dc) );
7b98cf02 182 m_window = dc.GetWindow();
1b89a5cd
SC
183}
184
888dde65
RR
185wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxMemoryDC& dc ) :
186 wxDCImpl( owner )
773ccc31
SC
187{
188 Init();
c0e69d72 189 wxGraphicsContext* context;
c0e69d72 190 context = wxGraphicsContext::Create(dc);
c0e69d72 191 SetGraphicsContext( context );
773ccc31 192}
773ccc31 193
6d0d8455 194#if wxUSE_PRINTING_ARCHITECTURE
b25c34aa
RR
195wxGCDCImpl::wxGCDCImpl( wxDC *owner, const wxPrinterDC& dc ) :
196 wxDCImpl( owner )
197{
198 Init();
199 SetGraphicsContext( wxGraphicsContext::Create(dc) );
200}
6d0d8455 201#endif
b25c34aa 202
2d770c4f
VZ
203#if defined(__WXMSW__) && wxUSE_ENH_METAFILE
204wxGCDCImpl::wxGCDCImpl(wxDC *owner, const wxEnhMetaFileDC& dc)
205 : wxDCImpl(owner)
206{
207 Init();
208 SetGraphicsContext(wxGraphicsContext::Create(dc));
209}
210#endif
211
888dde65 212void wxGCDCImpl::Init()
1b89a5cd
SC
213{
214 m_ok = false;
215 m_colour = true;
216 m_mm_to_pix_x = mm2pt;
217 m_mm_to_pix_y = mm2pt;
218
219 m_pen = *wxBLACK_PEN;
220 m_font = *wxNORMAL_FONT;
221 m_brush = *wxWHITE_BRUSH;
222
d9edff06 223 m_graphicContext = wxGraphicsContext::Create();
4280b879 224 m_logicalFunctionSupported = true;
1b89a5cd
SC
225}
226
227
888dde65 228wxGCDCImpl::~wxGCDCImpl()
1b89a5cd
SC
229{
230 delete m_graphicContext;
231}
232
08de4403
VZ
233void wxGCDCImpl::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y,
234 bool useMask )
1b89a5cd 235{
888dde65
RR
236 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") );
237 wxCHECK_RET( bmp.IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") );
1b89a5cd 238
08de4403
VZ
239 int w = bmp.GetWidth();
240 int h = bmp.GetHeight();
f889bdb3
SC
241 if ( bmp.GetDepth() == 1 )
242 {
243 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
244 m_graphicContext->SetBrush( wxBrush( m_textBackgroundColour , wxSOLID ) );
08de4403 245 m_graphicContext->DrawRectangle( x, y, w, h );
f889bdb3 246 m_graphicContext->SetBrush( wxBrush( m_textForegroundColour , wxSOLID ) );
08de4403 247 m_graphicContext->DrawBitmap( bmp, x, y, w, h );
f889bdb3
SC
248 m_graphicContext->SetBrush( m_graphicContext->CreateBrush(m_brush));
249 m_graphicContext->SetPen( m_graphicContext->CreatePen(m_pen));
250 }
08de4403
VZ
251 else // not a monochrome bitmap, handle it normally
252 {
253 // make a copy in case we need to remove its mask, if we don't modify
254 // it the copy is cheap as bitmaps are reference-counted
255 wxBitmap bmpCopy(bmp);
256 if ( !useMask && bmp.GetMask() )
257 bmpCopy.SetMask(NULL);
258
259 m_graphicContext->DrawBitmap( bmpCopy, x, y, w, h );
260 }
1b89a5cd
SC
261}
262
888dde65 263void wxGCDCImpl::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
1b89a5cd 264{
888dde65
RR
265 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid DC") );
266 wxCHECK_RET( icon.IsOk(), wxT("wxGCDC(cg)::DoDrawIcon - invalid icon") );
1b89a5cd 267
1b89a5cd
SC
268 wxCoord w = icon.GetWidth();
269 wxCoord h = icon.GetHeight();
1b89a5cd 270
0ebd9515 271 m_graphicContext->DrawIcon( icon , x, y, w, h );
1b89a5cd
SC
272}
273
b02d4340 274bool wxGCDCImpl::StartDoc( const wxString& WXUNUSED(message) )
fcaea2fa 275{
26dfebbd 276 return true;
fcaea2fa
SC
277}
278
b02d4340 279void wxGCDCImpl::EndDoc()
fcaea2fa
SC
280{
281}
282
888dde65 283void wxGCDCImpl::StartPage()
fcaea2fa
SC
284{
285}
286
b02d4340 287void wxGCDCImpl::EndPage()
fcaea2fa
SC
288{
289}
b02d4340 290
888dde65 291void wxGCDCImpl::Flush()
fcaea2fa 292{
50211394 293 m_graphicContext->Flush();
fcaea2fa
SC
294}
295
888dde65 296void wxGCDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
1b89a5cd 297{
888dde65 298 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetClippingRegion - invalid DC") );
1b89a5cd 299
0ebd9515 300 m_graphicContext->Clip( x, y, w, h );
1b89a5cd
SC
301 if ( m_clipping )
302 {
0ebd9515
SC
303 m_clipX1 = wxMax( m_clipX1, x );
304 m_clipY1 = wxMax( m_clipY1, y );
305 m_clipX2 = wxMin( m_clipX2, (x + w) );
306 m_clipY2 = wxMin( m_clipY2, (y + h) );
1b89a5cd
SC
307 }
308 else
309 {
310 m_clipping = true;
311
0ebd9515
SC
312 m_clipX1 = x;
313 m_clipY1 = y;
314 m_clipX2 = x + w;
315 m_clipY2 = y + h;
1b89a5cd
SC
316 }
317}
318
fdaad94e 319void wxGCDCImpl::DoSetDeviceClippingRegion( const wxRegion &region )
1b89a5cd 320{
4bae004c 321 // region is in device coordinates
fdaad94e 322 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetDeviceClippingRegion - invalid DC") );
1b89a5cd
SC
323
324 if (region.Empty())
325 {
fcaea2fa 326 //DestroyClippingRegion();
1b89a5cd
SC
327 return;
328 }
329
4bae004c 330 wxRegion logRegion( region );
1b89a5cd 331 wxCoord x, y, w, h;
0ebd9515 332
4bae004c
SC
333 logRegion.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) );
334 logRegion.GetBox( x, y, w, h );
335
336 m_graphicContext->Clip( logRegion );
0ebd9515 337 if ( m_clipping )
1b89a5cd 338 {
0ebd9515
SC
339 m_clipX1 = wxMax( m_clipX1, x );
340 m_clipY1 = wxMax( m_clipY1, y );
341 m_clipX2 = wxMin( m_clipX2, (x + w) );
342 m_clipY2 = wxMin( m_clipY2, (y + h) );
1b89a5cd
SC
343 }
344 else
345 {
0ebd9515 346 m_clipping = true;
1b89a5cd 347
0ebd9515
SC
348 m_clipX1 = x;
349 m_clipY1 = y;
350 m_clipX2 = x + w;
351 m_clipY2 = y + h;
1b89a5cd
SC
352 }
353}
354
888dde65 355void wxGCDCImpl::DestroyClippingRegion()
1b89a5cd
SC
356{
357 m_graphicContext->ResetClip();
cb6e26b8 358 // currently the clip eg of a window extends to the area between the scrollbars
4c51a665 359 // so we must explicitly make sure it only covers the area we want it to draw
cb6e26b8 360 int width, height ;
888dde65 361 GetOwner()->GetSize( &width , &height ) ;
fcaea2fa 362 m_graphicContext->Clip( DeviceToLogicalX(0) , DeviceToLogicalY(0) , DeviceToLogicalXRel(width), DeviceToLogicalYRel(height) );
b02d4340 363
1b89a5cd
SC
364 m_graphicContext->SetPen( m_pen );
365 m_graphicContext->SetBrush( m_brush );
366
367 m_clipping = false;
368}
369
888dde65 370void wxGCDCImpl::DoGetSizeMM( int* width, int* height ) const
1b89a5cd
SC
371{
372 int w = 0, h = 0;
373
888dde65 374 GetOwner()->GetSize( &w, &h );
1b89a5cd
SC
375 if (width)
376 *width = long( double(w) / (m_scaleX * m_mm_to_pix_x) );
377 if (height)
378 *height = long( double(h) / (m_scaleY * m_mm_to_pix_y) );
379}
380
888dde65 381void wxGCDCImpl::SetTextForeground( const wxColour &col )
1b89a5cd 382{
888dde65 383 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextForeground - invalid DC") );
1b89a5cd 384
9c17ca3f
SC
385 // don't set m_textForegroundColour to an invalid colour as we'd crash
386 // later then (we use m_textForegroundColour.GetColor() without checking
387 // in a few places)
38274d1d 388 if ( col.IsOk() )
1b89a5cd
SC
389 {
390 m_textForegroundColour = col;
391 m_graphicContext->SetFont( m_font, m_textForegroundColour );
392 }
393}
394
888dde65 395void wxGCDCImpl::SetTextBackground( const wxColour &col )
1b89a5cd 396{
888dde65 397 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::SetTextBackground - invalid DC") );
1b89a5cd
SC
398
399 m_textBackgroundColour = col;
400}
401
89efaf2b 402void wxGCDCImpl::SetMapMode( wxMappingMode mode )
1b89a5cd
SC
403{
404 switch (mode)
405 {
406 case wxMM_TWIPS:
407 SetLogicalScale( twips2mm * m_mm_to_pix_x, twips2mm * m_mm_to_pix_y );
408 break;
409
410 case wxMM_POINTS:
411 SetLogicalScale( pt2mm * m_mm_to_pix_x, pt2mm * m_mm_to_pix_y );
412 break;
413
414 case wxMM_METRIC:
415 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
416 break;
417
418 case wxMM_LOMETRIC:
419 SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 );
420 break;
421
422 case wxMM_TEXT:
423 default:
424 SetLogicalScale( 1.0, 1.0 );
425 break;
426 }
427
428 ComputeScaleAndOrigin();
429}
430
888dde65 431wxSize wxGCDCImpl::GetPPI() const
1b89a5cd
SC
432{
433 return wxSize(72, 72);
434}
435
888dde65 436int wxGCDCImpl::GetDepth() const
1b89a5cd
SC
437{
438 return 32;
439}
440
888dde65 441void wxGCDCImpl::ComputeScaleAndOrigin()
b02d4340 442{
2dedef25 443 wxDCImpl::ComputeScaleAndOrigin();
1b89a5cd 444
fd791571
SC
445 if ( m_graphicContext )
446 {
447 m_matrixCurrent = m_graphicContext->CreateMatrix();
08de4403 448
fd791571 449 // the logical origin sets the origin to have new coordinates
08de4403 450 m_matrixCurrent.Translate( m_deviceOriginX - m_logicalOriginX * m_signX * m_scaleX,
d225267e 451 m_deviceOriginY-m_logicalOriginY * m_signY * m_scaleY);
08de4403 452
d225267e 453 m_matrixCurrent.Scale( m_scaleX * m_signX, m_scaleY * m_signY );
08de4403 454
fd791571
SC
455 m_graphicContext->SetTransform( m_matrixOriginal );
456 m_graphicContext->ConcatTransform( m_matrixCurrent );
457 }
1b89a5cd
SC
458}
459
888dde65 460void wxGCDCImpl::SetPalette( const wxPalette& WXUNUSED(palette) )
1b89a5cd
SC
461{
462
463}
464
888dde65 465void wxGCDCImpl::SetBackgroundMode( int mode )
1b89a5cd
SC
466{
467 m_backgroundMode = mode;
468}
469
888dde65 470void wxGCDCImpl::SetFont( const wxFont &font )
1b89a5cd
SC
471{
472 m_font = font;
473 if ( m_graphicContext )
474 {
475 wxFont f = font;
888dde65 476 if ( f.IsOk() )
0ebd9515 477 f.SetPointSize( /*LogicalToDeviceYRel*/(font.GetPointSize()));
1b89a5cd
SC
478 m_graphicContext->SetFont( f, m_textForegroundColour );
479 }
480}
481
888dde65 482void wxGCDCImpl::SetPen( const wxPen &pen )
1b89a5cd 483{
1b89a5cd
SC
484 m_pen = pen;
485 if ( m_graphicContext )
486 {
0ebd9515 487 m_graphicContext->SetPen( m_pen );
1b89a5cd
SC
488 }
489}
490
888dde65 491void wxGCDCImpl::SetBrush( const wxBrush &brush )
1b89a5cd 492{
1b89a5cd
SC
493 m_brush = brush;
494 if ( m_graphicContext )
495 {
0ebd9515 496 m_graphicContext->SetBrush( m_brush );
1b89a5cd
SC
497 }
498}
b02d4340 499
888dde65 500void wxGCDCImpl::SetBackground( const wxBrush &brush )
1b89a5cd 501{
1b89a5cd 502 m_backgroundBrush = brush;
888dde65 503 if (!m_backgroundBrush.IsOk())
1b89a5cd
SC
504 return;
505}
506
89efaf2b 507void wxGCDCImpl::SetLogicalFunction( wxRasterOperationMode function )
1b89a5cd 508{
1b89a5cd 509 m_logicalFunction = function;
03647350 510
fec4e458
VZ
511 wxCompositionMode mode = TranslateRasterOp( function );
512 m_logicalFunctionSupported = mode != wxCOMPOSITION_INVALID;
bf02a7f9
SC
513 if (m_logicalFunctionSupported)
514 m_logicalFunctionSupported = m_graphicContext->SetCompositionMode(mode);
03647350 515
584be856 516 if ( function == wxXOR )
bf02a7f9 517 m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE);
1b89a5cd 518 else
bf02a7f9 519 m_graphicContext->SetAntialiasMode(wxANTIALIAS_DEFAULT);
1b89a5cd
SC
520}
521
888dde65 522bool wxGCDCImpl::DoFloodFill(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
03647350 523 const wxColour& WXUNUSED(col),
89efaf2b 524 wxFloodFillStyle WXUNUSED(style))
1b89a5cd
SC
525{
526 return false;
527}
528
888dde65 529bool wxGCDCImpl::DoGetPixel( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxColour *WXUNUSED(col) ) const
1b89a5cd
SC
530{
531 // wxCHECK_MSG( 0 , false, wxT("wxGCDC(cg)::DoGetPixel - not implemented") );
532 return false;
533}
534
888dde65 535void wxGCDCImpl::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
1b89a5cd 536{
888dde65 537 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLine - invalid DC") );
1b89a5cd 538
4280b879 539 if ( !m_logicalFunctionSupported )
1b89a5cd 540 return;
1b89a5cd 541
0ebd9515 542 m_graphicContext->StrokeLine(x1,y1,x2,y2);
1b89a5cd
SC
543
544 CalcBoundingBox(x1, y1);
545 CalcBoundingBox(x2, y2);
546}
547
888dde65 548void wxGCDCImpl::DoCrossHair( wxCoord x, wxCoord y )
1b89a5cd 549{
888dde65 550 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoCrossHair - invalid DC") );
1b89a5cd 551
4280b879 552 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
553 return;
554
555 int w = 0, h = 0;
556
888dde65 557 GetOwner()->GetSize( &w, &h );
1b89a5cd 558
0ebd9515
SC
559 m_graphicContext->StrokeLine(0,y,w,y);
560 m_graphicContext->StrokeLine(x,0,x,h);
1b89a5cd 561
0ebd9515
SC
562 CalcBoundingBox(0, 0);
563 CalcBoundingBox(0+w, 0+h);
1b89a5cd
SC
564}
565
888dde65 566void wxGCDCImpl::DoDrawArc( wxCoord x1, wxCoord y1,
1b89a5cd
SC
567 wxCoord x2, wxCoord y2,
568 wxCoord xc, wxCoord yc )
569{
888dde65 570 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawArc - invalid DC") );
1b89a5cd 571
4280b879 572 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
573 return;
574
0ebd9515
SC
575 double dx = x1 - xc;
576 double dy = y1 - yc;
1b89a5cd
SC
577 double radius = sqrt((double)(dx * dx + dy * dy));
578 wxCoord rad = (wxCoord)radius;
579 double sa, ea;
0ebd9515 580 if (x1 == x2 && y1 == y2)
1b89a5cd
SC
581 {
582 sa = 0.0;
583 ea = 360.0;
584 }
585 else if (radius == 0.0)
586 {
587 sa = ea = 0.0;
588 }
589 else
590 {
0ebd9515
SC
591 sa = (x1 - xc == 0) ?
592 (y1 - yc < 0) ? 90.0 : -90.0 :
593 -atan2(double(y1 - yc), double(x1 - xc)) * RAD2DEG;
594 ea = (x2 - xc == 0) ?
595 (y2 - yc < 0) ? 90.0 : -90.0 :
596 -atan2(double(y2 - yc), double(x2 - xc)) * RAD2DEG;
1b89a5cd
SC
597 }
598
599 bool fill = m_brush.GetStyle() != wxTRANSPARENT;
600
a4e73390 601 wxGraphicsPath path = m_graphicContext->CreatePath();
1b89a5cd 602 if ( fill && ((x1!=x2)||(y1!=y2)) )
0ebd9515 603 path.MoveToPoint( xc, yc );
4bae004c
SC
604 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
605 // get clockwise angles
606 path.AddArc( xc, yc , rad , DegToRad(-sa) , DegToRad(-ea), false );
1b89a5cd 607 if ( fill && ((x1!=x2)||(y1!=y2)) )
0ebd9515 608 path.AddLineToPoint( xc, yc );
1b89a5cd 609 m_graphicContext->DrawPath(path);
1b89a5cd
SC
610}
611
888dde65 612void wxGCDCImpl::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
1b89a5cd
SC
613 double sa, double ea )
614{
888dde65 615 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipticArc - invalid DC") );
1b89a5cd 616
4280b879 617 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
618 return;
619
1b89a5cd 620 m_graphicContext->PushState();
d9485f89 621 m_graphicContext->Translate(x+w/2.0,y+h/2.0);
0ebd9515 622 wxDouble factor = ((wxDouble) w) / h;
1b89a5cd 623 m_graphicContext->Scale( factor , 1.0);
d9485f89 624
1b89a5cd
SC
625 // since these angles (ea,sa) are measured counter-clockwise, we invert them to
626 // get clockwise angles
fcaea2fa
SC
627 if ( m_brush.GetStyle() != wxTRANSPARENT )
628 {
629 wxGraphicsPath path = m_graphicContext->CreatePath();
630 path.MoveToPoint( 0, 0 );
47c1bb95 631 path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
fcaea2fa
SC
632 path.AddLineToPoint( 0, 0 );
633 m_graphicContext->FillPath( path );
634
635 path = m_graphicContext->CreatePath();
636 path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
fcaea2fa
SC
637 m_graphicContext->StrokePath( path );
638 }
639 else
640 {
641 wxGraphicsPath path = m_graphicContext->CreatePath();
47c1bb95
SC
642 path.AddArc( 0, 0, h/2.0 , DegToRad(-sa) , DegToRad(-ea), sa > ea );
643 m_graphicContext->DrawPath( path );
fcaea2fa
SC
644 }
645
1b89a5cd 646 m_graphicContext->PopState();
1b89a5cd
SC
647}
648
888dde65 649void wxGCDCImpl::DoDrawPoint( wxCoord x, wxCoord y )
1b89a5cd 650{
888dde65 651 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPoint - invalid DC") );
1b89a5cd
SC
652
653 DoDrawLine( x , y , x + 1 , y + 1 );
654}
655
888dde65 656void wxGCDCImpl::DoDrawLines(int n, wxPoint points[],
1b89a5cd
SC
657 wxCoord xoffset, wxCoord yoffset)
658{
888dde65 659 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawLines - invalid DC") );
1b89a5cd 660
4280b879 661 if ( !m_logicalFunctionSupported )
1b89a5cd 662 return;
1b89a5cd
SC
663
664 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n];
665 for( int i = 0; i < n; ++i)
666 {
0ebd9515
SC
667 pointsD[i].m_x = points[i].x + xoffset;
668 pointsD[i].m_y = points[i].y + yoffset;
1b89a5cd
SC
669 }
670
671 m_graphicContext->StrokeLines( n , pointsD);
672 delete[] pointsD;
673}
674
675#if wxUSE_SPLINES
888dde65 676void wxGCDCImpl::DoDrawSpline(const wxPointList *points)
1b89a5cd 677{
888dde65 678 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawSpline - invalid DC") );
1b89a5cd 679
4280b879 680 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
681 return;
682
a4e73390 683 wxGraphicsPath path = m_graphicContext->CreatePath();
1b89a5cd 684
b0d7707b 685 wxPointList::compatibility_iterator node = points->GetFirst();
cb98e78b 686 if ( !node )
1b89a5cd
SC
687 // empty list
688 return;
689
b0d7707b 690 wxPoint *p = node->GetData();
1b89a5cd
SC
691
692 wxCoord x1 = p->x;
693 wxCoord y1 = p->y;
694
695 node = node->GetNext();
b0d7707b 696 p = node->GetData();
1b89a5cd
SC
697
698 wxCoord x2 = p->x;
699 wxCoord y2 = p->y;
700 wxCoord cx1 = ( x1 + x2 ) / 2;
701 wxCoord cy1 = ( y1 + y2 ) / 2;
702
0ebd9515
SC
703 path.MoveToPoint( x1 , y1 );
704 path.AddLineToPoint( cx1 , cy1 );
01871bf6 705#if !wxUSE_STD_CONTAINERS
1b89a5cd
SC
706
707 while ((node = node->GetNext()) != NULL)
708#else
709
710 while ((node = node->GetNext()))
01871bf6 711#endif // !wxUSE_STD_CONTAINERS
1b89a5cd
SC
712
713 {
b0d7707b 714 p = node->GetData();
1b89a5cd
SC
715 x1 = x2;
716 y1 = y2;
717 x2 = p->x;
718 y2 = p->y;
719 wxCoord cx4 = (x1 + x2) / 2;
720 wxCoord cy4 = (y1 + y2) / 2;
721
0ebd9515 722 path.AddQuadCurveToPoint(x1 , y1 ,cx4 , cy4 );
1b89a5cd
SC
723
724 cx1 = cx4;
725 cy1 = cy4;
726 }
727
0ebd9515 728 path.AddLineToPoint( x2 , y2 );
1b89a5cd
SC
729
730 m_graphicContext->StrokePath( path );
1b89a5cd
SC
731}
732#endif // wxUSE_SPLINES
733
888dde65 734void wxGCDCImpl::DoDrawPolygon( int n, wxPoint points[],
89efaf2b
FM
735 wxCoord xoffset, wxCoord yoffset,
736 wxPolygonFillMode fillStyle )
1b89a5cd 737{
888dde65 738 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawPolygon - invalid DC") );
1b89a5cd
SC
739
740 if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) )
741 return;
4280b879 742 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
743 return;
744
745 bool closeIt = false;
746 if (points[n-1] != points[0])
747 closeIt = true;
748
749 wxPoint2DDouble* pointsD = new wxPoint2DDouble[n+(closeIt?1:0)];
750 for( int i = 0; i < n; ++i)
751 {
0ebd9515
SC
752 pointsD[i].m_x = points[i].x + xoffset;
753 pointsD[i].m_y = points[i].y + yoffset;
1b89a5cd
SC
754 }
755 if ( closeIt )
756 pointsD[n] = pointsD[0];
757
758 m_graphicContext->DrawLines( n+(closeIt?1:0) , pointsD, fillStyle);
759 delete[] pointsD;
760}
761
888dde65 762void wxGCDCImpl::DoDrawPolyPolygon(int n,
1b89a5cd
SC
763 int count[],
764 wxPoint points[],
765 wxCoord xoffset,
766 wxCoord yoffset,
89efaf2b 767 wxPolygonFillMode fillStyle)
1b89a5cd
SC
768{
769 wxASSERT(n > 1);
a4e73390 770 wxGraphicsPath path = m_graphicContext->CreatePath();
1b89a5cd
SC
771
772 int i = 0;
773 for ( int j = 0; j < n; ++j)
774 {
775 wxPoint start = points[i];
0ebd9515 776 path.MoveToPoint( start.x+ xoffset, start.y+ yoffset);
1b89a5cd
SC
777 ++i;
778 int l = count[j];
779 for ( int k = 1; k < l; ++k)
780 {
0ebd9515 781 path.AddLineToPoint( points[i].x+ xoffset, points[i].y+ yoffset);
1b89a5cd
SC
782 ++i;
783 }
784 // close the polygon
785 if ( start != points[i-1])
0ebd9515 786 path.AddLineToPoint( start.x+ xoffset, start.y+ yoffset);
1b89a5cd
SC
787 }
788 m_graphicContext->DrawPath( path , fillStyle);
1b89a5cd
SC
789}
790
888dde65 791void wxGCDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
1b89a5cd 792{
888dde65 793 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRectangle - invalid DC") );
1b89a5cd 794
4280b879 795 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
796 return;
797
1b89a5cd 798 // CMB: draw nothing if transformed w or h is 0
0ebd9515 799 if (w == 0 || h == 0)
1b89a5cd
SC
800 return;
801
5ebfdf41
SC
802 if ( m_graphicContext->ShouldOffset() )
803 {
804 // if we are offsetting the entire rectangle is moved 0.5, so the
805 // border line gets off by 1
0ebd9515
SC
806 w -= 1;
807 h -= 1;
5ebfdf41 808 }
0ebd9515 809 m_graphicContext->DrawRectangle(x,y,w,h);
1b89a5cd
SC
810}
811
888dde65 812void wxGCDCImpl::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
0ebd9515 813 wxCoord w, wxCoord h,
1b89a5cd
SC
814 double radius)
815{
888dde65 816 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRoundedRectangle - invalid DC") );
1b89a5cd 817
4280b879 818 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
819 return;
820
821 if (radius < 0.0)
0ebd9515 822 radius = - radius * ((w < h) ? w : h);
1b89a5cd
SC
823
824 // CMB: draw nothing if transformed w or h is 0
0ebd9515 825 if (w == 0 || h == 0)
1b89a5cd
SC
826 return;
827
d9485f89
RD
828 if ( m_graphicContext->ShouldOffset() )
829 {
830 // if we are offsetting the entire rectangle is moved 0.5, so the
831 // border line gets off by 1
832 w -= 1;
833 h -= 1;
834 }
0ebd9515 835 m_graphicContext->DrawRoundedRectangle( x,y,w,h,radius);
1b89a5cd
SC
836}
837
888dde65 838void wxGCDCImpl::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
1b89a5cd 839{
888dde65 840 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawEllipse - invalid DC") );
1b89a5cd 841
4280b879 842 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
843 return;
844
d9485f89
RD
845 if ( m_graphicContext->ShouldOffset() )
846 {
847 // if we are offsetting the entire rectangle is moved 0.5, so the
848 // border line gets off by 1
849 w -= 1;
850 h -= 1;
851 }
0ebd9515 852 m_graphicContext->DrawEllipse(x,y,w,h);
1b89a5cd
SC
853}
854
888dde65 855bool wxGCDCImpl::CanDrawBitmap() const
1b89a5cd
SC
856{
857 return true;
858}
859
888dde65 860bool wxGCDCImpl::DoBlit(
1b89a5cd 861 wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
03647350 862 wxDC *source, wxCoord xsrc, wxCoord ysrc,
89efaf2b 863 wxRasterOperationMode logical_func , bool useMask,
1b89a5cd
SC
864 wxCoord xsrcMask, wxCoord ysrcMask )
865{
e3b81044
VZ
866 return DoStretchBlit( xdest, ydest, width, height,
867 source, xsrc, ysrc, width, height, logical_func, useMask,
868 xsrcMask,ysrcMask );
869}
870
888dde65 871bool wxGCDCImpl::DoStretchBlit(
e3b81044
VZ
872 wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight,
873 wxDC *source, wxCoord xsrc, wxCoord ysrc, wxCoord srcWidth, wxCoord srcHeight,
89efaf2b 874 wxRasterOperationMode logical_func , bool useMask,
e3b81044
VZ
875 wxCoord xsrcMask, wxCoord ysrcMask )
876{
888dde65
RR
877 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid DC") );
878 wxCHECK_MSG( source->IsOk(), false, wxT("wxGCDC(cg)::DoStretchBlit - invalid source DC") );
6c0aace2 879
1b89a5cd
SC
880 if ( logical_func == wxNO_OP )
881 return true;
03647350 882
fec4e458
VZ
883 wxCompositionMode mode = TranslateRasterOp(logical_func);
884 if ( mode == wxCOMPOSITION_INVALID )
c64c9cd3 885 {
bf02a7f9 886 wxFAIL_MSG( wxT("Blitting is not supported with this logical operation.") );
c64c9cd3
KO
887 return false;
888 }
1b89a5cd 889
d0f93bc7
PC
890 wxRect subrect(source->LogicalToDeviceX(xsrc),
891 source->LogicalToDeviceY(ysrc),
892 source->LogicalToDeviceXRel(srcWidth),
893 source->LogicalToDeviceYRel(srcHeight));
be88fea9 894 const wxRect subrectOrig = subrect;
d0f93bc7
PC
895 // clip the subrect down to the size of the source DC
896 wxRect clip;
897 source->GetSize(&clip.width, &clip.height);
898 subrect.Intersect(clip);
899 if (subrect.width == 0)
900 return true;
901
bf02a7f9 902 bool retval = true;
03647350 903
bf02a7f9
SC
904 wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
905 if (m_graphicContext->SetCompositionMode(mode))
1b89a5cd 906 {
bf02a7f9
SC
907 wxAntialiasMode formerAa = m_graphicContext->GetAntialiasMode();
908 if (mode == wxCOMPOSITION_XOR)
909 {
910 m_graphicContext->SetAntialiasMode(wxANTIALIAS_NONE);
911 }
03647350 912
bf02a7f9
SC
913 if (xsrcMask == -1 && ysrcMask == -1)
914 {
915 xsrcMask = xsrc;
916 ysrcMask = ysrc;
917 }
1b89a5cd 918
bf02a7f9 919 wxBitmap blit = source->GetAsBitmap( &subrect );
6c0aace2 920
bf02a7f9
SC
921 if ( blit.IsOk() )
922 {
923 if ( !useMask && blit.GetMask() )
924 blit.SetMask(NULL);
08de4403 925
be88fea9
PC
926 double x = xdest;
927 double y = ydest;
928 double w = dstWidth;
929 double h = dstHeight;
930 // adjust dest rect if source rect is clipped
931 if (subrect.width != subrectOrig.width || subrect.height != subrectOrig.height)
932 {
933 x += (subrect.x - subrectOrig.x) / double(subrectOrig.width) * dstWidth;
934 y += (subrect.y - subrectOrig.y) / double(subrectOrig.height) * dstHeight;
935 w *= double(subrect.width) / subrectOrig.width;
936 h *= double(subrect.height) / subrectOrig.height;
937 }
938 m_graphicContext->DrawBitmap(blit, x, y, w, h);
bf02a7f9
SC
939 }
940 else
941 {
942 wxFAIL_MSG( wxT("Cannot Blit. Unable to get contents of DC as bitmap.") );
943 retval = false;
944 }
03647350 945
bf02a7f9
SC
946 if (mode == wxCOMPOSITION_XOR)
947 {
948 m_graphicContext->SetAntialiasMode(formerAa);
949 }
1b89a5cd 950 }
bf02a7f9
SC
951 // reset composition
952 m_graphicContext->SetCompositionMode(formerMode);
1b89a5cd 953
bf02a7f9 954 return retval;
1b89a5cd
SC
955}
956
888dde65 957void wxGCDCImpl::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
1b89a5cd
SC
958 double angle)
959{
888dde65 960 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") );
1b89a5cd 961
6636ef8d 962 if ( str.empty() )
1b89a5cd 963 return;
4280b879 964 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
965 return;
966
068eb463
SC
967 if ( m_backgroundMode == wxTRANSPARENT )
968 m_graphicContext->DrawText( str, x ,y , DegToRad(angle ));
969 else
970 m_graphicContext->DrawText( str, x ,y , DegToRad(angle ), m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) );
1b89a5cd
SC
971}
972
888dde65 973void wxGCDCImpl::DoDrawText(const wxString& str, wxCoord x, wxCoord y)
1b89a5cd 974{
a6afde63
SC
975 // For compatibility with other ports (notably wxGTK) and because it's
976 // genuinely useful, we allow passing multiline strings to DrawText().
977 // However there is no native OSX function to draw them directly so we
978 // instead reuse the generic DrawLabel() method to render them. Of course,
979 // DrawLabel() itself will call back to us but with single line strings
980 // only so there won't be any infinite recursion here.
981 if ( str.find('\n') != wxString::npos )
982 {
983 GetOwner()->DrawLabel(str, wxRect(x, y, 0, 0));
984 return;
985 }
986
08de4403 987 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawText - invalid DC") );
1b89a5cd 988
6636ef8d 989 if ( str.empty() )
1b89a5cd 990 return;
4280b879
SC
991
992 if ( !m_logicalFunctionSupported )
1b89a5cd
SC
993 return;
994
068eb463
SC
995 if ( m_backgroundMode == wxTRANSPARENT )
996 m_graphicContext->DrawText( str, x ,y);
997 else
998 m_graphicContext->DrawText( str, x ,y , m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) );
1b89a5cd
SC
999}
1000
888dde65 1001bool wxGCDCImpl::CanGetTextExtent() const
1b89a5cd 1002{
888dde65 1003 wxCHECK_MSG( IsOk(), false, wxT("wxGCDC(cg)::CanGetTextExtent - invalid DC") );
1b89a5cd
SC
1004
1005 return true;
1006}
1007
888dde65 1008void wxGCDCImpl::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
1b89a5cd 1009 wxCoord *descent, wxCoord *externalLeading ,
c94f845b 1010 const wxFont *theFont ) const
1b89a5cd 1011{
d9edff06 1012 wxCHECK_RET( m_graphicContext, wxT("wxGCDC(cg)::DoGetTextExtent - invalid DC") );
1b89a5cd
SC
1013
1014 if ( theFont )
1015 {
1016 m_graphicContext->SetFont( *theFont, m_textForegroundColour );
1017 }
1018
1019 wxDouble h , d , e , w;
1020
1021 m_graphicContext->GetTextExtent( str, &w, &h, &d, &e );
1022
1023 if ( height )
fcaea2fa 1024 *height = (wxCoord)(h+0.5);
1b89a5cd 1025 if ( descent )
fcaea2fa 1026 *descent = (wxCoord)(d+0.5);
1b89a5cd 1027 if ( externalLeading )
fcaea2fa 1028 *externalLeading = (wxCoord)(e+0.5);
1b89a5cd 1029 if ( width )
fcaea2fa 1030 *width = (wxCoord)(w+0.5);
1b89a5cd
SC
1031
1032 if ( theFont )
1033 {
1034 m_graphicContext->SetFont( m_font, m_textForegroundColour );
1035 }
1036}
1037
888dde65 1038bool wxGCDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
1b89a5cd 1039{
d9edff06 1040 wxCHECK_MSG( m_graphicContext, false, wxT("wxGCDC(cg)::DoGetPartialTextExtents - invalid DC") );
1b89a5cd
SC
1041 widths.Clear();
1042 widths.Add(0,text.Length());
1043 if ( text.IsEmpty() )
1044 return true;
1045
1046 wxArrayDouble widthsD;
1047
1048 m_graphicContext->GetPartialTextExtents( text, widthsD );
1049 for ( size_t i = 0; i < widths.GetCount(); ++i )
0ebd9515 1050 widths[i] = (wxCoord)(widthsD[i] + 0.5);
1b89a5cd
SC
1051
1052 return true;
1053}
1054
888dde65 1055wxCoord wxGCDCImpl::GetCharWidth(void) const
1b89a5cd
SC
1056{
1057 wxCoord width;
1058 DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
1059
1060 return width;
1061}
1062
888dde65 1063wxCoord wxGCDCImpl::GetCharHeight(void) const
1b89a5cd
SC
1064{
1065 wxCoord height;
1066 DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
1067
1068 return height;
1069}
1070
888dde65 1071void wxGCDCImpl::Clear(void)
1b89a5cd 1072{
888dde65 1073 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") );
1b89a5cd
SC
1074 // TODO better implementation / incorporate size info into wxGCDC or context
1075 m_graphicContext->SetBrush( m_backgroundBrush );
1076 wxPen p = *wxTRANSPARENT_PEN;
1077 m_graphicContext->SetPen( p );
954c66fa
SC
1078 wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
1079 m_graphicContext->SetCompositionMode(wxCOMPOSITION_SOURCE);
1b89a5cd 1080 DoDrawRectangle( 0, 0, 32000 , 32000 );
954c66fa 1081 m_graphicContext->SetCompositionMode(formerMode);
6c0aace2 1082 m_graphicContext->SetPen( m_pen );
1b89a5cd
SC
1083 m_graphicContext->SetBrush( m_brush );
1084}
1085
888dde65 1086void wxGCDCImpl::DoGetSize(int *width, int *height) const
1b89a5cd 1087{
1cc7d13a
SC
1088 wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoGetSize - invalid DC") );
1089 wxDouble w,h;
1090 m_graphicContext->GetSize( &w, &h );
1091 if ( height )
1092 *height = (int) (h+0.5);
1093 if ( width )
1094 *width = (int) (w+0.5);
1b89a5cd
SC
1095}
1096
888dde65 1097void wxGCDCImpl::DoGradientFillLinear(const wxRect& rect,
1b89a5cd
SC
1098 const wxColour& initialColour,
1099 const wxColour& destColour,
1100 wxDirection nDirection )
1101{
1102 wxPoint start;
1103 wxPoint end;
1104 switch( nDirection)
1105 {
1106 case wxWEST :
1107 start = rect.GetRightBottom();
1108 start.x++;
1109 end = rect.GetLeftBottom();
1110 break;
1111 case wxEAST :
1112 start = rect.GetLeftBottom();
1113 end = rect.GetRightBottom();
1114 end.x++;
1115 break;
1116 case wxNORTH :
1117 start = rect.GetLeftBottom();
1118 start.y++;
1119 end = rect.GetLeftTop();
1120 break;
1121 case wxSOUTH :
1122 start = rect.GetLeftTop();
1123 end = rect.GetLeftBottom();
1124 end.y++;
1125 break;
1126 default :
1127 break;
1128 }
1129
0ebd9515 1130 if (rect.width == 0 || rect.height == 0)
1b89a5cd
SC
1131 return;
1132
0ebd9515
SC
1133 m_graphicContext->SetBrush( m_graphicContext->CreateLinearGradientBrush(
1134 start.x,start.y,end.x,end.y, initialColour, destColour));
1b89a5cd 1135 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
0ebd9515 1136 m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height);
1b89a5cd 1137 m_graphicContext->SetPen(m_pen);
be6b31f3 1138 m_graphicContext->SetBrush(m_brush);
1b89a5cd
SC
1139}
1140
888dde65 1141void wxGCDCImpl::DoGradientFillConcentric(const wxRect& rect,
1b89a5cd
SC
1142 const wxColour& initialColour,
1143 const wxColour& destColour,
1144 const wxPoint& circleCenter)
1145{
1146 //Radius
1147 wxInt32 cx = rect.GetWidth() / 2;
1148 wxInt32 cy = rect.GetHeight() / 2;
1149 wxInt32 nRadius;
1150 if (cx < cy)
1151 nRadius = cx;
1152 else
1153 nRadius = cy;
1154
0ebd9515 1155 // make sure the background is filled (todo move into specific platform implementation ?)
1b89a5cd
SC
1156 m_graphicContext->SetPen(*wxTRANSPARENT_PEN);
1157 m_graphicContext->SetBrush( wxBrush( destColour) );
0ebd9515 1158 m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height);
1b89a5cd
SC
1159
1160 m_graphicContext->SetBrush( m_graphicContext->CreateRadialGradientBrush(
0ebd9515
SC
1161 rect.x+circleCenter.x,rect.y+circleCenter.y,
1162 rect.x+circleCenter.x,rect.y+circleCenter.y,
1163 nRadius,initialColour,destColour));
1b89a5cd 1164
0ebd9515 1165 m_graphicContext->DrawRectangle(rect.x,rect.y,rect.width,rect.height);
1b89a5cd 1166 m_graphicContext->SetPen(m_pen);
be6b31f3 1167 m_graphicContext->SetBrush(m_brush);
1b89a5cd
SC
1168}
1169
888dde65 1170void wxGCDCImpl::DoDrawCheckMark(wxCoord x, wxCoord y,
1b89a5cd
SC
1171 wxCoord width, wxCoord height)
1172{
888dde65 1173 wxDCImpl::DoDrawCheckMark(x,y,width,height);
1b89a5cd
SC
1174}
1175
53d4bdbc
VZ
1176#ifdef __WXMSW__
1177wxRect wxGCDCImpl::MSWApplyGDIPlusTransform(const wxRect& r) const
1178{
1179 wxGraphicsContext* const gc = GetGraphicsContext();
1180 wxCHECK_MSG( gc, r, wxT("Invalid wxGCDC") );
1181
1182 double x = 0,
1183 y = 0;
1184 gc->GetTransform().TransformPoint(&x, &y);
1185
1186 wxRect rect(r);
1187 rect.Offset(x, y);
1188
1189 return rect;
1190}
1191#endif // __WXMSW__
1192
1b89a5cd 1193#endif // wxUSE_GRAPHICS_CONTEXT