]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
some os/2 icon-bitmap fixes
[wxWidgets.git] / include / wx / os2 / bitmap.h
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 #ifdef __GNUG__
16 #pragma interface "bitmap.h"
17 #endif
18
19 #include "wx/os2/private.h"
20 #include "wx/os2/gdiimage.h"
21 #include "wx/gdicmn.h"
22 #include "wx/palette.h"
23
24 class WXDLLEXPORT wxDC;
25 class WXDLLEXPORT wxControl;
26 class WXDLLEXPORT wxBitmap;
27 class WXDLLEXPORT wxBitmapHandler;
28 class WXDLLEXPORT wxIcon;
29 class WXDLLEXPORT wxMask;
30 class WXDLLEXPORT wxCursor;
31 class WXDLLEXPORT wxControl;
32
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 // ----------------------------------------------------------------------------
39
40 class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
41 {
42 public:
43 wxBitmapRefData();
44 virtual ~wxBitmapRefData() { Free(); }
45
46 virtual void Free();
47
48 public:
49 int m_nNumColors;
50 wxPalette m_vBitmapPalette;
51 int m_nQuality;
52
53 // OS2-specific
54 // ------------
55
56 wxDC* m_pSelectedInto;
57 HPS m_hPresentationSpace;
58
59 // optional mask for transparent drawing
60 wxMask* m_pBitmapMask;
61 };
62
63 // ----------------------------------------------------------------------------
64 // wxBitmap: a mono or colour bitmap
65 // ----------------------------------------------------------------------------
66
67 class WXDLLEXPORT wxBitmap : public wxGDIImage
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 { 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
163 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
164
165 void SetQuality(int nQ);
166
167 wxPalette* GetPalette() const
168 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
169
170 void SetPalette(const wxPalette& rPalette);
171
172 inline wxMask* GetMask() const
173 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
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
186
187 #if WXWIN_COMPATIBILITY
188 inline wxPalette* GetColourMap() const
189 { return GetPalette(); }
190
191 inline void SetColourMap(wxPalette* pCmap)
192 { SetPalette(*pCmap); };
193
194 #endif // WXWIN_COMPATIBILITY
195
196 // Implementation
197 public:
198 inline void SetHBITMAP(WXHBITMAP hBmp)
199 { SetHandle((WXHANDLE)hBmp); }
200
201 inline WXHBITMAP GetHBITMAP() const
202 { return (WXHBITMAP)GetHandle(); }
203
204 inline void SetSelectedInto(wxDC* pDc)
205 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
206
207 inline wxDC* GetSelectedInto() const
208 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
209
210 // An OS/2 version that probably doesn't do anything like the msw version
211 wxBitmap GetBitmapForDC(wxDC& rDc) const;
212
213 protected:
214 // common part of all ctors
215 void Init();
216
217 inline virtual wxGDIImageRefData* CreateData() const
218 { return new wxBitmapRefData; }
219
220 private:
221 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
222 HDC m_hDc;
223 HPS m_hPs;
224
225 DECLARE_DYNAMIC_CLASS(wxBitmap)
226 };
227
228 // ----------------------------------------------------------------------------
229 // wxMask: a mono bitmap used for drawing bitmaps transparently.
230 // ----------------------------------------------------------------------------
231
232 class WXDLLEXPORT wxMask : public wxObject
233 {
234 public:
235 wxMask();
236
237 // Construct a mask from a bitmap and a colour indicating the transparent
238 // area
239 wxMask( const wxBitmap& rBitmap
240 ,const wxColour& rColour
241 );
242
243 // Construct a mask from a bitmap and a palette index indicating the
244 // transparent area
245 wxMask( const wxBitmap& rBitmap
246 ,int nPaletteIndex
247 );
248
249 // Construct a mask from a mono bitmap (copies the bitmap).
250 wxMask(const wxBitmap& rBitmap);
251
252 // construct a mask from the givne bitmap handle
253 wxMask(WXHBITMAP hBmp)
254 { m_hMaskBitmap = hBmp; }
255
256 virtual ~wxMask();
257
258 bool Create( const wxBitmap& bitmap
259 ,const wxColour& rColour
260 );
261 bool Create( const wxBitmap& rBitmap
262 ,int nPaletteIndex
263 );
264 bool Create(const wxBitmap& rBitmap);
265
266 // Implementation
267 WXHBITMAP GetMaskBitmap() const
268 { return m_hMaskBitmap; }
269 void SetMaskBitmap(WXHBITMAP hBmp)
270 { m_hMaskBitmap = hBmp; }
271
272 protected:
273 WXHBITMAP m_hMaskBitmap;
274 DECLARE_DYNAMIC_CLASS(wxMask)
275 private:
276 HDC m_hDc;
277 HPS m_hPs;
278 };
279
280 // ----------------------------------------------------------------------------
281 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
282 // ----------------------------------------------------------------------------
283
284 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
285 {
286 public:
287 inline wxBitmapHandler()
288 { m_lType = wxBITMAP_TYPE_INVALID; }
289
290 inline wxBitmapHandler( const wxString& rName
291 ,const wxString& rExt
292 ,long lType
293 )
294 : wxGDIImageHandler( rName
295 ,rExt
296 ,lType)
297 {
298 }
299
300 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
301 // old class which worked only with bitmaps
302 virtual bool Create( wxBitmap* pBitmap
303 ,void* pData
304 ,long lFlags
305 ,int nWidth
306 ,int nHeight
307 ,int nDepth = 1
308 );
309 virtual bool LoadFile( wxBitmap* pBitmap
310 ,const wxString& rName
311 ,long lFlags
312 ,int nDesiredWidth
313 ,int nDesiredHeight
314 );
315 virtual bool SaveFile( wxBitmap* pBitmap
316 ,const wxString& rName
317 ,int lType
318 ,const wxPalette* pPalette = NULL
319 );
320
321 virtual bool Create( wxGDIImage* pImage
322 ,void* pData
323 ,long lFlags
324 ,int nWidth
325 ,int nHeight
326 ,int nDepth = 1
327 );
328 virtual bool Load( wxGDIImage* pImage
329 ,const wxString& rName
330 ,long lFlags
331 ,int nDesiredWidth
332 ,int nDesiredHeight
333 );
334 virtual bool Save( wxGDIImage* pImage
335 ,const wxString& rName
336 ,int lType
337 );
338 private:
339 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
340 };
341
342 #endif
343 // _WX_BITMAP_H_