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