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