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