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