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