]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dc.h
Add missing lines to setup.h.in. This properly fixes compilation under configure...
[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 #ifdef __WXMSW__
516 // Native Windows functions using the underlying HDC don't honour GDI+
517 // transformations which may be applied to it. Using this function we can
518 // transform the coordinates manually before passing them to such functions
519 // (as in e.g. wxRendererMSW code). It doesn't do anything if this is not a
520 // wxGCDC.
521 virtual wxRect MSWApplyGDIPlusTransform(const wxRect& r) const
522 {
523 return r;
524 }
525 #endif // __WXMSW__
526
527
528 // ---------------------------------------------------------
529 // the actual drawing API
530
531 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
532 wxFloodFillStyle style = wxFLOOD_SURFACE) = 0;
533
534 virtual void DoGradientFillLinear(const wxRect& rect,
535 const wxColour& initialColour,
536 const wxColour& destColour,
537 wxDirection nDirection = wxEAST);
538
539 virtual void DoGradientFillConcentric(const wxRect& rect,
540 const wxColour& initialColour,
541 const wxColour& destColour,
542 const wxPoint& circleCenter);
543
544 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
545
546 virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
547 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
548
549 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
550 wxCoord x2, wxCoord y2,
551 wxCoord xc, wxCoord yc) = 0;
552 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
553 wxCoord width, wxCoord height);
554 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
555 double sa, double ea) = 0;
556
557 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0;
558 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
559 wxCoord width, wxCoord height,
560 double radius) = 0;
561 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
562 wxCoord width, wxCoord height) = 0;
563
564 virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
565
566 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
567 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
568 bool useMask = false) = 0;
569
570 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
571 virtual void DoDrawRotatedText(const wxString& text,
572 wxCoord x, wxCoord y, double angle) = 0;
573
574 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
575 wxCoord width, wxCoord height,
576 wxDC *source,
577 wxCoord xsrc, wxCoord ysrc,
578 wxRasterOperationMode rop = wxCOPY,
579 bool useMask = false,
580 wxCoord xsrcMask = wxDefaultCoord,
581 wxCoord ysrcMask = wxDefaultCoord) = 0;
582
583 virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
584 wxCoord dstWidth, wxCoord dstHeight,
585 wxDC *source,
586 wxCoord xsrc, wxCoord ysrc,
587 wxCoord srcWidth, wxCoord srcHeight,
588 wxRasterOperationMode rop = wxCOPY,
589 bool useMask = false,
590 wxCoord xsrcMask = wxDefaultCoord,
591 wxCoord ysrcMask = wxDefaultCoord);
592
593 virtual wxBitmap DoGetAsBitmap(const wxRect *WXUNUSED(subrect)) const
594 { return wxNullBitmap; }
595
596
597 virtual void DoDrawLines(int n, wxPoint points[],
598 wxCoord xoffset, wxCoord yoffset ) = 0;
599 virtual void DrawLines(const wxPointList *list,
600 wxCoord xoffset, wxCoord yoffset );
601
602 virtual void DoDrawPolygon(int n, wxPoint points[],
603 wxCoord xoffset, wxCoord yoffset,
604 wxPolygonFillMode fillStyle = wxODDEVEN_RULE) = 0;
605 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
606 wxCoord xoffset, wxCoord yoffset,
607 wxPolygonFillMode fillStyle);
608 void DrawPolygon(const wxPointList *list,
609 wxCoord xoffset, wxCoord yoffset,
610 wxPolygonFillMode fillStyle );
611
612
613 #if wxUSE_SPLINES
614 void DrawSpline(wxCoord x1, wxCoord y1,
615 wxCoord x2, wxCoord y2,
616 wxCoord x3, wxCoord y3);
617 void DrawSpline(int n, wxPoint points[]);
618 void DrawSpline(const wxPointList *points) { DoDrawSpline(points); }
619
620 virtual void DoDrawSpline(const wxPointList *points);
621 #endif
622
623 // ---------------------------------------------------------
624 // wxMemoryDC Impl API
625
626 virtual void DoSelect(const wxBitmap& WXUNUSED(bmp))
627 { }
628
629 virtual const wxBitmap& GetSelectedBitmap() const
630 { return wxNullBitmap; }
631 virtual wxBitmap& GetSelectedBitmap()
632 { return wxNullBitmap; }
633
634 // ---------------------------------------------------------
635 // wxPrinterDC Impl API
636
637 virtual wxRect GetPaperRect() const
638 { int w = 0; int h = 0; DoGetSize( &w, &h ); return wxRect(0,0,w,h); }
639
640 virtual int GetResolution() const
641 { return -1; }
642
643 private:
644 wxDC *m_owner;
645
646 protected:
647 // unset clipping variables (after clipping region was destroyed)
648 void ResetClipping()
649 {
650 m_clipping = false;
651
652 m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0;
653 }
654
655 #ifdef __WXWINCE__
656 //! Generic method to draw ellipses, circles and arcs with current pen and brush.
657 /*! \param x Upper left corner of bounding box.
658 * \param y Upper left corner of bounding box.
659 * \param w Width of bounding box.
660 * \param h Height of bounding box.
661 * \param sa Starting angle of arc
662 * (counterclockwise, start at 3 o'clock, 360 is full circle).
663 * \param ea Ending angle of arc.
664 * \param angle Rotation angle, the Arc will be rotated after
665 * calculating begin and end.
666 */
667 void DrawEllipticArcRot( wxCoord x, wxCoord y,
668 wxCoord width, wxCoord height,
669 double sa = 0, double ea = 0, double angle = 0 )
670 { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); }
671
672 void DrawEllipticArcRot( const wxPoint& pt,
673 const wxSize& sz,
674 double sa = 0, double ea = 0, double angle = 0 )
675 { DoDrawEllipticArcRot( pt.x, pt.y, sz.x, sz.y, sa, ea, angle ); }
676
677 void DrawEllipticArcRot( const wxRect& rect,
678 double sa = 0, double ea = 0, double angle = 0 )
679 { DoDrawEllipticArcRot( rect.x, rect.y, rect.width, rect.height, sa, ea, angle ); }
680
681 virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y,
682 wxCoord w, wxCoord h,
683 double sa = 0, double ea = 0, double angle = 0 );
684
685 //! Rotates points around center.
686 /*! This is a quite straight method, it calculates in pixels
687 * and so it produces rounding errors.
688 * \param points The points inside will be rotated.
689 * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle).
690 * \param center Center of rotation.
691 */
692 void Rotate( wxPointList* points, double angle, wxPoint center = wxPoint(0,0) );
693
694 // used by DrawEllipticArcRot
695 // Careful: wxList gets filled with points you have to delete later.
696 void CalculateEllipticPoints( wxPointList* points,
697 wxCoord xStart, wxCoord yStart,
698 wxCoord w, wxCoord h,
699 double sa, double ea );
700 #endif // __WXWINCE__
701
702 // returns adjustment factor for converting wxFont "point size"; in wx
703 // it is point size on screen and needs to be multiplied by this value
704 // for rendering on higher-resolution DCs such as printer ones
705 static float GetFontPointSizeAdjustment(float dpi);
706
707 // window on which the DC draws or NULL
708 wxWindow *m_window;
709
710 // flags
711 bool m_colour:1;
712 bool m_ok:1;
713 bool m_clipping:1;
714 bool m_isInteractive:1;
715 bool m_isBBoxValid:1;
716
717 // coordinate system variables
718
719 wxCoord m_logicalOriginX, m_logicalOriginY;
720 wxCoord m_deviceOriginX, m_deviceOriginY; // Usually 0,0, can be change by user
721
722 wxCoord m_deviceLocalOriginX, m_deviceLocalOriginY; // non-zero if native top-left corner
723 // is not at 0,0. This was the case under
724 // Mac's GrafPorts (coordinate system
725 // used toplevel window's origin) and
726 // e.g. for Postscript, where the native
727 // origin in the bottom left corner.
728 double m_logicalScaleX, m_logicalScaleY;
729 double m_userScaleX, m_userScaleY;
730 double m_scaleX, m_scaleY; // calculated from logical scale and user scale
731
732 int m_signX, m_signY; // Used by SetAxisOrientation() to invert the axes
733
734 // what is a mm on a screen you don't know the size of?
735 double m_mm_to_pix_x,
736 m_mm_to_pix_y;
737
738 // bounding and clipping boxes
739 wxCoord m_minX, m_minY, m_maxX, m_maxY;
740 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
741
742 wxRasterOperationMode m_logicalFunction;
743 int m_backgroundMode;
744 wxMappingMode m_mappingMode;
745
746 wxPen m_pen;
747 wxBrush m_brush;
748 wxBrush m_backgroundBrush;
749 wxColour m_textForegroundColour;
750 wxColour m_textBackgroundColour;
751 wxFont m_font;
752
753 #if wxUSE_PALETTE
754 wxPalette m_palette;
755 bool m_hasCustomPalette;
756 #endif // wxUSE_PALETTE
757
758 private:
759 DECLARE_ABSTRACT_CLASS(wxDCImpl)
760 };
761
762
763 class WXDLLIMPEXP_CORE wxDC : public wxObject
764 {
765 public:
766 // copy attributes (font, colours and writing direction) from another DC
767 void CopyAttributes(const wxDC& dc);
768
769 virtual ~wxDC() { delete m_pimpl; }
770
771 wxDCImpl *GetImpl()
772 { return m_pimpl; }
773 const wxDCImpl *GetImpl() const
774 { return m_pimpl; }
775
776 wxWindow *GetWindow() const
777 { return m_pimpl->GetWindow(); }
778
779 bool IsOk() const
780 { return m_pimpl && m_pimpl->IsOk(); }
781
782 // query capabilities
783
784 bool CanDrawBitmap() const
785 { return m_pimpl->CanDrawBitmap(); }
786 bool CanGetTextExtent() const
787 { return m_pimpl->CanGetTextExtent(); }
788
789 // query dimension, colour deps, resolution
790
791 void GetSize(int *width, int *height) const
792 { m_pimpl->DoGetSize(width, height); }
793 wxSize GetSize() const
794 { return m_pimpl->GetSize(); }
795
796 void GetSizeMM(int* width, int* height) const
797 { m_pimpl->DoGetSizeMM(width, height); }
798 wxSize GetSizeMM() const
799 {
800 int w, h;
801 m_pimpl->DoGetSizeMM(&w, &h);
802 return wxSize(w, h);
803 }
804
805 int GetDepth() const
806 { return m_pimpl->GetDepth(); }
807 wxSize GetPPI() const
808 { return m_pimpl->GetPPI(); }
809
810 virtual int GetResolution() const
811 { return m_pimpl->GetResolution(); }
812
813 // Right-To-Left (RTL) modes
814
815 void SetLayoutDirection(wxLayoutDirection dir)
816 { m_pimpl->SetLayoutDirection( dir ); }
817 wxLayoutDirection GetLayoutDirection() const
818 { return m_pimpl->GetLayoutDirection(); }
819
820 // page and document
821
822 bool StartDoc(const wxString& message)
823 { return m_pimpl->StartDoc(message); }
824 void EndDoc()
825 { m_pimpl->EndDoc(); }
826
827 void StartPage()
828 { m_pimpl->StartPage(); }
829 void EndPage()
830 { m_pimpl->EndPage(); }
831
832 // bounding box
833
834 void CalcBoundingBox(wxCoord x, wxCoord y)
835 { m_pimpl->CalcBoundingBox(x,y); }
836 void ResetBoundingBox()
837 { m_pimpl->ResetBoundingBox(); }
838
839 wxCoord MinX() const
840 { return m_pimpl->MinX(); }
841 wxCoord MaxX() const
842 { return m_pimpl->MaxX(); }
843 wxCoord MinY() const
844 { return m_pimpl->MinY(); }
845 wxCoord MaxY() const
846 { return m_pimpl->MaxY(); }
847
848 // setters and getters
849
850 void SetFont(const wxFont& font)
851 { m_pimpl->SetFont( font ); }
852 const wxFont& GetFont() const
853 { return m_pimpl->GetFont(); }
854
855 void SetPen(const wxPen& pen)
856 { m_pimpl->SetPen( pen ); }
857 const wxPen& GetPen() const
858 { return m_pimpl->GetPen(); }
859
860 void SetBrush(const wxBrush& brush)
861 { m_pimpl->SetBrush( brush ); }
862 const wxBrush& GetBrush() const
863 { return m_pimpl->GetBrush(); }
864
865 void SetBackground(const wxBrush& brush)
866 { m_pimpl->SetBackground( brush ); }
867 const wxBrush& GetBackground() const
868 { return m_pimpl->GetBackground(); }
869
870 void SetBackgroundMode(int mode)
871 { m_pimpl->SetBackgroundMode( mode ); }
872 int GetBackgroundMode() const
873 { return m_pimpl->GetBackgroundMode(); }
874
875 void SetTextForeground(const wxColour& colour)
876 { m_pimpl->SetTextForeground(colour); }
877 const wxColour& GetTextForeground() const
878 { return m_pimpl->GetTextForeground(); }
879
880 void SetTextBackground(const wxColour& colour)
881 { m_pimpl->SetTextBackground(colour); }
882 const wxColour& GetTextBackground() const
883 { return m_pimpl->GetTextBackground(); }
884
885 #if wxUSE_PALETTE
886 void SetPalette(const wxPalette& palette)
887 { m_pimpl->SetPalette(palette); }
888 #endif // wxUSE_PALETTE
889
890 // logical functions
891
892 void SetLogicalFunction(wxRasterOperationMode function)
893 { m_pimpl->SetLogicalFunction(function); }
894 wxRasterOperationMode GetLogicalFunction() const
895 { return m_pimpl->GetLogicalFunction(); }
896
897 // text measurement
898
899 wxCoord GetCharHeight() const
900 { return m_pimpl->GetCharHeight(); }
901 wxCoord GetCharWidth() const
902 { return m_pimpl->GetCharWidth(); }
903
904 wxFontMetrics GetFontMetrics() const
905 {
906 wxFontMetrics fm;
907 m_pimpl->DoGetFontMetrics(&fm.height, &fm.ascent, &fm.descent,
908 &fm.internalLeading, &fm.externalLeading,
909 &fm.averageWidth);
910 return fm;
911 }
912
913 void GetTextExtent(const wxString& string,
914 wxCoord *x, wxCoord *y,
915 wxCoord *descent = NULL,
916 wxCoord *externalLeading = NULL,
917 const wxFont *theFont = NULL) const
918 { m_pimpl->DoGetTextExtent(string, x, y, descent, externalLeading, theFont); }
919
920 wxSize GetTextExtent(const wxString& string) const
921 {
922 wxCoord w, h;
923 m_pimpl->DoGetTextExtent(string, &w, &h);
924 return wxSize(w, h);
925 }
926
927 void GetMultiLineTextExtent(const wxString& string,
928 wxCoord *width,
929 wxCoord *height,
930 wxCoord *heightLine = NULL,
931 const wxFont *font = NULL) const
932 { m_pimpl->GetMultiLineTextExtent( string, width, height, heightLine, font ); }
933
934 wxSize GetMultiLineTextExtent(const wxString& string) const
935 {
936 wxCoord w, h;
937 m_pimpl->GetMultiLineTextExtent(string, &w, &h);
938 return wxSize(w, h);
939 }
940
941 bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
942 { return m_pimpl->DoGetPartialTextExtents(text, widths); }
943
944 // clearing
945
946 void Clear()
947 { m_pimpl->Clear(); }
948
949 // clipping
950
951 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
952 { m_pimpl->DoSetClippingRegion(x, y, width, height); }
953 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
954 { m_pimpl->DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); }
955 void SetClippingRegion(const wxRect& rect)
956 { m_pimpl->DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
957
958 // unlike the functions above, the coordinates of the region used in this
959 // one are in device coordinates, not the logical ones
960 void SetDeviceClippingRegion(const wxRegion& region)
961 { m_pimpl->DoSetDeviceClippingRegion(region); }
962
963 // this function is deprecated because its name is confusing: you may
964 // expect it to work with logical coordinates but, in fact, it does exactly
965 // the same thing as SetDeviceClippingRegion()
966 //
967 // please review the code using it and either replace it with calls to
968 // SetDeviceClippingRegion() or correct it if it was [wrongly] passing
969 // logical coordinates to this function
970 wxDEPRECATED_INLINE(void SetClippingRegion(const wxRegion& region),
971 SetDeviceClippingRegion(region); )
972
973 void DestroyClippingRegion()
974 { m_pimpl->DestroyClippingRegion(); }
975
976 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
977 { m_pimpl->DoGetClippingBox(x, y, w, h); }
978 void GetClippingBox(wxRect& rect) const
979 { m_pimpl->DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); }
980
981 // coordinates conversions and transforms
982
983 wxCoord DeviceToLogicalX(wxCoord x) const
984 { return m_pimpl->DeviceToLogicalX(x); }
985 wxCoord DeviceToLogicalY(wxCoord y) const
986 { return m_pimpl->DeviceToLogicalY(y); }
987 wxCoord DeviceToLogicalXRel(wxCoord x) const
988 { return m_pimpl->DeviceToLogicalXRel(x); }
989 wxCoord DeviceToLogicalYRel(wxCoord y) const
990 { return m_pimpl->DeviceToLogicalYRel(y); }
991 wxCoord LogicalToDeviceX(wxCoord x) const
992 { return m_pimpl->LogicalToDeviceX(x); }
993 wxCoord LogicalToDeviceY(wxCoord y) const
994 { return m_pimpl->LogicalToDeviceY(y); }
995 wxCoord LogicalToDeviceXRel(wxCoord x) const
996 { return m_pimpl->LogicalToDeviceXRel(x); }
997 wxCoord LogicalToDeviceYRel(wxCoord y) const
998 { return m_pimpl->LogicalToDeviceYRel(y); }
999
1000 void SetMapMode(wxMappingMode mode)
1001 { m_pimpl->SetMapMode(mode); }
1002 wxMappingMode GetMapMode() const
1003 { return m_pimpl->GetMapMode(); }
1004
1005 void SetUserScale(double x, double y)
1006 { m_pimpl->SetUserScale(x,y); }
1007 void GetUserScale(double *x, double *y) const
1008 { m_pimpl->GetUserScale( x, y ); }
1009
1010 void SetLogicalScale(double x, double y)
1011 { m_pimpl->SetLogicalScale( x, y ); }
1012 void GetLogicalScale(double *x, double *y)
1013 { m_pimpl->GetLogicalScale( x, y ); }
1014
1015 void SetLogicalOrigin(wxCoord x, wxCoord y)
1016 { m_pimpl->SetLogicalOrigin(x,y); }
1017 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const
1018 { m_pimpl->DoGetLogicalOrigin(x, y); }
1019 wxPoint GetLogicalOrigin() const
1020 { wxCoord x, y; m_pimpl->DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
1021
1022 void SetDeviceOrigin(wxCoord x, wxCoord y)
1023 { m_pimpl->SetDeviceOrigin( x, y); }
1024 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const
1025 { m_pimpl->DoGetDeviceOrigin(x, y); }
1026 wxPoint GetDeviceOrigin() const
1027 { wxCoord x, y; m_pimpl->DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
1028
1029 void SetAxisOrientation(bool xLeftRight, bool yBottomUp)
1030 { m_pimpl->SetAxisOrientation(xLeftRight, yBottomUp); }
1031
1032 #if wxUSE_DC_TRANSFORM_MATRIX
1033 bool CanUseTransformMatrix() const
1034 { return m_pimpl->CanUseTransformMatrix(); }
1035
1036 bool SetTransformMatrix(const wxAffineMatrix2D &matrix)
1037 { return m_pimpl->SetTransformMatrix(matrix); }
1038
1039 wxAffineMatrix2D GetTransformMatrix() const
1040 { return m_pimpl->GetTransformMatrix(); }
1041
1042 void ResetTransformMatrix()
1043 { m_pimpl->ResetTransformMatrix(); }
1044 #endif // wxUSE_DC_TRANSFORM_MATRIX
1045
1046 // mostly internal
1047 void SetDeviceLocalOrigin( wxCoord x, wxCoord y )
1048 { m_pimpl->SetDeviceLocalOrigin( x, y ); }
1049
1050
1051 // -----------------------------------------------
1052 // the actual drawing API
1053
1054 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col,
1055 wxFloodFillStyle style = wxFLOOD_SURFACE)
1056 { return m_pimpl->DoFloodFill(x, y, col, style); }
1057 bool FloodFill(const wxPoint& pt, const wxColour& col,
1058 wxFloodFillStyle style = wxFLOOD_SURFACE)
1059 { return m_pimpl->DoFloodFill(pt.x, pt.y, col, style); }
1060
1061 // fill the area specified by rect with a radial gradient, starting from
1062 // initialColour in the centre of the cercle and fading to destColour.
1063 void GradientFillConcentric(const wxRect& rect,
1064 const wxColour& initialColour,
1065 const wxColour& destColour)
1066 { m_pimpl->DoGradientFillConcentric( rect, initialColour, destColour,
1067 wxPoint(rect.GetWidth() / 2,
1068 rect.GetHeight() / 2)); }
1069
1070 void GradientFillConcentric(const wxRect& rect,
1071 const wxColour& initialColour,
1072 const wxColour& destColour,
1073 const wxPoint& circleCenter)
1074 { m_pimpl->DoGradientFillConcentric(rect, initialColour, destColour, circleCenter); }
1075
1076 // fill the area specified by rect with a linear gradient
1077 void GradientFillLinear(const wxRect& rect,
1078 const wxColour& initialColour,
1079 const wxColour& destColour,
1080 wxDirection nDirection = wxEAST)
1081 { m_pimpl->DoGradientFillLinear(rect, initialColour, destColour, nDirection); }
1082
1083 bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const
1084 { return m_pimpl->DoGetPixel(x, y, col); }
1085 bool GetPixel(const wxPoint& pt, wxColour *col) const
1086 { return m_pimpl->DoGetPixel(pt.x, pt.y, col); }
1087
1088 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
1089 { m_pimpl->DoDrawLine(x1, y1, x2, y2); }
1090 void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
1091 { m_pimpl->DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
1092
1093 void CrossHair(wxCoord x, wxCoord y)
1094 { m_pimpl->DoCrossHair(x, y); }
1095 void CrossHair(const wxPoint& pt)
1096 { m_pimpl->DoCrossHair(pt.x, pt.y); }
1097
1098 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
1099 wxCoord xc, wxCoord yc)
1100 { m_pimpl->DoDrawArc(x1, y1, x2, y2, xc, yc); }
1101 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
1102 { m_pimpl->DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
1103
1104 void DrawCheckMark(wxCoord x, wxCoord y,
1105 wxCoord width, wxCoord height)
1106 { m_pimpl->DoDrawCheckMark(x, y, width, height); }
1107 void DrawCheckMark(const wxRect& rect)
1108 { m_pimpl->DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
1109
1110 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
1111 double sa, double ea)
1112 { m_pimpl->DoDrawEllipticArc(x, y, w, h, sa, ea); }
1113 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
1114 double sa, double ea)
1115 { m_pimpl->DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
1116
1117 void DrawPoint(wxCoord x, wxCoord y)
1118 { m_pimpl->DoDrawPoint(x, y); }
1119 void DrawPoint(const wxPoint& pt)
1120 { m_pimpl->DoDrawPoint(pt.x, pt.y); }
1121
1122 void DrawLines(int n, wxPoint points[],
1123 wxCoord xoffset = 0, wxCoord yoffset = 0)
1124 { m_pimpl->DoDrawLines(n, points, xoffset, yoffset); }
1125 void DrawLines(const wxPointList *list,
1126 wxCoord xoffset = 0, wxCoord yoffset = 0)
1127 { m_pimpl->DrawLines( list, xoffset, yoffset ); }
1128 #if WXWIN_COMPATIBILITY_2_8
1129 wxDEPRECATED( void DrawLines(const wxList *list,
1130 wxCoord xoffset = 0, wxCoord yoffset = 0) );
1131 #endif // WXWIN_COMPATIBILITY_2_8
1132
1133 void DrawPolygon(int n, wxPoint points[],
1134 wxCoord xoffset = 0, wxCoord yoffset = 0,
1135 wxPolygonFillMode fillStyle = wxODDEVEN_RULE)
1136 { m_pimpl->DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
1137 void DrawPolygon(const wxPointList *list,
1138 wxCoord xoffset = 0, wxCoord yoffset = 0,
1139 wxPolygonFillMode fillStyle = wxODDEVEN_RULE)
1140 { m_pimpl->DrawPolygon( list, xoffset, yoffset, fillStyle ); }
1141 void DrawPolyPolygon(int n, int count[], wxPoint points[],
1142 wxCoord xoffset = 0, wxCoord yoffset = 0,
1143 wxPolygonFillMode fillStyle = wxODDEVEN_RULE)
1144 { m_pimpl->DoDrawPolyPolygon(n, count, points, xoffset, yoffset, fillStyle); }
1145 #if WXWIN_COMPATIBILITY_2_8
1146 wxDEPRECATED( void DrawPolygon(const wxList *list,
1147 wxCoord xoffset = 0, wxCoord yoffset = 0,
1148 wxPolygonFillMode fillStyle = wxODDEVEN_RULE) );
1149 #endif // WXWIN_COMPATIBILITY_2_8
1150
1151 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1152 { m_pimpl->DoDrawRectangle(x, y, width, height); }
1153 void DrawRectangle(const wxPoint& pt, const wxSize& sz)
1154 { m_pimpl->DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); }
1155 void DrawRectangle(const wxRect& rect)
1156 { m_pimpl->DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); }
1157
1158 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
1159 double radius)
1160 { m_pimpl->DoDrawRoundedRectangle(x, y, width, height, radius); }
1161 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
1162 double radius)
1163 { m_pimpl->DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
1164 void DrawRoundedRectangle(const wxRect& r, double radius)
1165 { m_pimpl->DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
1166
1167 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
1168 { m_pimpl->DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
1169 void DrawCircle(const wxPoint& pt, wxCoord radius)
1170 { m_pimpl->DoDrawEllipse(pt.x - radius, pt.y - radius, 2*radius, 2*radius); }
1171
1172 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
1173 { m_pimpl->DoDrawEllipse(x, y, width, height); }
1174 void DrawEllipse(const wxPoint& pt, const wxSize& sz)
1175 { m_pimpl->DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); }
1176 void DrawEllipse(const wxRect& rect)
1177 { m_pimpl->DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); }
1178
1179 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
1180 { m_pimpl->DoDrawIcon(icon, x, y); }
1181 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
1182 { m_pimpl->DoDrawIcon(icon, pt.x, pt.y); }
1183
1184 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
1185 bool useMask = false)
1186 { m_pimpl->DoDrawBitmap(bmp, x, y, useMask); }
1187 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
1188 bool useMask = false)
1189 { m_pimpl->DoDrawBitmap(bmp, pt.x, pt.y, useMask); }
1190
1191 void DrawText(const wxString& text, wxCoord x, wxCoord y)
1192 { m_pimpl->DoDrawText(text, x, y); }
1193 void DrawText(const wxString& text, const wxPoint& pt)
1194 { m_pimpl->DoDrawText(text, pt.x, pt.y); }
1195
1196 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
1197 { m_pimpl->DoDrawRotatedText(text, x, y, angle); }
1198 void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)
1199 { m_pimpl->DoDrawRotatedText(text, pt.x, pt.y, angle); }
1200
1201 // this version puts both optional bitmap and the text into the given
1202 // rectangle and aligns is as specified by alignment parameter; it also
1203 // will emphasize the character with the given index if it is != -1 and
1204 // return the bounding rectangle if required
1205 void DrawLabel(const wxString& text,
1206 const wxBitmap& image,
1207 const wxRect& rect,
1208 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
1209 int indexAccel = -1,
1210 wxRect *rectBounding = NULL);
1211
1212 void DrawLabel(const wxString& text, const wxRect& rect,
1213 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
1214 int indexAccel = -1)
1215 { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); }
1216
1217 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
1218 wxDC *source, wxCoord xsrc, wxCoord ysrc,
1219 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
1220 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
1221 {
1222 return m_pimpl->DoBlit(xdest, ydest, width, height,
1223 source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
1224 }
1225 bool Blit(const wxPoint& destPt, const wxSize& sz,
1226 wxDC *source, const wxPoint& srcPt,
1227 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
1228 const wxPoint& srcPtMask = wxDefaultPosition)
1229 {
1230 return m_pimpl->DoBlit(destPt.x, destPt.y, sz.x, sz.y,
1231 source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
1232 }
1233
1234 bool StretchBlit(wxCoord dstX, wxCoord dstY,
1235 wxCoord dstWidth, wxCoord dstHeight,
1236 wxDC *source,
1237 wxCoord srcX, wxCoord srcY,
1238 wxCoord srcWidth, wxCoord srcHeight,
1239 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
1240 wxCoord srcMaskX = wxDefaultCoord, wxCoord srcMaskY = wxDefaultCoord)
1241 {
1242 return m_pimpl->DoStretchBlit(dstX, dstY, dstWidth, dstHeight,
1243 source, srcX, srcY, srcWidth, srcHeight, rop, useMask, srcMaskX, srcMaskY);
1244 }
1245 bool StretchBlit(const wxPoint& dstPt, const wxSize& dstSize,
1246 wxDC *source, const wxPoint& srcPt, const wxSize& srcSize,
1247 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
1248 const wxPoint& srcMaskPt = wxDefaultPosition)
1249 {
1250 return m_pimpl->DoStretchBlit(dstPt.x, dstPt.y, dstSize.x, dstSize.y,
1251 source, srcPt.x, srcPt.y, srcSize.x, srcSize.y, rop, useMask, srcMaskPt.x, srcMaskPt.y);
1252 }
1253
1254 wxBitmap GetAsBitmap(const wxRect *subrect = (const wxRect *) NULL) const
1255 {
1256 return m_pimpl->DoGetAsBitmap(subrect);
1257 }
1258
1259 #if wxUSE_SPLINES
1260 void DrawSpline(wxCoord x1, wxCoord y1,
1261 wxCoord x2, wxCoord y2,
1262 wxCoord x3, wxCoord y3)
1263 { m_pimpl->DrawSpline(x1,y1,x2,y2,x3,y3); }
1264 void DrawSpline(int n, wxPoint points[])
1265 { m_pimpl->DrawSpline(n,points); }
1266 void DrawSpline(const wxPointList *points)
1267 { m_pimpl->DrawSpline(points); }
1268 #endif // wxUSE_SPLINES
1269
1270
1271 #if WXWIN_COMPATIBILITY_2_8
1272 // for compatibility with the old code when wxCoord was long everywhere
1273 wxDEPRECATED( void GetTextExtent(const wxString& string,
1274 long *x, long *y,
1275 long *descent = NULL,
1276 long *externalLeading = NULL,
1277 const wxFont *theFont = NULL) const );
1278 wxDEPRECATED( void GetLogicalOrigin(long *x, long *y) const );
1279 wxDEPRECATED( void GetDeviceOrigin(long *x, long *y) const );
1280 wxDEPRECATED( void GetClippingBox(long *x, long *y, long *w, long *h) const );
1281
1282 wxDEPRECATED( void DrawObject(wxDrawObject* drawobject) );
1283 #endif // WXWIN_COMPATIBILITY_2_8
1284
1285 #ifdef __WXMSW__
1286 // GetHDC() is the simplest way to retrieve an HDC From a wxDC but only
1287 // works if this wxDC is GDI-based and fails for GDI+ contexts (and
1288 // anything else without HDC, e.g. wxPostScriptDC)
1289 WXHDC GetHDC() const;
1290
1291 // don't use these methods manually, use GetTempHDC() instead
1292 virtual WXHDC AcquireHDC() { return GetHDC(); }
1293 virtual void ReleaseHDC(WXHDC WXUNUSED(hdc)) { }
1294
1295 // helper class holding the result of GetTempHDC() with std::auto_ptr<>-like
1296 // semantics, i.e. it is moved when copied
1297 class TempHDC
1298 {
1299 public:
1300 TempHDC(wxDC& dc)
1301 : m_dc(dc),
1302 m_hdc(dc.AcquireHDC())
1303 {
1304 }
1305
1306 TempHDC(const TempHDC& thdc)
1307 : m_dc(thdc.m_dc),
1308 m_hdc(thdc.m_hdc)
1309 {
1310 const_cast<TempHDC&>(thdc).m_hdc = 0;
1311 }
1312
1313 ~TempHDC()
1314 {
1315 if ( m_hdc )
1316 m_dc.ReleaseHDC(m_hdc);
1317 }
1318
1319 WXHDC GetHDC() const { return m_hdc; }
1320
1321 private:
1322 wxDC& m_dc;
1323 WXHDC m_hdc;
1324
1325 wxDECLARE_NO_ASSIGN_CLASS(TempHDC);
1326 };
1327
1328 // GetTempHDC() also works for wxGCDC (but still not for wxPostScriptDC &c)
1329 TempHDC GetTempHDC() { return TempHDC(*this); }
1330 #endif // __WXMSW__
1331
1332 protected:
1333 // ctor takes ownership of the pointer
1334 wxDC(wxDCImpl *pimpl) : m_pimpl(pimpl) { }
1335
1336 wxDCImpl * const m_pimpl;
1337
1338 private:
1339 DECLARE_ABSTRACT_CLASS(wxDC)
1340 wxDECLARE_NO_COPY_CLASS(wxDC);
1341 };
1342
1343 // ----------------------------------------------------------------------------
1344 // helper class: you can use it to temporarily change the DC text colour and
1345 // restore it automatically when the object goes out of scope
1346 // ----------------------------------------------------------------------------
1347
1348 class WXDLLIMPEXP_CORE wxDCTextColourChanger
1349 {
1350 public:
1351 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
1352
1353 wxDCTextColourChanger(wxDC& dc, const wxColour& col) : m_dc(dc)
1354 {
1355 Set(col);
1356 }
1357
1358 ~wxDCTextColourChanger()
1359 {
1360 if ( m_colFgOld.IsOk() )
1361 m_dc.SetTextForeground(m_colFgOld);
1362 }
1363
1364 void Set(const wxColour& col)
1365 {
1366 if ( !m_colFgOld.IsOk() )
1367 m_colFgOld = m_dc.GetTextForeground();
1368 m_dc.SetTextForeground(col);
1369 }
1370
1371 private:
1372 wxDC& m_dc;
1373
1374 wxColour m_colFgOld;
1375
1376 wxDECLARE_NO_COPY_CLASS(wxDCTextColourChanger);
1377 };
1378
1379 // ----------------------------------------------------------------------------
1380 // helper class: you can use it to temporarily change the DC pen and
1381 // restore it automatically when the object goes out of scope
1382 // ----------------------------------------------------------------------------
1383
1384 class WXDLLIMPEXP_CORE wxDCPenChanger
1385 {
1386 public:
1387 wxDCPenChanger(wxDC& dc, const wxPen& pen) : m_dc(dc), m_penOld(dc.GetPen())
1388 {
1389 m_dc.SetPen(pen);
1390 }
1391
1392 ~wxDCPenChanger()
1393 {
1394 if ( m_penOld.IsOk() )
1395 m_dc.SetPen(m_penOld);
1396 }
1397
1398 private:
1399 wxDC& m_dc;
1400
1401 wxPen m_penOld;
1402
1403 wxDECLARE_NO_COPY_CLASS(wxDCPenChanger);
1404 };
1405
1406 // ----------------------------------------------------------------------------
1407 // helper class: you can use it to temporarily change the DC brush and
1408 // restore it automatically when the object goes out of scope
1409 // ----------------------------------------------------------------------------
1410
1411 class WXDLLIMPEXP_CORE wxDCBrushChanger
1412 {
1413 public:
1414 wxDCBrushChanger(wxDC& dc, const wxBrush& brush) : m_dc(dc), m_brushOld(dc.GetBrush())
1415 {
1416 m_dc.SetBrush(brush);
1417 }
1418
1419 ~wxDCBrushChanger()
1420 {
1421 if ( m_brushOld.IsOk() )
1422 m_dc.SetBrush(m_brushOld);
1423 }
1424
1425 private:
1426 wxDC& m_dc;
1427
1428 wxBrush m_brushOld;
1429
1430 wxDECLARE_NO_COPY_CLASS(wxDCBrushChanger);
1431 };
1432
1433 // ----------------------------------------------------------------------------
1434 // another small helper class: sets the clipping region in its ctor and
1435 // destroys it in the dtor
1436 // ----------------------------------------------------------------------------
1437
1438 class WXDLLIMPEXP_CORE wxDCClipper
1439 {
1440 public:
1441 wxDCClipper(wxDC& dc, const wxRegion& r) : m_dc(dc)
1442 { dc.SetClippingRegion(r.GetBox()); }
1443 wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc)
1444 { dc.SetClippingRegion(r.x, r.y, r.width, r.height); }
1445 wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc)
1446 { dc.SetClippingRegion(x, y, w, h); }
1447
1448 ~wxDCClipper() { m_dc.DestroyClippingRegion(); }
1449
1450 private:
1451 wxDC& m_dc;
1452
1453 wxDECLARE_NO_COPY_CLASS(wxDCClipper);
1454 };
1455
1456 // ----------------------------------------------------------------------------
1457 // helper class: you can use it to temporarily change the DC font and
1458 // restore it automatically when the object goes out of scope
1459 // ----------------------------------------------------------------------------
1460
1461 class WXDLLIMPEXP_CORE wxDCFontChanger
1462 {
1463 public:
1464 wxDCFontChanger(wxDC& dc)
1465 : m_dc(dc), m_fontOld()
1466 {
1467 }
1468
1469 wxDCFontChanger(wxDC& dc, const wxFont& font)
1470 : m_dc(dc), m_fontOld(dc.GetFont())
1471 {
1472 m_dc.SetFont(font);
1473 }
1474
1475 void Set(const wxFont& font)
1476 {
1477 if ( !m_fontOld.IsOk() )
1478 m_fontOld = m_dc.GetFont();
1479 m_dc.SetFont(font);
1480 }
1481
1482 ~wxDCFontChanger()
1483 {
1484 if ( m_fontOld.IsOk() )
1485 m_dc.SetFont(m_fontOld);
1486 }
1487
1488 private:
1489 wxDC& m_dc;
1490
1491 wxFont m_fontOld;
1492
1493 wxDECLARE_NO_COPY_CLASS(wxDCFontChanger);
1494 };
1495
1496
1497 #endif // _WX_DC_H_BASE_