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(wxBitmap
,WXDLLEXPORT
)
32 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxIcon
,WXDLLEXPORT
)
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
44 #include "wx/palette.h"
45 #include "wx/module.h"
49 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
50 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase
,wxObject
)
52 wxList
wxBitmapBase::sm_handlers
;
54 void wxBitmapBase::AddHandler(wxBitmapHandlerBase
*handler
)
56 sm_handlers
.Append(handler
);
59 void wxBitmapBase::InsertHandler(wxBitmapHandlerBase
*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 bool wxBitmapHandlerBase::Create(wxBitmap
*, const void*, long, int, int, int)
134 bool wxBitmapHandlerBase::LoadFile(wxBitmap
*, const wxString
&, long, int, int)
139 bool wxBitmapHandlerBase::SaveFile(const wxBitmap
*, const wxString
&, int, const wxPalette
*)
144 class wxBitmapBaseModule
: public wxModule
146 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
148 wxBitmapBaseModule() {}
149 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
150 void OnExit() { wxBitmap::CleanUpHandlers(); }
153 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
155 #endif // wxUSE_BITMAP_BASE
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
161 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
163 wxBitmap::wxBitmap(const char* const* bits
)
165 wxCHECK2_MSG(bits
!= NULL
, return, wxT("invalid bitmap data"));
167 #if wxUSE_IMAGE && wxUSE_XPM
169 wxCHECK2_MSG(image
.Ok(), return, wxT("invalid bitmap data"));
171 *this = wxBitmap(image
);
173 wxFAIL_MSG(_T("creating bitmaps from XPMs not supported"));
174 #endif // wxUSE_IMAGE && wxUSE_XPM
176 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
186 return InitFromColour(bitmap
, colour
);
191 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
193 wxPalette
*pal
= bitmap
.GetPalette();
195 wxCHECK_MSG( pal
, false,
196 wxT("Cannot create mask from palette index of a bitmap without palette") );
199 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
201 return Create(bitmap
, wxColour(r
, g
, b
));
204 #endif // wxUSE_PALETTE
206 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
210 return InitFromMonoBitmap(bitmap
);