Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / include / wx / dc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dc.h
3 // Purpose: wxDC class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 05/25/99
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_DC_H_BASE_
12 #define _WX_DC_H_BASE_
13
14 // ----------------------------------------------------------------------------
15 // headers which we must include here
16 // ----------------------------------------------------------------------------
17
18 #include "wx/object.h" // the base class
19
20 #include "wx/intl.h" // for wxLayoutDirection
21 #include "wx/cursor.h" // we have member variables of these classes
22 #include "wx/font.h" // so we can't do without them
23 #include "wx/colour.h"
24 #include "wx/bitmap.h" // for wxNullBitmap
25 #include "wx/brush.h"
26 #include "wx/pen.h"
27 #include "wx/palette.h"
28 #include "wx/dynarray.h"
29 #include "wx/math.h"
30 #include "wx/image.h"
31 #include "wx/region.h"
32 #include "wx/affinematrix2d.h"
33
34 #define wxUSE_NEW_DC 1
35
36 class WXDLLIMPEXP_FWD_CORE wxDC;
37 class WXDLLIMPEXP_FWD_CORE wxClientDC;
38 class WXDLLIMPEXP_FWD_CORE wxPaintDC;
39 class WXDLLIMPEXP_FWD_CORE wxWindowDC;
40 class WXDLLIMPEXP_FWD_CORE wxScreenDC;
41 class WXDLLIMPEXP_FWD_CORE wxMemoryDC;
42 class WXDLLIMPEXP_FWD_CORE wxPrinterDC;
43 class WXDLLIMPEXP_FWD_CORE wxPrintData;
44
45 #if wxUSE_GRAPHICS_CONTEXT
46 class WXDLLIMPEXP_FWD_CORE wxGraphicsContext;
47 #endif
48
49 // Logical ops
50 enum wxRasterOperationMode
51 {
52 wxCLEAR, // 0
53 wxXOR, // src XOR dst
54 wxINVERT, // NOT dst
55 wxOR_REVERSE, // src OR (NOT dst)
56 wxAND_REVERSE, // src AND (NOT dst)
57 wxCOPY, // src
58 wxAND, // src AND dst
59 wxAND_INVERT, // (NOT src) AND dst
60 wxNO_OP, // dst
61 wxNOR, // (NOT src) AND (NOT dst)
62 wxEQUIV, // (NOT src) XOR dst
63 wxSRC_INVERT, // (NOT src)
64 wxOR_INVERT, // (NOT src) OR dst
65 wxNAND, // (NOT src) OR (NOT dst)
66 wxOR, // src OR dst
67 wxSET // 1
68 #if WXWIN_COMPATIBILITY_2_8
69 ,wxROP_BLACK = wxCLEAR,
70 wxBLIT_BLACKNESS = wxCLEAR,
71 wxROP_XORPEN = wxXOR,
72 wxBLIT_SRCINVERT = wxXOR,
73 wxROP_NOT = wxINVERT,
74 wxBLIT_DSTINVERT = wxINVERT,
75 wxROP_MERGEPENNOT = wxOR_REVERSE,
76 wxBLIT_00DD0228 = wxOR_REVERSE,
77 wxROP_MASKPENNOT = wxAND_REVERSE,
78 wxBLIT_SRCERASE = wxAND_REVERSE,
79 wxROP_COPYPEN = wxCOPY,
80 wxBLIT_SRCCOPY = wxCOPY,
81 wxROP_MASKPEN = wxAND,
82 wxBLIT_SRCAND = wxAND,
83 wxROP_MASKNOTPEN = wxAND_INVERT,
84 wxBLIT_00220326 = wxAND_INVERT,
85 wxROP_NOP = wxNO_OP,
86 wxBLIT_00AA0029 = wxNO_OP,
87 wxROP_NOTMERGEPEN = wxNOR,
88 wxBLIT_NOTSRCERASE = wxNOR,
89 wxROP_NOTXORPEN = wxEQUIV,
90 wxBLIT_00990066 = wxEQUIV,
91 wxROP_NOTCOPYPEN = wxSRC_INVERT,
92 wxBLIT_NOTSCRCOPY = wxSRC_INVERT,
93 wxROP_MERGENOTPEN = wxOR_INVERT,
94 wxBLIT_MERGEPAINT = wxOR_INVERT,
95 wxROP_NOTMASKPEN = wxNAND,
96 wxBLIT_007700E6 = wxNAND,
97 wxROP_MERGEPEN = wxOR,
98 wxBLIT_SRCPAINT = wxOR,
99 wxROP_WHITE = wxSET,
100 wxBLIT_WHITENESS = wxSET
101 #endif //WXWIN_COMPATIBILITY_2_8
102 };
103
104 // Flood styles
105 enum wxFloodFillStyle
106 {
107 wxFLOOD_SURFACE = 1,
108 wxFLOOD_BORDER
109 };
110
111 // Mapping modes
112 enum wxMappingMode
113 {
114 wxMM_TEXT = 1,
115 wxMM_METRIC,
116 wxMM_LOMETRIC,
117 wxMM_TWIPS,
118 wxMM_POINTS
119 };
120
121 // Description of text characteristics.
122 struct wxFontMetrics
123 {
124 wxFontMetrics()
125 {
126 height =
127 ascent =
128 descent =
129 internalLeading =
130 externalLeading =
131 averageWidth = 0;
132 }
133
134 int height, // Total character height.
135 ascent, // Part of the height above the baseline.
136 descent, // Part of the height below the baseline.
137 internalLeading, // Intra-line spacing.
138 externalLeading, // Inter-line spacing.
139 averageWidth; // Average font width, a.k.a. "x-width".
140 };
141
142 #if WXWIN_COMPATIBILITY_2_8
143
144 //-----------------------------------------------------------------------------
145 // wxDrawObject helper class
146 //-----------------------------------------------------------------------------
147
148 class WXDLLIMPEXP_CORE wxDrawObject
149 {
150 public:
151 wxDEPRECATED_CONSTRUCTOR(wxDrawObject)()
152 : m_isBBoxValid(false)
153 , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
154 { }
155
156 virtual ~wxDrawObject() { }
157
158 virtual void Draw(wxDC&) const { }
159
160 virtual void CalcBoundingBox(wxCoord x, wxCoord y)
161 {
162 if ( m_isBBoxValid )
163 {
164 if ( x < m_minX ) m_minX = x;
165 if ( y < m_minY ) m_minY = y;
166 if ( x > m_maxX ) m_maxX = x;
167 if ( y > m_maxY ) m_maxY = y;
168 }
169 else
170 {
171 m_isBBoxValid = true;
172
173 m_minX = x;
174 m_minY = y;
175 m_maxX = x;
176 m_maxY = y;
177 }
178 }
179
180 void ResetBoundingBox()
181 {
182 m_isBBoxValid = false;
183
184 m_minX = m_maxX = m_minY = m_maxY = 0;
185 }
186
187 // Get the final bounding box of the PostScript or Metafile picture.
188
189 wxCoord MinX() const { return m_minX; }
190 wxCoord MaxX() const { return m_maxX; }
191 wxCoord MinY() const { return m_minY; }
192 wxCoord MaxY() const { return m_maxY; }
193
194 //to define the type of object for derived objects
195 virtual int GetType()=0;
196
197 protected:
198 //for boundingbox calculation
199 bool m_isBBoxValid:1;
200 //for boundingbox calculation
201 wxCoord m_minX, m_minY, m_maxX, m_maxY;
202 };
203
204 #endif // WXWIN_COMPATIBILITY_2_8
205
206
207 //-----------------------------------------------------------------------------
208 // wxDCFactory
209 //-----------------------------------------------------------------------------
210
211 class WXDLLIMPEXP_FWD_CORE wxDCImpl;
212
213 class WXDLLIMPEXP_CORE wxDCFactory
214 {
215 public:
216 wxDCFactory() {}
217 virtual ~wxDCFactory() {}
218
219 virtual wxDCImpl* CreateWindowDC( wxWindowDC *owner, wxWindow *window ) = 0;
220 virtual wxDCImpl* CreateClientDC( wxClientDC *owner, wxWindow *window ) = 0;
221 virtual wxDCImpl* CreatePaintDC( wxPaintDC *owner, wxWindow *window ) = 0;
222 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner ) = 0;
223 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap ) = 0;
224 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc ) = 0;
225 virtual wxDCImpl* CreateScreenDC( wxScreenDC *owner ) = 0;
226 #if wxUSE_PRINTING_ARCHITECTURE
227 virtual wxDCImpl* CreatePrinterDC( wxPrinterDC *owner, const wxPrintData &data ) = 0;
228 #endif
229
230 static void Set(wxDCFactory *factory);
231 static wxDCFactory *Get();
232
233 private:
234 static wxDCFactory *m_factory;
235 };
236
237 //-----------------------------------------------------------------------------
238 // wxNativeDCFactory
239 //-----------------------------------------------------------------------------
240
241 class WXDLLIMPEXP_CORE wxNativeDCFactory: public wxDCFactory
242 {
243 public:
244 wxNativeDCFactory() {}
245
246 virtual wxDCImpl* CreateWindowDC( wxWindowDC *owner, wxWindow *window );
247 virtual wxDCImpl* CreateClientDC( wxClientDC *owner, wxWindow *window );
248 virtual wxDCImpl* CreatePaintDC( wxPaintDC *owner, wxWindow *window );
249 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner );
250 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap );
251 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc );
252 virtual wxDCImpl* CreateScreenDC( wxScreenDC *owner );
253 #if wxUSE_PRINTING_ARCHITECTURE
254 virtual wxDCImpl* CreatePrinterDC( wxPrinterDC *owner, const wxPrintData &data );
255 #endif
256 };
257
258 //-----------------------------------------------------------------------------
259 // wxDCImpl
260 //-----------------------------------------------------------------------------
261
262 class WXDLLIMPEXP_CORE wxDCImpl: public wxObject
263 {
264 public:
265 wxDCImpl( wxDC *owner );
266 virtual ~wxDCImpl();
267
268 wxDC *GetOwner() const { return m_owner; }
269
270 wxWindow* GetWindow() const { return m_window; }
271
272 virtual bool IsOk() const { return m_ok; }
273
274 // query capabilities
275
276 virtual bool CanDrawBitmap() const = 0;
277 virtual bool CanGetTextExtent() const = 0;
278
279 // get Cairo context
280 virtual void* GetCairoContext() const
281 {
282 return NULL;
283 }
284
285 virtual void* GetHandle() const { return NULL; }
286
287 // query dimension, colour deps, resolution
288
289 virtual void DoGetSize(int *width, int *height) const = 0;
290 void GetSize(int *width, int *height) const
291 {
292 DoGetSize(width, height);
293 return ;
294 }
295
296 wxSize GetSize() const
297 {
298 int w, h;
299 DoGetSize(&w, &h);
300 return wxSize(w, h);
301 }
302
303 virtual void DoGetSizeMM(int* width, int* height) const = 0;
304
305 virtual int GetDepth() const = 0;
306 virtual wxSize GetPPI() const = 0;
307
308 // Right-To-Left (RTL) modes
309
310 virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir)) { }
311 virtual wxLayoutDirection GetLayoutDirection() const { return wxLayout_Default; }
312
313 // page and document
314
315 virtual bool StartDoc(const wxString& WXUNUSED(message)) { return true; }
316 virtual void EndDoc() { }
317
318 virtual void StartPage() { }
319 virtual void EndPage() { }
320
321 // flushing the content of this dc immediately eg onto screen
322 virtual void Flush() { }
323
324 // bounding box
325
326 virtual void CalcBoundingBox(wxCoord x, wxCoord y)
327 {
328 if ( m_isBBoxValid )
329 {
330 if ( x < m_minX ) m_minX = x;
331 if ( y < m_minY ) m_minY = y;
332 if ( x > m_maxX ) m_maxX = x;
333 if ( y > m_maxY ) m_maxY = y;
334 }
335 else
336 {
337 m_isBBoxValid = true;
338
339 m_minX = x;
340 m_minY = y;
341 m_maxX = x;
342 m_maxY = y;
343 }
344 }
345 void ResetBoundingBox()
346 {
347 m_isBBoxValid = false;
348
349 m_minX = m_maxX = m_minY = m_maxY = 0;
350 }
351
352 wxCoord MinX() const { return m_minX; }
353 wxCoord MaxX() const { return m_maxX; }
354 wxCoord MinY() const { return m_minY; }
355 wxCoord MaxY() const { return m_maxY; }
356
357 // setters and getters
358
359 virtual void SetFont(const wxFont& font) = 0;
360 virtual const wxFont& GetFont() const { return m_font; }
361
362 virtual void SetPen(const wxPen& pen) = 0;
363 virtual const wxPen& GetPen() const { return m_pen; }
364
365 virtual void SetBrush(const wxBrush& brush) = 0;
366 virtual const wxBrush& GetBrush() const { return m_brush; }
367
368 virtual void SetBackground(const wxBrush& brush) = 0;
369 virtual const wxBrush& GetBackground() const { return m_backgroundBrush; }
370
371 virtual void SetBackgroundMode(int mode) = 0;
372 virtual int GetBackgroundMode() const { return m_backgroundMode; }
373
374 virtual void SetTextForeground(const wxColour& colour)
375 { m_textForegroundColour = colour; }
376 virtual const wxColour& GetTextForeground() const
377 { return m_textForegroundColour; }
378
379 virtual void SetTextBackground(const wxColour& colour)
380 { m_textBackgroundColour = colour; }
381 virtual const wxColour& GetTextBackground() const
382 { return m_textBackgroundColour; }
383
384 #if wxUSE_PALETTE
385 virtual void SetPalette(const wxPalette& palette) = 0;
386 #endif // wxUSE_PALETTE
387
388 // inherit the DC attributes (font and colours) from the given window
389 //
390 // this is called automatically when a window, client or paint DC is
391 // created
392 virtual void InheritAttributes(wxWindow *win);
393
394
395 // logical functions
396
397 virtual void SetLogicalFunction(wxRasterOperationMode function) = 0;
398 virtual wxRasterOperationMode GetLogicalFunction() const
399 { return m_logicalFunction; }
400
401 // text measurement
402
403 virtual wxCoord GetCharHeight() const = 0;
404 virtual wxCoord GetCharWidth() const = 0;
405
406 // The derived classes should really override DoGetFontMetrics() to return
407 // the correct values in the future but for now provide a default
408 // implementation in terms of DoGetTextExtent() to avoid breaking the
409 // compilation of all other ports as wxMSW is the only one to implement it.
410 virtual void DoGetFontMetrics(int *height,
411 int *ascent,
412 int *descent,
413 int *internalLeading,
414 int *externalLeading,
415 int *averageWidth) const;
416
417 virtual void DoGetTextExtent(const wxString& string,
418 wxCoord *x, wxCoord *y,
419 wxCoord *descent = NULL,
420 wxCoord *externalLeading = NULL,
421 const wxFont *theFont = NULL) const = 0;
422 virtual void GetMultiLineTextExtent(const wxString& string,
423 wxCoord *width,
424 wxCoord *height,
425 wxCoord *heightLine = NULL,
426 const wxFont *font = NULL) const;
427 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
428
429 // clearing
430
431 virtual void Clear() = 0;
432
433 // clipping
434
435 // Note that this pure virtual method has an implementation that updates
436 // the values returned by DoGetClippingBox() and so can be called from the
437 // derived class overridden version if it makes sense (i.e. if the clipping
438 // box coordinates are not already updated in some other way).
439 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
440 wxCoord w, wxCoord h) = 0;
441
442 // NB: this function works with device coordinates, not the logical ones!
443 virtual void DoSetDeviceClippingRegion(const wxRegion& region) = 0;
444
445 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
446 wxCoord *w, wxCoord *h) const
447 {
448 if ( x )
449 *x = m_clipX1;
450 if ( y )
451 *y = m_clipY1;
452 if ( w )
453 *w = m_clipX2 - m_clipX1;
454 if ( h )
455 *h = m_clipY2 - m_clipY1;
456 }
457
458 virtual void DestroyClippingRegion() { ResetClipping(); }
459
460
461 // coordinates conversions and transforms
462
463 virtual wxCoord DeviceToLogicalX(wxCoord x) const;
464 virtual wxCoord DeviceToLogicalY(wxCoord y) const;
465 virtual wxCoord DeviceToLogicalXRel(wxCoord x) const;
466 virtual wxCoord DeviceToLogicalYRel(wxCoord y) const;
467 virtual wxCoord LogicalToDeviceX(wxCoord x) const;
468 virtual wxCoord LogicalToDeviceY(wxCoord y) const;
469 virtual wxCoord LogicalToDeviceXRel(wxCoord x) const;
470 virtual wxCoord LogicalToDeviceYRel(wxCoord y) const;
471
472 virtual void SetMapMode(wxMappingMode mode);
473 virtual wxMappingMode GetMapMode() const { return m_mappingMode; }
474
475 virtual void SetUserScale(double x, double y);
476 virtual void GetUserScale(double *x, double *y) const
477 {
478 if ( x ) *x = m_userScaleX;
479 if ( y ) *y = m_userScaleY;
480 }
481
482 virtual void SetLogicalScale(double x, double y);
483 virtual void GetLogicalScale(double *x, double *y) const
484 {
485 if ( x ) *x = m_logicalScaleX;
486 if ( y ) *y = m_logicalScaleY;
487 }
488
489 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
490 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
491 {
492 if ( x ) *x = m_logicalOriginX;
493 if ( y ) *y = m_logicalOriginY;
494 }
495
496 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
497 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
498 {
499 if ( x ) *x = m_deviceOriginX;
500 if ( y ) *y = m_deviceOriginY;
501 }
502
503 #if wxUSE_DC_TRANSFORM_MATRIX
504 // Transform matrix support is not available in most ports right now
505 // (currently only wxMSW provides it) so do nothing in these methods by
506 // default.
507 virtual bool CanUseTransformMatrix() const
508 { return false; }
509 virtual bool SetTransformMatrix(const wxAffineMatrix2D& WXUNUSED(matrix))
510 { return false; }
511 virtual wxAffineMatrix2D GetTransformMatrix() const
512 { return wxAffineMatrix2D(); }
513 virtual void ResetTransformMatrix()
514 { }
515 #endif // wxUSE_DC_TRANSFORM_MATRIX
516
517 virtual void SetDeviceLocalOrigin( wxCoord x, wxCoord y );
518
519 virtual void ComputeScaleAndOrigin();
520
521 // this needs to overidden if the axis is inverted
522 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
523
524 virtual double GetContentScaleFactor() const { return m_contentScaleFactor; }
525
526 #ifdef __WXMSW__
527 // Native Windows functions using the underlying HDC don't honour GDI+
528 // transformations which may be applied to it. Using this function we can
529 // transform the coordinates manually before passing them to such functions
530 // (as in e.g. wxRendererMSW code). It doesn't do anything if this is not a
531 // wxGCDC.
532 virtual wxRect MSWApplyGDIPlusTransform(const wxRect& r) const
533 {
534 return r;
535 }
536 #endif // __WXMSW__
537
538
539 // ---------------------------------------------------------
540 // the actual drawing API
541
542 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
543 wxFloodFillStyle style = wxFLOOD_SURFACE) = 0;
544
545 virtual void DoGradientFillLinear(const wxRect& rect,
546 const wxColour& initialColour,
547 const wxColour& destColour,
548 wxDirection nDirection = wxEAST);
549
550 virtual void DoGradientFillConcentric(const wxRect& rect,
551 const wxColour& initialColour,
552 const wxColour& destColour,
553 const wxPoint& circleCenter);
554
555 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
556
557 virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
558 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
559
560 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
561 wxCoord x2, wxCoord y2,
562 wxCoord xc, wxCoord yc) = 0;
563 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
564 wxCoord width, wxCoord height);
565 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
566 double sa, double ea) = 0;
567
568 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0;
569 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
570 wxCoord width, wxCoord height,
571 double radius) = 0;
572 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
573 wxCoord width, wxCoord height) = 0;
574
575 virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
576
577 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
578 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
579 bool useMask = false) = 0;
580
581 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
582 virtual void DoDrawRotatedText(const wxString& text,
583 wxCoord x, wxCoord y, double angle) = 0;
584
585 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
586 wxCoord width, wxCoord height,
587 wxDC *source,
588 wxCoord xsrc, wxCoord ysrc,
589 wxRasterOperationMode rop = wxCOPY,
590 bool useMask = false,
591 wxCoord xsrcMask = wxDefaultCoord,
592 wxCoord ysrcMask = wxDefaultCoord) = 0;
593
594 virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
595 wxCoord dstWidth, wxCoord dstHeight,
596 wxDC *source,
597 wxCoord xsrc, wxCoord ysrc,
598 wxCoord srcWidth, wxCoord srcHeight,
599 wxRasterOperationMode rop = wxCOPY,
600 bool useMask = false,
601 wxCoord xsrcMask = wxDefaultCoord,
602 wxCoord ysrcMask = wxDefaultCoord);
603
604 virtual wxBitmap DoGetAsBitmap(const wxRect *WXUNUSED(subrect)) const
605 { return wxNullBitmap; }
606
607
608 virtual void DoDrawLines(int n, const wxPoint points[],
609 wxCoord xoffset, wxCoord yoffset ) = 0;
610 virtual void DrawLines(const wxPointList *list,
611 wxCoord xoffset, wxCoord yoffset );
612
613 virtual void DoDrawPolygon(int n, const wxPoint points[],
614 wxCoord xoffset, wxCoord yoffset,
615 wxPolygonFillMode fillStyle = wxODDEVEN_RULE) = 0;
616 virtual void DoDrawPolyPolygon(int n, const int count[], const wxPoint points[],
617 wxCoord xoffset, wxCoord yoffset,
618 wxPolygonFillMode fillStyle);
619 void DrawPolygon(const wxPointList *list,
620 wxCoord xoffset, wxCoord yoffset,
621 wxPolygonFillMode fillStyle );
622
623
624 #if wxUSE_SPLINES
625 void DrawSpline(wxCoord x1, wxCoord y1,
626 wxCoord x2, wxCoord y2,
627 wxCoord x3, wxCoord y3);
628 void DrawSpline(int n, const wxPoint points[]);
629 void DrawSpline(const wxPointList *points) { DoDrawSpline(points); }
630
631 virtual void DoDrawSpline(const wxPointList *points);
632 #endif
633
634 // ---------------------------------------------------------
635 // wxMemoryDC Impl API
636
637 virtual void DoSelect(const wxBitmap& WXUNUSED(bmp))
638 { }
639
640 virtual const wxBitmap& GetSelectedBitmap() const
641 { return wxNullBitmap; }
642 virtual wxBitmap& GetSelectedBitmap()
643 { return wxNullBitmap; }
644
645 // ---------------------------------------------------------
646 // wxPrinterDC Impl API
647
648 virtual wxRect GetPaperRect() const
649 { int w = 0; int h = 0; DoGetSize( &w, &h ); return wxRect(0,0,w,h); }
650
651 virtual int GetResolution() const
652 { return -1; }
653
654 #if wxUSE_GRAPHICS_CONTEXT
655 virtual wxGraphicsContext* GetGraphicsContext() const
656 { return NULL; }
657 virtual void SetGraphicsContext( wxGraphicsContext* WXUNUSED(ctx) )
658 {}
659 #endif
660
661 private:
662 wxDC *m_owner;
663
664 protected:
665 // unset clipping variables (after clipping region was destroyed)
666 void ResetClipping()
667 {
668 m_clipping = false;
669
670 m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0;
671 }
672
673 #ifdef __WXWINCE__
674 //! Generic method to draw ellipses, circles and arcs with current pen and brush.
675 /*! \param x Upper left corner of bounding box.
676 * \param y Upper left corner of bounding box.
677 * \param w Width of bounding box.
678 * \param h Height of bounding box.
679 * \param sa Starting angle of arc
680 * (counterclockwise, start at 3 o'clock, 360 is full circle).
681 * \param ea Ending angle of arc.
682 * \param angle Rotation angle, the Arc will be rotated after
683 * calculating begin and end.
684 */
685 void DrawEllipticArcRot( wxCoord x, wxCoord y,
686 wxCoord width, wxCoord height,
687 double sa = 0, double ea = 0, double angle = 0 )
688 { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); }
689
690 void DrawEllipticArcRot( const wxPoint& pt,
691 const wxSize& sz,
692 double sa = 0, double ea = 0, double angle = 0 )
693 { DoDrawEllipticArcRot( pt.x, pt.y, sz.x, sz.y, sa, ea, angle ); }
694
695 void DrawEllipticArcRot( const wxRect& rect,
696 double sa = 0, double ea = 0, double angle = 0 )
697 { DoDrawEllipticArcRot( rect.x, rect.y, rect.width, rect.height, sa, ea, angle ); }
698
699 virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y,
700 wxCoord w, wxCoord h,
701 double sa = 0, double ea = 0, double angle = 0 );
702
703 //! Rotates points around center.
704 /*! This is a quite straight method, it calculates in pixels
705 * and so it produces rounding errors.
706 * \param points The points inside will be rotated.
707 * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle).
708 * \param center Center of rotation.
709 */
710 void Rotate( wxPointList* points, double angle, wxPoint center = wxPoint(0,0) );
711
712 // used by DrawEllipticArcRot
713 // Careful: wxList gets filled with points you have to delete later.
714 void CalculateEllipticPoints( wxPointList* points,
715 wxCoord xStart, wxCoord yStart,
716 wxCoord w, wxCoord h,
717 double sa, double ea );
718 #endif // __WXWINCE__
719
720 // returns adjustment factor for converting wxFont "point size"; in wx
721 // it is point size on screen and needs to be multiplied by this value
722 // for rendering on higher-resolution DCs such as printer ones
723 static float GetFontPointSizeAdjustment(float dpi);
724
725 // window on which the DC draws or NULL
726 wxWindow *m_window;
727
728 // flags
729 bool m_colour:1;
730 bool m_ok:1;
731 bool m_clipping:1;
732 bool m_isInteractive:1;
733 bool m_isBBoxValid:1;
734
735 // coordinate system variables
736
737 wxCoord m_logicalOriginX, m_logicalOriginY;
738 wxCoord m_deviceOriginX, m_deviceOriginY; // Usually 0,0, can be change by user
739
740 wxCoord m_deviceLocalOriginX, m_deviceLocalOriginY; // non-zero if native top-left corner
741 // is not at 0,0. This was the case under
742 // Mac's GrafPorts (coordinate system
743 // used toplevel window's origin) and
744 // e.g. for Postscript, where the native
745 // origin in the bottom left corner.
746 double m_logicalScaleX, m_logicalScaleY;
747 double m_userScaleX, m_userScaleY;
748 double m_scaleX, m_scaleY; // calculated from logical scale and user scale
749
750 int m_signX, m_signY; // Used by SetAxisOrientation() to invert the axes
751
752 double m_contentScaleFactor; // used by high resolution displays (retina)
753
754 // what is a mm on a screen you don't know the size of?
755 double m_mm_to_pix_x,
756 m_mm_to_pix_y;
757
758 // bounding and clipping boxes
759 wxCoord m_minX, m_minY, m_maxX, m_maxY;
760 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
761
762 wxRasterOperationMode m_logicalFunction;
763 int m_backgroundMode;
764 wxMappingMode m_mappingMode;
765
766 wxPen m_pen;
767 wxBrush m_brush;
768 wxBrush m_backgroundBrush;
769 wxColour m_textForegroundColour;
770 wxColour m_textBackgroundColour;
771 wxFont m_font;
772
773 #if wxUSE_PALETTE
774 wxPalette m_palette;
775 bool m_hasCustomPalette;
776 #endif // wxUSE_PALETTE
777
778 private:
779 DECLARE_ABSTRACT_CLASS(wxDCImpl)
780 };
781
782
783 class WXDLLIMPEXP_CORE wxDC : public wxObject
784 {
785 public:
786 // copy attributes (font, colours and writing direction) from another DC
787 void CopyAttributes(const wxDC& dc);
788
789 virtual ~wxDC() { delete m_pimpl; }
790
791 wxDCImpl *GetImpl()
792 { return m_pimpl; }
793 const wxDCImpl *GetImpl() const
794 { return m_pimpl; }
795
796 wxWindow *GetWindow() const
797 { return m_pimpl->GetWindow(); }
798
799 void *GetHandle() const
800 { return m_pimpl->GetHandle(); }
801
802 bool IsOk() const
803 { return m_pimpl && m_pimpl->IsOk(); }
804
805 // query capabilities
806
807 bool CanDrawBitmap() const
808 { return m_pimpl->CanDrawBitmap(); }
809 bool CanGetTextExtent() const
810 { return m_pimpl->CanGetTextExtent(); }
811
812 // query dimension, colour deps, resolution
813
814 void GetSize(int *width, int *height) const
815 { m_pimpl->DoGetSize(width, height); }
816 wxSize GetSize() const
817 { return m_pimpl->GetSize(); }
818
819 void GetSizeMM(int* width, int* height) const
820 { m_pimpl->DoGetSizeMM(width, height); }
821 wxSize GetSizeMM() const
822 {
823 int w, h;
824 m_pimpl->DoGetSizeMM(&w, &h);
825 return wxSize(w, h);
826 }
827
828 int GetDepth() const
829 { return m_pimpl->GetDepth(); }
830 wxSize GetPPI() const
831 { return m_pimpl->GetPPI(); }
832
833 virtual int GetResolution() const
834 { return m_pimpl->GetResolution(); }
835
836 double GetContentScaleFactor() const
837 { return m_pimpl->GetContentScaleFactor(); }
838
839 // Right-To-Left (RTL) modes
840
841 void SetLayoutDirection(wxLayoutDirection dir)
842 { m_pimpl->SetLayoutDirection( dir ); }
843 wxLayoutDirection GetLayoutDirection() const
844 { return m_pimpl->GetLayoutDirection(); }
845
846 // page and document
847
848 bool StartDoc(const wxString& message)
849 { return m_pimpl->StartDoc(message); }
850 void EndDoc()
851 { m_pimpl->EndDoc(); }
852
853 void StartPage()
854 { m_pimpl->StartPage(); }
855 void EndPage()
856 { m_pimpl->EndPage(); }
857
858 // bounding box
859
860 void CalcBoundingBox(wxCoord x, wxCoord y)
861 { m_pimpl->CalcBoundingBox(x,y); }
862 void ResetBoundingBox()
863 { m_pimpl->ResetBoundingBox(); }
864
865 wxCoord MinX() const
866 { return m_pimpl->MinX(); }
867 wxCoord MaxX() const
868 { return m_pimpl->MaxX(); }
869 wxCoord MinY() const
870 { return m_pimpl->MinY(); }
871 wxCoord MaxY() const
872 { return m_pimpl->MaxY(); }
873
874 // setters and getters
875
876 void SetFont(const wxFont& font)
877 { m_pimpl->SetFont( font ); }
878 const wxFont& GetFont() const
879 { return m_pimpl->GetFont(); }
880
881 void SetPen(const wxPen& pen)
882 { m_pimpl->SetPen( pen ); }
883 const wxPen& GetPen() const
884 { return m_pimpl->GetPen(); }
885
886 void SetBrush(const wxBrush& brush)
887 { m_pimpl->SetBrush( brush ); }
888 const wxBrush& GetBrush() const
889 { return m_pimpl->GetBrush(); }
890
891 void SetBackground(const wxBrush& brush)
892 { m_pimpl->SetBackground( brush ); }
893 const wxBrush& GetBackground() const
894 { return m_pimpl->GetBackground(); }
895
896 void SetBackgroundMode(int mode)
897 { m_pimpl->SetBackgroundMode( mode ); }
898 int GetBackgroundMode() const
899 { return m_pimpl->GetBackgroundMode(); }
900
901 void SetTextForeground(const wxColour& colour)
902 { m_pimpl->SetTextForeground(colour); }
903 const wxColour& GetTextForeground() const
904 { return m_pimpl->GetTextForeground(); }
905
906 void SetTextBackground(const wxColour& colour)
907 { m_pimpl->SetTextBackground(colour); }
908 const wxColour& GetTextBackground() const
909 { return m_pimpl->GetTextBackground(); }
910
911 #if wxUSE_PALETTE
912 void SetPalette(const wxPalette& palette)
913 { m_pimpl->SetPalette(palette); }
914 #endif // wxUSE_PALETTE
915
916 // logical functions
917
918 void SetLogicalFunction(wxRasterOperationMode function)
919 { m_pimpl->SetLogicalFunction(function); }
920 wxRasterOperationMode GetLogicalFunction() const
921 { return m_pimpl->GetLogicalFunction(); }
922
923 // text measurement
924
925 wxCoord GetCharHeight() const
926 { return m_pimpl->GetCharHeight(); }
927 wxCoord GetCharWidth() const
928 { return m_pimpl->GetCharWidth(); }
929
930 wxFontMetrics GetFontMetrics() const
931 {
932 wxFontMetrics fm;
933 m_pimpl->DoGetFontMetrics(&fm.height, &fm.ascent, &fm.descent,
934 &fm.internalLeading, &fm.externalLeading,
935 &fm.averageWidth);
936 return fm;
937 }
938
939 void GetTextExtent(const wxString& string,
940 wxCoord *x, wxCoord *y,
941 wxCoord *descent = NULL,
942 wxCoord *externalLeading = NULL,
943 const wxFont *theFont = NULL) const
944 { m_pimpl->DoGetTextExtent(string, x, y, descent, externalLeading, theFont); }
945
946 wxSize GetTextExtent(const wxString& string) const
947 {
948 wxCoord w, h;
949 m_pimpl->DoGetTextExtent(string, &w, &h);
950 return wxSize(w, h);
951 }
952
953 void GetMultiLineTextExtent(const wxString& string,
954 wxCoord *width,
955 wxCoord *height,
956 wxCoord *heightLine = NULL,
957 const wxFont *font = NULL) const
958 { m_pimpl->GetMultiLineTextExtent( string, width, height, heightLine, font ); }
959
960 wxSize GetMultiLineTextExtent(const wxString& string) const
961 {
962 wxCoord w, h;
963 m_pimpl->GetMultiLineTextExtent(string, &w, &h);
964 return wxSize(w, h);
965 }
966
967 bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
968 { return m_pimpl->DoGetPartialTextExtents(text, widths); }
969
970 // clearing
971
972 void Clear()
973 { m_pimpl->Clear(); }
974
975 // clipping
976
977 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
978 { m_pimpl->DoSetClippingRegion(x, y, width, height); }
979 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
980 { m_pimpl->DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); }
981 void SetClippingRegion(const wxRect& rect)
982 { m_pimpl->DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
983
984 // unlike the functions above, the coordinates of the region used in this
985 // one are in device coordinates, not the logical ones
986 void SetDeviceClippingRegion(const wxRegion& region)
987 { m_pimpl->DoSetDeviceClippingRegion(region); }
988
989 // this function is deprecated because its name is confusing: you may
990 // expect it to work with logical coordinates but, in fact, it does exactly
991 // the same thing as SetDeviceClippingRegion()
992 //
993 // please review the code using it and either replace it with calls to
994 // SetDeviceClippingRegion() or correct it if it was [wrongly] passing
995 // logical coordinates to this function
996 wxDEPRECATED_INLINE(void SetClippingRegion(const wxRegion& region),
997 SetDeviceClippingRegion(region); )
998
999 void DestroyClippingRegion()
1000 { m_pimpl->DestroyClippingRegion(); }
1001
1002 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
1003 { m_pimpl->DoGetClippingBox(x, y, w, h); }
1004 void GetClippingBox(wxRect& rect) const
1005 { m_pimpl->DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); }
1006
1007 // coordinates conversions and transforms
1008
1009 wxCoord DeviceToLogicalX(wxCoord x) const
1010 { return m_pimpl->DeviceToLogicalX(x); }
1011 wxCoord DeviceToLogicalY(wxCoord y) const
1012 { return m_pimpl->DeviceToLogicalY(y); }
1013 wxCoord DeviceToLogicalXRel(wxCoord x) const
1014 { return m_pimpl->DeviceToLogicalXRel(x); }
1015 wxCoord DeviceToLogicalYRel(wxCoord y) const
1016 { return m_pimpl->DeviceToLogicalYRel(y); }
1017 wxCoord LogicalToDeviceX(wxCoord x) const
1018 { return m_pimpl->LogicalToDeviceX(x); }
1019 wxCoord LogicalToDeviceY(wxCoord y) const
1020 { return m_pimpl->LogicalToDeviceY(y); }
1021 wxCoord LogicalToDeviceXRel(wxCoord x) const
1022 { return m_pimpl->LogicalToDeviceXRel(x); }
1023 wxCoord LogicalToDeviceYRel(wxCoord y) const
1024 { return m_pimpl->LogicalToDeviceYRel(y); }
1025
1026 void SetMapMode(wxMappingMode mode)
1027 { m_pimpl->SetMapMode(mode); }
1028 wxMappingMode GetMapMode() const
1029 { return m_pimpl->GetMapMode(); }
1030
1031 void SetUserScale(double x, double y)
1032 { m_pimpl->SetUserScale(x,y); }
1033 void GetUserScale(double *x, double *y) const
1034 { m_pimpl->GetUserScale( x, y ); }
1035
1036 void SetLogicalScale(double x, double y)
1037 { m_pimpl->SetLogicalScale( x, y ); }
1038 void GetLogicalScale(double *x, double *y) const
1039 { m_pimpl->GetLogicalScale( x, y ); }
1040
1041 void SetLogicalOrigin(wxCoord x, wxCoord y)
1042 { m_pimpl->SetLogicalOrigin(x,y); }
1043 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const
1044 { m_pimpl->DoGetLogicalOrigin(x, y); }
1045 wxPoint GetLogicalOrigin() const
1046 { wxCoord x, y; m_pimpl->DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
1047
1048 void SetDeviceOrigin(wxCoord x, wxCoord y)
1049 { m_pimpl->SetDeviceOrigin( x, y); }
1050 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const
1051 { m_pimpl->DoGetDeviceOrigin(x, y); }
1052 wxPoint GetDeviceOrigin() const
1053 { wxCoord x, y; m_pimpl->DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
1054
1055 void SetAxisOrientation(bool xLeftRight, bool yBottomUp)
1056 { m_pimpl->SetAxisOrientation(xLeftRight, yBottomUp); }
1057
1058 #if wxUSE_DC_TRANSFORM_MATRIX
1059 bool CanUseTransformMatrix() const
1060 { return m_pimpl->CanUseTransformMatrix(); }
1061
1062 bool SetTransformMatrix(const wxAffineMatrix2D &matrix)
1063 { return m_pimpl->SetTransformMatrix(matrix); }
1064
1065 wxAffineMatrix2D GetTransformMatrix() const
1066 { return m_pimpl->GetTransformMatrix(); }
1067
1068 void ResetTransformMatrix()
1069 { m_pimpl->ResetTransformMatrix(); }
1070 #endif // wxUSE_DC_TRANSFORM_MATRIX
1071
1072 // mostly internal
1073 void SetDeviceLocalOrigin( wxCoord x, wxCoord y )
1074 { m_pimpl->SetDeviceLocalOrigin( x, y ); }
1075
1076
1077 // -----------------------------------------------
1078 // the actual drawing API
1079
1080 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col,
1081 wxFloodFillStyle style = wxFLOOD_SURFACE)
1082 { return m_pimpl->DoFloodFill(x, y, col, style); }
1083 bool FloodFill(const wxPoint& pt, const wxColour& col,
1084 wxFloodFillStyle style = wxFLOOD_SURFACE)
1085 { return m_pimpl->DoFloodFill(pt.x, pt.y, col, style); }
1086
1087 // fill the area specified by rect with a radial gradient, starting from
1088 // initialColour in the centre of the cercle and fading to destColour.
1089 void GradientFillConcentric(const wxRect& rect,
1090 const wxColour& initialColour,
1091 const wxColour& destColour)
1092 { m_pimpl->DoGradientFillConcentric( rect, initialColour, destColour,
1093 wxPoint(rect.GetWidth() / 2,
1094 rect.GetHeight() / 2)); }
1095
1096 void GradientFillConcentric(const wxRect& rect,
1097 const wxColour& initialColour,
1098 const wxColour& destColour,
1099 const wxPoint& circleCenter)
1100 { m_pimpl->DoGradientFillConcentric(rect, initialColour, destColour, circleCenter); }
1101
1102 // fill the area specified by rect with a linear gradient
1103 void GradientFillLinear(const wxRect& rect,
1104 const wxColour& initialColour,
1105 const wxColour& destColour,
1106 wxDirection nDirection = wxEAST)
1107 { m_pimpl->DoGradientFillLinear(rect, initialColour, destColour, nDirection); }
1108
1109 bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const
1110 { return m_pimpl->DoGetPixel(x, y, col); }
1111 bool GetPixel(const wxPoint& pt, wxColour *col) const
1112 { return m_pimpl->DoGetPixel(pt.x, pt.y, col); }
1113
1114 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
1115 { m_pimpl->DoDrawLine(x1, y1, x2, y2); }
1116 void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
1117 { m_pimpl->DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
1118
1119 void CrossHair(wxCoord x, wxCoord y)
1120 { m_pimpl->DoCrossHair(x, y); }
1121 void CrossHair(const wxPoint& pt)
1122 { m_pimpl->DoCrossHair(pt.x, pt.y); }
1123
1124 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
1125 wxCoord xc, wxCoord yc)
1126 { m_pimpl->DoDrawArc(x1, y1, x2, y2, xc, yc); }
1127 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
1128 { m_pimpl->DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
1129
1130 void DrawCheckMark(wxCoord x, wxCoord y,
1131 wxCoord width, wxCoord height)
1132 { m_pimpl->DoDrawCheckMark(x, y, width, height); }
1133 void DrawCheckMark(const wxRect& rect)
1134 { m_pimpl->DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
1135
1136 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
1137 double sa, double ea)
1138 { m_pimpl->DoDrawEllipticArc(x, y, w, h, sa, ea); }
1139 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
1140 double sa, double ea)
1141 { m_pimpl->DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
1142
1143 void DrawPoint(wxCoord x, wxCoord y)
1144 { m_pimpl->DoDrawPoint(x, y); }
1145 void DrawPoint(const wxPoint& pt)
1146 { m_pimpl->DoDrawPoint(pt.x, pt.y); }
1147
1148 void DrawLines(int n, const wxPoint points[],
1149 wxCoord xoffset = 0, wxCoord yoffset = 0)
1150 { m_pimpl->DoDrawLines(n, points, xoffset, yoffset); }
1151 void DrawLines(const wxPointList *list,
1152 wxCoord xoffset = 0, wxCoord yoffset = 0)
1153 { m_pimpl->DrawLines( list, xoffset, yoffset ); }
1154 #if WXWIN_COMPATIBILITY_2_8
1155 wxDEPRECATED( void DrawLines(const wxList *list,
1156 wxCoord xoffset = 0, wxCoord yoffset = 0) );
1157 #endif // WXWIN_COMPATIBILITY_2_8
1158
1159 void DrawPolygon(int n, const wxPoint points[],
1160 wxCoord xoffset = 0, wxCoord yoffset = 0,
1161 wxPolygonFillMode fillStyle = wxODDEVEN_RULE)
1162 { m_pimpl->DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
1163 void DrawPolygon(const wxPointList *list,
1164 wxCoord xoffset = 0, wxCoord yoffset = 0,
1165 wxPolygonFillMode fillStyle = wxODDEVEN_RULE)
1166 { m_pimpl->DrawPolygon( list, xoffset, yoffset, fillStyle ); }
1167 void DrawPolyPolygon(int n, const int count[], const wxPoint points[],
1168 wxCoord xoffset = 0, wxCoord yoffset = 0,
1169 wxPolygonFillMode fillStyle = wxODDEVEN_RULE)
1170 { m_pimpl->DoDrawPolyPolygon(n, count, points, xoffset, yoffset, fillStyle); }
1171 #if WXWIN_COMPATIBILITY_2_8
1172 wxDEPRECATED( void DrawPolygon(const wxList *list,
1173 wxCoord xoffset = 0, wxCoord yoffset = 0,
1174 wxPolygonFillMode fillStyle = wxODDEVEN_RULE) );
1175 #endif // WXWIN_COMPATIBILITY_2_8
1176
1177 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1178 { m_pimpl->DoDrawRectangle(x, y, width, height); }
1179 void DrawRectangle(const wxPoint& pt, const wxSize& sz)
1180 { m_pimpl->DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); }
1181 void DrawRectangle(const wxRect& rect)
1182 { m_pimpl->DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); }
1183
1184 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
1185 double radius)
1186 { m_pimpl->DoDrawRoundedRectangle(x, y, width, height, radius); }
1187 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
1188 double radius)
1189 { m_pimpl->DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
1190 void DrawRoundedRectangle(const wxRect& r, double radius)
1191 { m_pimpl->DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
1192
1193 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
1194 { m_pimpl->DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
1195 void DrawCircle(const wxPoint& pt, wxCoord radius)
1196 { m_pimpl->DoDrawEllipse(pt.x - radius, pt.y - radius, 2*radius, 2*radius); }
1197
1198 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1199 { m_pimpl->DoDrawEllipse(x, y, width, height); }
1200 void DrawEllipse(const wxPoint& pt, const wxSize& sz)
1201 { m_pimpl->DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); }
1202 void DrawEllipse(const wxRect& rect)
1203 { m_pimpl->DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); }
1204
1205 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
1206 { m_pimpl->DoDrawIcon(icon, x, y); }
1207 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
1208 { m_pimpl->DoDrawIcon(icon, pt.x, pt.y); }
1209
1210 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
1211 bool useMask = false)
1212 { m_pimpl->DoDrawBitmap(bmp, x, y, useMask); }
1213 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
1214 bool useMask = false)
1215 { m_pimpl->DoDrawBitmap(bmp, pt.x, pt.y, useMask); }
1216
1217 void DrawText(const wxString& text, wxCoord x, wxCoord y)
1218 { m_pimpl->DoDrawText(text, x, y); }
1219 void DrawText(const wxString& text, const wxPoint& pt)
1220 { m_pimpl->DoDrawText(text, pt.x, pt.y); }
1221
1222 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
1223 { m_pimpl->DoDrawRotatedText(text, x, y, angle); }
1224 void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)
1225 { m_pimpl->DoDrawRotatedText(text, pt.x, pt.y, angle); }
1226
1227 // this version puts both optional bitmap and the text into the given
1228 // rectangle and aligns is as specified by alignment parameter; it also
1229 // will emphasize the character with the given index if it is != -1 and
1230 // return the bounding rectangle if required
1231 void DrawLabel(const wxString& text,
1232 const wxBitmap& image,
1233 const wxRect& rect,
1234 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
1235 int indexAccel = -1,
1236 wxRect *rectBounding = NULL);
1237
1238 void DrawLabel(const wxString& text, const wxRect& rect,
1239 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
1240 int indexAccel = -1)
1241 { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); }
1242
1243 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
1244 wxDC *source, wxCoord xsrc, wxCoord ysrc,
1245 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
1246 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
1247 {
1248 return m_pimpl->DoBlit(xdest, ydest, width, height,
1249 source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
1250 }
1251 bool Blit(const wxPoint& destPt, const wxSize& sz,
1252 wxDC *source, const wxPoint& srcPt,
1253 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
1254 const wxPoint& srcPtMask = wxDefaultPosition)
1255 {
1256 return m_pimpl->DoBlit(destPt.x, destPt.y, sz.x, sz.y,
1257 source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
1258 }
1259
1260 bool StretchBlit(wxCoord dstX, wxCoord dstY,
1261 wxCoord dstWidth, wxCoord dstHeight,
1262 wxDC *source,
1263 wxCoord srcX, wxCoord srcY,
1264 wxCoord srcWidth, wxCoord srcHeight,
1265 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
1266 wxCoord srcMaskX = wxDefaultCoord, wxCoord srcMaskY = wxDefaultCoord)
1267 {
1268 return m_pimpl->DoStretchBlit(dstX, dstY, dstWidth, dstHeight,
1269 source, srcX, srcY, srcWidth, srcHeight, rop, useMask, srcMaskX, srcMaskY);
1270 }
1271 bool StretchBlit(const wxPoint& dstPt, const wxSize& dstSize,
1272 wxDC *source, const wxPoint& srcPt, const wxSize& srcSize,
1273 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
1274 const wxPoint& srcMaskPt = wxDefaultPosition)
1275 {
1276 return m_pimpl->DoStretchBlit(dstPt.x, dstPt.y, dstSize.x, dstSize.y,
1277 source, srcPt.x, srcPt.y, srcSize.x, srcSize.y, rop, useMask, srcMaskPt.x, srcMaskPt.y);
1278 }
1279
1280 wxBitmap GetAsBitmap(const wxRect *subrect = (const wxRect *) NULL) const
1281 {
1282 return m_pimpl->DoGetAsBitmap(subrect);
1283 }
1284
1285 #if wxUSE_SPLINES
1286 void DrawSpline(wxCoord x1, wxCoord y1,
1287 wxCoord x2, wxCoord y2,
1288 wxCoord x3, wxCoord y3)
1289 { m_pimpl->DrawSpline(x1,y1,x2,y2,x3,y3); }
1290 void DrawSpline(int n, const wxPoint points[])
1291 { m_pimpl->DrawSpline(n,points); }
1292 void DrawSpline(const wxPointList *points)
1293 { m_pimpl->DrawSpline(points); }
1294 #endif // wxUSE_SPLINES
1295
1296
1297 #if WXWIN_COMPATIBILITY_2_8
1298 // for compatibility with the old code when wxCoord was long everywhere
1299 wxDEPRECATED( void GetTextExtent(const wxString& string,
1300 long *x, long *y,
1301 long *descent = NULL,
1302 long *externalLeading = NULL,
1303 const wxFont *theFont = NULL) const );
1304 wxDEPRECATED( void GetLogicalOrigin(long *x, long *y) const );
1305 wxDEPRECATED( void GetDeviceOrigin(long *x, long *y) const );
1306 wxDEPRECATED( void GetClippingBox(long *x, long *y, long *w, long *h) const );
1307
1308 wxDEPRECATED( void DrawObject(wxDrawObject* drawobject) );
1309 #endif // WXWIN_COMPATIBILITY_2_8
1310
1311 #ifdef __WXMSW__
1312 // GetHDC() is the simplest way to retrieve an HDC From a wxDC but only
1313 // works if this wxDC is GDI-based and fails for GDI+ contexts (and
1314 // anything else without HDC, e.g. wxPostScriptDC)
1315 WXHDC GetHDC() const;
1316
1317 // don't use these methods manually, use GetTempHDC() instead
1318 virtual WXHDC AcquireHDC() { return GetHDC(); }
1319 virtual void ReleaseHDC(WXHDC WXUNUSED(hdc)) { }
1320
1321 // helper class holding the result of GetTempHDC() with std::auto_ptr<>-like
1322 // semantics, i.e. it is moved when copied
1323 class TempHDC
1324 {
1325 public:
1326 TempHDC(wxDC& dc)
1327 : m_dc(dc),
1328 m_hdc(dc.AcquireHDC())
1329 {
1330 }
1331
1332 TempHDC(const TempHDC& thdc)
1333 : m_dc(thdc.m_dc),
1334 m_hdc(thdc.m_hdc)
1335 {
1336 const_cast<TempHDC&>(thdc).m_hdc = 0;
1337 }
1338
1339 ~TempHDC()
1340 {
1341 if ( m_hdc )
1342 m_dc.ReleaseHDC(m_hdc);
1343 }
1344
1345 WXHDC GetHDC() const { return m_hdc; }
1346
1347 private:
1348 wxDC& m_dc;
1349 WXHDC m_hdc;
1350
1351 wxDECLARE_NO_ASSIGN_CLASS(TempHDC);
1352 };
1353
1354 // GetTempHDC() also works for wxGCDC (but still not for wxPostScriptDC &c)
1355 TempHDC GetTempHDC() { return TempHDC(*this); }
1356 #endif // __WXMSW__
1357
1358 #if wxUSE_GRAPHICS_CONTEXT
1359 virtual wxGraphicsContext* GetGraphicsContext() const
1360 {
1361 return m_pimpl->GetGraphicsContext();
1362 }
1363 virtual void SetGraphicsContext( wxGraphicsContext* ctx )
1364 {
1365 m_pimpl->SetGraphicsContext(ctx);
1366 }
1367 #endif
1368
1369 protected:
1370 // ctor takes ownership of the pointer
1371 wxDC(wxDCImpl *pimpl) : m_pimpl(pimpl) { }
1372
1373 wxDCImpl * const m_pimpl;
1374
1375 private:
1376 DECLARE_ABSTRACT_CLASS(wxDC)
1377 wxDECLARE_NO_COPY_CLASS(wxDC);
1378 };
1379
1380 // ----------------------------------------------------------------------------
1381 // helper class: you can use it to temporarily change the DC text colour and
1382 // restore it automatically when the object goes out of scope
1383 // ----------------------------------------------------------------------------
1384
1385 class WXDLLIMPEXP_CORE wxDCTextColourChanger
1386 {
1387 public:
1388 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
1389
1390 wxDCTextColourChanger(wxDC& dc, const wxColour& col) : m_dc(dc)
1391 {
1392 Set(col);
1393 }
1394
1395 ~wxDCTextColourChanger()
1396 {
1397 if ( m_colFgOld.IsOk() )
1398 m_dc.SetTextForeground(m_colFgOld);
1399 }
1400
1401 void Set(const wxColour& col)
1402 {
1403 if ( !m_colFgOld.IsOk() )
1404 m_colFgOld = m_dc.GetTextForeground();
1405 m_dc.SetTextForeground(col);
1406 }
1407
1408 private:
1409 wxDC& m_dc;
1410
1411 wxColour m_colFgOld;
1412
1413 wxDECLARE_NO_COPY_CLASS(wxDCTextColourChanger);
1414 };
1415
1416 // ----------------------------------------------------------------------------
1417 // helper class: you can use it to temporarily change the DC pen and
1418 // restore it automatically when the object goes out of scope
1419 // ----------------------------------------------------------------------------
1420
1421 class WXDLLIMPEXP_CORE wxDCPenChanger
1422 {
1423 public:
1424 wxDCPenChanger(wxDC& dc, const wxPen& pen) : m_dc(dc), m_penOld(dc.GetPen())
1425 {
1426 m_dc.SetPen(pen);
1427 }
1428
1429 ~wxDCPenChanger()
1430 {
1431 if ( m_penOld.IsOk() )
1432 m_dc.SetPen(m_penOld);
1433 }
1434
1435 private:
1436 wxDC& m_dc;
1437
1438 wxPen m_penOld;
1439
1440 wxDECLARE_NO_COPY_CLASS(wxDCPenChanger);
1441 };
1442
1443 // ----------------------------------------------------------------------------
1444 // helper class: you can use it to temporarily change the DC brush and
1445 // restore it automatically when the object goes out of scope
1446 // ----------------------------------------------------------------------------
1447
1448 class WXDLLIMPEXP_CORE wxDCBrushChanger
1449 {
1450 public:
1451 wxDCBrushChanger(wxDC& dc, const wxBrush& brush) : m_dc(dc), m_brushOld(dc.GetBrush())
1452 {
1453 m_dc.SetBrush(brush);
1454 }
1455
1456 ~wxDCBrushChanger()
1457 {
1458 if ( m_brushOld.IsOk() )
1459 m_dc.SetBrush(m_brushOld);
1460 }
1461
1462 private:
1463 wxDC& m_dc;
1464
1465 wxBrush m_brushOld;
1466
1467 wxDECLARE_NO_COPY_CLASS(wxDCBrushChanger);
1468 };
1469
1470 // ----------------------------------------------------------------------------
1471 // another small helper class: sets the clipping region in its ctor and
1472 // destroys it in the dtor
1473 // ----------------------------------------------------------------------------
1474
1475 class WXDLLIMPEXP_CORE wxDCClipper
1476 {
1477 public:
1478 wxDCClipper(wxDC& dc, const wxRegion& r) : m_dc(dc)
1479 { dc.SetClippingRegion(r.GetBox()); }
1480 wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc)
1481 { dc.SetClippingRegion(r.x, r.y, r.width, r.height); }
1482 wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc)
1483 { dc.SetClippingRegion(x, y, w, h); }
1484
1485 ~wxDCClipper() { m_dc.DestroyClippingRegion(); }
1486
1487 private:
1488 wxDC& m_dc;
1489
1490 wxDECLARE_NO_COPY_CLASS(wxDCClipper);
1491 };
1492
1493 // ----------------------------------------------------------------------------
1494 // helper class: you can use it to temporarily change the DC font and
1495 // restore it automatically when the object goes out of scope
1496 // ----------------------------------------------------------------------------
1497
1498 class WXDLLIMPEXP_CORE wxDCFontChanger
1499 {
1500 public:
1501 wxDCFontChanger(wxDC& dc)
1502 : m_dc(dc), m_fontOld()
1503 {
1504 }
1505
1506 wxDCFontChanger(wxDC& dc, const wxFont& font)
1507 : m_dc(dc), m_fontOld(dc.GetFont())
1508 {
1509 m_dc.SetFont(font);
1510 }
1511
1512 void Set(const wxFont& font)
1513 {
1514 if ( !m_fontOld.IsOk() )
1515 m_fontOld = m_dc.GetFont();
1516 m_dc.SetFont(font);
1517 }
1518
1519 ~wxDCFontChanger()
1520 {
1521 if ( m_fontOld.IsOk() )
1522 m_dc.SetFont(m_fontOld);
1523 }
1524
1525 private:
1526 wxDC& m_dc;
1527
1528 wxFont m_fontOld;
1529
1530 wxDECLARE_NO_COPY_CLASS(wxDCFontChanger);
1531 };
1532
1533
1534 #endif // _WX_DC_H_BASE_