]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dc.h
Don't use images for wxNotebook because of crash
[wxWidgets.git] / include / wx / dc.h
CommitLineData
006162a9
VZ
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
34138703
JS
12#ifndef _WX_DC_H_BASE_
13#define _WX_DC_H_BASE_
c801d85f 14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
a23fd0e1
VZ
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"
a23fd0e1
VZ
31#include "wx/list.h" // we use wxList in inline functions
32
aec43716
KH
33class WXDLLEXPORT wxDCBase;
34
35class WXDLLEXPORT wxDrawObject
36{
37public:
38
39 wxDrawObject()
ba161d7e
GD
40 : m_isBBoxValid(FALSE)
41 , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
42 { }
aec43716
KH
43
44 virtual ~wxDrawObject() { }
45
33ac7e6f 46 virtual void Draw(wxDCBase&) const { }
aec43716
KH
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
85protected:
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
a23fd0e1
VZ
92// ---------------------------------------------------------------------------
93// global variables
94// ---------------------------------------------------------------------------
95
96WXDLLEXPORT_DATA(extern int) wxPageNumber;
97
98// ---------------------------------------------------------------------------
99// wxDC is the device context - object on which any drawing is done
100// ---------------------------------------------------------------------------
101
102class WXDLLEXPORT wxDCBase : public wxObject
103{
a23fd0e1
VZ
104public:
105 wxDCBase()
ba161d7e
GD
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
a23fd0e1 132 {
f6bcfd97 133 ResetBoundingBox();
a23fd0e1
VZ
134 }
135
136 ~wxDCBase() { }
137
138 virtual void BeginDrawing() { }
139 virtual void EndDrawing() { }
140
141 // graphic primitives
142 // ------------------
143
aec43716
KH
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
387ebd3e 151 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col,
72cdf4c9 152 int style = wxFLOOD_SURFACE)
387ebd3e
JS
153 { return DoFloodFill(x, y, col, style); }
154 bool FloodFill(const wxPoint& pt, const wxColour& col,
72cdf4c9 155 int style = wxFLOOD_SURFACE)
387ebd3e 156 { return DoFloodFill(pt.x, pt.y, col, style); }
a23fd0e1 157
72cdf4c9 158 bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const
a23fd0e1
VZ
159 { return DoGetPixel(x, y, col); }
160 bool GetPixel(const wxPoint& pt, wxColour *col) const
161 { return DoGetPixel(pt.x, pt.y, col); }
162
72cdf4c9 163 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
a23fd0e1
VZ
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
72cdf4c9 168 void CrossHair(wxCoord x, wxCoord y)
a23fd0e1
VZ
169 { DoCrossHair(x, y); }
170 void CrossHair(const wxPoint& pt)
171 { DoCrossHair(pt.x, pt.y); }
172
72cdf4c9
VZ
173 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
174 wxCoord xc, wxCoord yc)
a23fd0e1
VZ
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
cd9da200
VZ
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
72cdf4c9
VZ
185 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
186 double sa, double ea)
7b90a8f2 187 { DoDrawEllipticArc(x, y, w, h, sa, ea); }
a23fd0e1
VZ
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
72cdf4c9 192 void DrawPoint(wxCoord x, wxCoord y)
a23fd0e1
VZ
193 { DoDrawPoint(x, y); }
194 void DrawPoint(const wxPoint& pt)
195 { DoDrawPoint(pt.x, pt.y); }
196
72cdf4c9
VZ
197 void DrawLines(int n, wxPoint points[],
198 wxCoord xoffset = 0, wxCoord yoffset = 0)
a23fd0e1 199 { DoDrawLines(n, points, xoffset, yoffset); }
72cdf4c9
VZ
200 void DrawLines(const wxList *list,
201 wxCoord xoffset = 0, wxCoord yoffset = 0);
a23fd0e1
VZ
202
203 void DrawPolygon(int n, wxPoint points[],
72cdf4c9 204 wxCoord xoffset = 0, wxCoord yoffset = 0,
a23fd0e1
VZ
205 int fillStyle = wxODDEVEN_RULE)
206 { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
207
208 void DrawPolygon(const wxList *list,
72cdf4c9 209 wxCoord xoffset = 0, wxCoord yoffset = 0,
bd5dd957 210 int fillStyle = wxODDEVEN_RULE);
a23fd0e1 211
72cdf4c9 212 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
a23fd0e1
VZ
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
72cdf4c9 219 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
a23fd0e1
VZ
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
72cdf4c9 228 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
220af862 229 { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
0371e9a8 230 void DrawCircle(const wxPoint& pt, wxCoord radius)
b95edd47 231 { DrawCircle(pt.x, pt.y, radius); }
0371e9a8 232
72cdf4c9 233 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
a23fd0e1
VZ
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
72cdf4c9 240 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
a23fd0e1
VZ
241 { DoDrawIcon(icon, x, y); }
242 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
243 { DoDrawIcon(icon, pt.x, pt.y); }
244
72cdf4c9
VZ
245 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
246 bool useMask = FALSE)
a23fd0e1
VZ
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
72cdf4c9 252 void DrawText(const wxString& text, wxCoord x, wxCoord y)
a23fd0e1
VZ
253 { DoDrawText(text, x, y); }
254 void DrawText(const wxString& text, const wxPoint& pt)
255 { DoDrawText(text, pt.x, pt.y); }
256
95724b1a
VZ
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
1e6feb95
VZ
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
72cdf4c9
VZ
278 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
279 wxDC *source, wxCoord xsrc, wxCoord ysrc,
0cbff120 280 int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1)
a23fd0e1
VZ
281 {
282 return DoBlit(xdest, ydest, width, height,
0cbff120 283 source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
a23fd0e1
VZ
284 }
285 bool Blit(const wxPoint& destPt, const wxSize& sz,
286 wxDC *source, const wxPoint& srcPt,
0cbff120 287 int rop = wxCOPY, bool useMask = FALSE, const wxPoint& srcPtMask = wxPoint(-1, -1))
a23fd0e1
VZ
288 {
289 return DoBlit(destPt.x, destPt.y, sz.x, sz.y,
0cbff120 290 source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
a23fd0e1
VZ
291 }
292
293#if wxUSE_SPLINES
72cdf4c9
VZ
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);
bd5dd957 298 void DrawSpline(int n, wxPoint points[]);
a23fd0e1
VZ
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
af0bb3b1
VZ
308 virtual bool StartDoc(const wxString& WXUNUSED(message)) { return TRUE; }
309 virtual void EndDoc() { }
a23fd0e1 310
af0bb3b1
VZ
311 virtual void StartPage() { }
312 virtual void EndPage() { }
a23fd0e1
VZ
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;
d275c7eb 322#if wxUSE_PALETTE
a23fd0e1 323 virtual void SetPalette(const wxPalette& palette) = 0;
d275c7eb 324#endif // wxUSE_PALETTE
a23fd0e1
VZ
325
326 // clipping region
327 // ---------------
328
72cdf4c9 329 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
a23fd0e1
VZ
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
72cdf4c9 340 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
a23fd0e1
VZ
341 { DoGetClippingBox(x, y, w, h); }
342 void GetClippingBox(wxRect& rect) const
8fb3a512
JS
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 }
a23fd0e1
VZ
349
350 // text extent
351 // -----------
352
72cdf4c9
VZ
353 virtual wxCoord GetCharHeight() const = 0;
354 virtual wxCoord GetCharWidth() const = 0;
cd9da200 355
1e6feb95 356 // only works for single line strings
72cdf4c9
VZ
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); }
a23fd0e1 363
1e6feb95
VZ
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
a23fd0e1
VZ
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.
72cdf4c9
VZ
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;
a23fd0e1
VZ
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...
f6bcfd97 428 int GetBackgroundMode() const { return m_backgroundMode; }
a23fd0e1
VZ
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
a23fd0e1
VZ
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
72cdf4c9 470 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
471 { DoGetLogicalOrigin(x, y); }
472 wxPoint GetLogicalOrigin() const
72cdf4c9
VZ
473 { wxCoord x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
474 virtual void SetLogicalOrigin(wxCoord x, wxCoord y) = 0;
a23fd0e1 475
72cdf4c9 476 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
477 { DoGetDeviceOrigin(x, y); }
478 wxPoint GetDeviceOrigin() const
72cdf4c9
VZ
479 { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
480 virtual void SetDeviceOrigin(wxCoord x, wxCoord y) = 0;
a23fd0e1
VZ
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
0cbff120
JS
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() ;
27748047 499#if 0 // wxUSE_DC_CACHEING
0cbff120
JS
500 static void EnableCache(bool cacheing) { sm_cacheing = cacheing; }
501 static bool CacheEnabled() { return sm_cacheing ; }
502#endif
503
a23fd0e1
VZ
504 // bounding box
505 // ------------
506
72cdf4c9 507 virtual void CalcBoundingBox(wxCoord x, wxCoord y)
a23fd0e1 508 {
f6bcfd97
BP
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;
a23fd0e1
VZ
532 }
533
534 // Get the final bounding box of the PostScript or Metafile picture.
72cdf4c9
VZ
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; }
a23fd0e1
VZ
539
540 // misc old functions
541 // ------------------
542
72cdf4c9
VZ
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 }
1dd989e1 584 void GetClippingBox(long *x, long *y, long *w, long *h) const
cd9da200
VZ
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;
1dd989e1 592 }
72cdf4c9
VZ
593#endif // !Win16
594
a23fd0e1 595#if WXWIN_COMPATIBILITY
d275c7eb
VZ
596
597#if wxUSE_PALETTE
a23fd0e1 598 virtual void SetColourMap(const wxPalette& palette) { SetPalette(palette); }
d275c7eb
VZ
599#endif // wxUSE_PALETTE
600
a23fd0e1
VZ
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; }
e30285ab 605 void GetSizeMM(float *width, float *height) const { int w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; }
d275c7eb 606
a23fd0e1
VZ
607#endif // WXWIN_COMPATIBILITY
608
609protected:
610 // the pure virtual functions which should be implemented by wxDC
387ebd3e 611 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
a23fd0e1
VZ
612 int style = wxFLOOD_SURFACE) = 0;
613
72cdf4c9 614 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
a23fd0e1 615
72cdf4c9
VZ
616 virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
617 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
a23fd0e1 618
72cdf4c9
VZ
619 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
620 wxCoord x2, wxCoord y2,
621 wxCoord xc, wxCoord yc) = 0;
cd9da200
VZ
622 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
623 wxCoord width, wxCoord height);
72cdf4c9 624 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
a23fd0e1
VZ
625 double sa, double ea) = 0;
626
72cdf4c9
VZ
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,
a23fd0e1 630 double radius) = 0;
72cdf4c9
VZ
631 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
632 wxCoord width, wxCoord height) = 0;
a23fd0e1 633
72cdf4c9 634 virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
a23fd0e1 635
72cdf4c9
VZ
636 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
637 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
a23fd0e1
VZ
638 bool useMask = FALSE) = 0;
639
72cdf4c9 640 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
95724b1a
VZ
641 virtual void DoDrawRotatedText(const wxString& text,
642 wxCoord x, wxCoord y, double angle) = 0;
a23fd0e1 643
72cdf4c9
VZ
644 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
645 wxCoord width, wxCoord height,
646 wxDC *source, wxCoord xsrc, wxCoord ysrc,
0cbff120 647 int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1) = 0;
a23fd0e1
VZ
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[],
72cdf4c9 653 wxCoord xoffset, wxCoord yoffset) = 0;
a23fd0e1 654 virtual void DoDrawPolygon(int n, wxPoint points[],
72cdf4c9 655 wxCoord xoffset, wxCoord yoffset,
a23fd0e1
VZ
656 int fillStyle = wxODDEVEN_RULE) = 0;
657
658 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
72cdf4c9
VZ
659 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
660 wxCoord width, wxCoord height) = 0;
b0e0d661
VZ
661
662 // FIXME are these functions really different?
72cdf4c9
VZ
663 virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y,
664 wxCoord *w, wxCoord *h)
b0e0d661 665 { DoGetClippingBox(x, y, w, h); }
72cdf4c9
VZ
666 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
667 wxCoord *w, wxCoord *h) const
a23fd0e1
VZ
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
72cdf4c9 682 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
683 {
684 if ( x ) *x = m_logicalOriginX;
685 if ( y ) *y = m_logicalOriginY;
686 }
687
72cdf4c9 688 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
689 {
690 if ( x ) *x = m_deviceOriginX;
691 if ( y ) *y = m_deviceOriginY;
692 }
693
72cdf4c9
VZ
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
64698f9a 700#if wxUSE_SPLINES
fe2e4366 701 virtual void DoDrawSpline(wxList *points);
64698f9a 702#endif
a23fd0e1
VZ
703
704protected:
705 // flags
706 bool m_colour:1;
707 bool m_ok:1;
708 bool m_clipping:1;
709 bool m_isInteractive:1;
f6bcfd97 710 bool m_isBBoxValid:1;
0cbff120 711#if wxUSE_DC_CACHEING
27748047 712// static bool sm_cacheing;
0cbff120 713#endif
a23fd0e1
VZ
714
715 // coordinate system variables
716
717 // TODO short descriptions of what exactly they are would be nice...
718
72cdf4c9
VZ
719 wxCoord m_logicalOriginX, m_logicalOriginY;
720 wxCoord m_deviceOriginX, m_deviceOriginY;
a23fd0e1
VZ
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
72cdf4c9
VZ
730 wxCoord m_minX, m_minY, m_maxX, m_maxY;
731 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
a23fd0e1
VZ
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;
d275c7eb
VZ
744
745#if wxUSE_PALETTE
a23fd0e1 746 wxPalette m_palette;
b95edd47 747 bool m_hasCustomPalette;
d275c7eb 748#endif // wxUSE_PALETTE
a23fd0e1
VZ
749
750private:
ac84e37d 751 DECLARE_NO_COPY_CLASS(wxDCBase)
cd9da200 752 DECLARE_ABSTRACT_CLASS(wxDCBase)
a23fd0e1
VZ
753};
754
755// ----------------------------------------------------------------------------
756// now include the declaration of wxDC class
757// ----------------------------------------------------------------------------
758
2049ba38 759#if defined(__WXMSW__)
a23fd0e1 760 #include "wx/msw/dc.h"
2049ba38 761#elif defined(__WXMOTIF__)
a23fd0e1 762 #include "wx/motif/dc.h"
2049ba38 763#elif defined(__WXGTK__)
a23fd0e1 764 #include "wx/gtk/dc.h"
83df96d6
JS
765#elif defined(__WXX11__)
766 #include "wx/x11/dc.h"
1e6feb95
VZ
767#elif defined(__WXMGL__)
768 #include "wx/mgl/dc.h"
34138703 769#elif defined(__WXMAC__)
a23fd0e1 770 #include "wx/mac/dc.h"
1777b9bb
DW
771#elif defined(__WXPM__)
772 #include "wx/os2/dc.h"
c801d85f
KB
773#endif
774
1e6feb95
VZ
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
780class WXDLLEXPORT wxDCTextColourChanger
781{
782public:
ba161d7e 783 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
1e6feb95
VZ
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
798private:
799 wxDC& m_dc;
800
801 wxColour m_colFgOld;
802};
803
e26be42b
VZ
804// ----------------------------------------------------------------------------
805// another small helper class: sets the clipping region in its ctor and
806// destroys it in the dtor
807// ----------------------------------------------------------------------------
808
809class WXDLLEXPORT wxDCClipper
810{
811public:
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
819private:
820 wxDC& m_dc;
821};
822
c801d85f 823#endif
34138703 824 // _WX_DC_H_BASE_