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