]>
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 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_BITMAP_H_ | |
13 | #define _WX_BITMAP_H_ | |
14 | ||
3b9e3455 DW |
15 | #ifdef __GNUG__ |
16 | #pragma interface "bitmap.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/os2/gdiimage.h" | |
0e320a79 DW |
20 | #include "wx/gdicmn.h" |
21 | #include "wx/palette.h" | |
22 | ||
0e320a79 DW |
23 | class WXDLLEXPORT wxDC; |
24 | class WXDLLEXPORT wxControl; | |
25 | class WXDLLEXPORT wxBitmap; | |
26 | class WXDLLEXPORT wxBitmapHandler; | |
27 | class WXDLLEXPORT wxIcon; | |
3b9e3455 | 28 | class WXDLLEXPORT wxMask; |
0e320a79 | 29 | class WXDLLEXPORT wxCursor; |
d88de032 | 30 | class WXDLLEXPORT wxControl; |
0e320a79 | 31 | |
3b9e3455 DW |
32 | // ---------------------------------------------------------------------------- |
33 | // Bitmap data | |
34 | // | |
35 | // NB: this class is private, but declared here to make it possible inline | |
36 | // wxBitmap functions accessing it | |
37 | // ---------------------------------------------------------------------------- | |
0e320a79 | 38 | |
3b9e3455 | 39 | class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData |
0e320a79 | 40 | { |
0e320a79 DW |
41 | public: |
42 | wxBitmapRefData(); | |
3b9e3455 DW |
43 | virtual ~wxBitmapRefData() { Free(); } |
44 | ||
45 | virtual void Free(); | |
0e320a79 DW |
46 | |
47 | public: | |
3b9e3455 DW |
48 | int m_nNumColors; |
49 | wxPalette m_vBitmapPalette; | |
50 | int m_nQuality; | |
0e320a79 | 51 | |
3b9e3455 DW |
52 | // OS2-specific |
53 | // ------------ | |
0e320a79 | 54 | |
3b9e3455 DW |
55 | wxDC* m_pSelectedInto; |
56 | HPS m_hPresentationSpace; | |
57 | ||
58 | // optional mask for transparent drawing | |
59 | wxMask* m_pBitmapMask; | |
0e320a79 DW |
60 | }; |
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) | |
74 | { Init(); Ref(rBitmap); } | |
75 | ||
76 | // Initialize with raw data | |
77 | wxBitmap( const char bits[] | |
78 | ,int nWidth | |
79 | ,int nHeight | |
80 | ,int nDepth = 1 | |
81 | ); | |
82 | ||
83 | // Initialize with XPM data | |
84 | wxBitmap( char** ppData | |
85 | ,wxControl* pAnItem = NULL | |
86 | ); | |
87 | ||
88 | // Load a file or resource | |
89 | wxBitmap( const wxString& rName | |
90 | ,long lType = wxBITMAP_TYPE_BMP_RESOURCE | |
91 | ); | |
92 | ||
93 | // New constructor for generalised creation from data | |
94 | wxBitmap( void* pData | |
95 | ,long lType | |
96 | ,int nWidth | |
97 | ,int nHeight | |
98 | ,int nDepth = 1 | |
99 | ); | |
100 | ||
101 | // If depth is omitted, will create a bitmap compatible with the display | |
102 | wxBitmap( int nWidth | |
103 | ,int nHeight | |
104 | ,int nDepth = -1 | |
105 | ); | |
106 | ||
107 | // we must have this, otherwise icons are silently copied into bitmaps using | |
108 | // the copy ctor but the resulting bitmap is invalid! | |
109 | inline wxBitmap(const wxIcon& rIcon) | |
110 | { Init(); CopyFromIcon(rIcon); } | |
111 | ||
112 | wxBitmap& operator=(const wxBitmap& rBitmap) | |
113 | { | |
114 | if ( m_refData != rBitmap.m_refData ) | |
115 | Ref(rBitmap); | |
116 | return(*this); | |
117 | } | |
118 | ||
119 | wxBitmap& operator=(const wxIcon& rIcon) | |
120 | { | |
121 | (void)CopyFromIcon(rIcon); | |
122 | ||
123 | return(*this); | |
124 | } | |
125 | ||
126 | wxBitmap& operator=(const wxCursor& rCursor) | |
127 | { | |
128 | (void)CopyFromCursor(rCursor); | |
129 | return (*this); | |
130 | } | |
131 | ||
132 | virtual ~wxBitmap(); | |
133 | ||
134 | // copies the contents and mask of the given (colour) icon to the bitmap | |
135 | bool CopyFromIcon(const wxIcon& rIcon); | |
136 | ||
137 | // copies the contents and mask of the given cursor to the bitmap | |
138 | bool CopyFromCursor(const wxCursor& rCursor); | |
139 | ||
140 | virtual bool Create( int nWidth | |
141 | ,int nHeight | |
142 | ,int nDepth = -1 | |
143 | ); | |
144 | virtual bool Create( void* pData | |
145 | ,long lType | |
146 | ,int nWidth | |
147 | ,int nHeight | |
148 | ,int nDepth = 1 | |
149 | ); | |
150 | virtual bool LoadFile( const wxString& rName | |
151 | ,long lType = wxBITMAP_TYPE_BMP_RESOURCE | |
152 | ); | |
153 | virtual bool SaveFile( const wxString& rName | |
154 | ,int lType | |
155 | ,const wxPalette* pCmap = NULL | |
156 | ); | |
157 | ||
158 | inline wxBitmapRefData* GetBitmapData() const | |
159 | { return (wxBitmapRefData *)m_refData; } | |
160 | ||
161 | inline int GetQuality() const | |
162 | { return (GetBitmapData() ? GetBitmapData()->m_quality : 0); } | |
163 | ||
164 | void SetQuality(int nQ); | |
165 | ||
166 | wxPalette* GetPalette() const | |
167 | { return (GetBitmapData() ? (& GetBitmapData()->m_bitmapPalette) : (wxPalette*) NULL); } | |
168 | ||
169 | void SetPalette(const wxPalette& rPalette); | |
170 | ||
171 | inline wxMask* GetMask() const | |
172 | { return (GetBitmapData() ? GetBitmapData()->m_bitmapMask : (wxMask*) NULL); } | |
173 | ||
174 | void SetMask(wxMask* pMask) ; | |
175 | ||
176 | inline bool operator==(const wxBitmap& rBitmap) | |
177 | { return m_refData == rBitmap.m_refData; } | |
178 | ||
179 | inline bool operator!=(const wxBitmap& rBitmap) | |
180 | { return m_refData != rBitmap.m_refData; } | |
181 | ||
182 | #if WXWIN_COMPATIBILITY_2 | |
183 | void SetOk(bool bIsOk); | |
184 | #endif // WXWIN_COMPATIBILITY_2 | |
0e320a79 | 185 | |
3b9e3455 DW |
186 | #if WXWIN_COMPATIBILITY |
187 | inline wxPalette* GetColourMap() const | |
188 | { return GetPalette(); } | |
0e320a79 | 189 | |
3b9e3455 DW |
190 | inline void SetColourMap(wxPalette* pCmap) |
191 | { SetPalette(*pCmap); }; | |
0e320a79 | 192 | |
3b9e3455 | 193 | #endif // WXWIN_COMPATIBILITY |
0e320a79 | 194 | |
3b9e3455 DW |
195 | // Implementation |
196 | public: | |
197 | inline void SetHBITMAP(WXHBITMAP hHmp) | |
198 | { SetHandle((WXHANDLE)bmp); } | |
199 | ||
200 | inline WXHBITMAP GetHBITMAP() const | |
201 | { return (WXHBITMAP)GetHandle(); } | |
202 | ||
203 | inline void SetSelectedInto(wxDC* pDc) | |
204 | { if (GetBitmapData()) GetBitmapData()->m_selectedInto = pDc; } | |
205 | ||
206 | inline wxDC* GetSelectedInto() const | |
207 | { return (GetBitmapData() ? GetBitmapData()->m_selectedInto : (wxDC*) NULL); } | |
208 | ||
4f72fe4f | 209 | // An OS/2 version that probably doesn't do anything like the msw version |
3b9e3455 | 210 | wxBitmap GetBitmapForDC(wxDC& rDc) const; |
0e320a79 | 211 | |
3b9e3455 DW |
212 | protected: |
213 | // common part of all ctors | |
214 | void Init(); | |
0e320a79 | 215 | |
3b9e3455 DW |
216 | inline virtual wxGDIImageRefData* CreateData() const |
217 | { return new wxBitmapRefData; } | |
0e320a79 | 218 | |
3b9e3455 DW |
219 | private: |
220 | bool CopyFromIconOrCursor(const wxGDIImage& rIcon); | |
4f72fe4f DW |
221 | HDC m_hDc; |
222 | HPS m_hPs; | |
0e320a79 | 223 | |
3b9e3455 DW |
224 | DECLARE_DYNAMIC_CLASS(wxBitmap) |
225 | }; | |
d88de032 | 226 | |
3b9e3455 DW |
227 | // ---------------------------------------------------------------------------- |
228 | // wxMask: a mono bitmap used for drawing bitmaps transparently. | |
229 | // ---------------------------------------------------------------------------- | |
0e320a79 | 230 | |
3b9e3455 DW |
231 | class WXDLLEXPORT wxMask : public wxObject |
232 | { | |
233 | public: | |
234 | wxMask(); | |
235 | ||
236 | // Construct a mask from a bitmap and a colour indicating the transparent | |
237 | // area | |
238 | wxMask( const wxBitmap& rBitmap | |
239 | ,const wxColour& rColour | |
240 | ); | |
241 | ||
242 | // Construct a mask from a bitmap and a palette index indicating the | |
243 | // transparent area | |
244 | wxMask( const wxBitmap& rBitmap | |
245 | ,int nPaletteIndex | |
246 | ); | |
247 | ||
248 | // Construct a mask from a mono bitmap (copies the bitmap). | |
249 | wxMask(const wxBitmap& rBitmap); | |
250 | ||
251 | // construct a mask from the givne bitmap handle | |
252 | wxMask(WXHBITMAP hBmp) | |
253 | { m_hMaskBitmap = hBmp; } | |
254 | ||
255 | virtual ~wxMask(); | |
256 | ||
257 | bool Create( const wxBitmap& bitmap | |
258 | ,const wxColour& rColour | |
259 | ); | |
260 | bool Create( const wxBitmap& rBitmap | |
261 | ,int nPaletteIndex | |
262 | ); | |
263 | bool Create(const wxBitmap& rBitmap); | |
264 | ||
265 | // Implementation | |
266 | WXHBITMAP GetMaskBitmap() const | |
267 | { return m_hMaskBitmap; } | |
268 | void SetMaskBitmap(WXHBITMAP hBmp) | |
269 | { m_hMaskBitmap = hBmp; } | |
0e320a79 | 270 | |
0e320a79 | 271 | protected: |
3b9e3455 DW |
272 | WXHBITMAP m_hMaskBitmap; |
273 | DECLARE_DYNAMIC_CLASS(wxMask) | |
274 | }; | |
275 | ||
276 | // ---------------------------------------------------------------------------- | |
277 | // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file | |
278 | // ---------------------------------------------------------------------------- | |
0e320a79 | 279 | |
3b9e3455 DW |
280 | class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler |
281 | { | |
0e320a79 | 282 | public: |
3b9e3455 DW |
283 | inline wxBitmapHandler() |
284 | { m_lType = wxBITMAP_TYPE_INVALID; } | |
285 | ||
286 | inline wxBitmapHandler( const wxString& rName | |
287 | ,const wxString& rExt | |
288 | ,long lType | |
289 | ) | |
290 | : wxGDIImageHandler( rName | |
291 | ,rExt | |
292 | ,lType) | |
293 | { | |
294 | } | |
295 | ||
296 | // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the | |
297 | // old class which worked only with bitmaps | |
298 | virtual bool Create( wxBitmap* pBitmap | |
299 | ,void* pData | |
300 | ,long lFlags | |
301 | ,int nWidth | |
302 | ,int nHeight | |
303 | ,int nDepth = 1 | |
304 | ); | |
305 | virtual bool LoadFile( wxBitmap* pBitmap | |
306 | ,const wxString& rName | |
307 | ,long lFlags | |
308 | ,int nDesiredWidth | |
309 | ,int nDesiredHeight | |
310 | ); | |
311 | virtual bool SaveFile( wxBitmap* pBitmap | |
312 | ,const wxString& rName | |
313 | ,int lType | |
314 | ,const wxPalette* pPalette = NULL | |
315 | ); | |
316 | ||
317 | virtual bool Create( wxGDIImage* pImage | |
318 | ,void* pData | |
319 | ,long lFlags | |
320 | ,int nWidth | |
321 | ,int nHeight | |
322 | ,int nDepth = 1 | |
323 | ); | |
324 | virtual bool Load( wxGDIImage* pImage | |
325 | ,const wxString& rName | |
326 | ,long lFlags | |
327 | ,int nDesiredWidth | |
328 | ,int nDesiredHeight | |
329 | ); | |
330 | virtual bool Save(wxGDIImage* pImage | |
331 | const wxString& rName | |
332 | int lType | |
333 | ); | |
334 | private: | |
335 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
0e320a79 | 336 | }; |
3b9e3455 | 337 | |
0e320a79 DW |
338 | #endif |
339 | // _WX_BITMAP_H_ |