wxPoint/Size/Rect() causes the same code with (0,0) initialization and is incomparabl...
[wxWidgets.git] / include / wx / dc.h
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) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DC_H_BASE_
13 #define _WX_DC_H_BASE_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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/bitmap.h" // for wxNullBitmap
29 #include "wx/brush.h"
30 #include "wx/pen.h"
31 #include "wx/palette.h"
32 #include "wx/list.h" // we use wxList in inline functions
33 #include "wx/dynarray.h"
34 #include "wx/math.h"
35
36 class WXDLLEXPORT wxDC;
37 class WXDLLEXPORT wxDCBase;
38
39 class WXDLLEXPORT wxDrawObject
40 {
41 public:
42
43 wxDrawObject()
44 : m_isBBoxValid(false)
45 , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0)
46 { }
47
48 virtual ~wxDrawObject() { }
49
50 virtual void Draw(wxDCBase&) const { }
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 {
63 m_isBBoxValid = true;
64
65 m_minX = x;
66 m_minY = y;
67 m_maxX = x;
68 m_maxY = y;
69 }
70 }
71
72 void ResetBoundingBox()
73 {
74 m_isBBoxValid = false;
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
89 protected:
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
96 // ---------------------------------------------------------------------------
97 // global variables
98 // ---------------------------------------------------------------------------
99
100 extern WXDLLEXPORT_DATA(int) wxPageNumber;
101
102 // ---------------------------------------------------------------------------
103 // wxDC is the device context - object on which any drawing is done
104 // ---------------------------------------------------------------------------
105
106 class WXDLLEXPORT wxDCBase : public wxObject
107 {
108 public:
109 wxDCBase()
110 : m_colour(wxColourDisplay())
111 , m_ok(true)
112 , m_clipping(false)
113 , m_isInteractive(0)
114 , m_isBBoxValid(false)
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()
134 , m_hasCustomPalette(false)
135 #endif // wxUSE_PALETTE
136 {
137 ResetBoundingBox();
138 ResetClipping();
139 }
140
141 ~wxDCBase() { }
142
143 virtual void BeginDrawing() { }
144 virtual void EndDrawing() { }
145
146 // graphic primitives
147 // ------------------
148
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
156 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col,
157 int style = wxFLOOD_SURFACE)
158 { return DoFloodFill(x, y, col, style); }
159 bool FloodFill(const wxPoint& pt, const wxColour& col,
160 int style = wxFLOOD_SURFACE)
161 { return DoFloodFill(pt.x, pt.y, col, style); }
162
163 bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const
164 { return DoGetPixel(x, y, col); }
165 bool GetPixel(const wxPoint& pt, wxColour *col) const
166 { return DoGetPixel(pt.x, pt.y, col); }
167
168 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
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
173 void CrossHair(wxCoord x, wxCoord y)
174 { DoCrossHair(x, y); }
175 void CrossHair(const wxPoint& pt)
176 { DoCrossHair(pt.x, pt.y); }
177
178 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
179 wxCoord xc, wxCoord yc)
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
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
190 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
191 double sa, double ea)
192 { DoDrawEllipticArc(x, y, w, h, sa, ea); }
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
197 void DrawPoint(wxCoord x, wxCoord y)
198 { DoDrawPoint(x, y); }
199 void DrawPoint(const wxPoint& pt)
200 { DoDrawPoint(pt.x, pt.y); }
201
202 void DrawLines(int n, wxPoint points[],
203 wxCoord xoffset = 0, wxCoord yoffset = 0)
204 { DoDrawLines(n, points, xoffset, yoffset); }
205 void DrawLines(const wxList *list,
206 wxCoord xoffset = 0, wxCoord yoffset = 0);
207
208 void DrawPolygon(int n, wxPoint points[],
209 wxCoord xoffset = 0, wxCoord yoffset = 0,
210 int fillStyle = wxODDEVEN_RULE)
211 { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
212
213 void DrawPolygon(const wxList *list,
214 wxCoord xoffset = 0, wxCoord yoffset = 0,
215 int fillStyle = wxODDEVEN_RULE);
216
217 void DrawPolyPolygon(int n, int count[], wxPoint points[],
218 wxCoord xoffset = 0, wxCoord yoffset = 0,
219 int fillStyle = wxODDEVEN_RULE)
220 { DoDrawPolyPolygon(n, count, points, xoffset, yoffset, fillStyle); }
221
222 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
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
229 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
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
238 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
239 { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
240 void DrawCircle(const wxPoint& pt, wxCoord radius)
241 { DrawCircle(pt.x, pt.y, radius); }
242
243 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
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
250 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
251 { DoDrawIcon(icon, x, y); }
252 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
253 { DoDrawIcon(icon, pt.x, pt.y); }
254
255 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
256 bool useMask = false)
257 { DoDrawBitmap(bmp, x, y, useMask); }
258 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
259 bool useMask = false)
260 { DoDrawBitmap(bmp, pt.x, pt.y, useMask); }
261
262 void DrawText(const wxString& text, wxCoord x, wxCoord y)
263 { DoDrawText(text, x, y); }
264 void DrawText(const wxString& text, const wxPoint& pt)
265 { DoDrawText(text, pt.x, pt.y); }
266
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
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
288 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
289 wxDC *source, wxCoord xsrc, wxCoord ysrc,
290 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
291 {
292 return DoBlit(xdest, ydest, width, height,
293 source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
294 }
295 bool Blit(const wxPoint& destPt, const wxSize& sz,
296 wxDC *source, const wxPoint& srcPt,
297 int rop = wxCOPY, bool useMask = false, const wxPoint& srcPtMask = wxDefaultPosition)
298 {
299 return DoBlit(destPt.x, destPt.y, sz.x, sz.y,
300 source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
301 }
302
303 #if wxUSE_SPLINES
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);
308 void DrawSpline(int n, wxPoint points[]);
309
310 void DrawSpline(wxList *points) { DoDrawSpline(points); }
311 #endif // wxUSE_SPLINES
312
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.
320 * \param sa Starting angle of arc
321 * (counterclockwise, start at 3 o'clock, 360 is full circle).
322 * \param ea Ending angle of arc.
323 * \param angle Rotation angle, the Arc will be rotated after
324 * calculating begin and end.
325 */
326 void DrawEllipticArcRot( wxCoord x, wxCoord y,
327 wxCoord width, wxCoord height,
328 double sa = 0, double ea = 0, double angle = 0 )
329 { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); }
330
331 void DrawEllipticArcRot( const wxPoint& pt,
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
340 virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y,
341 wxCoord w, wxCoord h,
342 double sa = 0, double ea = 0, double angle = 0 );
343
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.
350 */
351 void Rotate( wxList* points, double angle, wxPoint center = wxPoint(0,0) );
352
353 // used by DrawEllipticArcRot
354 // Careful: wxList gets filled with points you have to delete later.
355 void CalculateEllipticPoints( wxList* points,
356 wxCoord xStart, wxCoord yStart,
357 wxCoord w, wxCoord h,
358 double sa, double ea );
359 #endif
360
361 // global DC operations
362 // --------------------
363
364 virtual void Clear() = 0;
365
366 virtual bool StartDoc(const wxString& WXUNUSED(message)) { return true; }
367 virtual void EndDoc() { }
368
369 virtual void StartPage() { }
370 virtual void EndPage() { }
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;
380 #if wxUSE_PALETTE
381 virtual void SetPalette(const wxPalette& palette) = 0;
382 #endif // wxUSE_PALETTE
383
384 // clipping region
385 // ---------------
386
387 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
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
396 virtual void DestroyClippingRegion() { ResetClipping(); }
397
398 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
399 { DoGetClippingBox(x, y, w, h); }
400 void GetClippingBox(wxRect& rect) const
401 {
402 DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height);
403 }
404
405 // text extent
406 // -----------
407
408 virtual wxCoord GetCharHeight() const = 0;
409 virtual wxCoord GetCharWidth() const = 0;
410
411 // only works for single line strings
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); }
418
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
426 // Measure cumulative width of text after each character
427 bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
428 { return DoGetPartialTextExtents(text, widths); }
429
430
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.
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;
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
484 // accessors and setters
485 // ---------------------
486
487 int GetBackgroundMode() const { return m_backgroundMode; }
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; }
492
493 const wxColour& GetTextForeground() const { return m_textForegroundColour; }
494 const wxColour& GetTextBackground() const { return m_textBackgroundColour; }
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
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
521 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const
522 { DoGetLogicalOrigin(x, y); }
523 wxPoint GetLogicalOrigin() const
524 { wxCoord x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
525 virtual void SetLogicalOrigin(wxCoord x, wxCoord y) = 0;
526
527 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const
528 { DoGetDeviceOrigin(x, y); }
529 wxPoint GetDeviceOrigin() const
530 { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
531 virtual void SetDeviceOrigin(wxCoord x, wxCoord y) = 0;
532
533 virtual void ComputeScaleAndOrigin() {}
534
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
540 #if WXWIN_COMPATIBILITY_2_4
541 virtual void SetOptimization(bool WXUNUSED(opt)) { }
542 virtual bool GetOptimization() { return false; }
543 #endif
544
545 // bounding box
546 // ------------
547
548 virtual void CalcBoundingBox(wxCoord x, wxCoord y)
549 {
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 {
559 m_isBBoxValid = true;
560
561 m_minX = x;
562 m_minY = y;
563 m_maxX = x;
564 m_maxY = y;
565 }
566 }
567
568 void ResetBoundingBox()
569 {
570 m_isBBoxValid = false;
571
572 m_minX = m_maxX = m_minY = m_maxY = 0;
573 }
574
575 // Get the final bounding box of the PostScript or Metafile picture.
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; }
580
581 // misc old functions
582 // ------------------
583
584 // for compatibility with the old code when wxCoord was long everywhere
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 }
624 void GetClippingBox(long *x, long *y, long *w, long *h) const
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;
632 }
633
634 protected:
635 // the pure virtual functions which should be implemented by wxDC
636 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
637 int style = wxFLOOD_SURFACE) = 0;
638
639 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
640
641 virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
642 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
643
644 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
645 wxCoord x2, wxCoord y2,
646 wxCoord xc, wxCoord yc) = 0;
647 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
648 wxCoord width, wxCoord height);
649 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
650 double sa, double ea) = 0;
651
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,
655 double radius) = 0;
656 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
657 wxCoord width, wxCoord height) = 0;
658
659 virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
660
661 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
662 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
663 bool useMask = false) = 0;
664
665 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
666 virtual void DoDrawRotatedText(const wxString& text,
667 wxCoord x, wxCoord y, double angle) = 0;
668
669 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
670 wxCoord width, wxCoord height,
671 wxDC *source, wxCoord xsrc, wxCoord ysrc,
672 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) = 0;
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[],
678 wxCoord xoffset, wxCoord yoffset) = 0;
679 virtual void DoDrawPolygon(int n, wxPoint points[],
680 wxCoord xoffset, wxCoord yoffset,
681 int fillStyle = wxODDEVEN_RULE) = 0;
682 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
683 wxCoord xoffset, wxCoord yoffset,
684 int fillStyle);
685
686 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
687 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
688 wxCoord width, wxCoord height) = 0;
689
690 #if WXWIN_COMPATIBILITY_2_4
691 // this was only for confusing people, use DoGetClippingBox only
692 virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y,
693 wxCoord *w, wxCoord *h)
694 { DoGetClippingBox(x, y, w, h); }
695 #endif
696
697 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
698 wxCoord *w, wxCoord *h) const
699 {
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;
708 }
709
710 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
711 {
712 if ( x ) *x = m_logicalOriginX;
713 if ( y ) *y = m_logicalOriginY;
714 }
715
716 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
717 {
718 if ( x ) *x = m_deviceOriginX;
719 if ( y ) *y = m_deviceOriginY;
720 }
721
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;
727
728 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
729
730 #if wxUSE_SPLINES
731 virtual void DoDrawSpline(wxList *points);
732 #endif
733
734 protected:
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
743 // flags
744 bool m_colour:1;
745 bool m_ok:1;
746 bool m_clipping:1;
747 bool m_isInteractive:1;
748 bool m_isBBoxValid:1;
749
750 // coordinate system variables
751
752 // TODO short descriptions of what exactly they are would be nice...
753
754 wxCoord m_logicalOriginX, m_logicalOriginY;
755 wxCoord m_deviceOriginX, m_deviceOriginY;
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
765 wxCoord m_minX, m_minY, m_maxX, m_maxY;
766 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
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;
779
780 #if wxUSE_PALETTE
781 wxPalette m_palette;
782 bool m_hasCustomPalette;
783 #endif // wxUSE_PALETTE
784
785 private:
786 DECLARE_NO_COPY_CLASS(wxDCBase)
787 DECLARE_ABSTRACT_CLASS(wxDCBase)
788 };
789
790 // ----------------------------------------------------------------------------
791 // now include the declaration of wxDC class
792 // ----------------------------------------------------------------------------
793
794 #if defined(__WXPALMOS__)
795 #include "wx/palmos/dc.h"
796 #elif defined(__WXMSW__)
797 #include "wx/msw/dc.h"
798 #elif defined(__WXMOTIF__)
799 #include "wx/motif/dc.h"
800 #elif defined(__WXGTK__)
801 #include "wx/gtk/dc.h"
802 #elif defined(__WXX11__)
803 #include "wx/x11/dc.h"
804 #elif defined(__WXMGL__)
805 #include "wx/mgl/dc.h"
806 #elif defined(__WXMAC__)
807 #include "wx/mac/dc.h"
808 #elif defined(__WXCOCOA__)
809 #include "wx/cocoa/dc.h"
810 #elif defined(__WXPM__)
811 #include "wx/os2/dc.h"
812 #endif
813
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
819 class WXDLLEXPORT wxDCTextColourChanger
820 {
821 public:
822 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
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
837 private:
838 wxDC& m_dc;
839
840 wxColour m_colFgOld;
841
842 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger)
843 };
844
845 // ----------------------------------------------------------------------------
846 // another small helper class: sets the clipping region in its ctor and
847 // destroys it in the dtor
848 // ----------------------------------------------------------------------------
849
850 class WXDLLEXPORT wxDCClipper
851 {
852 public:
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
860 private:
861 wxDC& m_dc;
862
863 DECLARE_NO_COPY_CLASS(wxDCClipper)
864 };
865
866 #endif
867 // _WX_DC_H_BASE_