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 // ----------------------------------------------------------------------------
24 #include "wx/bitmap.h"
29 #include "wx/palette.h"
32 #include "wx/module.h"
35 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
36 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase
,wxObject
)
38 wxList
wxBitmapBase::sm_handlers
;
40 void wxBitmapBase::AddHandler(wxBitmapHandlerBase
*handler
)
42 sm_handlers
.Append(handler
);
45 void wxBitmapBase::InsertHandler(wxBitmapHandlerBase
*handler
)
47 sm_handlers
.Insert(handler
);
50 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
52 wxBitmapHandler
*handler
= FindHandler(name
);
55 sm_handlers
.DeleteObject(handler
);
62 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
64 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
67 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
68 if ( handler
->GetName() == name
)
70 node
= node
->GetNext();
75 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
77 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
80 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
81 if ( handler
->GetExtension() == extension
&&
82 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
84 node
= node
->GetNext();
89 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
91 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
94 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
95 if (handler
->GetType() == bitmapType
)
97 node
= node
->GetNext();
102 void wxBitmapBase::CleanUpHandlers()
104 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
107 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
108 wxList::compatibility_iterator next
= node
->GetNext();
110 sm_handlers
.Erase(node
);
115 class wxBitmapBaseModule
: public wxModule
117 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
119 wxBitmapBaseModule() {}
120 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; };
121 void OnExit() { wxBitmap::CleanUpHandlers(); };
124 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
126 #endif // wxUSE_BITMAP_BASE
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
132 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
136 return InitFromColour(bitmap
, colour
);
141 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
143 wxPalette
*pal
= bitmap
.GetPalette();
145 wxCHECK_MSG( pal
, false,
146 wxT("Cannot create mask from palette index of a bitmap without palette") );
149 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
151 return Create(bitmap
, wxColour(r
, g
, b
));
154 #endif // wxUSE_PALETTE
156 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
160 return InitFromMonoBitmap(bitmap
);