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 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
44 #include "wx/palette.h"
45 #include "wx/module.h"
49 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
50 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler
, wxObject
)
52 wxList
wxBitmapBase::sm_handlers
;
54 void wxBitmapBase::AddHandler(wxBitmapHandler
*handler
)
56 sm_handlers
.Append(handler
);
59 void wxBitmapBase::InsertHandler(wxBitmapHandler
*handler
)
61 sm_handlers
.Insert(handler
);
64 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
66 wxBitmapHandler
*handler
= FindHandler(name
);
69 sm_handlers
.DeleteObject(handler
);
76 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
78 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
81 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
82 if ( handler
->GetName() == name
)
84 node
= node
->GetNext();
89 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
91 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
94 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
95 if ( handler
->GetExtension() == extension
&&
96 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
98 node
= node
->GetNext();
103 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
105 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
108 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
109 if (handler
->GetType() == bitmapType
)
111 node
= node
->GetNext();
116 void wxBitmapBase::CleanUpHandlers()
118 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
121 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
122 wxList::compatibility_iterator next
= node
->GetNext();
124 sm_handlers
.Erase(node
);
129 class wxBitmapBaseModule
: public wxModule
131 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
133 wxBitmapBaseModule() {}
134 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
135 void OnExit() { wxBitmap::CleanUpHandlers(); }
138 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
140 #endif // wxUSE_BITMAP_BASE
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
148 wxBitmap::wxBitmap(const char* const* bits
)
150 wxCHECK2_MSG(bits
!= NULL
, return, wxT("invalid bitmap data"));
152 #if wxUSE_IMAGE && wxUSE_XPM
154 wxCHECK2_MSG(image
.Ok(), return, wxT("invalid bitmap data"));
156 *this = wxBitmap(image
);
158 wxFAIL_MSG(_T("creating bitmaps from XPMs not supported"));
159 #endif // wxUSE_IMAGE && wxUSE_XPM
161 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
163 // ----------------------------------------------------------------------------
165 // ----------------------------------------------------------------------------
167 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
171 return InitFromColour(bitmap
, colour
);
176 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
178 wxPalette
*pal
= bitmap
.GetPalette();
180 wxCHECK_MSG( pal
, false,
181 wxT("Cannot create mask from palette index of a bitmap without palette") );
184 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
186 return Create(bitmap
, wxColour(r
, g
, b
));
189 #endif // wxUSE_PALETTE
191 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
195 return InitFromMonoBitmap(bitmap
);