]> git.saurik.com Git - wxWidgets.git/blob - include/wx/bitmap.h
Better fix for wxSpinCtrlGeneric enabling/disabling bug in wxMSW.
[wxWidgets.git] / include / wx / bitmap.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/bitmap.h
3 // Purpose: wxBitmap class interface
4 // Author: Vaclav Slavik
5 // Modified by:
6 // Created: 22.04.01
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BITMAP_H_BASE_
13 #define _WX_BITMAP_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/string.h"
20 #include "wx/gdicmn.h" // for wxBitmapType
21 #include "wx/colour.h"
22 #include "wx/image.h"
23
24 class WXDLLIMPEXP_FWD_CORE wxBitmap;
25 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
26 class WXDLLIMPEXP_FWD_CORE wxIcon;
27 class WXDLLIMPEXP_FWD_CORE wxMask;
28 class WXDLLIMPEXP_FWD_CORE wxPalette;
29
30 // ----------------------------------------------------------------------------
31 // wxVariant support
32 // ----------------------------------------------------------------------------
33
34 #if wxUSE_VARIANT
35 #include "wx/variant.h"
36 DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap,WXDLLIMPEXP_CORE)
37 #endif
38
39 // ----------------------------------------------------------------------------
40 // wxMask represents the transparent area of the bitmap
41 // ----------------------------------------------------------------------------
42
43 // TODO: all implementation of wxMask, except the generic one,
44 // do not derive from wxMaskBase,,, they should
45 class WXDLLIMPEXP_CORE wxMaskBase : public wxObject
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
71 #if defined(__WXMGL__) || \
72 defined(__WXDFB__) || \
73 defined(__WXMAC__) || \
74 defined(__WXGTK__) || \
75 defined(__WXCOCOA__) || \
76 defined(__WXMOTIF__) || \
77 defined(__WXX11__)
78 #define wxUSE_BITMAP_BASE 1
79 #else
80 #define wxUSE_BITMAP_BASE 0
81 #endif
82
83 // a more readable way to tell
84 #define wxBITMAP_SCREEN_DEPTH (-1)
85
86
87 // All ports except wxMSW,wxOS2,wxPalmOS use wxBitmapHandler and wxBitmapBase as base class
88 // for wxBitmapHandler; wxMSW,wxOS2,wxPalmOS use wxGDIImageHandler as base class
89 // since it allows some code reuse there.
90 #if wxUSE_BITMAP_BASE
91
92 // ----------------------------------------------------------------------------
93 // wxBitmapHandler: class which knows how to create/load/save bitmaps in
94 // different formats
95 // ----------------------------------------------------------------------------
96
97 class WXDLLIMPEXP_CORE wxBitmapHandler : public wxObject
98 {
99 public:
100 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
101 virtual ~wxBitmapHandler() { }
102
103 // NOTE: the following functions should be pure virtuals, but they aren't
104 // because otherwise almost all ports would have to implement
105 // them as "return false"...
106
107 virtual bool Create(wxBitmap *WXUNUSED(bitmap), const void* WXUNUSED(data),
108 wxBitmapType WXUNUSED(type), int WXUNUSED(width), int WXUNUSED(height),
109 int WXUNUSED(depth) = 1)
110 { return false; }
111
112 virtual bool LoadFile(wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
113 wxBitmapType WXUNUSED(type), int WXUNUSED(desiredWidth),
114 int WXUNUSED(desiredHeight))
115 { return false; }
116
117 virtual bool SaveFile(const wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
118 wxBitmapType WXUNUSED(type), const wxPalette *WXUNUSED(palette) = NULL) const
119 { return false; }
120
121 void SetName(const wxString& name) { m_name = name; }
122 void SetExtension(const wxString& ext) { m_extension = ext; }
123 void SetType(wxBitmapType type) { m_type = type; }
124 const wxString& GetName() const { return m_name; }
125 const wxString& GetExtension() const { return m_extension; }
126 wxBitmapType GetType() const { return m_type; }
127
128 private:
129 wxString m_name;
130 wxString m_extension;
131 wxBitmapType m_type;
132
133 DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
134 };
135
136
137 // ----------------------------------------------------------------------------
138 // wxBitmap: class which represents platform-dependent bitmap (unlike wxImage)
139 // ----------------------------------------------------------------------------
140
141 class WXDLLIMPEXP_CORE wxBitmapBase : public wxGDIObject
142 {
143 public:
144 /*
145 Derived class must implement these:
146
147 wxBitmap();
148 wxBitmap(const wxBitmap& bmp);
149 wxBitmap(const char bits[], int width, int height, int depth = 1);
150 wxBitmap(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
151 wxBitmap(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH);
152 wxBitmap(const char* const* bits);
153 wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
154 wxBitmap(const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH);
155
156 static void InitStandardHandlers();
157 */
158
159 virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
160 virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
161
162 virtual int GetHeight() const = 0;
163 virtual int GetWidth() const = 0;
164 virtual int GetDepth() const = 0;
165
166 wxSize GetSize() const
167 { return wxSize(GetWidth(), GetHeight()); }
168
169 #if wxUSE_IMAGE
170 virtual wxImage ConvertToImage() const = 0;
171
172 // Convert to disabled (dimmed) bitmap.
173 wxBitmap ConvertToDisabled(unsigned char brightness = 255) const;
174 #endif // wxUSE_IMAGE
175
176 virtual wxMask *GetMask() const = 0;
177 virtual void SetMask(wxMask *mask) = 0;
178
179 virtual wxBitmap GetSubBitmap(const wxRect& rect) const = 0;
180
181 virtual bool SaveFile(const wxString &name, wxBitmapType type,
182 const wxPalette *palette = NULL) const = 0;
183 virtual bool LoadFile(const wxString &name, wxBitmapType type) = 0;
184
185 /*
186 If raw bitmap access is supported (see wx/rawbmp.h), the following
187 methods should be implemented:
188
189 virtual bool GetRawData(wxRawBitmapData *data) = 0;
190 virtual void UngetRawData(wxRawBitmapData *data) = 0;
191 */
192
193 #if wxUSE_PALETTE
194 virtual wxPalette *GetPalette() const = 0;
195 virtual void SetPalette(const wxPalette& palette) = 0;
196 #endif // wxUSE_PALETTE
197
198 // copies the contents and mask of the given (colour) icon to the bitmap
199 virtual bool CopyFromIcon(const wxIcon& icon) = 0;
200
201 // implementation:
202 virtual void SetHeight(int height) = 0;
203 virtual void SetWidth(int width) = 0;
204 virtual void SetDepth(int depth) = 0;
205
206 // Format handling
207 static inline wxList& GetHandlers() { return sm_handlers; }
208 static void AddHandler(wxBitmapHandler *handler);
209 static void InsertHandler(wxBitmapHandler *handler);
210 static bool RemoveHandler(const wxString& name);
211 static wxBitmapHandler *FindHandler(const wxString& name);
212 static wxBitmapHandler *FindHandler(const wxString& extension, wxBitmapType bitmapType);
213 static wxBitmapHandler *FindHandler(wxBitmapType bitmapType);
214
215 //static void InitStandardHandlers();
216 // (wxBitmap must implement this one)
217
218 static void CleanUpHandlers();
219
220 // this method is only used by the generic implementation of wxMask
221 // currently but could be useful elsewhere in the future: it can be
222 // overridden to quantize the colour to correspond to bitmap colour depth
223 // if necessary; default implementation simply returns the colour as is
224 virtual wxColour QuantizeColour(const wxColour& colour) const
225 {
226 return colour;
227 }
228
229 protected:
230 static wxList sm_handlers;
231
232 DECLARE_ABSTRACT_CLASS(wxBitmapBase)
233 };
234
235 #endif // wxUSE_BITMAP_BASE
236
237
238 // the wxBITMAP_DEFAULT_TYPE constant defines the default argument value
239 // for wxBitmap's ctor and wxBitmap::LoadFile() functions.
240 #if defined(__WXPALMOS__)
241 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
242 #include "wx/palmos/bitmap.h"
243 #elif defined(__WXMSW__)
244 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
245 #include "wx/msw/bitmap.h"
246 #elif defined(__WXMOTIF__)
247 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
248 #include "wx/x11/bitmap.h"
249 #elif defined(__WXGTK20__)
250 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
251 #include "wx/gtk/bitmap.h"
252 #elif defined(__WXGTK__)
253 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
254 #include "wx/gtk1/bitmap.h"
255 #elif defined(__WXX11__)
256 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
257 #include "wx/x11/bitmap.h"
258 #elif defined(__WXMGL__)
259 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
260 #include "wx/mgl/bitmap.h"
261 #elif defined(__WXDFB__)
262 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
263 #include "wx/dfb/bitmap.h"
264 #elif defined(__WXMAC__)
265 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_PICT_RESOURCE
266 #include "wx/osx/bitmap.h"
267 #elif defined(__WXCOCOA__)
268 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
269 #include "wx/cocoa/bitmap.h"
270 #elif defined(__WXPM__)
271 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
272 #include "wx/os2/bitmap.h"
273 #endif
274
275 #if wxUSE_IMAGE
276 inline
277 wxBitmap
278 #if wxUSE_BITMAP_BASE
279 wxBitmapBase::
280 #else
281 wxBitmap::
282 #endif
283 ConvertToDisabled(unsigned char brightness) const
284 {
285 return ConvertToImage().ConvertToDisabled(brightness);
286 }
287 #endif // wxUSE_IMAGE
288
289 // we must include generic mask.h after wxBitmap definition
290 #if defined(__WXMGL__) || defined(__WXDFB__)
291 #define wxUSE_GENERIC_MASK 1
292 #else
293 #define wxUSE_GENERIC_MASK 0
294 #endif
295
296 #if wxUSE_GENERIC_MASK
297 #include "wx/generic/mask.h"
298 #endif
299
300 #endif // _WX_BITMAP_H_BASE_