removed USE_SHARED_LIBRARY(IES)
[wxWidgets.git] / src / stubs / bitmap.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.cpp
3 // Purpose: wxBitmap
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "bitmap.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/utils.h"
18 #include "wx/palette.h"
19 #include "wx/bitmap.h"
20 #include "wx/icon.h"
21 #include "wx/log.h"
22
23 IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
24 IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
25
26 wxBitmapRefData::wxBitmapRefData()
27 {
28 m_ok = FALSE;
29 m_width = 0;
30 m_height = 0;
31 m_depth = 0;
32 m_quality = 0;
33 m_numColors = 0;
34 m_bitmapMask = NULL;
35 }
36
37 wxBitmapRefData::~wxBitmapRefData()
38 {
39 /*
40 * TODO: delete the bitmap data here.
41 */
42
43 if (m_bitmapMask)
44 delete m_bitmapMask;
45 m_bitmapMask = NULL;
46 }
47
48 wxList wxBitmap::sm_handlers;
49
50 wxBitmap::wxBitmap()
51 {
52 m_refData = NULL;
53
54 if ( wxTheBitmapList )
55 wxTheBitmapList->AddBitmap(this);
56 }
57
58 wxBitmap::~wxBitmap()
59 {
60 if (wxTheBitmapList)
61 wxTheBitmapList->DeleteObject(this);
62 }
63
64 wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
65 {
66 m_refData = new wxBitmapRefData;
67
68 M_BITMAPDATA->m_width = the_width ;
69 M_BITMAPDATA->m_height = the_height ;
70 M_BITMAPDATA->m_depth = no_bits ;
71 M_BITMAPDATA->m_numColors = 0;
72
73 /* TODO: create the bitmap from data */
74
75 if ( wxTheBitmapList )
76 wxTheBitmapList->AddBitmap(this);
77 }
78
79 wxBitmap::wxBitmap(int w, int h, int d)
80 {
81 (void)Create(w, h, d);
82
83 if ( wxTheBitmapList )
84 wxTheBitmapList->AddBitmap(this);
85 }
86
87 wxBitmap::wxBitmap(void *data, long type, int width, int height, int depth)
88 {
89 (void) Create(data, type, width, height, depth);
90
91 if ( wxTheBitmapList )
92 wxTheBitmapList->AddBitmap(this);
93 }
94
95 wxBitmap::wxBitmap(const wxString& filename, long type)
96 {
97 LoadFile(filename, (int)type);
98
99 if ( wxTheBitmapList )
100 wxTheBitmapList->AddBitmap(this);
101 }
102
103 /* TODO: maybe allow creation from XPM
104 // Create from data
105 wxBitmap::wxBitmap(const char **data)
106 {
107 (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
108 }
109 */
110
111 bool wxBitmap::Create(int w, int h, int d)
112 {
113 UnRef();
114
115 m_refData = new wxBitmapRefData;
116
117 M_BITMAPDATA->m_width = w;
118 M_BITMAPDATA->m_height = h;
119 M_BITMAPDATA->m_depth = d;
120
121 /* TODO: create new bitmap */
122
123 return M_BITMAPDATA->m_ok;
124 }
125
126 bool wxBitmap::LoadFile(const wxString& filename, long type)
127 {
128 UnRef();
129
130 m_refData = new wxBitmapRefData;
131
132 wxBitmapHandler *handler = FindHandler(type);
133
134 if ( handler == NULL ) {
135 wxLogWarning("no bitmap handler for type %d defined.", type);
136
137 return FALSE;
138 }
139
140 return handler->LoadFile(this, filename, type, -1, -1);
141 }
142
143 bool wxBitmap::Create(void *data, long type, int width, int height, int depth)
144 {
145 UnRef();
146
147 m_refData = new wxBitmapRefData;
148
149 wxBitmapHandler *handler = FindHandler(type);
150
151 if ( handler == NULL ) {
152 wxLogWarning("no bitmap handler for type %d defined.", type);
153
154 return FALSE;
155 }
156
157 return handler->Create(this, data, type, width, height, depth);
158 }
159
160 bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *palette)
161 {
162 wxBitmapHandler *handler = FindHandler(type);
163
164 if ( handler == NULL ) {
165 wxLogWarning("no bitmap handler for type %d defined.", type);
166
167 return FALSE;
168 }
169
170 return handler->SaveFile(this, filename, type, palette);
171 }
172
173 void wxBitmap::SetWidth(int w)
174 {
175 if (!M_BITMAPDATA)
176 m_refData = new wxBitmapRefData;
177
178 M_BITMAPDATA->m_width = w;
179 }
180
181 void wxBitmap::SetHeight(int h)
182 {
183 if (!M_BITMAPDATA)
184 m_refData = new wxBitmapRefData;
185
186 M_BITMAPDATA->m_height = h;
187 }
188
189 void wxBitmap::SetDepth(int d)
190 {
191 if (!M_BITMAPDATA)
192 m_refData = new wxBitmapRefData;
193
194 M_BITMAPDATA->m_depth = d;
195 }
196
197 void wxBitmap::SetQuality(int q)
198 {
199 if (!M_BITMAPDATA)
200 m_refData = new wxBitmapRefData;
201
202 M_BITMAPDATA->m_quality = q;
203 }
204
205 void wxBitmap::SetOk(bool isOk)
206 {
207 if (!M_BITMAPDATA)
208 m_refData = new wxBitmapRefData;
209
210 M_BITMAPDATA->m_ok = isOk;
211 }
212
213 void wxBitmap::SetPalette(const wxPalette& palette)
214 {
215 if (!M_BITMAPDATA)
216 m_refData = new wxBitmapRefData;
217
218 M_BITMAPDATA->m_bitmapPalette = palette ;
219 }
220
221 void wxBitmap::SetMask(wxMask *mask)
222 {
223 if (!M_BITMAPDATA)
224 m_refData = new wxBitmapRefData;
225
226 M_BITMAPDATA->m_bitmapMask = mask ;
227 }
228
229 void wxBitmap::AddHandler(wxBitmapHandler *handler)
230 {
231 sm_handlers.Append(handler);
232 }
233
234 void wxBitmap::InsertHandler(wxBitmapHandler *handler)
235 {
236 sm_handlers.Insert(handler);
237 }
238
239 bool wxBitmap::RemoveHandler(const wxString& name)
240 {
241 wxBitmapHandler *handler = FindHandler(name);
242 if ( handler )
243 {
244 sm_handlers.DeleteObject(handler);
245 return TRUE;
246 }
247 else
248 return FALSE;
249 }
250
251 wxBitmapHandler *wxBitmap::FindHandler(const wxString& name)
252 {
253 wxNode *node = sm_handlers.First();
254 while ( node )
255 {
256 wxBitmapHandler *handler = (wxBitmapHandler *)node->Data();
257 if ( handler->GetName() == name )
258 return handler;
259 node = node->Next();
260 }
261 return NULL;
262 }
263
264 wxBitmapHandler *wxBitmap::FindHandler(const wxString& extension, long bitmapType)
265 {
266 wxNode *node = sm_handlers.First();
267 while ( node )
268 {
269 wxBitmapHandler *handler = (wxBitmapHandler *)node->Data();
270 if ( handler->GetExtension() == extension &&
271 (bitmapType == -1 || handler->GetType() == bitmapType) )
272 return handler;
273 node = node->Next();
274 }
275 return NULL;
276 }
277
278 wxBitmapHandler *wxBitmap::FindHandler(long bitmapType)
279 {
280 wxNode *node = sm_handlers.First();
281 while ( node )
282 {
283 wxBitmapHandler *handler = (wxBitmapHandler *)node->Data();
284 if (handler->GetType() == bitmapType)
285 return handler;
286 node = node->Next();
287 }
288 return NULL;
289 }
290
291 /*
292 * wxMask
293 */
294
295 wxMask::wxMask()
296 {
297 /* TODO
298 m_maskBitmap = 0;
299 */
300 }
301
302 // Construct a mask from a bitmap and a colour indicating
303 // the transparent area
304 wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
305 {
306 /* TODO
307 m_maskBitmap = 0;
308 */
309 Create(bitmap, colour);
310 }
311
312 // Construct a mask from a bitmap and a palette index indicating
313 // the transparent area
314 wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
315 {
316 /* TODO
317 m_maskBitmap = 0;
318 */
319
320 Create(bitmap, paletteIndex);
321 }
322
323 // Construct a mask from a mono bitmap (copies the bitmap).
324 wxMask::wxMask(const wxBitmap& bitmap)
325 {
326 /* TODO
327 m_maskBitmap = 0;
328 */
329
330 Create(bitmap);
331 }
332
333 wxMask::~wxMask()
334 {
335 // TODO: delete mask bitmap
336 }
337
338 // Create a mask from a mono bitmap (copies the bitmap).
339 bool wxMask::Create(const wxBitmap& bitmap)
340 {
341 // TODO
342 return FALSE;
343 }
344
345 // Create a mask from a bitmap and a palette index indicating
346 // the transparent area
347 bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex)
348 {
349 // TODO
350 return FALSE;
351 }
352
353 // Create a mask from a bitmap and a colour indicating
354 // the transparent area
355 bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
356 {
357 // TODO
358 return FALSE;
359 }
360
361 /*
362 * wxBitmapHandler
363 */
364
365 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject)
366
367 bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
368 {
369 return FALSE;
370 }
371
372 bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long type,
373 int desiredWidth, int desiredHeight)
374 {
375 return FALSE;
376 }
377
378 bool wxBitmapHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
379 {
380 return FALSE;
381 }
382
383 /*
384 * Standard handlers
385 */
386
387 /* TODO: bitmap handlers, a bit like this:
388 class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
389 {
390 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
391 public:
392 inline wxBMPResourceHandler()
393 {
394 m_name = "Windows bitmap resource";
395 m_extension = "";
396 m_type = wxBITMAP_TYPE_BMP_RESOURCE;
397 };
398
399 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
400 int desiredWidth, int desiredHeight);
401 };
402 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
403 */
404
405 void wxBitmap::CleanUpHandlers()
406 {
407 wxNode *node = sm_handlers.First();
408 while ( node )
409 {
410 wxBitmapHandler *handler = (wxBitmapHandler *)node->Data();
411 wxNode *next = node->Next();
412 delete handler;
413 delete node;
414 node = next;
415 }
416 }
417
418 void wxBitmap::InitStandardHandlers()
419 {
420 /* TODO: initialize all standard bitmap or derive class handlers here.
421 AddHandler(new wxBMPResourceHandler);
422 AddHandler(new wxBMPFileHandler);
423 AddHandler(new wxXPMFileHandler);
424 AddHandler(new wxXPMDataHandler);
425 AddHandler(new wxICOResourceHandler);
426 AddHandler(new wxICOFileHandler);
427 */
428 }