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