]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/bitmap.h | |
3 | // Purpose: wxBitmap class interface | |
4 | // Author: Vaclav Slavik | |
5 | // Modified by: | |
6 | // Created: 22.04.01 | |
77ffb593 | 7 | // Copyright: (c) wxWidgets team |
65571936 | 8 | // Licence: wxWindows licence |
1e6feb95 VZ |
9 | /////////////////////////////////////////////////////////////////////////////// |
10 | ||
34138703 JS |
11 | #ifndef _WX_BITMAP_H_BASE_ |
12 | #define _WX_BITMAP_H_BASE_ | |
c801d85f | 13 | |
1e6feb95 VZ |
14 | // ---------------------------------------------------------------------------- |
15 | // headers | |
16 | // ---------------------------------------------------------------------------- | |
17 | ||
1e6feb95 | 18 | #include "wx/string.h" |
22bd9387 | 19 | #include "wx/gdicmn.h" // for wxBitmapType |
acb53ea5 | 20 | #include "wx/colour.h" |
ac04aa99 | 21 | #include "wx/image.h" |
1e6feb95 | 22 | |
b5dbe15d VS |
23 | class WXDLLIMPEXP_FWD_CORE wxBitmap; |
24 | class WXDLLIMPEXP_FWD_CORE wxBitmapHandler; | |
25 | class WXDLLIMPEXP_FWD_CORE wxIcon; | |
b5dbe15d VS |
26 | class WXDLLIMPEXP_FWD_CORE wxMask; |
27 | class WXDLLIMPEXP_FWD_CORE wxPalette; | |
a85ccd79 | 28 | class WXDLLIMPEXP_FWD_CORE wxDC; |
1e6feb95 | 29 | |
6f5d7825 RR |
30 | // ---------------------------------------------------------------------------- |
31 | // wxVariant support | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | #if wxUSE_VARIANT | |
35 | #include "wx/variant.h" | |
53a2db12 | 36 | DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap,WXDLLIMPEXP_CORE) |
6f5d7825 RR |
37 | #endif |
38 | ||
87f83ac8 VZ |
39 | // ---------------------------------------------------------------------------- |
40 | // wxMask represents the transparent area of the bitmap | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
e86f2cc8 FM |
43 | // TODO: all implementation of wxMask, except the generic one, |
44 | // do not derive from wxMaskBase,,, they should | |
53a2db12 | 45 | class WXDLLIMPEXP_CORE wxMaskBase : public wxObject |
87f83ac8 VZ |
46 | { |
47 | public: | |
48 | // create the mask from bitmap pixels of the given colour | |
49 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
50 | ||
51 | #if wxUSE_PALETTE | |
52 | // create the mask from bitmap pixels with the given palette index | |
53 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
54 | #endif // wxUSE_PALETTE | |
55 | ||
56 | // create the mask from the given mono bitmap | |
57 | bool Create(const wxBitmap& bitmap); | |
58 | ||
59 | protected: | |
60 | // this function is called from Create() to free the existing mask data | |
61 | virtual void FreeData() = 0; | |
62 | ||
63 | // these functions must be overridden to implement the corresponding public | |
64 | // Create() methods, they shouldn't call FreeData() as it's already called | |
65 | // by the public wrappers | |
66 | virtual bool InitFromColour(const wxBitmap& bitmap, | |
67 | const wxColour& colour) = 0; | |
68 | virtual bool InitFromMonoBitmap(const wxBitmap& bitmap) = 0; | |
69 | }; | |
70 | ||
0e1f8ea4 | 71 | #if defined(__WXDFB__) || \ |
d22004c4 | 72 | defined(__WXMAC__) || \ |
4611dd06 | 73 | defined(__WXGTK__) || \ |
d22004c4 WS |
74 | defined(__WXCOCOA__) || \ |
75 | defined(__WXMOTIF__) || \ | |
76 | defined(__WXX11__) | |
91885f46 VZ |
77 | #define wxUSE_BITMAP_BASE 1 |
78 | #else | |
79 | #define wxUSE_BITMAP_BASE 0 | |
80 | #endif | |
81 | ||
e86f2cc8 FM |
82 | // a more readable way to tell |
83 | #define wxBITMAP_SCREEN_DEPTH (-1) | |
84 | ||
85 | ||
20e6714a VZ |
86 | // ---------------------------------------------------------------------------- |
87 | // wxBitmapHelpers: container for various bitmap methods common to all ports. | |
88 | // ---------------------------------------------------------------------------- | |
89 | ||
90 | // Unfortunately, currently wxBitmap does not inherit from wxBitmapBase on all | |
91 | // platforms and this is not easy to fix. So we extract at least some common | |
c3f641cb | 92 | // methods into this class from which both wxBitmapBase (and hence wxBitmap on |
20e6714a VZ |
93 | // all platforms where it does inherit from it) and wxBitmap in wxMSW and other |
94 | // exceptional ports (only wxPM and old wxCocoa) inherit. | |
95 | class WXDLLIMPEXP_CORE wxBitmapHelpers | |
96 | { | |
97 | public: | |
98 | // Create a new wxBitmap from the PNG data in the given buffer. | |
99 | static wxBitmap NewFromPNGData(const void* data, size_t size); | |
100 | }; | |
101 | ||
102 | ||
bd362275 VZ |
103 | // All ports except wxMSW and wxOS2 use wxBitmapHandler and wxBitmapBase as |
104 | // base class for wxBitmapHandler; wxMSW and wxOS2 use wxGDIImageHandler as | |
105 | // base class since it allows some code reuse there. | |
91885f46 | 106 | #if wxUSE_BITMAP_BASE |
b496583b | 107 | |
1e6feb95 VZ |
108 | // ---------------------------------------------------------------------------- |
109 | // wxBitmapHandler: class which knows how to create/load/save bitmaps in | |
110 | // different formats | |
111 | // ---------------------------------------------------------------------------- | |
112 | ||
53a2db12 | 113 | class WXDLLIMPEXP_CORE wxBitmapHandler : public wxObject |
1e6feb95 VZ |
114 | { |
115 | public: | |
e86f2cc8 FM |
116 | wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; } |
117 | virtual ~wxBitmapHandler() { } | |
118 | ||
119 | // NOTE: the following functions should be pure virtuals, but they aren't | |
120 | // because otherwise almost all ports would have to implement | |
121 | // them as "return false"... | |
1e6feb95 | 122 | |
e86f2cc8 FM |
123 | virtual bool Create(wxBitmap *WXUNUSED(bitmap), const void* WXUNUSED(data), |
124 | wxBitmapType WXUNUSED(type), int WXUNUSED(width), int WXUNUSED(height), | |
125 | int WXUNUSED(depth) = 1) | |
126 | { return false; } | |
127 | ||
128 | virtual bool LoadFile(wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name), | |
129 | wxBitmapType WXUNUSED(type), int WXUNUSED(desiredWidth), | |
130 | int WXUNUSED(desiredHeight)) | |
131 | { return false; } | |
132 | ||
133 | virtual bool SaveFile(const wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name), | |
134 | wxBitmapType WXUNUSED(type), const wxPalette *WXUNUSED(palette) = NULL) const | |
135 | { return false; } | |
1e6feb95 | 136 | |
4b61c88d RR |
137 | void SetName(const wxString& name) { m_name = name; } |
138 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
139 | void SetType(wxBitmapType type) { m_type = type; } | |
452418c4 PC |
140 | const wxString& GetName() const { return m_name; } |
141 | const wxString& GetExtension() const { return m_extension; } | |
4b61c88d RR |
142 | wxBitmapType GetType() const { return m_type; } |
143 | ||
144 | private: | |
1e6feb95 VZ |
145 | wxString m_name; |
146 | wxString m_extension; | |
147 | wxBitmapType m_type; | |
148 | ||
e86f2cc8 | 149 | DECLARE_ABSTRACT_CLASS(wxBitmapHandler) |
1e6feb95 VZ |
150 | }; |
151 | ||
e86f2cc8 FM |
152 | // ---------------------------------------------------------------------------- |
153 | // wxBitmap: class which represents platform-dependent bitmap (unlike wxImage) | |
154 | // ---------------------------------------------------------------------------- | |
155 | ||
20e6714a VZ |
156 | class WXDLLIMPEXP_CORE wxBitmapBase : public wxGDIObject, |
157 | public wxBitmapHelpers | |
1e6feb95 VZ |
158 | { |
159 | public: | |
1e6feb95 VZ |
160 | /* |
161 | Derived class must implement these: | |
162 | ||
163 | wxBitmap(); | |
e86f2cc8 | 164 | wxBitmap(const wxBitmap& bmp); |
1e6feb95 | 165 | wxBitmap(const char bits[], int width, int height, int depth = 1); |
e86f2cc8 | 166 | wxBitmap(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH); |
732d8c74 | 167 | wxBitmap(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH); |
452418c4 | 168 | wxBitmap(const char* const* bits); |
1e6feb95 | 169 | wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM); |
e86f2cc8 | 170 | wxBitmap(const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH); |
1e6feb95 VZ |
171 | |
172 | static void InitStandardHandlers(); | |
173 | */ | |
174 | ||
e86f2cc8 | 175 | virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH) = 0; |
732d8c74 | 176 | virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH) = 0; |
a066916b | 177 | virtual bool CreateScaled(int w, int h, int d, double logicalScale) |
b5ec0c78 | 178 | { return Create(w*logicalScale,h*logicalScale,d); } |
e86f2cc8 | 179 | |
1e6feb95 VZ |
180 | virtual int GetHeight() const = 0; |
181 | virtual int GetWidth() const = 0; | |
182 | virtual int GetDepth() const = 0; | |
183 | ||
c74b07ac FM |
184 | wxSize GetSize() const |
185 | { return wxSize(GetWidth(), GetHeight()); } | |
186 | ||
9afa58e3 | 187 | // support for scaled bitmaps |
a85ccd79 SC |
188 | virtual double GetScaleFactor() const { return 1.0; } |
189 | virtual double GetScaledWidth() const { return GetWidth() / GetScaleFactor(); } | |
190 | virtual double GetScaledHeight() const { return GetHeight() / GetScaleFactor(); } | |
9afa58e3 SC |
191 | virtual wxSize GetScaledSize() const |
192 | { return wxSize(GetScaledWidth(), GetScaledHeight()); } | |
193 | ||
c0521644 | 194 | #if wxUSE_IMAGE |
1e6feb95 | 195 | virtual wxImage ConvertToImage() const = 0; |
ac04aa99 VZ |
196 | |
197 | // Convert to disabled (dimmed) bitmap. | |
198 | wxBitmap ConvertToDisabled(unsigned char brightness = 255) const; | |
c0521644 | 199 | #endif // wxUSE_IMAGE |
1e6feb95 VZ |
200 | |
201 | virtual wxMask *GetMask() const = 0; | |
202 | virtual void SetMask(wxMask *mask) = 0; | |
203 | ||
204 | virtual wxBitmap GetSubBitmap(const wxRect& rect) const = 0; | |
205 | ||
206 | virtual bool SaveFile(const wxString &name, wxBitmapType type, | |
d3b9f782 | 207 | const wxPalette *palette = NULL) const = 0; |
1e6feb95 VZ |
208 | virtual bool LoadFile(const wxString &name, wxBitmapType type) = 0; |
209 | ||
f28e099e VZ |
210 | /* |
211 | If raw bitmap access is supported (see wx/rawbmp.h), the following | |
212 | methods should be implemented: | |
213 | ||
214 | virtual bool GetRawData(wxRawBitmapData *data) = 0; | |
215 | virtual void UngetRawData(wxRawBitmapData *data) = 0; | |
216 | */ | |
217 | ||
218 | #if wxUSE_PALETTE | |
1e6feb95 VZ |
219 | virtual wxPalette *GetPalette() const = 0; |
220 | virtual void SetPalette(const wxPalette& palette) = 0; | |
f28e099e | 221 | #endif // wxUSE_PALETTE |
1e6feb95 | 222 | |
1e6feb95 VZ |
223 | // copies the contents and mask of the given (colour) icon to the bitmap |
224 | virtual bool CopyFromIcon(const wxIcon& icon) = 0; | |
225 | ||
226 | // implementation: | |
227 | virtual void SetHeight(int height) = 0; | |
228 | virtual void SetWidth(int width) = 0; | |
229 | virtual void SetDepth(int depth) = 0; | |
230 | ||
231 | // Format handling | |
232 | static inline wxList& GetHandlers() { return sm_handlers; } | |
e86f2cc8 FM |
233 | static void AddHandler(wxBitmapHandler *handler); |
234 | static void InsertHandler(wxBitmapHandler *handler); | |
1e6feb95 VZ |
235 | static bool RemoveHandler(const wxString& name); |
236 | static wxBitmapHandler *FindHandler(const wxString& name); | |
237 | static wxBitmapHandler *FindHandler(const wxString& extension, wxBitmapType bitmapType); | |
238 | static wxBitmapHandler *FindHandler(wxBitmapType bitmapType); | |
239 | ||
240 | //static void InitStandardHandlers(); | |
241 | // (wxBitmap must implement this one) | |
242 | ||
243 | static void CleanUpHandlers(); | |
244 | ||
87f83ac8 VZ |
245 | // this method is only used by the generic implementation of wxMask |
246 | // currently but could be useful elsewhere in the future: it can be | |
247 | // overridden to quantize the colour to correspond to bitmap colour depth | |
248 | // if necessary; default implementation simply returns the colour as is | |
249 | virtual wxColour QuantizeColour(const wxColour& colour) const | |
250 | { | |
251 | return colour; | |
252 | } | |
253 | ||
1e6feb95 VZ |
254 | protected: |
255 | static wxList sm_handlers; | |
256 | ||
257 | DECLARE_ABSTRACT_CLASS(wxBitmapBase) | |
258 | }; | |
91885f46 VZ |
259 | |
260 | #endif // wxUSE_BITMAP_BASE | |
1e6feb95 | 261 | |
cbea3ec6 FM |
262 | |
263 | // the wxBITMAP_DEFAULT_TYPE constant defines the default argument value | |
264 | // for wxBitmap's ctor and wxBitmap::LoadFile() functions. | |
bd362275 | 265 | #if defined(__WXMSW__) |
cbea3ec6 | 266 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE |
91885f46 | 267 | #include "wx/msw/bitmap.h" |
2049ba38 | 268 | #elif defined(__WXMOTIF__) |
cbea3ec6 | 269 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM |
91885f46 | 270 | #include "wx/x11/bitmap.h" |
1be7a35c | 271 | #elif defined(__WXGTK20__) |
327972e7 VZ |
272 | #ifdef __WINDOWS__ |
273 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE | |
274 | #else | |
275 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM | |
276 | #endif | |
91885f46 | 277 | #include "wx/gtk/bitmap.h" |
1be7a35c | 278 | #elif defined(__WXGTK__) |
cbea3ec6 | 279 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM |
91885f46 | 280 | #include "wx/gtk1/bitmap.h" |
83df96d6 | 281 | #elif defined(__WXX11__) |
cbea3ec6 | 282 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM |
91885f46 | 283 | #include "wx/x11/bitmap.h" |
b3c86150 | 284 | #elif defined(__WXDFB__) |
4ca8531f | 285 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE |
91885f46 | 286 | #include "wx/dfb/bitmap.h" |
34138703 | 287 | #elif defined(__WXMAC__) |
cbea3ec6 | 288 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_PICT_RESOURCE |
ef0e9220 | 289 | #include "wx/osx/bitmap.h" |
fed66a87 | 290 | #elif defined(__WXCOCOA__) |
cbea3ec6 | 291 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE |
91885f46 | 292 | #include "wx/cocoa/bitmap.h" |
1777b9bb | 293 | #elif defined(__WXPM__) |
cbea3ec6 | 294 | #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE |
91885f46 | 295 | #include "wx/os2/bitmap.h" |
c801d85f KB |
296 | #endif |
297 | ||
ac04aa99 VZ |
298 | #if wxUSE_IMAGE |
299 | inline | |
300 | wxBitmap | |
301 | #if wxUSE_BITMAP_BASE | |
302 | wxBitmapBase:: | |
303 | #else | |
304 | wxBitmap:: | |
305 | #endif | |
306 | ConvertToDisabled(unsigned char brightness) const | |
307 | { | |
308 | return ConvertToImage().ConvertToDisabled(brightness); | |
309 | } | |
310 | #endif // wxUSE_IMAGE | |
311 | ||
87f83ac8 | 312 | // we must include generic mask.h after wxBitmap definition |
0e1f8ea4 | 313 | #if defined(__WXDFB__) |
87f83ac8 VZ |
314 | #define wxUSE_GENERIC_MASK 1 |
315 | #else | |
316 | #define wxUSE_GENERIC_MASK 0 | |
317 | #endif | |
318 | ||
319 | #if wxUSE_GENERIC_MASK | |
320 | #include "wx/generic/mask.h" | |
321 | #endif | |
322 | ||
91885f46 | 323 | #endif // _WX_BITMAP_H_BASE_ |