Moved deprecated code to source file (didn't compile
[wxWidgets.git] / include / wx / dc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/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 // ----------------------------------------------------------------------------
16 // headers which we must include here
17 // ----------------------------------------------------------------------------
18
19 #include "wx/object.h" // the base class
20
21 #include "wx/intl.h" // for wxLayoutDirection
22 #include "wx/cursor.h" // we have member variables of these classes
23 #include "wx/font.h" // so we can't do without them
24 #include "wx/colour.h"
25 #include "wx/bitmap.h" // for wxNullBitmap
26 #include "wx/brush.h"
27 #include "wx/pen.h"
28 #include "wx/palette.h"
29 #include "wx/list.h" // we use wxList in inline functions
30 #include "wx/dynarray.h"
31 #include "wx/math.h"
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 // ---------------------------------------------------------------------------
98 // wxDC is the device context - object on which any drawing is done
99 // ---------------------------------------------------------------------------
100
101 class WXDLLEXPORT wxDCBase : public wxObject
102 {
103 public:
104 wxDCBase();
105 virtual ~wxDCBase();
106
107 // graphic primitives
108 // ------------------
109
110 virtual void DrawObject(wxDrawObject* drawobject)
111 {
112 drawobject->Draw(*this);
113 CalcBoundingBox(drawobject->MinX(),drawobject->MinY());
114 CalcBoundingBox(drawobject->MaxX(),drawobject->MaxY());
115 }
116
117 bool FloodFill(wxCoord x, wxCoord y, const wxColour& col,
118 int style = wxFLOOD_SURFACE)
119 { return DoFloodFill(x, y, col, style); }
120 bool FloodFill(const wxPoint& pt, const wxColour& col,
121 int style = wxFLOOD_SURFACE)
122 { return DoFloodFill(pt.x, pt.y, col, style); }
123
124 // fill the area specified by rect with a radial gradient, starting from
125 // initialColour in the centre of the cercle and fading to destColour.
126 void GradientFillConcentric(const wxRect& rect,
127 const wxColour& initialColour,
128 const wxColour& destColour)
129 { GradientFillConcentric(rect, initialColour, destColour,
130 wxPoint(rect.GetWidth() / 2,
131 rect.GetHeight() / 2)); }
132
133 void GradientFillConcentric(const wxRect& rect,
134 const wxColour& initialColour,
135 const wxColour& destColour,
136 const wxPoint& circleCenter)
137 { DoGradientFillConcentric(rect, initialColour, destColour, circleCenter); }
138
139 // fill the area specified by rect with a linear gradient
140 void GradientFillLinear(const wxRect& rect,
141 const wxColour& initialColour,
142 const wxColour& destColour,
143 wxDirection nDirection = wxEAST)
144 { DoGradientFillLinear(rect, initialColour, destColour, nDirection); }
145
146 bool GetPixel(wxCoord x, wxCoord y, wxColour *col) const
147 { return DoGetPixel(x, y, col); }
148 bool GetPixel(const wxPoint& pt, wxColour *col) const
149 { return DoGetPixel(pt.x, pt.y, col); }
150
151 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
152 { DoDrawLine(x1, y1, x2, y2); }
153 void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
154 { DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
155
156 void CrossHair(wxCoord x, wxCoord y)
157 { DoCrossHair(x, y); }
158 void CrossHair(const wxPoint& pt)
159 { DoCrossHair(pt.x, pt.y); }
160
161 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
162 wxCoord xc, wxCoord yc)
163 { DoDrawArc(x1, y1, x2, y2, xc, yc); }
164 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
165 { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
166
167 void DrawCheckMark(wxCoord x, wxCoord y,
168 wxCoord width, wxCoord height)
169 { DoDrawCheckMark(x, y, width, height); }
170 void DrawCheckMark(const wxRect& rect)
171 { DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
172
173 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
174 double sa, double ea)
175 { DoDrawEllipticArc(x, y, w, h, sa, ea); }
176 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
177 double sa, double ea)
178 { DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
179
180 void DrawPoint(wxCoord x, wxCoord y)
181 { DoDrawPoint(x, y); }
182 void DrawPoint(const wxPoint& pt)
183 { DoDrawPoint(pt.x, pt.y); }
184
185 void DrawLines(int n, wxPoint points[],
186 wxCoord xoffset = 0, wxCoord yoffset = 0)
187 { DoDrawLines(n, points, xoffset, yoffset); }
188 void DrawLines(const wxList *list,
189 wxCoord xoffset = 0, wxCoord yoffset = 0);
190
191 void DrawPolygon(int n, wxPoint points[],
192 wxCoord xoffset = 0, wxCoord yoffset = 0,
193 int fillStyle = wxODDEVEN_RULE)
194 { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
195
196 void DrawPolygon(const wxList *list,
197 wxCoord xoffset = 0, wxCoord yoffset = 0,
198 int fillStyle = wxODDEVEN_RULE);
199
200 void DrawPolyPolygon(int n, int count[], wxPoint points[],
201 wxCoord xoffset = 0, wxCoord yoffset = 0,
202 int fillStyle = wxODDEVEN_RULE)
203 { DoDrawPolyPolygon(n, count, points, xoffset, yoffset, fillStyle); }
204
205 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
206 { DoDrawRectangle(x, y, width, height); }
207 void DrawRectangle(const wxPoint& pt, const wxSize& sz)
208 { DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); }
209 void DrawRectangle(const wxRect& rect)
210 { DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); }
211
212 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
213 double radius)
214 { DoDrawRoundedRectangle(x, y, width, height, radius); }
215 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
216 double radius)
217 { DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
218 void DrawRoundedRectangle(const wxRect& r, double radius)
219 { DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
220
221 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
222 { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
223 void DrawCircle(const wxPoint& pt, wxCoord radius)
224 { DrawCircle(pt.x, pt.y, radius); }
225
226 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
227 { DoDrawEllipse(x, y, width, height); }
228 void DrawEllipse(const wxPoint& pt, const wxSize& sz)
229 { DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); }
230 void DrawEllipse(const wxRect& rect)
231 { DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); }
232
233 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
234 { DoDrawIcon(icon, x, y); }
235 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
236 { DoDrawIcon(icon, pt.x, pt.y); }
237
238 void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
239 bool useMask = false)
240 { DoDrawBitmap(bmp, x, y, useMask); }
241 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
242 bool useMask = false)
243 { DoDrawBitmap(bmp, pt.x, pt.y, useMask); }
244
245 void DrawText(const wxString& text, wxCoord x, wxCoord y)
246 { DoDrawText(text, x, y); }
247 void DrawText(const wxString& text, const wxPoint& pt)
248 { DoDrawText(text, pt.x, pt.y); }
249
250 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
251 { DoDrawRotatedText(text, x, y, angle); }
252 void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)
253 { DoDrawRotatedText(text, pt.x, pt.y, angle); }
254
255 // this version puts both optional bitmap and the text into the given
256 // rectangle and aligns is as specified by alignment parameter; it also
257 // will emphasize the character with the given index if it is != -1 and
258 // return the bounding rectangle if required
259 virtual void DrawLabel(const wxString& text,
260 const wxBitmap& image,
261 const wxRect& rect,
262 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
263 int indexAccel = -1,
264 wxRect *rectBounding = NULL);
265
266 void DrawLabel(const wxString& text, const wxRect& rect,
267 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
268 int indexAccel = -1)
269 { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); }
270
271 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
272 wxDC *source, wxCoord xsrc, wxCoord ysrc,
273 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
274 {
275 return DoBlit(xdest, ydest, width, height,
276 source, xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
277 }
278 bool Blit(const wxPoint& destPt, const wxSize& sz,
279 wxDC *source, const wxPoint& srcPt,
280 int rop = wxCOPY, bool useMask = false, const wxPoint& srcPtMask = wxDefaultPosition)
281 {
282 return DoBlit(destPt.x, destPt.y, sz.x, sz.y,
283 source, srcPt.x, srcPt.y, rop, useMask, srcPtMask.x, srcPtMask.y);
284 }
285
286 bool StretchBlit(wxCoord dstX, wxCoord dstY,
287 wxCoord dstWidth, wxCoord dstHeight,
288 wxDC *source,
289 wxCoord srcX, wxCoord srcY,
290 wxCoord srcWidth, wxCoord srcHeight,
291 int rop = wxCOPY, bool useMask = false,
292 wxCoord srcMaskX = wxDefaultCoord, wxCoord srcMaskY = wxDefaultCoord)
293 {
294 return DoStretchBlit(dstX, dstY, dstWidth, dstHeight,
295 source, srcX, srcY, srcWidth, srcHeight, rop, useMask, srcMaskX, srcMaskY);
296 }
297 bool StretchBlit(const wxPoint& dstPt, const wxSize& dstSize,
298 wxDC *source, const wxPoint& srcPt, const wxSize& srcSize,
299 int rop = wxCOPY, bool useMask = false, const wxPoint& srcMaskPt = wxDefaultPosition)
300 {
301 return DoStretchBlit(dstPt.x, dstPt.y, dstSize.x, dstSize.y,
302 source, srcPt.x, srcPt.y, srcSize.x, srcSize.y, rop, useMask, srcMaskPt.x, srcMaskPt.y);
303 }
304
305 wxBitmap GetAsBitmap(const wxRect *subrect = (const wxRect *) NULL) const
306 {
307 return DoGetAsBitmap(subrect);
308 }
309
310 #if wxUSE_SPLINES
311 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
312 void DrawSpline(wxCoord x1, wxCoord y1,
313 wxCoord x2, wxCoord y2,
314 wxCoord x3, wxCoord y3);
315 void DrawSpline(int n, wxPoint points[]);
316
317 void DrawSpline(wxList *points) { DoDrawSpline(points); }
318 #endif // wxUSE_SPLINES
319
320 // Eventually we will have wxUSE_GENERIC_DRAWELLIPSE
321 #ifdef __WXWINCE__
322 //! Generic method to draw ellipses, circles and arcs with current pen and brush.
323 /*! \param x Upper left corner of bounding box.
324 * \param y Upper left corner of bounding box.
325 * \param w Width of bounding box.
326 * \param h Height of bounding box.
327 * \param sa Starting angle of arc
328 * (counterclockwise, start at 3 o'clock, 360 is full circle).
329 * \param ea Ending angle of arc.
330 * \param angle Rotation angle, the Arc will be rotated after
331 * calculating begin and end.
332 */
333 void DrawEllipticArcRot( wxCoord x, wxCoord y,
334 wxCoord width, wxCoord height,
335 double sa = 0, double ea = 0, double angle = 0 )
336 { DoDrawEllipticArcRot( x, y, width, height, sa, ea, angle ); }
337
338 void DrawEllipticArcRot( const wxPoint& pt,
339 const wxSize& sz,
340 double sa = 0, double ea = 0, double angle = 0 )
341 { DoDrawEllipticArcRot( pt.x, pt.y, sz.x, sz.y, sa, ea, angle ); }
342
343 void DrawEllipticArcRot( const wxRect& rect,
344 double sa = 0, double ea = 0, double angle = 0 )
345 { DoDrawEllipticArcRot( rect.x, rect.y, rect.width, rect.height, sa, ea, angle ); }
346
347 virtual void DoDrawEllipticArcRot( wxCoord x, wxCoord y,
348 wxCoord w, wxCoord h,
349 double sa = 0, double ea = 0, double angle = 0 );
350
351 //! Rotates points around center.
352 /*! This is a quite straight method, it calculates in pixels
353 * and so it produces rounding errors.
354 * \param points The points inside will be rotated.
355 * \param angle Rotating angle (counterclockwise, start at 3 o'clock, 360 is full circle).
356 * \param center Center of rotation.
357 */
358 void Rotate( wxList* points, double angle, wxPoint center = wxPoint(0,0) );
359
360 // used by DrawEllipticArcRot
361 // Careful: wxList gets filled with points you have to delete later.
362 void CalculateEllipticPoints( wxList* points,
363 wxCoord xStart, wxCoord yStart,
364 wxCoord w, wxCoord h,
365 double sa, double ea );
366 #endif
367
368 // global DC operations
369 // --------------------
370
371 virtual void Clear() = 0;
372
373 virtual bool StartDoc(const wxString& WXUNUSED(message)) { return true; }
374 virtual void EndDoc() { }
375
376 virtual void StartPage() { }
377 virtual void EndPage() { }
378
379 #if WXWIN_COMPATIBILITY_2_6
380 wxDEPRECATED( void BeginDrawing() );
381 wxDEPRECATED( void EndDrawing() );
382 #endif // WXWIN_COMPATIBILITY_2_6
383
384
385 // set objects to use for drawing
386 // ------------------------------
387
388 virtual void SetFont(const wxFont& font) = 0;
389 virtual void SetPen(const wxPen& pen) = 0;
390 virtual void SetBrush(const wxBrush& brush) = 0;
391 virtual void SetBackground(const wxBrush& brush) = 0;
392 virtual void SetBackgroundMode(int mode) = 0;
393 #if wxUSE_PALETTE
394 virtual void SetPalette(const wxPalette& palette) = 0;
395 #endif // wxUSE_PALETTE
396
397 // clipping region
398 // ---------------
399
400 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
401 { DoSetClippingRegion(x, y, width, height); }
402 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
403 { DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); }
404 void SetClippingRegion(const wxRect& rect)
405 { DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
406 void SetClippingRegion(const wxRegion& region)
407 { DoSetClippingRegionAsRegion(region); }
408
409 virtual void DestroyClippingRegion() { ResetClipping(); }
410
411 void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *w, wxCoord *h) const
412 { DoGetClippingBox(x, y, w, h); }
413 void GetClippingBox(wxRect& rect) const
414 {
415 DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height);
416 }
417
418 // text extent
419 // -----------
420
421 virtual wxCoord GetCharHeight() const = 0;
422 virtual wxCoord GetCharWidth() const = 0;
423
424 // only works for single line strings
425 void GetTextExtent(const wxString& string,
426 wxCoord *x, wxCoord *y,
427 wxCoord *descent = NULL,
428 wxCoord *externalLeading = NULL,
429 const wxFont *theFont = NULL) const
430 { DoGetTextExtent(string, x, y, descent, externalLeading, theFont); }
431
432 wxSize GetTextExtent(const wxString& string) const
433 {
434 wxCoord w, h;
435 DoGetTextExtent(string, &w, &h);
436 return wxSize(w, h);
437 }
438
439 // works for single as well as multi-line strings
440 virtual void GetMultiLineTextExtent(const wxString& string,
441 wxCoord *width,
442 wxCoord *height,
443 wxCoord *heightLine = NULL,
444 const wxFont *font = NULL) const;
445
446 wxSize GetMultiLineTextExtent(const wxString& string) const
447 {
448 wxCoord w, h;
449 GetMultiLineTextExtent(string, &w, &h);
450 return wxSize(w, h);
451 }
452
453 // Measure cumulative width of text after each character
454 bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
455 { return DoGetPartialTextExtents(text, widths); }
456
457
458 // size and resolution
459 // -------------------
460
461 // in device units
462 void GetSize(int *width, int *height) const
463 { DoGetSize(width, height); }
464 wxSize GetSize() const
465 {
466 int w, h;
467 DoGetSize(&w, &h);
468
469 return wxSize(w, h);
470 }
471
472 // in mm
473 void GetSizeMM(int* width, int* height) const
474 { DoGetSizeMM(width, height); }
475 wxSize GetSizeMM() const
476 {
477 int w, h;
478 DoGetSizeMM(&w, &h);
479
480 return wxSize(w, h);
481 }
482
483 // query DC capabilities
484 // ---------------------
485
486 virtual bool CanDrawBitmap() const = 0;
487 virtual bool CanGetTextExtent() const = 0;
488
489 // colour depth
490 virtual int GetDepth() const = 0;
491
492 // Resolution in Pixels per inch
493 virtual wxSize GetPPI() const = 0;
494
495 virtual bool Ok() const { return IsOk(); }
496 virtual bool IsOk() const { return m_ok; }
497
498 // accessors and setters
499 // ---------------------
500
501 virtual int GetBackgroundMode() const { return m_backgroundMode; }
502 virtual const wxBrush& GetBackground() const { return m_backgroundBrush; }
503 virtual const wxBrush& GetBrush() const { return m_brush; }
504 virtual const wxFont& GetFont() const { return m_font; }
505 virtual const wxPen& GetPen() const { return m_pen; }
506
507 virtual const wxColour& GetTextForeground() const { return m_textForegroundColour; }
508 virtual const wxColour& GetTextBackground() const { return m_textBackgroundColour; }
509 virtual void SetTextForeground(const wxColour& colour)
510 { m_textForegroundColour = colour; }
511 virtual void SetTextBackground(const wxColour& colour)
512 { m_textBackgroundColour = colour; }
513
514
515 // coordinates conversions and transforms
516 // --------------------------------------
517
518 virtual wxCoord DeviceToLogicalX(wxCoord x) const;
519 virtual wxCoord DeviceToLogicalY(wxCoord y) const;
520 virtual wxCoord DeviceToLogicalXRel(wxCoord x) const;
521 virtual wxCoord DeviceToLogicalYRel(wxCoord y) const;
522 virtual wxCoord LogicalToDeviceX(wxCoord x) const;
523 virtual wxCoord LogicalToDeviceY(wxCoord y) const;
524 virtual wxCoord LogicalToDeviceXRel(wxCoord x) const;
525 virtual wxCoord LogicalToDeviceYRel(wxCoord y) const;
526
527 virtual void SetMapMode(int mode);
528 virtual int GetMapMode() const { return m_mappingMode; }
529
530 virtual void SetUserScale(double x, double y);
531 virtual void GetUserScale(double *x, double *y) const
532 {
533 if ( x ) *x = m_userScaleX;
534 if ( y ) *y = m_userScaleY;
535 }
536
537 virtual void SetLogicalScale(double x, double y);
538 virtual void GetLogicalScale(double *x, double *y)
539 {
540 if ( x ) *x = m_logicalScaleX;
541 if ( y ) *y = m_logicalScaleY;
542 }
543
544 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
545 void GetLogicalOrigin(wxCoord *x, wxCoord *y) const
546 { DoGetLogicalOrigin(x, y); }
547 wxPoint GetLogicalOrigin() const
548 { wxCoord x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
549
550 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
551 void GetDeviceOrigin(wxCoord *x, wxCoord *y) const
552 { DoGetDeviceOrigin(x, y); }
553 wxPoint GetDeviceOrigin() const
554 { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
555
556 virtual void SetDeviceLocalOrigin( wxCoord x, wxCoord y );
557
558 virtual void ComputeScaleAndOrigin();
559
560 // this needs to overidden if the axis is inverted (such
561 // as when using Postscript, where 0,0 is the lower left
562 // corner, not the upper left).
563 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
564
565 // logical functions
566 // ---------------------------
567
568 virtual int GetLogicalFunction() const { return m_logicalFunction; }
569 virtual void SetLogicalFunction(int function) = 0;
570
571 // bounding box
572 // ------------
573
574 virtual void CalcBoundingBox(wxCoord x, wxCoord y)
575 {
576 if ( m_isBBoxValid )
577 {
578 if ( x < m_minX ) m_minX = x;
579 if ( y < m_minY ) m_minY = y;
580 if ( x > m_maxX ) m_maxX = x;
581 if ( y > m_maxY ) m_maxY = y;
582 }
583 else
584 {
585 m_isBBoxValid = true;
586
587 m_minX = x;
588 m_minY = y;
589 m_maxX = x;
590 m_maxY = y;
591 }
592 }
593
594 void ResetBoundingBox()
595 {
596 m_isBBoxValid = false;
597
598 m_minX = m_maxX = m_minY = m_maxY = 0;
599 }
600
601 // Get the final bounding box of the PostScript or Metafile picture.
602 wxCoord MinX() const { return m_minX; }
603 wxCoord MaxX() const { return m_maxX; }
604 wxCoord MinY() const { return m_minY; }
605 wxCoord MaxY() const { return m_maxY; }
606
607 // misc old functions
608 // ------------------
609
610 #if WXWIN_COMPATIBILITY_2_8
611 // for compatibility with the old code when wxCoord was long everywhere
612 wxDEPRECATED( void GetTextExtent(const wxString& string,
613 long *x, long *y,
614 long *descent = NULL,
615 long *externalLeading = NULL,
616 const wxFont *theFont = NULL) const );
617 wxDEPRECATED( void GetLogicalOrigin(long *x, long *y) const );
618 wxDEPRECATED( void GetDeviceOrigin(long *x, long *y) const );
619 wxDEPRECATED( void GetClippingBox(long *x, long *y, long *w, long *h) const );
620 #endif // WXWIN_COMPATIBILITY_2_8
621
622 // RTL related functions
623 // ---------------------
624
625 // get or change the layout direction (LTR or RTL) for this dc,
626 // wxLayout_Default is returned if layout direction is not supported
627 virtual wxLayoutDirection GetLayoutDirection() const
628 { return wxLayout_Default; }
629 virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir))
630 { }
631
632 protected:
633 // the pure virtual functions which should be implemented by wxDC
634 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
635 int style = wxFLOOD_SURFACE) = 0;
636
637 virtual void DoGradientFillLinear(const wxRect& rect,
638 const wxColour& initialColour,
639 const wxColour& destColour,
640 wxDirection nDirection = wxEAST);
641
642 virtual void DoGradientFillConcentric(const wxRect& rect,
643 const wxColour& initialColour,
644 const wxColour& destColour,
645 const wxPoint& circleCenter);
646
647 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const = 0;
648
649 virtual void DoDrawPoint(wxCoord x, wxCoord y) = 0;
650 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) = 0;
651
652 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
653 wxCoord x2, wxCoord y2,
654 wxCoord xc, wxCoord yc) = 0;
655 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
656 wxCoord width, wxCoord height);
657 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
658 double sa, double ea) = 0;
659
660 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) = 0;
661 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
662 wxCoord width, wxCoord height,
663 double radius) = 0;
664 virtual void DoDrawEllipse(wxCoord x, wxCoord y,
665 wxCoord width, wxCoord height) = 0;
666
667 virtual void DoCrossHair(wxCoord x, wxCoord y) = 0;
668
669 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) = 0;
670 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
671 bool useMask = false) = 0;
672
673 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y) = 0;
674 virtual void DoDrawRotatedText(const wxString& text,
675 wxCoord x, wxCoord y, double angle) = 0;
676
677 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
678 wxCoord width, wxCoord height,
679 wxDC *source,
680 wxCoord xsrc, wxCoord ysrc,
681 int rop = wxCOPY,
682 bool useMask = false,
683 wxCoord xsrcMask = wxDefaultCoord,
684 wxCoord ysrcMask = wxDefaultCoord) = 0;
685
686 virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
687 wxCoord dstWidth, wxCoord dstHeight,
688 wxDC *source,
689 wxCoord xsrc, wxCoord ysrc,
690 wxCoord srcWidth, wxCoord srcHeight,
691 int rop = wxCOPY,
692 bool useMask = false,
693 wxCoord xsrcMask = wxDefaultCoord,
694 wxCoord ysrcMask = wxDefaultCoord);
695
696 virtual wxBitmap DoGetAsBitmap(const wxRect *WXUNUSED(subrect)) const
697 { return wxNullBitmap; }
698
699 virtual void DoGetSize(int *width, int *height) const = 0;
700 virtual void DoGetSizeMM(int* width, int* height) const = 0;
701
702 virtual void DoDrawLines(int n, wxPoint points[],
703 wxCoord xoffset, wxCoord yoffset) = 0;
704 virtual void DoDrawPolygon(int n, wxPoint points[],
705 wxCoord xoffset, wxCoord yoffset,
706 int fillStyle = wxODDEVEN_RULE) = 0;
707 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
708 wxCoord xoffset, wxCoord yoffset,
709 int fillStyle);
710
711 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
712 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
713 wxCoord width, wxCoord height) = 0;
714
715 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
716 wxCoord *w, wxCoord *h) const
717 {
718 if ( x )
719 *x = m_clipX1;
720 if ( y )
721 *y = m_clipY1;
722 if ( w )
723 *w = m_clipX2 - m_clipX1;
724 if ( h )
725 *h = m_clipY2 - m_clipY1;
726 }
727
728 virtual void DoGetLogicalOrigin(wxCoord *x, wxCoord *y) const
729 {
730 if ( x ) *x = m_logicalOriginX;
731 if ( y ) *y = m_logicalOriginY;
732 }
733
734 virtual void DoGetDeviceOrigin(wxCoord *x, wxCoord *y) const
735 {
736 if ( x ) *x = m_deviceOriginX;
737 if ( y ) *y = m_deviceOriginY;
738 }
739
740 virtual void DoGetTextExtent(const wxString& string,
741 wxCoord *x, wxCoord *y,
742 wxCoord *descent = NULL,
743 wxCoord *externalLeading = NULL,
744 const wxFont *theFont = NULL) const = 0;
745
746 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
747
748 #if wxUSE_SPLINES
749 virtual void DoDrawSpline(wxList *points);
750 #endif
751
752 protected:
753 // unset clipping variables (after clipping region was destroyed)
754 void ResetClipping()
755 {
756 m_clipping = false;
757
758 m_clipX1 = m_clipX2 = m_clipY1 = m_clipY2 = 0;
759 }
760
761 // flags
762 bool m_colour:1;
763 bool m_ok:1;
764 bool m_clipping:1;
765 bool m_isInteractive:1;
766 bool m_isBBoxValid:1;
767
768 // coordinate system variables
769
770 // TODO short descriptions of what exactly they are would be nice...
771
772 wxCoord m_logicalOriginX, m_logicalOriginY;
773 wxCoord m_deviceOriginX, m_deviceOriginY; // Usually 0,0, can be change by user
774
775 wxCoord m_deviceLocalOriginX, m_deviceLocalOriginY; // non-zero if native top-left corner
776 // is not at 0,0. This was the case under
777 // Mac's GrafPorts (coordinate system
778 // used toplevel window's origin) and
779 // e.g. for Postscript, where the native
780 // origin in the bottom left corner.
781 double m_logicalScaleX, m_logicalScaleY;
782 double m_userScaleX, m_userScaleY;
783 double m_scaleX, m_scaleY; // calculated from logical scale and user scale
784
785 // Used by SetAxisOrientation() to invert the axes
786 int m_signX, m_signY;
787
788 // what is a mm on a screen you don't know the size of?
789 double m_mm_to_pix_x,
790 m_mm_to_pix_y;
791
792 // bounding and clipping boxes
793 wxCoord m_minX, m_minY, m_maxX, m_maxY;
794 wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2;
795
796 int m_logicalFunction;
797 int m_backgroundMode;
798 int m_mappingMode;
799
800 // GDI objects
801 wxPen m_pen;
802 wxBrush m_brush;
803 wxBrush m_backgroundBrush;
804 wxColour m_textForegroundColour;
805 wxColour m_textBackgroundColour;
806 wxFont m_font;
807
808 #if wxUSE_PALETTE
809 wxPalette m_palette;
810 bool m_hasCustomPalette;
811 #endif // wxUSE_PALETTE
812
813 private:
814 DECLARE_NO_COPY_CLASS(wxDCBase)
815 DECLARE_ABSTRACT_CLASS(wxDCBase)
816 };
817
818 // ----------------------------------------------------------------------------
819 // now include the declaration of wxDC class
820 // ----------------------------------------------------------------------------
821
822 #if defined(__WXPALMOS__)
823 #include "wx/palmos/dc.h"
824 #elif defined(__WXMSW__)
825 #include "wx/msw/dc.h"
826 #elif defined(__WXMOTIF__)
827 #include "wx/motif/dc.h"
828 #elif defined(__WXGTK20__)
829 #include "wx/gtk/dc.h"
830 #elif defined(__WXGTK__)
831 #include "wx/gtk1/dc.h"
832 #elif defined(__WXX11__)
833 #include "wx/x11/dc.h"
834 #elif defined(__WXMGL__)
835 #include "wx/mgl/dc.h"
836 #elif defined(__WXDFB__)
837 #include "wx/dfb/dc.h"
838 #elif defined(__WXMAC__)
839 #include "wx/mac/dc.h"
840 #elif defined(__WXCOCOA__)
841 #include "wx/cocoa/dc.h"
842 #elif defined(__WXPM__)
843 #include "wx/os2/dc.h"
844 #endif
845
846 #if wxUSE_GRAPHICS_CONTEXT
847 #include "wx/dcgraph.h"
848 #endif
849
850 // ----------------------------------------------------------------------------
851 // helper class: you can use it to temporarily change the DC text colour and
852 // restore it automatically when the object goes out of scope
853 // ----------------------------------------------------------------------------
854
855 class WXDLLEXPORT wxDCTextColourChanger
856 {
857 public:
858 wxDCTextColourChanger(wxDC& dc) : m_dc(dc), m_colFgOld() { }
859
860 wxDCTextColourChanger(wxDC& dc, const wxColour& col) : m_dc(dc)
861 {
862 Set(col);
863 }
864
865 ~wxDCTextColourChanger()
866 {
867 if ( m_colFgOld.Ok() )
868 m_dc.SetTextForeground(m_colFgOld);
869 }
870
871 void Set(const wxColour& col)
872 {
873 if ( !m_colFgOld.Ok() )
874 m_colFgOld = m_dc.GetTextForeground();
875 m_dc.SetTextForeground(col);
876 }
877
878 private:
879 wxDC& m_dc;
880
881 wxColour m_colFgOld;
882
883 DECLARE_NO_COPY_CLASS(wxDCTextColourChanger)
884 };
885
886 // ----------------------------------------------------------------------------
887 // helper class: you can use it to temporarily change the DC pen and
888 // restore it automatically when the object goes out of scope
889 // ----------------------------------------------------------------------------
890
891 class WXDLLEXPORT wxDCPenChanger
892 {
893 public:
894 wxDCPenChanger(wxDC& dc, const wxPen& pen) : m_dc(dc), m_penOld(dc.GetPen())
895 {
896 m_dc.SetPen(pen);
897 }
898
899 ~wxDCPenChanger()
900 {
901 if ( m_penOld.Ok() )
902 m_dc.SetPen(m_penOld);
903 }
904
905 private:
906 wxDC& m_dc;
907
908 wxPen m_penOld;
909
910 DECLARE_NO_COPY_CLASS(wxDCPenChanger)
911 };
912
913 // ----------------------------------------------------------------------------
914 // helper class: you can use it to temporarily change the DC brush and
915 // restore it automatically when the object goes out of scope
916 // ----------------------------------------------------------------------------
917
918 class WXDLLEXPORT wxDCBrushChanger
919 {
920 public:
921 wxDCBrushChanger(wxDC& dc, const wxBrush& brush) : m_dc(dc), m_brushOld(dc.GetBrush())
922 {
923 m_dc.SetBrush(brush);
924 }
925
926 ~wxDCBrushChanger()
927 {
928 if ( m_brushOld.Ok() )
929 m_dc.SetBrush(m_brushOld);
930 }
931
932 private:
933 wxDC& m_dc;
934
935 wxBrush m_brushOld;
936
937 DECLARE_NO_COPY_CLASS(wxDCBrushChanger)
938 };
939
940 // ----------------------------------------------------------------------------
941 // another small helper class: sets the clipping region in its ctor and
942 // destroys it in the dtor
943 // ----------------------------------------------------------------------------
944
945 class WXDLLEXPORT wxDCClipper
946 {
947 public:
948 wxDCClipper(wxDC& dc, const wxRegion& r) : m_dc(dc)
949 { dc.SetClippingRegion(r); }
950 wxDCClipper(wxDC& dc, const wxRect& r) : m_dc(dc)
951 { dc.SetClippingRegion(r.x, r.y, r.width, r.height); }
952 wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h) : m_dc(dc)
953 { dc.SetClippingRegion(x, y, w, h); }
954
955 ~wxDCClipper() { m_dc.DestroyClippingRegion(); }
956
957 private:
958 wxDC& m_dc;
959
960 DECLARE_NO_COPY_CLASS(wxDCClipper)
961 };
962
963 #endif // _WX_DC_H_BASE_