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(wxBitmap
,WXDLLEXPORT
)
32 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxIcon
,WXDLLEXPORT
)
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
44 #include "wx/palette.h"
46 #include "wx/module.h"
50 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase
, wxGDIObject
)
51 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase
,wxObject
)
53 wxList
wxBitmapBase::sm_handlers
;
55 void wxBitmapBase::AddHandler(wxBitmapHandlerBase
*handler
)
57 sm_handlers
.Append(handler
);
60 void wxBitmapBase::InsertHandler(wxBitmapHandlerBase
*handler
)
62 sm_handlers
.Insert(handler
);
65 bool wxBitmapBase::RemoveHandler(const wxString
& name
)
67 wxBitmapHandler
*handler
= FindHandler(name
);
70 sm_handlers
.DeleteObject(handler
);
77 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& name
)
79 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
82 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
83 if ( handler
->GetName() == name
)
85 node
= node
->GetNext();
90 wxBitmapHandler
*wxBitmapBase::FindHandler(const wxString
& extension
, wxBitmapType bitmapType
)
92 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
95 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
96 if ( handler
->GetExtension() == extension
&&
97 (bitmapType
== wxBITMAP_TYPE_ANY
|| handler
->GetType() == bitmapType
) )
99 node
= node
->GetNext();
104 wxBitmapHandler
*wxBitmapBase::FindHandler(wxBitmapType bitmapType
)
106 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
109 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
110 if (handler
->GetType() == bitmapType
)
112 node
= node
->GetNext();
117 void wxBitmapBase::CleanUpHandlers()
119 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
122 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->GetData();
123 wxList::compatibility_iterator next
= node
->GetNext();
125 sm_handlers
.Erase(node
);
130 bool wxBitmapHandlerBase::Create(wxBitmap
*, const void*, long, int, int, int)
135 bool wxBitmapHandlerBase::LoadFile(wxBitmap
*, const wxString
&, long, int, int)
140 bool wxBitmapHandlerBase::SaveFile(const wxBitmap
*, const wxString
&, int, const wxPalette
*)
145 class wxBitmapBaseModule
: public wxModule
147 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule
)
149 wxBitmapBaseModule() {}
150 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; };
151 void OnExit() { wxBitmap::CleanUpHandlers(); };
154 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule
, wxModule
)
156 #endif // wxUSE_BITMAP_BASE
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
164 wxBitmap::wxBitmap(const char* const* bits
)
166 wxCHECK2_MSG(bits
!= NULL
, return, wxT("invalid bitmap data"));
168 #if wxUSE_IMAGE && wxUSE_XPM
170 wxCHECK2_MSG(image
.Ok(), return, wxT("invalid bitmap data"));
172 *this = wxBitmap(image
);
174 wxFAIL_MSG(_T("creating bitmaps from XPMs not supported"));
175 #endif // wxUSE_IMAGE && wxUSE_XPM
177 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
183 bool wxMaskBase::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
187 return InitFromColour(bitmap
, colour
);
192 bool wxMaskBase::Create(const wxBitmap
& bitmap
, int paletteIndex
)
194 wxPalette
*pal
= bitmap
.GetPalette();
196 wxCHECK_MSG( pal
, false,
197 wxT("Cannot create mask from palette index of a bitmap without palette") );
200 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
202 return Create(bitmap
, wxColour(r
, g
, b
));
205 #endif // wxUSE_PALETTE
207 bool wxMaskBase::Create(const wxBitmap
& bitmap
)
211 return InitFromMonoBitmap(bitmap
);