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