1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/bmpbase.cpp
3 // Purpose: wxBitmapBase
4 // Author: VaclavSlavik
7 // Copyright: (c) 2001, Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #include "wx/bitmap.h"
21 #include "wx/colour.h"
26 #if wxUSE_IMAGE && wxUSE_LIBPNG && wxUSE_STREAMS
27 #define wxHAS_PNG_LOAD
29 #include "wx/mstream.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
37 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap
,WXDLLEXPORT
)
38 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon
,WXDLLEXPORT
)
41 #if wxUSE_EXTENDED_RTTI
42 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxBitmap>)
43 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxIcon>)
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // wxOSX has a native version and doesn't use this one.
55 wxBitmap
wxBitmapHelpers::NewFromPNGData(const void* data
, size_t size
)
60 wxMemoryInputStream
is(data
, size
);
61 wxImage
image(is
, wxBITMAP_TYPE_PNG
);
63 bitmap
= wxBitmap(image
);
64 #endif // wxHAS_PNG_LOAD
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
80 #include "wx/palette.h"
81 #include "wx/module.h"
85 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
86 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler
, wxObject
)
88 wxList
wxBitmapBase::sm_handlers
;
90 void wxBitmapBase::AddHandler(wxBitmapHandler
*handler
)
92 sm_handlers
.Append(handler
);
95 void wxBitmapBase::InsertHandler(wxBitmapHandler
*handler
)
97 sm_handlers
.Insert(handler
);
100 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
102 wxBitmapHandler
*handler
= FindHandler(name
);
105 sm_handlers
.DeleteObject(handler
);
112 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
114 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
117 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
118 if ( handler
->GetName() == name
)
120 node
= node
->GetNext();
125 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
127 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
130 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
131 if ( handler
->GetExtension() == extension
&&
132 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
134 node
= node
->GetNext();
139 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
141 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
144 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
145 if (handler
->GetType() == bitmapType
)
147 node
= node
->GetNext();
152 void wxBitmapBase::CleanUpHandlers()
154 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
157 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
158 wxList::compatibility_iterator next
= node
->GetNext();
160 sm_handlers
.Erase(node
);
165 class wxBitmapBaseModule
: public wxModule
167 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
169 wxBitmapBaseModule() {}
170 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
171 void OnExit() { wxBitmap::CleanUpHandlers(); }
174 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
176 #endif // wxUSE_BITMAP_BASE
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
184 wxBitmap::wxBitmap(const char* const* bits
)
186 wxCHECK2_MSG(bits
!= NULL
, return, wxT("invalid bitmap data"));
188 #if wxUSE_IMAGE && wxUSE_XPM
190 wxCHECK2_MSG(image
.IsOk(), return, wxT("invalid bitmap data"));
192 *this = wxBitmap(image
);
194 wxFAIL_MSG(wxT("creating bitmaps from XPMs not supported"));
195 #endif // wxUSE_IMAGE && wxUSE_XPM
197 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
207 return InitFromColour(bitmap
, colour
);
212 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
214 wxPalette
*pal
= bitmap
.GetPalette();
216 wxCHECK_MSG( pal
, false,
217 wxT("Cannot create mask from palette index of a bitmap without palette") );
220 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
222 return Create(bitmap
, wxColour(r
, g
, b
));
225 #endif // wxUSE_PALETTE
227 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
231 return InitFromMonoBitmap(bitmap
);