remove Create{Window,Client,Paint}DC() methods without window parameter -- they don...
[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 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DC_H_BASE_
13 #define _WX_DC_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers which we must include here
17 // ----------------------------------------------------------------------------
18
19 #include "wx/object.h" // the base class
20
21 #include "wx/intl.h" // for wxLayoutDirection
22 #include "wx/cursor.h" // we have member variables of these classes
23 #include "wx/font.h" // so we can't do without them
24 #include "wx/colour.h"
25 #include "wx/bitmap.h" // for wxNullBitmap
26 #include "wx/brush.h"
27 #include "wx/pen.h"
28 #include "wx/palette.h"
29 #include "wx/dynarray.h"
30 #include "wx/math.h"
31 #include "wx/image.h"
32 #include "wx/cmndata.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 //-----------------------------------------------------------------------------
46 // wxDrawObject helper class
47 //-----------------------------------------------------------------------------
48
49 class WXDLLIMPEXP_CORE wxDrawObject
50 {
51 public:
52
53 wxDrawObject()
54 : m_isBBoxValid(false)
55 , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
56 { }
57
58 virtual ~wxDrawObject() { }
59
60 virtual void Draw(wxDC&) const { }
61
62 virtual void CalcBoundingBox(wxCoord x, wxCoord y)
63 {
64 if ( m_isBBoxValid )
65 {
66 if ( x < m_minX ) m_minX = x;
67 if ( y < m_minY ) m_minY = y;
68 if ( x > m_maxX ) m_maxX = x;
69 if ( y > m_maxY ) m_maxY = y;
70 }
71 else
72 {
73 m_isBBoxValid = true;
74
75 m_minX = x;
76 m_minY = y;
77 m_maxX = x;
78 m_maxY = y;
79 }
80 }
81
82 void ResetBoundingBox()
83 {
84 m_isBBoxValid = false;
85
86 m_minX = m_maxX = m_minY = m_maxY = 0;
87 }
88
89 // Get the final bounding box of the PostScript or Metafile picture.
90
91 wxCoord MinX() const { return m_minX; }
92 wxCoord MaxX() const { return m_maxX; }
93 wxCoord MinY() const { return m_minY; }
94 wxCoord MaxY() const { return m_maxY; }
95
96 //to define the type of object for derived objects
97 virtual int GetType()=0;
98
99 protected:
100 //for boundingbox calculation
101 bool m_isBBoxValid:1;
102 //for boundingbox calculation
103 wxCoord m_minX, m_minY, m_maxX, m_maxY;
104 };
105
106
107 //-----------------------------------------------------------------------------
108 // wxDCFactory
109 //-----------------------------------------------------------------------------
110
111 class WXDLLIMPEXP_FWD_CORE wxDCImpl;
112
113 class WXDLLIMPEXP_CORE wxDCFactory
114 {
115 public:
116 wxDCFactory() {}
117 virtual ~wxDCFactory() {}
118
119 virtual wxDCImpl* CreateWindowDC( wxWindowDC *owner, wxWindow *window ) = 0;
120 virtual wxDCImpl* CreateClientDC( wxClientDC *owner, wxWindow *window ) = 0;
121 virtual wxDCImpl* CreatePaintDC( wxPaintDC *owner, wxWindow *window ) = 0;
122 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner ) = 0;
123 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap ) = 0;
124 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc ) = 0;
125 virtual wxDCImpl* CreateScreenDC( wxScreenDC *owner ) = 0;
126 #if wxUSE_PRINTING_ARCHITECTURE
127 virtual wxDCImpl* CreatePrinterDC( wxPrinterDC *owner, const wxPrintData &data ) = 0;
128 #endif
129
130 static void Set(wxDCFactory *factory);
131 static wxDCFactory *Get();
132
133 private:
134 static wxDCFactory *m_factory;
135 };
136
137 //-----------------------------------------------------------------------------
138 // wxNativeDCFactory
139 //-----------------------------------------------------------------------------
140
141 class WXDLLIMPEXP_CORE wxNativeDCFactory: public wxDCFactory
142 {
143 public:
144 wxNativeDCFactory() {}
145
146 virtual wxDCImpl* CreateWindowDC( wxWindowDC *owner, wxWindow *window );
147 virtual wxDCImpl* CreateClientDC( wxClientDC *owner, wxWindow *window );
148 virtual wxDCImpl* CreatePaintDC( wxPaintDC *owner, wxWindow *window );
149 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner );
150 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxBitmap &bitmap );
151 virtual wxDCImpl* CreateMemoryDC( wxMemoryDC *owner, wxDC *dc );
152 virtual wxDCImpl* CreateScreenDC( wxScreenDC *owner );
153 #if wxUSE_PRINTING_ARCHITECTURE
154 virtual wxDCImpl* CreatePrinterDC( wxPrinterDC *owner, const wxPrintData &data );
155 #endif
156 };
157
158 //-----------------------------------------------------------------------------
159 // wxDCImpl
160 //-----------------------------------------------------------------------------
161
162 class WXDLLIMPEXP_CORE wxDCImpl: public wxObject
163 {
164 public:
165 wxDCImpl( wxDC *owner );
166 ~wxDCImpl();
167
168 wxDC *GetOwner() const { return m_owner; }
169
170 wxWindow* GetWindow() const { return m_window; }
171
172 virtual bool IsOk() const { return m_ok; }
173
174 // query capabilities
175
176 virtual bool CanDrawBitmap() const = 0;
177 virtual bool CanGetTextExtent() const = 0;
178
179 // get Cairo context
180 virtual void* GetCairoContext() const
181 {
182 return NULL;
183 }
184
185 // query dimension, colour deps, resolution
186
187 virtual void DoGetSize(int *width, int *height) const = 0;
188 void GetSize(int *width, int *height) const
189 {
190 DoGetSize(width, height);
191 return ;
192 }
193
194 wxSize GetSize() const
195 {
196 int w, h;
197 DoGetSize(&w, &h);
198 return wxSize(w, h);
199 }
200
201 virtual void DoGetSizeMM(int* width, int* height) const = 0;
202
203 virtual int GetDepth() const = 0;
204 virtual wxSize GetPPI() const = 0;
205
206 // Right-To-Left (RTL) modes
207
208 virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir)) { }
209 virtual wxLayoutDirection GetLayoutDirection() const { return wxLayout_Default; }
210
211 // page and document
212
213 virtual bool StartDoc(const wxString& WXUNUSED(message)) { return true; }
214 virtual void EndDoc() { }
215
216 virtual void StartPage() { }
217 virtual void EndPage() { }
218
219 // flushing the content of this dc immediately eg onto screen
220 virtual void Flush() { }
221
222 // bounding box
223
224 virtual void CalcBoundingBox(wxCoord x, wxCoord y)
225 {
226 if ( m_isBBoxValid )
227 {
228 if ( x < m_minX ) m_minX = x;
229 if ( y < m_minY ) m_minY = y;
230 if ( x > m_maxX ) m_maxX = x;
231 if ( y > m_maxY ) m_maxY = y;
232 }
233 else
234 {
235 m_isBBoxValid = true;
236
237 m_minX = x;
238 m_minY = y;
239 m_maxX = x;
240 m_maxY = y;
241 }
242 }
243 void ResetBoundingBox()
244 {
245 m_isBBoxValid = false;
246
247 m_minX = m_maxX = m_minY = m_maxY = 0;
248 }
249
250 wxCoord MinX() const { return m_minX; }
251 wxCoord MaxX() const { return m_maxX; }
252 wxCoord MinY() const { return m_minY; }
253 wxCoord MaxY() const { return m_maxY; }
254
255 // setters and getters
256
257 virtual void SetFont(const wxFont& font) = 0;
258 virtual const wxFont& GetFont() const { return m_font; }
259
260 virtual void SetPen(const wxPen& pen) = 0;
261 virtual const wxPen& GetPen() const { return m_pen; }
262
263 virtual void SetBrush(const wxBrush& brush) = 0;
264 virtual const wxBrush& GetBrush() const { return m_brush; }
265
266 virtual void SetBackground(const wxBrush& brush) = 0;
267 virtual const wxBrush& GetBackground() const { return m_backgroundBrush; }
268
269 virtual void SetBackgroundMode(int mode) = 0;
270 virtual int GetBackgroundMode() const { return m_backgroundMode; }
271
272 virtual void SetTextForeground(const wxColour& colour)
273 { m_textForegroundColour = colour; }
274 virtual const wxColour& GetTextForeground() const { return m_textForegroundColour; }
275
276 virtual void SetTextBackground(const wxColour& colour)
277 { m_textBackgroundColour = colour; }
278 virtual const wxColour& GetTextBackground() const { return m_textBackgroundColour; }
279
280 #if wxUSE_PALETTE
281 virtual void SetPalette(const wxPalette& palette) = 0;
282 #endif // wxUSE_PALETTE
283
284 // logical functions
285
286 virtual void SetLogicalFunction(int function) = 0;
287 virtual int GetLogicalFunction() const { return m_logicalFunction; }
288
289 // text measurement
290
291 virtual wxCoord GetCharHeight() const = 0;
292 virtual wxCoord GetCharWidth() const = 0;
293 virtual void DoGetTextExtent(const wxString& string,
294 wxCoord *x, wxCoord *y,
295 wxCoord *descent = NULL,
296 wxCoord *externalLeading = NULL,
297 const wxFont *theFont = NULL) const = 0;
298 virtual void GetMultiLineTextExtent(const wxString& string,
299 wxCoord *width,
300 wxCoord *height,
301 wxCoord *heightLine = NULL,
302 const wxFont *font = NULL) const;
303 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
304
305 // clearing
306
307 virtual void Clear() = 0;
308
309 // clipping
310
311 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
312 wxCoord width, wxCoord height) = 0;
313
314 // NB: this function works with device coordinates, not the logical ones!
315 virtual void DoSetDeviceClippingRegion(const wxRegion& region) = 0;
316
317 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
318 wxCoord *w, wxCoord *h) const
319 {
320 if ( x )
321 *x = m_clipX1;
322 if ( y )
323 *y = m_clipY1;
324 if ( w )
325 *w = m_clipX2 - m_clipX1;
326 if ( h )
327 *h = m_clipY2 - m_clipY1;
328 }
329
330 virtual void DestroyClippingRegion() { ResetClipping(); }
331
332
333 // coordinates conversions and transforms
334
335 virtual wxCoord DeviceToLogicalX(wxCoord x) const;
336 virtual wxCoord DeviceToLogicalY(wxCoord y) const;
337 virtual wxCoord DeviceToLogicalXRel(wxCoord x) const;
338 virtual wxCoord DeviceToLogicalYRel(wxCoord y) const;
339 virtual wxCoord LogicalToDeviceX(wxCoord x) const;
340 virtual wxCoord LogicalToDeviceY(wxCoord y) const;
341 virtual wxCoord LogicalToDeviceXRel(wxCoord x) const;
342 virtual wxCoord LogicalToDeviceYRel(wxCoord y) const;
343
344 virtual void SetMapMode(int mode);
345 virtual int GetMapMode() const { return m_mappingMode; }
346
347 virtual void SetUserScale(double x, double y);
348 virtual void GetUserScale(double *x, double *y) const
349 {
350 if ( x ) *x = m_userScaleX;
351 if ( y ) *y = m_userScaleY;
352 }
353
354 virtual void SetLogicalScale(double x, double y);
355 virtual void GetLogicalScale(double *x, double *y)
356 {
357 if ( x ) *x = m_logicalScaleX;
358 if ( y ) *y = m_logicalScaleY;
359 }
360
361 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
362 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
363 {
364 if ( x ) *x = m_logicalOriginX;
365 if ( y ) *y = m_logicalOriginY;
366 }
367
368 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
369 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
370 {
371 if ( x ) *x = m_deviceOriginX;
372 if ( y ) *y = m_deviceOriginY;
373 }
374
375 virtual void SetDeviceLocalOrigin( wxCoord x, wxCoord y );
376
377 virtual void ComputeScaleAndOrigin();
378
379 // this needs to overidden if the axis is inverted
380 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
381
382 // ---------------------------------------------------------
383 // the actual drawing API
384
385 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
386 int style = wxFLOOD_SURFACE) = 0;
387
388 virtual void DoGradientFillLinear(const wxRect& rect,
389 const wxColour& initialColour,
390 const wxColour& destColour,
391 wxDirection nDirection = wxEAST);
392
393 virtual void DoGradientFillConcentric(const wxRect& rect,
394 const wxColour& initialColour,
395 const wxColour& destColour,
396 const wxPoint& circleCenter);
397
398 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
399
400 virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
401 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
402
403 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
404 wxCoord x2, wxCoord y2,
405 wxCoord xc, wxCoord yc) = 0;
406 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
407 wxCoord width, wxCoord height);
408 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
409 double sa, double ea) = 0;
410
411 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0;
412 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
413 wxCoord width, wxCoord height,
414 double radius) = 0;
415 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
416 wxCoord width, wxCoord height) = 0;
417
418 virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
419
420 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
421 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
422 bool useMask = false) = 0;
423
424 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
425 virtual void DoDrawRotatedText(const wxString& text,
426 wxCoord x, wxCoord y, double angle) = 0;
427
428 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
429 wxCoord width, wxCoord height,
430 wxDC *source,
431 wxCoord xsrc, wxCoord ysrc,
432 int rop = wxCOPY,
433 bool useMask = false,
434 wxCoord xsrcMask = wxDefaultCoord,
435 wxCoord ysrcMask = wxDefaultCoord) = 0;
436
437 virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
438 wxCoord dstWidth, wxCoord dstHeight,
439 wxDC *source,
440 wxCoord xsrc, wxCoord ysrc,
441 wxCoord srcWidth, wxCoord srcHeight,
442 int rop = wxCOPY,
443 bool useMask = false,
444 wxCoord xsrcMask = wxDefaultCoord,
445 wxCoord ysrcMask = wxDefaultCoord);
446
447 virtual wxBitmap DoGetAsBitmap(const wxRect *WXUNUSED(subrect)) const
448 { return wxNullBitmap; }
449
450
451 virtual void DoDrawLines(int n, wxPoint points[],
452 wxCoord xoffset, wxCoord yoffset ) = 0;
453 virtual void DrawLines(const wxPointList *list,
454 wxCoord xoffset, wxCoord yoffset );
455
456 virtual void DoDrawPolygon(int n, wxPoint points[],
457 wxCoord xoffset, wxCoord yoffset,
458 int fillStyle = wxODDEVEN_RULE) = 0;
459 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
460 wxCoord xoffset, wxCoord yoffset,
461 int fillStyle);
462 void DrawPolygon(const wxPointList *list,
463 wxCoord xoffset, wxCoord yoffset,
464 int fillStyle );
465
466
467 #if wxUSE_SPLINES
468 void DrawSpline(wxCoord x1, wxCoord y1,
469 wxCoord x2, wxCoord y2,
470 wxCoord x3, wxCoord y3);
471 void DrawSpline(int n, wxPoint points[]);
472 void DrawSpline(const wxPointList *points) { DoDrawSpline(points); }
473
474 virtual void DoDrawSpline(const wxPointList *points);
475 #endif
476
477 // ---------------------------------------------------------
478 // wxMemoryDC Impl API
479
480 virtual void DoSelect(const wxBitmap& WXUNUSED(bmp))
481 { }
482
483 virtual const wxBitmap& GetSelectedBitmap() const
484 { return wxNullBitmap; }
485 virtual wxBitmap& GetSelectedBitmap()
486 { return wxNullBitmap; }
487
488 // ---------------------------------------------------------
489 // wxPrinterDC Impl API
490
491 virtual wxRect GetPaperRect()
492 { int w = 0; int h = 0; DoGetSize( &w, &h ); return wxRect(0,0,w,h); }
493
494 virtual int GetResolution()
495 { return -1; }
496
497 private:
498 wxDC *m_owner;
499
500 protected:
501 // unset clipping variables (after clipping region was destroyed)
502 void ResetClipping()
503 {
504 m_clipping = false;
505
506 m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0;
507 }
508
509 #ifdef __WXWINCE__
510 //! Generic method to draw ellipses, circles and arcs with current pen and brush.
511 /*! \param x Upper left corner of bounding box.
512 * \param y Upper left corner of bounding box.
513 * \param w Width of bounding box.
514 * \param h Height of bounding box.
515 * \param sa Starting angle of arc
516 * (counterclockwise, start at 3 o'clock, 360 is full circle).
517 * \param ea Ending angle of arc.
518 * \param angle Rotation angle, the Arc will be rotated after
519 * calculating begin and end.
520 */
521 void DrawEllipticArcRot( wxCoord x, wxCoord y,
522 wxCoord width, wxCoord height,
523 double sa = 0, double ea = 0, double angle = 0 )
524 { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); }
525
526 void DrawEllipticArcRot( const wxPoint& pt,
527 const wxSize& sz,
528 double sa = 0, double ea = 0, double angle = 0 )
529 { DoDrawEllipticArcRot( pt.x, pt.y, sz.x, sz.y, sa, ea, angle ); }
530
531 void DrawEllipticArcRot( const wxRect& rect,
532 double sa = 0, double ea = 0, double angle = 0 )
533 { DoDrawEllipticArcRot( rect.x, rect.y, rect.width, rect.height, sa, ea, angle ); }
534
535 virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y,
536 wxCoord w, wxCoord h,
537 double sa = 0, double ea = 0, double angle = 0 );
538
539 //! Rotates points around center.
540 /*! This is a quite straight method, it calculates in pixels
541 * and so it produces rounding errors.
542 * \param points The points inside will be rotated.
543 * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle).
544 * \param center Center of rotation.
545 */
546 void Rotate( wxPointList* points, double angle, wxPoint center = wxPoint(0,0) );
547
548 // used by DrawEllipticArcRot
549 // Careful: wxList gets filled with points you have to delete later.
550 void CalculateEllipticPoints( wxPointList* points,
551 wxCoord xStart, wxCoord yStart,
552 wxCoord w, wxCoord h,
553 double sa, double ea );
554 #endif // __WXWINCE__
555
556
557 // window on which the DC draws or NULL
558 wxWindow *m_window;
559
560 // flags
561 bool m_colour:1;
562 bool m_ok:1;
563 bool m_clipping:1;
564 bool m_isInteractive:1;
565 bool m_isBBoxValid:1;
566
567 // coordinate system variables
568
569 wxCoord m_logicalOriginX, m_logicalOriginY;
570 wxCoord m_deviceOriginX, m_deviceOriginY; // Usually 0,0, can be change by user
571
572 wxCoord m_deviceLocalOriginX, m_deviceLocalOriginY; // non-zero if native top-left corner
573 // is not at 0,0. This was the case under
574 // Mac's GrafPorts (coordinate system
575 // used toplevel window's origin) and
576 // e.g. for Postscript, where the native
577 // origin in the bottom left corner.
578 double m_logicalScaleX, m_logicalScaleY;
579 double m_userScaleX, m_userScaleY;
580 double m_scaleX, m_scaleY; // calculated from logical scale and user scale
581
582 int m_signX, m_signY; // Used by SetAxisOrientation() to invert the axes
583
584 // what is a mm on a screen you don't know the size of?
585 double m_mm_to_pix_x,
586 m_mm_to_pix_y;
587
588 // bounding and clipping boxes
589 wxCoord m_minX, m_minY, m_maxX, m_maxY;
590 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
591
592 int m_logicalFunction;
593 int m_backgroundMode;
594 int m_mappingMode;
595
596 wxPen m_pen;
597 wxBrush m_brush;
598 wxBrush m_backgroundBrush;
599 wxColour m_textForegroundColour;
600 wxColour m_textBackgroundColour;
601 wxFont m_font;
602
603 #if wxUSE_PALETTE
604 wxPalette m_palette;
605 bool m_hasCustomPalette;
606 #endif // wxUSE_PALETTE
607
608 private:
609 DECLARE_ABSTRACT_CLASS(wxDCImpl)
610 };
611
612
613 class WXDLLIMPEXP_CORE wxDC : public wxObject
614 {
615 public:
616 virtual ~wxDC() { delete m_pimpl; }
617
618 wxDCImpl *GetImpl()
619 { return m_pimpl; }
620 const wxDCImpl *GetImpl() const
621 { return m_pimpl; }
622
623 wxWindow *GetWindow() const
624 { return m_pimpl->GetWindow(); }
625
626 bool IsOk() const
627 { return m_pimpl && m_pimpl->IsOk(); }
628
629 // query capabilities
630
631 bool CanDrawBitmap() const
632 { return m_pimpl->CanDrawBitmap(); }
633 bool CanGetTextExtent() const
634 { return m_pimpl->CanGetTextExtent(); }
635
636 // query dimension, colour deps, resolution
637
638 void GetSize(int *width, int *height) const
639 { m_pimpl->DoGetSize(width, height); }
640 wxSize GetSize() const
641 { return m_pimpl->GetSize(); }
642
643 void GetSizeMM(int* width, int* height) const
644 { m_pimpl->DoGetSizeMM(width, height); }
645 wxSize GetSizeMM() const
646 {
647 int w, h;
648 m_pimpl->DoGetSizeMM(&w, &h);
649 return wxSize(w, h);
650 }
651
652 int GetDepth() const
653 { return m_pimpl->GetDepth(); }
654 wxSize GetPPI() const
655 { return m_pimpl->GetPPI(); }
656
657 virtual int GetResolution()
658 { return m_pimpl->GetResolution(); }
659
660 // Right-To-Left (RTL) modes
661
662 void SetLayoutDirection(wxLayoutDirection dir)
663 { m_pimpl->SetLayoutDirection( dir ); }
664 wxLayoutDirection GetLayoutDirection() const
665 { return m_pimpl->GetLayoutDirection(); }
666
667 // page and document
668
669 bool StartDoc(const wxString& message)
670 { return m_pimpl->StartDoc(message); }
671 void EndDoc()
672 { m_pimpl->EndDoc(); }
673
674 void StartPage()
675 { m_pimpl->StartPage(); }
676 void EndPage()
677 { m_pimpl->EndPage(); }
678
679 // bounding box
680
681 void CalcBoundingBox(wxCoord x, wxCoord y)
682 { m_pimpl->CalcBoundingBox(x,y); }
683 void ResetBoundingBox()
684 { m_pimpl->ResetBoundingBox(); }
685
686 wxCoord MinX() const
687 { return m_pimpl->MinX(); }
688 wxCoord MaxX() const
689 { return m_pimpl->MaxX(); }
690 wxCoord MinY() const
691 { return m_pimpl->MinY(); }
692 wxCoord MaxY() const
693 { return m_pimpl->MaxY(); }
694
695 // setters and getters
696
697 void SetFont(const wxFont& font)
698 { m_pimpl->SetFont( font ); }
699 const wxFont& GetFont() const
700 { return m_pimpl->GetFont(); }
701
702 void SetPen(const wxPen& pen)
703 { m_pimpl->SetPen( pen ); }
704 const wxPen& GetPen() const
705 { return m_pimpl->GetPen(); }
706
707 void SetBrush(const wxBrush& brush)
708 { m_pimpl->SetBrush( brush ); }
709 const wxBrush& GetBrush() const
710 { return m_pimpl->GetBrush(); }
711
712 void SetBackground(const wxBrush& brush)
713 { m_pimpl->SetBackground( brush ); }
714 const wxBrush& GetBackground() const
715 { return m_pimpl->GetBackground(); }
716
717 void SetBackgroundMode(int mode)
718 { m_pimpl->SetBackgroundMode( mode ); }
719 int GetBackgroundMode() const
720 { return m_pimpl->GetBackgroundMode(); }
721
722 void SetTextForeground(const wxColour& colour)
723 { m_pimpl->SetTextForeground(colour); }
724 const wxColour& GetTextForeground() const
725 { return m_pimpl->GetTextForeground(); }
726
727 void SetTextBackground(const wxColour& colour)
728 { m_pimpl->SetTextBackground(colour); }
729 const wxColour& GetTextBackground() const
730 { return m_pimpl->GetTextBackground(); }
731
732 #if wxUSE_PALETTE
733 void SetPalette(const wxPalette& palette)
734 { m_pimpl->SetPalette(palette); }
735 #endif // wxUSE_PALETTE
736
737 // logical functions
738
739 void SetLogicalFunction(int function)
740 { m_pimpl->SetLogicalFunction(function); }
741 int GetLogicalFunction() const
742 { return m_pimpl->GetLogicalFunction(); }
743
744 // text measurement
745
746 wxCoord GetCharHeight() const
747 { return m_pimpl->GetCharHeight(); }
748 wxCoord GetCharWidth() const
749 { return m_pimpl->GetCharWidth(); }
750
751 void GetTextExtent(const wxString& string,
752 wxCoord *x, wxCoord *y,
753 wxCoord *descent = NULL,
754 wxCoord *externalLeading = NULL,
755 const wxFont *theFont = NULL) const
756 { m_pimpl->DoGetTextExtent(string, x, y, descent, externalLeading, theFont); }
757
758 wxSize GetTextExtent(const wxString& string) const
759 {
760 wxCoord w, h;
761 m_pimpl->DoGetTextExtent(string, &w, &h);
762 return wxSize(w, h);
763 }
764
765 void GetMultiLineTextExtent(const wxString& string,
766 wxCoord *width,
767 wxCoord *height,
768 wxCoord *heightLine = NULL,
769 const wxFont *font = NULL) const
770 { m_pimpl->GetMultiLineTextExtent( string, width, height, heightLine, font ); }
771
772 wxSize GetMultiLineTextExtent(const wxString& string) const
773 {
774 wxCoord w, h;
775 m_pimpl->GetMultiLineTextExtent(string, &w, &h);
776 return wxSize(w, h);
777 }
778
779 bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
780 { return m_pimpl->DoGetPartialTextExtents(text, widths); }
781
782 // clearing
783
784 void Clear()
785 { m_pimpl->Clear(); }
786
787 // clipping
788
789 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
790 { m_pimpl->DoSetClippingRegion(x, y, width, height); }
791 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
792 { m_pimpl->DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); }
793 void SetClippingRegion(const wxRect& rect)
794 { m_pimpl->DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
795
796 // unlike the functions above, the coordinates of the region used in this
797 // one are in device coordinates, not the logical ones
798 void SetDeviceClippingRegion(const wxRegion& region)
799 { m_pimpl->DoSetDeviceClippingRegion(region); }
800
801 // this function is deprecated because its name is confusing: you may
802 // expect it to work with logical coordinates but, in fact, it does exactly
803 // the same thing as SetDeviceClippingRegion()
804 //
805 // please review the code using it and either replace it with calls to
806 // SetDeviceClippingRegion() or correct it if it was [wrongly] passing
807 // logical coordinates to this function
808 wxDEPRECATED_INLINE(void SetClippingRegion(const wxRegion& region),
809 SetDeviceClippingRegion(region); )
810
811 void DestroyClippingRegion()
812 { m_pimpl->DestroyClippingRegion(); }
813
814 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
815 { m_pimpl->DoGetClippingBox(x, y, w, h); }
816 void GetClippingBox(wxRect& rect) const
817 { m_pimpl->DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); }
818
819 // coordinates conversions and transforms
820
821 wxCoord DeviceToLogicalX(wxCoord x) const
822 { return m_pimpl->DeviceToLogicalX(x); }
823 wxCoord DeviceToLogicalY(wxCoord y) const
824 { return m_pimpl->DeviceToLogicalY(y); }
825 wxCoord DeviceToLogicalXRel(wxCoord x) const
826 { return m_pimpl->DeviceToLogicalXRel(x); }
827 wxCoord DeviceToLogicalYRel(wxCoord y) const
828 { return m_pimpl->DeviceToLogicalYRel(y); }
829 wxCoord LogicalToDeviceX(wxCoord x) const
830 { return m_pimpl->LogicalToDeviceX(x); }
831 wxCoord LogicalToDeviceY(wxCoord y) const
832 { return m_pimpl->LogicalToDeviceY(y); }
833 wxCoord LogicalToDeviceXRel(wxCoord x) const
834 { return m_pimpl->LogicalToDeviceXRel(x); }
835 wxCoord LogicalToDeviceYRel(wxCoord y) const
836 { return m_pimpl->LogicalToDeviceYRel(y); }
837
838 void SetMapMode(int mode)
839 { m_pimpl->SetMapMode(mode); }
840 int GetMapMode() const
841 { return m_pimpl->GetMapMode(); }
842
843 void SetUserScale(double x, double y)
844 { m_pimpl->SetUserScale(x,y); }
845 void GetUserScale(double *x, double *y) const
846 { m_pimpl->GetUserScale( x, y ); }
847
848 void SetLogicalScale(double x, double y)
849 { m_pimpl->SetLogicalScale( x, y ); }
850 void GetLogicalScale(double *x, double *y)
851 { m_pimpl->GetLogicalScale( x, y ); }
852
853 void SetLogicalOrigin(wxCoord x, wxCoord y)
854 { m_pimpl->SetLogicalOrigin(x,y); }
855 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const
856 { m_pimpl->DoGetLogicalOrigin(x, y); }
857 wxPoint GetLogicalOrigin() const
858 { wxCoord x, y; m_pimpl->DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
859
860 void SetDeviceOrigin(wxCoord x, wxCoord y)
861 { m_pimpl->SetDeviceOrigin( x, y); }
862 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const
863 { m_pimpl->DoGetDeviceOrigin(x, y); }
864 wxPoint GetDeviceOrigin() const
865 { wxCoord x, y; m_pimpl->DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
866
867 void SetAxisOrientation(bool xLeftRight, bool yBottomUp)
868 { m_pimpl->SetAxisOrientation(xLeftRight, yBottomUp); }
869
870 // mostly internal
871 void SetDeviceLocalOrigin( wxCoord x, wxCoord y )
872 { m_pimpl->SetDeviceLocalOrigin( x, y ); }
873
874
875 // draw generic object
876
877 void DrawObject(wxDrawObject* drawobject)
878 {
879 drawobject->Draw(*this);
880 CalcBoundingBox(drawobject->MinX(),drawobject->MinY());
881 CalcBoundingBox(drawobject->MaxX(),drawobject->MaxY());
882 }
883
884 // -----------------------------------------------
885 // the actual drawing API
886
887 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col,
888 int style = wxFLOOD_SURFACE)
889 { return m_pimpl->DoFloodFill(x, y, col, style); }
890 bool FloodFill(const wxPoint& pt, const wxColour& col,
891 int style = wxFLOOD_SURFACE)
892 { return m_pimpl->DoFloodFill(pt.x, pt.y, col, style); }
893
894 // fill the area specified by rect with a radial gradient, starting from
895 // initialColour in the centre of the cercle and fading to destColour.
896 void GradientFillConcentric(const wxRect& rect,
897 const wxColour& initialColour,
898 const wxColour& destColour)
899 { m_pimpl->DoGradientFillConcentric( rect, initialColour, destColour,
900 wxPoint(rect.GetWidth() / 2,
901 rect.GetHeight() / 2)); }
902
903 void GradientFillConcentric(const wxRect& rect,
904 const wxColour& initialColour,
905 const wxColour& destColour,
906 const wxPoint& circleCenter)
907 { m_pimpl->DoGradientFillConcentric(rect, initialColour, destColour, circleCenter); }
908
909 // fill the area specified by rect with a linear gradient
910 void GradientFillLinear(const wxRect& rect,
911 const wxColour& initialColour,
912 const wxColour& destColour,
913 wxDirection nDirection = wxEAST)
914 { m_pimpl->DoGradientFillLinear(rect, initialColour, destColour, nDirection); }
915
916 bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const
917 { return m_pimpl->DoGetPixel(x, y, col); }
918 bool GetPixel(const wxPoint& pt, wxColour *col) const
919 { return m_pimpl->DoGetPixel(pt.x, pt.y, col); }
920
921 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
922 { m_pimpl->DoDrawLine(x1, y1, x2, y2); }
923 void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
924 { m_pimpl->DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
925
926 void CrossHair(wxCoord x, wxCoord y)
927 { m_pimpl->DoCrossHair(x, y); }
928 void CrossHair(const wxPoint& pt)
929 { m_pimpl->DoCrossHair(pt.x, pt.y); }
930
931 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
932 wxCoord xc, wxCoord yc)
933 { m_pimpl->DoDrawArc(x1, y1, x2, y2, xc, yc); }
934 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
935 { m_pimpl->DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
936
937 void DrawCheckMark(wxCoord x, wxCoord y,
938 wxCoord width, wxCoord height)
939 { m_pimpl->DoDrawCheckMark(x, y, width, height); }
940 void DrawCheckMark(const wxRect& rect)
941 { m_pimpl->DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
942
943 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
944 double sa, double ea)
945 { m_pimpl->DoDrawEllipticArc(x, y, w, h, sa, ea); }
946 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
947 double sa, double ea)
948 { m_pimpl->DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
949
950 void DrawPoint(wxCoord x, wxCoord y)
951 { m_pimpl->DoDrawPoint(x, y); }
952 void DrawPoint(const wxPoint& pt)
953 { m_pimpl->DoDrawPoint(pt.x, pt.y); }
954
955 void DrawLines(int n, wxPoint points[],
956 wxCoord xoffset = 0, wxCoord yoffset = 0)
957 { m_pimpl->DoDrawLines(n, points, xoffset, yoffset); }
958 void DrawLines(const wxPointList *list,
959 wxCoord xoffset = 0, wxCoord yoffset = 0)
960 { m_pimpl->DrawLines( list, xoffset, yoffset ); }
961 #if WXWIN_COMPATIBILITY_2_8
962 wxDEPRECATED( void DrawLines(const wxList *list,
963 wxCoord xoffset = 0, wxCoord yoffset = 0) );
964 #endif // WXWIN_COMPATIBILITY_2_8
965
966 void DrawPolygon(int n, wxPoint points[],
967 wxCoord xoffset = 0, wxCoord yoffset = 0,
968 int fillStyle = wxODDEVEN_RULE)
969 { m_pimpl->DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
970 void DrawPolygon(const wxPointList *list,
971 wxCoord xoffset = 0, wxCoord yoffset = 0,
972 int fillStyle = wxODDEVEN_RULE)
973 { m_pimpl->DrawPolygon( list, xoffset, yoffset, fillStyle ); }
974 void DrawPolyPolygon(int n, int count[], wxPoint points[],
975 wxCoord xoffset = 0, wxCoord yoffset = 0,
976 int fillStyle = wxODDEVEN_RULE)
977 { m_pimpl->DoDrawPolyPolygon(n, count, points, xoffset, yoffset, fillStyle); }
978 #if WXWIN_COMPATIBILITY_2_8
979 wxDEPRECATED( void DrawPolygon(const wxList *list,
980 wxCoord xoffset = 0, wxCoord yoffset = 0,
981 int fillStyle = wxODDEVEN_RULE) );
982 #endif // WXWIN_COMPATIBILITY_2_8
983
984 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
985 { m_pimpl->DoDrawRectangle(x, y, width, height); }
986 void DrawRectangle(const wxPoint& pt, const wxSize& sz)
987 { m_pimpl->DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); }
988 void DrawRectangle(const wxRect& rect)
989 { m_pimpl->DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); }
990
991 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
992 double radius)
993 { m_pimpl->DoDrawRoundedRectangle(x, y, width, height, radius); }
994 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
995 double radius)
996 { m_pimpl->DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
997 void DrawRoundedRectangle(const wxRect& r, double radius)
998 { m_pimpl->DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
999
1000 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
1001 { m_pimpl->DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
1002 void DrawCircle(const wxPoint& pt, wxCoord radius)
1003 { m_pimpl->DoDrawEllipse(pt.x - radius, pt.y - radius, 2*radius, 2*radius); }
1004
1005 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1006 { m_pimpl->DoDrawEllipse(x, y, width, height); }
1007 void DrawEllipse(const wxPoint& pt, const wxSize& sz)
1008 { m_pimpl->DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); }
1009 void DrawEllipse(const wxRect& rect)
1010 { m_pimpl->DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); }
1011
1012 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
1013 { m_pimpl->DoDrawIcon(icon, x, y); }
1014 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
1015 { m_pimpl->DoDrawIcon(icon, pt.x, pt.y); }
1016
1017 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
1018 bool useMask = false)
1019 { m_pimpl->DoDrawBitmap(bmp, x, y, useMask); }
1020 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
1021 bool useMask = false)
1022 { m_pimpl->DoDrawBitmap(bmp, pt.x, pt.y, useMask); }
1023
1024 void DrawText(const wxString& text, wxCoord x, wxCoord y)
1025 { m_pimpl->DoDrawText(text, x, y); }
1026 void DrawText(const wxString& text, const wxPoint& pt)
1027 { m_pimpl->DoDrawText(text, pt.x, pt.y); }
1028
1029 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
1030 { m_pimpl->DoDrawRotatedText(text, x, y, angle); }
1031 void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)
1032 { m_pimpl->DoDrawRotatedText(text, pt.x, pt.y, angle); }
1033
1034 // this version puts both optional bitmap and the text into the given
1035 // rectangle and aligns is as specified by alignment parameter; it also
1036 // will emphasize the character with the given index if it is != -1 and
1037 // return the bounding rectangle if required
1038 void DrawLabel(const wxString& text,
1039 const wxBitmap& image,
1040 const wxRect& rect,
1041 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
1042 int indexAccel = -1,
1043 wxRect *rectBounding = NULL);
1044
1045 void DrawLabel(const wxString& text, const wxRect& rect,
1046 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
1047 int indexAccel = -1)
1048 { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); }
1049
1050 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
1051 wxDC *source, wxCoord xsrc, wxCoord ysrc,
1052 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
1053 {
1054 return m_pimpl->DoBlit(xdest, ydest, width, height,
1055 source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
1056 }
1057 bool Blit(const wxPoint& destPt, const wxSize& sz,
1058 wxDC *source, const wxPoint& srcPt,
1059 int rop = wxCOPY, bool useMask = false, const wxPoint& srcPtMask = wxDefaultPosition)
1060 {
1061 return m_pimpl->DoBlit(destPt.x, destPt.y, sz.x, sz.y,
1062 source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
1063 }
1064
1065 bool StretchBlit(wxCoord dstX, wxCoord dstY,
1066 wxCoord dstWidth, wxCoord dstHeight,
1067 wxDC *source,
1068 wxCoord srcX, wxCoord srcY,
1069 wxCoord srcWidth, wxCoord srcHeight,
1070 int rop = wxCOPY, bool useMask = false,
1071 wxCoord srcMaskX = wxDefaultCoord, wxCoord srcMaskY = wxDefaultCoord)
1072 {
1073 return m_pimpl->DoStretchBlit(dstX, dstY, dstWidth, dstHeight,
1074 source, srcX, srcY, srcWidth, srcHeight, rop, useMask, srcMaskX, srcMaskY);
1075 }
1076 bool StretchBlit(const wxPoint& dstPt, const wxSize& dstSize,
1077 wxDC *source, const wxPoint& srcPt, const wxSize& srcSize,
1078 int rop = wxCOPY, bool useMask = false, const wxPoint& srcMaskPt = wxDefaultPosition)
1079 {
1080 return m_pimpl->DoStretchBlit(dstPt.x, dstPt.y, dstSize.x, dstSize.y,
1081 source, srcPt.x, srcPt.y, srcSize.x, srcSize.y, rop, useMask, srcMaskPt.x, srcMaskPt.y);
1082 }
1083
1084 wxBitmap GetAsBitmap(const wxRect *subrect = (const wxRect *) NULL) const
1085 {
1086 return m_pimpl->DoGetAsBitmap(subrect);
1087 }
1088
1089 #if wxUSE_SPLINES
1090 void DrawSpline(wxCoord x1, wxCoord y1,
1091 wxCoord x2, wxCoord y2,
1092 wxCoord x3, wxCoord y3)
1093 { m_pimpl->DrawSpline(x1,y1,x2,y2,x3,y3); }
1094 void DrawSpline(int n, wxPoint points[])
1095 { m_pimpl->DrawSpline(n,points); }
1096 void DrawSpline(const wxPointList *points)
1097 { m_pimpl->DrawSpline(points); }
1098 #endif // wxUSE_SPLINES
1099
1100
1101 #if WXWIN_COMPATIBILITY_2_8
1102 // for compatibility with the old code when wxCoord was long everywhere
1103 wxDEPRECATED( void GetTextExtent(const wxString& string,
1104 long *x, long *y,
1105 long *descent = NULL,
1106 long *externalLeading = NULL,
1107 const wxFont *theFont = NULL) const );
1108 wxDEPRECATED( void GetLogicalOrigin(long *x, long *y) const );
1109 wxDEPRECATED( void GetDeviceOrigin(long *x, long *y) const );
1110 wxDEPRECATED( void GetClippingBox(long *x, long *y, long *w, long *h) const );
1111 #endif // WXWIN_COMPATIBILITY_2_8
1112
1113
1114 protected:
1115 // ctor takes ownership of the pointer
1116 wxDC(wxDCImpl *pimpl) : m_pimpl(pimpl) { }
1117
1118 wxDCImpl * const m_pimpl;
1119
1120 private:
1121 DECLARE_ABSTRACT_CLASS(wxDC)
1122 DECLARE_NO_COPY_CLASS(wxDC)
1123 };
1124
1125 // ----------------------------------------------------------------------------
1126 // helper class: you can use it to temporarily change the DC text colour and
1127 // restore it automatically when the object goes out of scope
1128 // ----------------------------------------------------------------------------
1129
1130 class WXDLLIMPEXP_CORE wxDCTextColourChanger
1131 {
1132 public:
1133 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
1134
1135 wxDCTextColourChanger(wxDC& dc, const wxColour& col) : m_dc(dc)
1136 {
1137 Set(col);
1138 }
1139
1140 ~wxDCTextColourChanger()
1141 {
1142 if ( m_colFgOld.Ok() )
1143 m_dc.SetTextForeground(m_colFgOld);
1144 }
1145
1146 void Set(const wxColour& col)
1147 {
1148 if ( !m_colFgOld.Ok() )
1149 m_colFgOld = m_dc.GetTextForeground();
1150 m_dc.SetTextForeground(col);
1151 }
1152
1153 private:
1154 wxDC& m_dc;
1155
1156 wxColour m_colFgOld;
1157
1158 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger)
1159 };
1160
1161 // ----------------------------------------------------------------------------
1162 // helper class: you can use it to temporarily change the DC pen and
1163 // restore it automatically when the object goes out of scope
1164 // ----------------------------------------------------------------------------
1165
1166 class WXDLLIMPEXP_CORE wxDCPenChanger
1167 {
1168 public:
1169 wxDCPenChanger(wxDC& dc, const wxPen& pen) : m_dc(dc), m_penOld(dc.GetPen())
1170 {
1171 m_dc.SetPen(pen);
1172 }
1173
1174 ~wxDCPenChanger()
1175 {
1176 if ( m_penOld.Ok() )
1177 m_dc.SetPen(m_penOld);
1178 }
1179
1180 private:
1181 wxDC& m_dc;
1182
1183 wxPen m_penOld;
1184
1185 DECLARE_NO_COPY_CLASS(wxDCPenChanger)
1186 };
1187
1188 // ----------------------------------------------------------------------------
1189 // helper class: you can use it to temporarily change the DC brush and
1190 // restore it automatically when the object goes out of scope
1191 // ----------------------------------------------------------------------------
1192
1193 class WXDLLIMPEXP_CORE wxDCBrushChanger
1194 {
1195 public:
1196 wxDCBrushChanger(wxDC& dc, const wxBrush& brush) : m_dc(dc), m_brushOld(dc.GetBrush())
1197 {
1198 m_dc.SetBrush(brush);
1199 }
1200
1201 ~wxDCBrushChanger()
1202 {
1203 if ( m_brushOld.Ok() )
1204 m_dc.SetBrush(m_brushOld);
1205 }
1206
1207 private:
1208 wxDC& m_dc;
1209
1210 wxBrush m_brushOld;
1211
1212 DECLARE_NO_COPY_CLASS(wxDCBrushChanger)
1213 };
1214
1215 // ----------------------------------------------------------------------------
1216 // another small helper class: sets the clipping region in its ctor and
1217 // destroys it in the dtor
1218 // ----------------------------------------------------------------------------
1219
1220 class WXDLLIMPEXP_CORE wxDCClipper
1221 {
1222 public:
1223 wxDCClipper(wxDC& dc, const wxRegion& r) : m_dc(dc)
1224 { dc.SetClippingRegion(r.GetBox()); }
1225 wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc)
1226 { dc.SetClippingRegion(r.x, r.y, r.width, r.height); }
1227 wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc)
1228 { dc.SetClippingRegion(x, y, w, h); }
1229
1230 ~wxDCClipper() { m_dc.DestroyClippingRegion(); }
1231
1232 private:
1233 wxDC& m_dc;
1234
1235 DECLARE_NO_COPY_CLASS(wxDCClipper)
1236 };
1237
1238 #endif // _WX_DC_H_BASE_