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"
41 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxBitmap
,WXDLLEXPORT
)
42 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxIcon
,WXDLLEXPORT
)
46 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
47 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase
,wxObject
)
49 wxList
wxBitmapBase::sm_handlers
;
51 void wxBitmapBase::AddHandler(wxBitmapHandlerBase
*handler
)
53 sm_handlers
.Append(handler
);
56 void wxBitmapBase::InsertHandler(wxBitmapHandlerBase
*handler
)
58 sm_handlers
.Insert(handler
);
61 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
63 wxBitmapHandler
*handler
= FindHandler(name
);
66 sm_handlers
.DeleteObject(handler
);
73 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
75 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
78 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
79 if ( handler
->GetName() == name
)
81 node
= node
->GetNext();
86 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
88 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
91 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
92 if ( handler
->GetExtension() == extension
&&
93 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
95 node
= node
->GetNext();
100 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
102 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
105 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
106 if (handler
->GetType() == bitmapType
)
108 node
= node
->GetNext();
113 void wxBitmapBase::CleanUpHandlers()
115 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
118 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
119 wxList::compatibility_iterator next
= node
->GetNext();
121 sm_handlers
.Erase(node
);
126 class wxBitmapBaseModule
: public wxModule
128 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
130 wxBitmapBaseModule() {}
131 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; };
132 void OnExit() { wxBitmap::CleanUpHandlers(); };
135 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
137 #endif // wxUSE_BITMAP_BASE
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
143 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
147 return InitFromColour(bitmap
, colour
);
152 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
154 wxPalette
*pal
= bitmap
.GetPalette();
156 wxCHECK_MSG( pal
, false,
157 wxT("Cannot create mask from palette index of a bitmap without palette") );
160 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
162 return Create(bitmap
, wxColour(r
, g
, b
));
165 #endif // wxUSE_PALETTE
167 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
171 return InitFromMonoBitmap(bitmap
);