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