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"
23 class WXDLLIMPEXP_FWD_CORE wxBitmap
;
24 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler
;
25 class WXDLLIMPEXP_FWD_CORE wxIcon
;
26 class WXDLLIMPEXP_FWD_CORE wxImage
;
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
,WXDLLEXPORT
)
39 // ----------------------------------------------------------------------------
40 // wxMask represents the transparent area of the bitmap
41 // ----------------------------------------------------------------------------
43 class WXDLLEXPORT wxMaskBase
: public wxObject
46 // create the mask from bitmap pixels of the given colour
47 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
50 // create the mask from bitmap pixels with the given palette index
51 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
52 #endif // wxUSE_PALETTE
54 // create the mask from the given mono bitmap
55 bool Create(const wxBitmap
& bitmap
);
58 // this function is called from Create() to free the existing mask data
59 virtual void FreeData() = 0;
61 // these functions must be overridden to implement the corresponding public
62 // Create() methods, they shouldn't call FreeData() as it's already called
63 // by the public wrappers
64 virtual bool InitFromColour(const wxBitmap
& bitmap
,
65 const wxColour
& colour
) = 0;
66 virtual bool InitFromMonoBitmap(const wxBitmap
& bitmap
) = 0;
69 #if defined(__WXMGL__) || \
70 defined(__WXDFB__) || \
71 defined(__WXMAC__) || \
72 defined(__WXGTK__) || \
73 defined(__WXCOCOA__) || \
74 defined(__WXMOTIF__) || \
76 #define wxUSE_BITMAP_BASE 1
78 #define wxUSE_BITMAP_BASE 0
81 // Only used by some ports
82 // FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes
85 // ----------------------------------------------------------------------------
86 // wxBitmapHandler: class which knows how to create/load/save bitmaps in
88 // ----------------------------------------------------------------------------
90 class WXDLLEXPORT wxBitmapHandlerBase
: public wxObject
93 wxBitmapHandlerBase() { m_type
= wxBITMAP_TYPE_INVALID
; }
94 virtual ~wxBitmapHandlerBase() { }
96 virtual bool Create(wxBitmap
*bitmap
, const void* data
, long flags
,
97 int width
, int height
, int depth
= 1);
98 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
99 int desiredWidth
, int desiredHeight
);
100 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
101 int type
, const wxPalette
*palette
= NULL
);
103 void SetName(const wxString
& name
) { m_name
= name
; }
104 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
105 void SetType(wxBitmapType type
) { m_type
= type
; }
106 const wxString
& GetName() const { return m_name
; }
107 const wxString
& GetExtension() const { return m_extension
; }
108 wxBitmapType
GetType() const { return m_type
; }
112 wxString m_extension
;
115 DECLARE_ABSTRACT_CLASS(wxBitmapHandlerBase
)
118 class WXDLLEXPORT wxBitmapBase
: public wxGDIObject
122 Derived class must implement these:
125 wxBitmap(int width, int height, int depth = -1);
126 wxBitmap(const char bits[], int width, int height, int depth = 1);
127 wxBitmap(const char* const* bits);
128 wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
129 wxBitmap(const wxImage& image, int depth = -1);
131 bool Create(int width, int height, int depth = -1);
133 static void InitStandardHandlers();
136 virtual bool Ok() const { return IsOk(); }
137 virtual bool IsOk() const = 0;
139 virtual int GetHeight() const = 0;
140 virtual int GetWidth() const = 0;
141 virtual int GetDepth() const = 0;
144 virtual wxImage
ConvertToImage() const = 0;
145 #endif // wxUSE_IMAGE
147 virtual wxMask
*GetMask() const = 0;
148 virtual void SetMask(wxMask
*mask
) = 0;
150 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const = 0;
152 virtual bool SaveFile(const wxString
&name
, wxBitmapType type
,
153 const wxPalette
*palette
= (wxPalette
*)NULL
) const = 0;
154 virtual bool LoadFile(const wxString
&name
, wxBitmapType type
) = 0;
157 If raw bitmap access is supported (see wx/rawbmp.h), the following
158 methods should be implemented:
160 virtual bool GetRawData(wxRawBitmapData *data) = 0;
161 virtual void UngetRawData(wxRawBitmapData *data) = 0;
165 virtual wxPalette
*GetPalette() const = 0;
166 virtual void SetPalette(const wxPalette
& palette
) = 0;
167 #endif // wxUSE_PALETTE
169 // copies the contents and mask of the given (colour) icon to the bitmap
170 virtual bool CopyFromIcon(const wxIcon
& icon
) = 0;
173 virtual void SetHeight(int height
) = 0;
174 virtual void SetWidth(int width
) = 0;
175 virtual void SetDepth(int depth
) = 0;
178 static inline wxList
& GetHandlers() { return sm_handlers
; }
179 static void AddHandler(wxBitmapHandlerBase
*handler
);
180 static void InsertHandler(wxBitmapHandlerBase
*handler
);
181 static bool RemoveHandler(const wxString
& name
);
182 static wxBitmapHandler
*FindHandler(const wxString
& name
);
183 static wxBitmapHandler
*FindHandler(const wxString
& extension
, wxBitmapType bitmapType
);
184 static wxBitmapHandler
*FindHandler(wxBitmapType bitmapType
);
186 //static void InitStandardHandlers();
187 // (wxBitmap must implement this one)
189 static void CleanUpHandlers();
191 // this method is only used by the generic implementation of wxMask
192 // currently but could be useful elsewhere in the future: it can be
193 // overridden to quantize the colour to correspond to bitmap colour depth
194 // if necessary; default implementation simply returns the colour as is
195 virtual wxColour
QuantizeColour(const wxColour
& colour
) const
201 static wxList sm_handlers
;
203 DECLARE_ABSTRACT_CLASS(wxBitmapBase
)
206 #endif // wxUSE_BITMAP_BASE
208 #if defined(__WXPALMOS__)
209 #include "wx/palmos/bitmap.h"
210 #elif defined(__WXMSW__)
211 #include "wx/msw/bitmap.h"
212 #elif defined(__WXMOTIF__)
213 #include "wx/x11/bitmap.h"
214 #elif defined(__WXGTK20__)
215 #include "wx/gtk/bitmap.h"
216 #elif defined(__WXGTK__)
217 #include "wx/gtk1/bitmap.h"
218 #elif defined(__WXX11__)
219 #include "wx/x11/bitmap.h"
220 #elif defined(__WXMGL__)
221 #include "wx/mgl/bitmap.h"
222 #elif defined(__WXDFB__)
223 #include "wx/dfb/bitmap.h"
224 #elif defined(__WXMAC__)
225 #include "wx/mac/bitmap.h"
226 #elif defined(__WXCOCOA__)
227 #include "wx/cocoa/bitmap.h"
228 #elif defined(__WXPM__)
229 #include "wx/os2/bitmap.h"
232 // we must include generic mask.h after wxBitmap definition
233 #if defined(__WXMGL__) || defined(__WXDFB__)
234 #define wxUSE_GENERIC_MASK 1
236 #define wxUSE_GENERIC_MASK 0
239 #if wxUSE_GENERIC_MASK
240 #include "wx/generic/mask.h"
243 #endif // _WX_BITMAP_H_BASE_