]>
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 | ); | |
87 | ~wxDCCacheEntry(); | |
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); |
fb46a9a6 DW |
103 | ~wxDC(); |
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 | |
132 | ,wxFont* pTheFont = NULL | |
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 | ); | |
143 | virtual void SetSystemScale( double dX | |
144 | ,double dY | |
145 | ); | |
146 | virtual void SetLogicalScale( double dX | |
147 | ,double dY | |
148 | ); | |
149 | virtual void SetLogicalOrigin( wxCoord vX | |
150 | ,wxCoord vY | |
151 | ); | |
152 | virtual void SetDeviceOrigin( wxCoord vX | |
153 | ,wxCoord vY | |
154 | ); | |
155 | virtual void SetAxisOrientation( bool bXLeftRight | |
156 | ,bool bYBottomUp | |
157 | ); | |
158 | virtual void SetLogicalFunction(int nFunction); | |
1408104d | 159 | |
fb46a9a6 DW |
160 | // implementation from now on |
161 | // -------------------------- | |
54da4255 | 162 | |
f6bcfd97 BP |
163 | virtual void SetRop(WXHDC hCdc); |
164 | virtual void SelectOldObjects(WXHDC hDc); | |
ce44c50e | 165 | |
f6bcfd97 BP |
166 | wxWindow* GetWindow(void) const { return m_pCanvas; } |
167 | void SetWindow(wxWindow* pWin) { m_pCanvas = pWin; } | |
ce44c50e | 168 | |
f6bcfd97 BP |
169 | WXHDC GetHDC(void) const { return m_hDC; } |
170 | void SetHDC( WXHDC hDc | |
171 | ,bool bOwnsDC = FALSE | |
172 | ) | |
ce44c50e | 173 | { |
f6bcfd97 | 174 | m_hDC = hDc; |
ce44c50e DW |
175 | m_bOwnsDC = bOwnsDC; |
176 | } | |
177 | ||
d8fcb5e8 DW |
178 | HPS GetHPS(void) const { return m_hPS; } |
179 | void SetHPS(HPS hPS) | |
180 | { | |
d8fcb5e8 DW |
181 | m_hPS = hPS; |
182 | } | |
f6bcfd97 BP |
183 | const wxBitmap& GetSelectedBitmap(void) const { return m_vSelectedBitmap; } |
184 | wxBitmap& GetSelectedBitmap(void) { return m_vSelectedBitmap; } | |
185 | ||
210a651b DW |
186 | void UpdateClipBox(); |
187 | ||
6835592c DW |
188 | #if wxUSE_DC_CACHEING |
189 | static wxDCCacheEntry* FindBitmapInCache( HPS hPS | |
190 | ,int nWidth | |
191 | ,int nHeight | |
192 | ); | |
193 | static wxDCCacheEntry* FindDCInCache( wxDCCacheEntry* pNotThis | |
194 | ,HPS hPS | |
195 | ); | |
196 | ||
197 | static void AddToBitmapCache(wxDCCacheEntry* pEntry); | |
198 | static void AddToDCCache(wxDCCacheEntry* pEntry); | |
199 | static void ClearCache(void); | |
200 | #endif | |
201 | ||
1408104d | 202 | protected: |
1d0edc0f | 203 | virtual bool DoFloodFill( wxCoord vX |
f6bcfd97 BP |
204 | ,wxCoord vY |
205 | ,const wxColour& rCol | |
206 | ,int nStyle = wxFLOOD_SURFACE | |
207 | ); | |
208 | ||
209 | virtual bool DoGetPixel( wxCoord vX | |
210 | ,wxCoord vY | |
211 | ,wxColour* pCol | |
212 | ) const; | |
213 | ||
214 | virtual void DoDrawPoint( wxCoord vX | |
215 | ,wxCoord vY | |
216 | ); | |
217 | virtual void DoDrawLine( wxCoord vX1 | |
218 | ,wxCoord vY1 | |
219 | ,wxCoord vX2 | |
220 | ,wxCoord vY2 | |
221 | ); | |
222 | ||
223 | virtual void DoDrawArc( wxCoord vX1 | |
224 | ,wxCoord vY1 | |
225 | ,wxCoord vX2 | |
226 | ,wxCoord vY2 | |
227 | ,wxCoord vXc | |
228 | ,wxCoord vYc | |
229 | ); | |
230 | virtual void DoDrawCheckMark( wxCoord vX | |
231 | ,wxCoord vY | |
232 | ,wxCoord vWidth | |
233 | ,wxCoord vHeight | |
234 | ); | |
235 | virtual void DoDrawEllipticArc( wxCoord vX | |
236 | ,wxCoord vY | |
237 | ,wxCoord vW | |
238 | ,wxCoord vH | |
239 | ,double dSa | |
240 | ,double dEa | |
241 | ); | |
242 | ||
243 | virtual void DoDrawRectangle( wxCoord vX | |
244 | ,wxCoord vY | |
245 | ,wxCoord vWidth | |
246 | ,wxCoord vHeight | |
247 | ); | |
248 | virtual void DoDrawRoundedRectangle( wxCoord vX | |
249 | ,wxCoord vY | |
250 | ,wxCoord vWidth | |
251 | ,wxCoord vHeight | |
252 | ,double dRadius | |
253 | ); | |
254 | virtual void DoDrawEllipse( wxCoord vX | |
255 | ,wxCoord vY | |
256 | ,wxCoord vWidth | |
257 | ,wxCoord vHeight | |
258 | ); | |
259 | ||
260 | virtual void DoCrossHair( wxCoord vX | |
261 | ,wxCoord vY | |
262 | ); | |
263 | ||
264 | virtual void DoDrawIcon( const wxIcon& rIcon | |
265 | ,wxCoord vX | |
266 | ,wxCoord vY | |
267 | ); | |
268 | virtual void DoDrawBitmap( const wxBitmap& rBmp | |
269 | ,wxCoord vX | |
270 | ,wxCoord vY | |
271 | ,bool bUseMask = FALSE | |
272 | ); | |
273 | ||
274 | virtual void DoDrawText( const wxString& rsText | |
275 | ,wxCoord vX | |
276 | ,wxCoord vY | |
277 | ); | |
278 | virtual void DoDrawRotatedText( const wxString& rsText | |
279 | ,wxCoord vX | |
280 | ,wxCoord vY | |
281 | ,double dAngle | |
282 | ); | |
283 | ||
284 | virtual bool DoBlit( wxCoord vXdest | |
285 | ,wxCoord vYdest | |
286 | ,wxCoord vWidth | |
287 | ,wxCoord vHeight | |
288 | ,wxDC* pSource | |
289 | ,wxCoord vXsrc | |
290 | ,wxCoord vYsrc | |
291 | ,int nRop = wxCOPY | |
292 | ,bool bUseMask = FALSE | |
6835592c DW |
293 | ,wxCoord vXsrcMask = -1 |
294 | ,wxCoord vYsrcMask = -1 | |
f6bcfd97 BP |
295 | ); |
296 | ||
297 | virtual void DoSetClippingRegionAsRegion(const wxRegion& rRegion); | |
298 | virtual void DoSetClippingRegion( wxCoord vX | |
299 | ,wxCoord vY | |
300 | ,wxCoord vWidth | |
301 | ,wxCoord vHeight | |
302 | ); | |
303 | virtual void DoGetClippingRegion( wxCoord* pX | |
304 | ,wxCoord* pY | |
305 | ,wxCoord* pWidth | |
306 | ,wxCoord* pHeight) | |
fb46a9a6 | 307 | { |
f6bcfd97 BP |
308 | GetClippingBox( pX |
309 | ,pY | |
310 | ,pWidth | |
311 | ,pHeight | |
312 | ); | |
fb46a9a6 | 313 | } |
1408104d | 314 | |
f6bcfd97 BP |
315 | virtual void DoGetSize( int* pWidth |
316 | ,int* pHeight | |
317 | ) const; | |
318 | virtual void DoGetSizeMM( int* pWidth | |
319 | ,int* pHeight | |
320 | ) const; | |
321 | ||
322 | virtual void DoDrawLines( int n | |
323 | ,wxPoint vaPoints[] | |
324 | ,wxCoord vXoffset | |
325 | ,wxCoord yYoffset | |
326 | ); | |
327 | virtual void DoDrawPolygon( int n | |
328 | ,wxPoint vaPoints[] | |
329 | ,wxCoord vXoffset | |
330 | ,wxCoord vYoffset | |
331 | ,int nFillStyle = wxODDEVEN_RULE | |
332 | ); | |
fb46a9a6 | 333 | |
938aa9c4 DW |
334 | #if wxUSE_PALETTE |
335 | void DoSelectPalette(bool bRealize = FALSE); | |
336 | void InitializePalette(void); | |
337 | #endif // wxUSE_PALETTE | |
fb46a9a6 | 338 | |
f6bcfd97 BP |
339 | // |
340 | // common part of DoDrawText() and DoDrawRotatedText() | |
341 | // | |
342 | void DrawAnyText( const wxString& rsText | |
343 | ,wxCoord vX | |
344 | ,wxCoord vY | |
345 | ); | |
fb46a9a6 | 346 | |
f6bcfd97 BP |
347 | // OS2-specific member variables ?? do we even need this under OS/2? |
348 | int m_nWindowExtX; | |
349 | int m_nWindowExtY; | |
1408104d | 350 | |
f6bcfd97 BP |
351 | // |
352 | // the window associated with this DC (may be NULL) | |
353 | // | |
354 | wxWindow* m_pCanvas; | |
355 | wxBitmap m_vSelectedBitmap; | |
1408104d | 356 | |
d7e1a322 DW |
357 | public: |
358 | // PM specific stuff | |
359 | HPS m_hPS; | |
360 | HPS m_hOldPS; // old hPS, if any | |
361 | bool m_bIsPaintTime;// True at Paint Time | |
362 | ||
363 | RECTL m_vRclPaint; // Bounding rectangle at Paint time etc. | |
f6bcfd97 | 364 | // |
fb46a9a6 | 365 | // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it |
f6bcfd97 BP |
366 | // |
367 | bool m_bOwnsDC:1; | |
fb46a9a6 | 368 | |
f6bcfd97 | 369 | // |
ac7fb818 | 370 | // our HDC |
f6bcfd97 BP |
371 | // |
372 | WXHDC m_hDC; | |
1408104d | 373 | |
f6bcfd97 | 374 | // |
1408104d DW |
375 | // Store all old GDI objects when do a SelectObject, so we can select them |
376 | // back in (this unselecting user's objects) so we can safely delete the | |
377 | // DC. | |
f6bcfd97 BP |
378 | // |
379 | WXHBITMAP m_hOldBitmap; | |
380 | WXHPEN m_hOldPen; | |
381 | WXHBRUSH m_hOldBrush; | |
382 | WXHFONT m_hOldFont; | |
383 | WXHPALETTE m_hOldPalette; | |
6835592c DW |
384 | |
385 | #if wxUSE_DC_CACHEING | |
386 | static wxList m_svBitmapCache; | |
387 | static wxList m_svDCCache; | |
388 | #endif | |
389 | }; // end of CLASS wxDC | |
0e320a79 DW |
390 | #endif |
391 | // _WX_DC_H_ |