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