]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
some compilation fixes for mingw32 and not only
[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
223 DECLARE_DYNAMIC_CLASS(wxBitmap)
224 };
225
226 // ----------------------------------------------------------------------------
227 // wxMask: a mono bitmap used for drawing bitmaps transparently.
228 // ----------------------------------------------------------------------------
229
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; }
269
270 protected:
271 WXHBITMAP m_hMaskBitmap;
272 DECLARE_DYNAMIC_CLASS(wxMask)
273 private:
274 HDC m_hDc;
275 HPS m_hPs;
276 };
277
278 // ----------------------------------------------------------------------------
279 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
280 // ----------------------------------------------------------------------------
281
282 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
283 {
284 public:
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
309 ,HPS hPs
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
329 ,HPS hPs
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_