1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class interface
4 // Author: Vaclav Slavik
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_BITMAP_H_BASE_
13 #define _WX_BITMAP_H_BASE_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/string.h"
20 #include "wx/gdicmn.h" // for wxBitmapType
21 #include "wx/colour.h"
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
;
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
35 #include "wx/variant.h"
36 DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap
,WXDLLIMPEXP_CORE
)
39 // ----------------------------------------------------------------------------
40 // wxMask represents the transparent area of the bitmap
41 // ----------------------------------------------------------------------------
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
48 // create the mask from bitmap pixels of the given colour
49 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
52 // create the mask from bitmap pixels with the given palette index
53 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
54 #endif // wxUSE_PALETTE
56 // create the mask from the given mono bitmap
57 bool Create(const wxBitmap
& bitmap
);
60 // this function is called from Create() to free the existing mask data
61 virtual void FreeData() = 0;
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;
71 #if defined(__WXDFB__) || \
72 defined(__WXMAC__) || \
73 defined(__WXGTK__) || \
74 defined(__WXCOCOA__) || \
75 defined(__WXMOTIF__) || \
77 #define wxUSE_BITMAP_BASE 1
79 #define wxUSE_BITMAP_BASE 0
82 // a more readable way to tell
83 #define wxBITMAP_SCREEN_DEPTH (-1)
86 // ----------------------------------------------------------------------------
87 // wxBitmapHelpers: container for various bitmap methods common to all ports.
88 // ----------------------------------------------------------------------------
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
92 // methods into this class from which both wxBitmapBase (and hence wxBitmap on
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
98 // Create a new wxBitmap from the PNG data in the given buffer.
99 static wxBitmap
NewFromPNGData(const void* data
, size_t size
);
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.
106 #if wxUSE_BITMAP_BASE
108 // ----------------------------------------------------------------------------
109 // wxBitmapHandler: class which knows how to create/load/save bitmaps in
111 // ----------------------------------------------------------------------------
113 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxObject
116 wxBitmapHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
117 virtual ~wxBitmapHandler() { }
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"...
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)
128 virtual bool LoadFile(wxBitmap
*WXUNUSED(bitmap
), const wxString
& WXUNUSED(name
),
129 wxBitmapType
WXUNUSED(type
), int WXUNUSED(desiredWidth
),
130 int WXUNUSED(desiredHeight
))
133 virtual bool SaveFile(const wxBitmap
*WXUNUSED(bitmap
), const wxString
& WXUNUSED(name
),
134 wxBitmapType
WXUNUSED(type
), const wxPalette
*WXUNUSED(palette
) = NULL
) const
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
; }
140 const wxString
& GetName() const { return m_name
; }
141 const wxString
& GetExtension() const { return m_extension
; }
142 wxBitmapType
GetType() const { return m_type
; }
146 wxString m_extension
;
149 DECLARE_ABSTRACT_CLASS(wxBitmapHandler
)
152 // ----------------------------------------------------------------------------
153 // wxBitmap: class which represents platform-dependent bitmap (unlike wxImage)
154 // ----------------------------------------------------------------------------
156 class WXDLLIMPEXP_CORE wxBitmapBase
: public wxGDIObject
,
157 public wxBitmapHelpers
161 Derived class must implement these:
164 wxBitmap(const wxBitmap& bmp);
165 wxBitmap(const char bits[], int width, int height, int depth = 1);
166 wxBitmap(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
167 wxBitmap(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH);
168 wxBitmap(const char* const* bits);
169 wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
170 wxBitmap(const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH);
172 static void InitStandardHandlers();
175 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
) = 0;
176 virtual bool Create(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
) = 0;
178 virtual int GetHeight() const = 0;
179 virtual int GetWidth() const = 0;
180 virtual int GetDepth() const = 0;
182 wxSize
GetSize() const
183 { return wxSize(GetWidth(), GetHeight()); }
186 virtual wxImage
ConvertToImage() const = 0;
188 // Convert to disabled (dimmed) bitmap.
189 wxBitmap
ConvertToDisabled(unsigned char brightness
= 255) const;
190 #endif // wxUSE_IMAGE
192 virtual wxMask
*GetMask() const = 0;
193 virtual void SetMask(wxMask
*mask
) = 0;
195 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const = 0;
197 virtual bool SaveFile(const wxString
&name
, wxBitmapType type
,
198 const wxPalette
*palette
= NULL
) const = 0;
199 virtual bool LoadFile(const wxString
&name
, wxBitmapType type
) = 0;
202 If raw bitmap access is supported (see wx/rawbmp.h), the following
203 methods should be implemented:
205 virtual bool GetRawData(wxRawBitmapData *data) = 0;
206 virtual void UngetRawData(wxRawBitmapData *data) = 0;
210 virtual wxPalette
*GetPalette() const = 0;
211 virtual void SetPalette(const wxPalette
& palette
) = 0;
212 #endif // wxUSE_PALETTE
214 // copies the contents and mask of the given (colour) icon to the bitmap
215 virtual bool CopyFromIcon(const wxIcon
& icon
) = 0;
218 virtual void SetHeight(int height
) = 0;
219 virtual void SetWidth(int width
) = 0;
220 virtual void SetDepth(int depth
) = 0;
223 static inline wxList
& GetHandlers() { return sm_handlers
; }
224 static void AddHandler(wxBitmapHandler
*handler
);
225 static void InsertHandler(wxBitmapHandler
*handler
);
226 static bool RemoveHandler(const wxString
& name
);
227 static wxBitmapHandler
*FindHandler(const wxString
& name
);
228 static wxBitmapHandler
*FindHandler(const wxString
& extension
, wxBitmapType bitmapType
);
229 static wxBitmapHandler
*FindHandler(wxBitmapType bitmapType
);
231 //static void InitStandardHandlers();
232 // (wxBitmap must implement this one)
234 static void CleanUpHandlers();
236 // this method is only used by the generic implementation of wxMask
237 // currently but could be useful elsewhere in the future: it can be
238 // overridden to quantize the colour to correspond to bitmap colour depth
239 // if necessary; default implementation simply returns the colour as is
240 virtual wxColour
QuantizeColour(const wxColour
& colour
) const
246 static wxList sm_handlers
;
248 DECLARE_ABSTRACT_CLASS(wxBitmapBase
)
251 #endif // wxUSE_BITMAP_BASE
254 // the wxBITMAP_DEFAULT_TYPE constant defines the default argument value
255 // for wxBitmap's ctor and wxBitmap::LoadFile() functions.
256 #if defined(__WXMSW__)
257 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
258 #include "wx/msw/bitmap.h"
259 #elif defined(__WXMOTIF__)
260 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
261 #include "wx/x11/bitmap.h"
262 #elif defined(__WXGTK20__)
264 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
266 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
268 #include "wx/gtk/bitmap.h"
269 #elif defined(__WXGTK__)
270 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
271 #include "wx/gtk1/bitmap.h"
272 #elif defined(__WXX11__)
273 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
274 #include "wx/x11/bitmap.h"
275 #elif defined(__WXDFB__)
276 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
277 #include "wx/dfb/bitmap.h"
278 #elif defined(__WXMAC__)
279 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_PICT_RESOURCE
280 #include "wx/osx/bitmap.h"
281 #elif defined(__WXCOCOA__)
282 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
283 #include "wx/cocoa/bitmap.h"
284 #elif defined(__WXPM__)
285 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
286 #include "wx/os2/bitmap.h"
292 #if wxUSE_BITMAP_BASE
297 ConvertToDisabled(unsigned char brightness
) const
299 return ConvertToImage().ConvertToDisabled(brightness
);
301 #endif // wxUSE_IMAGE
303 // we must include generic mask.h after wxBitmap definition
304 #if defined(__WXDFB__)
305 #define wxUSE_GENERIC_MASK 1
307 #define wxUSE_GENERIC_MASK 0
310 #if wxUSE_GENERIC_MASK
311 #include "wx/generic/mask.h"
314 #endif // _WX_BITMAP_H_BASE_