]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dc.h
move wx11 and (the rest of) wxMGL specific checks into /chkconf.h file
[wxWidgets.git] / include / wx / dc.h
CommitLineData
006162a9 1/////////////////////////////////////////////////////////////////////////////
4660e6ac 2// Name: wx/dc.h
006162a9
VZ
3// Purpose: wxDC class
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 05/25/99
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
006162a9
VZ
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_DC_H_BASE_
13#define _WX_DC_H_BASE_
c801d85f 14
a23fd0e1
VZ
15// ----------------------------------------------------------------------------
16// headers which we must include here
17// ----------------------------------------------------------------------------
18
19#include "wx/object.h" // the base class
20
21#include "wx/cursor.h" // we have member variables of these classes
22#include "wx/font.h" // so we can't do without them
23#include "wx/colour.h"
b494e2b0 24#include "wx/bitmap.h" // for wxNullBitmap
a23fd0e1
VZ
25#include "wx/brush.h"
26#include "wx/pen.h"
27#include "wx/palette.h"
a23fd0e1 28#include "wx/list.h" // we use wxList in inline functions
0919e93e 29#include "wx/dynarray.h"
19edb09c 30#include "wx/math.h"
a23fd0e1 31
f4515f98 32class WXDLLEXPORT wxDC;
aec43716
KH
33class WXDLLEXPORT wxDCBase;
34
35class WXDLLEXPORT wxDrawObject
36{
37public:
38
39 wxDrawObject()
68379eaf 40 : m_isBBoxValid(false)
ba161d7e
GD
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 {
68379eaf 59 m_isBBoxValid = true;
aec43716
KH
60
61 m_minX = x;
62 m_minY = y;
63 m_maxX = x;
64 m_maxY = y;
65 }
66 }
67
68 void ResetBoundingBox()
69 {
68379eaf 70 m_isBBoxValid = false;
aec43716
KH
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
a23fd0e1
VZ
96// ---------------------------------------------------------------------------
97// wxDC is the device context - object on which any drawing is done
98// ---------------------------------------------------------------------------
99
100class WXDLLEXPORT wxDCBase : public wxObject
101{
a23fd0e1
VZ
102public:
103 wxDCBase()
ba161d7e 104 : m_colour(wxColourDisplay())
68379eaf
WS
105 , m_ok(true)
106 , m_clipping(false)
ba161d7e 107 , m_isInteractive(0)
68379eaf 108 , m_isBBoxValid(false)
ba161d7e
GD
109 , m_logicalOriginX(0), m_logicalOriginY(0)
110 , m_deviceOriginX(0), m_deviceOriginY(0)
111 , m_logicalScaleX(1.0), m_logicalScaleY(1.0)
112 , m_userScaleX(1.0), m_userScaleY(1.0)
113 , m_scaleX(1.0), m_scaleY(1.0)
114 , m_signX(1), m_signY(1)
115 , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
116 , m_clipX1(0), m_clipY1(0), m_clipX2(0), m_clipY2(0)
117 , m_logicalFunction(wxCOPY)
118 , m_backgroundMode(wxTRANSPARENT)
119 , m_mappingMode(wxMM_TEXT)
120 , m_pen()
121 , m_brush()
122 , m_backgroundBrush(*wxTRANSPARENT_BRUSH)
123 , m_textForegroundColour(*wxBLACK)
124 , m_textBackgroundColour(*wxWHITE)
125 , m_font()
126#if wxUSE_PALETTE
127 , m_palette()
68379eaf 128 , m_hasCustomPalette(false)
ba161d7e 129#endif // wxUSE_PALETTE
a23fd0e1 130 {
f6bcfd97 131 ResetBoundingBox();
d16b634f 132 ResetClipping();
a23fd0e1
VZ
133 }
134
135 ~wxDCBase() { }
136
68df211f
JG
137#if WXWIN_COMPATIBILITY_2_6
138 wxDEPRECATED( virtual void BeginDrawing() );
139 wxDEPRECATED( virtual void EndDrawing() );
140#endif // WXWIN_COMPATIBILITY_2_6
a23fd0e1
VZ
141
142 // graphic primitives
143 // ------------------
144
aec43716
KH
145 virtual void DrawObject(wxDrawObject* drawobject)
146 {
147 drawobject->Draw(*this);
148 CalcBoundingBox(drawobject->MinX(),drawobject->MinY());
149 CalcBoundingBox(drawobject->MaxX(),drawobject->MaxY());
150 }
151
387ebd3e 152 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col,
72cdf4c9 153 int style = wxFLOOD_SURFACE)
387ebd3e
JS
154 { return DoFloodFill(x, y, col, style); }
155 bool FloodFill(const wxPoint& pt, const wxColour& col,
72cdf4c9 156 int style = wxFLOOD_SURFACE)
387ebd3e 157 { return DoFloodFill(pt.x, pt.y, col, style); }
a23fd0e1 158
213ad8e7
VZ
159 // fill the area specified by rect with a radial gradient, starting from
160 // initialColour in the centre of the cercle and fading to destColour.
161 void GradientFillConcentric(const wxRect& rect,
4660e6ac 162 const wxColour& initialColour,
213ad8e7
VZ
163 const wxColour& destColour)
164 { GradientFillConcentric(rect, initialColour, destColour,
165 wxPoint(rect.GetWidth() / 2,
166 rect.GetHeight() / 2)); }
167
168 void GradientFillConcentric(const wxRect& rect,
4660e6ac 169 const wxColour& initialColour,
213ad8e7
VZ
170 const wxColour& destColour,
171 const wxPoint& circleCenter);
172
173 // fill the area specified by rect with a linear gradient
174 void GradientFillLinear(const wxRect& rect,
4660e6ac 175 const wxColour& initialColour,
213ad8e7
VZ
176 const wxColour& destColour,
177 wxDirection nDirection = wxEAST)
178 { DoGradientFillLinear(rect, initialColour, destColour, nDirection); }
179
72cdf4c9 180 bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const
a23fd0e1
VZ
181 { return DoGetPixel(x, y, col); }
182 bool GetPixel(const wxPoint& pt, wxColour *col) const
183 { return DoGetPixel(pt.x, pt.y, col); }
184
72cdf4c9 185 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
a23fd0e1
VZ
186 { DoDrawLine(x1, y1, x2, y2); }
187 void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
188 { DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
189
72cdf4c9 190 void CrossHair(wxCoord x, wxCoord y)
a23fd0e1
VZ
191 { DoCrossHair(x, y); }
192 void CrossHair(const wxPoint& pt)
193 { DoCrossHair(pt.x, pt.y); }
194
72cdf4c9
VZ
195 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
196 wxCoord xc, wxCoord yc)
a23fd0e1
VZ
197 { DoDrawArc(x1, y1, x2, y2, xc, yc); }
198 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
199 { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
200
cd9da200
VZ
201 void DrawCheckMark(wxCoord x, wxCoord y,
202 wxCoord width, wxCoord height)
203 { DoDrawCheckMark(x, y, width, height); }
204 void DrawCheckMark(const wxRect& rect)
205 { DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
206
72cdf4c9
VZ
207 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
208 double sa, double ea)
7b90a8f2 209 { DoDrawEllipticArc(x, y, w, h, sa, ea); }
a23fd0e1
VZ
210 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
211 double sa, double ea)
212 { DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
213
72cdf4c9 214 void DrawPoint(wxCoord x, wxCoord y)
a23fd0e1
VZ
215 { DoDrawPoint(x, y); }
216 void DrawPoint(const wxPoint& pt)
217 { DoDrawPoint(pt.x, pt.y); }
218
72cdf4c9
VZ
219 void DrawLines(int n, wxPoint points[],
220 wxCoord xoffset = 0, wxCoord yoffset = 0)
a23fd0e1 221 { DoDrawLines(n, points, xoffset, yoffset); }
72cdf4c9
VZ
222 void DrawLines(const wxList *list,
223 wxCoord xoffset = 0, wxCoord yoffset = 0);
a23fd0e1
VZ
224
225 void DrawPolygon(int n, wxPoint points[],
72cdf4c9 226 wxCoord xoffset = 0, wxCoord yoffset = 0,
a23fd0e1
VZ
227 int fillStyle = wxODDEVEN_RULE)
228 { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
229
230 void DrawPolygon(const wxList *list,
72cdf4c9 231 wxCoord xoffset = 0, wxCoord yoffset = 0,
bd5dd957 232 int fillStyle = wxODDEVEN_RULE);
a23fd0e1 233
793db755 234 void DrawPolyPolygon(int n, int count[], wxPoint points[],
6e76b35d
VZ
235 wxCoord xoffset = 0, wxCoord yoffset = 0,
236 int fillStyle = wxODDEVEN_RULE)
793db755 237 { DoDrawPolyPolygon(n, count, points, xoffset, yoffset, fillStyle); }
6e76b35d 238
72cdf4c9 239 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
a23fd0e1
VZ
240 { DoDrawRectangle(x, y, width, height); }
241 void DrawRectangle(const wxPoint& pt, const wxSize& sz)
242 { DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); }
243 void DrawRectangle(const wxRect& rect)
244 { DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); }
245
72cdf4c9 246 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
a23fd0e1
VZ
247 double radius)
248 { DoDrawRoundedRectangle(x, y, width, height, radius); }
249 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
250 double radius)
251 { DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
252 void DrawRoundedRectangle(const wxRect& r, double radius)
253 { DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
254
72cdf4c9 255 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
220af862 256 { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
0371e9a8 257 void DrawCircle(const wxPoint& pt, wxCoord radius)
b95edd47 258 { DrawCircle(pt.x, pt.y, radius); }
0371e9a8 259
72cdf4c9 260 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
a23fd0e1
VZ
261 { DoDrawEllipse(x, y, width, height); }
262 void DrawEllipse(const wxPoint& pt, const wxSize& sz)
263 { DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); }
264 void DrawEllipse(const wxRect& rect)
265 { DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); }
266
72cdf4c9 267 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
a23fd0e1
VZ
268 { DoDrawIcon(icon, x, y); }
269 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
270 { DoDrawIcon(icon, pt.x, pt.y); }
271
72cdf4c9 272 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
68379eaf 273 bool useMask = false)
a23fd0e1
VZ
274 { DoDrawBitmap(bmp, x, y, useMask); }
275 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
68379eaf 276 bool useMask = false)
a23fd0e1
VZ
277 { DoDrawBitmap(bmp, pt.x, pt.y, useMask); }
278
72cdf4c9 279 void DrawText(const wxString& text, wxCoord x, wxCoord y)
a23fd0e1
VZ
280 { DoDrawText(text, x, y); }
281 void DrawText(const wxString& text, const wxPoint& pt)
282 { DoDrawText(text, pt.x, pt.y); }
283
95724b1a
VZ
284 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
285 { DoDrawRotatedText(text, x, y, angle); }
286 void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)
287 { DoDrawRotatedText(text, pt.x, pt.y, angle); }
288
1e6feb95
VZ
289 // this version puts both optional bitmap and the text into the given
290 // rectangle and aligns is as specified by alignment parameter; it also
291 // will emphasize the character with the given index if it is != -1 and
292 // return the bounding rectangle if required
293 virtual void DrawLabel(const wxString& text,
294 const wxBitmap& image,
295 const wxRect& rect,
296 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
297 int indexAccel = -1,
298 wxRect *rectBounding = NULL);
299
300 void DrawLabel(const wxString& text, const wxRect& rect,
301 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
302 int indexAccel = -1)
303 { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); }
304
72cdf4c9
VZ
305 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
306 wxDC *source, wxCoord xsrc, wxCoord ysrc,
68379eaf 307 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
a23fd0e1
VZ
308 {
309 return DoBlit(xdest, ydest, width, height,
0cbff120 310 source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
a23fd0e1
VZ
311 }
312 bool Blit(const wxPoint& destPt, const wxSize& sz,
313 wxDC *source, const wxPoint& srcPt,
68379eaf 314 int rop = wxCOPY, bool useMask = false, const wxPoint& srcPtMask = wxDefaultPosition)
a23fd0e1
VZ
315 {
316 return DoBlit(destPt.x, destPt.y, sz.x, sz.y,
0cbff120 317 source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
a23fd0e1
VZ
318 }
319
320#if wxUSE_SPLINES
72cdf4c9
VZ
321 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
322 void DrawSpline(wxCoord x1, wxCoord y1,
323 wxCoord x2, wxCoord y2,
324 wxCoord x3, wxCoord y3);
bd5dd957 325 void DrawSpline(int n, wxPoint points[]);
a23fd0e1
VZ
326
327 void DrawSpline(wxList *points) { DoDrawSpline(points); }
328#endif // wxUSE_SPLINES
329
12bdd77c
JS
330 // Eventually we will have wxUSE_GENERIC_DRAWELLIPSE
331#ifdef __WXWINCE__
332 //! Generic method to draw ellipses, circles and arcs with current pen and brush.
333 /*! \param x Upper left corner of bounding box.
334 * \param y Upper left corner of bounding box.
335 * \param w Width of bounding box.
336 * \param h Height of bounding box.
d16b634f 337 * \param sa Starting angle of arc
12bdd77c
JS
338 * (counterclockwise, start at 3 o'clock, 360 is full circle).
339 * \param ea Ending angle of arc.
d16b634f 340 * \param angle Rotation angle, the Arc will be rotated after
12bdd77c
JS
341 * calculating begin and end.
342 */
d16b634f
VZ
343 void DrawEllipticArcRot( wxCoord x, wxCoord y,
344 wxCoord width, wxCoord height,
12bdd77c
JS
345 double sa = 0, double ea = 0, double angle = 0 )
346 { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); }
d16b634f
VZ
347
348 void DrawEllipticArcRot( const wxPoint& pt,
12bdd77c
JS
349 const wxSize& sz,
350 double sa = 0, double ea = 0, double angle = 0 )
351 { DoDrawEllipticArcRot( pt.x, pt.y, sz.x, sz.y, sa, ea, angle ); }
352
353 void DrawEllipticArcRot( const wxRect& rect,
354 double sa = 0, double ea = 0, double angle = 0 )
355 { DoDrawEllipticArcRot( rect.x, rect.y, rect.width, rect.height, sa, ea, angle ); }
356
d16b634f
VZ
357 virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y,
358 wxCoord w, wxCoord h,
12bdd77c 359 double sa = 0, double ea = 0, double angle = 0 );
d16b634f 360
12bdd77c
JS
361 //! Rotates points around center.
362 /*! This is a quite straight method, it calculates in pixels
363 * and so it produces rounding errors.
364 * \param points The points inside will be rotated.
365 * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle).
366 * \param center Center of rotation.
d16b634f 367 */
c47addef 368 void Rotate( wxList* points, double angle, wxPoint center = wxPoint(0,0) );
12bdd77c
JS
369
370 // used by DrawEllipticArcRot
371 // Careful: wxList gets filled with points you have to delete later.
d16b634f
VZ
372 void CalculateEllipticPoints( wxList* points,
373 wxCoord xStart, wxCoord yStart,
374 wxCoord w, wxCoord h,
12bdd77c
JS
375 double sa, double ea );
376#endif
d16b634f 377
a23fd0e1
VZ
378 // global DC operations
379 // --------------------
380
381 virtual void Clear() = 0;
382
68379eaf 383 virtual bool StartDoc(const wxString& WXUNUSED(message)) { return true; }
af0bb3b1 384 virtual void EndDoc() { }
a23fd0e1 385
af0bb3b1
VZ
386 virtual void StartPage() { }
387 virtual void EndPage() { }
a23fd0e1
VZ
388
389 // set objects to use for drawing
390 // ------------------------------
391
392 virtual void SetFont(const wxFont& font) = 0;
393 virtual void SetPen(const wxPen& pen) = 0;
394 virtual void SetBrush(const wxBrush& brush) = 0;
395 virtual void SetBackground(const wxBrush& brush) = 0;
396 virtual void SetBackgroundMode(int mode) = 0;
d275c7eb 397#if wxUSE_PALETTE
a23fd0e1 398 virtual void SetPalette(const wxPalette& palette) = 0;
d275c7eb 399#endif // wxUSE_PALETTE
a23fd0e1
VZ
400
401 // clipping region
402 // ---------------
403
72cdf4c9 404 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
a23fd0e1
VZ
405 { DoSetClippingRegion(x, y, width, height); }
406 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
407 { DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); }
408 void SetClippingRegion(const wxRect& rect)
409 { DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
410 void SetClippingRegion(const wxRegion& region)
411 { DoSetClippingRegionAsRegion(region); }
412
d16b634f 413 virtual void DestroyClippingRegion() { ResetClipping(); }
a23fd0e1 414
72cdf4c9 415 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
a23fd0e1
VZ
416 { DoGetClippingBox(x, y, w, h); }
417 void GetClippingBox(wxRect& rect) const
8fb3a512 418 {
ae500232 419 DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height);
8fb3a512 420 }
a23fd0e1
VZ
421
422 // text extent
423 // -----------
424
72cdf4c9
VZ
425 virtual wxCoord GetCharHeight() const = 0;
426 virtual wxCoord GetCharWidth() const = 0;
cd9da200 427
1e6feb95 428 // only works for single line strings
72cdf4c9
VZ
429 void GetTextExtent(const wxString& string,
430 wxCoord *x, wxCoord *y,
431 wxCoord *descent = NULL,
432 wxCoord *externalLeading = NULL,
433 wxFont *theFont = NULL) const
434 { DoGetTextExtent(string, x, y, descent, externalLeading, theFont); }
a23fd0e1 435
1e6feb95
VZ
436 // works for single as well as multi-line strings
437 virtual void GetMultiLineTextExtent(const wxString& text,
438 wxCoord *width,
439 wxCoord *height,
440 wxCoord *heightLine = NULL,
441 wxFont *font = NULL);
442
0919e93e
RD
443 // Measure cumulative width of text after each character
444 bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
445 { return DoGetPartialTextExtents(text, widths); }
446
d16b634f 447
a23fd0e1
VZ
448 // size and resolution
449 // -------------------
450
451 // in device units
452 void GetSize(int *width, int *height) const
453 { DoGetSize(width, height); }
454 wxSize GetSize() const
455 {
456 int w, h;
457 DoGetSize(&w, &h);
458
459 return wxSize(w, h);
460 }
461
462 // in mm
463 void GetSizeMM(int* width, int* height) const
464 { DoGetSizeMM(width, height); }
465 wxSize GetSizeMM() const
466 {
467 int w, h;
468 DoGetSizeMM(&w, &h);
469
470 return wxSize(w, h);
471 }
472
473 // coordinates conversions
474 // -----------------------
475
476 // This group of functions does actual conversion of the input, as you'd
477 // expect.
72cdf4c9
VZ
478 wxCoord DeviceToLogicalX(wxCoord x) const;
479 wxCoord DeviceToLogicalY(wxCoord y) const;
480 wxCoord DeviceToLogicalXRel(wxCoord x) const;
481 wxCoord DeviceToLogicalYRel(wxCoord y) const;
482 wxCoord LogicalToDeviceX(wxCoord x) const;
483 wxCoord LogicalToDeviceY(wxCoord y) const;
484 wxCoord LogicalToDeviceXRel(wxCoord x) const;
485 wxCoord LogicalToDeviceYRel(wxCoord y) const;
a23fd0e1
VZ
486
487 // query DC capabilities
488 // ---------------------
489
490 virtual bool CanDrawBitmap() const = 0;
491 virtual bool CanGetTextExtent() const = 0;
492
493 // colour depth
494 virtual int GetDepth() const = 0;
495
496 // Resolution in Pixels per inch
497 virtual wxSize GetPPI() const = 0;
498
499 virtual bool Ok() const { return m_ok; }
500
2439f37a
VZ
501 // accessors and setters
502 // ---------------------
a23fd0e1 503
f6bcfd97 504 int GetBackgroundMode() const { return m_backgroundMode; }
a23fd0e1
VZ
505 const wxBrush& GetBackground() const { return m_backgroundBrush; }
506 const wxBrush& GetBrush() const { return m_brush; }
507 const wxFont& GetFont() const { return m_font; }
508 const wxPen& GetPen() const { return m_pen; }
a23fd0e1 509
2439f37a
VZ
510 const wxColour& GetTextForeground() const { return m_textForegroundColour; }
511 const wxColour& GetTextBackground() const { return m_textBackgroundColour; }
a23fd0e1
VZ
512 virtual void SetTextForeground(const wxColour& colour)
513 { m_textForegroundColour = colour; }
514 virtual void SetTextBackground(const wxColour& colour)
515 { m_textBackgroundColour = colour; }
516
517 int GetMapMode() const { return m_mappingMode; }
518 virtual void SetMapMode(int mode) = 0;
519
520 virtual void GetUserScale(double *x, double *y) const
521 {
522 if ( x ) *x = m_userScaleX;
523 if ( y ) *y = m_userScaleY;
524 }
525 virtual void SetUserScale(double x, double y) = 0;
526
a23fd0e1
VZ
527 virtual void GetLogicalScale(double *x, double *y)
528 {
529 if ( x ) *x = m_logicalScaleX;
530 if ( y ) *y = m_logicalScaleY;
531 }
532 virtual void SetLogicalScale(double x, double y)
533 {
534 m_logicalScaleX = x;
535 m_logicalScaleY = y;
536 }
537
72cdf4c9 538 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
539 { DoGetLogicalOrigin(x, y); }
540 wxPoint GetLogicalOrigin() const
72cdf4c9
VZ
541 { wxCoord x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
542 virtual void SetLogicalOrigin(wxCoord x, wxCoord y) = 0;
a23fd0e1 543
72cdf4c9 544 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
545 { DoGetDeviceOrigin(x, y); }
546 wxPoint GetDeviceOrigin() const
72cdf4c9
VZ
547 { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
548 virtual void SetDeviceOrigin(wxCoord x, wxCoord y) = 0;
a23fd0e1 549
b1263dcf
WS
550 virtual void ComputeScaleAndOrigin() {}
551
a23fd0e1
VZ
552 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0;
553
554 int GetLogicalFunction() const { return m_logicalFunction; }
555 virtual void SetLogicalFunction(int function) = 0;
556
ea76a6a5 557#if WXWIN_COMPATIBILITY_2_4
a23fd0e1 558 virtual void SetOptimization(bool WXUNUSED(opt)) { }
68379eaf 559 virtual bool GetOptimization() { return false; }
ea76a6a5 560#endif
a23fd0e1
VZ
561
562 // bounding box
563 // ------------
564
72cdf4c9 565 virtual void CalcBoundingBox(wxCoord x, wxCoord y)
a23fd0e1 566 {
f6bcfd97
BP
567 if ( m_isBBoxValid )
568 {
569 if ( x < m_minX ) m_minX = x;
570 if ( y < m_minY ) m_minY = y;
571 if ( x > m_maxX ) m_maxX = x;
572 if ( y > m_maxY ) m_maxY = y;
573 }
574 else
575 {
68379eaf 576 m_isBBoxValid = true;
f6bcfd97
BP
577
578 m_minX = x;
579 m_minY = y;
580 m_maxX = x;
581 m_maxY = y;
582 }
583 }
584
585 void ResetBoundingBox()
586 {
68379eaf 587 m_isBBoxValid = false;
f6bcfd97
BP
588
589 m_minX = m_maxX = m_minY = m_maxY = 0;
a23fd0e1
VZ
590 }
591
592 // Get the final bounding box of the PostScript or Metafile picture.
72cdf4c9
VZ
593 wxCoord MinX() const { return m_minX; }
594 wxCoord MaxX() const { return m_maxX; }
595 wxCoord MinY() const { return m_minY; }
596 wxCoord MaxY() const { return m_maxY; }
a23fd0e1
VZ
597
598 // misc old functions
599 // ------------------
600
72cdf4c9 601 // for compatibility with the old code when wxCoord was long everywhere
72cdf4c9
VZ
602 void GetTextExtent(const wxString& string,
603 long *x, long *y,
604 long *descent = NULL,
605 long *externalLeading = NULL,
606 wxFont *theFont = NULL) const
607 {
608 wxCoord x2, y2, descent2, externalLeading2;
609 DoGetTextExtent(string, &x2, &y2,
610 &descent2, &externalLeading2,
611 theFont);
612 if ( x )
613 *x = x2;
614 if ( y )
615 *y = y2;
616 if ( descent )
617 *descent = descent2;
618 if ( externalLeading )
619 *externalLeading = externalLeading2;
620 }
621
622 void GetLogicalOrigin(long *x, long *y) const
623 {
624 wxCoord x2, y2;
625 DoGetLogicalOrigin(&x2, &y2);
626 if ( x )
627 *x = x2;
628 if ( y )
629 *y = y2;
630 }
631
632 void GetDeviceOrigin(long *x, long *y) const
633 {
634 wxCoord x2, y2;
635 DoGetDeviceOrigin(&x2, &y2);
636 if ( x )
637 *x = x2;
638 if ( y )
639 *y = y2;
640 }
1dd989e1 641 void GetClippingBox(long *x, long *y, long *w, long *h) const
cd9da200
VZ
642 {
643 wxCoord xx,yy,ww,hh;
644 DoGetClippingBox(&xx, &yy, &ww, &hh);
645 if (x) *x = xx;
646 if (y) *y = yy;
647 if (w) *w = ww;
648 if (h) *h = hh;
1dd989e1 649 }
72cdf4c9 650
a23fd0e1
VZ
651protected:
652 // the pure virtual functions which should be implemented by wxDC
387ebd3e 653 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
a23fd0e1
VZ
654 int style = wxFLOOD_SURFACE) = 0;
655
213ad8e7
VZ
656 virtual void DoGradientFillLinear(const wxRect& rect,
657 const wxColour& initialColour,
658 const wxColour& destColour,
659 wxDirection nDirection = wxEAST);
4660e6ac 660
72cdf4c9 661 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
a23fd0e1 662
72cdf4c9
VZ
663 virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
664 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
a23fd0e1 665
72cdf4c9
VZ
666 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
667 wxCoord x2, wxCoord y2,
668 wxCoord xc, wxCoord yc) = 0;
cd9da200
VZ
669 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
670 wxCoord width, wxCoord height);
72cdf4c9 671 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
a23fd0e1
VZ
672 double sa, double ea) = 0;
673
72cdf4c9
VZ
674 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0;
675 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
676 wxCoord width, wxCoord height,
a23fd0e1 677 double radius) = 0;
72cdf4c9
VZ
678 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
679 wxCoord width, wxCoord height) = 0;
a23fd0e1 680
72cdf4c9 681 virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
a23fd0e1 682
72cdf4c9
VZ
683 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
684 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
68379eaf 685 bool useMask = false) = 0;
a23fd0e1 686
72cdf4c9 687 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
95724b1a
VZ
688 virtual void DoDrawRotatedText(const wxString& text,
689 wxCoord x, wxCoord y, double angle) = 0;
a23fd0e1 690
72cdf4c9
VZ
691 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
692 wxCoord width, wxCoord height,
693 wxDC *source, wxCoord xsrc, wxCoord ysrc,
68379eaf 694 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) = 0;
a23fd0e1
VZ
695
696 virtual void DoGetSize(int *width, int *height) const = 0;
697 virtual void DoGetSizeMM(int* width, int* height) const = 0;
698
699 virtual void DoDrawLines(int n, wxPoint points[],
72cdf4c9 700 wxCoord xoffset, wxCoord yoffset) = 0;
a23fd0e1 701 virtual void DoDrawPolygon(int n, wxPoint points[],
72cdf4c9 702 wxCoord xoffset, wxCoord yoffset,
a23fd0e1 703 int fillStyle = wxODDEVEN_RULE) = 0;
793db755 704 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
6e76b35d
VZ
705 wxCoord xoffset, wxCoord yoffset,
706 int fillStyle);
a23fd0e1
VZ
707
708 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
72cdf4c9
VZ
709 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
710 wxCoord width, wxCoord height) = 0;
b0e0d661 711
c5789d15
WS
712#if WXWIN_COMPATIBILITY_2_4
713 // this was only for confusing people, use DoGetClippingBox only
72cdf4c9
VZ
714 virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y,
715 wxCoord *w, wxCoord *h)
b0e0d661 716 { DoGetClippingBox(x, y, w, h); }
c5789d15
WS
717#endif
718
72cdf4c9
VZ
719 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
720 wxCoord *w, wxCoord *h) const
a23fd0e1 721 {
d16b634f
VZ
722 if ( x )
723 *x = m_clipX1;
724 if ( y )
725 *y = m_clipY1;
726 if ( w )
727 *w = m_clipX2 - m_clipX1;
728 if ( h )
729 *h = m_clipY2 - m_clipY1;
a23fd0e1
VZ
730 }
731
72cdf4c9 732 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
733 {
734 if ( x ) *x = m_logicalOriginX;
735 if ( y ) *y = m_logicalOriginY;
736 }
737
72cdf4c9 738 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
739 {
740 if ( x ) *x = m_deviceOriginX;
741 if ( y ) *y = m_deviceOriginY;
742 }
743
72cdf4c9
VZ
744 virtual void DoGetTextExtent(const wxString& string,
745 wxCoord *x, wxCoord *y,
746 wxCoord *descent = NULL,
747 wxCoord *externalLeading = NULL,
748 wxFont *theFont = NULL) const = 0;
d16b634f 749
0919e93e 750 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
d16b634f 751
64698f9a 752#if wxUSE_SPLINES
fe2e4366 753 virtual void DoDrawSpline(wxList *points);
64698f9a 754#endif
a23fd0e1
VZ
755
756protected:
d16b634f
VZ
757 // unset clipping variables (after clipping region was destroyed)
758 void ResetClipping()
759 {
760 m_clipping = false;
761
762 m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0;
763 }
764
a23fd0e1
VZ
765 // flags
766 bool m_colour:1;
767 bool m_ok:1;
768 bool m_clipping:1;
769 bool m_isInteractive:1;
f6bcfd97 770 bool m_isBBoxValid:1;
a23fd0e1
VZ
771
772 // coordinate system variables
773
774 // TODO short descriptions of what exactly they are would be nice...
775
72cdf4c9
VZ
776 wxCoord m_logicalOriginX, m_logicalOriginY;
777 wxCoord m_deviceOriginX, m_deviceOriginY;
a23fd0e1
VZ
778
779 double m_logicalScaleX, m_logicalScaleY;
780 double m_userScaleX, m_userScaleY;
781 double m_scaleX, m_scaleY;
782
783 // Used by SetAxisOrientation() to invert the axes
784 int m_signX, m_signY;
785
786 // bounding and clipping boxes
72cdf4c9
VZ
787 wxCoord m_minX, m_minY, m_maxX, m_maxY;
788 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
a23fd0e1
VZ
789
790 int m_logicalFunction;
791 int m_backgroundMode;
792 int m_mappingMode;
793
794 // GDI objects
795 wxPen m_pen;
796 wxBrush m_brush;
797 wxBrush m_backgroundBrush;
798 wxColour m_textForegroundColour;
799 wxColour m_textBackgroundColour;
800 wxFont m_font;
d275c7eb
VZ
801
802#if wxUSE_PALETTE
a23fd0e1 803 wxPalette m_palette;
b95edd47 804 bool m_hasCustomPalette;
d275c7eb 805#endif // wxUSE_PALETTE
a23fd0e1
VZ
806
807private:
ac84e37d 808 DECLARE_NO_COPY_CLASS(wxDCBase)
cd9da200 809 DECLARE_ABSTRACT_CLASS(wxDCBase)
a23fd0e1
VZ
810};
811
812// ----------------------------------------------------------------------------
813// now include the declaration of wxDC class
814// ----------------------------------------------------------------------------
815
4055ed82 816#if defined(__WXPALMOS__)
ffecfa5a
JS
817 #include "wx/palmos/dc.h"
818#elif defined(__WXMSW__)
a23fd0e1 819 #include "wx/msw/dc.h"
2049ba38 820#elif defined(__WXMOTIF__)
a23fd0e1 821 #include "wx/motif/dc.h"
1be7a35c 822#elif defined(__WXGTK20__)
a23fd0e1 823 #include "wx/gtk/dc.h"
1be7a35c
MR
824#elif defined(__WXGTK__)
825 #include "wx/gtk1/dc.h"
83df96d6
JS
826#elif defined(__WXX11__)
827 #include "wx/x11/dc.h"
1e6feb95
VZ
828#elif defined(__WXMGL__)
829 #include "wx/mgl/dc.h"
34138703 830#elif defined(__WXMAC__)
a23fd0e1 831 #include "wx/mac/dc.h"
f4515f98
DE
832#elif defined(__WXCOCOA__)
833 #include "wx/cocoa/dc.h"
1777b9bb
DW
834#elif defined(__WXPM__)
835 #include "wx/os2/dc.h"
c801d85f
KB
836#endif
837
1e6feb95
VZ
838// ----------------------------------------------------------------------------
839// helper class: you can use it to temporarily change the DC text colour and
840// restore it automatically when the object goes out of scope
841// ----------------------------------------------------------------------------
842
843class WXDLLEXPORT wxDCTextColourChanger
844{
845public:
ba161d7e 846 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
1e6feb95
VZ
847
848 ~wxDCTextColourChanger()
849 {
850 if ( m_colFgOld.Ok() )
851 m_dc.SetTextForeground(m_colFgOld);
852 }
853
854 void Set(const wxColour& col)
855 {
856 if ( !m_colFgOld.Ok() )
857 m_colFgOld = m_dc.GetTextForeground();
858 m_dc.SetTextForeground(col);
859 }
860
861private:
862 wxDC& m_dc;
863
864 wxColour m_colFgOld;
fc7a2a60
VZ
865
866 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger)
1e6feb95
VZ
867};
868
4660e6ac
WS
869// ----------------------------------------------------------------------------
870// helper class: you can use it to temporarily change the DC pen and
871// restore it automatically when the object goes out of scope
872// ----------------------------------------------------------------------------
873
874class WXDLLEXPORT wxDCPenChanger
875{
876public:
0164f8eb
WS
877 wxDCPenChanger(wxDC& dc, const wxPen& pen) : m_dc(dc), m_penOld(dc.GetPen())
878 {
879 m_dc.SetPen(pen);
880 }
4660e6ac
WS
881
882 ~wxDCPenChanger()
883 {
884 if ( m_penOld.Ok() )
885 m_dc.SetPen(m_penOld);
886 }
887
4660e6ac
WS
888private:
889 wxDC& m_dc;
890
891 wxPen m_penOld;
892
893 DECLARE_NO_COPY_CLASS(wxDCPenChanger)
894};
895
896// ----------------------------------------------------------------------------
897// helper class: you can use it to temporarily change the DC brush and
898// restore it automatically when the object goes out of scope
899// ----------------------------------------------------------------------------
900
901class WXDLLEXPORT wxDCBrushChanger
902{
903public:
0164f8eb
WS
904 wxDCBrushChanger(wxDC& dc, const wxBrush& brush) : m_dc(dc), m_brushOld(dc.GetBrush())
905 {
906 m_dc.SetBrush(brush);
907 }
4660e6ac
WS
908
909 ~wxDCBrushChanger()
910 {
911 if ( m_brushOld.Ok() )
912 m_dc.SetBrush(m_brushOld);
913 }
914
4660e6ac
WS
915private:
916 wxDC& m_dc;
917
918 wxBrush m_brushOld;
919
920 DECLARE_NO_COPY_CLASS(wxDCBrushChanger)
921};
922
e26be42b
VZ
923// ----------------------------------------------------------------------------
924// another small helper class: sets the clipping region in its ctor and
925// destroys it in the dtor
926// ----------------------------------------------------------------------------
927
928class WXDLLEXPORT wxDCClipper
929{
930public:
fc298ea7
VZ
931 wxDCClipper(wxDC& dc, const wxRegion& r) : m_dc(dc)
932 { dc.SetClippingRegion(r); }
e26be42b
VZ
933 wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc)
934 { dc.SetClippingRegion(r.x, r.y, r.width, r.height); }
935 wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc)
936 { dc.SetClippingRegion(x, y, w, h); }
937
938 ~wxDCClipper() { m_dc.DestroyClippingRegion(); }
939
940private:
941 wxDC& m_dc;
fc7a2a60
VZ
942
943 DECLARE_NO_COPY_CLASS(wxDCClipper)
e26be42b
VZ
944};
945
c801d85f 946#endif
34138703 947 // _WX_DC_H_BASE_