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