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