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