1. MSW message handling simplifications
[wxWidgets.git] / include / wx / dc.h
1 #ifndef _WX_DC_H_BASE_
2 #define _WX_DC_H_BASE_
3
4 #ifdef __GNUG__
5 #pragma interface "dcbase.h"
6 #endif
7
8 // ----------------------------------------------------------------------------
9 // headers which we must include here
10 // ----------------------------------------------------------------------------
11
12 #include "wx/object.h" // the base class
13
14 #include "wx/cursor.h" // we have member variables of these classes
15 #include "wx/font.h" // so we can't do without them
16 #include "wx/colour.h"
17 #include "wx/brush.h"
18 #include "wx/pen.h"
19 #include "wx/palette.h"
20
21 #include "wx/list.h" // we use wxList in inline functions
22
23 // ---------------------------------------------------------------------------
24 // types
25 // ---------------------------------------------------------------------------
26
27 // type which should be used (whenever possible, i.e. as long as it doesn't
28 // break compatibility) for screen coordinates
29 typedef int wxCoord;
30
31 // ---------------------------------------------------------------------------
32 // global variables
33 // ---------------------------------------------------------------------------
34
35 WXDLLEXPORT_DATA(extern int) wxPageNumber;
36
37 // ---------------------------------------------------------------------------
38 // wxDC is the device context - object on which any drawing is done
39 // ---------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxDCBase : public wxObject
42 {
43 DECLARE_ABSTRACT_CLASS(wxDCBase)
44
45 public:
46 wxDCBase()
47 {
48 m_clipping = FALSE;
49 m_ok = TRUE;
50
51 m_minX = m_minY = m_maxX = m_maxY = 0;
52
53 m_signX = m_signY = 1;
54
55 m_logicalOriginX = m_logicalOriginY =
56 m_deviceOriginX = m_deviceOriginY = 0;
57
58 m_logicalScaleX = m_logicalScaleY =
59 m_userScaleX = m_userScaleY =
60 m_scaleX = m_scaleY = 1.0;
61
62 m_logicalFunction = -1;
63
64 m_backgroundMode = wxTRANSPARENT;
65
66 m_mappingMode = wxMM_TEXT;
67
68 m_backgroundBrush = *wxWHITE_BRUSH;
69
70 m_textForegroundColour = *wxBLACK;
71 m_textBackgroundColour = *wxWHITE;
72
73 m_colour = wxColourDisplay();
74 }
75
76 ~wxDCBase() { }
77
78 virtual void BeginDrawing() { }
79 virtual void EndDrawing() { }
80
81 // graphic primitives
82 // ------------------
83
84 void FloodFill(long x, long y, const wxColour& col,
85 int style = wxFLOOD_SURFACE)
86 { DoFloodFill(x, y, col, style); }
87 void FloodFill(const wxPoint& pt, const wxColour& col,
88 int style = wxFLOOD_SURFACE)
89 { DoFloodFill(pt.x, pt.y, col, style); }
90
91 bool GetPixel(long x, long y, wxColour *col) const
92 { return DoGetPixel(x, y, col); }
93 bool GetPixel(const wxPoint& pt, wxColour *col) const
94 { return DoGetPixel(pt.x, pt.y, col); }
95
96 void DrawLine(long x1, long y1, long x2, long y2)
97 { DoDrawLine(x1, y1, x2, y2); }
98 void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
99 { DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
100
101 void CrossHair(long x, long y)
102 { DoCrossHair(x, y); }
103 void CrossHair(const wxPoint& pt)
104 { DoCrossHair(pt.x, pt.y); }
105
106 void DrawArc(long x1, long y1, long x2, long y2, long xc, long yc)
107 { DoDrawArc(x1, y1, x2, y2, xc, yc); }
108 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
109 { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
110
111 void DrawEllipticArc(long x, long y, long w, long h, double sa, double ea)
112 { DoDrawEllipticArc(x, y, x, y, sa, ea); }
113 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
114 double sa, double ea)
115 { DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
116
117 void DrawPoint(long x, long y)
118 { DoDrawPoint(x, y); }
119 void DrawPoint(const wxPoint& pt)
120 { DoDrawPoint(pt.x, pt.y); }
121
122 void DrawLines(int n, wxPoint points[], long xoffset = 0, long yoffset = 0)
123 { DoDrawLines(n, points, xoffset, yoffset); }
124 void DrawLines(const wxList *list, long xoffset = 0, long yoffset = 0)
125 {
126 int n = list->Number();
127 wxPoint *points = new wxPoint[n];
128
129 int i = 0;
130 for ( wxNode *node = list->First(); node; node = node->Next(), i++ )
131 {
132 wxPoint *point = (wxPoint *)node->Data();
133 points[i].x = point->x;
134 points[i].y = point->y;
135 }
136
137 DoDrawLines(n, points, xoffset, yoffset);
138
139 delete [] points;
140 }
141
142 void DrawPolygon(int n, wxPoint points[],
143 long xoffset = 0, long yoffset = 0,
144 int fillStyle = wxODDEVEN_RULE)
145 { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
146
147 void DrawPolygon(const wxList *list,
148 long xoffset = 0, long yoffset = 0,
149 int fillStyle = wxODDEVEN_RULE)
150 {
151 int n = list->Number();
152 wxPoint *points = new wxPoint[n];
153
154 int i = 0;
155 for ( wxNode *node = list->First(); node; node = node->Next(), i++ )
156 {
157 wxPoint *point = (wxPoint *)node->Data();
158 points[i].x = point->x;
159 points[i].y = point->y;
160 }
161
162 DoDrawPolygon(n, points, xoffset, yoffset, fillStyle);
163
164 delete [] points;
165 }
166
167 void DrawRectangle(long x, long y, long width, long height)
168 { DoDrawRectangle(x, y, width, height); }
169 void DrawRectangle(const wxPoint& pt, const wxSize& sz)
170 { DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); }
171 void DrawRectangle(const wxRect& rect)
172 { DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); }
173
174 void DrawRoundedRectangle(long x, long y, long width, long height,
175 double radius)
176 { DoDrawRoundedRectangle(x, y, width, height, radius); }
177 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
178 double radius)
179 { DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
180 void DrawRoundedRectangle(const wxRect& r, double radius)
181 { DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
182
183 void DrawEllipse(long x, long y, long width, long height)
184 { DoDrawEllipse(x, y, width, height); }
185 void DrawEllipse(const wxPoint& pt, const wxSize& sz)
186 { DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); }
187 void DrawEllipse(const wxRect& rect)
188 { DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); }
189
190 void DrawIcon(const wxIcon& icon, long x, long y)
191 { DoDrawIcon(icon, x, y); }
192 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
193 { DoDrawIcon(icon, pt.x, pt.y); }
194
195 void DrawBitmap(const wxBitmap &bmp, long x, long y, bool useMask = FALSE)
196 { DoDrawBitmap(bmp, x, y, useMask); }
197 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
198 bool useMask = FALSE)
199 { DoDrawBitmap(bmp, pt.x, pt.y, useMask); }
200
201 void DrawText(const wxString& text, long x, long y)
202 { DoDrawText(text, x, y); }
203 void DrawText(const wxString& text, const wxPoint& pt)
204 { DoDrawText(text, pt.x, pt.y); }
205
206 bool Blit(long xdest, long ydest, long width, long height,
207 wxDC *source, long xsrc, long ysrc,
208 int rop = wxCOPY, bool useMask = FALSE)
209 {
210 return DoBlit(xdest, ydest, width, height,
211 source, xsrc, ysrc, rop, useMask);
212 }
213 bool Blit(const wxPoint& destPt, const wxSize& sz,
214 wxDC *source, const wxPoint& srcPt,
215 int rop = wxCOPY, bool useMask = FALSE)
216 {
217 return DoBlit(destPt.x, destPt.y, sz.x, sz.y,
218 source, srcPt.x, srcPt.y, rop, useMask);
219 }
220
221 #if wxUSE_SPLINES
222 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
223 void DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3)
224 {
225 wxList point_list;
226
227 wxPoint *point1 = new wxPoint;
228 point1->x = x1; point1->y = y1;
229 point_list.Append((wxObject*)point1);
230
231 wxPoint *point2 = new wxPoint;
232 point2->x = x2; point2->y = y2;
233 point_list.Append((wxObject*)point2);
234
235 wxPoint *point3 = new wxPoint;
236 point3->x = x3; point3->y = y3;
237 point_list.Append((wxObject*)point3);
238
239 DrawSpline(&point_list);
240
241 for( wxNode *node = point_list.First(); node; node = node->Next() )
242 {
243 wxPoint *p = (wxPoint *)node->Data();
244 delete p;
245 }
246 }
247
248 void DrawSpline(int n, wxPoint points[])
249 {
250 wxList list;
251 for (int i =0; i < n; i++)
252 {
253 list.Append((wxObject*)&points[i]);
254 }
255
256 DrawSpline(&list);
257 }
258
259 void DrawSpline(wxList *points) { DoDrawSpline(points); }
260 #endif // wxUSE_SPLINES
261
262 // global DC operations
263 // --------------------
264
265 virtual void Clear() = 0;
266
267 virtual bool StartDoc(const wxString& message) = 0;
268 virtual void EndDoc() = 0;
269
270 virtual void StartPage() = 0;
271 virtual void EndPage() = 0;
272
273 // set objects to use for drawing
274 // ------------------------------
275
276 virtual void SetFont(const wxFont& font) = 0;
277 virtual void SetPen(const wxPen& pen) = 0;
278 virtual void SetBrush(const wxBrush& brush) = 0;
279 virtual void SetBackground(const wxBrush& brush) = 0;
280 virtual void SetBackgroundMode(int mode) = 0;
281 virtual void SetPalette(const wxPalette& palette) = 0;
282
283 // clipping region
284 // ---------------
285
286 void SetClippingRegion(long x, long y, long width, long height)
287 { DoSetClippingRegion(x, y, width, height); }
288 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
289 { DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); }
290 void SetClippingRegion(const wxRect& rect)
291 { DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
292 void SetClippingRegion(const wxRegion& region)
293 { DoSetClippingRegionAsRegion(region); }
294
295 virtual void DestroyClippingRegion() = 0;
296
297 void GetClippingBox(long *x, long *y, long *w, long *h) const
298 { DoGetClippingBox(x, y, w, h); }
299 void GetClippingBox(wxRect& rect) const
300 { DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); }
301
302 // text extent
303 // -----------
304
305 virtual long GetCharHeight() const = 0;
306 virtual long GetCharWidth() const = 0;
307 virtual void GetTextExtent(const wxString& string,
308 long *x, long *y,
309 long *descent = NULL,
310 long *externalLeading = NULL,
311 wxFont *theFont = NULL) const = 0;
312
313 // size and resolution
314 // -------------------
315
316 // in device units
317 void GetSize(int *width, int *height) const
318 { DoGetSize(width, height); }
319 wxSize GetSize() const
320 {
321 int w, h;
322 DoGetSize(&w, &h);
323
324 return wxSize(w, h);
325 }
326
327 // in mm
328 void GetSizeMM(int* width, int* height) const
329 { DoGetSizeMM(width, height); }
330 wxSize GetSizeMM() const
331 {
332 int w, h;
333 DoGetSizeMM(&w, &h);
334
335 return wxSize(w, h);
336 }
337
338 // coordinates conversions
339 // -----------------------
340
341 // This group of functions does actual conversion of the input, as you'd
342 // expect.
343 long DeviceToLogicalX(long x) const;
344 long DeviceToLogicalY(long y) const;
345 long DeviceToLogicalXRel(long x) const;
346 long DeviceToLogicalYRel(long y) const;
347 long LogicalToDeviceX(long x) const;
348 long LogicalToDeviceY(long y) const;
349 long LogicalToDeviceXRel(long x) const;
350 long LogicalToDeviceYRel(long y) const;
351
352 // query DC capabilities
353 // ---------------------
354
355 virtual bool CanDrawBitmap() const = 0;
356 virtual bool CanGetTextExtent() const = 0;
357
358 // colour depth
359 virtual int GetDepth() const = 0;
360
361 // Resolution in Pixels per inch
362 virtual wxSize GetPPI() const = 0;
363
364 virtual bool Ok() const { return m_ok; }
365
366 // accessors
367 // ---------
368
369 // const...
370 const wxBrush& GetBackground() const { return m_backgroundBrush; }
371 const wxBrush& GetBrush() const { return m_brush; }
372 const wxFont& GetFont() const { return m_font; }
373 const wxPen& GetPen() const { return m_pen; }
374 const wxColour& GetTextBackground() const { return m_textBackgroundColour; }
375 const wxColour& GetTextForeground() const { return m_textForegroundColour; }
376
377 // ... and non const
378 wxBrush& GetBackground() { return m_backgroundBrush; }
379 wxBrush& GetBrush() { return m_brush; }
380 wxFont& GetFont() { return m_font; }
381 wxPen& GetPen() { return m_pen; }
382 wxColour& GetTextBackground() { return m_textBackgroundColour; }
383 wxColour& GetTextForeground() { return m_textForegroundColour; }
384
385 virtual void SetTextForeground(const wxColour& colour)
386 { m_textForegroundColour = colour; }
387 virtual void SetTextBackground(const wxColour& colour)
388 { m_textBackgroundColour = colour; }
389
390 int GetMapMode() const { return m_mappingMode; }
391 virtual void SetMapMode(int mode) = 0;
392
393 virtual void GetUserScale(double *x, double *y) const
394 {
395 if ( x ) *x = m_userScaleX;
396 if ( y ) *y = m_userScaleY;
397 }
398 virtual void SetUserScale(double x, double y) = 0;
399
400 virtual void SetSystemScale(double x, double y) = 0;
401
402 virtual void GetLogicalScale(double *x, double *y)
403 {
404 if ( x ) *x = m_logicalScaleX;
405 if ( y ) *y = m_logicalScaleY;
406 }
407 virtual void SetLogicalScale(double x, double y)
408 {
409 m_logicalScaleX = x;
410 m_logicalScaleY = y;
411 }
412
413 void GetLogicalOrigin(long *x, long *y) const
414 { DoGetLogicalOrigin(x, y); }
415 wxPoint GetLogicalOrigin() const
416 { long x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
417 virtual void SetLogicalOrigin(long x, long y) = 0;
418
419 void GetDeviceOrigin(long *x, long *y) const
420 { DoGetDeviceOrigin(x, y); }
421 wxPoint GetDeviceOrigin() const
422 { long x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
423 virtual void SetDeviceOrigin(long x, long y) = 0;
424
425 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0;
426
427 int GetLogicalFunction() const { return m_logicalFunction; }
428 virtual void SetLogicalFunction(int function) = 0;
429
430 // Sometimes we need to override optimization, e.g. if other software is
431 // drawing onto our surface and we can't be sure of who's done what.
432 //
433 // FIXME: is this (still) used?
434 virtual void SetOptimization(bool WXUNUSED(opt)) { }
435 virtual bool GetOptimization() { return FALSE; }
436
437 // bounding box
438 // ------------
439
440 virtual void CalcBoundingBox(long x, long y)
441 {
442 if (x < m_minX) m_minX = x;
443 if (y < m_minY) m_minY = y;
444 if (x > m_maxX) m_maxX = x;
445 if (y > m_maxY) m_maxY = y;
446 }
447
448 // Get the final bounding box of the PostScript or Metafile picture.
449 long MinX() const { return m_minX; }
450 long MaxX() const { return m_maxX; }
451 long MinY() const { return m_minY; }
452 long MaxY() const { return m_maxY; }
453
454 // misc old functions
455 // ------------------
456
457 #if WXWIN_COMPATIBILITY
458 virtual void SetColourMap(const wxPalette& palette) { SetPalette(palette); }
459 void GetTextExtent(const wxString& string, float *x, float *y,
460 float *descent = NULL, float *externalLeading = NULL,
461 wxFont *theFont = NULL, bool use16bit = FALSE) const ;
462 void GetSize(float* width, float* height) const { int w, h; GetSize(& w, & h); *width = w; *height = h; }
463 void GetSizeMM(float *width, float *height) const { long w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; }
464 #endif // WXWIN_COMPATIBILITY
465
466 protected:
467 // the pure virtual functions which should be implemented by wxDC
468 virtual void DoFloodFill(long x, long y, const wxColour& col,
469 int style = wxFLOOD_SURFACE) = 0;
470
471 virtual bool DoGetPixel(long x, long y, wxColour *col) const = 0;
472
473 virtual void DoDrawPoint(long x, long y) = 0;
474 virtual void DoDrawLine(long x1, long y1, long x2, long y2) = 0;
475
476 virtual void DoDrawArc(long x1, long y1,
477 long x2, long y2,
478 long xc, long yc) = 0;
479 virtual void DoDrawEllipticArc(long x, long y, long w, long h,
480 double sa, double ea) = 0;
481
482 virtual void DoDrawRectangle(long x, long y, long width, long height) = 0;
483 virtual void DoDrawRoundedRectangle(long x, long y,
484 long width, long height,
485 double radius) = 0;
486 virtual void DoDrawEllipse(long x, long y, long width, long height) = 0;
487
488 virtual void DoCrossHair(long x, long y) = 0;
489
490 virtual void DoDrawIcon(const wxIcon& icon, long x, long y) = 0;
491 virtual void DoDrawBitmap(const wxBitmap &bmp, long x, long y,
492 bool useMask = FALSE) = 0;
493
494 virtual void DoDrawText(const wxString& text, long x, long y) = 0;
495
496 virtual bool DoBlit(long xdest, long ydest, long width, long height,
497 wxDC *source, long xsrc, long ysrc,
498 int rop = wxCOPY, bool useMask = FALSE) = 0;
499
500 virtual void DoGetSize(int *width, int *height) const = 0;
501 virtual void DoGetSizeMM(int* width, int* height) const = 0;
502
503 virtual void DoDrawLines(int n, wxPoint points[],
504 long xoffset, long yoffset) = 0;
505 virtual void DoDrawPolygon(int n, wxPoint points[],
506 long xoffset, long yoffset,
507 int fillStyle = wxODDEVEN_RULE) = 0;
508
509 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
510 virtual void DoSetClippingRegion(long x, long y,
511 long width, long height) = 0;
512 virtual void DoGetClippingRegion(long *x, long *y,
513 long *width, long *height) = 0;
514 virtual void DoGetClippingBox(long *x, long *y,
515 long *w, long *h) const
516 {
517 if ( m_clipping )
518 {
519 if ( x ) *x = m_clipX1;
520 if ( y ) *y = m_clipY1;
521 if ( w ) *w = m_clipX2 - m_clipX1;
522 if ( h ) *h = m_clipY2 - m_clipY1;
523 }
524 else
525 {
526 *x = *y = *w = *h = 0;
527 }
528 }
529
530 virtual void DoGetLogicalOrigin(long *x, long *y) const
531 {
532 if ( x ) *x = m_logicalOriginX;
533 if ( y ) *y = m_logicalOriginY;
534 }
535
536 virtual void DoGetDeviceOrigin(long *x, long *y) const
537 {
538 if ( x ) *x = m_deviceOriginX;
539 if ( y ) *y = m_deviceOriginY;
540 }
541
542 virtual void DoDrawSpline(wxList *points) = 0;
543
544 protected:
545 // flags
546 bool m_colour:1;
547 bool m_ok:1;
548 bool m_clipping:1;
549 bool m_isInteractive:1;
550
551 // coordinate system variables
552
553 // TODO short descriptions of what exactly they are would be nice...
554
555 long m_logicalOriginX, m_logicalOriginY;
556 long m_deviceOriginX, m_deviceOriginY;
557
558 double m_logicalScaleX, m_logicalScaleY;
559 double m_userScaleX, m_userScaleY;
560 double m_scaleX, m_scaleY;
561
562 // Used by SetAxisOrientation() to invert the axes
563 int m_signX, m_signY;
564
565 // bounding and clipping boxes
566 long m_minX, m_minY, m_maxX, m_maxY;
567 long m_clipX1, m_clipY1, m_clipX2, m_clipY2;
568
569 int m_logicalFunction;
570 int m_backgroundMode;
571 int m_mappingMode;
572
573 // GDI objects
574 wxPen m_pen;
575 wxBrush m_brush;
576 wxBrush m_backgroundBrush;
577 wxColour m_textForegroundColour;
578 wxColour m_textBackgroundColour;
579 wxFont m_font;
580 wxPalette m_palette;
581
582 private:
583 DECLARE_NO_COPY_CLASS(wxDCBase);
584 };
585
586 // ----------------------------------------------------------------------------
587 // now include the declaration of wxDC class
588 // ----------------------------------------------------------------------------
589
590 #if defined(__WXMSW__)
591 #include "wx/msw/dc.h"
592 #elif defined(__WXMOTIF__)
593 #include "wx/motif/dc.h"
594 #elif defined(__WXGTK__)
595 #include "wx/gtk/dc.h"
596 #elif defined(__WXQT__)
597 #include "wx/qt/dc.h"
598 #elif defined(__WXMAC__)
599 #include "wx/mac/dc.h"
600 #elif defined(__WXSTUBS__)
601 #include "wx/stubs/dc.h"
602 #endif
603
604 #endif
605 // _WX_DC_H_BASE_