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