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"
25 class WXDLLEXPORT wxDC
: public wxObject
27 DECLARE_ABSTRACT_CLASS(wxDC
)
33 inline void wxDC::BeginDrawing(void) {}
34 inline void wxDC::EndDrawing(void) {}
36 virtual void FloodFill(long x1
, long y1
, const wxColour
& col
, int style
=wxFLOOD_SURFACE
) ;
37 inline void FloodFill(const wxPoint
& pt
, const wxColour
& col
, int style
=wxFLOOD_SURFACE
)
39 FloodFill(pt
.x
, pt
.y
, col
, style
);
42 virtual bool GetPixel(long x1
, long y1
, wxColour
*col
) const ;
43 inline bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
45 return GetPixel(pt
.x
, pt
.y
, col
);
48 virtual void DrawLine(long x1
, long y1
, long x2
, long y2
);
49 inline void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
51 DrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
);
54 virtual void CrossHair(long x
, long y
) ;
55 inline void CrossHair(const wxPoint
& pt
)
57 CrossHair(pt
.x
, pt
.y
);
60 virtual void DrawArc(long x1
,long y1
,long x2
,long y2
,long xc
, long yc
);
61 inline void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
63 DrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
);
66 virtual void DrawEllipticArc (long x
, long y
, long w
, long h
, double sa
, double ea
);
67 virtual void DrawEllipticArc (const wxPoint
& pt
, const wxSize
& sz
, double sa
, double ea
)
69 DrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
);
72 virtual void DrawPoint(long x
, long y
);
73 inline void DrawPoint(const wxPoint
& pt
)
75 DrawPoint(pt
.x
, pt
.y
);
78 virtual void DrawLines(int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0);
80 virtual void DrawPolygon(int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
82 virtual void DrawRectangle(long x
, long y
, long width
, long height
);
83 inline void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
85 DrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
87 inline void DrawRectangle(const wxRect
& rect
)
89 DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
92 virtual void DrawRoundedRectangle(long x
, long y
, long width
, long height
, double radius
= 20.0);
93 inline void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
, double radius
= 20.0)
95 DrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
);
97 inline void DrawRoundedRectangle(const wxRect
& rect
, double radius
= 20.0)
99 DrawRoundedRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
, radius
);
102 virtual void DrawEllipse(long x
, long y
, long width
, long height
);
103 inline void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
105 DrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
107 inline void DrawEllipse(const wxRect
& rect
)
109 DrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
112 virtual void DrawIcon(const wxIcon
& icon
, long x
, long y
);
113 inline void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
115 DrawIcon(icon
, pt
.x
, pt
.y
);
118 virtual void DrawBitmap( const wxBitmap
&bmp
, long x
, long y
, bool useMask
=FALSE
);
120 inline void DrawPoint(wxPoint
& point
) { DrawPoint(point
.x
, point
.y
); }
121 virtual void DrawLines(wxList
*list
, long xoffset
= 0, long yoffset
= 0);
122 virtual void DrawPolygon(wxList
*list
, long xoffset
= 0, long yoffset
= 0, int fillStyle
=wxODDEVEN_RULE
);
124 virtual void DrawText(const wxString
& text
, long x
, long y
, bool use16bit
= FALSE
);
125 inline void DrawText(const wxString
& text
, const wxPoint
& pt
, bool use16bit
= FALSE
)
127 DrawText(text
, pt
.x
, pt
.y
, use16bit
);
130 virtual bool Blit(long xdest
, long ydest
, long width
, long height
,
131 wxDC
*source
, long xsrc
, long ysrc
, int rop
= wxCOPY
, bool useMask
= FALSE
);
132 inline bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
133 wxDC
*source
, const wxPoint
& srcPt
, int rop
= wxCOPY
, bool useMask
= FALSE
)
135 return Blit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
, source
, srcPt
.x
, srcPt
.y
, rop
, useMask
);
141 virtual void DrawSpline(long x1
, long y1
, long x2
, long y2
, long x3
, long y3
);
142 // Any number of control points - a list of pointers to wxPoints
143 virtual void DrawSpline(wxList
*points
);
144 virtual void DrawSpline(int n
, wxPoint points
[]);
146 virtual void Clear(void);
147 virtual void SetFont(const wxFont
& font
);
148 virtual void SetPen(const wxPen
& pen
);
149 virtual void SetBrush(const wxBrush
& brush
);
150 virtual void SetLogicalFunction(int function
);
151 virtual void SetBackground(const wxBrush
& brush
);
152 virtual void SetBackgroundMode(int mode
);
154 virtual void SetClippingRegion(long x
, long y
, long width
, long height
);
155 inline void SetClippingRegion(const wxPoint
& pt
, const wxSize
& sz
)
157 SetClippingRegion(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
159 inline void SetClippingRegion(const wxRect
& rect
)
161 SetClippingRegion(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
163 virtual void SetClippingRegion(const wxRegion
& region
);
165 virtual void SetPalette(const wxPalette
& palette
);
166 #if WXWIN_COMPATIBILITY
167 virtual inline void SetColourMap(const wxPalette
& palette
) { SetPalette(palette
); };
169 virtual void DestroyClippingRegion(void);
170 virtual long GetCharHeight(void) const;
171 virtual long GetCharWidth(void) const;
172 virtual void GetTextExtent(const wxString
& string
, long *x
, long *y
,
173 long *descent
= NULL
, long *externalLeading
= NULL
,
174 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const;
175 #if WXWIN_COMPATIBILITY
176 void GetTextExtent(const wxString
& string
, float *x
, float *y
,
177 float *descent
= NULL
, float *externalLeading
= NULL
,
178 wxFont
*theFont
= NULL
, bool use16bit
= FALSE
) const ;
181 // Size in device units
182 virtual void GetSize(int* width
, int* height
) const;
183 inline wxSize
GetSize(void) const { int w
, h
; GetSize(&w
, &h
); return wxSize(w
, h
); }
186 virtual void GetSizeMM(long* width
, long* height
) const ;
189 #if WXWIN_COMPATIBILITY
190 inline void GetSize(float* width
, float* height
) const { int w
, h
; GetSize(& w
, & h
); *width
= w
; *height
= h
; }
191 inline void GetSizeMM(float *width
, float *height
) const { long w
, h
; GetSizeMM(& w
, & h
); *width
= (float) w
; *height
= (float) h
; }
194 virtual bool StartDoc(const wxString
& message
);
195 virtual void EndDoc(void);
196 virtual void StartPage(void);
197 virtual void EndPage(void);
198 virtual void SetMapMode(int mode
);
199 virtual void SetUserScale(double x
, double y
);
200 virtual void SetSystemScale(double x
, double y
);
201 virtual void SetLogicalOrigin(long x
, long y
);
202 virtual void SetDeviceOrigin(long x
, long y
);
203 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
205 // This group of functions does actual conversion
206 // of the input, as you'd expect.
208 long DeviceToLogicalX(long x
) const;
209 long DeviceToLogicalY(long y
) const;
210 long DeviceToLogicalXRel(long x
) const;
211 long DeviceToLogicalYRel(long y
) const;
212 long LogicalToDeviceX(long x
) const;
213 long LogicalToDeviceY(long y
) const;
214 long LogicalToDeviceXRel(long x
) const;
215 long LogicalToDeviceYRel(long y
) const;
217 // This group of functions may not do any conversion
218 // if m_scaleGDI is TRUE, since the HDC does the
219 // conversion automatically.
220 // m_scaleGDI NOW OBSOLETE
221 long ImplDeviceToLogicalX(long x
) const;
222 long ImplDeviceToLogicalY(long y
) const;
223 long ImplDeviceToLogicalXRel(long x
) const;
224 long ImplDeviceToLogicalYRel(long y
) const;
225 long ImplLogicalToDeviceX(long x
) const;
226 long ImplLogicalToDeviceY(long y
) const;
227 long ImplLogicalToDeviceXRel(long x
) const;
228 long ImplLogicalToDeviceYRel(long y
) const;
230 virtual bool CanDrawBitmap(void) const;
231 virtual bool CanGetTextExtent(void) const;
233 virtual void SetTextForeground(const wxColour
& colour
);
234 virtual void SetTextBackground(const wxColour
& colour
);
235 inline virtual bool Ok(void) const {return m_ok
;};
236 inline virtual int GetMapMode(void) const {return m_mappingMode
;};
238 inline virtual wxBrush
*GetBackground(void) const { return (wxBrush
*) &m_backgroundBrush
;}
239 inline virtual wxBrush
*GetBrush(void) const { return (wxBrush
*) &m_brush
;}
240 inline virtual wxFont
*GetFont(void) const { return (wxFont
*) &m_font
;}
241 inline virtual int GetLogicalFunction(void) const { return m_logicalFunction
;}
242 inline virtual wxPen
*GetPen(void) const { return (wxPen
*) &m_pen
;}
243 inline virtual wxColour
&GetTextBackground(void) const { return (wxColour
&) m_textBackgroundColour
;}
244 inline virtual wxColour
&GetTextForeground(void) const { return (wxColour
&) m_textForegroundColour
;}
246 virtual void SetLogicalScale(double x
, double y
);
247 virtual inline void GetUserScale(double* x
, double *y
) const { *x
= m_userScaleX
; *y
= m_userScaleY
; }
248 virtual void CalcBoundingBox(long x
, long y
);
249 // Get the final bounding box of the PostScript or Metafile picture.
250 virtual inline long MinX(void) const { return m_minX
; }
251 virtual inline long MaxX(void) const { return m_maxX
; }
252 virtual inline long MinY(void) const { return m_minY
; }
253 virtual inline long MaxY(void) const { return m_maxY
; }
254 // Sometimes we need to override optimization, e.g.
255 // if other software is drawing onto our surface and we
256 // can't be sure of who's done what.
257 virtual inline void SetOptimization(bool WXUNUSED(opt
)) { }
258 virtual inline bool GetOptimization(void) { return FALSE
; }
260 virtual void GetClippingBox(long *x
,long *y
,long *w
,long *h
) const ;
261 inline void GetClippingBox(wxRect
& rect
) const
264 GetClippingBox(&x
, &y
, &w
, &h
); rect
.x
= x
; rect
.y
= y
; rect
.width
= w
; rect
.height
= h
;
267 // This should probably be made available on other platforms
268 int wxDC::GetDepth(void) const ;
271 virtual void SetRop(WXHDC cdc
);
272 virtual void DoClipping(WXHDC cdc
);
273 virtual void SelectOldObjects(WXHDC dc
);
275 inline wxWindow
*GetWindow(void) const { return m_canvas
; }
276 inline void SetWindow(wxWindow
*win
) { m_canvas
= win
; }
277 inline WXHDC
GetHDC(void) const { return m_hDC
; }
278 inline void SetHDC(WXHDC dc
, bool bOwnsDC
= FALSE
) { m_hDC
= dc
; m_bOwnsDC
= bOwnsDC
; }
284 bool m_isInteractive
;
286 // Coordinate system variables
287 long m_logicalOriginX
;
288 long m_logicalOriginY
;
290 long m_deviceOriginX
;
291 long m_deviceOriginY
;
293 double m_logicalScaleX
;
294 double m_logicalScaleY
;
299 int m_signX
; // Used by SetAxisOrientation() to
300 int m_signY
; // invert the axes
304 long m_minX
; // bounding box
309 int m_logicalFunction
;
310 int m_backgroundMode
;
314 wxBrush m_backgroundBrush
;
315 wxColour m_textForegroundColour
;
316 wxColour m_textBackgroundColour
;
323 // bool m_dontDelete;
326 double m_systemScaleX
;
327 double m_systemScaleY
;
330 wxBitmap m_selectedBitmap
;
333 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
339 // Store all old GDI objects when do a SelectObject,
340 // so we can select them back in (this unselecting user's
341 // objects) so we can safely delete the DC.
342 WXHBITMAP m_oldBitmap
;
346 WXHPALETTE m_oldPalette
;
348 // Stores scaling, translation, rotation
349 // wxTransformMatrix m_transformMatrix;
351 // Do we wish to scale GDI objects too, e.g. pen width?
357 #define XLOG2DEV(x) ImplLogicalToDeviceX(x)
359 #define YLOG2DEV(y) ImplLogicalToDeviceY(y)
362 #define XLOG2DEVREL(x) ImplLogicalToDeviceXRel(x)
363 #define YLOG2DEVREL(y) ImplLogicalToDeviceYRel(y)
367 #define XDEV2LOG(x) ImplDeviceToLogicalX(x)
369 #define YDEV2LOG(y) ImplDeviceToLogicalY(y)
372 #define XDEV2LOGREL(x) ImplDeviceToLogicalXRel(x)
373 #define YDEV2LOGREL(y) ImplDeviceToLogicalYRel(y)
376 * Have the same macros as for XView but not for every operation:
377 * just for calculating window/viewport extent (a better way of scaling).
382 #define MS_XLOG2DEV(x) LogicalToDevice(x)
384 #define MS_YLOG2DEV(y) LogicalToDevice(y)
387 #define MS_XLOG2DEVREL(x) LogicalToDeviceXRel(x)
388 #define MS_YLOG2DEVREL(y) LogicalToDeviceYRel(y)
392 #define MS_XDEV2LOG(x) DeviceToLogicalX(x)
394 #define MS_YDEV2LOG(y) DeviceToLogicalY(y)
397 #define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x)
398 #define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y)
403 extern int wxPageNumber
;
406 #define METRIC_CONVERSION_CONSTANT 0.0393700787
408 // Scaling factors for various unit conversions
409 #define mm2inches (METRIC_CONVERSION_CONSTANT)
410 #define inches2mm (1/METRIC_CONVERSION_CONSTANT)
412 #define mm2twips (METRIC_CONVERSION_CONSTANT*1440)
413 #define twips2mm (1/(METRIC_CONVERSION_CONSTANT*1440))
415 #define mm2pt (METRIC_CONVERSION_CONSTANT*72)
416 #define pt2mm (1/(METRIC_CONVERSION_CONSTANT*72))
418 #define wx_round(a) (int)((a)+.5)