]> git.saurik.com Git - wxWidgets.git/blame - src/common/bmpbase.cpp
Fix typo in last commit
[wxWidgets.git] / src / common / bmpbase.cpp
CommitLineData
a04eec87 1/////////////////////////////////////////////////////////////////////////////
f03e8f9b 2// Name: src/common/bmpbase.cpp
a04eec87
VS
3// Purpose: wxBitmapBase
4// Author: VaclavSlavik
5// Created: 2001/04/11
6// RCS-ID: $Id$
7// Copyright: (c) 2001, Vaclav Slavik
65571936 8// Licence: wxWindows licence
a04eec87
VS
9/////////////////////////////////////////////////////////////////////////////
10
9d4ca3aa
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
da8cebb2
WS
18#include "wx/bitmap.h"
19
20#ifndef WX_PRECOMP
21 #include "wx/colour.h"
d4f6dbf6 22 #include "wx/icon.h"
1deb3af2 23 #include "wx/image.h"
da8cebb2
WS
24#endif // WX_PRECOMP
25
bae328c1
WS
26// ----------------------------------------------------------------------------
27// wxVariant support
28// ----------------------------------------------------------------------------
29
30#if wxUSE_VARIANT
55ccdb93
VZ
31IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap,WXDLLEXPORT)
32IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT)
bae328c1
WS
33#endif
34
e765d7ee
SC
35#if wxUSE_EXTENDED_RTTI
36//WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxBitmap>)
37//WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxIcon>)
38#endif
39
91885f46
VZ
40// ----------------------------------------------------------------------------
41// wxBitmapBase
42// ----------------------------------------------------------------------------
43
ab00f409
WS
44#if wxUSE_BITMAP_BASE
45
e4db172a
WS
46#ifndef WX_PRECOMP
47 #include "wx/log.h"
de6185e2 48 #include "wx/utils.h"
559a723c 49 #include "wx/palette.h"
02761f6c 50 #include "wx/module.h"
e4db172a
WS
51#endif // WX_PRECOMP
52
6f5d7825 53
a04eec87 54IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
e86f2cc8 55IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler, wxObject)
a04eec87
VS
56
57wxList wxBitmapBase::sm_handlers;
58
c822d4ca 59void wxBitmapBase::AddHandler(wxBitmapHandler *handler)
a04eec87
VS
60{
61 sm_handlers.Append(handler);
62}
63
c822d4ca 64void wxBitmapBase::InsertHandler(wxBitmapHandler *handler)
a04eec87
VS
65{
66 sm_handlers.Insert(handler);
67}
68
69bool wxBitmapBase::RemoveHandler(const wxString& name)
70{
71 wxBitmapHandler *handler = FindHandler(name);
72 if ( handler )
73 {
74 sm_handlers.DeleteObject(handler);
c9d59ee7 75 return true;
a04eec87
VS
76 }
77 else
c9d59ee7 78 return false;
a04eec87
VS
79}
80
81wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
82{
ac32ba44 83 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
84 while ( node )
85 {
1bc822df 86 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
a04eec87
VS
87 if ( handler->GetName() == name )
88 return handler;
1bc822df 89 node = node->GetNext();
a04eec87
VS
90 }
91 return NULL;
92}
93
94wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
95{
ac32ba44 96 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
97 while ( node )
98 {
1bc822df 99 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
a04eec87 100 if ( handler->GetExtension() == extension &&
4b232264 101 (bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
a04eec87 102 return handler;
1bc822df 103 node = node->GetNext();
a04eec87
VS
104 }
105 return NULL;
106}
107
108wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
109{
ac32ba44 110 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
111 while ( node )
112 {
1bc822df 113 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
a04eec87
VS
114 if (handler->GetType() == bitmapType)
115 return handler;
1bc822df 116 node = node->GetNext();
a04eec87
VS
117 }
118 return NULL;
119}
120
121void wxBitmapBase::CleanUpHandlers()
122{
ac32ba44 123 wxList::compatibility_iterator node = sm_handlers.GetFirst();
a04eec87
VS
124 while ( node )
125 {
1bc822df 126 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
ac32ba44 127 wxList::compatibility_iterator next = node->GetNext();
a04eec87 128 delete handler;
ac32ba44 129 sm_handlers.Erase(node);
a04eec87
VS
130 node = next;
131 }
132}
133
a04eec87
VS
134class wxBitmapBaseModule: public wxModule
135{
136DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
137public:
138 wxBitmapBaseModule() {}
98d6e4b4
PC
139 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
140 void OnExit() { wxBitmap::CleanUpHandlers(); }
a04eec87
VS
141};
142
143IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
ee058011 144
91885f46
VZ
145#endif // wxUSE_BITMAP_BASE
146
452418c4
PC
147// ----------------------------------------------------------------------------
148// wxBitmap common
149// ----------------------------------------------------------------------------
150
151#if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
152
153wxBitmap::wxBitmap(const char* const* bits)
154{
155 wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));
156
157#if wxUSE_IMAGE && wxUSE_XPM
158 wxImage image(bits);
a1b806b9 159 wxCHECK2_MSG(image.IsOk(), return, wxT("invalid bitmap data"));
452418c4
PC
160
161 *this = wxBitmap(image);
162#else
9a83f860 163 wxFAIL_MSG(wxT("creating bitmaps from XPMs not supported"));
452418c4
PC
164#endif // wxUSE_IMAGE && wxUSE_XPM
165}
166#endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
167
87f83ac8
VZ
168// ----------------------------------------------------------------------------
169// wxMaskBase
170// ----------------------------------------------------------------------------
171
172bool wxMaskBase::Create(const wxBitmap& bitmap, const wxColour& colour)
173{
174 FreeData();
175
176 return InitFromColour(bitmap, colour);
177}
178
179#if wxUSE_PALETTE
180
181bool wxMaskBase::Create(const wxBitmap& bitmap, int paletteIndex)
182{
183 wxPalette *pal = bitmap.GetPalette();
184
185 wxCHECK_MSG( pal, false,
186 wxT("Cannot create mask from palette index of a bitmap without palette") );
187
188 unsigned char r,g,b;
189 pal->GetRGB(paletteIndex, &r, &g, &b);
190
191 return Create(bitmap, wxColour(r, g, b));
192}
193
194#endif // wxUSE_PALETTE
195
196bool wxMaskBase::Create(const wxBitmap& bitmap)
197{
198 FreeData();
199
200 return InitFromMonoBitmap(bitmap);
201}