]>
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 | ||
89 | // Load a resource | |
90 | wxBitmap( int nId | |
91 | ,long lType = wxBITMAP_TYPE_BMP_RESOURCE | |
92 | ); | |
93 | ||
94 | // For compatiability with other ports, under OS/2 does same as default ctor | |
95 | inline wxBitmap( const wxString& WXUNUSED(rFilename) | |
96 | ,long WXUNUSED(lType) | |
97 | ) | |
98 | { Init(); } | |
99 | // New constructor for generalised creation from data | |
100 | wxBitmap( const void* pData | |
101 | ,long lType | |
102 | ,int nWidth | |
103 | ,int nHeight | |
104 | ,int nDepth = 1 | |
105 | ); | |
106 | ||
107 | // If depth is omitted, will create a bitmap compatible with the display | |
108 | wxBitmap( int nWidth, int nHeight, int nDepth = -1 ); | |
109 | ||
110 | wxBitmap( const wxImage& image, int depth = -1 ) | |
111 | { (void)CreateFromImage(image, depth); } | |
112 | ||
113 | // we must have this, otherwise icons are silently copied into bitmaps using | |
114 | // the copy ctor but the resulting bitmap is invalid! | |
115 | inline wxBitmap(const wxIcon& rIcon) | |
116 | { Init(); CopyFromIcon(rIcon); } | |
117 | ||
118 | wxBitmap& operator=(const wxIcon& rIcon) | |
119 | { | |
120 | (void)CopyFromIcon(rIcon); | |
121 | ||
122 | return(*this); | |
123 | } | |
124 | ||
125 | wxBitmap& operator=(const wxCursor& rCursor) | |
126 | { | |
127 | (void)CopyFromCursor(rCursor); | |
128 | return (*this); | |
129 | } | |
130 | ||
131 | virtual ~wxBitmap(); | |
132 | ||
133 | wxImage ConvertToImage() const; | |
134 | ||
135 | // get the given part of bitmap | |
136 | wxBitmap GetSubBitmap(const wxRect& rRect) const; | |
137 | ||
138 | // copies the contents and mask of the given (colour) icon to the bitmap | |
139 | bool CopyFromIcon(const wxIcon& rIcon); | |
140 | ||
141 | // copies the contents and mask of the given cursor to the bitmap | |
142 | bool CopyFromCursor(const wxCursor& rCursor); | |
143 | ||
144 | virtual bool Create( int nWidth | |
145 | ,int nHeight | |
146 | ,int nDepth = -1 | |
147 | ); | |
148 | virtual bool Create( const void* pData | |
149 | ,long lType | |
150 | ,int nWidth | |
151 | ,int nHeight | |
152 | ,int nDepth = 1 | |
153 | ); | |
154 | virtual bool LoadFile( int nId | |
155 | ,long lType = wxBITMAP_TYPE_BMP_RESOURCE | |
156 | ); | |
157 | virtual bool LoadFile( const wxString& rName | |
158 | ,long lType = wxBITMAP_TYPE_XPM | |
159 | ); | |
160 | virtual bool SaveFile( const wxString& rName | |
161 | ,int lType | |
162 | ,const wxPalette* pCmap = NULL | |
163 | ); | |
164 | ||
165 | inline wxBitmapRefData* GetBitmapData() const | |
166 | { return (wxBitmapRefData *)m_refData; } | |
167 | ||
168 | inline int GetQuality() const | |
169 | { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); } | |
170 | ||
171 | void SetQuality(int nQ); | |
172 | ||
173 | wxPalette* GetPalette() const | |
174 | { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); } | |
175 | ||
176 | void SetPalette(const wxPalette& rPalette); | |
177 | ||
178 | inline wxMask* GetMask() const | |
179 | { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); } | |
180 | ||
181 | void SetMask(wxMask* pMask) ; | |
182 | ||
183 | inline bool operator==(const wxBitmap& rBitmap) const | |
184 | { return m_refData == rBitmap.m_refData; } | |
185 | ||
186 | inline bool operator!=(const wxBitmap& rBitmap) const | |
187 | { return m_refData != rBitmap.m_refData; } | |
188 | ||
189 | // Implementation | |
190 | public: | |
191 | inline void SetHBITMAP(WXHBITMAP hBmp) | |
192 | { SetHandle((WXHANDLE)hBmp); } | |
193 | ||
194 | inline WXHBITMAP GetHBITMAP() const | |
195 | { return (WXHBITMAP)GetHandle(); } | |
196 | ||
197 | inline void SetSelectedInto(wxDC* pDc) | |
198 | { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; } | |
199 | ||
200 | inline wxDC* GetSelectedInto() const | |
201 | { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); } | |
202 | ||
203 | inline bool IsMono(void) const { return m_bIsMono; } | |
204 | ||
205 | // An OS/2 version that probably doesn't do anything like the msw version | |
206 | wxBitmap GetBitmapForDC(wxDC& rDc) const; | |
207 | ||
208 | protected: | |
209 | // common part of all ctors | |
210 | void Init(); | |
211 | ||
212 | inline virtual wxGDIImageRefData* CreateData() const | |
213 | { return new wxBitmapRefData; } | |
214 | ||
215 | bool CreateFromImage(const wxImage& image, int depth); | |
216 | ||
217 | private: | |
218 | bool CopyFromIconOrCursor(const wxGDIImage& rIcon); | |
219 | ||
220 | bool m_bIsMono; | |
221 | DECLARE_DYNAMIC_CLASS(wxBitmap) | |
222 | }; // end of CLASS wxBitmap | |
223 | ||
224 | // ---------------------------------------------------------------------------- | |
225 | // wxMask: a mono bitmap used for drawing bitmaps transparently. | |
226 | // ---------------------------------------------------------------------------- | |
227 | ||
228 | class WXDLLEXPORT wxMask : public wxObject | |
229 | { | |
230 | public: | |
231 | wxMask(); | |
232 | ||
233 | // Construct a mask from a bitmap and a colour indicating the transparent | |
234 | // area | |
235 | wxMask( const wxBitmap& rBitmap | |
236 | ,const wxColour& rColour | |
237 | ); | |
238 | ||
239 | // Construct a mask from a bitmap and a palette index indicating the | |
240 | // transparent area | |
241 | wxMask( const wxBitmap& rBitmap | |
242 | ,int nPaletteIndex | |
243 | ); | |
244 | ||
245 | // Construct a mask from a mono bitmap (copies the bitmap). | |
246 | wxMask(const wxBitmap& rBitmap); | |
247 | ||
248 | // construct a mask from the givne bitmap handle | |
249 | wxMask(WXHBITMAP hBmp) | |
250 | { m_hMaskBitmap = hBmp; } | |
251 | ||
252 | virtual ~wxMask(); | |
253 | ||
254 | bool Create( const wxBitmap& bitmap | |
255 | ,const wxColour& rColour | |
256 | ); | |
257 | bool Create( const wxBitmap& rBitmap | |
258 | ,int nPaletteIndex | |
259 | ); | |
260 | bool Create(const wxBitmap& rBitmap); | |
261 | ||
262 | // Implementation | |
263 | WXHBITMAP GetMaskBitmap() const | |
264 | { return m_hMaskBitmap; } | |
265 | void SetMaskBitmap(WXHBITMAP hBmp) | |
266 | { m_hMaskBitmap = hBmp; } | |
267 | ||
268 | protected: | |
269 | WXHBITMAP m_hMaskBitmap; | |
270 | DECLARE_DYNAMIC_CLASS(wxMask) | |
271 | }; // end of CLASS wxMask | |
272 | ||
273 | // ---------------------------------------------------------------------------- | |
274 | // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file | |
275 | // ---------------------------------------------------------------------------- | |
276 | ||
277 | class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler | |
278 | { | |
279 | public: | |
280 | inline wxBitmapHandler() | |
281 | { m_lType = wxBITMAP_TYPE_INVALID; } | |
282 | ||
283 | inline wxBitmapHandler( const wxString& rName | |
284 | ,const wxString& rExt | |
285 | ,long lType | |
286 | ) | |
287 | : wxGDIImageHandler( rName | |
288 | ,rExt | |
289 | ,lType) | |
290 | { | |
291 | } | |
292 | ||
293 | // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the | |
294 | // old class which worked only with bitmaps | |
295 | virtual bool Create( wxBitmap* pBitmap | |
296 | ,const void* pData | |
297 | ,long lFlags | |
298 | ,int nWidth | |
299 | ,int nHeight | |
300 | ,int nDepth = 1 | |
301 | ); | |
302 | virtual bool LoadFile( wxBitmap* pBitmap | |
303 | ,int nId | |
304 | ,long lFlags | |
305 | ,int nDesiredWidth | |
306 | ,int nDesiredHeight | |
307 | ); | |
308 | virtual bool LoadFile( wxBitmap* pBitmap | |
309 | ,const wxString& rName | |
310 | ,long lFlags | |
311 | ,int nDesiredWidth | |
312 | ,int nDesiredHeight | |
313 | ); | |
314 | virtual bool SaveFile( wxBitmap* pBitmap | |
315 | ,const wxString& rName | |
316 | ,int lType | |
317 | ,const wxPalette* pPalette = NULL | |
318 | ); | |
319 | ||
320 | virtual bool Create( wxGDIImage* pImage | |
321 | ,const void* pData | |
322 | ,long lFlags | |
323 | ,int nWidth | |
324 | ,int nHeight | |
325 | ,int nDepth = 1 | |
326 | ); | |
327 | virtual bool Load( wxGDIImage* pImage | |
328 | ,int nId | |
329 | ,long lFlags | |
330 | ,int nDesiredWidth | |
331 | ,int nDesiredHeight | |
332 | ); | |
333 | virtual bool Save( wxGDIImage* pImage | |
334 | ,const wxString& rName | |
335 | ,int lType | |
336 | ); | |
337 | private: | |
338 | inline virtual bool Load( wxGDIImage* WXUNUSED(pImage) | |
339 | ,const wxString& WXUNUSED(rName) | |
340 | ,HPS WXUNUSED(hPs) | |
341 | ,long WXUNUSED(lFlags) | |
342 | ,int WXUNUSED(nDesiredWidth) | |
343 | ,int WXUNUSED(nDesiredHeight) | |
344 | ) | |
345 | { return false; } | |
346 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
347 | }; // end of CLASS wxBitmapHandler | |
348 | ||
349 | #endif | |
350 | // _WX_BITMAP_H_ |