1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dc.h"
23 #include "wx/gdicmn.h"
24 #include "wx/window.h"
26 // Clash with Windows header files
39 class WXDLLEXPORT wxDC
: public wxObject
41 DECLARE_ABSTRACT_CLASS(wxDC
)
47 #ifdef WX_COMP_INLINE_NO_CLASS
48 inline void BeginDrawing(void) {}
49 inline void EndDrawing(void) {}
51 inline void wxDC::BeginDrawing(void) {}
52 inline void wxDC::EndDrawing(void) {}
55 virtual void FloodFill(long x1
, long y1
, const wxColour
& col
, int style
=wxFLOOD_SURFACE
) ;
56 inline void FloodFill(const wxPoint
& pt
, const wxColour
& col
, int style
=wxFLOOD_SURFACE
)
58 FloodFill(pt
.x
, pt
.y
, col
, style
);
61 virtual bool GetPixel(long x1
, long y1
, wxColour
*col
) const ;
62 inline bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
64 return GetPixel(pt
.x
, pt
.y
, col
);
67 virtual void DrawLine(long x1
, long y1
, long x2
, long y2
);
68 inline void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
70 DrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
);
73 virtual void CrossHair(long x
, long y
) ;
74 inline void CrossHair(const wxPoint
& pt
)
76 CrossHair(pt
.x
, pt
.y
);
79 virtual void DrawArc(long x1
,long y1
,long x2
,long y2
,long xc
, long yc
);
80 inline void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
82 DrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
);
85 virtual void DrawEllipticArc (long x
, long y
, long w
, long h
, double sa
, double ea
);
86 virtual void DrawEllipticArc (const wxPoint
& pt
, const wxSize
& sz
, double sa
, double ea
)
88 DrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
);
91 virtual void DrawPoint(long x
, long y
);
92 inline void DrawPoint(const wxPoint
& pt
)
94 DrawPoint(pt
.x
, pt
.y
);
97 virtual void DrawLines(int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0);
99 virtual void DrawPolygon(int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
101 virtual void DrawRectangle(long x
, long y
, long width
, long height
);
102 inline void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
104 DrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
106 inline void DrawRectangle(const wxRect
& rect
)
108 DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
111 virtual void DrawRoundedRectangle(long x
, long y
, long width
, long height
, double radius
= 20.0);
112 inline void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
, double radius
= 20.0)
114 DrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
);
116 inline void DrawRoundedRectangle(const wxRect
& rect
, double radius
= 20.0)
118 DrawRoundedRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
, radius
);
121 virtual void DrawEllipse(long x
, long y
, long width
, long height
);
122 inline void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
124 DrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
126 inline void DrawEllipse(const wxRect
& rect
)
128 DrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
131 virtual void DrawIcon(const wxIcon
& icon
, long x
, long y
);
132 inline void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
134 DrawIcon(icon
, pt
.x
, pt
.y
);
137 virtual void DrawBitmap( const wxBitmap
&bmp
, long x
, long y
, bool useMask
=FALSE
);
139 inline void DrawPoint(wxPoint
& point
) { DrawPoint(point
.x
, point
.y
); }
140 virtual void DrawLines(wxList
*list
, long xoffset
= 0, long yoffset
= 0);
141 virtual void DrawPolygon(wxList
*list
, long xoffset
= 0, long yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
143 virtual void DrawText(const wxString
& text
, long x
, long y
, bool use16bit
= FALSE
);
144 inline void DrawText(const wxString
& text
, const wxPoint
& pt
, bool use16bit
= FALSE
)
146 DrawText(text
, pt
.x
, pt
.y
, use16bit
);
149 virtual bool Blit(long xdest
, long ydest
, long width
, long height
,
150 wxDC
*source
, long xsrc
, long ysrc
, int rop
= wxCOPY
, bool useMask
= FALSE
);
151 inline bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
152 wxDC
*source
, const wxPoint
& srcPt
, int rop
= wxCOPY
, bool useMask
= FALSE
)
154 return Blit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
, source
, srcPt
.x
, srcPt
.y
, rop
, useMask
);
160 virtual void DrawSpline(long x1
, long y1
, long x2
, long y2
, long x3
, long y3
);
161 // Any number of control points - a list of pointers to wxPoints
162 virtual void DrawSpline(wxList
*points
);
163 virtual void DrawSpline(int n
, wxPoint points
[]);
165 virtual void Clear(void);
166 virtual void SetFont(const wxFont
& font
);
167 virtual void SetPen(const wxPen
& pen
);
168 virtual void SetBrush(const wxBrush
& brush
);
169 virtual void SetLogicalFunction(int function
);
170 virtual void SetBackground(const wxBrush
& brush
);
171 virtual void SetBackgroundMode(int mode
);
173 virtual void SetClippingRegion(long x
, long y
, long width
, long height
);
174 inline void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
176 SetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
178 inline void SetClippingRegion(const wxRect
& rect
)
180 SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
182 virtual void SetClippingRegion(const wxRegion
& region
);
184 virtual void SetPalette(const wxPalette
& palette
);
185 #if WXWIN_COMPATIBILITY
186 virtual inline void SetColourMap(const wxPalette
& palette
) { SetPalette(palette
); };
188 virtual void DestroyClippingRegion(void);
189 virtual long GetCharHeight(void) const;
190 virtual long GetCharWidth(void) const;
191 virtual void GetTextExtent(const wxString
& string
, long *x
, long *y
,
192 long *descent
= NULL
, long *externalLeading
= NULL
,
193 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const;
194 #if WXWIN_COMPATIBILITY
195 void GetTextExtent(const wxString
& string
, float *x
, float *y
,
196 float *descent
= NULL
, float *externalLeading
= NULL
,
197 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const ;
200 // Size in device units
201 virtual void GetSize(int* width
, int* height
) const;
202 inline wxSize
GetSize() const { int w
, h
; GetSize(&w
, &h
); return wxSize(w
, h
); }
205 virtual void GetSizeMM(int* width
, int* height
) const ;
206 inline wxSize
GetSizeMM() const { int w
, h
; GetSizeMM(&w
, &h
); return wxSize(w
, h
); }
208 // Resolution in Pixels per inch
209 virtual wxSize
GetPPI(void) const ;
212 #if WXWIN_COMPATIBILITY
213 inline void GetSize(float* width
, float* height
) const { int w
, h
; GetSize(& w
, & h
); *width
= w
; *height
= h
; }
214 inline void GetSizeMM(float *width
, float *height
) const { long w
, h
; GetSizeMM(& w
, & h
); *width
= (float) w
; *height
= (float) h
; }
217 virtual bool StartDoc(const wxString
& message
);
218 virtual void EndDoc(void);
219 virtual void StartPage(void);
220 virtual void EndPage(void);
221 virtual void SetMapMode(int mode
);
222 virtual void SetUserScale(double x
, double y
);
223 virtual void SetSystemScale(double x
, double y
);
224 virtual void SetLogicalOrigin(long x
, long y
);
225 virtual void SetDeviceOrigin(long x
, long y
);
226 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
228 // This group of functions does actual conversion
229 // of the input, as you'd expect.
231 long DeviceToLogicalX(long x
) const;
232 long DeviceToLogicalY(long y
) const;
233 long DeviceToLogicalXRel(long x
) const;
234 long DeviceToLogicalYRel(long y
) const;
235 long LogicalToDeviceX(long x
) const;
236 long LogicalToDeviceY(long y
) const;
237 long LogicalToDeviceXRel(long x
) const;
238 long LogicalToDeviceYRel(long y
) const;
240 // This group of functions may not do any conversion
241 // if m_scaleGDI is TRUE, since the HDC does the
242 // conversion automatically.
243 // m_scaleGDI NOW OBSOLETE
244 long ImplDeviceToLogicalX(long x
) const;
245 long ImplDeviceToLogicalY(long y
) const;
246 long ImplDeviceToLogicalXRel(long x
) const;
247 long ImplDeviceToLogicalYRel(long y
) const;
248 long ImplLogicalToDeviceX(long x
) const;
249 long ImplLogicalToDeviceY(long y
) const;
250 long ImplLogicalToDeviceXRel(long x
) const;
251 long ImplLogicalToDeviceYRel(long y
) const;
253 virtual bool CanDrawBitmap(void) const;
254 virtual bool CanGetTextExtent(void) const;
256 virtual void SetTextForeground(const wxColour
& colour
);
257 virtual void SetTextBackground(const wxColour
& colour
);
258 inline virtual bool Ok(void) const {return m_ok
;};
259 inline virtual int GetMapMode(void) const {return m_mappingMode
;};
261 inline virtual wxBrush
& GetBackground(void) const { return (wxBrush
&) m_backgroundBrush
;}
262 inline virtual wxBrush
& GetBrush(void) const { return (wxBrush
&) m_brush
;}
263 inline virtual wxFont
& GetFont(void) const { return (wxFont
&) m_font
;}
264 inline virtual int GetLogicalFunction(void) const { return m_logicalFunction
;}
265 inline virtual wxPen
& GetPen(void) const { return (wxPen
&) m_pen
;}
266 inline virtual wxColour
&GetTextBackground(void) const { return (wxColour
&) m_textBackgroundColour
;}
267 inline virtual wxColour
&GetTextForeground(void) const { return (wxColour
&) m_textForegroundColour
;}
269 virtual void SetLogicalScale(double x
, double y
);
270 virtual inline void GetUserScale(double* x
, double *y
) const { *x
= m_userScaleX
; *y
= m_userScaleY
; }
271 virtual void CalcBoundingBox(long x
, long y
);
272 // Get the final bounding box of the PostScript or Metafile picture.
273 virtual inline long MinX(void) const { return m_minX
; }
274 virtual inline long MaxX(void) const { return m_maxX
; }
275 virtual inline long MinY(void) const { return m_minY
; }
276 virtual inline long MaxY(void) const { return m_maxY
; }
277 // Sometimes we need to override optimization, e.g.
278 // if other software is drawing onto our surface and we
279 // can't be sure of who's done what.
280 virtual inline void SetOptimization(bool WXUNUSED(opt
)) { }
281 virtual inline bool GetOptimization(void) { return FALSE
; }
283 virtual void GetClippingBox(long *x
,long *y
,long *w
,long *h
) const ;
284 inline void GetClippingBox(wxRect
& rect
) const
287 GetClippingBox(&x
, &y
, &w
, &h
); rect
.x
= x
; rect
.y
= y
; rect
.width
= w
; rect
.height
= h
;
290 // This should probably be made available on other platforms
291 #ifdef WX_COMP_INLINE_NO_CLASS
292 int GetDepth(void) const ;
294 int wxDC::GetDepth(void) const ;
298 virtual void SetRop(WXHDC cdc
);
299 virtual void DoClipping(WXHDC cdc
);
300 virtual void SelectOldObjects(WXHDC dc
);
302 inline wxWindow
*GetWindow(void) const { return m_canvas
; }
303 inline void SetWindow(wxWindow
*win
) { m_canvas
= win
; }
304 inline WXHDC
GetHDC(void) const { return m_hDC
; }
305 inline void SetHDC(WXHDC dc
, bool bOwnsDC
= FALSE
) { m_hDC
= dc
; m_bOwnsDC
= bOwnsDC
; }
311 bool m_isInteractive
;
313 // Coordinate system variables
314 long m_logicalOriginX
;
315 long m_logicalOriginY
;
317 long m_deviceOriginX
;
318 long m_deviceOriginY
;
320 double m_logicalScaleX
;
321 double m_logicalScaleY
;
326 int m_signX
; // Used by SetAxisOrientation() to
327 int m_signY
; // invert the axes
331 long m_minX
; // bounding box
336 int m_logicalFunction
;
337 int m_backgroundMode
;
341 wxBrush m_backgroundBrush
;
342 wxColour m_textForegroundColour
;
343 wxColour m_textBackgroundColour
;
350 // bool m_dontDelete;
353 double m_systemScaleX
;
354 double m_systemScaleY
;
357 wxBitmap m_selectedBitmap
;
359 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
365 // Store all old GDI objects when do a SelectObject,
366 // so we can select them back in (this unselecting user's
367 // objects) so we can safely delete the DC.
368 WXHBITMAP m_oldBitmap
;
372 WXHPALETTE m_oldPalette
;
374 // Stores scaling, translation, rotation
375 // wxTransformMatrix m_transformMatrix;
377 // Do we wish to scale GDI objects too, e.g. pen width?
383 #define XLOG2DEV(x) ImplLogicalToDeviceX(x)
385 #define YLOG2DEV(y) ImplLogicalToDeviceY(y)
388 #define XLOG2DEVREL(x) ImplLogicalToDeviceXRel(x)
389 #define YLOG2DEVREL(y) ImplLogicalToDeviceYRel(y)
393 #define XDEV2LOG(x) ImplDeviceToLogicalX(x)
395 #define YDEV2LOG(y) ImplDeviceToLogicalY(y)
398 #define XDEV2LOGREL(x) ImplDeviceToLogicalXRel(x)
399 #define YDEV2LOGREL(y) ImplDeviceToLogicalYRel(y)
402 * Have the same macros as for XView but not for every operation:
403 * just for calculating window/viewport extent (a better way of scaling).
408 #define MS_XLOG2DEV(x) LogicalToDevice(x)
410 #define MS_YLOG2DEV(y) LogicalToDevice(y)
413 #define MS_XLOG2DEVREL(x) LogicalToDeviceXRel(x)
414 #define MS_YLOG2DEVREL(y) LogicalToDeviceYRel(y)
418 #define MS_XDEV2LOG(x) DeviceToLogicalX(x)
420 #define MS_YDEV2LOG(y) DeviceToLogicalY(y)
423 #define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x)
424 #define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y)
429 extern int wxPageNumber
;
432 #define METRIC_CONVERSION_CONSTANT 0.0393700787
434 // Scaling factors for various unit conversions
435 #define mm2inches (METRIC_CONVERSION_CONSTANT)
436 #define inches2mm (1/METRIC_CONVERSION_CONSTANT)
438 #define mm2twips (METRIC_CONVERSION_CONSTANT*1440)
439 #define twips2mm (1/(METRIC_CONVERSION_CONSTANT*1440))
441 #define mm2pt (METRIC_CONVERSION_CONSTANT*72)
442 #define pt2mm (1/(METRIC_CONVERSION_CONSTANT*72))
444 #define wx_round(a) (int)((a)+.5)