]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dc.h
Compilation fix for old GCC versions.
[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 }
c64c9cd3 316
c59abe03 317 wxBitmap GetAsBitmap(const wxRect *subrect = (const wxRect *) NULL) const
c64c9cd3 318 {
c59abe03 319 return DoGetAsBitmap(subrect);
c64c9cd3 320 }
a23fd0e1
VZ
321
322#if wxUSE_SPLINES
72cdf4c9
VZ
323 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
324 void DrawSpline(wxCoord x1, wxCoord y1,
325 wxCoord x2, wxCoord y2,
326 wxCoord x3, wxCoord y3);
bd5dd957 327 void DrawSpline(int n, wxPoint points[]);
a23fd0e1
VZ
328
329 void DrawSpline(wxList *points) { DoDrawSpline(points); }
330#endif // wxUSE_SPLINES
331
12bdd77c
JS
332 // Eventually we will have wxUSE_GENERIC_DRAWELLIPSE
333#ifdef __WXWINCE__
334 //! Generic method to draw ellipses, circles and arcs with current pen and brush.
335 /*! \param x Upper left corner of bounding box.
336 * \param y Upper left corner of bounding box.
337 * \param w Width of bounding box.
338 * \param h Height of bounding box.
d16b634f 339 * \param sa Starting angle of arc
12bdd77c
JS
340 * (counterclockwise, start at 3 o'clock, 360 is full circle).
341 * \param ea Ending angle of arc.
d16b634f 342 * \param angle Rotation angle, the Arc will be rotated after
12bdd77c
JS
343 * calculating begin and end.
344 */
d16b634f
VZ
345 void DrawEllipticArcRot( wxCoord x, wxCoord y,
346 wxCoord width, wxCoord height,
12bdd77c
JS
347 double sa = 0, double ea = 0, double angle = 0 )
348 { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); }
d16b634f
VZ
349
350 void DrawEllipticArcRot( const wxPoint& pt,
12bdd77c
JS
351 const wxSize& sz,
352 double sa = 0, double ea = 0, double angle = 0 )
353 { DoDrawEllipticArcRot( pt.x, pt.y, sz.x, sz.y, sa, ea, angle ); }
354
355 void DrawEllipticArcRot( const wxRect& rect,
356 double sa = 0, double ea = 0, double angle = 0 )
357 { DoDrawEllipticArcRot( rect.x, rect.y, rect.width, rect.height, sa, ea, angle ); }
358
d16b634f
VZ
359 virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y,
360 wxCoord w, wxCoord h,
12bdd77c 361 double sa = 0, double ea = 0, double angle = 0 );
d16b634f 362
12bdd77c
JS
363 //! Rotates points around center.
364 /*! This is a quite straight method, it calculates in pixels
365 * and so it produces rounding errors.
366 * \param points The points inside will be rotated.
367 * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle).
368 * \param center Center of rotation.
d16b634f 369 */
c47addef 370 void Rotate( wxList* points, double angle, wxPoint center = wxPoint(0,0) );
12bdd77c
JS
371
372 // used by DrawEllipticArcRot
373 // Careful: wxList gets filled with points you have to delete later.
d16b634f
VZ
374 void CalculateEllipticPoints( wxList* points,
375 wxCoord xStart, wxCoord yStart,
376 wxCoord w, wxCoord h,
12bdd77c
JS
377 double sa, double ea );
378#endif
d16b634f 379
a23fd0e1
VZ
380 // global DC operations
381 // --------------------
382
383 virtual void Clear() = 0;
384
68379eaf 385 virtual bool StartDoc(const wxString& WXUNUSED(message)) { return true; }
af0bb3b1 386 virtual void EndDoc() { }
a23fd0e1 387
af0bb3b1
VZ
388 virtual void StartPage() { }
389 virtual void EndPage() { }
a23fd0e1 390
2e992e06
VZ
391#if WXWIN_COMPATIBILITY_2_6
392 wxDEPRECATED( void BeginDrawing() );
393 wxDEPRECATED( void EndDrawing() );
394#endif // WXWIN_COMPATIBILITY_2_6
395
396
a23fd0e1
VZ
397 // set objects to use for drawing
398 // ------------------------------
399
400 virtual void SetFont(const wxFont& font) = 0;
401 virtual void SetPen(const wxPen& pen) = 0;
402 virtual void SetBrush(const wxBrush& brush) = 0;
403 virtual void SetBackground(const wxBrush& brush) = 0;
404 virtual void SetBackgroundMode(int mode) = 0;
d275c7eb 405#if wxUSE_PALETTE
a23fd0e1 406 virtual void SetPalette(const wxPalette& palette) = 0;
d275c7eb 407#endif // wxUSE_PALETTE
a23fd0e1
VZ
408
409 // clipping region
410 // ---------------
411
72cdf4c9 412 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
a23fd0e1
VZ
413 { DoSetClippingRegion(x, y, width, height); }
414 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
415 { DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); }
416 void SetClippingRegion(const wxRect& rect)
417 { DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
418 void SetClippingRegion(const wxRegion& region)
419 { DoSetClippingRegionAsRegion(region); }
420
d16b634f 421 virtual void DestroyClippingRegion() { ResetClipping(); }
a23fd0e1 422
72cdf4c9 423 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
a23fd0e1
VZ
424 { DoGetClippingBox(x, y, w, h); }
425 void GetClippingBox(wxRect& rect) const
8fb3a512 426 {
ae500232 427 DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height);
8fb3a512 428 }
a23fd0e1
VZ
429
430 // text extent
431 // -----------
432
72cdf4c9
VZ
433 virtual wxCoord GetCharHeight() const = 0;
434 virtual wxCoord GetCharWidth() const = 0;
cd9da200 435
1e6feb95 436 // only works for single line strings
72cdf4c9
VZ
437 void GetTextExtent(const wxString& string,
438 wxCoord *x, wxCoord *y,
439 wxCoord *descent = NULL,
440 wxCoord *externalLeading = NULL,
441 wxFont *theFont = NULL) const
442 { DoGetTextExtent(string, x, y, descent, externalLeading, theFont); }
a23fd0e1 443
1e6feb95
VZ
444 // works for single as well as multi-line strings
445 virtual void GetMultiLineTextExtent(const wxString& text,
446 wxCoord *width,
447 wxCoord *height,
448 wxCoord *heightLine = NULL,
449 wxFont *font = NULL);
450
0919e93e
RD
451 // Measure cumulative width of text after each character
452 bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
453 { return DoGetPartialTextExtents(text, widths); }
454
d16b634f 455
a23fd0e1
VZ
456 // size and resolution
457 // -------------------
458
459 // in device units
460 void GetSize(int *width, int *height) const
461 { DoGetSize(width, height); }
462 wxSize GetSize() const
463 {
464 int w, h;
465 DoGetSize(&w, &h);
466
467 return wxSize(w, h);
468 }
469
470 // in mm
471 void GetSizeMM(int* width, int* height) const
472 { DoGetSizeMM(width, height); }
473 wxSize GetSizeMM() const
474 {
475 int w, h;
476 DoGetSizeMM(&w, &h);
477
478 return wxSize(w, h);
479 }
480
481 // coordinates conversions
482 // -----------------------
483
484 // This group of functions does actual conversion of the input, as you'd
485 // expect.
72cdf4c9
VZ
486 wxCoord DeviceToLogicalX(wxCoord x) const;
487 wxCoord DeviceToLogicalY(wxCoord y) const;
488 wxCoord DeviceToLogicalXRel(wxCoord x) const;
489 wxCoord DeviceToLogicalYRel(wxCoord y) const;
490 wxCoord LogicalToDeviceX(wxCoord x) const;
491 wxCoord LogicalToDeviceY(wxCoord y) const;
492 wxCoord LogicalToDeviceXRel(wxCoord x) const;
493 wxCoord LogicalToDeviceYRel(wxCoord y) const;
a23fd0e1
VZ
494
495 // query DC capabilities
496 // ---------------------
497
498 virtual bool CanDrawBitmap() const = 0;
499 virtual bool CanGetTextExtent() const = 0;
500
501 // colour depth
502 virtual int GetDepth() const = 0;
503
504 // Resolution in Pixels per inch
505 virtual wxSize GetPPI() const = 0;
506
b7cacb43
VZ
507 virtual bool Ok() const { return IsOk(); }
508 virtual bool IsOk() const { return m_ok; }
a23fd0e1 509
2439f37a
VZ
510 // accessors and setters
511 // ---------------------
a23fd0e1 512
2e992e06
VZ
513 virtual int GetBackgroundMode() const { return m_backgroundMode; }
514 virtual const wxBrush& GetBackground() const { return m_backgroundBrush; }
515 virtual const wxBrush& GetBrush() const { return m_brush; }
516 virtual const wxFont& GetFont() const { return m_font; }
517 virtual const wxPen& GetPen() const { return m_pen; }
a23fd0e1 518
2e992e06
VZ
519 virtual const wxColour& GetTextForeground() const { return m_textForegroundColour; }
520 virtual const wxColour& GetTextBackground() const { return m_textBackgroundColour; }
a23fd0e1
VZ
521 virtual void SetTextForeground(const wxColour& colour)
522 { m_textForegroundColour = colour; }
523 virtual void SetTextBackground(const wxColour& colour)
524 { m_textBackgroundColour = colour; }
525
2e992e06 526 virtual int GetMapMode() const { return m_mappingMode; }
a23fd0e1
VZ
527 virtual void SetMapMode(int mode) = 0;
528
529 virtual void GetUserScale(double *x, double *y) const
530 {
531 if ( x ) *x = m_userScaleX;
532 if ( y ) *y = m_userScaleY;
533 }
534 virtual void SetUserScale(double x, double y) = 0;
535
a23fd0e1
VZ
536 virtual void GetLogicalScale(double *x, double *y)
537 {
538 if ( x ) *x = m_logicalScaleX;
539 if ( y ) *y = m_logicalScaleY;
540 }
541 virtual void SetLogicalScale(double x, double y)
542 {
543 m_logicalScaleX = x;
544 m_logicalScaleY = y;
545 }
546
72cdf4c9 547 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
548 { DoGetLogicalOrigin(x, y); }
549 wxPoint GetLogicalOrigin() const
72cdf4c9
VZ
550 { wxCoord x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
551 virtual void SetLogicalOrigin(wxCoord x, wxCoord y) = 0;
a23fd0e1 552
72cdf4c9 553 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
554 { DoGetDeviceOrigin(x, y); }
555 wxPoint GetDeviceOrigin() const
72cdf4c9
VZ
556 { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
557 virtual void SetDeviceOrigin(wxCoord x, wxCoord y) = 0;
a23fd0e1 558
b1263dcf
WS
559 virtual void ComputeScaleAndOrigin() {}
560
a23fd0e1
VZ
561 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0;
562
2e992e06 563 virtual int GetLogicalFunction() const { return m_logicalFunction; }
a23fd0e1
VZ
564 virtual void SetLogicalFunction(int function) = 0;
565
ea76a6a5 566#if WXWIN_COMPATIBILITY_2_4
a23fd0e1 567 virtual void SetOptimization(bool WXUNUSED(opt)) { }
68379eaf 568 virtual bool GetOptimization() { return false; }
ea76a6a5 569#endif
a23fd0e1
VZ
570
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,
615 wxFont *theFont = NULL) const
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,
717 wxDC *source, wxCoord xsrc, wxCoord ysrc,
68379eaf 718 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) = 0;
a23fd0e1 719
c59abe03 720 virtual wxBitmap DoGetAsBitmap(const wxRect *WXUNUSED(subrect)) const { return wxNullBitmap; }
c64c9cd3 721
a23fd0e1
VZ
722 virtual void DoGetSize(int *width, int *height) const = 0;
723 virtual void DoGetSizeMM(int* width, int* height) const = 0;
724
725 virtual void DoDrawLines(int n, wxPoint points[],
72cdf4c9 726 wxCoord xoffset, wxCoord yoffset) = 0;
a23fd0e1 727 virtual void DoDrawPolygon(int n, wxPoint points[],
72cdf4c9 728 wxCoord xoffset, wxCoord yoffset,
a23fd0e1 729 int fillStyle = wxODDEVEN_RULE) = 0;
793db755 730 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
6e76b35d
VZ
731 wxCoord xoffset, wxCoord yoffset,
732 int fillStyle);
a23fd0e1
VZ
733
734 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
72cdf4c9
VZ
735 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
736 wxCoord width, wxCoord height) = 0;
b0e0d661 737
c5789d15
WS
738#if WXWIN_COMPATIBILITY_2_4
739 // this was only for confusing people, use DoGetClippingBox only
72cdf4c9
VZ
740 virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y,
741 wxCoord *w, wxCoord *h)
b0e0d661 742 { DoGetClippingBox(x, y, w, h); }
c5789d15
WS
743#endif
744
72cdf4c9
VZ
745 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
746 wxCoord *w, wxCoord *h) const
a23fd0e1 747 {
d16b634f
VZ
748 if ( x )
749 *x = m_clipX1;
750 if ( y )
751 *y = m_clipY1;
752 if ( w )
753 *w = m_clipX2 - m_clipX1;
754 if ( h )
755 *h = m_clipY2 - m_clipY1;
a23fd0e1
VZ
756 }
757
72cdf4c9 758 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
759 {
760 if ( x ) *x = m_logicalOriginX;
761 if ( y ) *y = m_logicalOriginY;
762 }
763
72cdf4c9 764 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
a23fd0e1
VZ
765 {
766 if ( x ) *x = m_deviceOriginX;
767 if ( y ) *y = m_deviceOriginY;
768 }
769
72cdf4c9
VZ
770 virtual void DoGetTextExtent(const wxString& string,
771 wxCoord *x, wxCoord *y,
772 wxCoord *descent = NULL,
773 wxCoord *externalLeading = NULL,
774 wxFont *theFont = NULL) const = 0;
d16b634f 775
0919e93e 776 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
d16b634f 777
64698f9a 778#if wxUSE_SPLINES
fe2e4366 779 virtual void DoDrawSpline(wxList *points);
64698f9a 780#endif
a23fd0e1
VZ
781
782protected:
d16b634f
VZ
783 // unset clipping variables (after clipping region was destroyed)
784 void ResetClipping()
785 {
786 m_clipping = false;
787
788 m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0;
789 }
790
a23fd0e1
VZ
791 // flags
792 bool m_colour:1;
793 bool m_ok:1;
794 bool m_clipping:1;
795 bool m_isInteractive:1;
f6bcfd97 796 bool m_isBBoxValid:1;
a23fd0e1
VZ
797
798 // coordinate system variables
799
800 // TODO short descriptions of what exactly they are would be nice...
801
72cdf4c9
VZ
802 wxCoord m_logicalOriginX, m_logicalOriginY;
803 wxCoord m_deviceOriginX, m_deviceOriginY;
a23fd0e1
VZ
804
805 double m_logicalScaleX, m_logicalScaleY;
806 double m_userScaleX, m_userScaleY;
807 double m_scaleX, m_scaleY;
808
809 // Used by SetAxisOrientation() to invert the axes
810 int m_signX, m_signY;
811
812 // bounding and clipping boxes
72cdf4c9
VZ
813 wxCoord m_minX, m_minY, m_maxX, m_maxY;
814 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
a23fd0e1
VZ
815
816 int m_logicalFunction;
817 int m_backgroundMode;
818 int m_mappingMode;
819
820 // GDI objects
821 wxPen m_pen;
822 wxBrush m_brush;
823 wxBrush m_backgroundBrush;
824 wxColour m_textForegroundColour;
825 wxColour m_textBackgroundColour;
826 wxFont m_font;
d275c7eb
VZ
827
828#if wxUSE_PALETTE
a23fd0e1 829 wxPalette m_palette;
b95edd47 830 bool m_hasCustomPalette;
d275c7eb 831#endif // wxUSE_PALETTE
a23fd0e1
VZ
832
833private:
ac84e37d 834 DECLARE_NO_COPY_CLASS(wxDCBase)
cd9da200 835 DECLARE_ABSTRACT_CLASS(wxDCBase)
a23fd0e1
VZ
836};
837
838// ----------------------------------------------------------------------------
839// now include the declaration of wxDC class
840// ----------------------------------------------------------------------------
841
4055ed82 842#if defined(__WXPALMOS__)
ffecfa5a
JS
843 #include "wx/palmos/dc.h"
844#elif defined(__WXMSW__)
a23fd0e1 845 #include "wx/msw/dc.h"
2049ba38 846#elif defined(__WXMOTIF__)
a23fd0e1 847 #include "wx/motif/dc.h"
1be7a35c 848#elif defined(__WXGTK20__)
a23fd0e1 849 #include "wx/gtk/dc.h"
1be7a35c
MR
850#elif defined(__WXGTK__)
851 #include "wx/gtk1/dc.h"
83df96d6
JS
852#elif defined(__WXX11__)
853 #include "wx/x11/dc.h"
1e6feb95
VZ
854#elif defined(__WXMGL__)
855 #include "wx/mgl/dc.h"
b3c86150
VS
856#elif defined(__WXDFB__)
857 #include "wx/dfb/dc.h"
34138703 858#elif defined(__WXMAC__)
a23fd0e1 859 #include "wx/mac/dc.h"
f4515f98
DE
860#elif defined(__WXCOCOA__)
861 #include "wx/cocoa/dc.h"
1777b9bb
DW
862#elif defined(__WXPM__)
863 #include "wx/os2/dc.h"
c801d85f
KB
864#endif
865
8acd14d1
SC
866#if wxUSE_GRAPHICS_CONTEXT
867 #include "wx/dcgraph.h"
868#endif
869
1e6feb95
VZ
870// ----------------------------------------------------------------------------
871// helper class: you can use it to temporarily change the DC text colour and
872// restore it automatically when the object goes out of scope
873// ----------------------------------------------------------------------------
874
875class WXDLLEXPORT wxDCTextColourChanger
876{
877public:
ba161d7e 878 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
1e6feb95 879
1b97b23d
VS
880 wxDCTextColourChanger(wxDC& dc, const wxColour& col) : m_dc(dc)
881 {
882 Set(col);
883 }
884
1e6feb95
VZ
885 ~wxDCTextColourChanger()
886 {
887 if ( m_colFgOld.Ok() )
888 m_dc.SetTextForeground(m_colFgOld);
889 }
890
891 void Set(const wxColour& col)
892 {
893 if ( !m_colFgOld.Ok() )
894 m_colFgOld = m_dc.GetTextForeground();
895 m_dc.SetTextForeground(col);
896 }
897
898private:
899 wxDC& m_dc;
900
901 wxColour m_colFgOld;
fc7a2a60
VZ
902
903 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger)
1e6feb95
VZ
904};
905
4660e6ac
WS
906// ----------------------------------------------------------------------------
907// helper class: you can use it to temporarily change the DC pen and
908// restore it automatically when the object goes out of scope
909// ----------------------------------------------------------------------------
910
911class WXDLLEXPORT wxDCPenChanger
912{
913public:
0164f8eb
WS
914 wxDCPenChanger(wxDC& dc, const wxPen& pen) : m_dc(dc), m_penOld(dc.GetPen())
915 {
916 m_dc.SetPen(pen);
917 }
4660e6ac
WS
918
919 ~wxDCPenChanger()
920 {
921 if ( m_penOld.Ok() )
922 m_dc.SetPen(m_penOld);
923 }
924
4660e6ac
WS
925private:
926 wxDC& m_dc;
927
928 wxPen m_penOld;
929
930 DECLARE_NO_COPY_CLASS(wxDCPenChanger)
931};
932
933// ----------------------------------------------------------------------------
934// helper class: you can use it to temporarily change the DC brush and
935// restore it automatically when the object goes out of scope
936// ----------------------------------------------------------------------------
937
938class WXDLLEXPORT wxDCBrushChanger
939{
940public:
0164f8eb
WS
941 wxDCBrushChanger(wxDC& dc, const wxBrush& brush) : m_dc(dc), m_brushOld(dc.GetBrush())
942 {
943 m_dc.SetBrush(brush);
944 }
4660e6ac
WS
945
946 ~wxDCBrushChanger()
947 {
948 if ( m_brushOld.Ok() )
949 m_dc.SetBrush(m_brushOld);
950 }
951
4660e6ac
WS
952private:
953 wxDC& m_dc;
954
955 wxBrush m_brushOld;
956
957 DECLARE_NO_COPY_CLASS(wxDCBrushChanger)
958};
959
e26be42b
VZ
960// ----------------------------------------------------------------------------
961// another small helper class: sets the clipping region in its ctor and
962// destroys it in the dtor
963// ----------------------------------------------------------------------------
964
965class WXDLLEXPORT wxDCClipper
966{
967public:
fc298ea7
VZ
968 wxDCClipper(wxDC& dc, const wxRegion& r) : m_dc(dc)
969 { dc.SetClippingRegion(r); }
e26be42b
VZ
970 wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc)
971 { dc.SetClippingRegion(r.x, r.y, r.width, r.height); }
972 wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc)
973 { dc.SetClippingRegion(x, y, w, h); }
974
975 ~wxDCClipper() { m_dc.DestroyClippingRegion(); }
976
977private:
978 wxDC& m_dc;
fc7a2a60
VZ
979
980 DECLARE_NO_COPY_CLASS(wxDCClipper)
e26be42b
VZ
981};
982
8b56b16a 983#endif // _WX_DC_H_BASE_