1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/bmpbase.cpp
3 // Purpose: wxBitmapBase
4 // Author: VaclavSlavik
6 // Copyright: (c) 2001, Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
17 #include "wx/bitmap.h"
20 #include "wx/colour.h"
25 #if wxUSE_IMAGE && wxUSE_LIBPNG && wxUSE_STREAMS
26 #define wxHAS_PNG_LOAD
28 #include "wx/mstream.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
36 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap
,WXDLLEXPORT
)
37 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon
,WXDLLEXPORT
)
40 #if wxUSE_EXTENDED_RTTI
41 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxBitmap>)
42 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxIcon>)
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // wxOSX has a native version and doesn't use this one.
54 wxBitmap
wxBitmapHelpers::NewFromPNGData(const void* data
, size_t size
)
59 wxMemoryInputStream
is(data
, size
);
60 wxImage
image(is
, wxBITMAP_TYPE_PNG
);
62 bitmap
= wxBitmap(image
);
63 #endif // wxHAS_PNG_LOAD
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
79 #include "wx/palette.h"
80 #include "wx/module.h"
84 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
85 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler
, wxObject
)
87 wxList
wxBitmapBase::sm_handlers
;
89 void wxBitmapBase::AddHandler(wxBitmapHandler
*handler
)
91 sm_handlers
.Append(handler
);
94 void wxBitmapBase::InsertHandler(wxBitmapHandler
*handler
)
96 sm_handlers
.Insert(handler
);
99 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
101 wxBitmapHandler
*handler
= FindHandler(name
);
104 sm_handlers
.DeleteObject(handler
);
111 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
113 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
116 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
117 if ( handler
->GetName() == name
)
119 node
= node
->GetNext();
124 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
126 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
129 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
130 if ( handler
->GetExtension() == extension
&&
131 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
133 node
= node
->GetNext();
138 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
140 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
143 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
144 if (handler
->GetType() == bitmapType
)
146 node
= node
->GetNext();
151 void wxBitmapBase::CleanUpHandlers()
153 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
156 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
157 wxList::compatibility_iterator next
= node
->GetNext();
159 sm_handlers
.Erase(node
);
164 class wxBitmapBaseModule
: public wxModule
166 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
168 wxBitmapBaseModule() {}
169 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
170 void OnExit() { wxBitmap::CleanUpHandlers(); }
173 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
175 #endif // wxUSE_BITMAP_BASE
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
183 wxBitmap::wxBitmap(const char* const* bits
)
185 wxCHECK2_MSG(bits
!= NULL
, return, wxT("invalid bitmap data"));
187 #if wxUSE_IMAGE && wxUSE_XPM
189 wxCHECK2_MSG(image
.IsOk(), return, wxT("invalid bitmap data"));
191 *this = wxBitmap(image
);
193 wxFAIL_MSG(wxT("creating bitmaps from XPMs not supported"));
194 #endif // wxUSE_IMAGE && wxUSE_XPM
196 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
206 return InitFromColour(bitmap
, colour
);
211 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
213 wxPalette
*pal
= bitmap
.GetPalette();
215 wxCHECK_MSG( pal
, false,
216 wxT("Cannot create mask from palette index of a bitmap without palette") );
219 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
221 return Create(bitmap
, wxColour(r
, g
, b
));
224 #endif // wxUSE_PALETTE
226 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
230 return InitFromMonoBitmap(bitmap
);