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