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