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"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
31 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap
,WXDLLEXPORT
)
32 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon
,WXDLLEXPORT
)
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
44 #include "wx/palette.h"
45 #include "wx/module.h"
49 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
50 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler
, wxObject
)
52 wxList
wxBitmapBase::sm_handlers
;
54 void wxBitmapBase::AddHandler(wxBitmapHandler
*handler
)
56 sm_handlers
.Append(handler
);
59 void wxBitmapBase::InsertHandler(wxBitmapHandler
*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 wxBitmap
wxBitmapBase::ConvertToDisabled(unsigned char brightness
) const
142 wxImage image
= ConvertToImage();
143 bmp
= wxBitmap(image
.ConvertToDisabled(brightness
));
148 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
150 #endif // wxUSE_BITMAP_BASE
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
158 wxBitmap::wxBitmap(const char* const* bits
)
160 wxCHECK2_MSG(bits
!= NULL
, return, wxT("invalid bitmap data"));
162 #if wxUSE_IMAGE && wxUSE_XPM
164 wxCHECK2_MSG(image
.Ok(), return, wxT("invalid bitmap data"));
166 *this = wxBitmap(image
);
168 wxFAIL_MSG(wxT("creating bitmaps from XPMs not supported"));
169 #endif // wxUSE_IMAGE && wxUSE_XPM
171 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
181 return InitFromColour(bitmap
, colour
);
186 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
188 wxPalette
*pal
= bitmap
.GetPalette();
190 wxCHECK_MSG( pal
, false,
191 wxT("Cannot create mask from palette index of a bitmap without palette") );
194 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
196 return Create(bitmap
, wxColour(r
, g
, b
));
199 #endif // wxUSE_PALETTE
201 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
205 return InitFromMonoBitmap(bitmap
);