]>
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/palette.h" |
17 | ||
b5dbe15d VS |
18 | class WXDLLIMPEXP_FWD_CORE wxBitmap; |
19 | class WXDLLIMPEXP_FWD_CORE wxBitmapHandler; | |
20 | class WXDLLIMPEXP_FWD_CORE wxBitmapRefData; | |
21 | class WXDLLIMPEXP_FWD_CORE wxControl; | |
22 | class WXDLLIMPEXP_FWD_CORE wxCursor; | |
23 | class WXDLLIMPEXP_FWD_CORE wxDC; | |
086b3a5b | 24 | #if wxUSE_WXDIB |
b5dbe15d | 25 | class WXDLLIMPEXP_FWD_CORE wxDIB; |
086b3a5b | 26 | #endif |
b5dbe15d VS |
27 | class WXDLLIMPEXP_FWD_CORE wxIcon; |
28 | class WXDLLIMPEXP_FWD_CORE wxImage; | |
29 | class WXDLLIMPEXP_FWD_CORE wxMask; | |
30 | class WXDLLIMPEXP_FWD_CORE wxPalette; | |
31 | class WXDLLIMPEXP_FWD_CORE wxPixelDataBase; | |
2bda0e17 | 32 | |
11f406f9 VZ |
33 | // What kind of transparency should a bitmap copied from an icon or cursor |
34 | // have? | |
35 | enum wxBitmapTransparency | |
36 | { | |
37 | wxBitmapTransparency_Auto, // default: copy alpha if the source has it | |
38 | wxBitmapTransparency_None, // never create alpha | |
39 | wxBitmapTransparency_Always // always use alpha | |
40 | }; | |
41 | ||
6d167489 VZ |
42 | // ---------------------------------------------------------------------------- |
43 | // wxBitmap: a mono or colour bitmap | |
e86f2cc8 | 44 | // NOTE: for wxMSW we don't use the wxBitmapBase base class declared in bitmap.h! |
6d167489 | 45 | // ---------------------------------------------------------------------------- |
2bda0e17 | 46 | |
53a2db12 | 47 | class WXDLLIMPEXP_CORE wxBitmap : public wxGDIImage |
6d167489 | 48 | { |
2bda0e17 | 49 | public: |
4fe5383d | 50 | // default ctor creates an invalid bitmap, you must Create() it later |
f8855e47 | 51 | wxBitmap() { } |
4fe5383d VZ |
52 | |
53 | // Initialize with raw data | |
54 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
55 | ||
56 | // Initialize with XPM data | |
452418c4 | 57 | wxBitmap(const char* const* data); |
459f812b | 58 | #ifdef wxNEEDS_CHARPP |
29b7b6ca PC |
59 | wxBitmap(char** data) |
60 | { | |
61 | *this = wxBitmap(wx_const_cast(const char* const*, data)); | |
62 | } | |
63 | #endif | |
2bda0e17 | 64 | |
4fe5383d | 65 | // Load a file or resource |
cbea3ec6 | 66 | wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE); |
2bda0e17 | 67 | |
4fe5383d | 68 | // New constructor for generalised creation from data |
e86f2cc8 | 69 | wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1); |
2bda0e17 | 70 | |
2cf45d69 VZ |
71 | // Create a new, uninitialized bitmap of the given size and depth (if it |
72 | // is omitted, will create a bitmap compatible with the display) | |
73 | // | |
74 | // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor | |
75 | // taking a DC argument if you want to force using DDB in this case | |
4fe5383d | 76 | wxBitmap(int width, int height, int depth = -1); |
6d51f220 | 77 | |
2cf45d69 VZ |
78 | // Create a bitmap compatible with the given DC |
79 | wxBitmap(int width, int height, const wxDC& dc); | |
80 | ||
50a9dd77 | 81 | #if wxUSE_IMAGE |
2cf45d69 | 82 | // Convert from wxImage |
6463b9f5 JS |
83 | wxBitmap(const wxImage& image, int depth = -1) |
84 | { (void)CreateFromImage(image, depth); } | |
2cf45d69 VZ |
85 | |
86 | // Create a DDB compatible with the given DC from wxImage | |
6463b9f5 JS |
87 | wxBitmap(const wxImage& image, const wxDC& dc) |
88 | { (void)CreateFromImage(image, dc); } | |
6d51f220 | 89 | #endif // wxUSE_IMAGE |
2bda0e17 | 90 | |
4fe5383d VZ |
91 | // we must have this, otherwise icons are silently copied into bitmaps using |
92 | // the copy ctor but the resulting bitmap is invalid! | |
11f406f9 VZ |
93 | wxBitmap(const wxIcon& icon, |
94 | wxBitmapTransparency transp = wxBitmapTransparency_Auto) | |
95 | { | |
96 | CopyFromIcon(icon, transp); | |
97 | } | |
2bda0e17 | 98 | |
4fe5383d VZ |
99 | wxBitmap& operator=(const wxIcon& icon) |
100 | { | |
101 | (void)CopyFromIcon(icon); | |
07cf98cb | 102 | |
4fe5383d VZ |
103 | return *this; |
104 | } | |
07cf98cb | 105 | |
6d167489 VZ |
106 | wxBitmap& operator=(const wxCursor& cursor) |
107 | { | |
108 | (void)CopyFromCursor(cursor); | |
109 | ||
110 | return *this; | |
111 | } | |
112 | ||
4fe5383d | 113 | virtual ~wxBitmap(); |
2bda0e17 | 114 | |
50a9dd77 | 115 | #if wxUSE_IMAGE |
fd859211 | 116 | wxImage ConvertToImage() const; |
6d51f220 | 117 | #endif // wxUSE_IMAGE |
fd859211 | 118 | |
4b7f2165 | 119 | // get the given part of bitmap |
8208e181 | 120 | wxBitmap GetSubBitmap( const wxRect& rect ) const; |
6d51f220 | 121 | |
18f2ae49 | 122 | // NB: This should not be called from user code. It is for wx internal |
cbea3ec6 | 123 | // use only. |
18f2ae49 KO |
124 | wxBitmap GetSubBitmapOfHDC( const wxRect& rect, WXHDC hdc ) const; |
125 | ||
4fe5383d | 126 | // copies the contents and mask of the given (colour) icon to the bitmap |
11f406f9 VZ |
127 | bool CopyFromIcon(const wxIcon& icon, |
128 | wxBitmapTransparency transp = wxBitmapTransparency_Auto); | |
2bda0e17 | 129 | |
6d167489 | 130 | // copies the contents and mask of the given cursor to the bitmap |
11f406f9 VZ |
131 | bool CopyFromCursor(const wxCursor& cursor, |
132 | wxBitmapTransparency transp = wxBitmapTransparency_Auto); | |
6d167489 | 133 | |
086b3a5b | 134 | #if wxUSE_WXDIB |
b0ea5d96 VZ |
135 | // copies from a device independent bitmap |
136 | bool CopyFromDIB(const wxDIB& dib); | |
086b3a5b | 137 | #endif |
b0ea5d96 | 138 | |
e86f2cc8 | 139 | virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH); |
2cf45d69 | 140 | virtual bool Create(int width, int height, const wxDC& dc); |
e86f2cc8 | 141 | virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1); |
cbea3ec6 | 142 | virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE); |
e86f2cc8 | 143 | virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const; |
4fe5383d | 144 | |
8bbbae21 VZ |
145 | wxBitmapRefData *GetBitmapData() const |
146 | { return (wxBitmapRefData *)m_refData; } | |
6d167489 | 147 | |
2cf45d69 | 148 | // raw bitmap access support functions |
b9bcaf11 VZ |
149 | void *GetRawData(wxPixelDataBase& data, int bpp); |
150 | void UngetRawData(wxPixelDataBase& data); | |
2cf45d69 | 151 | |
d275c7eb | 152 | #if wxUSE_PALETTE |
8bbbae21 | 153 | wxPalette* GetPalette() const; |
4fe5383d | 154 | void SetPalette(const wxPalette& palette); |
d275c7eb | 155 | #endif // wxUSE_PALETTE |
2bda0e17 | 156 | |
8bbbae21 | 157 | wxMask *GetMask() const; |
ec023a6e | 158 | wxBitmap GetMaskBitmap() const; |
acf8e3d2 | 159 | void SetMask(wxMask *mask); |
2bda0e17 | 160 | |
10b41b53 VZ |
161 | // these functions are internal and shouldn't be used, they risk to |
162 | // disappear in the future | |
acf8e3d2 | 163 | bool HasAlpha() const; |
10b41b53 | 164 | void UseAlpha(); |
8bbbae21 | 165 | |
2cf45d69 VZ |
166 | // implementation only from now on |
167 | // ------------------------------- | |
2bda0e17 | 168 | |
2bda0e17 | 169 | public: |
6d167489 VZ |
170 | void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); } |
171 | WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); } | |
172 | ||
acf8e3d2 | 173 | #ifdef __WXDEBUG__ |
8bbbae21 VZ |
174 | void SetSelectedInto(wxDC *dc); |
175 | wxDC *GetSelectedInto() const; | |
acf8e3d2 | 176 | #endif // __WXDEBUG__ |
6d167489 | 177 | |
4fe5383d | 178 | protected: |
8bbbae21 | 179 | virtual wxGDIImageRefData *CreateData() const; |
8f884a0d | 180 | virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; |
6d167489 | 181 | |
2cf45d69 VZ |
182 | // creates an uninitialized bitmap, called from Create()s above |
183 | bool DoCreate(int w, int h, int depth, WXHDC hdc); | |
184 | ||
50a9dd77 | 185 | #if wxUSE_IMAGE |
fd859211 VS |
186 | // creates the bitmap from wxImage, supposed to be called from ctor |
187 | bool CreateFromImage(const wxImage& image, int depth); | |
4b7f2165 | 188 | |
2cf45d69 VZ |
189 | // creates a DDB from wxImage, supposed to be called from ctor |
190 | bool CreateFromImage(const wxImage& image, const wxDC& dc); | |
8bbbae21 | 191 | |
2cf45d69 VZ |
192 | // common part of the 2 methods above (hdc may be 0) |
193 | bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc); | |
194 | #endif // wxUSE_IMAGE | |
0becd470 | 195 | |
4fe5383d | 196 | private: |
6d167489 | 197 | // common part of CopyFromIcon/CopyFromCursor for Win32 |
11f406f9 VZ |
198 | bool |
199 | CopyFromIconOrCursor(const wxGDIImage& icon, | |
200 | wxBitmapTransparency transp = wxBitmapTransparency_Auto); | |
50a9dd77 | 201 | |
6d167489 | 202 | |
4fe5383d | 203 | DECLARE_DYNAMIC_CLASS(wxBitmap) |
2bda0e17 | 204 | }; |
ce3ed50d | 205 | |
6d167489 VZ |
206 | // ---------------------------------------------------------------------------- |
207 | // wxMask: a mono bitmap used for drawing bitmaps transparently. | |
208 | // ---------------------------------------------------------------------------- | |
209 | ||
53a2db12 | 210 | class WXDLLIMPEXP_CORE wxMask : public wxObject |
6d167489 VZ |
211 | { |
212 | public: | |
213 | wxMask(); | |
214 | ||
1b7c01c9 VZ |
215 | // Copy constructor |
216 | wxMask(const wxMask &mask); | |
217 | ||
6d167489 VZ |
218 | // Construct a mask from a bitmap and a colour indicating the transparent |
219 | // area | |
220 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
221 | ||
222 | // Construct a mask from a bitmap and a palette index indicating the | |
223 | // transparent area | |
224 | wxMask(const wxBitmap& bitmap, int paletteIndex); | |
225 | ||
226 | // Construct a mask from a mono bitmap (copies the bitmap). | |
227 | wxMask(const wxBitmap& bitmap); | |
228 | ||
229 | // construct a mask from the givne bitmap handle | |
230 | wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; } | |
231 | ||
232 | virtual ~wxMask(); | |
233 | ||
234 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
235 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
236 | bool Create(const wxBitmap& bitmap); | |
237 | ||
238 | // Implementation | |
239 | WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } | |
240 | void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } | |
241 | ||
242 | protected: | |
243 | WXHBITMAP m_maskBitmap; | |
244 | ||
245 | DECLARE_DYNAMIC_CLASS(wxMask) | |
246 | }; | |
247 | ||
e86f2cc8 | 248 | |
6d167489 VZ |
249 | // ---------------------------------------------------------------------------- |
250 | // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file | |
e86f2cc8 | 251 | // NOTE: for wxMSW we don't use the wxBitmapHandler class declared in bitmap.h! |
6d167489 VZ |
252 | // ---------------------------------------------------------------------------- |
253 | ||
53a2db12 | 254 | class WXDLLIMPEXP_CORE wxBitmapHandler : public wxGDIImageHandler |
6d167489 VZ |
255 | { |
256 | public: | |
cb62a16a | 257 | wxBitmapHandler() { } |
e86f2cc8 FM |
258 | wxBitmapHandler(const wxString& name, const wxString& ext, wxBitmapType type) |
259 | : wxGDIImageHandler(name, ext, type) { } | |
6d167489 | 260 | |
e86f2cc8 | 261 | // implement wxGDIImageHandler's pure virtuals: |
6d167489 VZ |
262 | |
263 | virtual bool Create(wxGDIImage *image, | |
452418c4 | 264 | const void* data, |
e86f2cc8 | 265 | wxBitmapType type, |
6d167489 VZ |
266 | int width, int height, int depth = 1); |
267 | virtual bool Load(wxGDIImage *image, | |
268 | const wxString& name, | |
e86f2cc8 | 269 | wxBitmapType type, |
6d167489 | 270 | int desiredWidth, int desiredHeight); |
e86f2cc8 | 271 | virtual bool Save(const wxGDIImage *image, |
6d167489 | 272 | const wxString& name, |
e86f2cc8 FM |
273 | wxBitmapType type) const; |
274 | ||
275 | ||
276 | // make wxBitmapHandler compatible with the wxBitmapHandler interface | |
277 | // declared in bitmap.h, even if it's derived from wxGDIImageHandler: | |
278 | ||
279 | virtual bool Create(wxBitmap *bitmap, | |
280 | const void* data, | |
281 | wxBitmapType type, | |
282 | int width, int height, int depth = 1); | |
283 | virtual bool LoadFile(wxBitmap *bitmap, | |
284 | const wxString& name, | |
285 | wxBitmapType type, | |
286 | int desiredWidth, int desiredHeight); | |
287 | virtual bool SaveFile(const wxBitmap *bitmap, | |
288 | const wxString& name, | |
289 | wxBitmapType type, | |
290 | const wxPalette *palette = NULL) const; | |
6d167489 VZ |
291 | |
292 | private: | |
293 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
294 | }; | |
295 | ||
2bda0e17 | 296 | #endif |
bbcdf8bc | 297 | // _WX_BITMAP_H_ |