]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dc.h
Support for G_FILENAME_ENCODING=@locale
[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 // Reserved for future use
635 virtual void ReservedDCFunc1() {}
636 virtual void ReservedDCFunc2() {}
637 virtual void ReservedDCFunc3() {}
638 virtual void ReservedDCFunc4() {}
639 virtual void ReservedDCFunc5() {}
640 virtual void ReservedDCFunc6() {}
641 virtual void ReservedDCFunc7() {}
642 virtual void ReservedDCFunc8() {}
643 virtual void ReservedDCFunc9() {}
644
645 protected:
646 // the pure virtual functions which should be implemented by wxDC
647 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
648 int style = wxFLOOD_SURFACE) = 0;
649
650 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
651
652 virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
653 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
654
655 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
656 wxCoord x2, wxCoord y2,
657 wxCoord xc, wxCoord yc) = 0;
658 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
659 wxCoord width, wxCoord height);
660 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
661 double sa, double ea) = 0;
662
663 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0;
664 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
665 wxCoord width, wxCoord height,
666 double radius) = 0;
667 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
668 wxCoord width, wxCoord height) = 0;
669
670 virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
671
672 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
673 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
674 bool useMask = false) = 0;
675
676 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
677 virtual void DoDrawRotatedText(const wxString& text,
678 wxCoord x, wxCoord y, double angle) = 0;
679
680 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
681 wxCoord width, wxCoord height,
682 wxDC *source, wxCoord xsrc, wxCoord ysrc,
683 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord) = 0;
684
685 virtual void DoGetSize(int *width, int *height) const = 0;
686 virtual void DoGetSizeMM(int* width, int* height) const = 0;
687
688 virtual void DoDrawLines(int n, wxPoint points[],
689 wxCoord xoffset, wxCoord yoffset) = 0;
690 virtual void DoDrawPolygon(int n, wxPoint points[],
691 wxCoord xoffset, wxCoord yoffset,
692 int fillStyle = wxODDEVEN_RULE) = 0;
693 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
694 wxCoord xoffset, wxCoord yoffset,
695 int fillStyle);
696
697 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
698 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
699 wxCoord width, wxCoord height) = 0;
700
701 #if WXWIN_COMPATIBILITY_2_4
702 // this was only for confusing people, use DoGetClippingBox only
703 virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y,
704 wxCoord *w, wxCoord *h)
705 { DoGetClippingBox(x, y, w, h); }
706 #endif
707
708 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
709 wxCoord *w, wxCoord *h) const
710 {
711 if ( x )
712 *x = m_clipX1;
713 if ( y )
714 *y = m_clipY1;
715 if ( w )
716 *w = m_clipX2 - m_clipX1;
717 if ( h )
718 *h = m_clipY2 - m_clipY1;
719 }
720
721 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
722 {
723 if ( x ) *x = m_logicalOriginX;
724 if ( y ) *y = m_logicalOriginY;
725 }
726
727 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
728 {
729 if ( x ) *x = m_deviceOriginX;
730 if ( y ) *y = m_deviceOriginY;
731 }
732
733 virtual void DoGetTextExtent(const wxString& string,
734 wxCoord *x, wxCoord *y,
735 wxCoord *descent = NULL,
736 wxCoord *externalLeading = NULL,
737 wxFont *theFont = NULL) const = 0;
738
739 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
740
741 #if wxUSE_SPLINES
742 virtual void DoDrawSpline(wxList *points);
743 #endif
744
745 protected:
746 // unset clipping variables (after clipping region was destroyed)
747 void ResetClipping()
748 {
749 m_clipping = false;
750
751 m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0;
752 }
753
754 // flags
755 bool m_colour:1;
756 bool m_ok:1;
757 bool m_clipping:1;
758 bool m_isInteractive:1;
759 bool m_isBBoxValid:1;
760
761 // coordinate system variables
762
763 // TODO short descriptions of what exactly they are would be nice...
764
765 wxCoord m_logicalOriginX, m_logicalOriginY;
766 wxCoord m_deviceOriginX, m_deviceOriginY;
767
768 double m_logicalScaleX, m_logicalScaleY;
769 double m_userScaleX, m_userScaleY;
770 double m_scaleX, m_scaleY;
771
772 // Used by SetAxisOrientation() to invert the axes
773 int m_signX, m_signY;
774
775 // bounding and clipping boxes
776 wxCoord m_minX, m_minY, m_maxX, m_maxY;
777 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
778
779 int m_logicalFunction;
780 int m_backgroundMode;
781 int m_mappingMode;
782
783 // GDI objects
784 wxPen m_pen;
785 wxBrush m_brush;
786 wxBrush m_backgroundBrush;
787 wxColour m_textForegroundColour;
788 wxColour m_textBackgroundColour;
789 wxFont m_font;
790
791 #if wxUSE_PALETTE
792 wxPalette m_palette;
793 bool m_hasCustomPalette;
794 #endif // wxUSE_PALETTE
795
796 private:
797 DECLARE_NO_COPY_CLASS(wxDCBase)
798 DECLARE_ABSTRACT_CLASS(wxDCBase)
799 };
800
801 // ----------------------------------------------------------------------------
802 // now include the declaration of wxDC class
803 // ----------------------------------------------------------------------------
804
805 #if defined(__WXPALMOS__)
806 #include "wx/palmos/dc.h"
807 #elif defined(__WXMSW__)
808 #include "wx/msw/dc.h"
809 #elif defined(__WXMOTIF__)
810 #include "wx/motif/dc.h"
811 #elif defined(__WXGTK__)
812 #include "wx/gtk/dc.h"
813 #elif defined(__WXX11__)
814 #include "wx/x11/dc.h"
815 #elif defined(__WXMGL__)
816 #include "wx/mgl/dc.h"
817 #elif defined(__WXMAC__)
818 #include "wx/mac/dc.h"
819 #elif defined(__WXCOCOA__)
820 #include "wx/cocoa/dc.h"
821 #elif defined(__WXPM__)
822 #include "wx/os2/dc.h"
823 #endif
824
825 // ----------------------------------------------------------------------------
826 // helper class: you can use it to temporarily change the DC text colour and
827 // restore it automatically when the object goes out of scope
828 // ----------------------------------------------------------------------------
829
830 class WXDLLEXPORT wxDCTextColourChanger
831 {
832 public:
833 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
834
835 ~wxDCTextColourChanger()
836 {
837 if ( m_colFgOld.Ok() )
838 m_dc.SetTextForeground(m_colFgOld);
839 }
840
841 void Set(const wxColour& col)
842 {
843 if ( !m_colFgOld.Ok() )
844 m_colFgOld = m_dc.GetTextForeground();
845 m_dc.SetTextForeground(col);
846 }
847
848 private:
849 wxDC& m_dc;
850
851 wxColour m_colFgOld;
852
853 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger)
854 };
855
856 // ----------------------------------------------------------------------------
857 // another small helper class: sets the clipping region in its ctor and
858 // destroys it in the dtor
859 // ----------------------------------------------------------------------------
860
861 class WXDLLEXPORT wxDCClipper
862 {
863 public:
864 wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc)
865 { dc.SetClippingRegion(r.x, r.y, r.width, r.height); }
866 wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc)
867 { dc.SetClippingRegion(x, y, w, h); }
868
869 ~wxDCClipper() { m_dc.DestroyClippingRegion(); }
870
871 private:
872 wxDC& m_dc;
873
874 DECLARE_NO_COPY_CLASS(wxDCClipper)
875 };
876
877 #endif
878 // _WX_DC_H_BASE_