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