]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.h | |
3 | // Purpose: wxDC class | |
f0a56ab0 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
f0a56ab0 | 6 | // Created: 08/26/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
f0a56ab0 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_DC_H_ | |
13 | #define _WX_DC_H_ | |
14 | ||
fb46a9a6 | 15 | #include "wx/defs.h" |
0e320a79 | 16 | |
fb46a9a6 DW |
17 | // --------------------------------------------------------------------------- |
18 | // macros | |
19 | // --------------------------------------------------------------------------- | |
20 | ||
21 | // Logical to device | |
22 | // Absolute | |
23 | #define XLOG2DEV(x) (x) | |
24 | #define YLOG2DEV(y) (y) | |
25 | ||
26 | // Relative | |
27 | #define XLOG2DEVREL(x) (x) | |
28 | #define YLOG2DEVREL(y) (y) | |
29 | ||
30 | // Device to logical | |
31 | // Absolute | |
32 | #define XDEV2LOG(x) (x) | |
33 | ||
34 | #define YDEV2LOG(y) (y) | |
35 | ||
36 | // Relative | |
37 | #define XDEV2LOGREL(x) (x) | |
38 | #define YDEV2LOGREL(y) (y) | |
39 | ||
40 | /* | |
41 | * Have the same macros as for XView but not for every operation: | |
42 | * just for calculating window/viewport extent (a better way of scaling). | |
43 | */ | |
44 | ||
45 | // Logical to device | |
46 | // Absolute | |
47 | #define MS_XLOG2DEV(x) LogicalToDevice(x) | |
48 | ||
49 | #define MS_YLOG2DEV(y) LogicalToDevice(y) | |
50 | ||
51 | // Relative | |
52 | #define MS_XLOG2DEVREL(x) LogicalToDeviceXRel(x) | |
53 | #define MS_YLOG2DEVREL(y) LogicalToDeviceYRel(y) | |
54 | ||
55 | // Device to logical | |
56 | // Absolute | |
57 | #define MS_XDEV2LOG(x) DeviceToLogicalX(x) | |
58 | ||
59 | #define MS_YDEV2LOG(y) DeviceToLogicalY(y) | |
0e320a79 | 60 | |
fb46a9a6 DW |
61 | // Relative |
62 | #define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x) | |
63 | #define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y) | |
0e320a79 | 64 | |
fb46a9a6 | 65 | #define YSCALE(y) (yorigin - (y)) |
0e320a79 | 66 | |
fb46a9a6 | 67 | #define wx_round(a) (int)((a)+.5) |
0e320a79 | 68 | |
6835592c DW |
69 | #if wxUSE_DC_CACHEING |
70 | /* | |
71 | * Cached blitting, maintaining a cache | |
72 | * of bitmaps required for transparent blitting | |
73 | * instead of constant creation/deletion | |
74 | */ | |
75 | ||
76 | class wxDCCacheEntry : public wxObject | |
77 | { | |
78 | public: | |
79 | wxDCCacheEntry( WXHBITMAP hBitmap | |
80 | ,int nWidth | |
81 | ,int nHeight | |
82 | ,int nDepth | |
83 | ); | |
84 | wxDCCacheEntry( HPS hPS | |
85 | ,int nDepth | |
86 | ); | |
d3c7fc99 | 87 | virtual ~wxDCCacheEntry(); |
6835592c DW |
88 | |
89 | WXHBITMAP m_hBitmap; | |
90 | HPS m_hPS; | |
91 | int m_nWidth; | |
92 | int m_nHeight; | |
93 | int m_nDepth; | |
94 | }; // end of CLASS wxDCCacheEntry | |
95 | #endif | |
96 | ||
fb46a9a6 | 97 | class WXDLLEXPORT wxDC : public wxDCBase |
54da4255 | 98 | { |
fb46a9a6 | 99 | DECLARE_DYNAMIC_CLASS(wxDC) |
54da4255 | 100 | |
fb46a9a6 | 101 | public: |
d7e1a322 | 102 | wxDC(void); |
d3c7fc99 | 103 | virtual ~wxDC(); |
fb46a9a6 DW |
104 | |
105 | // implement base class pure virtuals | |
106 | // ---------------------------------- | |
107 | ||
f6bcfd97 BP |
108 | virtual void Clear(void); |
109 | ||
110 | virtual bool StartDoc(const wxString& rsMessage); | |
111 | virtual void EndDoc(void); | |
112 | ||
113 | virtual void StartPage(void); | |
114 | virtual void EndPage(void); | |
115 | ||
116 | virtual void SetFont(const wxFont& rFont); | |
117 | virtual void SetPen(const wxPen& rPen); | |
118 | virtual void SetBrush(const wxBrush& rBrush); | |
119 | virtual void SetBackground(const wxBrush& rBrush); | |
120 | virtual void SetBackgroundMode(int nMode); | |
121 | virtual void SetPalette(const wxPalette& rPalette); | |
122 | ||
123 | virtual void DestroyClippingRegion(void); | |
124 | ||
125 | virtual wxCoord GetCharHeight(void) const; | |
126 | virtual wxCoord GetCharWidth(void) const; | |
127 | virtual void DoGetTextExtent( const wxString& rsString | |
128 | ,wxCoord* pX | |
129 | ,wxCoord* pY | |
130 | ,wxCoord* pDescent = NULL | |
131 | ,wxCoord* pExternalLeading = NULL | |
951f68d0 | 132 | ,const wxFont* pTheFont = NULL |
f6bcfd97 BP |
133 | ) const; |
134 | virtual bool CanDrawBitmap(void) const; | |
135 | virtual bool CanGetTextExtent(void) const; | |
136 | virtual int GetDepth(void) const; | |
137 | virtual wxSize GetPPI(void) const; | |
138 | ||
139 | virtual void SetMapMode(int nMode); | |
140 | virtual void SetUserScale( double dX | |
141 | ,double dY | |
142 | ); | |
f6bcfd97 BP |
143 | virtual void SetLogicalScale( double dX |
144 | ,double dY | |
145 | ); | |
146 | virtual void SetLogicalOrigin( wxCoord vX | |
147 | ,wxCoord vY | |
148 | ); | |
149 | virtual void SetDeviceOrigin( wxCoord vX | |
150 | ,wxCoord vY | |
151 | ); | |
152 | virtual void SetAxisOrientation( bool bXLeftRight | |
153 | ,bool bYBottomUp | |
154 | ); | |
155 | virtual void SetLogicalFunction(int nFunction); | |
1408104d | 156 | |
fb46a9a6 DW |
157 | // implementation from now on |
158 | // -------------------------- | |
54da4255 | 159 | |
f6bcfd97 BP |
160 | virtual void SetRop(WXHDC hCdc); |
161 | virtual void SelectOldObjects(WXHDC hDc); | |
ce44c50e | 162 | |
f6bcfd97 BP |
163 | wxWindow* GetWindow(void) const { return m_pCanvas; } |
164 | void SetWindow(wxWindow* pWin) { m_pCanvas = pWin; } | |
ce44c50e | 165 | |
f6bcfd97 BP |
166 | WXHDC GetHDC(void) const { return m_hDC; } |
167 | void SetHDC( WXHDC hDc | |
168 | ,bool bOwnsDC = FALSE | |
169 | ) | |
ce44c50e | 170 | { |
f6bcfd97 | 171 | m_hDC = hDc; |
ce44c50e DW |
172 | m_bOwnsDC = bOwnsDC; |
173 | } | |
174 | ||
d8fcb5e8 DW |
175 | HPS GetHPS(void) const { return m_hPS; } |
176 | void SetHPS(HPS hPS) | |
177 | { | |
d8fcb5e8 DW |
178 | m_hPS = hPS; |
179 | } | |
f6bcfd97 BP |
180 | const wxBitmap& GetSelectedBitmap(void) const { return m_vSelectedBitmap; } |
181 | wxBitmap& GetSelectedBitmap(void) { return m_vSelectedBitmap; } | |
182 | ||
210a651b DW |
183 | void UpdateClipBox(); |
184 | ||
6835592c DW |
185 | #if wxUSE_DC_CACHEING |
186 | static wxDCCacheEntry* FindBitmapInCache( HPS hPS | |
187 | ,int nWidth | |
188 | ,int nHeight | |
189 | ); | |
190 | static wxDCCacheEntry* FindDCInCache( wxDCCacheEntry* pNotThis | |
191 | ,HPS hPS | |
192 | ); | |
193 | ||
194 | static void AddToBitmapCache(wxDCCacheEntry* pEntry); | |
195 | static void AddToDCCache(wxDCCacheEntry* pEntry); | |
196 | static void ClearCache(void); | |
197 | #endif | |
198 | ||
1408104d | 199 | protected: |
1d0edc0f | 200 | virtual bool DoFloodFill( wxCoord vX |
f6bcfd97 BP |
201 | ,wxCoord vY |
202 | ,const wxColour& rCol | |
203 | ,int nStyle = wxFLOOD_SURFACE | |
204 | ); | |
205 | ||
206 | virtual bool DoGetPixel( wxCoord vX | |
207 | ,wxCoord vY | |
208 | ,wxColour* pCol | |
209 | ) const; | |
210 | ||
211 | virtual void DoDrawPoint( wxCoord vX | |
212 | ,wxCoord vY | |
213 | ); | |
214 | virtual void DoDrawLine( wxCoord vX1 | |
215 | ,wxCoord vY1 | |
216 | ,wxCoord vX2 | |
217 | ,wxCoord vY2 | |
218 | ); | |
219 | ||
220 | virtual void DoDrawArc( wxCoord vX1 | |
221 | ,wxCoord vY1 | |
222 | ,wxCoord vX2 | |
223 | ,wxCoord vY2 | |
224 | ,wxCoord vXc | |
225 | ,wxCoord vYc | |
226 | ); | |
227 | virtual void DoDrawCheckMark( wxCoord vX | |
228 | ,wxCoord vY | |
229 | ,wxCoord vWidth | |
230 | ,wxCoord vHeight | |
231 | ); | |
232 | virtual void DoDrawEllipticArc( wxCoord vX | |
233 | ,wxCoord vY | |
234 | ,wxCoord vW | |
235 | ,wxCoord vH | |
236 | ,double dSa | |
237 | ,double dEa | |
238 | ); | |
239 | ||
240 | virtual void DoDrawRectangle( wxCoord vX | |
241 | ,wxCoord vY | |
242 | ,wxCoord vWidth | |
243 | ,wxCoord vHeight | |
244 | ); | |
245 | virtual void DoDrawRoundedRectangle( wxCoord vX | |
246 | ,wxCoord vY | |
247 | ,wxCoord vWidth | |
248 | ,wxCoord vHeight | |
249 | ,double dRadius | |
250 | ); | |
251 | virtual void DoDrawEllipse( wxCoord vX | |
252 | ,wxCoord vY | |
253 | ,wxCoord vWidth | |
254 | ,wxCoord vHeight | |
255 | ); | |
256 | ||
257 | virtual void DoCrossHair( wxCoord vX | |
258 | ,wxCoord vY | |
259 | ); | |
260 | ||
261 | virtual void DoDrawIcon( const wxIcon& rIcon | |
262 | ,wxCoord vX | |
263 | ,wxCoord vY | |
264 | ); | |
265 | virtual void DoDrawBitmap( const wxBitmap& rBmp | |
266 | ,wxCoord vX | |
267 | ,wxCoord vY | |
268 | ,bool bUseMask = FALSE | |
269 | ); | |
270 | ||
271 | virtual void DoDrawText( const wxString& rsText | |
272 | ,wxCoord vX | |
273 | ,wxCoord vY | |
274 | ); | |
275 | virtual void DoDrawRotatedText( const wxString& rsText | |
276 | ,wxCoord vX | |
277 | ,wxCoord vY | |
278 | ,double dAngle | |
279 | ); | |
280 | ||
281 | virtual bool DoBlit( wxCoord vXdest | |
282 | ,wxCoord vYdest | |
283 | ,wxCoord vWidth | |
284 | ,wxCoord vHeight | |
285 | ,wxDC* pSource | |
286 | ,wxCoord vXsrc | |
287 | ,wxCoord vYsrc | |
288 | ,int nRop = wxCOPY | |
289 | ,bool bUseMask = FALSE | |
6835592c DW |
290 | ,wxCoord vXsrcMask = -1 |
291 | ,wxCoord vYsrcMask = -1 | |
f6bcfd97 BP |
292 | ); |
293 | ||
294 | virtual void DoSetClippingRegionAsRegion(const wxRegion& rRegion); | |
295 | virtual void DoSetClippingRegion( wxCoord vX | |
296 | ,wxCoord vY | |
297 | ,wxCoord vWidth | |
298 | ,wxCoord vHeight | |
299 | ); | |
1408104d | 300 | |
f6bcfd97 BP |
301 | virtual void DoGetSize( int* pWidth |
302 | ,int* pHeight | |
303 | ) const; | |
304 | virtual void DoGetSizeMM( int* pWidth | |
305 | ,int* pHeight | |
306 | ) const; | |
307 | ||
308 | virtual void DoDrawLines( int n | |
309 | ,wxPoint vaPoints[] | |
310 | ,wxCoord vXoffset | |
311 | ,wxCoord yYoffset | |
312 | ); | |
313 | virtual void DoDrawPolygon( int n | |
314 | ,wxPoint vaPoints[] | |
315 | ,wxCoord vXoffset | |
316 | ,wxCoord vYoffset | |
317 | ,int nFillStyle = wxODDEVEN_RULE | |
318 | ); | |
fb46a9a6 | 319 | |
938aa9c4 DW |
320 | #if wxUSE_PALETTE |
321 | void DoSelectPalette(bool bRealize = FALSE); | |
322 | void InitializePalette(void); | |
323 | #endif // wxUSE_PALETTE | |
fb46a9a6 | 324 | |
f6bcfd97 BP |
325 | // |
326 | // common part of DoDrawText() and DoDrawRotatedText() | |
327 | // | |
328 | void DrawAnyText( const wxString& rsText | |
329 | ,wxCoord vX | |
330 | ,wxCoord vY | |
331 | ); | |
fb46a9a6 | 332 | |
f6bcfd97 BP |
333 | // OS2-specific member variables ?? do we even need this under OS/2? |
334 | int m_nWindowExtX; | |
335 | int m_nWindowExtY; | |
1408104d | 336 | |
f6bcfd97 BP |
337 | // |
338 | // the window associated with this DC (may be NULL) | |
339 | // | |
340 | wxWindow* m_pCanvas; | |
341 | wxBitmap m_vSelectedBitmap; | |
1408104d | 342 | |
d7e1a322 DW |
343 | public: |
344 | // PM specific stuff | |
345 | HPS m_hPS; | |
346 | HPS m_hOldPS; // old hPS, if any | |
347 | bool m_bIsPaintTime;// True at Paint Time | |
348 | ||
349 | RECTL m_vRclPaint; // Bounding rectangle at Paint time etc. | |
f6bcfd97 | 350 | // |
fb46a9a6 | 351 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it |
f6bcfd97 BP |
352 | // |
353 | bool m_bOwnsDC:1; | |
fb46a9a6 | 354 | |
f6bcfd97 | 355 | // |
ac7fb818 | 356 | // our HDC |
f6bcfd97 BP |
357 | // |
358 | WXHDC m_hDC; | |
1408104d | 359 | |
f6bcfd97 | 360 | // |
1408104d DW |
361 | // Store all old GDI objects when do a SelectObject, so we can select them |
362 | // back in (this unselecting user's objects) so we can safely delete the | |
363 | // DC. | |
f6bcfd97 BP |
364 | // |
365 | WXHBITMAP m_hOldBitmap; | |
366 | WXHPEN m_hOldPen; | |
367 | WXHBRUSH m_hOldBrush; | |
368 | WXHFONT m_hOldFont; | |
369 | WXHPALETTE m_hOldPalette; | |
6835592c DW |
370 | |
371 | #if wxUSE_DC_CACHEING | |
372 | static wxList m_svBitmapCache; | |
373 | static wxList m_svDCCache; | |
374 | #endif | |
375 | }; // end of CLASS wxDC | |
0e320a79 DW |
376 | #endif |
377 | // _WX_DC_H_ |