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