]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
argh... yet another compilation fix
[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
58 //
59 // Optional mask for transparent drawing
60 //
61 wxMask* m_pBitmapMask;
62 }; // end of CLASS wxBitmapRefData
63
64 // ----------------------------------------------------------------------------
65 // wxBitmap: a mono or colour bitmap
66 // ----------------------------------------------------------------------------
67
68 class WXDLLEXPORT wxBitmap : public wxGDIImage
69 {
70 public:
71 // default ctor creates an invalid bitmap, you must Create() it later
72 wxBitmap() { Init(); }
73
74 // Copy constructors
75 inline wxBitmap(const wxBitmap& rBitmap)
76 { Init(); Ref(rBitmap); }
77
78 // Initialize with raw data
79 wxBitmap( const char bits[]
80 ,int nWidth
81 ,int nHeight
82 ,int nDepth = 1
83 );
84
85 // Initialize with XPM data
86 wxBitmap(const char** ppData);
87 wxBitmap(char** ppData);
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 // get the given part of bitmap
136 wxBitmap GetSubBitmap(const wxRect& rRect) const;
137
138 // copies the contents and mask of the given (colour) icon to the bitmap
139 bool CopyFromIcon(const wxIcon& rIcon);
140
141 // copies the contents and mask of the given cursor to the bitmap
142 bool CopyFromCursor(const wxCursor& rCursor);
143
144 virtual bool Create( int nWidth
145 ,int nHeight
146 ,int nDepth = -1
147 );
148 virtual bool Create( void* pData
149 ,long lType
150 ,int nWidth
151 ,int nHeight
152 ,int nDepth = 1
153 );
154 virtual bool LoadFile( const wxString& rName
155 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
156 );
157 virtual bool SaveFile( const wxString& rName
158 ,int lType
159 ,const wxPalette* pCmap = NULL
160 );
161
162 inline wxBitmapRefData* GetBitmapData() const
163 { return (wxBitmapRefData *)m_refData; }
164
165 inline int GetQuality() const
166 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
167
168 void SetQuality(int nQ);
169
170 wxPalette* GetPalette() const
171 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
172
173 void SetPalette(const wxPalette& rPalette);
174
175 inline wxMask* GetMask() const
176 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
177
178 void SetMask(wxMask* pMask) ;
179
180 inline bool operator==(const wxBitmap& rBitmap)
181 { return m_refData == rBitmap.m_refData; }
182
183 inline bool operator!=(const wxBitmap& rBitmap)
184 { return m_refData != rBitmap.m_refData; }
185
186 #if WXWIN_COMPATIBILITY_2
187 void SetOk(bool bIsOk);
188 #endif // WXWIN_COMPATIBILITY_2
189
190 #if WXWIN_COMPATIBILITY
191 inline wxPalette* GetColourMap() const
192 { return GetPalette(); }
193
194 inline void SetColourMap(wxPalette* pCmap)
195 { SetPalette(*pCmap); };
196
197 #endif // WXWIN_COMPATIBILITY
198
199 // Implementation
200 public:
201 inline void SetHBITMAP(WXHBITMAP hBmp)
202 { SetHandle((WXHANDLE)hBmp); }
203
204 inline WXHBITMAP GetHBITMAP() const
205 { return (WXHBITMAP)GetHandle(); }
206
207 inline void SetSelectedInto(wxDC* pDc)
208 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
209
210 inline wxDC* GetSelectedInto() const
211 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
212
213 // An OS/2 version that probably doesn't do anything like the msw version
214 wxBitmap GetBitmapForDC(wxDC& rDc) const;
215
216 // inline LONG GetId() const
217 // { return (GetBitmapData() ? GetBitmapData()->m_lId : 0L); }
218
219
220 protected:
221 // common part of all ctors
222 void Init();
223
224 inline virtual wxGDIImageRefData* CreateData() const
225 { return new wxBitmapRefData; }
226
227 // creates the bitmap from XPM data, supposed to be called from ctor
228 bool CreateFromXpm(const char **bits);
229
230 private:
231 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
232
233 DECLARE_DYNAMIC_CLASS(wxBitmap)
234 }; // end of CLASS wxBitmap
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 }; // end of CLASS wxMask
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 ,HPS hPs
317 ,long lFlags
318 ,int nDesiredWidth
319 ,int nDesiredHeight
320 );
321 virtual bool SaveFile( wxBitmap* pBitmap
322 ,const wxString& rName
323 ,int lType
324 ,const wxPalette* pPalette = NULL
325 );
326
327 virtual bool Create( wxGDIImage* pImage
328 ,void* pData
329 ,long lFlags
330 ,int nWidth
331 ,int nHeight
332 ,int nDepth = 1
333 );
334 virtual bool Load( wxGDIImage* pImage
335 ,const wxString& rName
336 ,HPS hPs
337 ,long lFlags
338 ,int nDesiredWidth
339 ,int nDesiredHeight
340 );
341 virtual bool Save( wxGDIImage* pImage
342 ,const wxString& rName
343 ,int lType
344 );
345 private:
346 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
347 }; // end of CLASS wxBitmapHandler
348
349 #endif
350 // _WX_BITMAP_H_