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