5 #pragma interface "dcbase.h"
8 // ----------------------------------------------------------------------------
9 // headers which we must include here
10 // ----------------------------------------------------------------------------
12 #include "wx/object.h" // the base class
14 #include "wx/cursor.h" // we have member variables of these classes
15 #include "wx/font.h" // so we can't do without them
16 #include "wx/colour.h"
19 #include "wx/palette.h"
21 #include "wx/list.h" // we use wxList in inline functions
23 // ---------------------------------------------------------------------------
25 // ---------------------------------------------------------------------------
27 // type which should be used (whenever possible, i.e. as long as it doesn't
28 // break compatibility) for screen coordinates
31 // ---------------------------------------------------------------------------
33 // ---------------------------------------------------------------------------
35 WXDLLEXPORT_DATA(extern int) wxPageNumber
;
37 // ---------------------------------------------------------------------------
38 // wxDC is the device context - object on which any drawing is done
39 // ---------------------------------------------------------------------------
41 class WXDLLEXPORT wxDCBase
: public wxObject
43 DECLARE_ABSTRACT_CLASS(wxDCBase
)
51 m_minX
= m_minY
= m_maxX
= m_maxY
= 0;
53 m_signX
= m_signY
= 1;
55 m_logicalOriginX
= m_logicalOriginY
=
56 m_deviceOriginX
= m_deviceOriginY
= 0;
58 m_logicalScaleX
= m_logicalScaleY
=
59 m_userScaleX
= m_userScaleY
=
60 m_scaleX
= m_scaleY
= 1.0;
62 m_logicalFunction
= -1;
64 m_backgroundMode
= wxTRANSPARENT
;
66 m_mappingMode
= wxMM_TEXT
;
68 m_backgroundBrush
= *wxWHITE_BRUSH
;
70 m_textForegroundColour
= *wxBLACK
;
71 m_textBackgroundColour
= *wxWHITE
;
73 m_colour
= wxColourDisplay();
78 virtual void BeginDrawing() { }
79 virtual void EndDrawing() { }
84 void FloodFill(long x
, long y
, const wxColour
& col
,
85 int style
= wxFLOOD_SURFACE
)
86 { DoFloodFill(x
, y
, col
, style
); }
87 void FloodFill(const wxPoint
& pt
, const wxColour
& col
,
88 int style
= wxFLOOD_SURFACE
)
89 { DoFloodFill(pt
.x
, pt
.y
, col
, style
); }
91 bool GetPixel(long x
, long y
, wxColour
*col
) const
92 { return DoGetPixel(x
, y
, col
); }
93 bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
94 { return DoGetPixel(pt
.x
, pt
.y
, col
); }
96 void DrawLine(long x1
, long y1
, long x2
, long y2
)
97 { DoDrawLine(x1
, y1
, x2
, y2
); }
98 void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
99 { DoDrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
); }
101 void CrossHair(long x
, long y
)
102 { DoCrossHair(x
, y
); }
103 void CrossHair(const wxPoint
& pt
)
104 { DoCrossHair(pt
.x
, pt
.y
); }
106 void DrawArc(long x1
, long y1
, long x2
, long y2
, long xc
, long yc
)
107 { DoDrawArc(x1
, y1
, x2
, y2
, xc
, yc
); }
108 void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
109 { DoDrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
); }
111 void DrawEllipticArc(long x
, long y
, long w
, long h
, double sa
, double ea
)
112 { DoDrawEllipticArc(x
, y
, x
, y
, sa
, ea
); }
113 void DrawEllipticArc(const wxPoint
& pt
, const wxSize
& sz
,
114 double sa
, double ea
)
115 { DoDrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
); }
117 void DrawPoint(long x
, long y
)
118 { DoDrawPoint(x
, y
); }
119 void DrawPoint(const wxPoint
& pt
)
120 { DoDrawPoint(pt
.x
, pt
.y
); }
122 void DrawLines(int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0)
123 { DoDrawLines(n
, points
, xoffset
, yoffset
); }
124 void DrawLines(const wxList
*list
, long xoffset
= 0, long yoffset
= 0)
126 int n
= list
->Number();
127 wxPoint
*points
= new wxPoint
[n
];
130 for ( wxNode
*node
= list
->First(); node
; node
= node
->Next(), i
++ )
132 wxPoint
*point
= (wxPoint
*)node
->Data();
133 points
[i
].x
= point
->x
;
134 points
[i
].y
= point
->y
;
137 DoDrawLines(n
, points
, xoffset
, yoffset
);
142 void DrawPolygon(int n
, wxPoint points
[],
143 long xoffset
= 0, long yoffset
= 0,
144 int fillStyle
= wxODDEVEN_RULE
)
145 { DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
); }
147 void DrawPolygon(const wxList
*list
,
148 long xoffset
= 0, long yoffset
= 0,
149 int fillStyle
= wxODDEVEN_RULE
)
151 int n
= list
->Number();
152 wxPoint
*points
= new wxPoint
[n
];
155 for ( wxNode
*node
= list
->First(); node
; node
= node
->Next(), i
++ )
157 wxPoint
*point
= (wxPoint
*)node
->Data();
158 points
[i
].x
= point
->x
;
159 points
[i
].y
= point
->y
;
162 DoDrawPolygon(n
, points
, xoffset
, yoffset
, fillStyle
);
167 void DrawRectangle(long x
, long y
, long width
, long height
)
168 { DoDrawRectangle(x
, y
, width
, height
); }
169 void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
170 { DoDrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
171 void DrawRectangle(const wxRect
& rect
)
172 { DoDrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
174 void DrawRoundedRectangle(long x
, long y
, long width
, long height
,
176 { DoDrawRoundedRectangle(x
, y
, width
, height
, radius
); }
177 void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
,
179 { DoDrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
); }
180 void DrawRoundedRectangle(const wxRect
& r
, double radius
)
181 { DoDrawRoundedRectangle(r
.x
, r
.y
, r
.width
, r
.height
, radius
); }
183 void DrawEllipse(long x
, long y
, long width
, long height
)
184 { DoDrawEllipse(x
, y
, width
, height
); }
185 void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
186 { DoDrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
187 void DrawEllipse(const wxRect
& rect
)
188 { DoDrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
190 void DrawIcon(const wxIcon
& icon
, long x
, long y
)
191 { DoDrawIcon(icon
, x
, y
); }
192 void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
193 { DoDrawIcon(icon
, pt
.x
, pt
.y
); }
195 void DrawBitmap(const wxBitmap
&bmp
, long x
, long y
, bool useMask
= FALSE
)
196 { DoDrawBitmap(bmp
, x
, y
, useMask
); }
197 void DrawBitmap(const wxBitmap
&bmp
, const wxPoint
& pt
,
198 bool useMask
= FALSE
)
199 { DoDrawBitmap(bmp
, pt
.x
, pt
.y
, useMask
); }
201 void DrawText(const wxString
& text
, long x
, long y
)
202 { DoDrawText(text
, x
, y
); }
203 void DrawText(const wxString
& text
, const wxPoint
& pt
)
204 { DoDrawText(text
, pt
.x
, pt
.y
); }
206 bool Blit(long xdest
, long ydest
, long width
, long height
,
207 wxDC
*source
, long xsrc
, long ysrc
,
208 int rop
= wxCOPY
, bool useMask
= FALSE
)
210 return DoBlit(xdest
, ydest
, width
, height
,
211 source
, xsrc
, ysrc
, rop
, useMask
);
213 bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
214 wxDC
*source
, const wxPoint
& srcPt
,
215 int rop
= wxCOPY
, bool useMask
= FALSE
)
217 return DoBlit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
,
218 source
, srcPt
.x
, srcPt
.y
, rop
, useMask
);
222 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
223 void DrawSpline(long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
227 wxPoint
*point1
= new wxPoint
;
228 point1
->x
= x1
; point1
->y
= y1
;
229 point_list
.Append((wxObject
*)point1
);
231 wxPoint
*point2
= new wxPoint
;
232 point2
->x
= x2
; point2
->y
= y2
;
233 point_list
.Append((wxObject
*)point2
);
235 wxPoint
*point3
= new wxPoint
;
236 point3
->x
= x3
; point3
->y
= y3
;
237 point_list
.Append((wxObject
*)point3
);
239 DrawSpline(&point_list
);
241 for( wxNode
*node
= point_list
.First(); node
; node
= node
->Next() )
243 wxPoint
*p
= (wxPoint
*)node
->Data();
248 void DrawSpline(int n
, wxPoint points
[])
251 for (int i
=0; i
< n
; i
++)
253 list
.Append((wxObject
*)&points
[i
]);
259 void DrawSpline(wxList
*points
) { DoDrawSpline(points
); }
260 #endif // wxUSE_SPLINES
262 // global DC operations
263 // --------------------
265 virtual void Clear() = 0;
267 virtual bool StartDoc(const wxString
& message
) = 0;
268 virtual void EndDoc() = 0;
270 virtual void StartPage() = 0;
271 virtual void EndPage() = 0;
273 // set objects to use for drawing
274 // ------------------------------
276 virtual void SetFont(const wxFont
& font
) = 0;
277 virtual void SetPen(const wxPen
& pen
) = 0;
278 virtual void SetBrush(const wxBrush
& brush
) = 0;
279 virtual void SetBackground(const wxBrush
& brush
) = 0;
280 virtual void SetBackgroundMode(int mode
) = 0;
281 virtual void SetPalette(const wxPalette
& palette
) = 0;
286 void SetClippingRegion(long x
, long y
, long width
, long height
)
287 { DoSetClippingRegion(x
, y
, width
, height
); }
288 void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
289 { DoSetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
); }
290 void SetClippingRegion(const wxRect
& rect
)
291 { DoSetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
292 void SetClippingRegion(const wxRegion
& region
)
293 { DoSetClippingRegionAsRegion(region
); }
295 virtual void DestroyClippingRegion() = 0;
297 void GetClippingBox(long *x
, long *y
, long *w
, long *h
) const
298 { DoGetClippingBox(x
, y
, w
, h
); }
299 void GetClippingBox(wxRect
& rect
) const
300 { DoGetClippingBox(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
); }
305 virtual long GetCharHeight() const = 0;
306 virtual long GetCharWidth() const = 0;
307 virtual void GetTextExtent(const wxString
& string
,
309 long *descent
= NULL
,
310 long *externalLeading
= NULL
,
311 wxFont
*theFont
= NULL
) const = 0;
313 // size and resolution
314 // -------------------
317 void GetSize(int *width
, int *height
) const
318 { DoGetSize(width
, height
); }
319 wxSize
GetSize() const
328 void GetSizeMM(int* width
, int* height
) const
329 { DoGetSizeMM(width
, height
); }
330 wxSize
GetSizeMM() const
338 // coordinates conversions
339 // -----------------------
341 // This group of functions does actual conversion of the input, as you'd
343 long DeviceToLogicalX(long x
) const;
344 long DeviceToLogicalY(long y
) const;
345 long DeviceToLogicalXRel(long x
) const;
346 long DeviceToLogicalYRel(long y
) const;
347 long LogicalToDeviceX(long x
) const;
348 long LogicalToDeviceY(long y
) const;
349 long LogicalToDeviceXRel(long x
) const;
350 long LogicalToDeviceYRel(long y
) const;
352 // query DC capabilities
353 // ---------------------
355 virtual bool CanDrawBitmap() const = 0;
356 virtual bool CanGetTextExtent() const = 0;
359 virtual int GetDepth() const = 0;
361 // Resolution in Pixels per inch
362 virtual wxSize
GetPPI() const = 0;
364 virtual bool Ok() const { return m_ok
; }
370 const wxBrush
& GetBackground() const { return m_backgroundBrush
; }
371 const wxBrush
& GetBrush() const { return m_brush
; }
372 const wxFont
& GetFont() const { return m_font
; }
373 const wxPen
& GetPen() const { return m_pen
; }
374 const wxColour
& GetTextBackground() const { return m_textBackgroundColour
; }
375 const wxColour
& GetTextForeground() const { return m_textForegroundColour
; }
378 wxBrush
& GetBackground() { return m_backgroundBrush
; }
379 wxBrush
& GetBrush() { return m_brush
; }
380 wxFont
& GetFont() { return m_font
; }
381 wxPen
& GetPen() { return m_pen
; }
382 wxColour
& GetTextBackground() { return m_textBackgroundColour
; }
383 wxColour
& GetTextForeground() { return m_textForegroundColour
; }
385 virtual void SetTextForeground(const wxColour
& colour
)
386 { m_textForegroundColour
= colour
; }
387 virtual void SetTextBackground(const wxColour
& colour
)
388 { m_textBackgroundColour
= colour
; }
390 int GetMapMode() const { return m_mappingMode
; }
391 virtual void SetMapMode(int mode
) = 0;
393 virtual void GetUserScale(double *x
, double *y
) const
395 if ( x
) *x
= m_userScaleX
;
396 if ( y
) *y
= m_userScaleY
;
398 virtual void SetUserScale(double x
, double y
) = 0;
400 virtual void SetSystemScale(double x
, double y
) = 0;
402 virtual void GetLogicalScale(double *x
, double *y
)
404 if ( x
) *x
= m_logicalScaleX
;
405 if ( y
) *y
= m_logicalScaleY
;
407 virtual void SetLogicalScale(double x
, double y
)
413 void GetLogicalOrigin(long *x
, long *y
) const
414 { DoGetLogicalOrigin(x
, y
); }
415 wxPoint
GetLogicalOrigin() const
416 { long x
, y
; DoGetLogicalOrigin(&x
, &y
); return wxPoint(x
, y
); }
417 virtual void SetLogicalOrigin(long x
, long y
) = 0;
419 void GetDeviceOrigin(long *x
, long *y
) const
420 { DoGetDeviceOrigin(x
, y
); }
421 wxPoint
GetDeviceOrigin() const
422 { long x
, y
; DoGetDeviceOrigin(&x
, &y
); return wxPoint(x
, y
); }
423 virtual void SetDeviceOrigin(long x
, long y
) = 0;
425 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
) = 0;
427 int GetLogicalFunction() const { return m_logicalFunction
; }
428 virtual void SetLogicalFunction(int function
) = 0;
430 // Sometimes we need to override optimization, e.g. if other software is
431 // drawing onto our surface and we can't be sure of who's done what.
433 // FIXME: is this (still) used?
434 virtual void SetOptimization(bool WXUNUSED(opt
)) { }
435 virtual bool GetOptimization() { return FALSE
; }
440 virtual void CalcBoundingBox(long x
, long y
)
442 if (x
< m_minX
) m_minX
= x
;
443 if (y
< m_minY
) m_minY
= y
;
444 if (x
> m_maxX
) m_maxX
= x
;
445 if (y
> m_maxY
) m_maxY
= y
;
448 // Get the final bounding box of the PostScript or Metafile picture.
449 long MinX() const { return m_minX
; }
450 long MaxX() const { return m_maxX
; }
451 long MinY() const { return m_minY
; }
452 long MaxY() const { return m_maxY
; }
454 // misc old functions
455 // ------------------
457 #if WXWIN_COMPATIBILITY
458 virtual void SetColourMap(const wxPalette
& palette
) { SetPalette(palette
); }
459 void GetTextExtent(const wxString
& string
, float *x
, float *y
,
460 float *descent
= NULL
, float *externalLeading
= NULL
,
461 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const ;
462 void GetSize(float* width
, float* height
) const { int w
, h
; GetSize(& w
, & h
); *width
= w
; *height
= h
; }
463 void GetSizeMM(float *width
, float *height
) const { long w
, h
; GetSizeMM(& w
, & h
); *width
= (float) w
; *height
= (float) h
; }
464 #endif // WXWIN_COMPATIBILITY
467 // the pure virtual functions which should be implemented by wxDC
468 virtual void DoFloodFill(long x
, long y
, const wxColour
& col
,
469 int style
= wxFLOOD_SURFACE
) = 0;
471 virtual bool DoGetPixel(long x
, long y
, wxColour
*col
) const = 0;
473 virtual void DoDrawPoint(long x
, long y
) = 0;
474 virtual void DoDrawLine(long x1
, long y1
, long x2
, long y2
) = 0;
476 virtual void DoDrawArc(long x1
, long y1
,
478 long xc
, long yc
) = 0;
479 virtual void DoDrawEllipticArc(long x
, long y
, long w
, long h
,
480 double sa
, double ea
) = 0;
482 virtual void DoDrawRectangle(long x
, long y
, long width
, long height
) = 0;
483 virtual void DoDrawRoundedRectangle(long x
, long y
,
484 long width
, long height
,
486 virtual void DoDrawEllipse(long x
, long y
, long width
, long height
) = 0;
488 virtual void DoCrossHair(long x
, long y
) = 0;
490 virtual void DoDrawIcon(const wxIcon
& icon
, long x
, long y
) = 0;
491 virtual void DoDrawBitmap(const wxBitmap
&bmp
, long x
, long y
,
492 bool useMask
= FALSE
) = 0;
494 virtual void DoDrawText(const wxString
& text
, long x
, long y
) = 0;
496 virtual bool DoBlit(long xdest
, long ydest
, long width
, long height
,
497 wxDC
*source
, long xsrc
, long ysrc
,
498 int rop
= wxCOPY
, bool useMask
= FALSE
) = 0;
500 virtual void DoGetSize(int *width
, int *height
) const = 0;
501 virtual void DoGetSizeMM(int* width
, int* height
) const = 0;
503 virtual void DoDrawLines(int n
, wxPoint points
[],
504 long xoffset
, long yoffset
) = 0;
505 virtual void DoDrawPolygon(int n
, wxPoint points
[],
506 long xoffset
, long yoffset
,
507 int fillStyle
= wxODDEVEN_RULE
) = 0;
509 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
) = 0;
510 virtual void DoSetClippingRegion(long x
, long y
,
511 long width
, long height
) = 0;
512 virtual void DoGetClippingRegion(long *x
, long *y
,
513 long *width
, long *height
) = 0;
514 virtual void DoGetClippingBox(long *x
, long *y
,
515 long *w
, long *h
) const
519 if ( x
) *x
= m_clipX1
;
520 if ( y
) *y
= m_clipY1
;
521 if ( w
) *w
= m_clipX2
- m_clipX1
;
522 if ( h
) *h
= m_clipY2
- m_clipY1
;
526 *x
= *y
= *w
= *h
= 0;
530 virtual void DoGetLogicalOrigin(long *x
, long *y
) const
532 if ( x
) *x
= m_logicalOriginX
;
533 if ( y
) *y
= m_logicalOriginY
;
536 virtual void DoGetDeviceOrigin(long *x
, long *y
) const
538 if ( x
) *x
= m_deviceOriginX
;
539 if ( y
) *y
= m_deviceOriginY
;
542 virtual void DoDrawSpline(wxList
*points
) = 0;
549 bool m_isInteractive
:1;
551 // coordinate system variables
553 // TODO short descriptions of what exactly they are would be nice...
555 long m_logicalOriginX
, m_logicalOriginY
;
556 long m_deviceOriginX
, m_deviceOriginY
;
558 double m_logicalScaleX
, m_logicalScaleY
;
559 double m_userScaleX
, m_userScaleY
;
560 double m_scaleX
, m_scaleY
;
562 // Used by SetAxisOrientation() to invert the axes
563 int m_signX
, m_signY
;
565 // bounding and clipping boxes
566 long m_minX
, m_minY
, m_maxX
, m_maxY
;
567 long m_clipX1
, m_clipY1
, m_clipX2
, m_clipY2
;
569 int m_logicalFunction
;
570 int m_backgroundMode
;
576 wxBrush m_backgroundBrush
;
577 wxColour m_textForegroundColour
;
578 wxColour m_textBackgroundColour
;
583 DECLARE_NO_COPY_CLASS(wxDCBase
);
586 // ----------------------------------------------------------------------------
587 // now include the declaration of wxDC class
588 // ----------------------------------------------------------------------------
590 #if defined(__WXMSW__)
591 #include "wx/msw/dc.h"
592 #elif defined(__WXMOTIF__)
593 #include "wx/motif/dc.h"
594 #elif defined(__WXGTK__)
595 #include "wx/gtk/dc.h"
596 #elif defined(__WXQT__)
597 #include "wx/qt/dc.h"
598 #elif defined(__WXMAC__)
599 #include "wx/mac/dc.h"
600 #elif defined(__WXSTUBS__)
601 #include "wx/stubs/dc.h"