]>
Commit | Line | Data |
---|---|---|
8cf73271 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.h | |
3 | // Purpose: wxDC class | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
65571936 | 9 | // Licence: wxWindows licence |
8cf73271 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_DC_H_ | |
13 | #define _WX_DC_H_ | |
14 | ||
8cf73271 SC |
15 | #include "wx/pen.h" |
16 | #include "wx/brush.h" | |
17 | #include "wx/icon.h" | |
18 | #include "wx/font.h" | |
19 | #include "wx/gdicmn.h" | |
20 | ||
21 | //----------------------------------------------------------------------------- | |
22 | // constants | |
23 | //----------------------------------------------------------------------------- | |
24 | ||
25 | #ifndef MM_TEXT | |
26 | #define MM_TEXT 0 | |
27 | #define MM_ISOTROPIC 1 | |
28 | #define MM_ANISOTROPIC 2 | |
29 | #define MM_LOMETRIC 3 | |
30 | #define MM_HIMETRIC 4 | |
31 | #define MM_TWIPS 5 | |
32 | #define MM_POINTS 6 | |
33 | #define MM_METRIC 7 | |
34 | #endif | |
35 | ||
36 | //----------------------------------------------------------------------------- | |
37 | // global variables | |
38 | //----------------------------------------------------------------------------- | |
39 | ||
40 | extern int wxPageNumber; | |
41 | ||
42 | class wxMacPortStateHelper ; | |
20b69855 SC |
43 | |
44 | class WXDLLEXPORT wxGraphicPath | |
45 | { | |
46 | public : | |
47 | virtual ~wxGraphicPath() {} | |
48 | ||
49 | virtual void MoveToPoint( wxCoord x1 , wxCoord y1 ) = 0 ; | |
50 | ||
51 | virtual void AddLineToPoint( wxCoord x1 , wxCoord y1 ) = 0 ; | |
52 | ||
e828c96a SC |
53 | virtual void AddQuadCurveToPoint( wxCoord cx1, wxCoord cy1, wxCoord x1, wxCoord y1 ) = 0 ; |
54 | ||
20b69855 SC |
55 | virtual void AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) = 0 ; |
56 | ||
57 | virtual void AddCircle( wxCoord x, wxCoord y , wxCoord r ) = 0 ; | |
58 | ||
59 | virtual void CloseSubpath() = 0 ; | |
60 | } ; | |
61 | ||
62 | class WXDLLEXPORT wxGraphicContext | |
63 | { | |
64 | public: | |
65 | virtual ~wxGraphicContext() {} | |
66 | ||
67 | virtual void Clip( const wxRegion ®ion ) = 0 ; | |
68 | ||
69 | virtual void StrokePath( const wxGraphicPath *path ) = 0 ; | |
70 | ||
71 | virtual void DrawPath( const wxGraphicPath *path , int fillStyle = wxWINDING_RULE ) = 0 ; | |
72 | ||
73 | virtual void FillPath( const wxGraphicPath *path , const wxColor &fillColor , int fillStyle = wxWINDING_RULE ) = 0 ; | |
74 | ||
75 | virtual void SetPen( const wxPen &pen ) = 0 ; | |
76 | ||
77 | virtual void SetBrush( const wxBrush &brush ) = 0 ; | |
78 | ||
79 | virtual wxGraphicPath* CreatePath() = 0 ; | |
80 | } ; | |
81 | ||
8cf73271 SC |
82 | //----------------------------------------------------------------------------- |
83 | // wxDC | |
84 | //----------------------------------------------------------------------------- | |
85 | ||
86 | class WXDLLEXPORT wxDC: public wxDCBase | |
87 | { | |
88 | DECLARE_DYNAMIC_CLASS(wxDC) | |
89 | DECLARE_NO_COPY_CLASS(wxDC) | |
90 | ||
91 | public: | |
92 | ||
93 | wxDC(); | |
94 | ~wxDC(); | |
c5789d15 | 95 | |
8cf73271 SC |
96 | |
97 | // implement base class pure virtuals | |
98 | // ---------------------------------- | |
99 | ||
100 | virtual void Clear(); | |
101 | ||
b1263dcf | 102 | virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return true; } |
8cf73271 | 103 | virtual void EndDoc(void) {}; |
c5789d15 | 104 | |
8cf73271 SC |
105 | virtual void StartPage(void) {}; |
106 | virtual void EndPage(void) {}; | |
107 | ||
108 | virtual void SetFont(const wxFont& font); | |
109 | virtual void SetPen(const wxPen& pen); | |
110 | virtual void SetBrush(const wxBrush& brush); | |
111 | virtual void SetBackground(const wxBrush& brush); | |
112 | virtual void SetBackgroundMode(int mode); | |
113 | virtual void SetPalette(const wxPalette& palette); | |
114 | ||
115 | virtual void DestroyClippingRegion(); | |
116 | ||
117 | virtual wxCoord GetCharHeight() const; | |
118 | virtual wxCoord GetCharWidth() const; | |
119 | virtual void DoGetTextExtent(const wxString& string, | |
120 | wxCoord *x, wxCoord *y, | |
121 | wxCoord *descent = NULL, | |
122 | wxCoord *externalLeading = NULL, | |
123 | wxFont *theFont = NULL) const; | |
124 | virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; | |
125 | ||
126 | virtual bool CanDrawBitmap() const; | |
127 | virtual bool CanGetTextExtent() const; | |
128 | virtual int GetDepth() const; | |
129 | virtual wxSize GetPPI() const; | |
130 | ||
131 | virtual void SetMapMode(int mode); | |
132 | virtual void SetUserScale(double x, double y); | |
133 | ||
134 | virtual void SetLogicalScale(double x, double y); | |
135 | virtual void SetLogicalOrigin(wxCoord x, wxCoord y); | |
136 | virtual void SetDeviceOrigin(wxCoord x, wxCoord y); | |
137 | virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); | |
138 | virtual void SetLogicalFunction(int function); | |
139 | ||
140 | virtual void SetTextForeground(const wxColour& colour) ; | |
141 | virtual void SetTextBackground(const wxColour& colour) ; | |
142 | ||
b1263dcf | 143 | virtual void ComputeScaleAndOrigin(); |
c5789d15 | 144 | |
b1263dcf | 145 | public: |
c5789d15 | 146 | |
8cf73271 SC |
147 | wxCoord XDEV2LOG(wxCoord x) const |
148 | { | |
149 | long new_x = x - m_deviceOriginX ; | |
150 | if (new_x > 0) | |
151 | return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; | |
152 | else | |
153 | return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX; | |
154 | } | |
155 | wxCoord XDEV2LOGREL(wxCoord x) const | |
c5789d15 | 156 | { |
8cf73271 SC |
157 | if (x > 0) |
158 | return (wxCoord)((double)(x) / m_scaleX + 0.5); | |
159 | else | |
160 | return (wxCoord)((double)(x) / m_scaleX - 0.5); | |
161 | } | |
162 | wxCoord YDEV2LOG(wxCoord y) const | |
163 | { | |
164 | long new_y = y - m_deviceOriginY ; | |
165 | if (new_y > 0) | |
166 | return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; | |
167 | else | |
168 | return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY; | |
169 | } | |
170 | wxCoord YDEV2LOGREL(wxCoord y) const | |
c5789d15 | 171 | { |
8cf73271 SC |
172 | if (y > 0) |
173 | return (wxCoord)((double)(y) / m_scaleY + 0.5); | |
174 | else | |
175 | return (wxCoord)((double)(y) / m_scaleY - 0.5); | |
176 | } | |
177 | wxCoord XLOG2DEV(wxCoord x) const | |
c5789d15 | 178 | { |
8cf73271 SC |
179 | long new_x = x - m_logicalOriginX; |
180 | if (new_x > 0) | |
181 | return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX ; | |
182 | else | |
183 | return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX ; | |
184 | } | |
185 | wxCoord XLOG2DEVREL(wxCoord x) const | |
c5789d15 | 186 | { |
8cf73271 SC |
187 | if (x > 0) |
188 | return (wxCoord)((double)(x) * m_scaleX + 0.5); | |
189 | else | |
190 | return (wxCoord)((double)(x) * m_scaleX - 0.5); | |
191 | } | |
192 | wxCoord YLOG2DEV(wxCoord y) const | |
193 | { | |
194 | long new_y = y - m_logicalOriginY ; | |
195 | if (new_y > 0) | |
196 | return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY ; | |
197 | else | |
198 | return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY ; | |
199 | } | |
200 | wxCoord YLOG2DEVREL(wxCoord y) const | |
c5789d15 | 201 | { |
8cf73271 SC |
202 | if (y > 0) |
203 | return (wxCoord)((double)(y) * m_scaleY + 0.5); | |
204 | else | |
205 | return (wxCoord)((double)(y) * m_scaleY - 0.5); | |
206 | } | |
207 | wxCoord XLOG2DEVMAC(wxCoord x) const | |
c5789d15 | 208 | { |
8cf73271 SC |
209 | long new_x = x - m_logicalOriginX; |
210 | if (new_x > 0) | |
211 | return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x ; | |
212 | else | |
213 | return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x ; | |
214 | } | |
215 | wxCoord YLOG2DEVMAC(wxCoord y) const | |
216 | { | |
217 | long new_y = y - m_logicalOriginY ; | |
218 | if (new_y > 0) | |
219 | return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y ; | |
220 | else | |
221 | return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y ; | |
222 | } | |
71cc158e SC |
223 | #if wxMAC_USE_CORE_GRAPHICS |
224 | wxGraphicContext* GetGraphicContext() { return m_graphicContext ; } | |
225 | #else | |
8cf73271 SC |
226 | WXHRGN MacGetCurrentClipRgn() { return m_macCurrentClipRgn ; } |
227 | static void MacSetupBackgroundForCurrentPort(const wxBrush& background ) ; | |
20b69855 | 228 | #endif |
8cf73271 SC |
229 | // |
230 | ||
231 | protected: | |
232 | virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, | |
233 | int style = wxFLOOD_SURFACE); | |
234 | ||
235 | virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const; | |
236 | ||
237 | virtual void DoDrawPoint(wxCoord x, wxCoord y); | |
e828c96a SC |
238 | #if wxMAC_USE_CORE_GRAPHICS && wxUSE_SPLINES |
239 | virtual void DoDrawSpline(wxList *points); | |
240 | #endif | |
8cf73271 SC |
241 | virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); |
242 | ||
243 | virtual void DoDrawArc(wxCoord x1, wxCoord y1, | |
244 | wxCoord x2, wxCoord y2, | |
245 | wxCoord xc, wxCoord yc); | |
c5789d15 | 246 | |
8cf73271 SC |
247 | virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
248 | double sa, double ea); | |
249 | ||
250 | virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
251 | virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y, | |
252 | wxCoord width, wxCoord height, | |
253 | double radius); | |
254 | virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height); | |
255 | ||
256 | virtual void DoCrossHair(wxCoord x, wxCoord y); | |
257 | ||
258 | virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); | |
259 | virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, | |
b1263dcf | 260 | bool useMask = false); |
8cf73271 SC |
261 | |
262 | virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y); | |
263 | virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, | |
264 | double angle); | |
265 | ||
266 | virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, | |
267 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
b1263dcf | 268 | int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1); |
8cf73271 SC |
269 | |
270 | // this is gnarly - we can't even call this function DoSetClippingRegion() | |
271 | // because of virtual function hiding | |
272 | virtual void DoSetClippingRegionAsRegion(const wxRegion& region); | |
273 | virtual void DoSetClippingRegion(wxCoord x, wxCoord y, | |
274 | wxCoord width, wxCoord height); | |
8cf73271 SC |
275 | |
276 | virtual void DoGetSizeMM(int* width, int* height) const; | |
277 | ||
278 | virtual void DoDrawLines(int n, wxPoint points[], | |
279 | wxCoord xoffset, wxCoord yoffset); | |
280 | virtual void DoDrawPolygon(int n, wxPoint points[], | |
281 | wxCoord xoffset, wxCoord yoffset, | |
282 | int fillStyle = wxODDEVEN_RULE); | |
283 | ||
284 | protected: | |
285 | //begin wxmac | |
286 | // Variables used for scaling | |
c5789d15 | 287 | double m_mm_to_pix_x,m_mm_to_pix_y; |
8cf73271 | 288 | // not yet used |
c5789d15 | 289 | bool m_needComputeScaleX,m_needComputeScaleY; |
8cf73271 SC |
290 | // If un-scrolled is non-zero or d.o. changes with scrolling. |
291 | // Set using SetInternalDeviceOrigin(). | |
292 | long m_internalDeviceOriginX,m_internalDeviceOriginY; | |
293 | // To be set by external classes such as wxScrolledWindow | |
294 | // using SetDeviceOrigin() | |
295 | long m_externalDeviceOriginX,m_externalDeviceOriginY; | |
c5789d15 | 296 | |
8cf73271 SC |
297 | // Begin implementation for Mac |
298 | public: | |
c5789d15 | 299 | |
20b69855 | 300 | #if !wxMAC_USE_CORE_GRAPHICS |
8cf73271 | 301 | WXHBITMAP m_macMask ; |
20b69855 | 302 | #endif |
8cf73271 | 303 | |
c5789d15 | 304 | // in order to preserve the const inheritance of the virtual functions, we have to |
8cf73271 SC |
305 | // use mutable variables starting from CWPro 5 |
306 | ||
307 | void MacInstallFont() const ; | |
20b69855 | 308 | #if !wxMAC_USE_CORE_GRAPHICS |
8cf73271 SC |
309 | void MacInstallPen() const ; |
310 | void MacInstallBrush() const ; | |
20b69855 SC |
311 | #endif |
312 | ||
ddb08e02 | 313 | wxPoint m_macLocalOrigin ; |
20b69855 | 314 | mutable void* m_macATSUIStyle ; |
8cf73271 | 315 | |
ddb08e02 | 316 | WXHDC m_macPort ; |
20b69855 SC |
317 | #if wxMAC_USE_CORE_GRAPHICS |
318 | // CoreGraphics | |
319 | wxGraphicContext * m_graphicContext ; | |
880f5369 | 320 | wxPoint m_macLocalOriginInPort ; |
20b69855 | 321 | #else |
880f5369 SC |
322 | mutable bool m_macFontInstalled ; |
323 | mutable bool m_macPenInstalled ; | |
324 | mutable bool m_macBrushInstalled ; | |
325 | ||
326 | WXHRGN m_macBoundaryClipRgn ; | |
327 | WXHRGN m_macCurrentClipRgn ; | |
328 | void MacSetupPort( wxMacPortStateHelper* ph ) const ; | |
329 | void MacCleanupPort( wxMacPortStateHelper* ph ) const ; | |
8cf73271 SC |
330 | mutable wxMacPortStateHelper* m_macCurrentPortStateHelper ; |
331 | mutable bool m_macFormerAliasState ; | |
332 | mutable short m_macFormerAliasSize ; | |
333 | mutable bool m_macAliasWasEnabled ; | |
334 | mutable void* m_macForegroundPixMap ; | |
335 | mutable void* m_macBackgroundPixMap ; | |
20b69855 | 336 | #endif |
613a24f7 | 337 | |
20b69855 SC |
338 | #if wxMAC_USE_CORE_GRAPHICS |
339 | #endif | |
8cf73271 SC |
340 | }; |
341 | ||
342 | #endif | |
343 | // _WX_DC_H_ |