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