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 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
31 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap
,WXDLLEXPORT
)
32 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon
,WXDLLEXPORT
)
35 #if wxUSE_EXTENDED_RTTI
36 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxBitmap>)
37 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxIcon>)
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
49 #include "wx/palette.h"
50 #include "wx/module.h"
54 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
55 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler
, wxObject
)
57 wxList
wxBitmapBase::sm_handlers
;
59 void wxBitmapBase::AddHandler(wxBitmapHandler
*handler
)
61 sm_handlers
.Append(handler
);
64 void wxBitmapBase::InsertHandler(wxBitmapHandler
*handler
)
66 sm_handlers
.Insert(handler
);
69 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
71 wxBitmapHandler
*handler
= FindHandler(name
);
74 sm_handlers
.DeleteObject(handler
);
81 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
83 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
86 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
87 if ( handler
->GetName() == name
)
89 node
= node
->GetNext();
94 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
96 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
99 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
100 if ( handler
->GetExtension() == extension
&&
101 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
103 node
= node
->GetNext();
108 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
110 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
113 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
114 if (handler
->GetType() == bitmapType
)
116 node
= node
->GetNext();
121 void wxBitmapBase::CleanUpHandlers()
123 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
126 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
127 wxList::compatibility_iterator next
= node
->GetNext();
129 sm_handlers
.Erase(node
);
134 class wxBitmapBaseModule
: public wxModule
136 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
138 wxBitmapBaseModule() {}
139 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
140 void OnExit() { wxBitmap::CleanUpHandlers(); }
143 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
145 #endif // wxUSE_BITMAP_BASE
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
153 wxBitmap::wxBitmap(const char* const* bits
)
155 wxCHECK2_MSG(bits
!= NULL
, return, wxT("invalid bitmap data"));
157 #if wxUSE_IMAGE && wxUSE_XPM
159 wxCHECK2_MSG(image
.IsOk(), return, wxT("invalid bitmap data"));
161 *this = wxBitmap(image
);
163 wxFAIL_MSG(wxT("creating bitmaps from XPMs not supported"));
164 #endif // wxUSE_IMAGE && wxUSE_XPM
166 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
176 return InitFromColour(bitmap
, colour
);
181 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
183 wxPalette
*pal
= bitmap
.GetPalette();
185 wxCHECK_MSG( pal
, false,
186 wxT("Cannot create mask from palette index of a bitmap without palette") );
189 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
191 return Create(bitmap
, wxColour(r
, g
, b
));
194 #endif // wxUSE_PALETTE
196 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
200 return InitFromMonoBitmap(bitmap
);