]>
Commit | Line | Data |
---|---|---|
006162a9 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.h | |
3 | // Purpose: wxDC class | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 05/25/99 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
006162a9 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_DC_H_BASE_ |
13 | #define _WX_DC_H_BASE_ | |
c801d85f | 14 | |
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
a23fd0e1 VZ |
16 | #pragma interface "dcbase.h" |
17 | #endif | |
18 | ||
19 | // ---------------------------------------------------------------------------- | |
20 | // headers which we must include here | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
23 | #include "wx/object.h" // the base class | |
24 | ||
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" | |
28 | #include "wx/brush.h" | |
29 | #include "wx/pen.h" | |
30 | #include "wx/palette.h" | |
a23fd0e1 | 31 | #include "wx/list.h" // we use wxList in inline functions |
0919e93e | 32 | #include "wx/dynarray.h" |
a23fd0e1 | 33 | |
f4515f98 | 34 | class WXDLLEXPORT wxDC; |
aec43716 KH |
35 | class WXDLLEXPORT wxDCBase; |
36 | ||
37 | class WXDLLEXPORT wxDrawObject | |
38 | { | |
39 | public: | |
40 | ||
41 | wxDrawObject() | |
ba161d7e GD |
42 | : m_isBBoxValid(FALSE) |
43 | , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0) | |
44 | { } | |
aec43716 KH |
45 | |
46 | virtual ~wxDrawObject() { } | |
47 | ||
33ac7e6f | 48 | virtual void Draw(wxDCBase&) const { } |
aec43716 KH |
49 | |
50 | virtual void CalcBoundingBox(wxCoord x, wxCoord y) | |
51 | { | |
52 | if ( m_isBBoxValid ) | |
53 | { | |
54 | if ( x < m_minX ) m_minX = x; | |
55 | if ( y < m_minY ) m_minY = y; | |
56 | if ( x > m_maxX ) m_maxX = x; | |
57 | if ( y > m_maxY ) m_maxY = y; | |
58 | } | |
59 | else | |
60 | { | |
61 | m_isBBoxValid = TRUE; | |
62 | ||
63 | m_minX = x; | |
64 | m_minY = y; | |
65 | m_maxX = x; | |
66 | m_maxY = y; | |
67 | } | |
68 | } | |
69 | ||
70 | void ResetBoundingBox() | |
71 | { | |
72 | m_isBBoxValid = FALSE; | |
73 | ||
74 | m_minX = m_maxX = m_minY = m_maxY = 0; | |
75 | } | |
76 | ||
77 | // Get the final bounding box of the PostScript or Metafile picture. | |
78 | ||
79 | wxCoord MinX() const { return m_minX; } | |
80 | wxCoord MaxX() const { return m_maxX; } | |
81 | wxCoord MinY() const { return m_minY; } | |
82 | wxCoord MaxY() const { return m_maxY; } | |
83 | ||
84 | //to define the type of object for derived objects | |
85 | virtual int GetType()=0; | |
86 | ||
87 | protected: | |
88 | //for boundingbox calculation | |
89 | bool m_isBBoxValid:1; | |
90 | //for boundingbox calculation | |
91 | wxCoord m_minX, m_minY, m_maxX, m_maxY; | |
92 | }; | |
93 | ||
a23fd0e1 VZ |
94 | // --------------------------------------------------------------------------- |
95 | // global variables | |
96 | // --------------------------------------------------------------------------- | |
97 | ||
98 | WXDLLEXPORT_DATA(extern int) wxPageNumber; | |
99 | ||
100 | // --------------------------------------------------------------------------- | |
101 | // wxDC is the device context - object on which any drawing is done | |
102 | // --------------------------------------------------------------------------- | |
103 | ||
104 | class WXDLLEXPORT wxDCBase : public wxObject | |
105 | { | |
a23fd0e1 VZ |
106 | public: |
107 | wxDCBase() | |
ba161d7e GD |
108 | : m_colour(wxColourDisplay()) |
109 | , m_ok(TRUE) | |
110 | , m_clipping(FALSE) | |
111 | , m_isInteractive(0) | |
112 | , m_isBBoxValid(FALSE) | |
113 | , m_logicalOriginX(0), m_logicalOriginY(0) | |
114 | , m_deviceOriginX(0), m_deviceOriginY(0) | |
115 | , m_logicalScaleX(1.0), m_logicalScaleY(1.0) | |
116 | , m_userScaleX(1.0), m_userScaleY(1.0) | |
117 | , m_scaleX(1.0), m_scaleY(1.0) | |
118 | , m_signX(1), m_signY(1) | |
119 | , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0) | |
120 | , m_clipX1(0), m_clipY1(0), m_clipX2(0), m_clipY2(0) | |
121 | , m_logicalFunction(wxCOPY) | |
122 | , m_backgroundMode(wxTRANSPARENT) | |
123 | , m_mappingMode(wxMM_TEXT) | |
124 | , m_pen() | |
125 | , m_brush() | |
126 | , m_backgroundBrush(*wxTRANSPARENT_BRUSH) | |
127 | , m_textForegroundColour(*wxBLACK) | |
128 | , m_textBackgroundColour(*wxWHITE) | |
129 | , m_font() | |
130 | #if wxUSE_PALETTE | |
131 | , m_palette() | |
132 | , m_hasCustomPalette(FALSE) | |
133 | #endif // wxUSE_PALETTE | |
a23fd0e1 | 134 | { |
f6bcfd97 | 135 | ResetBoundingBox(); |
d16b634f | 136 | ResetClipping(); |
a23fd0e1 VZ |
137 | } |
138 | ||
139 | ~wxDCBase() { } | |
140 | ||
141 | virtual void BeginDrawing() { } | |
142 | virtual void EndDrawing() { } | |
143 | ||
144 | // graphic primitives | |
145 | // ------------------ | |
146 | ||
aec43716 KH |
147 | virtual void DrawObject(wxDrawObject* drawobject) |
148 | { | |
149 | drawobject->Draw(*this); | |
150 | CalcBoundingBox(drawobject->MinX(),drawobject->MinY()); | |
151 | CalcBoundingBox(drawobject->MaxX(),drawobject->MaxY()); | |
152 | } | |
153 | ||
387ebd3e | 154 | bool FloodFill(wxCoord x, wxCoord y, const wxColour& col, |
72cdf4c9 | 155 | int style = wxFLOOD_SURFACE) |
387ebd3e JS |
156 | { return DoFloodFill(x, y, col, style); } |
157 | bool FloodFill(const wxPoint& pt, const wxColour& col, | |
72cdf4c9 | 158 | int style = wxFLOOD_SURFACE) |
387ebd3e | 159 | { return DoFloodFill(pt.x, pt.y, col, style); } |
a23fd0e1 | 160 | |
72cdf4c9 | 161 | bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const |
a23fd0e1 VZ |
162 | { return DoGetPixel(x, y, col); } |
163 | bool GetPixel(const wxPoint& pt, wxColour *col) const | |
164 | { return DoGetPixel(pt.x, pt.y, col); } | |
165 | ||
72cdf4c9 | 166 | void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) |
a23fd0e1 VZ |
167 | { DoDrawLine(x1, y1, x2, y2); } |
168 | void DrawLine(const wxPoint& pt1, const wxPoint& pt2) | |
169 | { DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); } | |
170 | ||
72cdf4c9 | 171 | void CrossHair(wxCoord x, wxCoord y) |
a23fd0e1 VZ |
172 | { DoCrossHair(x, y); } |
173 | void CrossHair(const wxPoint& pt) | |
174 | { DoCrossHair(pt.x, pt.y); } | |
175 | ||
72cdf4c9 VZ |
176 | void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, |
177 | wxCoord xc, wxCoord yc) | |
a23fd0e1 VZ |
178 | { DoDrawArc(x1, y1, x2, y2, xc, yc); } |
179 | void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre) | |
180 | { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); } | |
181 | ||
cd9da200 VZ |
182 | void DrawCheckMark(wxCoord x, wxCoord y, |
183 | wxCoord width, wxCoord height) | |
184 | { DoDrawCheckMark(x, y, width, height); } | |
185 | void DrawCheckMark(const wxRect& rect) | |
186 | { DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); } | |
187 | ||
72cdf4c9 VZ |
188 | void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
189 | double sa, double ea) | |
7b90a8f2 | 190 | { DoDrawEllipticArc(x, y, w, h, sa, ea); } |
a23fd0e1 VZ |
191 | void DrawEllipticArc(const wxPoint& pt, const wxSize& sz, |
192 | double sa, double ea) | |
193 | { DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); } | |
194 | ||
72cdf4c9 | 195 | void DrawPoint(wxCoord x, wxCoord y) |
a23fd0e1 VZ |
196 | { DoDrawPoint(x, y); } |
197 | void DrawPoint(const wxPoint& pt) | |
198 | { DoDrawPoint(pt.x, pt.y); } | |
199 | ||
72cdf4c9 VZ |
200 | void DrawLines(int n, wxPoint points[], |
201 | wxCoord xoffset = 0, wxCoord yoffset = 0) | |
a23fd0e1 | 202 | { DoDrawLines(n, points, xoffset, yoffset); } |
72cdf4c9 VZ |
203 | void DrawLines(const wxList *list, |
204 | wxCoord xoffset = 0, wxCoord yoffset = 0); | |
a23fd0e1 VZ |
205 | |
206 | void DrawPolygon(int n, wxPoint points[], | |
72cdf4c9 | 207 | wxCoord xoffset = 0, wxCoord yoffset = 0, |
a23fd0e1 VZ |
208 | int fillStyle = wxODDEVEN_RULE) |
209 | { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); } | |
210 | ||
211 | void DrawPolygon(const wxList *list, | |
72cdf4c9 | 212 | wxCoord xoffset = 0, wxCoord yoffset = 0, |
bd5dd957 | 213 | int fillStyle = wxODDEVEN_RULE); |
a23fd0e1 | 214 | |
793db755 | 215 | void DrawPolyPolygon(int n, int count[], wxPoint points[], |
6e76b35d VZ |
216 | wxCoord xoffset = 0, wxCoord yoffset = 0, |
217 | int fillStyle = wxODDEVEN_RULE) | |
793db755 | 218 | { DoDrawPolyPolygon(n, count, points, xoffset, yoffset, fillStyle); } |
6e76b35d | 219 | |
72cdf4c9 | 220 | void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
a23fd0e1 VZ |
221 | { DoDrawRectangle(x, y, width, height); } |
222 | void DrawRectangle(const wxPoint& pt, const wxSize& sz) | |
223 | { DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); } | |
224 | void DrawRectangle(const wxRect& rect) | |
225 | { DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); } | |
226 | ||
72cdf4c9 | 227 | void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, |
a23fd0e1 VZ |
228 | double radius) |
229 | { DoDrawRoundedRectangle(x, y, width, height, radius); } | |
230 | void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, | |
231 | double radius) | |
232 | { DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); } | |
233 | void DrawRoundedRectangle(const wxRect& r, double radius) | |
234 | { DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); } | |
235 | ||
72cdf4c9 | 236 | void DrawCircle(wxCoord x, wxCoord y, wxCoord radius) |
220af862 | 237 | { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); } |
0371e9a8 | 238 | void DrawCircle(const wxPoint& pt, wxCoord radius) |
b95edd47 | 239 | { DrawCircle(pt.x, pt.y, radius); } |
0371e9a8 | 240 | |
72cdf4c9 | 241 | void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
a23fd0e1 VZ |
242 | { DoDrawEllipse(x, y, width, height); } |
243 | void DrawEllipse(const wxPoint& pt, const wxSize& sz) | |
244 | { DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); } | |
245 | void DrawEllipse(const wxRect& rect) | |
246 | { DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); } | |
247 | ||
72cdf4c9 | 248 | void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) |
a23fd0e1 VZ |
249 | { DoDrawIcon(icon, x, y); } |
250 | void DrawIcon(const wxIcon& icon, const wxPoint& pt) | |
251 | { DoDrawIcon(icon, pt.x, pt.y); } | |
252 | ||
72cdf4c9 VZ |
253 | void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, |
254 | bool useMask = FALSE) | |
a23fd0e1 VZ |
255 | { DoDrawBitmap(bmp, x, y, useMask); } |
256 | void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, | |
257 | bool useMask = FALSE) | |
258 | { DoDrawBitmap(bmp, pt.x, pt.y, useMask); } | |
259 | ||
72cdf4c9 | 260 | void DrawText(const wxString& text, wxCoord x, wxCoord y) |
a23fd0e1 VZ |
261 | { DoDrawText(text, x, y); } |
262 | void DrawText(const wxString& text, const wxPoint& pt) | |
263 | { DoDrawText(text, pt.x, pt.y); } | |
264 | ||
95724b1a VZ |
265 | void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) |
266 | { DoDrawRotatedText(text, x, y, angle); } | |
267 | void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle) | |
268 | { DoDrawRotatedText(text, pt.x, pt.y, angle); } | |
269 | ||
1e6feb95 VZ |
270 | // this version puts both optional bitmap and the text into the given |
271 | // rectangle and aligns is as specified by alignment parameter; it also | |
272 | // will emphasize the character with the given index if it is != -1 and | |
273 | // return the bounding rectangle if required | |
274 | virtual void DrawLabel(const wxString& text, | |
275 | const wxBitmap& image, | |
276 | const wxRect& rect, | |
277 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
278 | int indexAccel = -1, | |
279 | wxRect *rectBounding = NULL); | |
280 | ||
281 | void DrawLabel(const wxString& text, const wxRect& rect, | |
282 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
283 | int indexAccel = -1) | |
284 | { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); } | |
285 | ||
72cdf4c9 VZ |
286 | bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
287 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
0cbff120 | 288 | int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1) |
a23fd0e1 VZ |
289 | { |
290 | return DoBlit(xdest, ydest, width, height, | |
0cbff120 | 291 | source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask); |
a23fd0e1 VZ |
292 | } |
293 | bool Blit(const wxPoint& destPt, const wxSize& sz, | |
294 | wxDC *source, const wxPoint& srcPt, | |
0cbff120 | 295 | int rop = wxCOPY, bool useMask = FALSE, const wxPoint& srcPtMask = wxPoint(-1, -1)) |
a23fd0e1 VZ |
296 | { |
297 | return DoBlit(destPt.x, destPt.y, sz.x, sz.y, | |
0cbff120 | 298 | source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y); |
a23fd0e1 VZ |
299 | } |
300 | ||
301 | #if wxUSE_SPLINES | |
72cdf4c9 VZ |
302 | // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?) |
303 | void DrawSpline(wxCoord x1, wxCoord y1, | |
304 | wxCoord x2, wxCoord y2, | |
305 | wxCoord x3, wxCoord y3); | |
bd5dd957 | 306 | void DrawSpline(int n, wxPoint points[]); |
a23fd0e1 VZ |
307 | |
308 | void DrawSpline(wxList *points) { DoDrawSpline(points); } | |
309 | #endif // wxUSE_SPLINES | |
310 | ||
12bdd77c JS |
311 | // Eventually we will have wxUSE_GENERIC_DRAWELLIPSE |
312 | #ifdef __WXWINCE__ | |
313 | //! Generic method to draw ellipses, circles and arcs with current pen and brush. | |
314 | /*! \param x Upper left corner of bounding box. | |
315 | * \param y Upper left corner of bounding box. | |
316 | * \param w Width of bounding box. | |
317 | * \param h Height of bounding box. | |
d16b634f | 318 | * \param sa Starting angle of arc |
12bdd77c JS |
319 | * (counterclockwise, start at 3 o'clock, 360 is full circle). |
320 | * \param ea Ending angle of arc. | |
d16b634f | 321 | * \param angle Rotation angle, the Arc will be rotated after |
12bdd77c JS |
322 | * calculating begin and end. |
323 | */ | |
d16b634f VZ |
324 | void DrawEllipticArcRot( wxCoord x, wxCoord y, |
325 | wxCoord width, wxCoord height, | |
12bdd77c JS |
326 | double sa = 0, double ea = 0, double angle = 0 ) |
327 | { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); } | |
d16b634f VZ |
328 | |
329 | void DrawEllipticArcRot( const wxPoint& pt, | |
12bdd77c JS |
330 | const wxSize& sz, |
331 | double sa = 0, double ea = 0, double angle = 0 ) | |
332 | { DoDrawEllipticArcRot( pt.x, pt.y, sz.x, sz.y, sa, ea, angle ); } | |
333 | ||
334 | void DrawEllipticArcRot( const wxRect& rect, | |
335 | double sa = 0, double ea = 0, double angle = 0 ) | |
336 | { DoDrawEllipticArcRot( rect.x, rect.y, rect.width, rect.height, sa, ea, angle ); } | |
337 | ||
d16b634f VZ |
338 | virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y, |
339 | wxCoord w, wxCoord h, | |
12bdd77c | 340 | double sa = 0, double ea = 0, double angle = 0 ); |
d16b634f | 341 | |
12bdd77c JS |
342 | //! Rotates points around center. |
343 | /*! This is a quite straight method, it calculates in pixels | |
344 | * and so it produces rounding errors. | |
345 | * \param points The points inside will be rotated. | |
346 | * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle). | |
347 | * \param center Center of rotation. | |
d16b634f | 348 | */ |
12bdd77c JS |
349 | void Rotate( wxList* points, double angle, wxPoint center = wxPoint() ); |
350 | ||
351 | // used by DrawEllipticArcRot | |
352 | // Careful: wxList gets filled with points you have to delete later. | |
d16b634f VZ |
353 | void CalculateEllipticPoints( wxList* points, |
354 | wxCoord xStart, wxCoord yStart, | |
355 | wxCoord w, wxCoord h, | |
12bdd77c JS |
356 | double sa, double ea ); |
357 | #endif | |
d16b634f | 358 | |
a23fd0e1 VZ |
359 | // global DC operations |
360 | // -------------------- | |
361 | ||
362 | virtual void Clear() = 0; | |
363 | ||
af0bb3b1 VZ |
364 | virtual bool StartDoc(const wxString& WXUNUSED(message)) { return TRUE; } |
365 | virtual void EndDoc() { } | |
a23fd0e1 | 366 | |
af0bb3b1 VZ |
367 | virtual void StartPage() { } |
368 | virtual void EndPage() { } | |
a23fd0e1 VZ |
369 | |
370 | // set objects to use for drawing | |
371 | // ------------------------------ | |
372 | ||
373 | virtual void SetFont(const wxFont& font) = 0; | |
374 | virtual void SetPen(const wxPen& pen) = 0; | |
375 | virtual void SetBrush(const wxBrush& brush) = 0; | |
376 | virtual void SetBackground(const wxBrush& brush) = 0; | |
377 | virtual void SetBackgroundMode(int mode) = 0; | |
d275c7eb | 378 | #if wxUSE_PALETTE |
a23fd0e1 | 379 | virtual void SetPalette(const wxPalette& palette) = 0; |
d275c7eb | 380 | #endif // wxUSE_PALETTE |
a23fd0e1 VZ |
381 | |
382 | // clipping region | |
383 | // --------------- | |
384 | ||
72cdf4c9 | 385 | void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
a23fd0e1 VZ |
386 | { DoSetClippingRegion(x, y, width, height); } |
387 | void SetClippingRegion(const wxPoint& pt, const wxSize& sz) | |
388 | { DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); } | |
389 | void SetClippingRegion(const wxRect& rect) | |
390 | { DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); } | |
391 | void SetClippingRegion(const wxRegion& region) | |
392 | { DoSetClippingRegionAsRegion(region); } | |
393 | ||
d16b634f | 394 | virtual void DestroyClippingRegion() { ResetClipping(); } |
a23fd0e1 | 395 | |
72cdf4c9 | 396 | void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const |
a23fd0e1 VZ |
397 | { DoGetClippingBox(x, y, w, h); } |
398 | void GetClippingBox(wxRect& rect) const | |
8fb3a512 | 399 | { |
ae500232 | 400 | DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); |
8fb3a512 | 401 | } |
a23fd0e1 VZ |
402 | |
403 | // text extent | |
404 | // ----------- | |
405 | ||
72cdf4c9 VZ |
406 | virtual wxCoord GetCharHeight() const = 0; |
407 | virtual wxCoord GetCharWidth() const = 0; | |
cd9da200 | 408 | |
1e6feb95 | 409 | // only works for single line strings |
72cdf4c9 VZ |
410 | void GetTextExtent(const wxString& string, |
411 | wxCoord *x, wxCoord *y, | |
412 | wxCoord *descent = NULL, | |
413 | wxCoord *externalLeading = NULL, | |
414 | wxFont *theFont = NULL) const | |
415 | { DoGetTextExtent(string, x, y, descent, externalLeading, theFont); } | |
a23fd0e1 | 416 | |
1e6feb95 VZ |
417 | // works for single as well as multi-line strings |
418 | virtual void GetMultiLineTextExtent(const wxString& text, | |
419 | wxCoord *width, | |
420 | wxCoord *height, | |
421 | wxCoord *heightLine = NULL, | |
422 | wxFont *font = NULL); | |
423 | ||
0919e93e RD |
424 | // Measure cumulative width of text after each character |
425 | bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const | |
426 | { return DoGetPartialTextExtents(text, widths); } | |
427 | ||
d16b634f | 428 | |
a23fd0e1 VZ |
429 | // size and resolution |
430 | // ------------------- | |
431 | ||
432 | // in device units | |
433 | void GetSize(int *width, int *height) const | |
434 | { DoGetSize(width, height); } | |
435 | wxSize GetSize() const | |
436 | { | |
437 | int w, h; | |
438 | DoGetSize(&w, &h); | |
439 | ||
440 | return wxSize(w, h); | |
441 | } | |
442 | ||
443 | // in mm | |
444 | void GetSizeMM(int* width, int* height) const | |
445 | { DoGetSizeMM(width, height); } | |
446 | wxSize GetSizeMM() const | |
447 | { | |
448 | int w, h; | |
449 | DoGetSizeMM(&w, &h); | |
450 | ||
451 | return wxSize(w, h); | |
452 | } | |
453 | ||
454 | // coordinates conversions | |
455 | // ----------------------- | |
456 | ||
457 | // This group of functions does actual conversion of the input, as you'd | |
458 | // expect. | |
72cdf4c9 VZ |
459 | wxCoord DeviceToLogicalX(wxCoord x) const; |
460 | wxCoord DeviceToLogicalY(wxCoord y) const; | |
461 | wxCoord DeviceToLogicalXRel(wxCoord x) const; | |
462 | wxCoord DeviceToLogicalYRel(wxCoord y) const; | |
463 | wxCoord LogicalToDeviceX(wxCoord x) const; | |
464 | wxCoord LogicalToDeviceY(wxCoord y) const; | |
465 | wxCoord LogicalToDeviceXRel(wxCoord x) const; | |
466 | wxCoord LogicalToDeviceYRel(wxCoord y) const; | |
a23fd0e1 VZ |
467 | |
468 | // query DC capabilities | |
469 | // --------------------- | |
470 | ||
471 | virtual bool CanDrawBitmap() const = 0; | |
472 | virtual bool CanGetTextExtent() const = 0; | |
473 | ||
474 | // colour depth | |
475 | virtual int GetDepth() const = 0; | |
476 | ||
477 | // Resolution in Pixels per inch | |
478 | virtual wxSize GetPPI() const = 0; | |
479 | ||
480 | virtual bool Ok() const { return m_ok; } | |
481 | ||
2439f37a VZ |
482 | // accessors and setters |
483 | // --------------------- | |
a23fd0e1 | 484 | |
f6bcfd97 | 485 | int GetBackgroundMode() const { return m_backgroundMode; } |
a23fd0e1 VZ |
486 | const wxBrush& GetBackground() const { return m_backgroundBrush; } |
487 | const wxBrush& GetBrush() const { return m_brush; } | |
488 | const wxFont& GetFont() const { return m_font; } | |
489 | const wxPen& GetPen() const { return m_pen; } | |
a23fd0e1 | 490 | |
2439f37a VZ |
491 | const wxColour& GetTextForeground() const { return m_textForegroundColour; } |
492 | const wxColour& GetTextBackground() const { return m_textBackgroundColour; } | |
a23fd0e1 VZ |
493 | virtual void SetTextForeground(const wxColour& colour) |
494 | { m_textForegroundColour = colour; } | |
495 | virtual void SetTextBackground(const wxColour& colour) | |
496 | { m_textBackgroundColour = colour; } | |
497 | ||
498 | int GetMapMode() const { return m_mappingMode; } | |
499 | virtual void SetMapMode(int mode) = 0; | |
500 | ||
501 | virtual void GetUserScale(double *x, double *y) const | |
502 | { | |
503 | if ( x ) *x = m_userScaleX; | |
504 | if ( y ) *y = m_userScaleY; | |
505 | } | |
506 | virtual void SetUserScale(double x, double y) = 0; | |
507 | ||
a23fd0e1 VZ |
508 | virtual void GetLogicalScale(double *x, double *y) |
509 | { | |
510 | if ( x ) *x = m_logicalScaleX; | |
511 | if ( y ) *y = m_logicalScaleY; | |
512 | } | |
513 | virtual void SetLogicalScale(double x, double y) | |
514 | { | |
515 | m_logicalScaleX = x; | |
516 | m_logicalScaleY = y; | |
517 | } | |
518 | ||
72cdf4c9 | 519 | void GetLogicalOrigin(wxCoord *x, wxCoord *y) const |
a23fd0e1 VZ |
520 | { DoGetLogicalOrigin(x, y); } |
521 | wxPoint GetLogicalOrigin() const | |
72cdf4c9 VZ |
522 | { wxCoord x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); } |
523 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y) = 0; | |
a23fd0e1 | 524 | |
72cdf4c9 | 525 | void GetDeviceOrigin(wxCoord *x, wxCoord *y) const |
a23fd0e1 VZ |
526 | { DoGetDeviceOrigin(x, y); } |
527 | wxPoint GetDeviceOrigin() const | |
72cdf4c9 VZ |
528 | { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); } |
529 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y) = 0; | |
a23fd0e1 VZ |
530 | |
531 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0; | |
532 | ||
533 | int GetLogicalFunction() const { return m_logicalFunction; } | |
534 | virtual void SetLogicalFunction(int function) = 0; | |
535 | ||
536 | // Sometimes we need to override optimization, e.g. if other software is | |
537 | // drawing onto our surface and we can't be sure of who's done what. | |
538 | // | |
539 | // FIXME: is this (still) used? | |
540 | virtual void SetOptimization(bool WXUNUSED(opt)) { } | |
541 | virtual bool GetOptimization() { return FALSE; } | |
542 | ||
543 | // bounding box | |
544 | // ------------ | |
545 | ||
72cdf4c9 | 546 | virtual void CalcBoundingBox(wxCoord x, wxCoord y) |
a23fd0e1 | 547 | { |
f6bcfd97 BP |
548 | if ( m_isBBoxValid ) |
549 | { | |
550 | if ( x < m_minX ) m_minX = x; | |
551 | if ( y < m_minY ) m_minY = y; | |
552 | if ( x > m_maxX ) m_maxX = x; | |
553 | if ( y > m_maxY ) m_maxY = y; | |
554 | } | |
555 | else | |
556 | { | |
557 | m_isBBoxValid = TRUE; | |
558 | ||
559 | m_minX = x; | |
560 | m_minY = y; | |
561 | m_maxX = x; | |
562 | m_maxY = y; | |
563 | } | |
564 | } | |
565 | ||
566 | void ResetBoundingBox() | |
567 | { | |
568 | m_isBBoxValid = FALSE; | |
569 | ||
570 | m_minX = m_maxX = m_minY = m_maxY = 0; | |
a23fd0e1 VZ |
571 | } |
572 | ||
573 | // Get the final bounding box of the PostScript or Metafile picture. | |
72cdf4c9 VZ |
574 | wxCoord MinX() const { return m_minX; } |
575 | wxCoord MaxX() const { return m_maxX; } | |
576 | wxCoord MinY() const { return m_minY; } | |
577 | wxCoord MaxY() const { return m_maxY; } | |
a23fd0e1 VZ |
578 | |
579 | // misc old functions | |
580 | // ------------------ | |
581 | ||
72cdf4c9 | 582 | // for compatibility with the old code when wxCoord was long everywhere |
72cdf4c9 VZ |
583 | void GetTextExtent(const wxString& string, |
584 | long *x, long *y, | |
585 | long *descent = NULL, | |
586 | long *externalLeading = NULL, | |
587 | wxFont *theFont = NULL) const | |
588 | { | |
589 | wxCoord x2, y2, descent2, externalLeading2; | |
590 | DoGetTextExtent(string, &x2, &y2, | |
591 | &descent2, &externalLeading2, | |
592 | theFont); | |
593 | if ( x ) | |
594 | *x = x2; | |
595 | if ( y ) | |
596 | *y = y2; | |
597 | if ( descent ) | |
598 | *descent = descent2; | |
599 | if ( externalLeading ) | |
600 | *externalLeading = externalLeading2; | |
601 | } | |
602 | ||
603 | void GetLogicalOrigin(long *x, long *y) const | |
604 | { | |
605 | wxCoord x2, y2; | |
606 | DoGetLogicalOrigin(&x2, &y2); | |
607 | if ( x ) | |
608 | *x = x2; | |
609 | if ( y ) | |
610 | *y = y2; | |
611 | } | |
612 | ||
613 | void GetDeviceOrigin(long *x, long *y) const | |
614 | { | |
615 | wxCoord x2, y2; | |
616 | DoGetDeviceOrigin(&x2, &y2); | |
617 | if ( x ) | |
618 | *x = x2; | |
619 | if ( y ) | |
620 | *y = y2; | |
621 | } | |
1dd989e1 | 622 | void GetClippingBox(long *x, long *y, long *w, long *h) const |
cd9da200 VZ |
623 | { |
624 | wxCoord xx,yy,ww,hh; | |
625 | DoGetClippingBox(&xx, &yy, &ww, &hh); | |
626 | if (x) *x = xx; | |
627 | if (y) *y = yy; | |
628 | if (w) *w = ww; | |
629 | if (h) *h = hh; | |
1dd989e1 | 630 | } |
72cdf4c9 | 631 | |
a23fd0e1 VZ |
632 | protected: |
633 | // the pure virtual functions which should be implemented by wxDC | |
387ebd3e | 634 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, |
a23fd0e1 VZ |
635 | int style = wxFLOOD_SURFACE) = 0; |
636 | ||
72cdf4c9 | 637 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0; |
a23fd0e1 | 638 | |
72cdf4c9 VZ |
639 | virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0; |
640 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0; | |
a23fd0e1 | 641 | |
72cdf4c9 VZ |
642 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, |
643 | wxCoord x2, wxCoord y2, | |
644 | wxCoord xc, wxCoord yc) = 0; | |
cd9da200 VZ |
645 | virtual void DoDrawCheckMark(wxCoord x, wxCoord y, |
646 | wxCoord width, wxCoord height); | |
72cdf4c9 | 647 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
a23fd0e1 VZ |
648 | double sa, double ea) = 0; |
649 | ||
72cdf4c9 VZ |
650 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0; |
651 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
652 | wxCoord width, wxCoord height, | |
a23fd0e1 | 653 | double radius) = 0; |
72cdf4c9 VZ |
654 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, |
655 | wxCoord width, wxCoord height) = 0; | |
a23fd0e1 | 656 | |
72cdf4c9 | 657 | virtual void DoCrossHair(wxCoord x, wxCoord y) = 0; |
a23fd0e1 | 658 | |
72cdf4c9 VZ |
659 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0; |
660 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
a23fd0e1 VZ |
661 | bool useMask = FALSE) = 0; |
662 | ||
72cdf4c9 | 663 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0; |
95724b1a VZ |
664 | virtual void DoDrawRotatedText(const wxString& text, |
665 | wxCoord x, wxCoord y, double angle) = 0; | |
a23fd0e1 | 666 | |
72cdf4c9 VZ |
667 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, |
668 | wxCoord width, wxCoord height, | |
669 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
0cbff120 | 670 | int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1) = 0; |
a23fd0e1 VZ |
671 | |
672 | virtual void DoGetSize(int *width, int *height) const = 0; | |
673 | virtual void DoGetSizeMM(int* width, int* height) const = 0; | |
674 | ||
675 | virtual void DoDrawLines(int n, wxPoint points[], | |
72cdf4c9 | 676 | wxCoord xoffset, wxCoord yoffset) = 0; |
a23fd0e1 | 677 | virtual void DoDrawPolygon(int n, wxPoint points[], |
72cdf4c9 | 678 | wxCoord xoffset, wxCoord yoffset, |
a23fd0e1 | 679 | int fillStyle = wxODDEVEN_RULE) = 0; |
793db755 | 680 | virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[], |
6e76b35d VZ |
681 | wxCoord xoffset, wxCoord yoffset, |
682 | int fillStyle); | |
a23fd0e1 VZ |
683 | |
684 | virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0; | |
72cdf4c9 VZ |
685 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, |
686 | wxCoord width, wxCoord height) = 0; | |
b0e0d661 VZ |
687 | |
688 | // FIXME are these functions really different? | |
72cdf4c9 VZ |
689 | virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y, |
690 | wxCoord *w, wxCoord *h) | |
b0e0d661 | 691 | { DoGetClippingBox(x, y, w, h); } |
72cdf4c9 VZ |
692 | virtual void DoGetClippingBox(wxCoord *x, wxCoord *y, |
693 | wxCoord *w, wxCoord *h) const | |
a23fd0e1 | 694 | { |
d16b634f VZ |
695 | if ( x ) |
696 | *x = m_clipX1; | |
697 | if ( y ) | |
698 | *y = m_clipY1; | |
699 | if ( w ) | |
700 | *w = m_clipX2 - m_clipX1; | |
701 | if ( h ) | |
702 | *h = m_clipY2 - m_clipY1; | |
a23fd0e1 VZ |
703 | } |
704 | ||
72cdf4c9 | 705 | virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const |
a23fd0e1 VZ |
706 | { |
707 | if ( x ) *x = m_logicalOriginX; | |
708 | if ( y ) *y = m_logicalOriginY; | |
709 | } | |
710 | ||
72cdf4c9 | 711 | virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const |
a23fd0e1 VZ |
712 | { |
713 | if ( x ) *x = m_deviceOriginX; | |
714 | if ( y ) *y = m_deviceOriginY; | |
715 | } | |
716 | ||
72cdf4c9 VZ |
717 | virtual void DoGetTextExtent(const wxString& string, |
718 | wxCoord *x, wxCoord *y, | |
719 | wxCoord *descent = NULL, | |
720 | wxCoord *externalLeading = NULL, | |
721 | wxFont *theFont = NULL) const = 0; | |
d16b634f | 722 | |
0919e93e | 723 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; |
d16b634f | 724 | |
64698f9a | 725 | #if wxUSE_SPLINES |
fe2e4366 | 726 | virtual void DoDrawSpline(wxList *points); |
64698f9a | 727 | #endif |
a23fd0e1 VZ |
728 | |
729 | protected: | |
d16b634f VZ |
730 | // unset clipping variables (after clipping region was destroyed) |
731 | void ResetClipping() | |
732 | { | |
733 | m_clipping = false; | |
734 | ||
735 | m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0; | |
736 | } | |
737 | ||
a23fd0e1 VZ |
738 | // flags |
739 | bool m_colour:1; | |
740 | bool m_ok:1; | |
741 | bool m_clipping:1; | |
742 | bool m_isInteractive:1; | |
f6bcfd97 | 743 | bool m_isBBoxValid:1; |
a23fd0e1 VZ |
744 | |
745 | // coordinate system variables | |
746 | ||
747 | // TODO short descriptions of what exactly they are would be nice... | |
748 | ||
72cdf4c9 VZ |
749 | wxCoord m_logicalOriginX, m_logicalOriginY; |
750 | wxCoord m_deviceOriginX, m_deviceOriginY; | |
a23fd0e1 VZ |
751 | |
752 | double m_logicalScaleX, m_logicalScaleY; | |
753 | double m_userScaleX, m_userScaleY; | |
754 | double m_scaleX, m_scaleY; | |
755 | ||
756 | // Used by SetAxisOrientation() to invert the axes | |
757 | int m_signX, m_signY; | |
758 | ||
759 | // bounding and clipping boxes | |
72cdf4c9 VZ |
760 | wxCoord m_minX, m_minY, m_maxX, m_maxY; |
761 | wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2; | |
a23fd0e1 VZ |
762 | |
763 | int m_logicalFunction; | |
764 | int m_backgroundMode; | |
765 | int m_mappingMode; | |
766 | ||
767 | // GDI objects | |
768 | wxPen m_pen; | |
769 | wxBrush m_brush; | |
770 | wxBrush m_backgroundBrush; | |
771 | wxColour m_textForegroundColour; | |
772 | wxColour m_textBackgroundColour; | |
773 | wxFont m_font; | |
d275c7eb VZ |
774 | |
775 | #if wxUSE_PALETTE | |
a23fd0e1 | 776 | wxPalette m_palette; |
b95edd47 | 777 | bool m_hasCustomPalette; |
d275c7eb | 778 | #endif // wxUSE_PALETTE |
a23fd0e1 VZ |
779 | |
780 | private: | |
ac84e37d | 781 | DECLARE_NO_COPY_CLASS(wxDCBase) |
cd9da200 | 782 | DECLARE_ABSTRACT_CLASS(wxDCBase) |
a23fd0e1 VZ |
783 | }; |
784 | ||
785 | // ---------------------------------------------------------------------------- | |
786 | // now include the declaration of wxDC class | |
787 | // ---------------------------------------------------------------------------- | |
788 | ||
2049ba38 | 789 | #if defined(__WXMSW__) |
a23fd0e1 | 790 | #include "wx/msw/dc.h" |
2049ba38 | 791 | #elif defined(__WXMOTIF__) |
a23fd0e1 | 792 | #include "wx/motif/dc.h" |
2049ba38 | 793 | #elif defined(__WXGTK__) |
a23fd0e1 | 794 | #include "wx/gtk/dc.h" |
83df96d6 JS |
795 | #elif defined(__WXX11__) |
796 | #include "wx/x11/dc.h" | |
1e6feb95 VZ |
797 | #elif defined(__WXMGL__) |
798 | #include "wx/mgl/dc.h" | |
34138703 | 799 | #elif defined(__WXMAC__) |
a23fd0e1 | 800 | #include "wx/mac/dc.h" |
f4515f98 DE |
801 | #elif defined(__WXCOCOA__) |
802 | #include "wx/cocoa/dc.h" | |
1777b9bb DW |
803 | #elif defined(__WXPM__) |
804 | #include "wx/os2/dc.h" | |
c801d85f KB |
805 | #endif |
806 | ||
1e6feb95 VZ |
807 | // ---------------------------------------------------------------------------- |
808 | // helper class: you can use it to temporarily change the DC text colour and | |
809 | // restore it automatically when the object goes out of scope | |
810 | // ---------------------------------------------------------------------------- | |
811 | ||
812 | class WXDLLEXPORT wxDCTextColourChanger | |
813 | { | |
814 | public: | |
ba161d7e | 815 | wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { } |
1e6feb95 VZ |
816 | |
817 | ~wxDCTextColourChanger() | |
818 | { | |
819 | if ( m_colFgOld.Ok() ) | |
820 | m_dc.SetTextForeground(m_colFgOld); | |
821 | } | |
822 | ||
823 | void Set(const wxColour& col) | |
824 | { | |
825 | if ( !m_colFgOld.Ok() ) | |
826 | m_colFgOld = m_dc.GetTextForeground(); | |
827 | m_dc.SetTextForeground(col); | |
828 | } | |
829 | ||
830 | private: | |
831 | wxDC& m_dc; | |
832 | ||
833 | wxColour m_colFgOld; | |
fc7a2a60 VZ |
834 | |
835 | DECLARE_NO_COPY_CLASS(wxDCTextColourChanger) | |
1e6feb95 VZ |
836 | }; |
837 | ||
e26be42b VZ |
838 | // ---------------------------------------------------------------------------- |
839 | // another small helper class: sets the clipping region in its ctor and | |
840 | // destroys it in the dtor | |
841 | // ---------------------------------------------------------------------------- | |
842 | ||
843 | class WXDLLEXPORT wxDCClipper | |
844 | { | |
845 | public: | |
846 | wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc) | |
847 | { dc.SetClippingRegion(r.x, r.y, r.width, r.height); } | |
848 | wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc) | |
849 | { dc.SetClippingRegion(x, y, w, h); } | |
850 | ||
851 | ~wxDCClipper() { m_dc.DestroyClippingRegion(); } | |
852 | ||
853 | private: | |
854 | wxDC& m_dc; | |
fc7a2a60 VZ |
855 | |
856 | DECLARE_NO_COPY_CLASS(wxDCClipper) | |
e26be42b VZ |
857 | }; |
858 | ||
c801d85f | 859 | #endif |
34138703 | 860 | // _WX_DC_H_BASE_ |