5 #pragma interface "dcbase.h"
8 // ----------------------------------------------------------------------------
9 // headers which we must include here
10 // ----------------------------------------------------------------------------
12 #include "wx/object.h" // the base class
14 #include "wx/cursor.h" // we have member variables of these classes
15 #include "wx/font.h" // so we can't do without them
16 #include "wx/colour.h"
19 #include "wx/palette.h"
21 #include "wx/list.h" // we use wxList in inline functions
23 // ---------------------------------------------------------------------------
25 // ---------------------------------------------------------------------------
27 // type which should be used (whenever possible, i.e. as long as it doesn't
28 // break compatibility) for screen coordinates
31 // ---------------------------------------------------------------------------
33 // ---------------------------------------------------------------------------
35 WXDLLEXPORT_DATA(extern int) wxPageNumber
;
37 // ---------------------------------------------------------------------------
38 // wxDC is the device context - object on which any drawing is done
39 // ---------------------------------------------------------------------------
41 class WXDLLEXPORT wxDCBase
: public wxObject
43 DECLARE_ABSTRACT_CLASS(wxDCBase
)
51 m_minX
= m_minY
= m_maxX
= m_maxY
= 0;
53 m_signX
= m_signY
= 1;
55 m_logicalOriginX
= m_logicalOriginY
=
56 m_deviceOriginX
= m_deviceOriginY
= 0;
58 m_logicalScaleX
= m_logicalScaleY
=
59 m_userScaleX
= m_userScaleY
=
60 m_scaleX
= m_scaleY
= 1.0;
62 m_logicalFunction
= -1;
64 m_backgroundMode
= wxTRANSPARENT
;
66 m_mappingMode
= wxMM_TEXT
;
68 m_backgroundBrush
= *wxWHITE_BRUSH
;
70 m_textForegroundColour
= *wxBLACK
;
71 m_textBackgroundColour
= *wxWHITE
;
73 m_colour
= wxColourDisplay();
78 virtual void BeginDrawing() { }
79 virtual void EndDrawing() { }
84 void FloodFill(long x
, long y
, const wxColour
& col
,
85 int style
= wxFLOOD_SURFACE
)
86 { DoFloodFill(x
, y
, col
, style
); }
87 void FloodFill(const wxPoint
& pt
, const wxColour
& col
,
88 int style
= wxFLOOD_SURFACE
)
89 { DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
91 bool GetPixel(long x
, long y
, wxColour
*col
) const
92 { return DoGetPixel(x
, y
, col
); }
93 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
94 { return DoGetPixel(pt
.x
, pt
.y
, col
); }
96 void DrawLine(long x1
, long y1
, long x2
, long y2
)
97 { DoDrawLine(x1
, y1
, x2
, y2
); }
98 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
99 { DoDrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
); }
101 void CrossHair(long x
, long y
)
102 { DoCrossHair(x
, y
); }
103 void CrossHair(const wxPoint
& pt
)
104 { DoCrossHair(pt
.x
, pt
.y
); }
106 void DrawArc(long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
107 { DoDrawArc(x1
, y1
, x2
, y2
, xc
, yc
); }
108 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
109 { DoDrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
); }
111 void DrawEllipticArc(long x
, long y
, long w
, long h
, double sa
, double ea
)
112 { DoDrawEllipticArc(x
, y
, w
, h
, sa
, ea
); }
113 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
114 double sa
, double ea
)
115 { DoDrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
); }
117 void DrawPoint(long x
, long y
)
118 { DoDrawPoint(x
, y
); }
119 void DrawPoint(const wxPoint
& pt
)
120 { DoDrawPoint(pt
.x
, pt
.y
); }
122 void DrawLines(int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0)
123 { DoDrawLines(n
, points
, xoffset
, yoffset
); }
124 void DrawLines(const wxList
*list
, long xoffset
= 0, long yoffset
= 0);
126 void DrawPolygon(int n
, wxPoint points
[],
127 long xoffset
= 0, long yoffset
= 0,
128 int fillStyle
= wxODDEVEN_RULE
)
129 { DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
131 void DrawPolygon(const wxList
*list
,
132 long xoffset
= 0, long yoffset
= 0,
133 int fillStyle
= wxODDEVEN_RULE
);
135 void DrawRectangle(long x
, long y
, long width
, long height
)
136 { DoDrawRectangle(x
, y
, width
, height
); }
137 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
138 { DoDrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
139 void DrawRectangle(const wxRect
& rect
)
140 { DoDrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
142 void DrawRoundedRectangle(long x
, long y
, long width
, long height
,
144 { DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
145 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
147 { DoDrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
); }
148 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
149 { DoDrawRoundedRectangle(r
.x
, r
.y
, r
.width
, r
.height
, radius
); }
151 void DrawCircle(long x
, long y
, long radius
)
152 { DoDrawEllipse(x
- radius
, y
- radius
, 2*radius
, 2*radius
); }
153 void DrawEllipse(long x
, long y
, long width
, long height
)
154 { DoDrawEllipse(x
, y
, width
, height
); }
155 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
156 { DoDrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
157 void DrawEllipse(const wxRect
& rect
)
158 { DoDrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
160 void DrawIcon(const wxIcon
& icon
, long x
, long y
)
161 { DoDrawIcon(icon
, x
, y
); }
162 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
163 { DoDrawIcon(icon
, pt
.x
, pt
.y
); }
165 void DrawBitmap(const wxBitmap
&bmp
, long x
, long y
, bool useMask
= FALSE
)
166 { DoDrawBitmap(bmp
, x
, y
, useMask
); }
167 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
168 bool useMask
= FALSE
)
169 { DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
171 void DrawText(const wxString
& text
, long x
, long y
)
172 { DoDrawText(text
, x
, y
); }
173 void DrawText(const wxString
& text
, const wxPoint
& pt
)
174 { DoDrawText(text
, pt
.x
, pt
.y
); }
176 bool Blit(long xdest
, long ydest
, long width
, long height
,
177 wxDC
*source
, long xsrc
, long ysrc
,
178 int rop
= wxCOPY
, bool useMask
= FALSE
)
180 return DoBlit(xdest
, ydest
, width
, height
,
181 source
, xsrc
, ysrc
, rop
, useMask
);
183 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
184 wxDC
*source
, const wxPoint
& srcPt
,
185 int rop
= wxCOPY
, bool useMask
= FALSE
)
187 return DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
188 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
);
192 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
193 void DrawSpline(long x1
, long y1
, long x2
, long y2
, long x3
, long y3
);
194 void DrawSpline(int n
, wxPoint points
[]);
196 void DrawSpline(wxList
*points
) { DoDrawSpline(points
); }
197 #endif // wxUSE_SPLINES
199 // global DC operations
200 // --------------------
202 virtual void Clear() = 0;
204 virtual bool StartDoc(const wxString
& message
) = 0;
205 virtual void EndDoc() = 0;
207 virtual void StartPage() = 0;
208 virtual void EndPage() = 0;
210 // set objects to use for drawing
211 // ------------------------------
213 virtual void SetFont(const wxFont
& font
) = 0;
214 virtual void SetPen(const wxPen
& pen
) = 0;
215 virtual void SetBrush(const wxBrush
& brush
) = 0;
216 virtual void SetBackground(const wxBrush
& brush
) = 0;
217 virtual void SetBackgroundMode(int mode
) = 0;
218 virtual void SetPalette(const wxPalette
& palette
) = 0;
223 void SetClippingRegion(long x
, long y
, long width
, long height
)
224 { DoSetClippingRegion(x
, y
, width
, height
); }
225 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
226 { DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
227 void SetClippingRegion(const wxRect
& rect
)
228 { DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
229 void SetClippingRegion(const wxRegion
& region
)
230 { DoSetClippingRegionAsRegion(region
); }
232 virtual void DestroyClippingRegion() = 0;
234 void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const
235 { DoGetClippingBox(x
, y
, w
, h
); }
236 void GetClippingBox(wxRect
& rect
) const
237 { DoGetClippingBox(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
); }
242 virtual long GetCharHeight() const = 0;
243 virtual long GetCharWidth() const = 0;
244 virtual void GetTextExtent(const wxString
& string
,
246 long *descent
= NULL
,
247 long *externalLeading
= NULL
,
248 wxFont
*theFont
= NULL
) const = 0;
250 // size and resolution
251 // -------------------
254 void GetSize(int *width
, int *height
) const
255 { DoGetSize(width
, height
); }
256 wxSize
GetSize() const
265 void GetSizeMM(int* width
, int* height
) const
266 { DoGetSizeMM(width
, height
); }
267 wxSize
GetSizeMM() const
275 // coordinates conversions
276 // -----------------------
278 // This group of functions does actual conversion of the input, as you'd
280 long DeviceToLogicalX(long x
) const;
281 long DeviceToLogicalY(long y
) const;
282 long DeviceToLogicalXRel(long x
) const;
283 long DeviceToLogicalYRel(long y
) const;
284 long LogicalToDeviceX(long x
) const;
285 long LogicalToDeviceY(long y
) const;
286 long LogicalToDeviceXRel(long x
) const;
287 long LogicalToDeviceYRel(long y
) const;
289 // query DC capabilities
290 // ---------------------
292 virtual bool CanDrawBitmap() const = 0;
293 virtual bool CanGetTextExtent() const = 0;
296 virtual int GetDepth() const = 0;
298 // Resolution in Pixels per inch
299 virtual wxSize
GetPPI() const = 0;
301 virtual bool Ok() const { return m_ok
; }
307 const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
308 const wxBrush
& GetBrush() const { return m_brush
; }
309 const wxFont
& GetFont() const { return m_font
; }
310 const wxPen
& GetPen() const { return m_pen
; }
311 const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
312 const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
315 wxBrush
& GetBackground() { return m_backgroundBrush
; }
316 wxBrush
& GetBrush() { return m_brush
; }
317 wxFont
& GetFont() { return m_font
; }
318 wxPen
& GetPen() { return m_pen
; }
319 wxColour
& GetTextBackground() { return m_textBackgroundColour
; }
320 wxColour
& GetTextForeground() { return m_textForegroundColour
; }
322 virtual void SetTextForeground(const wxColour
& colour
)
323 { m_textForegroundColour
= colour
; }
324 virtual void SetTextBackground(const wxColour
& colour
)
325 { m_textBackgroundColour
= colour
; }
327 int GetMapMode() const { return m_mappingMode
; }
328 virtual void SetMapMode(int mode
) = 0;
330 virtual void GetUserScale(double *x
, double *y
) const
332 if ( x
) *x
= m_userScaleX
;
333 if ( y
) *y
= m_userScaleY
;
335 virtual void SetUserScale(double x
, double y
) = 0;
337 virtual void GetLogicalScale(double *x
, double *y
)
339 if ( x
) *x
= m_logicalScaleX
;
340 if ( y
) *y
= m_logicalScaleY
;
342 virtual void SetLogicalScale(double x
, double y
)
348 void GetLogicalOrigin(long *x
, long *y
) const
349 { DoGetLogicalOrigin(x
, y
); }
350 wxPoint
GetLogicalOrigin() const
351 { long x
, y
; DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
352 virtual void SetLogicalOrigin(long x
, long y
) = 0;
354 void GetDeviceOrigin(long *x
, long *y
) const
355 { DoGetDeviceOrigin(x
, y
); }
356 wxPoint
GetDeviceOrigin() const
357 { long x
, y
; DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
358 virtual void SetDeviceOrigin(long x
, long y
) = 0;
360 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
) = 0;
362 int GetLogicalFunction() const { return m_logicalFunction
; }
363 virtual void SetLogicalFunction(int function
) = 0;
365 // Sometimes we need to override optimization, e.g. if other software is
366 // drawing onto our surface and we can't be sure of who's done what.
368 // FIXME: is this (still) used?
369 virtual void SetOptimization(bool WXUNUSED(opt
)) { }
370 virtual bool GetOptimization() { return FALSE
; }
375 virtual void CalcBoundingBox(long x
, long y
)
377 if (x
< m_minX
) m_minX
= x
;
378 if (y
< m_minY
) m_minY
= y
;
379 if (x
> m_maxX
) m_maxX
= x
;
380 if (y
> m_maxY
) m_maxY
= y
;
383 // Get the final bounding box of the PostScript or Metafile picture.
384 long MinX() const { return m_minX
; }
385 long MaxX() const { return m_maxX
; }
386 long MinY() const { return m_minY
; }
387 long MaxY() const { return m_maxY
; }
389 // misc old functions
390 // ------------------
392 #if WXWIN_COMPATIBILITY
393 virtual void SetColourMap(const wxPalette
& palette
) { SetPalette(palette
); }
394 void GetTextExtent(const wxString
& string
, float *x
, float *y
,
395 float *descent
= NULL
, float *externalLeading
= NULL
,
396 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const ;
397 void GetSize(float* width
, float* height
) const { int w
, h
; GetSize(& w
, & h
); *width
= w
; *height
= h
; }
398 void GetSizeMM(float *width
, float *height
) const { long w
, h
; GetSizeMM(& w
, & h
); *width
= (float) w
; *height
= (float) h
; }
399 #endif // WXWIN_COMPATIBILITY
402 // the pure virtual functions which should be implemented by wxDC
403 virtual void DoFloodFill(long x
, long y
, const wxColour
& col
,
404 int style
= wxFLOOD_SURFACE
) = 0;
406 virtual bool DoGetPixel(long x
, long y
, wxColour
*col
) const = 0;
408 virtual void DoDrawPoint(long x
, long y
) = 0;
409 virtual void DoDrawLine(long x1
, long y1
, long x2
, long y2
) = 0;
411 virtual void DoDrawArc(long x1
, long y1
,
413 long xc
, long yc
) = 0;
414 virtual void DoDrawEllipticArc(long x
, long y
, long w
, long h
,
415 double sa
, double ea
) = 0;
417 virtual void DoDrawRectangle(long x
, long y
, long width
, long height
) = 0;
418 virtual void DoDrawRoundedRectangle(long x
, long y
,
419 long width
, long height
,
421 virtual void DoDrawEllipse(long x
, long y
, long width
, long height
) = 0;
423 virtual void DoCrossHair(long x
, long y
) = 0;
425 virtual void DoDrawIcon(const wxIcon
& icon
, long x
, long y
) = 0;
426 virtual void DoDrawBitmap(const wxBitmap
&bmp
, long x
, long y
,
427 bool useMask
= FALSE
) = 0;
429 virtual void DoDrawText(const wxString
& text
, long x
, long y
) = 0;
431 virtual bool DoBlit(long xdest
, long ydest
, long width
, long height
,
432 wxDC
*source
, long xsrc
, long ysrc
,
433 int rop
= wxCOPY
, bool useMask
= FALSE
) = 0;
435 virtual void DoGetSize(int *width
, int *height
) const = 0;
436 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
438 virtual void DoDrawLines(int n
, wxPoint points
[],
439 long xoffset
, long yoffset
) = 0;
440 virtual void DoDrawPolygon(int n
, wxPoint points
[],
441 long xoffset
, long yoffset
,
442 int fillStyle
= wxODDEVEN_RULE
) = 0;
444 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
445 virtual void DoSetClippingRegion(long x
, long y
,
446 long width
, long height
) = 0;
448 // FIXME are these functions really different?
449 virtual void DoGetClippingRegion(long *x
, long *y
,
451 { DoGetClippingBox(x
, y
, w
, h
); }
452 virtual void DoGetClippingBox(long *x
, long *y
,
453 long *w
, long *h
) const
457 if ( x
) *x
= m_clipX1
;
458 if ( y
) *y
= m_clipY1
;
459 if ( w
) *w
= m_clipX2
- m_clipX1
;
460 if ( h
) *h
= m_clipY2
- m_clipY1
;
464 *x
= *y
= *w
= *h
= 0;
468 virtual void DoGetLogicalOrigin(long *x
, long *y
) const
470 if ( x
) *x
= m_logicalOriginX
;
471 if ( y
) *y
= m_logicalOriginY
;
474 virtual void DoGetDeviceOrigin(long *x
, long *y
) const
476 if ( x
) *x
= m_deviceOriginX
;
477 if ( y
) *y
= m_deviceOriginY
;
481 virtual void DoDrawSpline(wxList
*points
) = 0;
489 bool m_isInteractive
:1;
491 // coordinate system variables
493 // TODO short descriptions of what exactly they are would be nice...
495 long m_logicalOriginX
, m_logicalOriginY
;
496 long m_deviceOriginX
, m_deviceOriginY
;
498 double m_logicalScaleX
, m_logicalScaleY
;
499 double m_userScaleX
, m_userScaleY
;
500 double m_scaleX
, m_scaleY
;
502 // Used by SetAxisOrientation() to invert the axes
503 int m_signX
, m_signY
;
505 // bounding and clipping boxes
506 long m_minX
, m_minY
, m_maxX
, m_maxY
;
507 long m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
509 int m_logicalFunction
;
510 int m_backgroundMode
;
516 wxBrush m_backgroundBrush
;
517 wxColour m_textForegroundColour
;
518 wxColour m_textBackgroundColour
;
523 DECLARE_NO_COPY_CLASS(wxDCBase
);
526 // ----------------------------------------------------------------------------
527 // now include the declaration of wxDC class
528 // ----------------------------------------------------------------------------
530 #if defined(__WXMSW__)
531 #include "wx/msw/dc.h"
532 #elif defined(__WXMOTIF__)
533 #include "wx/motif/dc.h"
534 #elif defined(__WXGTK__)
535 #include "wx/gtk/dc.h"
536 #elif defined(__WXQT__)
537 #include "wx/qt/dc.h"
538 #elif defined(__WXMAC__)
539 #include "wx/mac/dc.h"
540 #elif defined(__WXSTUBS__)
541 #include "wx/stubs/dc.h"