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
) ;
106 void ComputeScaleAndOrigin(void);
110 wxCoord
XDEV2LOG(wxCoord x
) const
112 long new_x
= x
- m_deviceOriginX
;
114 return (wxCoord
)((double)(new_x
) / m_scaleX
+ 0.5) * m_signX
+ m_logicalOriginX
;
116 return (wxCoord
)((double)(new_x
) / m_scaleX
- 0.5) * m_signX
+ m_logicalOriginX
;
118 wxCoord
XDEV2LOGREL(wxCoord x
) const
121 return (wxCoord
)((double)(x
) / m_scaleX
+ 0.5);
123 return (wxCoord
)((double)(x
) / m_scaleX
- 0.5);
125 wxCoord
YDEV2LOG(wxCoord y
) const
127 long new_y
= y
- m_deviceOriginY
;
129 return (wxCoord
)((double)(new_y
) / m_scaleY
+ 0.5) * m_signY
+ m_logicalOriginY
;
131 return (wxCoord
)((double)(new_y
) / m_scaleY
- 0.5) * m_signY
+ m_logicalOriginY
;
133 wxCoord
YDEV2LOGREL(wxCoord y
) const
136 return (wxCoord
)((double)(y
) / m_scaleY
+ 0.5);
138 return (wxCoord
)((double)(y
) / m_scaleY
- 0.5);
140 wxCoord
XLOG2DEV(wxCoord x
) const
142 long new_x
= x
- m_logicalOriginX
;
144 return (wxCoord
)((double)(new_x
) * m_scaleX
+ 0.5) * m_signX
+ m_deviceOriginX
;
146 return (wxCoord
)((double)(new_x
) * m_scaleX
- 0.5) * m_signX
+ m_deviceOriginX
;
148 wxCoord
XLOG2DEVREL(wxCoord x
) const
151 return (wxCoord
)((double)(x
) * m_scaleX
+ 0.5);
153 return (wxCoord
)((double)(x
) * m_scaleX
- 0.5);
155 wxCoord
YLOG2DEV(wxCoord y
) const
157 long new_y
= y
- m_logicalOriginY
;
159 return (wxCoord
)((double)(new_y
) * m_scaleY
+ 0.5) * m_signY
+ m_deviceOriginY
;
161 return (wxCoord
)((double)(new_y
) * m_scaleY
- 0.5) * m_signY
+ m_deviceOriginY
;
163 wxCoord
YLOG2DEVREL(wxCoord y
) const
166 return (wxCoord
)((double)(y
) * m_scaleY
+ 0.5);
168 return (wxCoord
)((double)(y
) * m_scaleY
- 0.5);
174 virtual void DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
175 int style
= wxFLOOD_SURFACE
);
177 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
179 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
180 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
182 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
183 wxCoord x2
, wxCoord y2
,
184 wxCoord xc
, wxCoord yc
);
186 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
187 double sa
, double ea
);
189 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
190 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
191 wxCoord width
, wxCoord height
,
193 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
195 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
197 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
198 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
199 bool useMask
= FALSE
);
201 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
202 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
205 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
206 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
207 int rop
= wxCOPY
, bool useMask
= FALSE
);
209 // this is gnarly - we can't even call this function DoSetClippingRegion()
210 // because of virtual function hiding
211 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
212 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
213 wxCoord width
, wxCoord height
);
214 virtual void DoGetClippingRegion(wxCoord
*x
, wxCoord
*y
,
215 wxCoord
*width
, wxCoord
*height
)
217 GetClippingBox(x
, y
, width
, height
);
220 virtual void DoGetSize(int *width
, int *height
) const;
221 virtual void DoGetSizeMM(int* width
, int* height
) const;
223 virtual void DoDrawLines(int n
, wxPoint points
[],
224 wxCoord xoffset
, wxCoord yoffset
);
225 virtual void DoDrawPolygon(int n
, wxPoint points
[],
226 wxCoord xoffset
, wxCoord yoffset
,
227 int fillStyle
= wxODDEVEN_RULE
);
235 double m_mm_to_pix_x
,m_mm_to_pix_y
;
236 bool m_needComputeScaleX
,m_needComputeScaleY
; // not yet used
237 long m_internalDeviceOriginX
,m_internalDeviceOriginY
; // If un-scrolled is non-zero or
238 // d.o. changes with scrolling.
239 // Set using SetInternalDeviceOrigin().
241 long m_externalDeviceOriginX
,m_externalDeviceOriginY
; // To be set by external classes
242 // such as wxScrolledWindow
243 // using SetDeviceOrigin()
245 GWorldPtr m_macMask
;
247 // in order to preserve the const inheritance of the virtual functions, we have to
248 // use mutable variables starting from CWPro 5
250 void MacInstallFont() const ;
251 void MacInstallPen() const ;
252 void MacInstallBrush() const ;
254 mutable bool m_macFontInstalled
;
255 mutable bool m_macPenInstalled
;
256 mutable bool m_macBrushInstalled
;
258 mutable long m_macPortId
;
259 GrafPtr m_macOrigPort
;
261 Point m_macLocalOrigin
;
262 mutable AGAPortHelper m_macPortHelper
;
263 void MacSetupPort() const ;
264 void MacVerifySetup() const { if ( m_macPortId
!= m_macCurrentPortId
) MacSetupPort() ; }
265 static void MacInvalidateSetup() { m_macCurrentPortId
++ ; }
266 static long m_macCurrentPortId
;