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 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
22 #include "wx/bitmap.h"
27 #include "wx/colour.h"
30 #include "wx/palette.h"
33 #include "wx/module.h"
36 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
37 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase
,wxObject
)
39 wxList
wxBitmapBase::sm_handlers
;
41 void wxBitmapBase::AddHandler(wxBitmapHandlerBase
*handler
)
43 sm_handlers
.Append(handler
);
46 void wxBitmapBase::InsertHandler(wxBitmapHandlerBase
*handler
)
48 sm_handlers
.Insert(handler
);
51 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
53 wxBitmapHandler
*handler
= FindHandler(name
);
56 sm_handlers
.DeleteObject(handler
);
63 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
65 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
68 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
69 if ( handler
->GetName() == name
)
71 node
= node
->GetNext();
76 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
78 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
81 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
82 if ( handler
->GetExtension() == extension
&&
83 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
85 node
= node
->GetNext();
90 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
92 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
95 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
96 if (handler
->GetType() == bitmapType
)
98 node
= node
->GetNext();
103 void wxBitmapBase::CleanUpHandlers()
105 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
108 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
109 wxList::compatibility_iterator next
= node
->GetNext();
111 sm_handlers
.Erase(node
);
116 class wxBitmapBaseModule
: public wxModule
118 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
120 wxBitmapBaseModule() {}
121 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; };
122 void OnExit() { wxBitmap::CleanUpHandlers(); };
125 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
127 #endif // wxUSE_BITMAP_BASE
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
137 return InitFromColour(bitmap
, colour
);
142 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
144 wxPalette
*pal
= bitmap
.GetPalette();
146 wxCHECK_MSG( pal
, false,
147 wxT("Cannot create mask from palette index of a bitmap without palette") );
150 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
152 return Create(bitmap
, wxColour(r
, g
, b
));
155 #endif // wxUSE_PALETTE
157 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
161 return InitFromMonoBitmap(bitmap
);