]> git.saurik.com Git - wxWidgets.git/blob - src/common/bmpbase.cpp
mac methodname fixed, so all use the same now
[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(wxBitmap,WXDLLEXPORT)
32 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxIcon,WXDLLEXPORT)
33 #endif
34
35 // ----------------------------------------------------------------------------
36 // wxBitmapBase
37 // ----------------------------------------------------------------------------
38
39 #if wxUSE_BITMAP_BASE
40
41 #ifndef WX_PRECOMP
42 #include "wx/log.h"
43 #include "wx/utils.h"
44 #include "wx/palette.h"
45 #include "wx/module.h"
46 #endif // WX_PRECOMP
47
48
49 IMPLEMENT_ABSTRACT_CLASS(wxBitmapBase, wxGDIObject)
50 IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandlerBase,wxObject)
51
52 wxList wxBitmapBase::sm_handlers;
53
54 void wxBitmapBase::AddHandler(wxBitmapHandlerBase *handler)
55 {
56 sm_handlers.Append(handler);
57 }
58
59 void wxBitmapBase::InsertHandler(wxBitmapHandlerBase *handler)
60 {
61 sm_handlers.Insert(handler);
62 }
63
64 bool wxBitmapBase::RemoveHandler(const wxString& name)
65 {
66 wxBitmapHandler *handler = FindHandler(name);
67 if ( handler )
68 {
69 sm_handlers.DeleteObject(handler);
70 return true;
71 }
72 else
73 return false;
74 }
75
76 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& name)
77 {
78 wxList::compatibility_iterator node = sm_handlers.GetFirst();
79 while ( node )
80 {
81 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
82 if ( handler->GetName() == name )
83 return handler;
84 node = node->GetNext();
85 }
86 return NULL;
87 }
88
89 wxBitmapHandler *wxBitmapBase::FindHandler(const wxString& extension, wxBitmapType bitmapType)
90 {
91 wxList::compatibility_iterator node = sm_handlers.GetFirst();
92 while ( node )
93 {
94 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
95 if ( handler->GetExtension() == extension &&
96 (bitmapType == wxBITMAP_TYPE_ANY || handler->GetType() == bitmapType) )
97 return handler;
98 node = node->GetNext();
99 }
100 return NULL;
101 }
102
103 wxBitmapHandler *wxBitmapBase::FindHandler(wxBitmapType bitmapType)
104 {
105 wxList::compatibility_iterator node = sm_handlers.GetFirst();
106 while ( node )
107 {
108 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
109 if (handler->GetType() == bitmapType)
110 return handler;
111 node = node->GetNext();
112 }
113 return NULL;
114 }
115
116 void wxBitmapBase::CleanUpHandlers()
117 {
118 wxList::compatibility_iterator node = sm_handlers.GetFirst();
119 while ( node )
120 {
121 wxBitmapHandler *handler = (wxBitmapHandler *)node->GetData();
122 wxList::compatibility_iterator next = node->GetNext();
123 delete handler;
124 sm_handlers.Erase(node);
125 node = next;
126 }
127 }
128
129 bool wxBitmapHandlerBase::Create(wxBitmap*, const void*, long, int, int, int)
130 {
131 return false;
132 }
133
134 bool wxBitmapHandlerBase::LoadFile(wxBitmap*, const wxString&, long, int, int)
135 {
136 return false;
137 }
138
139 bool wxBitmapHandlerBase::SaveFile(const wxBitmap*, const wxString&, int, const wxPalette*)
140 {
141 return false;
142 }
143
144 class wxBitmapBaseModule: public wxModule
145 {
146 DECLARE_DYNAMIC_CLASS(wxBitmapBaseModule)
147 public:
148 wxBitmapBaseModule() {}
149 bool OnInit() { wxBitmap::InitStandardHandlers(); return true; }
150 void OnExit() { wxBitmap::CleanUpHandlers(); }
151 };
152
153 IMPLEMENT_DYNAMIC_CLASS(wxBitmapBaseModule, wxModule)
154
155 #endif // wxUSE_BITMAP_BASE
156
157 // ----------------------------------------------------------------------------
158 // wxBitmap common
159 // ----------------------------------------------------------------------------
160
161 #if !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
162
163 wxBitmap::wxBitmap(const char* const* bits)
164 {
165 wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));
166
167 #if wxUSE_IMAGE && wxUSE_XPM
168 wxImage image(bits);
169 wxCHECK2_MSG(image.Ok(), return, wxT("invalid bitmap data"));
170
171 *this = wxBitmap(image);
172 #else
173 wxFAIL_MSG(_T("creating bitmaps from XPMs not supported"));
174 #endif // wxUSE_IMAGE && wxUSE_XPM
175 }
176 #endif // !(defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__))
177
178 // ----------------------------------------------------------------------------
179 // wxMaskBase
180 // ----------------------------------------------------------------------------
181
182 bool wxMaskBase::Create(const wxBitmap& bitmap, const wxColour& colour)
183 {
184 FreeData();
185
186 return InitFromColour(bitmap, colour);
187 }
188
189 #if wxUSE_PALETTE
190
191 bool wxMaskBase::Create(const wxBitmap& bitmap, int paletteIndex)
192 {
193 wxPalette *pal = bitmap.GetPalette();
194
195 wxCHECK_MSG( pal, false,
196 wxT("Cannot create mask from palette index of a bitmap without palette") );
197
198 unsigned char r,g,b;
199 pal->GetRGB(paletteIndex, &r, &g, &b);
200
201 return Create(bitmap, wxColour(r, g, b));
202 }
203
204 #endif // wxUSE_PALETTE
205
206 bool wxMaskBase::Create(const wxBitmap& bitmap)
207 {
208 FreeData();
209
210 return InitFromMonoBitmap(bitmap);
211 }