1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dc.h"
23 #include "wx/gdicmn.h"
24 #include "wx/mac/aga.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
32 #define MM_ISOTROPIC 1
33 #define MM_ANISOTROPIC 2
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 extern int wxPageNumber
;
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 class WXDLLEXPORT wxDC
: public wxDCBase
53 DECLARE_DYNAMIC_CLASS(wxDC
)
61 // implement base class pure virtuals
62 // ----------------------------------
66 virtual bool StartDoc( const wxString
& WXUNUSED(message
) ) { return TRUE
; };
67 virtual void EndDoc(void) {};
69 virtual void StartPage(void) {};
70 virtual void EndPage(void) {};
72 virtual void SetFont(const wxFont
& font
);
73 virtual void SetPen(const wxPen
& pen
);
74 virtual void SetBrush(const wxBrush
& brush
);
75 virtual void SetBackground(const wxBrush
& brush
);
76 virtual void SetBackgroundMode(int mode
);
77 virtual void SetPalette(const wxPalette
& palette
);
79 virtual void DestroyClippingRegion();
81 virtual wxCoord
GetCharHeight() const;
82 virtual wxCoord
GetCharWidth() const;
83 virtual void DoGetTextExtent(const wxString
& string
,
84 wxCoord
*x
, wxCoord
*y
,
85 wxCoord
*descent
= NULL
,
86 wxCoord
*externalLeading
= NULL
,
87 wxFont
*theFont
= NULL
) const;
89 virtual bool CanDrawBitmap() const;
90 virtual bool CanGetTextExtent() const;
91 virtual int GetDepth() const;
92 virtual wxSize
GetPPI() const;
94 virtual void SetMapMode(int mode
);
95 virtual void SetUserScale(double x
, double y
);
97 virtual void SetLogicalScale(double x
, double y
);
98 virtual void SetLogicalOrigin(wxCoord x
, wxCoord y
);
99 virtual void SetDeviceOrigin(wxCoord x
, wxCoord y
);
100 virtual void SetAxisOrientation(bool xLeftRight
, bool yBottomUp
);
101 virtual void SetLogicalFunction(int function
);
103 virtual void SetTextForeground(const wxColour
& colour
) ;
104 virtual void SetTextBackground(const wxColour
& colour
) ;
110 void BeginDrawing(void) {};
111 void EndDrawing(void) {};
113 virtual bool Ok(void) const { return m_ok; };
115 virtual void FloodFill( long x1, long y1, const wxColour& col, int style=wxFLOOD_SURFACE );
116 inline void FloodFill(const wxPoint& pt, const wxColour& col, int style=wxFLOOD_SURFACE)
118 FloodFill(pt.x, pt.y, col, style);
121 virtual bool GetPixel( long x1, long y1, wxColour *col ) const ;
122 inline bool GetPixel(const wxPoint& pt, wxColour *col) const
124 return GetPixel(pt.x, pt.y, col);
127 virtual void DrawLine( long x1, long y1, long x2, long y2 );
128 inline void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
130 DrawLine(pt1.x, pt1.y, pt2.x, pt2.y);
133 virtual void CrossHair( long x, long y );
134 inline void CrossHair(const wxPoint& pt)
136 CrossHair(pt.x, pt.y);
139 virtual void DrawArc( long x1, long y1, long x2, long y2, long xc, long yc );
140 inline void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
142 DrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y);
145 virtual void DrawEllipticArc( long x, long y, long width, long height, double sa, double ea );
146 virtual void DrawEllipticArc (const wxPoint& pt, const wxSize& sz, double sa, double ea)
148 DrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea);
151 virtual void DrawPoint( long x, long y );
152 virtual void DrawPoint( wxPoint& point );
154 virtual void DrawLines( int n, wxPoint points[], long xoffset = 0, long yoffset = 0 );
155 virtual void DrawLines( wxList *points, long xoffset = 0, long yoffset = 0 );
156 virtual void DrawPolygon( int n, wxPoint points[], long xoffset = 0, long yoffset = 0,
157 int fillStyle=wxODDEVEN_RULE );
158 virtual void DrawPolygon( wxList *lines, long xoffset = 0, long yoffset = 0,
159 int fillStyle=wxODDEVEN_RULE );
161 virtual void DrawRectangle( long x, long y, long width, long height );
162 inline void DrawRectangle(const wxPoint& pt, const wxSize& sz)
164 DrawRectangle(pt.x, pt.y, sz.x, sz.y);
166 inline void DrawRectangle(const wxRect& rect)
168 DrawRectangle(rect.x, rect.y, rect.width, rect.height);
170 virtual void DrawRoundedRectangle( long x, long y, long width, long height, double radius = 20.0 );
171 inline void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius = 20.0)
173 DrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius);
175 inline void DrawRoundedRectangle(const wxRect& rect, double radius = 20.0)
177 DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, radius);
180 virtual void DrawEllipse( long x, long y, long width, long height );
181 inline void DrawEllipse(const wxPoint& pt, const wxSize& sz)
183 DrawEllipse(pt.x, pt.y, sz.x, sz.y);
185 inline void DrawEllipse(const wxRect& rect)
187 DrawEllipse(rect.x, rect.y, rect.width, rect.height);
190 virtual void DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 );
191 virtual void DrawSpline( wxList *points );
192 virtual void DrawSpline( int n, wxPoint points[] );
194 virtual bool CanDrawBitmap(void) const ;
196 virtual void DrawIcon( const wxIcon &icon, long x, long y, bool useMask=FALSE );
197 inline void DrawIcon(const wxIcon& icon, const wxPoint& pt)
199 DrawIcon(icon, pt.x, pt.y);
202 void DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask=FALSE ) ;
204 virtual bool Blit( long xdest, long ydest, long width, long height,
205 wxDC *source, long xsrc, long ysrc, int logical_func = wxCOPY, bool useMask=FALSE );
206 inline bool Blit(const wxPoint& destPt, const wxSize& sz,
207 wxDC *source, const wxPoint& srcPt, int rop = wxCOPY, bool useMask = FALSE)
209 return Blit(destPt.x, destPt.y, sz.x, sz.y, source, srcPt.x, srcPt.y, rop, useMask);
212 virtual void DrawText( const wxString &text, long x, long y, bool use16 = FALSE );
213 inline void DrawText(const wxString& text, const wxPoint& pt, bool use16bit = FALSE)
215 DrawText(text, pt.x, pt.y, use16bit);
218 virtual bool CanGetTextExtent(void) const ;
219 virtual void GetTextExtent( const wxString &string, int *width, int *height,
220 int *descent = NULL, int *externalLeading = NULL,
221 wxFont *theFont = NULL, bool use16 = FALSE ) const ;
222 virtual wxCoord GetCharWidth(void) const;
223 virtual wxCoord GetCharHeight(void) const;
225 virtual void Clear(void);
227 virtual void SetFont( const wxFont &font );
228 virtual wxFont& GetFont(void) const { return (wxFont&) m_font; };
230 virtual void SetPen( const wxPen &pen );
231 virtual wxPen& GetPen(void) const { return (wxPen&) m_pen; };
233 virtual void SetBrush( const wxBrush &brush );
234 virtual wxBrush& GetBrush(void) const { return (wxBrush&) m_brush; };
236 virtual void SetBackground( const wxBrush &brush );
237 virtual wxBrush& GetBackground(void) const { return (wxBrush&) m_backgroundBrush; };
239 virtual void SetLogicalFunction( int function );
240 virtual int GetLogicalFunction(void) const { return m_logicalFunction; };
242 virtual void SetTextForeground( const wxColour &col );
243 virtual void SetTextBackground( const wxColour &col );
244 virtual wxColour& GetTextBackground(void) const { return (wxColour&)m_textBackgroundColour; };
245 virtual wxColour& GetTextForeground(void) const { return (wxColour&)m_textForegroundColour; };
247 virtual void SetBackgroundMode( int mode );
248 virtual int GetBackgroundMode(void) const { return m_backgroundMode; };
250 virtual void SetPalette( const wxPalette& palette );
251 void SetColourMap( const wxPalette& palette ) { SetPalette(palette); };
253 // the first two must be overridden and called
254 virtual void SetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
255 virtual void SetClippingRegion( const wxRect& rect );
256 virtual void DestroyClippingRegion(void);
257 virtual void GetClippingBox( wxCoord *x, wxCoord *y, wxCoord *width, wxCoord *height ) const;
258 virtual void GetClippingBox( long *x, long *y, long *width, long *height ) const;
259 virtual void GetClippingBox(wxRect& rect) const;
261 virtual inline long MinX(void) const { return m_minX; }
262 virtual inline long MaxX(void) const { return m_maxX; }
263 virtual inline long MinY(void) const { return m_minY; }
264 virtual inline long MaxY(void) const { return m_maxY; }
266 virtual void GetSize( int* width, int* height ) const;
267 inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); }
268 virtual void GetSizeMM( long* width, long* height ) const;
271 virtual int GetMapMode(void) const { return m_mappingMode; };
273 virtual void GetUserScale( double *x, double *y );
274 virtual void GetLogicalScale( double *x, double *y );
276 virtual void GetLogicalOrigin( long *x, long *y );
277 virtual void GetDeviceOrigin( long *x, long *y );
278 virtual void SetInternalDeviceOrigin( long x, long y );
279 virtual void GetInternalDeviceOrigin( long *x, long *y );
281 virtual void SetOptimization( bool WXUNUSED(optimize) ) {};
282 virtual bool GetOptimization(void) { return m_optimize; };
284 virtual long DeviceToLogicalX(long x) const;
285 virtual long DeviceToLogicalY(long y) const;
286 virtual long DeviceToLogicalXRel(long x) const;
287 virtual long DeviceToLogicalYRel(long y) const;
288 virtual long LogicalToDeviceX(long x) const;
289 virtual long LogicalToDeviceY(long y) const;
290 virtual long LogicalToDeviceXRel(long x) const;
291 virtual long LogicalToDeviceYRel(long y) const;
293 void CalcBoundingBox( long x, long y );
296 void ComputeScaleAndOrigin(void);
300 wxCoord
XDEV2LOG(wxCoord x
) const
302 long new_x
= x
- m_deviceOriginX
;
304 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
306 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
308 wxCoord
XDEV2LOGREL(wxCoord x
) const
311 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
313 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
315 wxCoord
YDEV2LOG(wxCoord y
) const
317 long new_y
= y
- m_deviceOriginY
;
319 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
321 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
323 wxCoord
YDEV2LOGREL(wxCoord y
) const
326 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
328 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
330 wxCoord
XLOG2DEV(wxCoord x
) const
332 long new_x
= x
- m_logicalOriginX
;
334 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
336 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
338 wxCoord
XLOG2DEVREL(wxCoord x
) const
341 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
343 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
345 wxCoord
YLOG2DEV(wxCoord y
) const
347 long new_y
= y
- m_logicalOriginY
;
349 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
351 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
353 wxCoord
YLOG2DEVREL(wxCoord y
) const
356 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
358 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
364 virtual void DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
365 int style
= wxFLOOD_SURFACE
);
367 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
369 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
370 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
372 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
373 wxCoord x2
, wxCoord y2
,
374 wxCoord xc
, wxCoord yc
);
376 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
377 double sa
, double ea
);
379 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
380 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
381 wxCoord width
, wxCoord height
,
383 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
385 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
387 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
388 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
389 bool useMask
= FALSE
);
391 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
392 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
395 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
396 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
397 int rop
= wxCOPY
, bool useMask
= FALSE
);
399 // this is gnarly - we can't even call this function DoSetClippingRegion()
400 // because of virtual function hiding
401 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
402 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
403 wxCoord width
, wxCoord height
);
404 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
405 wxCoord
*width
, wxCoord
*height
)
407 GetClippingBox(x
, y
, width
, height
);
410 virtual void DoGetSize(int *width
, int *height
) const;
411 virtual void DoGetSizeMM(int* width
, int* height
) const;
413 virtual void DoDrawLines(int n
, wxPoint points
[],
414 wxCoord xoffset
, wxCoord yoffset
);
415 virtual void DoDrawPolygon(int n
, wxPoint points
[],
416 wxCoord xoffset
, wxCoord yoffset
,
417 int fillStyle
= wxODDEVEN_RULE
);
420 virtual void DoDrawSpline(wxList
*points
);
421 #endif // wxUSE_SPLINES
428 double m_mm_to_pix_x
,m_mm_to_pix_y
;
429 bool m_needComputeScaleX
,m_needComputeScaleY
; // not yet used
430 long m_internalDeviceOriginX
,m_internalDeviceOriginY
; // If un-scrolled is non-zero or
431 // d.o. changes with scrolling.
432 // Set using SetInternalDeviceOrigin().
434 long m_externalDeviceOriginX
,m_externalDeviceOriginY
; // To be set by external classes
435 // such as wxScrolledWindow
436 // using SetDeviceOrigin()
438 GWorldPtr m_macMask
;
440 // in order to preserve the const inheritance of the virtual functions, we have to
441 // use mutable variables starting from CWPro 5
443 void MacInstallFont() const ;
444 void MacInstallPen() const ;
445 void MacInstallBrush() const ;
447 mutable bool m_macFontInstalled
;
448 mutable bool m_macPenInstalled
;
449 mutable bool m_macBrushInstalled
;
451 mutable long m_macPortId
;
452 GrafPtr m_macOrigPort
;
454 Point m_macLocalOrigin
;
455 mutable AGAPortHelper m_macPortHelper
;
456 void MacSetupPort() const ;
457 void MacVerifySetup() const { if ( m_macPortId
!= m_macCurrentPortId
) MacSetupPort() ; }
458 static void MacInvalidateSetup() { m_macCurrentPortId
++ ; }
459 static long m_macCurrentPortId
;