]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
bitmap and image updates
[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/gdiimage.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
22
23 class WXDLLEXPORT wxDC;
24 class WXDLLEXPORT wxControl;
25 class WXDLLEXPORT wxBitmap;
26 class WXDLLEXPORT wxBitmapHandler;
27 class WXDLLEXPORT wxIcon;
28 class WXDLLEXPORT wxMask;
29 class WXDLLEXPORT wxCursor;
30 class WXDLLEXPORT wxControl;
31
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 // ----------------------------------------------------------------------------
38
39 class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
40 {
41 public:
42 wxBitmapRefData();
43 virtual ~wxBitmapRefData() { Free(); }
44
45 virtual void Free();
46
47 public:
48 int m_nNumColors;
49 wxPalette m_vBitmapPalette;
50 int m_nQuality;
51
52 // OS2-specific
53 // ------------
54
55 wxDC* m_pSelectedInto;
56 HPS m_hPresentationSpace;
57
58 // optional mask for transparent drawing
59 wxMask* m_pBitmapMask;
60 };
61
62 // ----------------------------------------------------------------------------
63 // wxBitmap: a mono or colour bitmap
64 // ----------------------------------------------------------------------------
65
66 class WXDLLEXPORT wxBitmap : public wxGDIImage
67 {
68 public:
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
185
186 #if WXWIN_COMPATIBILITY
187 inline wxPalette* GetColourMap() const
188 { return GetPalette(); }
189
190 inline void SetColourMap(wxPalette* pCmap)
191 { SetPalette(*pCmap); };
192
193 #endif // WXWIN_COMPATIBILITY
194
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
209 // Creates a bitmap that matches the device context's depth, from an
210 // arbitray bitmap. At present, the original bitmap must have an associated
211 // palette. (TODO: use a default palette if no palette exists.) This
212 // function is necessary for you to Blit an arbitrary bitmap (which may
213 // have the wrong depth). wxDC::SelectObject will compare the depth of the
214 // bitmap with the DC's depth, and create a new bitmap if the depths
215 // differ. Eventually we should perhaps make this a public API function so
216 // that an app can efficiently produce bitmaps of the correct depth. The
217 // Windows solution is to use SetDibBits to blit an arbotrary DIB directly
218 // to a DC, but this is too Windows-specific, hence this solution of
219 // quietly converting the wxBitmap. Contributed by Frederic Villeneuve
220 // <frederic.villeneuve@natinst.com>
221 wxBitmap GetBitmapForDC(wxDC& rDc) const;
222
223 protected:
224 // common part of all ctors
225 void Init();
226
227 inline virtual wxGDIImageRefData* CreateData() const
228 { return new wxBitmapRefData; }
229
230 private:
231 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
232
233 DECLARE_DYNAMIC_CLASS(wxBitmap)
234 };
235
236 // ----------------------------------------------------------------------------
237 // wxMask: a mono bitmap used for drawing bitmaps transparently.
238 // ----------------------------------------------------------------------------
239
240 class WXDLLEXPORT wxMask : public wxObject
241 {
242 public:
243 wxMask();
244
245 // Construct a mask from a bitmap and a colour indicating the transparent
246 // area
247 wxMask( const wxBitmap& rBitmap
248 ,const wxColour& rColour
249 );
250
251 // Construct a mask from a bitmap and a palette index indicating the
252 // transparent area
253 wxMask( const wxBitmap& rBitmap
254 ,int nPaletteIndex
255 );
256
257 // Construct a mask from a mono bitmap (copies the bitmap).
258 wxMask(const wxBitmap& rBitmap);
259
260 // construct a mask from the givne bitmap handle
261 wxMask(WXHBITMAP hBmp)
262 { m_hMaskBitmap = hBmp; }
263
264 virtual ~wxMask();
265
266 bool Create( const wxBitmap& bitmap
267 ,const wxColour& rColour
268 );
269 bool Create( const wxBitmap& rBitmap
270 ,int nPaletteIndex
271 );
272 bool Create(const wxBitmap& rBitmap);
273
274 // Implementation
275 WXHBITMAP GetMaskBitmap() const
276 { return m_hMaskBitmap; }
277 void SetMaskBitmap(WXHBITMAP hBmp)
278 { m_hMaskBitmap = hBmp; }
279
280 protected:
281 WXHBITMAP m_hMaskBitmap;
282 DECLARE_DYNAMIC_CLASS(wxMask)
283 };
284
285 // ----------------------------------------------------------------------------
286 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
287 // ----------------------------------------------------------------------------
288
289 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
290 {
291 public:
292 inline wxBitmapHandler()
293 { m_lType = wxBITMAP_TYPE_INVALID; }
294
295 inline wxBitmapHandler( const wxString& rName
296 ,const wxString& rExt
297 ,long lType
298 )
299 : wxGDIImageHandler( rName
300 ,rExt
301 ,lType)
302 {
303 }
304
305 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
306 // old class which worked only with bitmaps
307 virtual bool Create( wxBitmap* pBitmap
308 ,void* pData
309 ,long lFlags
310 ,int nWidth
311 ,int nHeight
312 ,int nDepth = 1
313 );
314 virtual bool LoadFile( wxBitmap* pBitmap
315 ,const wxString& rName
316 ,long lFlags
317 ,int nDesiredWidth
318 ,int nDesiredHeight
319 );
320 virtual bool SaveFile( wxBitmap* pBitmap
321 ,const wxString& rName
322 ,int lType
323 ,const wxPalette* pPalette = NULL
324 );
325
326 virtual bool Create( wxGDIImage* pImage
327 ,void* pData
328 ,long lFlags
329 ,int nWidth
330 ,int nHeight
331 ,int nDepth = 1
332 );
333 virtual bool Load( wxGDIImage* pImage
334 ,const wxString& rName
335 ,long lFlags
336 ,int nDesiredWidth
337 ,int nDesiredHeight
338 );
339 virtual bool Save(wxGDIImage* pImage
340 const wxString& rName
341 int lType
342 );
343 private:
344 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
345 };
346
347 #endif
348 // _WX_BITMAP_H_