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