1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DC_H_BASE_
13 #define _WX_DC_H_BASE_
16 #pragma interface "dcbase.h"
19 // ----------------------------------------------------------------------------
20 // headers which we must include here
21 // ----------------------------------------------------------------------------
23 #include "wx/object.h" // the base class
25 #include "wx/cursor.h" // we have member variables of these classes
26 #include "wx/font.h" // so we can't do without them
27 #include "wx/colour.h"
30 #include "wx/palette.h"
32 #include "wx/list.h" // we use wxList in inline functions
34 // ---------------------------------------------------------------------------
36 // ---------------------------------------------------------------------------
38 WXDLLEXPORT_DATA(extern int) wxPageNumber
;
40 // ---------------------------------------------------------------------------
41 // wxDC is the device context - object on which any drawing is done
42 // ---------------------------------------------------------------------------
44 class WXDLLEXPORT wxDCBase
: public wxObject
46 DECLARE_ABSTRACT_CLASS(wxDCBase
)
54 m_minX
= m_minY
= m_maxX
= m_maxY
= 0;
56 m_signX
= m_signY
= 1;
58 m_logicalOriginX
= m_logicalOriginY
=
59 m_deviceOriginX
= m_deviceOriginY
= 0;
61 m_logicalScaleX
= m_logicalScaleY
=
62 m_userScaleX
= m_userScaleY
=
63 m_scaleX
= m_scaleY
= 1.0;
65 m_logicalFunction
= -1;
67 m_backgroundMode
= wxTRANSPARENT
;
69 m_mappingMode
= wxMM_TEXT
;
71 m_backgroundBrush
= *wxTRANSPARENT_BRUSH
;
73 m_textForegroundColour
= *wxBLACK
;
74 m_textBackgroundColour
= *wxWHITE
;
76 m_colour
= wxColourDisplay();
81 virtual void BeginDrawing() { }
82 virtual void EndDrawing() { }
87 void FloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
88 int style
= wxFLOOD_SURFACE
)
89 { DoFloodFill(x
, y
, col
, style
); }
90 void FloodFill(const wxPoint
& pt
, const wxColour
& col
,
91 int style
= wxFLOOD_SURFACE
)
92 { DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
94 bool GetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
95 { return DoGetPixel(x
, y
, col
); }
96 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
97 { return DoGetPixel(pt
.x
, pt
.y
, col
); }
99 void DrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
100 { DoDrawLine(x1
, y1
, x2
, y2
); }
101 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
102 { DoDrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
); }
104 void CrossHair(wxCoord x
, wxCoord y
)
105 { DoCrossHair(x
, y
); }
106 void CrossHair(const wxPoint
& pt
)
107 { DoCrossHair(pt
.x
, pt
.y
); }
109 void DrawArc(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
,
110 wxCoord xc
, wxCoord yc
)
111 { DoDrawArc(x1
, y1
, x2
, y2
, xc
, yc
); }
112 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
113 { DoDrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
); }
115 void DrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
116 double sa
, double ea
)
117 { DoDrawEllipticArc(x
, y
, w
, h
, sa
, ea
); }
118 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
119 double sa
, double ea
)
120 { DoDrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
); }
122 void DrawPoint(wxCoord x
, wxCoord y
)
123 { DoDrawPoint(x
, y
); }
124 void DrawPoint(const wxPoint
& pt
)
125 { DoDrawPoint(pt
.x
, pt
.y
); }
127 void DrawLines(int n
, wxPoint points
[],
128 wxCoord xoffset
= 0, wxCoord yoffset
= 0)
129 { DoDrawLines(n
, points
, xoffset
, yoffset
); }
130 void DrawLines(const wxList
*list
,
131 wxCoord xoffset
= 0, wxCoord yoffset
= 0);
133 void DrawPolygon(int n
, wxPoint points
[],
134 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
135 int fillStyle
= wxODDEVEN_RULE
)
136 { DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
138 void DrawPolygon(const wxList
*list
,
139 wxCoord xoffset
= 0, wxCoord yoffset
= 0,
140 int fillStyle
= wxODDEVEN_RULE
);
142 void DrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
143 { DoDrawRectangle(x
, y
, width
, height
); }
144 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
145 { DoDrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
146 void DrawRectangle(const wxRect
& rect
)
147 { DoDrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
149 void DrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
,
151 { DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
152 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
154 { DoDrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
); }
155 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
156 { DoDrawRoundedRectangle(r
.x
, r
.y
, r
.width
, r
.height
, radius
); }
158 void DrawCircle(wxCoord x
, wxCoord y
, wxCoord radius
)
159 { DoDrawEllipse(x
- radius
, y
- radius
, 2*radius
, 2*radius
); }
160 void DrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
161 { DoDrawEllipse(x
, y
, width
, height
); }
162 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
163 { DoDrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
164 void DrawEllipse(const wxRect
& rect
)
165 { DoDrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
167 void DrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
168 { DoDrawIcon(icon
, x
, y
); }
169 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
170 { DoDrawIcon(icon
, pt
.x
, pt
.y
); }
172 void DrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
173 bool useMask
= FALSE
)
174 { DoDrawBitmap(bmp
, x
, y
, useMask
); }
175 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
176 bool useMask
= FALSE
)
177 { DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
179 void DrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
180 { DoDrawText(text
, x
, y
); }
181 void DrawText(const wxString
& text
, const wxPoint
& pt
)
182 { DoDrawText(text
, pt
.x
, pt
.y
); }
184 bool Blit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
185 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
186 int rop
= wxCOPY
, bool useMask
= FALSE
)
188 return DoBlit(xdest
, ydest
, width
, height
,
189 source
, xsrc
, ysrc
, rop
, useMask
);
191 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
192 wxDC
*source
, const wxPoint
& srcPt
,
193 int rop
= wxCOPY
, bool useMask
= FALSE
)
195 return DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
196 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
);
200 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
201 void DrawSpline(wxCoord x1
, wxCoord y1
,
202 wxCoord x2
, wxCoord y2
,
203 wxCoord x3
, wxCoord y3
);
204 void DrawSpline(int n
, wxPoint points
[]);
206 void DrawSpline(wxList
*points
) { DoDrawSpline(points
); }
207 #endif // wxUSE_SPLINES
209 // global DC operations
210 // --------------------
212 virtual void Clear() = 0;
214 virtual bool StartDoc(const wxString
& WXUNUSED(message
)) { return TRUE
; }
215 virtual void EndDoc() { }
217 virtual void StartPage() { }
218 virtual void EndPage() { }
220 // set objects to use for drawing
221 // ------------------------------
223 virtual void SetFont(const wxFont
& font
) = 0;
224 virtual void SetPen(const wxPen
& pen
) = 0;
225 virtual void SetBrush(const wxBrush
& brush
) = 0;
226 virtual void SetBackground(const wxBrush
& brush
) = 0;
227 virtual void SetBackgroundMode(int mode
) = 0;
228 virtual void SetPalette(const wxPalette
& palette
) = 0;
233 void SetClippingRegion(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
234 { DoSetClippingRegion(x
, y
, width
, height
); }
235 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
236 { DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
237 void SetClippingRegion(const wxRect
& rect
)
238 { DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
239 void SetClippingRegion(const wxRegion
& region
)
240 { DoSetClippingRegionAsRegion(region
); }
242 virtual void DestroyClippingRegion() = 0;
244 void GetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
245 { DoGetClippingBox(x
, y
, w
, h
); }
246 void GetClippingBox(wxRect
& rect
) const
248 // Necessary to use intermediate variables for 16-bit compilation
250 DoGetClippingBox(&x
, &y
, &w
, &h
);
251 rect
.x
= x
; rect
.y
= y
; rect
.width
= w
; rect
.height
= h
;
257 virtual wxCoord
GetCharHeight() const = 0;
258 virtual wxCoord
GetCharWidth() const = 0;
260 void GetTextExtent(const wxString
& string
,
261 wxCoord
*x
, wxCoord
*y
,
262 wxCoord
*descent
= NULL
,
263 wxCoord
*externalLeading
= NULL
,
264 wxFont
*theFont
= NULL
) const
265 { DoGetTextExtent(string
, x
, y
, descent
, externalLeading
, theFont
); }
267 // size and resolution
268 // -------------------
271 void GetSize(int *width
, int *height
) const
272 { DoGetSize(width
, height
); }
273 wxSize
GetSize() const
282 void GetSizeMM(int* width
, int* height
) const
283 { DoGetSizeMM(width
, height
); }
284 wxSize
GetSizeMM() const
292 // coordinates conversions
293 // -----------------------
295 // This group of functions does actual conversion of the input, as you'd
297 wxCoord
DeviceToLogicalX(wxCoord x
) const;
298 wxCoord
DeviceToLogicalY(wxCoord y
) const;
299 wxCoord
DeviceToLogicalXRel(wxCoord x
) const;
300 wxCoord
DeviceToLogicalYRel(wxCoord y
) const;
301 wxCoord
LogicalToDeviceX(wxCoord x
) const;
302 wxCoord
LogicalToDeviceY(wxCoord y
) const;
303 wxCoord
LogicalToDeviceXRel(wxCoord x
) const;
304 wxCoord
LogicalToDeviceYRel(wxCoord y
) const;
306 // query DC capabilities
307 // ---------------------
309 virtual bool CanDrawBitmap() const = 0;
310 virtual bool CanGetTextExtent() const = 0;
313 virtual int GetDepth() const = 0;
315 // Resolution in Pixels per inch
316 virtual wxSize
GetPPI() const = 0;
318 virtual bool Ok() const { return m_ok
; }
324 const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
325 const wxBrush
& GetBrush() const { return m_brush
; }
326 const wxFont
& GetFont() const { return m_font
; }
327 const wxPen
& GetPen() const { return m_pen
; }
328 const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
329 const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
332 wxBrush
& GetBackground() { return m_backgroundBrush
; }
333 wxBrush
& GetBrush() { return m_brush
; }
334 wxFont
& GetFont() { return m_font
; }
335 wxPen
& GetPen() { return m_pen
; }
336 wxColour
& GetTextBackground() { return m_textBackgroundColour
; }
337 wxColour
& GetTextForeground() { return m_textForegroundColour
; }
339 virtual void SetTextForeground(const wxColour
& colour
)
340 { m_textForegroundColour
= colour
; }
341 virtual void SetTextBackground(const wxColour
& colour
)
342 { m_textBackgroundColour
= colour
; }
344 int GetMapMode() const { return m_mappingMode
; }
345 virtual void SetMapMode(int mode
) = 0;
347 virtual void GetUserScale(double *x
, double *y
) const
349 if ( x
) *x
= m_userScaleX
;
350 if ( y
) *y
= m_userScaleY
;
352 virtual void SetUserScale(double x
, double y
) = 0;
354 virtual void GetLogicalScale(double *x
, double *y
)
356 if ( x
) *x
= m_logicalScaleX
;
357 if ( y
) *y
= m_logicalScaleY
;
359 virtual void SetLogicalScale(double x
, double y
)
365 void GetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
366 { DoGetLogicalOrigin(x
, y
); }
367 wxPoint
GetLogicalOrigin() const
368 { wxCoord x
, y
; DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
369 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
) = 0;
371 void GetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
372 { DoGetDeviceOrigin(x
, y
); }
373 wxPoint
GetDeviceOrigin() const
374 { wxCoord x
, y
; DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
375 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
) = 0;
377 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
) = 0;
379 int GetLogicalFunction() const { return m_logicalFunction
; }
380 virtual void SetLogicalFunction(int function
) = 0;
382 // Sometimes we need to override optimization, e.g. if other software is
383 // drawing onto our surface and we can't be sure of who's done what.
385 // FIXME: is this (still) used?
386 virtual void SetOptimization(bool WXUNUSED(opt
)) { }
387 virtual bool GetOptimization() { return FALSE
; }
392 virtual void CalcBoundingBox(wxCoord x
, wxCoord y
)
394 if ( x
< m_minX
) m_minX
= x
;
395 if ( y
< m_minY
) m_minY
= y
;
396 if ( x
> m_maxX
) m_maxX
= x
;
397 if ( y
> m_maxY
) m_maxY
= y
;
400 // Get the final bounding box of the PostScript or Metafile picture.
401 wxCoord
MinX() const { return m_minX
; }
402 wxCoord
MaxX() const { return m_maxX
; }
403 wxCoord
MinY() const { return m_minY
; }
404 wxCoord
MaxY() const { return m_maxY
; }
406 // misc old functions
407 // ------------------
409 // for compatibility with the old code when wxCoord was long everywhere
411 void GetTextExtent(const wxString
& string
,
413 long *descent
= NULL
,
414 long *externalLeading
= NULL
,
415 wxFont
*theFont
= NULL
) const
417 wxCoord x2
, y2
, descent2
, externalLeading2
;
418 DoGetTextExtent(string
, &x2
, &y2
,
419 &descent2
, &externalLeading2
,
427 if ( externalLeading
)
428 *externalLeading
= externalLeading2
;
431 void GetLogicalOrigin(long *x
, long *y
) const
434 DoGetLogicalOrigin(&x2
, &y2
);
441 void GetDeviceOrigin(long *x
, long *y
) const
444 DoGetDeviceOrigin(&x2
, &y2
);
450 void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const
453 DoGetClippingBox(&xx
, &yy
, &ww
, &hh
);
461 #if WXWIN_COMPATIBILITY
462 virtual void SetColourMap(const wxPalette
& palette
) { SetPalette(palette
); }
463 void GetTextExtent(const wxString
& string
, float *x
, float *y
,
464 float *descent
= NULL
, float *externalLeading
= NULL
,
465 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const ;
466 void GetSize(float* width
, float* height
) const { int w
, h
; GetSize(& w
, & h
); *width
= w
; *height
= h
; }
467 void GetSizeMM(float *width
, float *height
) const { long w
, h
; GetSizeMM(& w
, & h
); *width
= (float) w
; *height
= (float) h
; }
468 #endif // WXWIN_COMPATIBILITY
471 // the pure virtual functions which should be implemented by wxDC
472 virtual void DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
473 int style
= wxFLOOD_SURFACE
) = 0;
475 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const = 0;
477 virtual void DoDrawPoint(wxCoord x
, wxCoord y
) = 0;
478 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
) = 0;
480 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
481 wxCoord x2
, wxCoord y2
,
482 wxCoord xc
, wxCoord yc
) = 0;
483 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
484 double sa
, double ea
) = 0;
486 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
) = 0;
487 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
488 wxCoord width
, wxCoord height
,
490 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
,
491 wxCoord width
, wxCoord height
) = 0;
493 virtual void DoCrossHair(wxCoord x
, wxCoord y
) = 0;
495 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
) = 0;
496 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
497 bool useMask
= FALSE
) = 0;
499 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
) = 0;
501 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
,
502 wxCoord width
, wxCoord height
,
503 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
504 int rop
= wxCOPY
, bool useMask
= FALSE
) = 0;
506 virtual void DoGetSize(int *width
, int *height
) const = 0;
507 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
509 virtual void DoDrawLines(int n
, wxPoint points
[],
510 wxCoord xoffset
, wxCoord yoffset
) = 0;
511 virtual void DoDrawPolygon(int n
, wxPoint points
[],
512 wxCoord xoffset
, wxCoord yoffset
,
513 int fillStyle
= wxODDEVEN_RULE
) = 0;
515 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
516 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
517 wxCoord width
, wxCoord height
) = 0;
519 // FIXME are these functions really different?
520 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
521 wxCoord
*w
, wxCoord
*h
)
522 { DoGetClippingBox(x
, y
, w
, h
); }
523 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
524 wxCoord
*w
, wxCoord
*h
) const
528 if ( x
) *x
= m_clipX1
;
529 if ( y
) *y
= m_clipY1
;
530 if ( w
) *w
= m_clipX2
- m_clipX1
;
531 if ( h
) *h
= m_clipY2
- m_clipY1
;
535 *x
= *y
= *w
= *h
= 0;
539 virtual void DoGetLogicalOrigin(wxCoord
*x
, wxCoord
*y
) const
541 if ( x
) *x
= m_logicalOriginX
;
542 if ( y
) *y
= m_logicalOriginY
;
545 virtual void DoGetDeviceOrigin(wxCoord
*x
, wxCoord
*y
) const
547 if ( x
) *x
= m_deviceOriginX
;
548 if ( y
) *y
= m_deviceOriginY
;
551 virtual void DoGetTextExtent(const wxString
& string
,
552 wxCoord
*x
, wxCoord
*y
,
553 wxCoord
*descent
= NULL
,
554 wxCoord
*externalLeading
= NULL
,
555 wxFont
*theFont
= NULL
) const = 0;
558 virtual void DoDrawSpline(wxList
*points
) = 0;
566 bool m_isInteractive
:1;
568 // coordinate system variables
570 // TODO short descriptions of what exactly they are would be nice...
572 wxCoord m_logicalOriginX
, m_logicalOriginY
;
573 wxCoord m_deviceOriginX
, m_deviceOriginY
;
575 double m_logicalScaleX
, m_logicalScaleY
;
576 double m_userScaleX
, m_userScaleY
;
577 double m_scaleX
, m_scaleY
;
579 // Used by SetAxisOrientation() to invert the axes
580 int m_signX
, m_signY
;
582 // bounding and clipping boxes
583 wxCoord m_minX
, m_minY
, m_maxX
, m_maxY
;
584 wxCoord m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
586 int m_logicalFunction
;
587 int m_backgroundMode
;
593 wxBrush m_backgroundBrush
;
594 wxColour m_textForegroundColour
;
595 wxColour m_textBackgroundColour
;
600 DECLARE_NO_COPY_CLASS(wxDCBase
);
603 // ----------------------------------------------------------------------------
604 // now include the declaration of wxDC class
605 // ----------------------------------------------------------------------------
607 #if defined(__WXMSW__)
608 #include "wx/msw/dc.h"
609 #elif defined(__WXMOTIF__)
610 #include "wx/motif/dc.h"
611 #elif defined(__WXGTK__)
612 #include "wx/gtk/dc.h"
613 #elif defined(__WXQT__)
614 #include "wx/qt/dc.h"
615 #elif defined(__WXMAC__)
616 #include "wx/mac/dc.h"
617 #elif defined(__WXPM__)
618 #include "wx/os2/dc.h"
619 #elif defined(__WXSTUBS__)
620 #include "wx/stubs/dc.h"