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