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 // ----------------------------------------------------------------------------
20 #include "wx/object.h"
21 #include "wx/string.h"
22 #include "wx/gdiobj.h"
23 #include "wx/gdicmn.h" // for wxBitmapType
24 #include "wx/colour.h"
26 class WXDLLEXPORT wxBitmap
;
27 class WXDLLEXPORT wxBitmapHandler
;
28 class WXDLLEXPORT wxIcon
;
29 class WXDLLEXPORT wxImage
;
30 class WXDLLEXPORT wxMask
;
31 class WXDLLEXPORT wxPalette
;
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
38 #include "wx/variant.h"
39 DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap
,WXDLLEXPORT
)
42 // ----------------------------------------------------------------------------
43 // wxMask represents the transparent area of the bitmap
44 // ----------------------------------------------------------------------------
46 class WXDLLEXPORT wxMaskBase
: public wxObject
49 // create the mask from bitmap pixels of the given colour
50 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
53 // create the mask from bitmap pixels with the given palette index
54 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
55 #endif // wxUSE_PALETTE
57 // create the mask from the given mono bitmap
58 bool Create(const wxBitmap
& bitmap
);
61 // this function is called from Create() to free the existing mask data
62 virtual void FreeData() = 0;
64 // these functions must be overridden to implement the corresponding public
65 // Create() methods, they shouldn't call FreeData() as it's already called
66 // by the public wrappers
67 virtual bool InitFromColour(const wxBitmap
& bitmap
,
68 const wxColour
& colour
) = 0;
69 virtual bool InitFromMonoBitmap(const wxBitmap
& bitmap
) = 0;
72 #if defined(__WXMGL__) || \
73 defined(__WXDFB__) || \
74 defined(__WXMAC__) || \
75 defined(__WXGTK__) || \
76 defined(__WXCOCOA__) || \
77 defined(__WXMOTIF__) || \
79 #define wxUSE_BITMAP_BASE 1
81 #define wxUSE_BITMAP_BASE 0
84 // Only used by some ports
85 // FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes
88 // ----------------------------------------------------------------------------
89 // wxBitmapHandler: class which knows how to create/load/save bitmaps in
91 // ----------------------------------------------------------------------------
93 class WXDLLEXPORT wxBitmapHandlerBase
: public wxObject
99 , m_type(wxBITMAP_TYPE_INVALID
)
102 virtual ~wxBitmapHandlerBase() { }
104 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
,
105 int width
, int height
, int depth
= 1) = 0;
106 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
107 int desiredWidth
, int desiredHeight
) = 0;
108 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
109 int type
, const wxPalette
*palette
= NULL
) = 0;
111 void SetName(const wxString
& name
) { m_name
= name
; }
112 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
113 void SetType(wxBitmapType type
) { m_type
= type
; }
114 wxString
GetName() const { return m_name
; }
115 wxString
GetExtension() const { return m_extension
; }
116 wxBitmapType
GetType() const { return m_type
; }
120 wxString m_extension
;
124 DECLARE_ABSTRACT_CLASS(wxBitmapHandlerBase
)
127 class WXDLLEXPORT wxBitmapBase
: public wxGDIObject
131 Derived class must implement these:
134 wxBitmap(int width, int height, int depth = -1);
135 wxBitmap(const char bits[], int width, int height, int depth = 1);
136 wxBitmap(const char **bits);
137 wxBitmap(char **bits);
138 wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
139 wxBitmap(const wxImage& image, int depth = -1);
140 bool operator == (const wxBitmap& bmp) const;
141 bool operator != (const wxBitmap& bmp) const;
143 bool Create(int width, int height, int depth = -1);
145 static void InitStandardHandlers();
148 virtual bool Ok() const = 0;
150 virtual int GetHeight() const = 0;
151 virtual int GetWidth() const = 0;
152 virtual int GetDepth() const = 0;
154 virtual wxImage
ConvertToImage() const = 0;
156 virtual wxMask
*GetMask() const = 0;
157 virtual void SetMask(wxMask
*mask
) = 0;
159 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const = 0;
161 virtual bool SaveFile(const wxString
&name
, wxBitmapType type
,
162 const wxPalette
*palette
= (wxPalette
*)NULL
) const = 0;
163 virtual bool LoadFile(const wxString
&name
, wxBitmapType type
) = 0;
166 If raw bitmap access is supported (see wx/rawbmp.h), the following
167 methods should be implemented:
169 virtual bool GetRawData(wxRawBitmapData *data) = 0;
170 virtual void UngetRawData(wxRawBitmapData *data) = 0;
174 virtual wxPalette
*GetPalette() const = 0;
175 virtual void SetPalette(const wxPalette
& palette
) = 0;
176 #endif // wxUSE_PALETTE
178 // copies the contents and mask of the given (colour) icon to the bitmap
179 virtual bool CopyFromIcon(const wxIcon
& icon
) = 0;
182 virtual void SetHeight(int height
) = 0;
183 virtual void SetWidth(int width
) = 0;
184 virtual void SetDepth(int depth
) = 0;
187 static inline wxList
& GetHandlers() { return sm_handlers
; }
188 static void AddHandler(wxBitmapHandlerBase
*handler
);
189 static void InsertHandler(wxBitmapHandlerBase
*handler
);
190 static bool RemoveHandler(const wxString
& name
);
191 static wxBitmapHandler
*FindHandler(const wxString
& name
);
192 static wxBitmapHandler
*FindHandler(const wxString
& extension
, wxBitmapType bitmapType
);
193 static wxBitmapHandler
*FindHandler(wxBitmapType bitmapType
);
195 //static void InitStandardHandlers();
196 // (wxBitmap must implement this one)
198 static void CleanUpHandlers();
200 // this method is only used by the generic implementation of wxMask
201 // currently but could be useful elsewhere in the future: it can be
202 // overridden to quantize the colour to correspond to bitmap colour depth
203 // if necessary; default implementation simply returns the colour as is
204 virtual wxColour
QuantizeColour(const wxColour
& colour
) const
210 static wxList sm_handlers
;
212 DECLARE_ABSTRACT_CLASS(wxBitmapBase
)
215 #endif // wxUSE_BITMAP_BASE
217 #if defined(__WXPALMOS__)
218 #include "wx/palmos/bitmap.h"
219 #elif defined(__WXMSW__)
220 #include "wx/msw/bitmap.h"
221 #elif defined(__WXMOTIF__)
222 #include "wx/x11/bitmap.h"
223 #elif defined(__WXGTK20__)
224 #include "wx/gtk/bitmap.h"
225 #elif defined(__WXGTK__)
226 #include "wx/gtk1/bitmap.h"
227 #elif defined(__WXX11__)
228 #include "wx/x11/bitmap.h"
229 #elif defined(__WXMGL__)
230 #include "wx/mgl/bitmap.h"
231 #elif defined(__WXDFB__)
232 #include "wx/dfb/bitmap.h"
233 #elif defined(__WXMAC__)
234 #include "wx/mac/bitmap.h"
235 #elif defined(__WXCOCOA__)
236 #include "wx/cocoa/bitmap.h"
237 #elif defined(__WXPM__)
238 #include "wx/os2/bitmap.h"
241 // we must include generic mask.h after wxBitmap definition
242 #if defined(__WXMGL__) || defined(__WXDFB__)
243 #define wxUSE_GENERIC_MASK 1
245 #define wxUSE_GENERIC_MASK 0
248 #if wxUSE_GENERIC_MASK
249 #include "wx/generic/mask.h"
252 #endif // _WX_BITMAP_H_BASE_