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