]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dc.h
wxScrolledWindow inherits from wxPanel to
[wxWidgets.git] / include / wx / dc.h
CommitLineData
34138703
JS
1#ifndef _WX_DC_H_BASE_
2#define _WX_DC_H_BASE_
c801d85f 3
a23fd0e1
VZ
4#ifdef __GNUG__
5 #pragma interface "dcbase.h"
64698f9a 6 #pragma implementation "dcbase.h"
a23fd0e1
VZ
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
30typedef int wxCoord;
31
32// ---------------------------------------------------------------------------
33// global variables
34// ---------------------------------------------------------------------------
35
36WXDLLEXPORT_DATA(extern int) wxPageNumber;
37
38// ---------------------------------------------------------------------------
39// wxDC is the device context - object on which any drawing is done
40// ---------------------------------------------------------------------------
41
42class WXDLLEXPORT wxDCBase : public wxObject
43{
44 DECLARE_ABSTRACT_CLASS(wxDCBase)
45
46public:
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 =
220af862 60 m_userScaleX = m_userScaleY =
a23fd0e1
VZ
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)
7b90a8f2 113 { DoDrawEllipticArc(x, y, w, h, sa, ea); }
a23fd0e1
VZ
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); }
bd5dd957 125 void DrawLines(const wxList *list, long xoffset = 0, long yoffset = 0);
a23fd0e1
VZ
126
127 void DrawPolygon(int n, wxPoint points[],
128 long xoffset = 0, long yoffset = 0,
129 int fillStyle = wxODDEVEN_RULE)
130 { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
131
132 void DrawPolygon(const wxList *list,
133 long xoffset = 0, long yoffset = 0,
bd5dd957 134 int fillStyle = wxODDEVEN_RULE);
a23fd0e1
VZ
135
136 void DrawRectangle(long x, long y, long width, long height)
137 { DoDrawRectangle(x, y, width, height); }
138 void DrawRectangle(const wxPoint& pt, const wxSize& sz)
139 { DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); }
140 void DrawRectangle(const wxRect& rect)
141 { DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); }
142
143 void DrawRoundedRectangle(long x, long y, long width, long height,
144 double radius)
145 { DoDrawRoundedRectangle(x, y, width, height, radius); }
146 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
147 double radius)
148 { DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
149 void DrawRoundedRectangle(const wxRect& r, double radius)
150 { DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
151
220af862
VZ
152 void DrawCircle(long x, long y, long radius)
153 { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
a23fd0e1
VZ
154 void DrawEllipse(long x, long y, long width, long height)
155 { DoDrawEllipse(x, y, width, height); }
156 void DrawEllipse(const wxPoint& pt, const wxSize& sz)
157 { DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); }
158 void DrawEllipse(const wxRect& rect)
159 { DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); }
160
161 void DrawIcon(const wxIcon& icon, long x, long y)
162 { DoDrawIcon(icon, x, y); }
163 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
164 { DoDrawIcon(icon, pt.x, pt.y); }
165
166 void DrawBitmap(const wxBitmap &bmp, long x, long y, bool useMask = FALSE)
167 { DoDrawBitmap(bmp, x, y, useMask); }
168 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
169 bool useMask = FALSE)
170 { DoDrawBitmap(bmp, pt.x, pt.y, useMask); }
171
172 void DrawText(const wxString& text, long x, long y)
173 { DoDrawText(text, x, y); }
174 void DrawText(const wxString& text, const wxPoint& pt)
175 { DoDrawText(text, pt.x, pt.y); }
176
177 bool Blit(long xdest, long ydest, long width, long height,
178 wxDC *source, long xsrc, long ysrc,
179 int rop = wxCOPY, bool useMask = FALSE)
180 {
181 return DoBlit(xdest, ydest, width, height,
182 source, xsrc, ysrc, rop, useMask);
183 }
184 bool Blit(const wxPoint& destPt, const wxSize& sz,
185 wxDC *source, const wxPoint& srcPt,
186 int rop = wxCOPY, bool useMask = FALSE)
187 {
188 return DoBlit(destPt.x, destPt.y, sz.x, sz.y,
189 source, srcPt.x, srcPt.y, rop, useMask);
190 }
191
192#if wxUSE_SPLINES
bd5dd957
BM
193// TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
194 void DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3);
195 void DrawSpline(int n, wxPoint points[]);
a23fd0e1
VZ
196
197 void DrawSpline(wxList *points) { DoDrawSpline(points); }
198#endif // wxUSE_SPLINES
199
200 // global DC operations
201 // --------------------
202
203 virtual void Clear() = 0;
204
205 virtual bool StartDoc(const wxString& message) = 0;
206 virtual void EndDoc() = 0;
207
208 virtual void StartPage() = 0;
209 virtual void EndPage() = 0;
210
211 // set objects to use for drawing
212 // ------------------------------
213
214 virtual void SetFont(const wxFont& font) = 0;
215 virtual void SetPen(const wxPen& pen) = 0;
216 virtual void SetBrush(const wxBrush& brush) = 0;
217 virtual void SetBackground(const wxBrush& brush) = 0;
218 virtual void SetBackgroundMode(int mode) = 0;
219 virtual void SetPalette(const wxPalette& palette) = 0;
220
221 // clipping region
222 // ---------------
223
224 void SetClippingRegion(long x, long y, long width, long height)
225 { DoSetClippingRegion(x, y, width, height); }
226 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
227 { DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); }
228 void SetClippingRegion(const wxRect& rect)
229 { DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
230 void SetClippingRegion(const wxRegion& region)
231 { DoSetClippingRegionAsRegion(region); }
232
233 virtual void DestroyClippingRegion() = 0;
234
235 void GetClippingBox(long *x, long *y, long *w, long *h) const
236 { DoGetClippingBox(x, y, w, h); }
237 void GetClippingBox(wxRect& rect) const
238 { DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); }
239
240 // text extent
241 // -----------
242
243 virtual long GetCharHeight() const = 0;
244 virtual long GetCharWidth() const = 0;
245 virtual void GetTextExtent(const wxString& string,
246 long *x, long *y,
247 long *descent = NULL,
248 long *externalLeading = NULL,
249 wxFont *theFont = NULL) const = 0;
250
251 // size and resolution
252 // -------------------
253
254 // in device units
255 void GetSize(int *width, int *height) const
256 { DoGetSize(width, height); }
257 wxSize GetSize() const
258 {
259 int w, h;
260 DoGetSize(&w, &h);
261
262 return wxSize(w, h);
263 }
264
265 // in mm
266 void GetSizeMM(int* width, int* height) const
267 { DoGetSizeMM(width, height); }
268 wxSize GetSizeMM() const
269 {
270 int w, h;
271 DoGetSizeMM(&w, &h);
272
273 return wxSize(w, h);
274 }
275
276 // coordinates conversions
277 // -----------------------
278
279 // This group of functions does actual conversion of the input, as you'd
280 // expect.
281 long DeviceToLogicalX(long x) const;
282 long DeviceToLogicalY(long y) const;
283 long DeviceToLogicalXRel(long x) const;
284 long DeviceToLogicalYRel(long y) const;
285 long LogicalToDeviceX(long x) const;
286 long LogicalToDeviceY(long y) const;
287 long LogicalToDeviceXRel(long x) const;
288 long LogicalToDeviceYRel(long y) const;
289
290 // query DC capabilities
291 // ---------------------
292
293 virtual bool CanDrawBitmap() const = 0;
294 virtual bool CanGetTextExtent() const = 0;
295
296 // colour depth
297 virtual int GetDepth() const = 0;
298
299 // Resolution in Pixels per inch
300 virtual wxSize GetPPI() const = 0;
301
302 virtual bool Ok() const { return m_ok; }
303
304 // accessors
305 // ---------
306
307 // const...
308 const wxBrush& GetBackground() const { return m_backgroundBrush; }
309 const wxBrush& GetBrush() const { return m_brush; }
310 const wxFont& GetFont() const { return m_font; }
311 const wxPen& GetPen() const { return m_pen; }
312 const wxColour& GetTextBackground() const { return m_textBackgroundColour; }
313 const wxColour& GetTextForeground() const { return m_textForegroundColour; }
314
315 // ... and non const
316 wxBrush& GetBackground() { return m_backgroundBrush; }
317 wxBrush& GetBrush() { return m_brush; }
318 wxFont& GetFont() { return m_font; }
319 wxPen& GetPen() { return m_pen; }
320 wxColour& GetTextBackground() { return m_textBackgroundColour; }
321 wxColour& GetTextForeground() { return m_textForegroundColour; }
322
323 virtual void SetTextForeground(const wxColour& colour)
324 { m_textForegroundColour = colour; }
325 virtual void SetTextBackground(const wxColour& colour)
326 { m_textBackgroundColour = colour; }
327
328 int GetMapMode() const { return m_mappingMode; }
329 virtual void SetMapMode(int mode) = 0;
330
331 virtual void GetUserScale(double *x, double *y) const
332 {
333 if ( x ) *x = m_userScaleX;
334 if ( y ) *y = m_userScaleY;
335 }
336 virtual void SetUserScale(double x, double y) = 0;
337
a23fd0e1
VZ
338 virtual void GetLogicalScale(double *x, double *y)
339 {
340 if ( x ) *x = m_logicalScaleX;
341 if ( y ) *y = m_logicalScaleY;
342 }
343 virtual void SetLogicalScale(double x, double y)
344 {
345 m_logicalScaleX = x;
346 m_logicalScaleY = y;
347 }
348
349 void GetLogicalOrigin(long *x, long *y) const
350 { DoGetLogicalOrigin(x, y); }
351 wxPoint GetLogicalOrigin() const
352 { long x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
353 virtual void SetLogicalOrigin(long x, long y) = 0;
354
355 void GetDeviceOrigin(long *x, long *y) const
356 { DoGetDeviceOrigin(x, y); }
357 wxPoint GetDeviceOrigin() const
358 { long x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
359 virtual void SetDeviceOrigin(long x, long y) = 0;
360
361 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0;
362
363 int GetLogicalFunction() const { return m_logicalFunction; }
364 virtual void SetLogicalFunction(int function) = 0;
365
366 // Sometimes we need to override optimization, e.g. if other software is
367 // drawing onto our surface and we can't be sure of who's done what.
368 //
369 // FIXME: is this (still) used?
370 virtual void SetOptimization(bool WXUNUSED(opt)) { }
371 virtual bool GetOptimization() { return FALSE; }
372
373 // bounding box
374 // ------------
375
376 virtual void CalcBoundingBox(long x, long y)
377 {
378 if (x < m_minX) m_minX = x;
379 if (y < m_minY) m_minY = y;
380 if (x > m_maxX) m_maxX = x;
381 if (y > m_maxY) m_maxY = y;
382 }
383
384 // Get the final bounding box of the PostScript or Metafile picture.
385 long MinX() const { return m_minX; }
386 long MaxX() const { return m_maxX; }
387 long MinY() const { return m_minY; }
388 long MaxY() const { return m_maxY; }
389
390 // misc old functions
391 // ------------------
392
393#if WXWIN_COMPATIBILITY
394 virtual void SetColourMap(const wxPalette& palette) { SetPalette(palette); }
395 void GetTextExtent(const wxString& string, float *x, float *y,
396 float *descent = NULL, float *externalLeading = NULL,
397 wxFont *theFont = NULL, bool use16bit = FALSE) const ;
398 void GetSize(float* width, float* height) const { int w, h; GetSize(& w, & h); *width = w; *height = h; }
399 void GetSizeMM(float *width, float *height) const { long w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; }
400#endif // WXWIN_COMPATIBILITY
401
402protected:
403 // the pure virtual functions which should be implemented by wxDC
404 virtual void DoFloodFill(long x, long y, const wxColour& col,
405 int style = wxFLOOD_SURFACE) = 0;
406
407 virtual bool DoGetPixel(long x, long y, wxColour *col) const = 0;
408
409 virtual void DoDrawPoint(long x, long y) = 0;
410 virtual void DoDrawLine(long x1, long y1, long x2, long y2) = 0;
411
412 virtual void DoDrawArc(long x1, long y1,
413 long x2, long y2,
414 long xc, long yc) = 0;
415 virtual void DoDrawEllipticArc(long x, long y, long w, long h,
416 double sa, double ea) = 0;
417
418 virtual void DoDrawRectangle(long x, long y, long width, long height) = 0;
419 virtual void DoDrawRoundedRectangle(long x, long y,
420 long width, long height,
421 double radius) = 0;
422 virtual void DoDrawEllipse(long x, long y, long width, long height) = 0;
423
424 virtual void DoCrossHair(long x, long y) = 0;
425
426 virtual void DoDrawIcon(const wxIcon& icon, long x, long y) = 0;
427 virtual void DoDrawBitmap(const wxBitmap &bmp, long x, long y,
428 bool useMask = FALSE) = 0;
429
430 virtual void DoDrawText(const wxString& text, long x, long y) = 0;
431
432 virtual bool DoBlit(long xdest, long ydest, long width, long height,
433 wxDC *source, long xsrc, long ysrc,
434 int rop = wxCOPY, bool useMask = FALSE) = 0;
435
436 virtual void DoGetSize(int *width, int *height) const = 0;
437 virtual void DoGetSizeMM(int* width, int* height) const = 0;
438
439 virtual void DoDrawLines(int n, wxPoint points[],
440 long xoffset, long yoffset) = 0;
441 virtual void DoDrawPolygon(int n, wxPoint points[],
442 long xoffset, long yoffset,
443 int fillStyle = wxODDEVEN_RULE) = 0;
444
445 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
446 virtual void DoSetClippingRegion(long x, long y,
447 long width, long height) = 0;
b0e0d661
VZ
448
449 // FIXME are these functions really different?
a23fd0e1 450 virtual void DoGetClippingRegion(long *x, long *y,
b0e0d661
VZ
451 long *w, long *h)
452 { DoGetClippingBox(x, y, w, h); }
a23fd0e1
VZ
453 virtual void DoGetClippingBox(long *x, long *y,
454 long *w, long *h) const
455 {
456 if ( m_clipping )
457 {
458 if ( x ) *x = m_clipX1;
459 if ( y ) *y = m_clipY1;
460 if ( w ) *w = m_clipX2 - m_clipX1;
461 if ( h ) *h = m_clipY2 - m_clipY1;
462 }
463 else
464 {
465 *x = *y = *w = *h = 0;
466 }
467 }
468
469 virtual void DoGetLogicalOrigin(long *x, long *y) const
470 {
471 if ( x ) *x = m_logicalOriginX;
472 if ( y ) *y = m_logicalOriginY;
473 }
474
475 virtual void DoGetDeviceOrigin(long *x, long *y) const
476 {
477 if ( x ) *x = m_deviceOriginX;
478 if ( y ) *y = m_deviceOriginY;
479 }
480
64698f9a 481#if wxUSE_SPLINES
a23fd0e1 482 virtual void DoDrawSpline(wxList *points) = 0;
64698f9a 483#endif
a23fd0e1
VZ
484
485protected:
486 // flags
487 bool m_colour:1;
488 bool m_ok:1;
489 bool m_clipping:1;
490 bool m_isInteractive:1;
491
492 // coordinate system variables
493
494 // TODO short descriptions of what exactly they are would be nice...
495
496 long m_logicalOriginX, m_logicalOriginY;
497 long m_deviceOriginX, m_deviceOriginY;
498
499 double m_logicalScaleX, m_logicalScaleY;
500 double m_userScaleX, m_userScaleY;
501 double m_scaleX, m_scaleY;
502
503 // Used by SetAxisOrientation() to invert the axes
504 int m_signX, m_signY;
505
506 // bounding and clipping boxes
507 long m_minX, m_minY, m_maxX, m_maxY;
508 long m_clipX1, m_clipY1, m_clipX2, m_clipY2;
509
510 int m_logicalFunction;
511 int m_backgroundMode;
512 int m_mappingMode;
513
514 // GDI objects
515 wxPen m_pen;
516 wxBrush m_brush;
517 wxBrush m_backgroundBrush;
518 wxColour m_textForegroundColour;
519 wxColour m_textBackgroundColour;
520 wxFont m_font;
521 wxPalette m_palette;
522
523private:
524 DECLARE_NO_COPY_CLASS(wxDCBase);
525};
526
527// ----------------------------------------------------------------------------
528// now include the declaration of wxDC class
529// ----------------------------------------------------------------------------
530
2049ba38 531#if defined(__WXMSW__)
a23fd0e1 532 #include "wx/msw/dc.h"
2049ba38 533#elif defined(__WXMOTIF__)
a23fd0e1 534 #include "wx/motif/dc.h"
2049ba38 535#elif defined(__WXGTK__)
a23fd0e1 536 #include "wx/gtk/dc.h"
b4e76e0d 537#elif defined(__WXQT__)
a23fd0e1 538 #include "wx/qt/dc.h"
34138703 539#elif defined(__WXMAC__)
a23fd0e1 540 #include "wx/mac/dc.h"
34138703 541#elif defined(__WXSTUBS__)
a23fd0e1 542 #include "wx/stubs/dc.h"
c801d85f
KB
543#endif
544
545#endif
34138703 546 // _WX_DC_H_BASE_