]>
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 | ||
0e320a79 DW |
20 | class WXDLLEXPORT wxDC; |
21 | class WXDLLEXPORT wxControl; | |
22 | class WXDLLEXPORT wxBitmap; | |
23 | class WXDLLEXPORT wxBitmapHandler; | |
24 | class WXDLLEXPORT wxIcon; | |
3b9e3455 | 25 | class WXDLLEXPORT wxMask; |
0e320a79 | 26 | class WXDLLEXPORT wxCursor; |
d88de032 | 27 | class WXDLLEXPORT wxControl; |
fd859211 | 28 | class WXDLLEXPORT 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(); | |
3b9e3455 DW |
41 | virtual ~wxBitmapRefData() { Free(); } |
42 | ||
43 | virtual void Free(); | |
0e320a79 DW |
44 | |
45 | public: | |
3b9e3455 DW |
46 | int m_nNumColors; |
47 | wxPalette m_vBitmapPalette; | |
48 | int m_nQuality; | |
0e320a79 | 49 | |
3b9e3455 DW |
50 | // OS2-specific |
51 | // ------------ | |
0e320a79 | 52 | |
3b9e3455 | 53 | wxDC* m_pSelectedInto; |
3b9e3455 | 54 | |
8bb6da4a DW |
55 | // |
56 | // Optional mask for transparent drawing | |
57 | // | |
3b9e3455 | 58 | wxMask* m_pBitmapMask; |
8bb6da4a | 59 | }; // end of CLASS wxBitmapRefData |
0e320a79 | 60 | |
3b9e3455 DW |
61 | // ---------------------------------------------------------------------------- |
62 | // wxBitmap: a mono or colour bitmap | |
63 | // ---------------------------------------------------------------------------- | |
0e320a79 | 64 | |
3b9e3455 | 65 | class WXDLLEXPORT wxBitmap : public wxGDIImage |
0e320a79 | 66 | { |
0e320a79 | 67 | public: |
3b9e3455 DW |
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) | |
f8855e47 VZ |
73 | : wxGDIImage(rBitmap) |
74 | { | |
75 | Init(); | |
76 | SetHandle(rBitmap.GetHandle()); | |
77 | } | |
3b9e3455 DW |
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 | |
452418c4 | 87 | wxBitmap(const char* const* bits); |
3b9e3455 | 88 | |
b6f4144e DW |
89 | // Load a resource |
90 | wxBitmap( int nId | |
3b9e3455 DW |
91 | ,long lType = wxBITMAP_TYPE_BMP_RESOURCE |
92 | ); | |
93 | ||
b6f4144e DW |
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(); } | |
3b9e3455 | 99 | // New constructor for generalised creation from data |
452418c4 | 100 | wxBitmap( const void* pData |
3b9e3455 DW |
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 | |
7e1e6965 | 108 | wxBitmap( int nWidth, int nHeight, int nDepth = -1 ); |
3b9e3455 | 109 | |
98edf626 | 110 | wxBitmap( const wxImage& image, int depth = -1 ) |
fd859211 VS |
111 | { (void)CreateFromImage(image, depth); } |
112 | ||
3b9e3455 DW |
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 | ||
3b9e3455 DW |
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 | ||
98edf626 | 133 | wxImage ConvertToImage() const; |
fd859211 | 134 | |
341366c6 DW |
135 | // get the given part of bitmap |
136 | wxBitmap GetSubBitmap(const wxRect& rRect) const; | |
137 | ||
3b9e3455 DW |
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 | ); | |
452418c4 | 148 | virtual bool Create( const void* pData |
3b9e3455 DW |
149 | ,long lType |
150 | ,int nWidth | |
151 | ,int nHeight | |
152 | ,int nDepth = 1 | |
153 | ); | |
b6f4144e | 154 | virtual bool LoadFile( int nId |
3b9e3455 DW |
155 | ,long lType = wxBITMAP_TYPE_BMP_RESOURCE |
156 | ); | |
c90c3400 SN |
157 | virtual bool LoadFile( const wxString& rName |
158 | ,long lType = wxBITMAP_TYPE_XPM | |
159 | ); | |
3b9e3455 DW |
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 | |
58b16424 | 169 | { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); } |
3b9e3455 DW |
170 | |
171 | void SetQuality(int nQ); | |
172 | ||
173 | wxPalette* GetPalette() const | |
58b16424 | 174 | { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); } |
3b9e3455 DW |
175 | |
176 | void SetPalette(const wxPalette& rPalette); | |
177 | ||
178 | inline wxMask* GetMask() const | |
58b16424 | 179 | { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); } |
3b9e3455 DW |
180 | |
181 | void SetMask(wxMask* pMask) ; | |
182 | ||
ab4fece8 | 183 | inline bool operator==(const wxBitmap& rBitmap) const |
3b9e3455 DW |
184 | { return m_refData == rBitmap.m_refData; } |
185 | ||
ab4fece8 | 186 | inline bool operator!=(const wxBitmap& rBitmap) const |
3b9e3455 DW |
187 | { return m_refData != rBitmap.m_refData; } |
188 | ||
3b9e3455 DW |
189 | // Implementation |
190 | public: | |
58b16424 DW |
191 | inline void SetHBITMAP(WXHBITMAP hBmp) |
192 | { SetHandle((WXHANDLE)hBmp); } | |
3b9e3455 DW |
193 | |
194 | inline WXHBITMAP GetHBITMAP() const | |
195 | { return (WXHBITMAP)GetHandle(); } | |
196 | ||
197 | inline void SetSelectedInto(wxDC* pDc) | |
58b16424 | 198 | { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; } |
3b9e3455 DW |
199 | |
200 | inline wxDC* GetSelectedInto() const | |
58b16424 | 201 | { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); } |
3b9e3455 | 202 | |
79c09341 | 203 | inline bool IsMono(void) const { return m_bIsMono; } |
1759c491 | 204 | |
4f72fe4f | 205 | // An OS/2 version that probably doesn't do anything like the msw version |
3b9e3455 | 206 | wxBitmap GetBitmapForDC(wxDC& rDc) const; |
0e320a79 | 207 | |
3b9e3455 DW |
208 | protected: |
209 | // common part of all ctors | |
210 | void Init(); | |
0e320a79 | 211 | |
3b9e3455 DW |
212 | inline virtual wxGDIImageRefData* CreateData() const |
213 | { return new wxBitmapRefData; } | |
0e320a79 | 214 | |
fd859211 | 215 | bool CreateFromImage(const wxImage& image, int depth); |
341366c6 | 216 | |
3b9e3455 DW |
217 | private: |
218 | bool CopyFromIconOrCursor(const wxGDIImage& rIcon); | |
0e320a79 | 219 | |
79c09341 | 220 | bool m_bIsMono; |
3b9e3455 | 221 | DECLARE_DYNAMIC_CLASS(wxBitmap) |
341366c6 | 222 | }; // end of CLASS wxBitmap |
d88de032 | 223 | |
3b9e3455 DW |
224 | // ---------------------------------------------------------------------------- |
225 | // wxMask: a mono bitmap used for drawing bitmaps transparently. | |
226 | // ---------------------------------------------------------------------------- | |
0e320a79 | 227 | |
3b9e3455 DW |
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; } | |
0e320a79 | 267 | |
0e320a79 | 268 | protected: |
3b9e3455 DW |
269 | WXHBITMAP m_hMaskBitmap; |
270 | DECLARE_DYNAMIC_CLASS(wxMask) | |
8bb6da4a | 271 | }; // end of CLASS wxMask |
3b9e3455 DW |
272 | |
273 | // ---------------------------------------------------------------------------- | |
274 | // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file | |
275 | // ---------------------------------------------------------------------------- | |
0e320a79 | 276 | |
3b9e3455 DW |
277 | class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler |
278 | { | |
0e320a79 | 279 | public: |
3b9e3455 DW |
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 | |
452418c4 | 296 | ,const void* pData |
3b9e3455 DW |
297 | ,long lFlags |
298 | ,int nWidth | |
299 | ,int nHeight | |
300 | ,int nDepth = 1 | |
301 | ); | |
302 | virtual bool LoadFile( wxBitmap* pBitmap | |
b6f4144e | 303 | ,int nId |
3b9e3455 DW |
304 | ,long lFlags |
305 | ,int nDesiredWidth | |
306 | ,int nDesiredHeight | |
307 | ); | |
c90c3400 SN |
308 | virtual bool LoadFile( wxBitmap* pBitmap |
309 | ,const wxString& rName | |
310 | ,long lFlags | |
311 | ,int nDesiredWidth | |
312 | ,int nDesiredHeight | |
313 | ); | |
3b9e3455 DW |
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 | |
452418c4 | 321 | ,const void* pData |
3b9e3455 DW |
322 | ,long lFlags |
323 | ,int nWidth | |
324 | ,int nHeight | |
325 | ,int nDepth = 1 | |
326 | ); | |
327 | virtual bool Load( wxGDIImage* pImage | |
b6f4144e | 328 | ,int nId |
3b9e3455 DW |
329 | ,long lFlags |
330 | ,int nDesiredWidth | |
331 | ,int nDesiredHeight | |
332 | ); | |
58b16424 DW |
333 | virtual bool Save( wxGDIImage* pImage |
334 | ,const wxString& rName | |
335 | ,int lType | |
3b9e3455 DW |
336 | ); |
337 | private: | |
7e1e6965 WS |
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) | |
b6f4144e | 344 | ) |
7e1e6965 | 345 | { return false; } |
3b9e3455 | 346 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) |
8bb6da4a | 347 | }; // end of CLASS wxBitmapHandler |
3b9e3455 | 348 | |
0e320a79 DW |
349 | #endif |
350 | // _WX_BITMAP_H_ |