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