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