1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dc.h"
23 #include "wx/gdicmn.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
31 #define MM_ISOTROPIC 1
32 #define MM_ANISOTROPIC 2
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 extern int wxPageNumber
;
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 class WXDLLEXPORT wxDC
: public wxObject
52 DECLARE_ABSTRACT_CLASS(wxDC
)
59 void BeginDrawing(void) {};
60 void EndDrawing(void) {};
62 virtual bool Ok(void) const { return m_ok
; };
64 virtual void FloodFill( long x1
, long y1
, const wxColour
& col
, int style
=wxFLOOD_SURFACE
);
65 inline void FloodFill(const wxPoint
& pt
, const wxColour
& col
, int style
=wxFLOOD_SURFACE
)
67 FloodFill(pt
.x
, pt
.y
, col
, style
);
70 virtual bool GetPixel( long x1
, long y1
, wxColour
*col
) const ;
71 inline bool GetPixel(const wxPoint
& pt
, wxColour
*col
) const
73 return GetPixel(pt
.x
, pt
.y
, col
);
76 virtual void DrawLine( long x1
, long y1
, long x2
, long y2
);
77 inline void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
79 DrawLine(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
);
82 virtual void CrossHair( long x
, long y
);
83 inline void CrossHair(const wxPoint
& pt
)
85 CrossHair(pt
.x
, pt
.y
);
88 virtual void DrawArc( long x1
, long y1
, long x2
, long y2
, long xc
, long yc
);
89 inline void DrawArc(const wxPoint
& pt1
, const wxPoint
& pt2
, const wxPoint
& centre
)
91 DrawArc(pt1
.x
, pt1
.y
, pt2
.x
, pt2
.y
, centre
.x
, centre
.y
);
94 virtual void DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
);
95 virtual void DrawEllipticArc (const wxPoint
& pt
, const wxSize
& sz
, double sa
, double ea
)
97 DrawEllipticArc(pt
.x
, pt
.y
, sz
.x
, sz
.y
, sa
, ea
);
100 virtual void DrawPoint( long x
, long y
);
101 virtual void DrawPoint( wxPoint
& point
);
103 virtual void DrawLines( int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0 );
104 virtual void DrawLines( wxList
*points
, long xoffset
= 0, long yoffset
= 0 );
105 virtual void DrawPolygon( int n
, wxPoint points
[], long xoffset
= 0, long yoffset
= 0,
106 int fillStyle
=wxODDEVEN_RULE
);
107 virtual void DrawPolygon( wxList
*lines
, long xoffset
= 0, long yoffset
= 0,
108 int fillStyle
=wxODDEVEN_RULE
);
110 virtual void DrawRectangle( long x
, long y
, long width
, long height
);
111 inline void DrawRectangle(const wxPoint
& pt
, const wxSize
& sz
)
113 DrawRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
115 inline void DrawRectangle(const wxRect
& rect
)
117 DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
119 virtual void DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
= 20.0 );
120 inline void DrawRoundedRectangle(const wxPoint
& pt
, const wxSize
& sz
, double radius
= 20.0)
122 DrawRoundedRectangle(pt
.x
, pt
.y
, sz
.x
, sz
.y
, radius
);
124 inline void DrawRoundedRectangle(const wxRect
& rect
, double radius
= 20.0)
126 DrawRoundedRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
, radius
);
129 virtual void DrawEllipse( long x
, long y
, long width
, long height
);
130 inline void DrawEllipse(const wxPoint
& pt
, const wxSize
& sz
)
132 DrawEllipse(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
134 inline void DrawEllipse(const wxRect
& rect
)
136 DrawEllipse(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
139 virtual void DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
);
140 virtual void DrawSpline( wxList
*points
);
141 virtual void DrawSpline( int n
, wxPoint points
[] );
143 virtual bool CanDrawBitmap(void) const ;
145 virtual void DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
=FALSE
);
146 inline void DrawIcon(const wxIcon
& icon
, const wxPoint
& pt
)
148 DrawIcon(icon
, pt
.x
, pt
.y
);
151 void DrawBitmap( const wxBitmap
&bmp
, long x
, long y
, bool useMask
=FALSE
) ;
153 virtual bool Blit( long xdest
, long ydest
, long width
, long height
,
154 wxDC
*source
, long xsrc
, long ysrc
, int logical_func
= wxCOPY
, bool useMask
=FALSE
);
155 inline bool Blit(const wxPoint
& destPt
, const wxSize
& sz
,
156 wxDC
*source
, const wxPoint
& srcPt
, int rop
= wxCOPY
, bool useMask
= FALSE
)
158 return Blit(destPt
.x
, destPt
.y
, sz
.x
, sz
.y
, source
, srcPt
.x
, srcPt
.y
, rop
, useMask
);
161 virtual void DrawText( const wxString
&text
, long x
, long y
, bool use16
= FALSE
);
162 inline void DrawText(const wxString
& text
, const wxPoint
& pt
, bool use16bit
= FALSE
)
164 DrawText(text
, pt
.x
, pt
.y
, use16bit
);
167 virtual bool CanGetTextExtent(void) const ;
168 virtual void GetTextExtent( const wxString
&string
, long *width
, long *height
,
169 long *descent
= NULL
, long *externalLeading
= NULL
,
170 wxFont
*theFont
= NULL
, bool use16
= FALSE
) const ;
171 virtual void GetTextExtent( const wxString
&string
, int *width
, int *height
,
172 int *descent
= NULL
, int *externalLeading
= NULL
,
173 wxFont
*theFont
= NULL
, bool use16
= FALSE
) const
175 long lwidth
,lheight
,ldescent
,lexternal
;
176 GetTextExtent( string
, &lwidth
,&lheight
,&ldescent
,&lexternal
,theFont
,use16
) ;
179 if (descent
) *descent
= ldescent
;
180 if (externalLeading
) *externalLeading
= lexternal
;
182 virtual wxCoord
GetCharWidth(void) const;
183 virtual wxCoord
GetCharHeight(void) const;
185 virtual void Clear(void);
187 virtual void SetFont( const wxFont
&font
);
188 virtual wxFont
& GetFont(void) const { return (wxFont
&) m_font
; };
190 virtual void SetPen( const wxPen
&pen
);
191 virtual wxPen
& GetPen(void) const { return (wxPen
&) m_pen
; };
193 virtual void SetBrush( const wxBrush
&brush
);
194 virtual wxBrush
& GetBrush(void) const { return (wxBrush
&) m_brush
; };
196 virtual void SetBackground( const wxBrush
&brush
);
197 virtual wxBrush
& GetBackground(void) const { return (wxBrush
&) m_backgroundBrush
; };
199 virtual void SetLogicalFunction( int function
);
200 virtual int GetLogicalFunction(void) const { return m_logicalFunction
; };
202 virtual void SetTextForeground( const wxColour
&col
);
203 virtual void SetTextBackground( const wxColour
&col
);
204 virtual wxColour
& GetTextBackground(void) const { return (wxColour
&)m_textBackgroundColour
; };
205 virtual wxColour
& GetTextForeground(void) const { return (wxColour
&)m_textForegroundColour
; };
207 virtual void SetBackgroundMode( int mode
);
208 virtual int GetBackgroundMode(void) const { return m_backgroundMode
; };
210 virtual void SetPalette( const wxPalette
& palette
);
211 void SetColourMap( const wxPalette
& palette
) { SetPalette(palette
); };
213 // the first two must be overridden and called
214 virtual void SetClippingRegion( wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
215 virtual void SetClippingRegion( const wxRect
& rect
);
216 virtual void DestroyClippingRegion(void);
217 virtual void GetClippingBox( wxCoord
*x
, wxCoord
*y
, wxCoord
*width
, wxCoord
*height
) const;
218 virtual void GetClippingBox( long *x
, long *y
, long *width
, long *height
) const;
219 virtual void GetClippingBox(wxRect
& rect
) const;
221 virtual inline long MinX(void) const { return m_minX
; }
222 virtual inline long MaxX(void) const { return m_maxX
; }
223 virtual inline long MinY(void) const { return m_minY
; }
224 virtual inline long MaxY(void) const { return m_maxY
; }
226 virtual void GetSize( int* width
, int* height
) const;
227 inline wxSize
GetSize(void) const { int w
, h
; GetSize(&w
, &h
); return wxSize(w
, h
); }
228 virtual void GetSizeMM( long* width
, long* height
) const;
230 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return TRUE
; };
231 virtual void EndDoc(void) {};
232 virtual void StartPage(void) {};
233 virtual void EndPage(void) {};
235 virtual void SetMapMode( int mode
);
236 virtual int GetMapMode(void) const { return m_mappingMode
; };
238 virtual void SetUserScale( double x
, double y
);
239 virtual void GetUserScale( double *x
, double *y
);
240 virtual void SetLogicalScale( double x
, double y
);
241 virtual void GetLogicalScale( double *x
, double *y
);
243 virtual void SetLogicalOrigin( long x
, long y
);
244 virtual void GetLogicalOrigin( long *x
, long *y
);
245 virtual void SetDeviceOrigin( long x
, long y
);
246 virtual void GetDeviceOrigin( long *x
, long *y
);
247 virtual void SetInternalDeviceOrigin( long x
, long y
);
248 virtual void GetInternalDeviceOrigin( long *x
, long *y
);
250 virtual void SetAxisOrientation( bool xLeftRight
, bool yBottomUp
);
252 virtual void SetOptimization( bool WXUNUSED(optimize
) ) {};
253 virtual bool GetOptimization(void) { return m_optimize
; };
255 virtual long DeviceToLogicalX(long x
) const;
256 virtual long DeviceToLogicalY(long y
) const;
257 virtual long DeviceToLogicalXRel(long x
) const;
258 virtual long DeviceToLogicalYRel(long y
) const;
259 virtual long LogicalToDeviceX(long x
) const;
260 virtual long LogicalToDeviceY(long y
) const;
261 virtual long LogicalToDeviceXRel(long x
) const;
262 virtual long LogicalToDeviceYRel(long y
) const;
266 void CalcBoundingBox( long x
, long y
);
267 void ComputeScaleAndOrigin(void);
269 long XDEV2LOG(long x
) const
271 long new_x
= x
- m_deviceOriginX
;
273 return (long)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
275 return (long)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
277 long XDEV2LOGREL(long x
) const
280 return (long)((double)(x
) / m_scaleX
+ 0.5);
282 return (long)((double)(x
) / m_scaleX
- 0.5);
284 long YDEV2LOG(long y
) const
286 long new_y
= y
- m_deviceOriginY
;
288 return (long)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
290 return (long)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
292 long YDEV2LOGREL(long y
) const
295 return (long)((double)(y
) / m_scaleY
+ 0.5);
297 return (long)((double)(y
) / m_scaleY
- 0.5);
299 long XLOG2DEV(long x
) const
301 long new_x
= x
- m_logicalOriginX
;
303 return (long)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
305 return (long)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
307 long XLOG2DEVREL(long x
) const
310 return (long)((double)(x
) * m_scaleX
+ 0.5);
312 return (long)((double)(x
) * m_scaleX
- 0.5);
314 long YLOG2DEV(long y
) const
316 long new_y
= y
- m_logicalOriginY
;
318 return (long)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
320 return (long)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
322 long YLOG2DEVREL(long y
) const
325 return (long)((double)(y
) * m_scaleY
+ 0.5);
327 return (long)((double)(y
) * m_scaleY
- 0.5);
335 // not sure, what these mean
336 bool m_clipping
; // Is clipping on right now ?
337 bool m_isInteractive
; // Is GetPixel possible ?
338 bool m_autoSetting
; // wxMSW only ?
339 bool m_dontDelete
; // wxMSW only ?
340 bool m_optimize
; // wxMSW only ?
341 wxString m_filename
; // Not sure where this belongs.
345 wxBrush m_backgroundBrush
;
346 wxColour m_textForegroundColour
;
347 wxColour m_textBackgroundColour
;
350 int m_logicalFunction
;
351 int m_backgroundMode
;
352 int m_textAlignment
; // gone in wxWin 2.0 ?
356 // not sure what for, but what is a mm on a screen you don't know the size of?
357 double m_mm_to_pix_x
,m_mm_to_pix_y
;
359 long m_internalDeviceOriginX
,m_internalDeviceOriginY
; // If un-scrolled is non-zero or
360 // d.o. changes with scrolling.
361 // Set using SetInternalDeviceOrigin().
363 long m_externalDeviceOriginX
,m_externalDeviceOriginY
; // To be set by external classes
364 // such as wxScrolledWindow
365 // using SetDeviceOrigin()
367 long m_deviceOriginX
,m_deviceOriginY
; // Sum of the two above.
369 long m_logicalOriginX
,m_logicalOriginY
; // User defined.
371 double m_scaleX
,m_scaleY
;
372 double m_logicalScaleX
,m_logicalScaleY
;
373 double m_userScaleX
,m_userScaleY
;
374 long m_signX
,m_signY
;
376 bool m_needComputeScaleX
,m_needComputeScaleY
; // not yet used
378 float m_scaleFactor
; // wxPSDC wants to have this. Will disappear.
380 long m_clipX1
,m_clipY1
,m_clipX2
,m_clipY2
;
381 long m_minX
,m_maxX
,m_minY
,m_maxY
;
385 GWorldPtr m_macMask
;
387 // in order to preserve the const inheritance of the virtual functions, we have to
388 // use mutable variables starting from CWPro 5
390 void MacInstallFont() const ;
391 void MacInstallPen() const ;
392 void MacInstallBrush() const ;
394 mutable bool m_macFontInstalled
;
395 mutable bool m_macPenInstalled
;
396 mutable bool m_macBrushInstalled
;
398 mutable long m_macPortId
;
399 GrafPtr m_macOrigPort
;
401 Point m_macLocalOrigin
;
403 void MacSetupPort() const ;
404 void MacVerifySetup() const { if ( m_macPortId
!= m_macCurrentPortId
) MacSetupPort() ; }
406 static long m_macCurrentPortId
;