]> git.saurik.com Git - wxWidgets.git/blob - src/common/bmpbase.cpp
Don't generate any events from wxSpinCtrl and wxSpinCtrlDouble methods.
[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 // Copyright: (c) 2001, Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #include "wx/bitmap.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/colour.h"
21 #include "wx/icon.h"
22 #include "wx/image.h"
23 #endif // WX_PRECOMP
24
25 #if wxUSE_IMAGE && wxUSE_LIBPNG && wxUSE_STREAMS
26 #define wxHAS_PNG_LOAD
27
28 #include "wx/mstream.h"
29 #endif
30
31 // ----------------------------------------------------------------------------
32 // wxVariant support
33 // ----------------------------------------------------------------------------
34
35 #if wxUSE_VARIANT
36 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap,WXDLLEXPORT)
37 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT)
38 #endif
39
40 #if wxUSE_EXTENDED_RTTI
41 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxBitmap>)
42 //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxIcon>)
43 #endif
44
45 // ----------------------------------------------------------------------------
46 // wxBitmapHelpers
47 // ----------------------------------------------------------------------------
48
49 // wxOSX has a native version and doesn't use this one.
50
51 #ifndef __WXOSX__
52
53 /* static */
54 wxBitmap wxBitmapHelpers::NewFromPNGData(const void* data, size_t size)
55 {
56 wxBitmap bitmap;
57
58 #ifdef wxHAS_PNG_LOAD
59 wxMemoryInputStream is(data, size);
60 wxImage image(is, wxBITMAP_TYPE_PNG);
61 if ( image.IsOk() )
62 bitmap = wxBitmap(image);
63 #endif // wxHAS_PNG_LOAD
64
65 return bitmap;
66 }
67
68 #endif // !__WXOSX__
69
70 // ----------------------------------------------------------------------------
71 // wxBitmapBase
72 // ----------------------------------------------------------------------------
73
74 #if wxUSE_BITMAP_BASE
75
76 #ifndef WX_PRECOMP
77 #include "wx/log.h"
78 #include "wx/utils.h"
79 #include "wx/palette.h"
80 #include "wx/module.h"
81 #endif // WX_PRECOMP
82
83
84 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
85 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler, wxObject)
86
87 wxList wxBitmapBase::sm_handlers;
88
89 void wxBitmapBase::AddHandler(wxBitmapHandler *handler)
90 {
91 sm_handlers.Append(handler);
92 }
93
94 void wxBitmapBase::InsertHandler(wxBitmapHandler *handler)
95 {
96 sm_handlers.Insert(handler);
97 }
98
99 bool wxBitmapBase::RemoveHandler(const wxString& name)
100 {
101 wxBitmapHandler *handler = FindHandler(name);
102 if ( handler )
103 {
104 sm_handlers.DeleteObject(handler);
105 return true;
106 }
107 else
108 return false;
109 }
110
111 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
112 {
113 wxList::compatibility_iterator node = sm_handlers.GetFirst();
114 while ( node )
115 {
116 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
117 if ( handler->GetName() == name )
118 return handler;
119 node = node->GetNext();
120 }
121 return NULL;
122 }
123
124 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
125 {
126 wxList::compatibility_iterator node = sm_handlers.GetFirst();
127 while ( node )
128 {
129 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
130 if ( handler->GetExtension() == extension &&
131 (bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
132 return handler;
133 node = node->GetNext();
134 }
135 return NULL;
136 }
137
138 wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
139 {
140 wxList::compatibility_iterator node = sm_handlers.GetFirst();
141 while ( node )
142 {
143 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
144 if (handler->GetType() == bitmapType)
145 return handler;
146 node = node->GetNext();
147 }
148 return NULL;
149 }
150
151 void wxBitmapBase::CleanUpHandlers()
152 {
153 wxList::compatibility_iterator node = sm_handlers.GetFirst();
154 while ( node )
155 {
156 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
157 wxList::compatibility_iterator next = node->GetNext();
158 delete handler;
159 sm_handlers.Erase(node);
160 node = next;
161 }
162 }
163
164 class wxBitmapBaseModule: public wxModule
165 {
166 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
167 public:
168 wxBitmapBaseModule() {}
169 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
170 void OnExit() { wxBitmap::CleanUpHandlers(); }
171 };
172
173 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
174
175 #endif // wxUSE_BITMAP_BASE
176
177 // ----------------------------------------------------------------------------
178 // wxBitmap common
179 // ----------------------------------------------------------------------------
180
181 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
182
183 wxBitmap::wxBitmap(const char* const* bits)
184 {
185 wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));
186
187 #if wxUSE_IMAGE && wxUSE_XPM
188 wxImage image(bits);
189 wxCHECK2_MSG(image.IsOk(), return, wxT("invalid bitmap data"));
190
191 *this = wxBitmap(image);
192 #else
193 wxFAIL_MSG(wxT("creating bitmaps from XPMs not supported"));
194 #endif // wxUSE_IMAGE && wxUSE_XPM
195 }
196 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
197
198 // ----------------------------------------------------------------------------
199 // wxMaskBase
200 // ----------------------------------------------------------------------------
201
202 bool wxMaskBase::Create(const wxBitmap& bitmap, const wxColour& colour)
203 {
204 FreeData();
205
206 return InitFromColour(bitmap, colour);
207 }
208
209 #if wxUSE_PALETTE
210
211 bool wxMaskBase::Create(const wxBitmap& bitmap, int paletteIndex)
212 {
213 wxPalette *pal = bitmap.GetPalette();
214
215 wxCHECK_MSG( pal, false,
216 wxT("Cannot create mask from palette index of a bitmap without palette") );
217
218 unsigned char r,g,b;
219 pal->GetRGB(paletteIndex, &r, &g, &b);
220
221 return Create(bitmap, wxColour(r, g, b));
222 }
223
224 #endif // wxUSE_PALETTE
225
226 bool wxMaskBase::Create(const wxBitmap& bitmap)
227 {
228 FreeData();
229
230 return InitFromMonoBitmap(bitmap);
231 }