]>
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 WXDLLIMPEXP_FWD_CORE wxDC; | |
21 | class WXDLLIMPEXP_FWD_CORE wxControl; | |
22 | class WXDLLIMPEXP_FWD_CORE wxBitmap; | |
23 | class WXDLLIMPEXP_FWD_CORE wxBitmapHandler; | |
24 | class WXDLLIMPEXP_FWD_CORE wxIcon; | |
25 | class WXDLLIMPEXP_FWD_CORE wxMask; | |
26 | class WXDLLIMPEXP_FWD_CORE wxCursor; | |
27 | class WXDLLIMPEXP_FWD_CORE wxControl; | |
28 | class WXDLLIMPEXP_FWD_CORE wxPixelDataBase; | |
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 WXDLLIMPEXP_CORE wxBitmapRefData : public wxGDIImageRefData | |
38 | { | |
39 | public: | |
40 | wxBitmapRefData(); | |
41 | wxBitmapRefData(const wxBitmapRefData &tocopy); | |
42 | virtual ~wxBitmapRefData() { Free(); } | |
43 | ||
44 | virtual void Free(); | |
45 | ||
46 | public: | |
47 | int m_nNumColors; | |
48 | wxPalette m_vBitmapPalette; | |
49 | int m_nQuality; | |
50 | ||
51 | // OS2-specific | |
52 | // ------------ | |
53 | ||
54 | wxDC* m_pSelectedInto; | |
55 | ||
56 | // | |
57 | // Optional mask for transparent drawing | |
58 | // | |
59 | wxMask* m_pBitmapMask; | |
60 | }; // end of CLASS wxBitmapRefData | |
61 | ||
62 | // ---------------------------------------------------------------------------- | |
63 | // wxBitmap: a mono or colour bitmap | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
66 | class WXDLLIMPEXP_CORE wxBitmap : public wxGDIImage, | |
67 | public wxBitmapHelpers | |
68 | { | |
69 | public: | |
70 | // default ctor creates an invalid bitmap, you must Create() it later | |
71 | wxBitmap() { Init(); } | |
72 | ||
73 | // Copy constructors | |
74 | inline wxBitmap(const wxBitmap& rBitmap) | |
75 | : wxGDIImage(rBitmap) | |
76 | { | |
77 | Init(); | |
78 | SetHandle(rBitmap.GetHandle()); | |
79 | } | |
80 | ||
81 | // Initialize with raw data | |
82 | wxBitmap( const char bits[] | |
83 | ,int nWidth | |
84 | ,int nHeight | |
85 | ,int nDepth = 1 | |
86 | ); | |
87 | ||
88 | // Initialize with XPM data | |
89 | wxBitmap(const char* const* bits); | |
90 | #ifdef wxNEEDS_CHARPP | |
91 | // needed for old GCC | |
92 | wxBitmap(char** data) | |
93 | { | |
94 | *this = wxBitmap(const_cast<const char* const*>(data)); | |
95 | } | |
96 | #endif | |
97 | ||
98 | // Load a resource | |
99 | wxBitmap( int nId | |
100 | ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE | |
101 | ); | |
102 | ||
103 | // For compatiability with other ports, under OS/2 does same as default ctor | |
104 | inline wxBitmap( const wxString& WXUNUSED(rFilename) | |
105 | ,wxBitmapType WXUNUSED(lType) | |
106 | ) | |
107 | { Init(); } | |
108 | // New constructor for generalised creation from data | |
109 | wxBitmap( const void* pData | |
110 | ,wxBitmapType lType | |
111 | ,int nWidth | |
112 | ,int nHeight | |
113 | ,int nDepth = 1 | |
114 | ); | |
115 | ||
116 | // If depth is omitted, will create a bitmap compatible with the display | |
117 | wxBitmap( int nWidth, int nHeight, int nDepth = -1 ) | |
118 | { | |
119 | Init(); | |
120 | (void)Create(nWidth, nHeight, nDepth); | |
121 | } | |
122 | wxBitmap( const wxSize& sz, int nDepth = -1 ) | |
123 | { | |
124 | Init(); | |
125 | (void)Create(sz, nDepth); | |
126 | } | |
127 | ||
128 | wxBitmap( const wxImage& image, int depth = -1 ) | |
129 | { (void)CreateFromImage(image, depth); } | |
130 | ||
131 | // we must have this, otherwise icons are silently copied into bitmaps using | |
132 | // the copy ctor but the resulting bitmap is invalid! | |
133 | inline wxBitmap(const wxIcon& rIcon) | |
134 | { Init(); CopyFromIcon(rIcon); } | |
135 | ||
136 | wxBitmap& operator=(const wxIcon& rIcon) | |
137 | { | |
138 | (void)CopyFromIcon(rIcon); | |
139 | ||
140 | return(*this); | |
141 | } | |
142 | ||
143 | wxBitmap& operator=(const wxCursor& rCursor) | |
144 | { | |
145 | (void)CopyFromCursor(rCursor); | |
146 | return (*this); | |
147 | } | |
148 | ||
149 | virtual ~wxBitmap(); | |
150 | ||
151 | wxImage ConvertToImage() const; | |
152 | wxBitmap ConvertToDisabled(unsigned char brightness = 255) const; | |
153 | ||
154 | // get the given part of bitmap | |
155 | wxBitmap GetSubBitmap(const wxRect& rRect) const; | |
156 | ||
157 | // copies the contents and mask of the given (colour) icon to the bitmap | |
158 | bool CopyFromIcon(const wxIcon& rIcon); | |
159 | ||
160 | // copies the contents and mask of the given cursor to the bitmap | |
161 | bool CopyFromCursor(const wxCursor& rCursor); | |
162 | ||
163 | virtual bool Create( int nWidth | |
164 | ,int nHeight | |
165 | ,int nDepth = wxBITMAP_SCREEN_DEPTH | |
166 | ); | |
167 | virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH) | |
168 | { return Create(sz.GetWidth(), sz.GetHeight(), depth); } | |
169 | virtual bool Create(int width, int height, const wxDC& WXUNUSED(dc)) | |
170 | { return Create(width,height); } | |
171 | ||
172 | virtual bool Create( const void* pData | |
173 | ,wxBitmapType lType | |
174 | ,int nWidth | |
175 | ,int nHeight | |
176 | ,int nDepth = 1 | |
177 | ); | |
178 | virtual bool LoadFile( int nId | |
179 | ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE | |
180 | ); | |
181 | virtual bool LoadFile( const wxString& rName | |
182 | ,wxBitmapType lType = wxBITMAP_DEFAULT_TYPE | |
183 | ); | |
184 | virtual bool SaveFile( const wxString& rName | |
185 | ,wxBitmapType lType | |
186 | ,const wxPalette* pCmap = NULL | |
187 | ); | |
188 | ||
189 | inline wxBitmapRefData* GetBitmapData() const | |
190 | { return (wxBitmapRefData *)m_refData; } | |
191 | ||
192 | // raw bitmap access support functions | |
193 | void *GetRawData(wxPixelDataBase& data, int bpp); | |
194 | void UngetRawData(wxPixelDataBase& data); | |
195 | ||
196 | inline int GetQuality() const | |
197 | { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); } | |
198 | ||
199 | void SetQuality(int nQ); | |
200 | ||
201 | wxPalette* GetPalette() const | |
202 | { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : NULL); } | |
203 | ||
204 | void SetPalette(const wxPalette& rPalette); | |
205 | ||
206 | inline wxMask* GetMask() const | |
207 | { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : NULL); } | |
208 | ||
209 | void SetMask(wxMask* pMask) ; | |
210 | ||
211 | // Implementation | |
212 | public: | |
213 | inline void SetHBITMAP(WXHBITMAP hBmp) | |
214 | { SetHandle((WXHANDLE)hBmp); } | |
215 | ||
216 | inline WXHBITMAP GetHBITMAP() const | |
217 | { return (WXHBITMAP)GetHandle(); } | |
218 | ||
219 | inline void SetSelectedInto(wxDC* pDc) | |
220 | { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; } | |
221 | ||
222 | inline wxDC* GetSelectedInto() const | |
223 | { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : NULL); } | |
224 | ||
225 | inline bool IsMono(void) const { return m_bIsMono; } | |
226 | ||
227 | // An OS/2 version that probably doesn't do anything like the msw version | |
228 | wxBitmap GetBitmapForDC(wxDC& rDc) const; | |
229 | ||
230 | protected: | |
231 | // common part of all ctors | |
232 | void Init(); | |
233 | ||
234 | inline virtual wxGDIImageRefData* CreateData() const | |
235 | { return new wxBitmapRefData; } | |
236 | ||
237 | bool CreateFromImage(const wxImage& image, int depth); | |
238 | ||
239 | virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; | |
240 | ||
241 | private: | |
242 | bool CopyFromIconOrCursor(const wxGDIImage& rIcon); | |
243 | ||
244 | bool m_bIsMono; | |
245 | DECLARE_DYNAMIC_CLASS(wxBitmap) | |
246 | }; // end of CLASS wxBitmap | |
247 | ||
248 | // ---------------------------------------------------------------------------- | |
249 | // wxMask: a mono bitmap used for drawing bitmaps transparently. | |
250 | // ---------------------------------------------------------------------------- | |
251 | ||
252 | class WXDLLIMPEXP_CORE wxMask : public wxObject | |
253 | { | |
254 | public: | |
255 | wxMask(); | |
256 | wxMask( const wxMask& tocopy); | |
257 | ||
258 | // Construct a mask from a bitmap and a colour indicating the transparent | |
259 | // area | |
260 | wxMask( const wxBitmap& rBitmap | |
261 | ,const wxColour& rColour | |
262 | ); | |
263 | ||
264 | // Construct a mask from a bitmap and a palette index indicating the | |
265 | // transparent area | |
266 | wxMask( const wxBitmap& rBitmap | |
267 | ,int nPaletteIndex | |
268 | ); | |
269 | ||
270 | // Construct a mask from a mono bitmap (copies the bitmap). | |
271 | wxMask(const wxBitmap& rBitmap); | |
272 | ||
273 | // construct a mask from the givne bitmap handle | |
274 | wxMask(WXHBITMAP hBmp) | |
275 | { m_hMaskBitmap = hBmp; } | |
276 | ||
277 | virtual ~wxMask(); | |
278 | ||
279 | bool Create( const wxBitmap& bitmap | |
280 | ,const wxColour& rColour | |
281 | ); | |
282 | bool Create( const wxBitmap& rBitmap | |
283 | ,int nPaletteIndex | |
284 | ); | |
285 | bool Create(const wxBitmap& rBitmap); | |
286 | ||
287 | // Implementation | |
288 | WXHBITMAP GetMaskBitmap() const | |
289 | { return m_hMaskBitmap; } | |
290 | void SetMaskBitmap(WXHBITMAP hBmp) | |
291 | { m_hMaskBitmap = hBmp; } | |
292 | ||
293 | protected: | |
294 | WXHBITMAP m_hMaskBitmap; | |
295 | DECLARE_DYNAMIC_CLASS(wxMask) | |
296 | }; // end of CLASS wxMask | |
297 | ||
298 | // ---------------------------------------------------------------------------- | |
299 | // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file | |
300 | // ---------------------------------------------------------------------------- | |
301 | ||
302 | class WXDLLIMPEXP_CORE wxBitmapHandler : public wxGDIImageHandler | |
303 | { | |
304 | public: | |
305 | inline wxBitmapHandler() | |
306 | { m_lType = wxBITMAP_TYPE_INVALID; } | |
307 | ||
308 | inline wxBitmapHandler( const wxString& rName | |
309 | ,const wxString& rExt | |
310 | ,wxBitmapType lType | |
311 | ) | |
312 | : wxGDIImageHandler( rName | |
313 | ,rExt | |
314 | ,lType) | |
315 | { | |
316 | } | |
317 | ||
318 | // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the | |
319 | // old class which worked only with bitmaps | |
320 | virtual bool Create( wxBitmap* pBitmap | |
321 | ,const void* pData | |
322 | ,wxBitmapType lType | |
323 | ,int nWidth | |
324 | ,int nHeight | |
325 | ,int nDepth = 1 | |
326 | ); | |
327 | virtual bool LoadFile( wxBitmap* pBitmap | |
328 | ,int nId | |
329 | ,wxBitmapType lType | |
330 | ,int nDesiredWidth | |
331 | ,int nDesiredHeight | |
332 | ); | |
333 | virtual bool LoadFile( wxBitmap* pBitmap | |
334 | ,const wxString& rName | |
335 | ,wxBitmapType lType | |
336 | ,int nDesiredWidth | |
337 | ,int nDesiredHeight | |
338 | ); | |
339 | virtual bool SaveFile( wxBitmap* pBitmap | |
340 | ,const wxString& rName | |
341 | ,wxBitmapType lType | |
342 | ,const wxPalette* pPalette = NULL | |
343 | ) const; | |
344 | ||
345 | virtual bool Create( wxGDIImage* pImage | |
346 | ,const void* pData | |
347 | ,wxBitmapType lFlags | |
348 | ,int nWidth | |
349 | ,int nHeight | |
350 | ,int nDepth = 1 | |
351 | ); | |
352 | virtual bool Load( wxGDIImage* pImage | |
353 | ,int nId | |
354 | ,wxBitmapType lFlags | |
355 | ,int nDesiredWidth | |
356 | ,int nDesiredHeight | |
357 | ); | |
358 | virtual bool Save( const wxGDIImage* pImage | |
359 | ,const wxString& rName | |
360 | ,wxBitmapType lType | |
361 | ) const; | |
362 | private: | |
363 | inline virtual bool Load( wxGDIImage* WXUNUSED(pImage) | |
364 | ,const wxString& WXUNUSED(rName) | |
365 | ,WXHANDLE WXUNUSED(hPs) | |
366 | ,wxBitmapType WXUNUSED(lFlags) | |
367 | ,int WXUNUSED(nDesiredWidth) | |
368 | ,int WXUNUSED(nDesiredHeight) | |
369 | ) | |
370 | { return false; } | |
371 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
372 | }; // end of CLASS wxBitmapHandler | |
373 | ||
374 | #endif | |
375 | // _WX_BITMAP_H_ |