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