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