]>
Commit | Line | Data |
---|---|---|
0e320a79 | 1 | ///////////////////////////////////////////////////////////////////////////// |
3b9e3455 | 2 | // Name: wx/os2/bitmap.h |
0e320a79 | 3 | // Purpose: wxBitmap class |
d88de032 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
3b9e3455 | 6 | // Created: 11/28/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
d88de032 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_BITMAP_H_ | |
13 | #define _WX_BITMAP_H_ | |
14 | ||
3b9e3455 DW |
15 | #ifdef __GNUG__ |
16 | #pragma interface "bitmap.h" | |
17 | #endif | |
18 | ||
58b16424 | 19 | #include "wx/os2/private.h" |
3b9e3455 | 20 | #include "wx/os2/gdiimage.h" |
0e320a79 DW |
21 | #include "wx/gdicmn.h" |
22 | #include "wx/palette.h" | |
23 | ||
0e320a79 DW |
24 | class WXDLLEXPORT wxDC; |
25 | class WXDLLEXPORT wxControl; | |
26 | class WXDLLEXPORT wxBitmap; | |
27 | class WXDLLEXPORT wxBitmapHandler; | |
28 | class WXDLLEXPORT wxIcon; | |
3b9e3455 | 29 | class WXDLLEXPORT wxMask; |
0e320a79 | 30 | class WXDLLEXPORT wxCursor; |
d88de032 | 31 | class WXDLLEXPORT wxControl; |
0e320a79 | 32 | |
3b9e3455 DW |
33 | // ---------------------------------------------------------------------------- |
34 | // Bitmap data | |
35 | // | |
36 | // NB: this class is private, but declared here to make it possible inline | |
37 | // wxBitmap functions accessing it | |
38 | // ---------------------------------------------------------------------------- | |
0e320a79 | 39 | |
3b9e3455 | 40 | class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData |
0e320a79 | 41 | { |
0e320a79 DW |
42 | public: |
43 | wxBitmapRefData(); | |
3b9e3455 DW |
44 | virtual ~wxBitmapRefData() { Free(); } |
45 | ||
46 | virtual void Free(); | |
0e320a79 DW |
47 | |
48 | public: | |
3b9e3455 DW |
49 | int m_nNumColors; |
50 | wxPalette m_vBitmapPalette; | |
51 | int m_nQuality; | |
0e320a79 | 52 | |
3b9e3455 DW |
53 | // OS2-specific |
54 | // ------------ | |
0e320a79 | 55 | |
3b9e3455 DW |
56 | wxDC* m_pSelectedInto; |
57 | HPS m_hPresentationSpace; | |
fd368161 | 58 | LONG m_lId; |
3b9e3455 DW |
59 | |
60 | // optional mask for transparent drawing | |
61 | wxMask* m_pBitmapMask; | |
0e320a79 DW |
62 | }; |
63 | ||
3b9e3455 DW |
64 | // ---------------------------------------------------------------------------- |
65 | // wxBitmap: a mono or colour bitmap | |
66 | // ---------------------------------------------------------------------------- | |
0e320a79 | 67 | |
3b9e3455 | 68 | class WXDLLEXPORT wxBitmap : public wxGDIImage |
0e320a79 | 69 | { |
0e320a79 | 70 | public: |
3b9e3455 DW |
71 | // default ctor creates an invalid bitmap, you must Create() it later |
72 | wxBitmap() { Init(); } | |
73 | ||
74 | // Copy constructors | |
75 | inline wxBitmap(const wxBitmap& rBitmap) | |
76 | { Init(); Ref(rBitmap); } | |
77 | ||
78 | // Initialize with raw data | |
79 | wxBitmap( const char bits[] | |
80 | ,int nWidth | |
81 | ,int nHeight | |
82 | ,int nDepth = 1 | |
83 | ); | |
84 | ||
85 | // Initialize with XPM data | |
86 | wxBitmap( char** ppData | |
87 | ,wxControl* pAnItem = NULL | |
88 | ); | |
89 | ||
90 | // Load a file or resource | |
91 | wxBitmap( const wxString& rName | |
92 | ,long lType = wxBITMAP_TYPE_BMP_RESOURCE | |
93 | ); | |
94 | ||
95 | // New constructor for generalised creation from data | |
96 | wxBitmap( void* pData | |
97 | ,long lType | |
98 | ,int nWidth | |
99 | ,int nHeight | |
100 | ,int nDepth = 1 | |
101 | ); | |
102 | ||
103 | // If depth is omitted, will create a bitmap compatible with the display | |
104 | wxBitmap( int nWidth | |
105 | ,int nHeight | |
106 | ,int nDepth = -1 | |
107 | ); | |
108 | ||
109 | // we must have this, otherwise icons are silently copied into bitmaps using | |
110 | // the copy ctor but the resulting bitmap is invalid! | |
111 | inline wxBitmap(const wxIcon& rIcon) | |
112 | { Init(); CopyFromIcon(rIcon); } | |
113 | ||
114 | wxBitmap& operator=(const wxBitmap& rBitmap) | |
115 | { | |
116 | if ( m_refData != rBitmap.m_refData ) | |
117 | Ref(rBitmap); | |
118 | return(*this); | |
119 | } | |
120 | ||
121 | wxBitmap& operator=(const wxIcon& rIcon) | |
122 | { | |
123 | (void)CopyFromIcon(rIcon); | |
124 | ||
125 | return(*this); | |
126 | } | |
127 | ||
128 | wxBitmap& operator=(const wxCursor& rCursor) | |
129 | { | |
130 | (void)CopyFromCursor(rCursor); | |
131 | return (*this); | |
132 | } | |
133 | ||
134 | virtual ~wxBitmap(); | |
135 | ||
136 | // copies the contents and mask of the given (colour) icon to the bitmap | |
137 | bool CopyFromIcon(const wxIcon& rIcon); | |
138 | ||
139 | // copies the contents and mask of the given cursor to the bitmap | |
140 | bool CopyFromCursor(const wxCursor& rCursor); | |
141 | ||
142 | virtual bool Create( int nWidth | |
143 | ,int nHeight | |
144 | ,int nDepth = -1 | |
145 | ); | |
146 | virtual bool Create( void* pData | |
147 | ,long lType | |
148 | ,int nWidth | |
149 | ,int nHeight | |
150 | ,int nDepth = 1 | |
151 | ); | |
152 | virtual bool LoadFile( const wxString& rName | |
153 | ,long lType = wxBITMAP_TYPE_BMP_RESOURCE | |
154 | ); | |
155 | virtual bool SaveFile( const wxString& rName | |
156 | ,int lType | |
157 | ,const wxPalette* pCmap = NULL | |
158 | ); | |
159 | ||
160 | inline wxBitmapRefData* GetBitmapData() const | |
161 | { return (wxBitmapRefData *)m_refData; } | |
162 | ||
163 | inline int GetQuality() const | |
58b16424 | 164 | { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); } |
3b9e3455 DW |
165 | |
166 | void SetQuality(int nQ); | |
167 | ||
168 | wxPalette* GetPalette() const | |
58b16424 | 169 | { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); } |
3b9e3455 DW |
170 | |
171 | void SetPalette(const wxPalette& rPalette); | |
172 | ||
173 | inline wxMask* GetMask() const | |
58b16424 | 174 | { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); } |
3b9e3455 DW |
175 | |
176 | void SetMask(wxMask* pMask) ; | |
177 | ||
178 | inline bool operator==(const wxBitmap& rBitmap) | |
179 | { return m_refData == rBitmap.m_refData; } | |
180 | ||
181 | inline bool operator!=(const wxBitmap& rBitmap) | |
182 | { return m_refData != rBitmap.m_refData; } | |
183 | ||
184 | #if WXWIN_COMPATIBILITY_2 | |
185 | void SetOk(bool bIsOk); | |
186 | #endif // WXWIN_COMPATIBILITY_2 | |
0e320a79 | 187 | |
3b9e3455 DW |
188 | #if WXWIN_COMPATIBILITY |
189 | inline wxPalette* GetColourMap() const | |
190 | { return GetPalette(); } | |
0e320a79 | 191 | |
3b9e3455 DW |
192 | inline void SetColourMap(wxPalette* pCmap) |
193 | { SetPalette(*pCmap); }; | |
0e320a79 | 194 | |
3b9e3455 | 195 | #endif // WXWIN_COMPATIBILITY |
0e320a79 | 196 | |
3b9e3455 DW |
197 | // Implementation |
198 | public: | |
58b16424 DW |
199 | inline void SetHBITMAP(WXHBITMAP hBmp) |
200 | { SetHandle((WXHANDLE)hBmp); } | |
3b9e3455 DW |
201 | |
202 | inline WXHBITMAP GetHBITMAP() const | |
203 | { return (WXHBITMAP)GetHandle(); } | |
204 | ||
205 | inline void SetSelectedInto(wxDC* pDc) | |
58b16424 | 206 | { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; } |
3b9e3455 DW |
207 | |
208 | inline wxDC* GetSelectedInto() const | |
58b16424 | 209 | { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); } |
3b9e3455 | 210 | |
4f72fe4f | 211 | // An OS/2 version that probably doesn't do anything like the msw version |
3b9e3455 | 212 | wxBitmap GetBitmapForDC(wxDC& rDc) const; |
0e320a79 | 213 | |
fd368161 DW |
214 | inline LONG GetId() const |
215 | { return (GetBitmapData() ? GetBitmapData()->m_lId : 0L); } | |
216 | ||
217 | ||
3b9e3455 DW |
218 | protected: |
219 | // common part of all ctors | |
220 | void Init(); | |
0e320a79 | 221 | |
3b9e3455 DW |
222 | inline virtual wxGDIImageRefData* CreateData() const |
223 | { return new wxBitmapRefData; } | |
0e320a79 | 224 | |
3b9e3455 DW |
225 | private: |
226 | bool CopyFromIconOrCursor(const wxGDIImage& rIcon); | |
0e320a79 | 227 | |
3b9e3455 DW |
228 | DECLARE_DYNAMIC_CLASS(wxBitmap) |
229 | }; | |
d88de032 | 230 | |
3b9e3455 DW |
231 | // ---------------------------------------------------------------------------- |
232 | // wxMask: a mono bitmap used for drawing bitmaps transparently. | |
233 | // ---------------------------------------------------------------------------- | |
0e320a79 | 234 | |
3b9e3455 DW |
235 | class WXDLLEXPORT wxMask : public wxObject |
236 | { | |
237 | public: | |
238 | wxMask(); | |
239 | ||
240 | // Construct a mask from a bitmap and a colour indicating the transparent | |
241 | // area | |
242 | wxMask( const wxBitmap& rBitmap | |
243 | ,const wxColour& rColour | |
244 | ); | |
245 | ||
246 | // Construct a mask from a bitmap and a palette index indicating the | |
247 | // transparent area | |
248 | wxMask( const wxBitmap& rBitmap | |
249 | ,int nPaletteIndex | |
250 | ); | |
251 | ||
252 | // Construct a mask from a mono bitmap (copies the bitmap). | |
253 | wxMask(const wxBitmap& rBitmap); | |
254 | ||
255 | // construct a mask from the givne bitmap handle | |
256 | wxMask(WXHBITMAP hBmp) | |
257 | { m_hMaskBitmap = hBmp; } | |
258 | ||
259 | virtual ~wxMask(); | |
260 | ||
261 | bool Create( const wxBitmap& bitmap | |
262 | ,const wxColour& rColour | |
263 | ); | |
264 | bool Create( const wxBitmap& rBitmap | |
265 | ,int nPaletteIndex | |
266 | ); | |
267 | bool Create(const wxBitmap& rBitmap); | |
268 | ||
269 | // Implementation | |
270 | WXHBITMAP GetMaskBitmap() const | |
271 | { return m_hMaskBitmap; } | |
272 | void SetMaskBitmap(WXHBITMAP hBmp) | |
273 | { m_hMaskBitmap = hBmp; } | |
0e320a79 | 274 | |
0e320a79 | 275 | protected: |
3b9e3455 DW |
276 | WXHBITMAP m_hMaskBitmap; |
277 | DECLARE_DYNAMIC_CLASS(wxMask) | |
43543d98 DW |
278 | private: |
279 | HDC m_hDc; | |
280 | HPS m_hPs; | |
3b9e3455 DW |
281 | }; |
282 | ||
283 | // ---------------------------------------------------------------------------- | |
284 | // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file | |
285 | // ---------------------------------------------------------------------------- | |
0e320a79 | 286 | |
3b9e3455 DW |
287 | class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler |
288 | { | |
0e320a79 | 289 | public: |
3b9e3455 DW |
290 | inline wxBitmapHandler() |
291 | { m_lType = wxBITMAP_TYPE_INVALID; } | |
292 | ||
293 | inline wxBitmapHandler( const wxString& rName | |
294 | ,const wxString& rExt | |
295 | ,long lType | |
296 | ) | |
297 | : wxGDIImageHandler( rName | |
298 | ,rExt | |
299 | ,lType) | |
300 | { | |
301 | } | |
302 | ||
303 | // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the | |
304 | // old class which worked only with bitmaps | |
305 | virtual bool Create( wxBitmap* pBitmap | |
306 | ,void* pData | |
307 | ,long lFlags | |
308 | ,int nWidth | |
309 | ,int nHeight | |
310 | ,int nDepth = 1 | |
311 | ); | |
312 | virtual bool LoadFile( wxBitmap* pBitmap | |
313 | ,const wxString& rName | |
8ea3f821 | 314 | ,HPS hPs |
3b9e3455 DW |
315 | ,long lFlags |
316 | ,int nDesiredWidth | |
317 | ,int nDesiredHeight | |
318 | ); | |
319 | virtual bool SaveFile( wxBitmap* pBitmap | |
320 | ,const wxString& rName | |
321 | ,int lType | |
322 | ,const wxPalette* pPalette = NULL | |
323 | ); | |
324 | ||
325 | virtual bool Create( wxGDIImage* pImage | |
326 | ,void* pData | |
327 | ,long lFlags | |
328 | ,int nWidth | |
329 | ,int nHeight | |
330 | ,int nDepth = 1 | |
331 | ); | |
332 | virtual bool Load( wxGDIImage* pImage | |
333 | ,const wxString& rName | |
8ea3f821 | 334 | ,HPS hPs |
3b9e3455 DW |
335 | ,long lFlags |
336 | ,int nDesiredWidth | |
337 | ,int nDesiredHeight | |
338 | ); | |
58b16424 DW |
339 | virtual bool Save( wxGDIImage* pImage |
340 | ,const wxString& rName | |
341 | ,int lType | |
3b9e3455 DW |
342 | ); |
343 | private: | |
344 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
0e320a79 | 345 | }; |
3b9e3455 | 346 | |
0e320a79 DW |
347 | #endif |
348 | // _WX_BITMAP_H_ |