]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
fixed virtual function hiding for LoadBitmap()
[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 class WXDLLEXPORT wxImage;
33
34 // ----------------------------------------------------------------------------
35 // Bitmap data
36 //
37 // NB: this class is private, but declared here to make it possible inline
38 // wxBitmap functions accessing it
39 // ----------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
42 {
43 public:
44 wxBitmapRefData();
45 virtual ~wxBitmapRefData() { Free(); }
46
47 virtual void Free();
48
49 public:
50 int m_nNumColors;
51 wxPalette m_vBitmapPalette;
52 int m_nQuality;
53
54 // OS2-specific
55 // ------------
56
57 wxDC* m_pSelectedInto;
58
59 //
60 // Optional mask for transparent drawing
61 //
62 wxMask* m_pBitmapMask;
63 }; // end of CLASS wxBitmapRefData
64
65 // ----------------------------------------------------------------------------
66 // wxBitmap: a mono or colour bitmap
67 // ----------------------------------------------------------------------------
68
69 class WXDLLEXPORT wxBitmap : public wxGDIImage
70 {
71 public:
72 // default ctor creates an invalid bitmap, you must Create() it later
73 wxBitmap() { Init(); }
74
75 // Copy constructors
76 inline wxBitmap(const wxBitmap& rBitmap)
77 { Init(); Ref(rBitmap); SetHandle(rBitmap.GetHandle()); }
78
79 // Initialize with raw data
80 wxBitmap( const char bits[]
81 ,int nWidth
82 ,int nHeight
83 ,int nDepth = 1
84 );
85
86 // Initialize with XPM data
87 wxBitmap(const char** ppData) { CreateFromXpm(ppData); }
88 wxBitmap(char** ppData) { CreateFromXpm((const char**)ppData); }
89
90 // Load a resource
91 wxBitmap( int nId
92 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
93 );
94
95 // For compatiability with other ports, under OS/2 does same as default ctor
96 inline wxBitmap( const wxString& WXUNUSED(rFilename)
97 ,long WXUNUSED(lType)
98 )
99 { Init(); }
100 // New constructor for generalised creation from data
101 wxBitmap( void* pData
102 ,long lType
103 ,int nWidth
104 ,int nHeight
105 ,int nDepth = 1
106 );
107
108 // If depth is omitted, will create a bitmap compatible with the display
109 wxBitmap( int nWidth, int nHeight, int nDepth = -1 );
110
111 wxBitmap( const wxImage& image, int depth = -1 )
112 { (void)CreateFromImage(image, depth); }
113
114 // we must have this, otherwise icons are silently copied into bitmaps using
115 // the copy ctor but the resulting bitmap is invalid!
116 inline wxBitmap(const wxIcon& rIcon)
117 { Init(); CopyFromIcon(rIcon); }
118
119 wxBitmap& operator=(const wxBitmap& rBitmap)
120 {
121 if ( m_refData != rBitmap.m_refData )
122 Ref(rBitmap);
123 return(*this);
124 }
125
126 wxBitmap& operator=(const wxIcon& rIcon)
127 {
128 (void)CopyFromIcon(rIcon);
129
130 return(*this);
131 }
132
133 wxBitmap& operator=(const wxCursor& rCursor)
134 {
135 (void)CopyFromCursor(rCursor);
136 return (*this);
137 }
138
139 virtual ~wxBitmap();
140
141 wxImage ConvertToImage() const;
142
143 // get the given part of bitmap
144 wxBitmap GetSubBitmap(const wxRect& rRect) const;
145
146 // copies the contents and mask of the given (colour) icon to the bitmap
147 bool CopyFromIcon(const wxIcon& rIcon);
148
149 // copies the contents and mask of the given cursor to the bitmap
150 bool CopyFromCursor(const wxCursor& rCursor);
151
152 virtual bool Create( int nWidth
153 ,int nHeight
154 ,int nDepth = -1
155 );
156 virtual bool Create( void* pData
157 ,long lType
158 ,int nWidth
159 ,int nHeight
160 ,int nDepth = 1
161 );
162 virtual bool LoadFile( int nId
163 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
164 );
165 virtual bool SaveFile( const wxString& rName
166 ,int lType
167 ,const wxPalette* pCmap = NULL
168 );
169
170 inline wxBitmapRefData* GetBitmapData() const
171 { return (wxBitmapRefData *)m_refData; }
172
173 inline int GetQuality() const
174 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
175
176 void SetQuality(int nQ);
177
178 wxPalette* GetPalette() const
179 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
180
181 void SetPalette(const wxPalette& rPalette);
182
183 inline wxMask* GetMask() const
184 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
185
186 void SetMask(wxMask* pMask) ;
187
188 inline bool operator==(const wxBitmap& rBitmap) const
189 { return m_refData == rBitmap.m_refData; }
190
191 inline bool operator!=(const wxBitmap& rBitmap) const
192 { return m_refData != rBitmap.m_refData; }
193
194 // Implementation
195 public:
196 inline void SetHBITMAP(WXHBITMAP hBmp)
197 { SetHandle((WXHANDLE)hBmp); }
198
199 inline WXHBITMAP GetHBITMAP() const
200 { return (WXHBITMAP)GetHandle(); }
201
202 inline void SetSelectedInto(wxDC* pDc)
203 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
204
205 inline wxDC* GetSelectedInto() const
206 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
207
208 inline bool IsMono(void) const { return m_bIsMono; }
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 // creates the bitmap from XPM data, supposed to be called from ctor
221 bool CreateFromXpm(const char** ppData);
222 bool CreateFromImage(const wxImage& image, int depth);
223
224 private:
225 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
226
227 bool m_bIsMono;
228 DECLARE_DYNAMIC_CLASS(wxBitmap)
229 }; // end of CLASS wxBitmap
230
231 // ----------------------------------------------------------------------------
232 // wxMask: a mono bitmap used for drawing bitmaps transparently.
233 // ----------------------------------------------------------------------------
234
235 class WXDLLEXPORT wxMask : public wxObject
236 {
237 public:
238 wxMask();
239
240 // Construct a mask from a bitmap and a colour indicating the transparent
241 // area
242 wxMask( const wxBitmap& rBitmap
243 ,const wxColour& rColour
244 );
245
246 // Construct a mask from a bitmap and a palette index indicating the
247 // transparent area
248 wxMask( const wxBitmap& rBitmap
249 ,int nPaletteIndex
250 );
251
252 // Construct a mask from a mono bitmap (copies the bitmap).
253 wxMask(const wxBitmap& rBitmap);
254
255 // construct a mask from the givne bitmap handle
256 wxMask(WXHBITMAP hBmp)
257 { m_hMaskBitmap = hBmp; }
258
259 virtual ~wxMask();
260
261 bool Create( const wxBitmap& bitmap
262 ,const wxColour& rColour
263 );
264 bool Create( const wxBitmap& rBitmap
265 ,int nPaletteIndex
266 );
267 bool Create(const wxBitmap& rBitmap);
268
269 // Implementation
270 WXHBITMAP GetMaskBitmap() const
271 { return m_hMaskBitmap; }
272 void SetMaskBitmap(WXHBITMAP hBmp)
273 { m_hMaskBitmap = hBmp; }
274
275 protected:
276 WXHBITMAP m_hMaskBitmap;
277 DECLARE_DYNAMIC_CLASS(wxMask)
278 }; // end of CLASS wxMask
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 ,int nId
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 ,int nId
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 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
340 ,const wxString& WXUNUSED(rName)
341 ,HPS WXUNUSED(hPs)
342 ,long WXUNUSED(lFlags)
343 ,int WXUNUSED(nDesiredWidth)
344 ,int WXUNUSED(nDesiredHeight)
345 )
346 { return false; }
347 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
348 }; // end of CLASS wxBitmapHandler
349
350 #endif
351 // _WX_BITMAP_H_