]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/bitmap.h
Add wxABI_VERSION wrappers
[wxWidgets.git] / include / wx / msw / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BITMAP_H_
13 #define _WX_BITMAP_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "bitmap.h"
17 #endif
18
19 #include "wx/msw/gdiimage.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
22
23 class WXDLLEXPORT wxBitmap;
24 class WXDLLEXPORT wxBitmapHandler;
25 class WXDLLEXPORT wxBitmapRefData;
26 class WXDLLEXPORT wxControl;
27 class WXDLLEXPORT wxCursor;
28 class WXDLLEXPORT wxDC;
29 #if wxUSE_WXDIB
30 class WXDLLEXPORT wxDIB;
31 #endif
32 class WXDLLEXPORT wxIcon;
33 class WXDLLEXPORT wxImage;
34 class WXDLLEXPORT wxMask;
35 class WXDLLEXPORT wxPalette;
36 class WXDLLEXPORT wxPixelDataBase;
37
38 // ----------------------------------------------------------------------------
39 // wxBitmap: a mono or colour bitmap
40 // ----------------------------------------------------------------------------
41
42 class WXDLLEXPORT wxBitmap : public wxGDIImage
43 {
44 public:
45 // default ctor creates an invalid bitmap, you must Create() it later
46 wxBitmap() { Init(); }
47
48 // Copy constructors
49 wxBitmap(const wxBitmap& bitmap) : wxGDIImage(bitmap) { Init(); Ref(bitmap); }
50
51 // Initialize with raw data
52 wxBitmap(const char bits[], int width, int height, int depth = 1);
53
54 // Initialize with XPM data
55 wxBitmap(const char **data) { CreateFromXpm(data); }
56 wxBitmap(char **data) { CreateFromXpm((const char **)data); }
57
58 // Load a file or resource
59 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
60
61 // New constructor for generalised creation from data
62 wxBitmap(void *data, long type, int width, int height, int depth = 1);
63
64 // Create a new, uninitialized bitmap of the given size and depth (if it
65 // is omitted, will create a bitmap compatible with the display)
66 //
67 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
68 // taking a DC argument if you want to force using DDB in this case
69 wxBitmap(int width, int height, int depth = -1);
70
71 // Create a bitmap compatible with the given DC
72 wxBitmap(int width, int height, const wxDC& dc);
73
74 #if wxUSE_IMAGE && wxUSE_WXDIB
75 // Convert from wxImage
76 wxBitmap(const wxImage& image, int depth = -1)
77 { (void)CreateFromImage(image, depth); }
78
79 // Create a DDB compatible with the given DC from wxImage
80 wxBitmap(const wxImage& image, const wxDC& dc)
81 { (void)CreateFromImage(image, dc); }
82 #endif // wxUSE_IMAGE
83
84 // we must have this, otherwise icons are silently copied into bitmaps using
85 // the copy ctor but the resulting bitmap is invalid!
86 wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); }
87
88 wxBitmap& operator=(const wxBitmap& bitmap)
89 {
90 if ( m_refData != bitmap.m_refData )
91 Ref(bitmap);
92 return *this;
93 }
94
95 wxBitmap& operator=(const wxIcon& icon)
96 {
97 (void)CopyFromIcon(icon);
98
99 return *this;
100 }
101
102 wxBitmap& operator=(const wxCursor& cursor)
103 {
104 (void)CopyFromCursor(cursor);
105
106 return *this;
107 }
108
109 virtual ~wxBitmap();
110
111 #if wxUSE_IMAGE && wxUSE_WXDIB
112 wxImage ConvertToImage() const;
113 #endif // wxUSE_IMAGE
114
115 // get the given part of bitmap
116 wxBitmap GetSubBitmap( const wxRect& rect ) const;
117
118 // copies the contents and mask of the given (colour) icon to the bitmap
119 bool CopyFromIcon(const wxIcon& icon);
120
121 // copies the contents and mask of the given cursor to the bitmap
122 bool CopyFromCursor(const wxCursor& cursor);
123
124 #if wxUSE_WXDIB
125 // copies from a device independent bitmap
126 bool CopyFromDIB(const wxDIB& dib);
127 #endif
128
129 virtual bool Create(int width, int height, int depth = -1);
130 virtual bool Create(int width, int height, const wxDC& dc);
131 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
132 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
133 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
134
135 wxBitmapRefData *GetBitmapData() const
136 { return (wxBitmapRefData *)m_refData; }
137
138 // raw bitmap access support functions
139 void *GetRawData(wxPixelDataBase& data, int bpp);
140 void UngetRawData(wxPixelDataBase& data);
141
142 #if wxUSE_PALETTE
143 wxPalette* GetPalette() const;
144 void SetPalette(const wxPalette& palette);
145 #endif // wxUSE_PALETTE
146
147 wxMask *GetMask() const;
148 wxBitmap GetMaskBitmap() const;
149 void SetMask(wxMask *mask);
150
151 bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
152 bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
153
154 // these functions are internal and shouldn't be used, they risk to
155 // disappear in the future
156 bool HasAlpha() const;
157 void UseAlpha();
158
159 #if WXWIN_COMPATIBILITY_2_4
160 // these functions do nothing and are only there for backwards
161 // compatibility
162 wxDEPRECATED( int GetQuality() const );
163 wxDEPRECATED( void SetQuality(int quality) );
164 #endif // WXWIN_COMPATIBILITY_2_4
165
166 // implementation only from now on
167 // -------------------------------
168
169 public:
170 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
171 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
172
173 #ifdef __WXDEBUG__
174 void SetSelectedInto(wxDC *dc);
175 wxDC *GetSelectedInto() const;
176 #endif // __WXDEBUG__
177
178 protected:
179 // common part of all ctors
180 void Init();
181
182 virtual wxGDIImageRefData *CreateData() const;
183 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
184
185 // creates the bitmap from XPM data, supposed to be called from ctor
186 bool CreateFromXpm(const char **bits);
187
188 // creates an uninitialized bitmap, called from Create()s above
189 bool DoCreate(int w, int h, int depth, WXHDC hdc);
190
191 #if wxUSE_IMAGE && wxUSE_WXDIB
192 // creates the bitmap from wxImage, supposed to be called from ctor
193 bool CreateFromImage(const wxImage& image, int depth);
194
195 // creates a DDB from wxImage, supposed to be called from ctor
196 bool CreateFromImage(const wxImage& image, const wxDC& dc);
197
198 // common part of the 2 methods above (hdc may be 0)
199 bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc);
200 #endif // wxUSE_IMAGE
201
202 private:
203 #ifdef __WIN32__
204 // common part of CopyFromIcon/CopyFromCursor for Win32
205 bool CopyFromIconOrCursor(const wxGDIImage& icon);
206 #endif // __WIN32__
207
208 DECLARE_DYNAMIC_CLASS(wxBitmap)
209 };
210
211 // ----------------------------------------------------------------------------
212 // wxMask: a mono bitmap used for drawing bitmaps transparently.
213 // ----------------------------------------------------------------------------
214
215 class WXDLLEXPORT wxMask : public wxObject
216 {
217 public:
218 wxMask();
219
220 // Construct a mask from a bitmap and a colour indicating the transparent
221 // area
222 wxMask(const wxBitmap& bitmap, const wxColour& colour);
223
224 // Construct a mask from a bitmap and a palette index indicating the
225 // transparent area
226 wxMask(const wxBitmap& bitmap, int paletteIndex);
227
228 // Construct a mask from a mono bitmap (copies the bitmap).
229 wxMask(const wxBitmap& bitmap);
230
231 // construct a mask from the givne bitmap handle
232 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
233
234 virtual ~wxMask();
235
236 bool Create(const wxBitmap& bitmap, const wxColour& colour);
237 bool Create(const wxBitmap& bitmap, int paletteIndex);
238 bool Create(const wxBitmap& bitmap);
239
240 // Implementation
241 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
242 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
243
244 protected:
245 WXHBITMAP m_maskBitmap;
246
247 DECLARE_DYNAMIC_CLASS(wxMask)
248 };
249
250 // ----------------------------------------------------------------------------
251 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
252 // ----------------------------------------------------------------------------
253
254 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
255 {
256 public:
257 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
258 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
259 : wxGDIImageHandler(name, ext, type)
260 {
261 }
262
263 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
264 // old class which worked only with bitmaps
265 virtual bool Create(wxBitmap *bitmap,
266 void *data,
267 long flags,
268 int width, int height, int depth = 1);
269 virtual bool LoadFile(wxBitmap *bitmap,
270 const wxString& name,
271 long flags,
272 int desiredWidth, int desiredHeight);
273 virtual bool SaveFile(wxBitmap *bitmap,
274 const wxString& name,
275 int type,
276 const wxPalette *palette = NULL);
277
278 virtual bool Create(wxGDIImage *image,
279 void *data,
280 long flags,
281 int width, int height, int depth = 1);
282 virtual bool Load(wxGDIImage *image,
283 const wxString& name,
284 long flags,
285 int desiredWidth, int desiredHeight);
286 virtual bool Save(wxGDIImage *image,
287 const wxString& name,
288 int type);
289
290 private:
291 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
292 };
293
294 #endif
295 // _WX_BITMAP_H_