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