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 bool wxBitmapBase::Create(int width
, int height
, const wxDC
& WXUNUSED(dc
))
92 return Create(width
,height
);
95 void wxBitmapBase::AddHandler(wxBitmapHandler
*handler
)
97 sm_handlers
.Append(handler
);
100 void wxBitmapBase::InsertHandler(wxBitmapHandler
*handler
)
102 sm_handlers
.Insert(handler
);
105 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
107 wxBitmapHandler
*handler
= FindHandler(name
);
110 sm_handlers
.DeleteObject(handler
);
117 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
119 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
122 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
123 if ( handler
->GetName() == name
)
125 node
= node
->GetNext();
130 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
132 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
135 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
136 if ( handler
->GetExtension() == extension
&&
137 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
139 node
= node
->GetNext();
144 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
146 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
149 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
150 if (handler
->GetType() == bitmapType
)
152 node
= node
->GetNext();
157 void wxBitmapBase::CleanUpHandlers()
159 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
162 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
163 wxList::compatibility_iterator next
= node
->GetNext();
165 sm_handlers
.Erase(node
);
170 class wxBitmapBaseModule
: public wxModule
172 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
174 wxBitmapBaseModule() {}
175 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
176 void OnExit() { wxBitmap::CleanUpHandlers(); }
179 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
181 #endif // wxUSE_BITMAP_BASE
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
189 wxBitmap::wxBitmap(const char* const* bits
)
191 wxCHECK2_MSG(bits
!= NULL
, return, wxT("invalid bitmap data"));
193 #if wxUSE_IMAGE && wxUSE_XPM
195 wxCHECK2_MSG(image
.IsOk(), return, wxT("invalid bitmap data"));
197 *this = wxBitmap(image
);
199 wxFAIL_MSG(wxT("creating bitmaps from XPMs not supported"));
200 #endif // wxUSE_IMAGE && wxUSE_XPM
202 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
212 return InitFromColour(bitmap
, colour
);
217 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
219 wxPalette
*pal
= bitmap
.GetPalette();
221 wxCHECK_MSG( pal
, false,
222 wxT("Cannot create mask from palette index of a bitmap without palette") );
225 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
227 return Create(bitmap
, wxColour(r
, g
, b
));
230 #endif // wxUSE_PALETTE
232 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
236 return InitFromMonoBitmap(bitmap
);