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"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
30 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxBitmap
,WXDLLEXPORT
)
31 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxIcon
,WXDLLEXPORT
)
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
43 #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 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 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
150 return InitFromColour(bitmap
, colour
);
155 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
157 wxPalette
*pal
= bitmap
.GetPalette();
159 wxCHECK_MSG( pal
, false,
160 wxT("Cannot create mask from palette index of a bitmap without palette") );
163 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
165 return Create(bitmap
, wxColour(r
, g
, b
));
168 #endif // wxUSE_PALETTE
170 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
174 return InitFromMonoBitmap(bitmap
);