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"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
33 #include "wx/palette.h"
36 #include "wx/module.h"
39 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
40 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase
,wxObject
)
42 wxList
wxBitmapBase::sm_handlers
;
44 void wxBitmapBase::AddHandler(wxBitmapHandlerBase
*handler
)
46 sm_handlers
.Append(handler
);
49 void wxBitmapBase::InsertHandler(wxBitmapHandlerBase
*handler
)
51 sm_handlers
.Insert(handler
);
54 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
56 wxBitmapHandler
*handler
= FindHandler(name
);
59 sm_handlers
.DeleteObject(handler
);
66 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
68 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
71 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
72 if ( handler
->GetName() == name
)
74 node
= node
->GetNext();
79 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
81 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
84 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
85 if ( handler
->GetExtension() == extension
&&
86 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
88 node
= node
->GetNext();
93 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
95 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
98 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
99 if (handler
->GetType() == bitmapType
)
101 node
= node
->GetNext();
106 void wxBitmapBase::CleanUpHandlers()
108 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
111 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
112 wxList::compatibility_iterator next
= node
->GetNext();
114 sm_handlers
.Erase(node
);
119 class wxBitmapBaseModule
: public wxModule
121 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
123 wxBitmapBaseModule() {}
124 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; };
125 void OnExit() { wxBitmap::CleanUpHandlers(); };
128 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
130 #endif // wxUSE_BITMAP_BASE
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
140 return InitFromColour(bitmap
, colour
);
145 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
147 wxPalette
*pal
= bitmap
.GetPalette();
149 wxCHECK_MSG( pal
, false,
150 wxT("Cannot create mask from palette index of a bitmap without palette") );
153 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
155 return Create(bitmap
, wxColour(r
, g
, b
));
158 #endif // wxUSE_PALETTE
160 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
164 return InitFromMonoBitmap(bitmap
);