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 // type which should be used (whenever possible, i.e. as long as it doesn't
39 // break compatibility) for screen coordinates
42 // ---------------------------------------------------------------------------
44 // ---------------------------------------------------------------------------
46 WXDLLEXPORT_DATA(extern int) wxPageNumber
;
48 // ---------------------------------------------------------------------------
49 // wxDC is the device context - object on which any drawing is done
50 // ---------------------------------------------------------------------------
52 class WXDLLEXPORT wxDCBase
: public wxObject
54 DECLARE_ABSTRACT_CLASS(wxDCBase
)
62 m_minX
= m_minY
= m_maxX
= m_maxY
= 0;
64 m_signX
= m_signY
= 1;
66 m_logicalOriginX
= m_logicalOriginY
=
67 m_deviceOriginX
= m_deviceOriginY
= 0;
69 m_logicalScaleX
= m_logicalScaleY
=
70 m_userScaleX
= m_userScaleY
=
71 m_scaleX
= m_scaleY
= 1.0;
73 m_logicalFunction
= -1;
75 m_backgroundMode
= wxTRANSPARENT
;
77 m_mappingMode
= wxMM_TEXT
;
79 m_backgroundBrush
= *wxTRANSPARENT_BRUSH
;
81 m_textForegroundColour
= *wxBLACK
;
82 m_textBackgroundColour
= *wxWHITE
;
84 m_colour
= wxColourDisplay();
89 virtual void BeginDrawing() { }
90 virtual void EndDrawing() { }
95 void FloodFill(long x
, long y
, const wxColour
& col
,
96 int style
= wxFLOOD_SURFACE
)
97 { DoFloodFill(x
, y
, col
, style
); }
98 void FloodFill(const wxPoint
& pt
, const wxColour
& col
,
99 int style
= wxFLOOD_SURFACE
)
100 { DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
102 bool GetPixel(long x
, long y
, wxColour
*col
) const
103 { return DoGetPixel(x
, y
, col
); }
104 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
105 { return DoGetPixel(pt
.x
, pt
.y
, col
); }
107 void DrawLine(long x1
, long y1
, long x2
, long y2
)
108 { DoDrawLine(x1
, y1
, x2
, y2
); }
109 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
110 { DoDrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
); }
112 void CrossHair(long x
, long y
)
113 { DoCrossHair(x
, y
); }
114 void CrossHair(const wxPoint
& pt
)
115 { DoCrossHair(pt
.x
, pt
.y
); }
117 void DrawArc(long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
118 { DoDrawArc(x1
, y1
, x2
, y2
, xc
, yc
); }
119 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
120 { DoDrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
); }
122 void DrawEllipticArc(long x
, long y
, long w
, long h
, double sa
, double ea
)
123 { DoDrawEllipticArc(x
, y
, w
, h
, sa
, ea
); }
124 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
125 double sa
, double ea
)
126 { DoDrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
); }
128 void DrawPoint(long x
, long y
)
129 { DoDrawPoint(x
, y
); }
130 void DrawPoint(const wxPoint
& pt
)
131 { DoDrawPoint(pt
.x
, pt
.y
); }
133 void DrawLines(int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0)
134 { DoDrawLines(n
, points
, xoffset
, yoffset
); }
135 void DrawLines(const wxList
*list
, long xoffset
= 0, long yoffset
= 0);
137 void DrawPolygon(int n
, wxPoint points
[],
138 long xoffset
= 0, long yoffset
= 0,
139 int fillStyle
= wxODDEVEN_RULE
)
140 { DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
142 void DrawPolygon(const wxList
*list
,
143 long xoffset
= 0, long yoffset
= 0,
144 int fillStyle
= wxODDEVEN_RULE
);
146 void DrawRectangle(long x
, long y
, long width
, long height
)
147 { DoDrawRectangle(x
, y
, width
, height
); }
148 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
149 { DoDrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
150 void DrawRectangle(const wxRect
& rect
)
151 { DoDrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
153 void DrawRoundedRectangle(long x
, long y
, long width
, long height
,
155 { DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
156 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
158 { DoDrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
); }
159 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
160 { DoDrawRoundedRectangle(r
.x
, r
.y
, r
.width
, r
.height
, radius
); }
162 void DrawCircle(long x
, long y
, long radius
)
163 { DoDrawEllipse(x
- radius
, y
- radius
, 2*radius
, 2*radius
); }
164 void DrawEllipse(long x
, long y
, long width
, long height
)
165 { DoDrawEllipse(x
, y
, width
, height
); }
166 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
167 { DoDrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
168 void DrawEllipse(const wxRect
& rect
)
169 { DoDrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
171 void DrawIcon(const wxIcon
& icon
, long x
, long y
)
172 { DoDrawIcon(icon
, x
, y
); }
173 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
174 { DoDrawIcon(icon
, pt
.x
, pt
.y
); }
176 void DrawBitmap(const wxBitmap
&bmp
, long x
, long y
, bool useMask
= FALSE
)
177 { DoDrawBitmap(bmp
, x
, y
, useMask
); }
178 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
179 bool useMask
= FALSE
)
180 { DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
182 void DrawText(const wxString
& text
, long x
, long y
)
183 { DoDrawText(text
, x
, y
); }
184 void DrawText(const wxString
& text
, const wxPoint
& pt
)
185 { DoDrawText(text
, pt
.x
, pt
.y
); }
187 bool Blit(long xdest
, long ydest
, long width
, long height
,
188 wxDC
*source
, long xsrc
, long ysrc
,
189 int rop
= wxCOPY
, bool useMask
= FALSE
)
191 return DoBlit(xdest
, ydest
, width
, height
,
192 source
, xsrc
, ysrc
, rop
, useMask
);
194 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
195 wxDC
*source
, const wxPoint
& srcPt
,
196 int rop
= wxCOPY
, bool useMask
= FALSE
)
198 return DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
199 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
);
203 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
204 void DrawSpline(long x1
, long y1
, long x2
, long y2
, long x3
, long y3
);
205 void DrawSpline(int n
, wxPoint points
[]);
207 void DrawSpline(wxList
*points
) { DoDrawSpline(points
); }
208 #endif // wxUSE_SPLINES
210 // global DC operations
211 // --------------------
213 virtual void Clear() = 0;
215 virtual bool StartDoc(const wxString
& WXUNUSED(message
)) { return TRUE
; }
216 virtual void EndDoc() { }
218 virtual void StartPage() { }
219 virtual void EndPage() { }
221 // set objects to use for drawing
222 // ------------------------------
224 virtual void SetFont(const wxFont
& font
) = 0;
225 virtual void SetPen(const wxPen
& pen
) = 0;
226 virtual void SetBrush(const wxBrush
& brush
) = 0;
227 virtual void SetBackground(const wxBrush
& brush
) = 0;
228 virtual void SetBackgroundMode(int mode
) = 0;
229 virtual void SetPalette(const wxPalette
& palette
) = 0;
234 void SetClippingRegion(long x
, long y
, long width
, long height
)
235 { DoSetClippingRegion(x
, y
, width
, height
); }
236 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
237 { DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
238 void SetClippingRegion(const wxRect
& rect
)
239 { DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
240 void SetClippingRegion(const wxRegion
& region
)
241 { DoSetClippingRegionAsRegion(region
); }
243 virtual void DestroyClippingRegion() = 0;
245 void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const
246 { DoGetClippingBox(x
, y
, w
, h
); }
247 void GetClippingBox(wxRect
& rect
) const
248 { DoGetClippingBox(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
); }
253 virtual long GetCharHeight() const = 0;
254 virtual long GetCharWidth() const = 0;
255 virtual void GetTextExtent(const wxString
& string
,
257 long *descent
= NULL
,
258 long *externalLeading
= NULL
,
259 wxFont
*theFont
= NULL
) const = 0;
261 // size and resolution
262 // -------------------
265 void GetSize(int *width
, int *height
) const
266 { DoGetSize(width
, height
); }
267 wxSize
GetSize() const
276 void GetSizeMM(int* width
, int* height
) const
277 { DoGetSizeMM(width
, height
); }
278 wxSize
GetSizeMM() const
286 // coordinates conversions
287 // -----------------------
289 // This group of functions does actual conversion of the input, as you'd
291 long DeviceToLogicalX(long x
) const;
292 long DeviceToLogicalY(long y
) const;
293 long DeviceToLogicalXRel(long x
) const;
294 long DeviceToLogicalYRel(long y
) const;
295 long LogicalToDeviceX(long x
) const;
296 long LogicalToDeviceY(long y
) const;
297 long LogicalToDeviceXRel(long x
) const;
298 long LogicalToDeviceYRel(long y
) const;
300 // query DC capabilities
301 // ---------------------
303 virtual bool CanDrawBitmap() const = 0;
304 virtual bool CanGetTextExtent() const = 0;
307 virtual int GetDepth() const = 0;
309 // Resolution in Pixels per inch
310 virtual wxSize
GetPPI() const = 0;
312 virtual bool Ok() const { return m_ok
; }
318 const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
319 const wxBrush
& GetBrush() const { return m_brush
; }
320 const wxFont
& GetFont() const { return m_font
; }
321 const wxPen
& GetPen() const { return m_pen
; }
322 const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
323 const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
326 wxBrush
& GetBackground() { return m_backgroundBrush
; }
327 wxBrush
& GetBrush() { return m_brush
; }
328 wxFont
& GetFont() { return m_font
; }
329 wxPen
& GetPen() { return m_pen
; }
330 wxColour
& GetTextBackground() { return m_textBackgroundColour
; }
331 wxColour
& GetTextForeground() { return m_textForegroundColour
; }
333 virtual void SetTextForeground(const wxColour
& colour
)
334 { m_textForegroundColour
= colour
; }
335 virtual void SetTextBackground(const wxColour
& colour
)
336 { m_textBackgroundColour
= colour
; }
338 int GetMapMode() const { return m_mappingMode
; }
339 virtual void SetMapMode(int mode
) = 0;
341 virtual void GetUserScale(double *x
, double *y
) const
343 if ( x
) *x
= m_userScaleX
;
344 if ( y
) *y
= m_userScaleY
;
346 virtual void SetUserScale(double x
, double y
) = 0;
348 virtual void GetLogicalScale(double *x
, double *y
)
350 if ( x
) *x
= m_logicalScaleX
;
351 if ( y
) *y
= m_logicalScaleY
;
353 virtual void SetLogicalScale(double x
, double y
)
359 void GetLogicalOrigin(long *x
, long *y
) const
360 { DoGetLogicalOrigin(x
, y
); }
361 wxPoint
GetLogicalOrigin() const
362 { long x
, y
; DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
363 virtual void SetLogicalOrigin(long x
, long y
) = 0;
365 void GetDeviceOrigin(long *x
, long *y
) const
366 { DoGetDeviceOrigin(x
, y
); }
367 wxPoint
GetDeviceOrigin() const
368 { long x
, y
; DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
369 virtual void SetDeviceOrigin(long x
, long y
) = 0;
371 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
) = 0;
373 int GetLogicalFunction() const { return m_logicalFunction
; }
374 virtual void SetLogicalFunction(int function
) = 0;
376 // Sometimes we need to override optimization, e.g. if other software is
377 // drawing onto our surface and we can't be sure of who's done what.
379 // FIXME: is this (still) used?
380 virtual void SetOptimization(bool WXUNUSED(opt
)) { }
381 virtual bool GetOptimization() { return FALSE
; }
386 virtual void CalcBoundingBox(long x
, long y
)
388 if (x
< m_minX
) m_minX
= x
;
389 if (y
< m_minY
) m_minY
= y
;
390 if (x
> m_maxX
) m_maxX
= x
;
391 if (y
> m_maxY
) m_maxY
= y
;
394 // Get the final bounding box of the PostScript or Metafile picture.
395 long MinX() const { return m_minX
; }
396 long MaxX() const { return m_maxX
; }
397 long MinY() const { return m_minY
; }
398 long MaxY() const { return m_maxY
; }
400 // misc old functions
401 // ------------------
403 #if WXWIN_COMPATIBILITY
404 virtual void SetColourMap(const wxPalette
& palette
) { SetPalette(palette
); }
405 void GetTextExtent(const wxString
& string
, float *x
, float *y
,
406 float *descent
= NULL
, float *externalLeading
= NULL
,
407 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const ;
408 void GetSize(float* width
, float* height
) const { int w
, h
; GetSize(& w
, & h
); *width
= w
; *height
= h
; }
409 void GetSizeMM(float *width
, float *height
) const { long w
, h
; GetSizeMM(& w
, & h
); *width
= (float) w
; *height
= (float) h
; }
410 #endif // WXWIN_COMPATIBILITY
413 // the pure virtual functions which should be implemented by wxDC
414 virtual void DoFloodFill(long x
, long y
, const wxColour
& col
,
415 int style
= wxFLOOD_SURFACE
) = 0;
417 virtual bool DoGetPixel(long x
, long y
, wxColour
*col
) const = 0;
419 virtual void DoDrawPoint(long x
, long y
) = 0;
420 virtual void DoDrawLine(long x1
, long y1
, long x2
, long y2
) = 0;
422 virtual void DoDrawArc(long x1
, long y1
,
424 long xc
, long yc
) = 0;
425 virtual void DoDrawEllipticArc(long x
, long y
, long w
, long h
,
426 double sa
, double ea
) = 0;
428 virtual void DoDrawRectangle(long x
, long y
, long width
, long height
) = 0;
429 virtual void DoDrawRoundedRectangle(long x
, long y
,
430 long width
, long height
,
432 virtual void DoDrawEllipse(long x
, long y
, long width
, long height
) = 0;
434 virtual void DoCrossHair(long x
, long y
) = 0;
436 virtual void DoDrawIcon(const wxIcon
& icon
, long x
, long y
) = 0;
437 virtual void DoDrawBitmap(const wxBitmap
&bmp
, long x
, long y
,
438 bool useMask
= FALSE
) = 0;
440 virtual void DoDrawText(const wxString
& text
, long x
, long y
) = 0;
442 virtual bool DoBlit(long xdest
, long ydest
, long width
, long height
,
443 wxDC
*source
, long xsrc
, long ysrc
,
444 int rop
= wxCOPY
, bool useMask
= FALSE
) = 0;
446 virtual void DoGetSize(int *width
, int *height
) const = 0;
447 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
449 virtual void DoDrawLines(int n
, wxPoint points
[],
450 long xoffset
, long yoffset
) = 0;
451 virtual void DoDrawPolygon(int n
, wxPoint points
[],
452 long xoffset
, long yoffset
,
453 int fillStyle
= wxODDEVEN_RULE
) = 0;
455 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
456 virtual void DoSetClippingRegion(long x
, long y
,
457 long width
, long height
) = 0;
459 // FIXME are these functions really different?
460 virtual void DoGetClippingRegion(long *x
, long *y
,
462 { DoGetClippingBox(x
, y
, w
, h
); }
463 virtual void DoGetClippingBox(long *x
, long *y
,
464 long *w
, long *h
) const
468 if ( x
) *x
= m_clipX1
;
469 if ( y
) *y
= m_clipY1
;
470 if ( w
) *w
= m_clipX2
- m_clipX1
;
471 if ( h
) *h
= m_clipY2
- m_clipY1
;
475 *x
= *y
= *w
= *h
= 0;
479 virtual void DoGetLogicalOrigin(long *x
, long *y
) const
481 if ( x
) *x
= m_logicalOriginX
;
482 if ( y
) *y
= m_logicalOriginY
;
485 virtual void DoGetDeviceOrigin(long *x
, long *y
) const
487 if ( x
) *x
= m_deviceOriginX
;
488 if ( y
) *y
= m_deviceOriginY
;
492 virtual void DoDrawSpline(wxList
*points
) = 0;
500 bool m_isInteractive
:1;
502 // coordinate system variables
504 // TODO short descriptions of what exactly they are would be nice...
506 long m_logicalOriginX
, m_logicalOriginY
;
507 long m_deviceOriginX
, m_deviceOriginY
;
509 double m_logicalScaleX
, m_logicalScaleY
;
510 double m_userScaleX
, m_userScaleY
;
511 double m_scaleX
, m_scaleY
;
513 // Used by SetAxisOrientation() to invert the axes
514 int m_signX
, m_signY
;
516 // bounding and clipping boxes
517 long m_minX
, m_minY
, m_maxX
, m_maxY
;
518 long m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
520 int m_logicalFunction
;
521 int m_backgroundMode
;
527 wxBrush m_backgroundBrush
;
528 wxColour m_textForegroundColour
;
529 wxColour m_textBackgroundColour
;
534 DECLARE_NO_COPY_CLASS(wxDCBase
);
537 // ----------------------------------------------------------------------------
538 // now include the declaration of wxDC class
539 // ----------------------------------------------------------------------------
541 #if defined(__WXMSW__)
542 #include "wx/msw/dc.h"
543 #elif defined(__WXMOTIF__)
544 #include "wx/motif/dc.h"
545 #elif defined(__WXGTK__)
546 #include "wx/gtk/dc.h"
547 #elif defined(__WXQT__)
548 #include "wx/qt/dc.h"
549 #elif defined(__WXMAC__)
550 #include "wx/mac/dc.h"
551 #elif defined(__WXSTUBS__)
552 #include "wx/stubs/dc.h"