]> git.saurik.com Git - wxWidgets.git/blob - src/common/bmpbase.cpp
Fix the build system in gtk, plus a couple of compilation errors. wxWebView now succe...
[wxWidgets.git] / src / common / bmpbase.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/bmpbase.cpp
3 // Purpose: wxBitmapBase
4 // Author: VaclavSlavik
5 // Created: 2001/04/11
6 // RCS-ID: $Id$
7 // Copyright: (c) 2001, Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/bitmap.h"
19
20 #ifndef WX_PRECOMP
21 #include "wx/colour.h"
22 #include "wx/icon.h"
23 #include "wx/image.h"
24 #endif // WX_PRECOMP
25
26 // ----------------------------------------------------------------------------
27 // wxVariant support
28 // ----------------------------------------------------------------------------
29
30 #if wxUSE_VARIANT
31 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap,WXDLLEXPORT)
32 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT)
33 #endif
34
35 #if wxUSE_EXTENDED_RTTI
36 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxBitmap>)
37 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxIcon>)
38 #endif
39
40 // ----------------------------------------------------------------------------
41 // wxBitmapBase
42 // ----------------------------------------------------------------------------
43
44 #if wxUSE_BITMAP_BASE
45
46 #ifndef WX_PRECOMP
47 #include "wx/log.h"
48 #include "wx/utils.h"
49 #include "wx/palette.h"
50 #include "wx/module.h"
51 #endif // WX_PRECOMP
52
53
54 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
55 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler, wxObject)
56
57 wxList wxBitmapBase::sm_handlers;
58
59 void wxBitmapBase::AddHandler(wxBitmapHandler *handler)
60 {
61 sm_handlers.Append(handler);
62 }
63
64 void wxBitmapBase::InsertHandler(wxBitmapHandler *handler)
65 {
66 sm_handlers.Insert(handler);
67 }
68
69 bool wxBitmapBase::RemoveHandler(const wxString& name)
70 {
71 wxBitmapHandler *handler = FindHandler(name);
72 if ( handler )
73 {
74 sm_handlers.DeleteObject(handler);
75 return true;
76 }
77 else
78 return false;
79 }
80
81 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
82 {
83 wxList::compatibility_iterator node = sm_handlers.GetFirst();
84 while ( node )
85 {
86 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
87 if ( handler->GetName() == name )
88 return handler;
89 node = node->GetNext();
90 }
91 return NULL;
92 }
93
94 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
95 {
96 wxList::compatibility_iterator node = sm_handlers.GetFirst();
97 while ( node )
98 {
99 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
100 if ( handler->GetExtension() == extension &&
101 (bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
102 return handler;
103 node = node->GetNext();
104 }
105 return NULL;
106 }
107
108 wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
109 {
110 wxList::compatibility_iterator node = sm_handlers.GetFirst();
111 while ( node )
112 {
113 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
114 if (handler->GetType() == bitmapType)
115 return handler;
116 node = node->GetNext();
117 }
118 return NULL;
119 }
120
121 void wxBitmapBase::CleanUpHandlers()
122 {
123 wxList::compatibility_iterator node = sm_handlers.GetFirst();
124 while ( node )
125 {
126 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
127 wxList::compatibility_iterator next = node->GetNext();
128 delete handler;
129 sm_handlers.Erase(node);
130 node = next;
131 }
132 }
133
134 class wxBitmapBaseModule: public wxModule
135 {
136 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
137 public:
138 wxBitmapBaseModule() {}
139 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
140 void OnExit() { wxBitmap::CleanUpHandlers(); }
141 };
142
143 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
144
145 #endif // wxUSE_BITMAP_BASE
146
147 // ----------------------------------------------------------------------------
148 // wxBitmap common
149 // ----------------------------------------------------------------------------
150
151 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
152
153 wxBitmap::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);
159 wxCHECK2_MSG(image.Ok(), return, wxT("invalid bitmap data"));
160
161 *this = wxBitmap(image);
162 #else
163 wxFAIL_MSG(wxT("creating bitmaps from XPMs not supported"));
164 #endif // wxUSE_IMAGE && wxUSE_XPM
165 }
166 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
167
168 // ----------------------------------------------------------------------------
169 // wxMaskBase
170 // ----------------------------------------------------------------------------
171
172 bool wxMaskBase::Create(const wxBitmap& bitmap, const wxColour& colour)
173 {
174 FreeData();
175
176 return InitFromColour(bitmap, colour);
177 }
178
179 #if wxUSE_PALETTE
180
181 bool 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
196 bool wxMaskBase::Create(const wxBitmap& bitmap)
197 {
198 FreeData();
199
200 return InitFromMonoBitmap(bitmap);
201 }