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