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