- forward declare wxDC for use as a pointer or reference parameter in
[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 #if defined(__GNUG__) && !defined(__APPLE__)
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 wxDC;
34 class WXDLLEXPORT wxDCBase;
35
36 class WXDLLEXPORT wxDrawObject
37 {
38 public:
39
40 wxDrawObject()
41 : m_isBBoxValid(FALSE)
42 , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
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 : 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
133 {
134 ResetBoundingBox();
135 }
136
137 ~wxDCBase() { }
138
139 virtual void BeginDrawing() { }
140 virtual void EndDrawing() { }
141
142 // graphic primitives
143 // ------------------
144
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
152 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col,
153 int style = wxFLOOD_SURFACE)
154 { return DoFloodFill(x, y, col, style); }
155 bool FloodFill(const wxPoint& pt, const wxColour& col,
156 int style = wxFLOOD_SURFACE)
157 { return DoFloodFill(pt.x, pt.y, col, style); }
158
159 bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const
160 { return DoGetPixel(x, y, col); }
161 bool GetPixel(const wxPoint& pt, wxColour *col) const
162 { return DoGetPixel(pt.x, pt.y, col); }
163
164 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
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
169 void CrossHair(wxCoord x, wxCoord y)
170 { DoCrossHair(x, y); }
171 void CrossHair(const wxPoint& pt)
172 { DoCrossHair(pt.x, pt.y); }
173
174 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
175 wxCoord xc, wxCoord yc)
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
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
186 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
187 double sa, double ea)
188 { DoDrawEllipticArc(x, y, w, h, sa, ea); }
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
193 void DrawPoint(wxCoord x, wxCoord y)
194 { DoDrawPoint(x, y); }
195 void DrawPoint(const wxPoint& pt)
196 { DoDrawPoint(pt.x, pt.y); }
197
198 void DrawLines(int n, wxPoint points[],
199 wxCoord xoffset = 0, wxCoord yoffset = 0)
200 { DoDrawLines(n, points, xoffset, yoffset); }
201 void DrawLines(const wxList *list,
202 wxCoord xoffset = 0, wxCoord yoffset = 0);
203
204 void DrawPolygon(int n, wxPoint points[],
205 wxCoord xoffset = 0, wxCoord yoffset = 0,
206 int fillStyle = wxODDEVEN_RULE)
207 { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
208
209 void DrawPolygon(const wxList *list,
210 wxCoord xoffset = 0, wxCoord yoffset = 0,
211 int fillStyle = wxODDEVEN_RULE);
212
213 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
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
220 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
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
229 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
230 { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
231 void DrawCircle(const wxPoint& pt, wxCoord radius)
232 { DrawCircle(pt.x, pt.y, radius); }
233
234 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
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
241 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
242 { DoDrawIcon(icon, x, y); }
243 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
244 { DoDrawIcon(icon, pt.x, pt.y); }
245
246 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
247 bool useMask = FALSE)
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
253 void DrawText(const wxString& text, wxCoord x, wxCoord y)
254 { DoDrawText(text, x, y); }
255 void DrawText(const wxString& text, const wxPoint& pt)
256 { DoDrawText(text, pt.x, pt.y); }
257
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
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
279 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
280 wxDC *source, wxCoord xsrc, wxCoord ysrc,
281 int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1)
282 {
283 return DoBlit(xdest, ydest, width, height,
284 source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
285 }
286 bool Blit(const wxPoint& destPt, const wxSize& sz,
287 wxDC *source, const wxPoint& srcPt,
288 int rop = wxCOPY, bool useMask = FALSE, const wxPoint& srcPtMask = wxPoint(-1, -1))
289 {
290 return DoBlit(destPt.x, destPt.y, sz.x, sz.y,
291 source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
292 }
293
294 #if wxUSE_SPLINES
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);
299 void DrawSpline(int n, wxPoint points[]);
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
309 virtual bool StartDoc(const wxString& WXUNUSED(message)) { return TRUE; }
310 virtual void EndDoc() { }
311
312 virtual void StartPage() { }
313 virtual void EndPage() { }
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;
323 #if wxUSE_PALETTE
324 virtual void SetPalette(const wxPalette& palette) = 0;
325 #endif // wxUSE_PALETTE
326
327 // clipping region
328 // ---------------
329
330 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
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
341 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
342 { DoGetClippingBox(x, y, w, h); }
343 void GetClippingBox(wxRect& rect) const
344 {
345 // Necessary to use intermediate variables for 16-bit compilation
346 wxCoord x, y, w, h;
347 DoGetClippingBox(&x, &y, &w, &h);
348 rect.x = x; rect.y = y; rect.width = w; rect.height = h;
349 }
350
351 // text extent
352 // -----------
353
354 virtual wxCoord GetCharHeight() const = 0;
355 virtual wxCoord GetCharWidth() const = 0;
356
357 // only works for single line strings
358 void GetTextExtent(const wxString& string,
359 wxCoord *x, wxCoord *y,
360 wxCoord *descent = NULL,
361 wxCoord *externalLeading = NULL,
362 wxFont *theFont = NULL) const
363 { DoGetTextExtent(string, x, y, descent, externalLeading, theFont); }
364
365 // works for single as well as multi-line strings
366 virtual void GetMultiLineTextExtent(const wxString& text,
367 wxCoord *width,
368 wxCoord *height,
369 wxCoord *heightLine = NULL,
370 wxFont *font = NULL);
371
372 // size and resolution
373 // -------------------
374
375 // in device units
376 void GetSize(int *width, int *height) const
377 { DoGetSize(width, height); }
378 wxSize GetSize() const
379 {
380 int w, h;
381 DoGetSize(&w, &h);
382
383 return wxSize(w, h);
384 }
385
386 // in mm
387 void GetSizeMM(int* width, int* height) const
388 { DoGetSizeMM(width, height); }
389 wxSize GetSizeMM() const
390 {
391 int w, h;
392 DoGetSizeMM(&w, &h);
393
394 return wxSize(w, h);
395 }
396
397 // coordinates conversions
398 // -----------------------
399
400 // This group of functions does actual conversion of the input, as you'd
401 // expect.
402 wxCoord DeviceToLogicalX(wxCoord x) const;
403 wxCoord DeviceToLogicalY(wxCoord y) const;
404 wxCoord DeviceToLogicalXRel(wxCoord x) const;
405 wxCoord DeviceToLogicalYRel(wxCoord y) const;
406 wxCoord LogicalToDeviceX(wxCoord x) const;
407 wxCoord LogicalToDeviceY(wxCoord y) const;
408 wxCoord LogicalToDeviceXRel(wxCoord x) const;
409 wxCoord LogicalToDeviceYRel(wxCoord y) const;
410
411 // query DC capabilities
412 // ---------------------
413
414 virtual bool CanDrawBitmap() const = 0;
415 virtual bool CanGetTextExtent() const = 0;
416
417 // colour depth
418 virtual int GetDepth() const = 0;
419
420 // Resolution in Pixels per inch
421 virtual wxSize GetPPI() const = 0;
422
423 virtual bool Ok() const { return m_ok; }
424
425 // accessors
426 // ---------
427
428 // const...
429 int GetBackgroundMode() const { return m_backgroundMode; }
430 const wxBrush& GetBackground() const { return m_backgroundBrush; }
431 const wxBrush& GetBrush() const { return m_brush; }
432 const wxFont& GetFont() const { return m_font; }
433 const wxPen& GetPen() const { return m_pen; }
434 const wxColour& GetTextBackground() const { return m_textBackgroundColour; }
435 const wxColour& GetTextForeground() const { return m_textForegroundColour; }
436
437 // ... and non const
438 wxBrush& GetBackground() { return m_backgroundBrush; }
439 wxBrush& GetBrush() { return m_brush; }
440 wxFont& GetFont() { return m_font; }
441 wxPen& GetPen() { return m_pen; }
442 wxColour& GetTextBackground() { return m_textBackgroundColour; }
443 wxColour& GetTextForeground() { return m_textForegroundColour; }
444
445 virtual void SetTextForeground(const wxColour& colour)
446 { m_textForegroundColour = colour; }
447 virtual void SetTextBackground(const wxColour& colour)
448 { m_textBackgroundColour = colour; }
449
450 int GetMapMode() const { return m_mappingMode; }
451 virtual void SetMapMode(int mode) = 0;
452
453 virtual void GetUserScale(double *x, double *y) const
454 {
455 if ( x ) *x = m_userScaleX;
456 if ( y ) *y = m_userScaleY;
457 }
458 virtual void SetUserScale(double x, double y) = 0;
459
460 virtual void GetLogicalScale(double *x, double *y)
461 {
462 if ( x ) *x = m_logicalScaleX;
463 if ( y ) *y = m_logicalScaleY;
464 }
465 virtual void SetLogicalScale(double x, double y)
466 {
467 m_logicalScaleX = x;
468 m_logicalScaleY = y;
469 }
470
471 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const
472 { DoGetLogicalOrigin(x, y); }
473 wxPoint GetLogicalOrigin() const
474 { wxCoord x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
475 virtual void SetLogicalOrigin(wxCoord x, wxCoord y) = 0;
476
477 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const
478 { DoGetDeviceOrigin(x, y); }
479 wxPoint GetDeviceOrigin() const
480 { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
481 virtual void SetDeviceOrigin(wxCoord x, wxCoord y) = 0;
482
483 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0;
484
485 int GetLogicalFunction() const { return m_logicalFunction; }
486 virtual void SetLogicalFunction(int function) = 0;
487
488 // Sometimes we need to override optimization, e.g. if other software is
489 // drawing onto our surface and we can't be sure of who's done what.
490 //
491 // FIXME: is this (still) used?
492 virtual void SetOptimization(bool WXUNUSED(opt)) { }
493 virtual bool GetOptimization() { return FALSE; }
494
495 // Some platforms have a DC cache, which should be cleared
496 // at appropriate points such as after a series of DC operations.
497 // Put ClearCache in the wxDC implementation class, since it has to be
498 // static.
499 // static void ClearCache() ;
500 #if 0 // wxUSE_DC_CACHEING
501 static void EnableCache(bool cacheing) { sm_cacheing = cacheing; }
502 static bool CacheEnabled() { return sm_cacheing ; }
503 #endif
504
505 // bounding box
506 // ------------
507
508 virtual void CalcBoundingBox(wxCoord x, wxCoord y)
509 {
510 if ( m_isBBoxValid )
511 {
512 if ( x < m_minX ) m_minX = x;
513 if ( y < m_minY ) m_minY = y;
514 if ( x > m_maxX ) m_maxX = x;
515 if ( y > m_maxY ) m_maxY = y;
516 }
517 else
518 {
519 m_isBBoxValid = TRUE;
520
521 m_minX = x;
522 m_minY = y;
523 m_maxX = x;
524 m_maxY = y;
525 }
526 }
527
528 void ResetBoundingBox()
529 {
530 m_isBBoxValid = FALSE;
531
532 m_minX = m_maxX = m_minY = m_maxY = 0;
533 }
534
535 // Get the final bounding box of the PostScript or Metafile picture.
536 wxCoord MinX() const { return m_minX; }
537 wxCoord MaxX() const { return m_maxX; }
538 wxCoord MinY() const { return m_minY; }
539 wxCoord MaxY() const { return m_maxY; }
540
541 // misc old functions
542 // ------------------
543
544 // for compatibility with the old code when wxCoord was long everywhere
545 #ifndef __WIN16__
546 void GetTextExtent(const wxString& string,
547 long *x, long *y,
548 long *descent = NULL,
549 long *externalLeading = NULL,
550 wxFont *theFont = NULL) const
551 {
552 wxCoord x2, y2, descent2, externalLeading2;
553 DoGetTextExtent(string, &x2, &y2,
554 &descent2, &externalLeading2,
555 theFont);
556 if ( x )
557 *x = x2;
558 if ( y )
559 *y = y2;
560 if ( descent )
561 *descent = descent2;
562 if ( externalLeading )
563 *externalLeading = externalLeading2;
564 }
565
566 void GetLogicalOrigin(long *x, long *y) const
567 {
568 wxCoord x2, y2;
569 DoGetLogicalOrigin(&x2, &y2);
570 if ( x )
571 *x = x2;
572 if ( y )
573 *y = y2;
574 }
575
576 void GetDeviceOrigin(long *x, long *y) const
577 {
578 wxCoord x2, y2;
579 DoGetDeviceOrigin(&x2, &y2);
580 if ( x )
581 *x = x2;
582 if ( y )
583 *y = y2;
584 }
585 void GetClippingBox(long *x, long *y, long *w, long *h) const
586 {
587 wxCoord xx,yy,ww,hh;
588 DoGetClippingBox(&xx, &yy, &ww, &hh);
589 if (x) *x = xx;
590 if (y) *y = yy;
591 if (w) *w = ww;
592 if (h) *h = hh;
593 }
594 #endif // !Win16
595
596 #if WXWIN_COMPATIBILITY
597
598 #if wxUSE_PALETTE
599 virtual void SetColourMap(const wxPalette& palette) { SetPalette(palette); }
600 #endif // wxUSE_PALETTE
601
602 void GetTextExtent(const wxString& string, float *x, float *y,
603 float *descent = NULL, float *externalLeading = NULL,
604 wxFont *theFont = NULL, bool use16bit = FALSE) const ;
605 void GetSize(float* width, float* height) const { int w, h; GetSize(& w, & h); *width = w; *height = h; }
606 void GetSizeMM(float *width, float *height) const { int w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; }
607
608 #endif // WXWIN_COMPATIBILITY
609
610 protected:
611 // the pure virtual functions which should be implemented by wxDC
612 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
613 int style = wxFLOOD_SURFACE) = 0;
614
615 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
616
617 virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
618 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
619
620 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
621 wxCoord x2, wxCoord y2,
622 wxCoord xc, wxCoord yc) = 0;
623 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
624 wxCoord width, wxCoord height);
625 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
626 double sa, double ea) = 0;
627
628 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0;
629 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
630 wxCoord width, wxCoord height,
631 double radius) = 0;
632 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
633 wxCoord width, wxCoord height) = 0;
634
635 virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
636
637 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
638 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
639 bool useMask = FALSE) = 0;
640
641 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
642 virtual void DoDrawRotatedText(const wxString& text,
643 wxCoord x, wxCoord y, double angle) = 0;
644
645 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
646 wxCoord width, wxCoord height,
647 wxDC *source, wxCoord xsrc, wxCoord ysrc,
648 int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1) = 0;
649
650 virtual void DoGetSize(int *width, int *height) const = 0;
651 virtual void DoGetSizeMM(int* width, int* height) const = 0;
652
653 virtual void DoDrawLines(int n, wxPoint points[],
654 wxCoord xoffset, wxCoord yoffset) = 0;
655 virtual void DoDrawPolygon(int n, wxPoint points[],
656 wxCoord xoffset, wxCoord yoffset,
657 int fillStyle = wxODDEVEN_RULE) = 0;
658
659 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
660 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
661 wxCoord width, wxCoord height) = 0;
662
663 // FIXME are these functions really different?
664 virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y,
665 wxCoord *w, wxCoord *h)
666 { DoGetClippingBox(x, y, w, h); }
667 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
668 wxCoord *w, wxCoord *h) const
669 {
670 if ( m_clipping )
671 {
672 if ( x ) *x = m_clipX1;
673 if ( y ) *y = m_clipY1;
674 if ( w ) *w = m_clipX2 - m_clipX1;
675 if ( h ) *h = m_clipY2 - m_clipY1;
676 }
677 else
678 {
679 *x = *y = *w = *h = 0;
680 }
681 }
682
683 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
684 {
685 if ( x ) *x = m_logicalOriginX;
686 if ( y ) *y = m_logicalOriginY;
687 }
688
689 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
690 {
691 if ( x ) *x = m_deviceOriginX;
692 if ( y ) *y = m_deviceOriginY;
693 }
694
695 virtual void DoGetTextExtent(const wxString& string,
696 wxCoord *x, wxCoord *y,
697 wxCoord *descent = NULL,
698 wxCoord *externalLeading = NULL,
699 wxFont *theFont = NULL) const = 0;
700
701 #if wxUSE_SPLINES
702 virtual void DoDrawSpline(wxList *points);
703 #endif
704
705 protected:
706 // flags
707 bool m_colour:1;
708 bool m_ok:1;
709 bool m_clipping:1;
710 bool m_isInteractive:1;
711 bool m_isBBoxValid:1;
712 #if wxUSE_DC_CACHEING
713 // static bool sm_cacheing;
714 #endif
715
716 // coordinate system variables
717
718 // TODO short descriptions of what exactly they are would be nice...
719
720 wxCoord m_logicalOriginX, m_logicalOriginY;
721 wxCoord m_deviceOriginX, m_deviceOriginY;
722
723 double m_logicalScaleX, m_logicalScaleY;
724 double m_userScaleX, m_userScaleY;
725 double m_scaleX, m_scaleY;
726
727 // Used by SetAxisOrientation() to invert the axes
728 int m_signX, m_signY;
729
730 // bounding and clipping boxes
731 wxCoord m_minX, m_minY, m_maxX, m_maxY;
732 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
733
734 int m_logicalFunction;
735 int m_backgroundMode;
736 int m_mappingMode;
737
738 // GDI objects
739 wxPen m_pen;
740 wxBrush m_brush;
741 wxBrush m_backgroundBrush;
742 wxColour m_textForegroundColour;
743 wxColour m_textBackgroundColour;
744 wxFont m_font;
745
746 #if wxUSE_PALETTE
747 wxPalette m_palette;
748 bool m_hasCustomPalette;
749 #endif // wxUSE_PALETTE
750
751 private:
752 DECLARE_NO_COPY_CLASS(wxDCBase)
753 DECLARE_ABSTRACT_CLASS(wxDCBase)
754 };
755
756 // ----------------------------------------------------------------------------
757 // now include the declaration of wxDC class
758 // ----------------------------------------------------------------------------
759
760 #if defined(__WXMSW__)
761 #include "wx/msw/dc.h"
762 #elif defined(__WXMOTIF__)
763 #include "wx/motif/dc.h"
764 #elif defined(__WXGTK__)
765 #include "wx/gtk/dc.h"
766 #elif defined(__WXX11__)
767 #include "wx/x11/dc.h"
768 #elif defined(__WXMGL__)
769 #include "wx/mgl/dc.h"
770 #elif defined(__WXMAC__)
771 #include "wx/mac/dc.h"
772 #elif defined(__WXCOCOA__)
773 #include "wx/cocoa/dc.h"
774 #elif defined(__WXPM__)
775 #include "wx/os2/dc.h"
776 #endif
777
778 // ----------------------------------------------------------------------------
779 // helper class: you can use it to temporarily change the DC text colour and
780 // restore it automatically when the object goes out of scope
781 // ----------------------------------------------------------------------------
782
783 class WXDLLEXPORT wxDCTextColourChanger
784 {
785 public:
786 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
787
788 ~wxDCTextColourChanger()
789 {
790 if ( m_colFgOld.Ok() )
791 m_dc.SetTextForeground(m_colFgOld);
792 }
793
794 void Set(const wxColour& col)
795 {
796 if ( !m_colFgOld.Ok() )
797 m_colFgOld = m_dc.GetTextForeground();
798 m_dc.SetTextForeground(col);
799 }
800
801 private:
802 wxDC& m_dc;
803
804 wxColour m_colFgOld;
805 };
806
807 // ----------------------------------------------------------------------------
808 // another small helper class: sets the clipping region in its ctor and
809 // destroys it in the dtor
810 // ----------------------------------------------------------------------------
811
812 class WXDLLEXPORT wxDCClipper
813 {
814 public:
815 wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc)
816 { dc.SetClippingRegion(r.x, r.y, r.width, r.height); }
817 wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc)
818 { dc.SetClippingRegion(x, y, w, h); }
819
820 ~wxDCClipper() { m_dc.DestroyClippingRegion(); }
821
822 private:
823 wxDC& m_dc;
824 };
825
826 #endif
827 // _WX_DC_H_BASE_