]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/dc.h
Allow OS X Cocoa (or any OS X port) to override GetBestSize and provide a native...
[wxWidgets.git] / include / wx / os2 / dc.h
CommitLineData
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"
2c24e7ad 16#include "wx/dc.h"
0e320a79 17
fb46a9a6
DW
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)
0e320a79 61
fb46a9a6
DW
62// Relative
63#define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x)
64#define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y)
0e320a79 65
fb46a9a6 66#define YSCALE(y) (yorigin - (y))
0e320a79 67
fb46a9a6 68#define wx_round(a) (int)((a)+.5)
0e320a79 69
6835592c
DW
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
77class wxDCCacheEntry : public wxObject
78{
79public:
80 wxDCCacheEntry( WXHBITMAP hBitmap
81 ,int nWidth
82 ,int nHeight
83 ,int nDepth
84 );
85 wxDCCacheEntry( HPS hPS
86 ,int nDepth
87 );
d3c7fc99 88 virtual ~wxDCCacheEntry();
6835592c
DW
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
2c24e7ad
SN
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
53a2db12 100class WXDLLIMPEXP_CORE wxPMDCImpl : public wxDCImpl
54da4255 101{
fb46a9a6 102 DECLARE_DYNAMIC_CLASS(wxDC)
54da4255 103
fb46a9a6 104public:
2c24e7ad
SN
105 wxPMDCImpl(wxDC *owner, WXHDC hDC);
106 virtual ~wxPMDCImpl();
fb46a9a6
DW
107
108 // implement base class pure virtuals
109 // ----------------------------------
110
a1d6411d 111 virtual void Clear();
f6bcfd97
BP
112
113 virtual bool StartDoc(const wxString& rsMessage);
a1d6411d 114 virtual void EndDoc();
f6bcfd97 115
a1d6411d
SN
116 virtual void StartPage();
117 virtual void EndPage();
f6bcfd97
BP
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
a1d6411d 126 virtual void DestroyClippingRegion();
f6bcfd97 127
a1d6411d
SN
128 virtual wxCoord GetCharHeight() const;
129 virtual wxCoord GetCharWidth() const;
2c24e7ad 130
a1d6411d
SN
131 virtual bool CanDrawBitmap() const;
132 virtual bool CanGetTextExtent() const;
133 virtual int GetDepth() const;
134 virtual wxSize GetPPI() const;
f6bcfd97 135
a1d6411d 136 virtual void SetMapMode(wxMappingMode nMode);
f6bcfd97
BP
137 virtual void SetUserScale( double dX
138 ,double dY
139 );
f6bcfd97
BP
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 );
89efaf2b 152 virtual void SetLogicalFunction(wxRasterOperationMode nFunction);
1408104d 153
fb46a9a6
DW
154 // implementation from now on
155 // --------------------------
54da4255 156
f6bcfd97
BP
157 virtual void SetRop(WXHDC hCdc);
158 virtual void SelectOldObjects(WXHDC hDc);
ce44c50e 159
a1d6411d 160 wxWindow* GetWindow() const { return m_pCanvas; }
f6bcfd97 161 void SetWindow(wxWindow* pWin) { m_pCanvas = pWin; }
ce44c50e 162
a1d6411d 163 WXHDC GetHDC() const { return m_hDC; }
f6bcfd97
BP
164 void SetHDC( WXHDC hDc
165 ,bool bOwnsDC = FALSE
166 )
ce44c50e 167 {
f6bcfd97 168 m_hDC = hDc;
ce44c50e
DW
169 m_bOwnsDC = bOwnsDC;
170 }
171
a1d6411d 172 HPS GetHPS() const { return m_hPS; }
d8fcb5e8
DW
173 void SetHPS(HPS hPS)
174 {
d8fcb5e8
DW
175 m_hPS = hPS;
176 }
a1d6411d
SN
177 const wxBitmap& GetSelectedBitmap() const { return m_vSelectedBitmap; }
178 wxBitmap& GetSelectedBitmap() { return m_vSelectedBitmap; }
f6bcfd97 179
210a651b
DW
180 void UpdateClipBox();
181
6835592c
DW
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);
a1d6411d 193 static void ClearCache();
6835592c
DW
194#endif
195
1408104d 196protected:
2c24e7ad
SN
197 void Init()
198 {
2c6dbc21
VZ
199 m_pCanvas = NULL;
200 m_hOldBitmap = 0;
201 m_hOldPen = 0;
202 m_hOldBrush = 0;
203 m_hOldFont = 0;
2c24e7ad
SN
204#if wxUSE_PALETTE
205 m_hOldPalette = 0;
206#endif // wxUSE_PALETTE
207
2c6dbc21
VZ
208 m_bOwnsDC = false;
209 m_hDC = 0;
210 m_hOldPS = NULL;
211 m_hPS = NULL;
212 m_bIsPaintTime = false; // True at Paint Time
2c24e7ad 213
2c6dbc21
VZ
214 m_pen.SetColour(*wxBLACK);
215 m_brush.SetColour(*wxWHITE);
2c24e7ad
SN
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
222public:
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;
89efaf2b
FM
230 virtual bool DoFloodFill( wxCoord vX
231 ,wxCoord vY
232 ,const wxColour& rCol
233 ,wxFloodFillStyle nStyle = wxFLOOD_SURFACE
f6bcfd97
BP
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
89efaf2b 318 ,wxRasterOperationMode nRop = wxCOPY
f6bcfd97 319 ,bool bUseMask = FALSE
6835592c
DW
320 ,wxCoord vXsrcMask = -1
321 ,wxCoord vYsrcMask = -1
f6bcfd97
BP
322 );
323
f6bcfd97
BP
324 virtual void DoSetClippingRegion( wxCoord vX
325 ,wxCoord vY
326 ,wxCoord vWidth
327 ,wxCoord vHeight
328 );
fdaad94e 329 virtual void DoSetDeviceClippingRegion(const wxRegion& rRegion);
1408104d 330
f6bcfd97
BP
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
89efaf2b 347 ,wxPolygonFillMode nFillStyle = wxODDEVEN_RULE
f6bcfd97 348 );
fb46a9a6 349
938aa9c4
DW
350#if wxUSE_PALETTE
351 void DoSelectPalette(bool bRealize = FALSE);
a1d6411d 352 void InitializePalette();
938aa9c4 353#endif // wxUSE_PALETTE
fb46a9a6 354
2c24e7ad 355protected:
f6bcfd97
BP
356 //
357 // common part of DoDrawText() and DoDrawRotatedText()
358 //
359 void DrawAnyText( const wxString& rsText
360 ,wxCoord vX
361 ,wxCoord vY
362 );
fb46a9a6 363
f6bcfd97
BP
364 // OS2-specific member variables ?? do we even need this under OS/2?
365 int m_nWindowExtX;
366 int m_nWindowExtY;
1408104d 367
f6bcfd97
BP
368 //
369 // the window associated with this DC (may be NULL)
370 //
371 wxWindow* m_pCanvas;
372 wxBitmap m_vSelectedBitmap;
1408104d 373
d7e1a322
DW
374public:
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.
f6bcfd97 381 //
fb46a9a6 382 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
f6bcfd97
BP
383 //
384 bool m_bOwnsDC:1;
fb46a9a6 385
f6bcfd97 386 //
ac7fb818 387 // our HDC
f6bcfd97
BP
388 //
389 WXHDC m_hDC;
1408104d 390
f6bcfd97 391 //
1408104d
DW
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.
f6bcfd97
BP
395 //
396 WXHBITMAP m_hOldBitmap;
397 WXHPEN m_hOldPen;
398 WXHBRUSH m_hOldBrush;
399 WXHFONT m_hOldFont;
400 WXHPALETTE m_hOldPalette;
6835592c
DW
401
402#if wxUSE_DC_CACHEING
403 static wxList m_svBitmapCache;
404 static wxList m_svDCCache;
405#endif
406}; // end of CLASS wxDC
0e320a79
DW
407#endif
408 // _WX_DC_H_