]>
Commit | Line | Data |
---|---|---|
7c78e7c7 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: bitmap.cpp | |
01b2eeec KB |
3 | // Purpose: wxBitmap |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7c78e7c7 | 7 | // RCS-ID: $Id$ |
01b2eeec KB |
8 | // Copyright: (c) AUTHOR |
9 | // Licence: wxWindows licence | |
7c78e7c7 RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "bitmap.h" | |
14 | #endif | |
15 | ||
01b2eeec KB |
16 | #include "wx/setup.h" |
17 | #include "wx/utils.h" | |
18 | #include "wx/palette.h" | |
7c78e7c7 | 19 | #include "wx/bitmap.h" |
01b2eeec KB |
20 | #include "wx/icon.h" |
21 | #include "wx/log.h" | |
7c78e7c7 | 22 | |
01b2eeec KB |
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 | } | |
7c78e7c7 | 38 | |
01b2eeec KB |
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 | } | |
7c78e7c7 | 49 | |
01b2eeec | 50 | wxList wxBitmap::sm_handlers; |
7c78e7c7 | 51 | |
01b2eeec | 52 | wxBitmap::wxBitmap() |
7c78e7c7 | 53 | { |
01b2eeec | 54 | m_refData = NULL; |
7c78e7c7 | 55 | |
01b2eeec KB |
56 | if ( wxTheBitmapList ) |
57 | wxTheBitmapList->AddBitmap(this); | |
58 | } | |
59 | ||
60 | wxBitmap::~wxBitmap() | |
7c78e7c7 | 61 | { |
01b2eeec KB |
62 | if (wxTheBitmapList) |
63 | wxTheBitmapList->DeleteObject(this); | |
64 | } | |
7c78e7c7 | 65 | |
01b2eeec | 66 | wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits) |
7c78e7c7 | 67 | { |
01b2eeec KB |
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; | |
7c78e7c7 | 74 | |
01b2eeec KB |
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) | |
7c78e7c7 | 82 | { |
01b2eeec KB |
83 | (void)Create(w, h, d); |
84 | ||
85 | if ( wxTheBitmapList ) | |
86 | wxTheBitmapList->AddBitmap(this); | |
87 | } | |
7c78e7c7 | 88 | |
01b2eeec | 89 | wxBitmap::wxBitmap(void *data, long type, int width, int height, int depth) |
7c78e7c7 | 90 | { |
01b2eeec | 91 | (void) Create(data, type, width, height, depth); |
7c78e7c7 | 92 | |
01b2eeec KB |
93 | if ( wxTheBitmapList ) |
94 | wxTheBitmapList->AddBitmap(this); | |
95 | } | |
7c78e7c7 | 96 | |
01b2eeec | 97 | wxBitmap::wxBitmap(const wxString& filename, long type) |
7c78e7c7 | 98 | { |
01b2eeec | 99 | LoadFile(filename, (int)type); |
7c78e7c7 | 100 | |
01b2eeec KB |
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) | |
7c78e7c7 | 108 | { |
01b2eeec KB |
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; | |
7c78e7c7 | 118 | |
01b2eeec KB |
119 | M_BITMAPDATA->m_width = w; |
120 | M_BITMAPDATA->m_height = h; | |
121 | M_BITMAPDATA->m_depth = d; | |
7c78e7c7 | 122 | |
01b2eeec | 123 | /* TODO: create new bitmap */ |
7c78e7c7 | 124 | |
01b2eeec KB |
125 | return M_BITMAPDATA->m_ok; |
126 | } | |
7c78e7c7 | 127 | |
01b2eeec | 128 | bool wxBitmap::LoadFile(const wxString& filename, long type) |
7c78e7c7 | 129 | { |
01b2eeec KB |
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 | } | |
7c78e7c7 | 144 | |
01b2eeec | 145 | bool wxBitmap::Create(void *data, long type, int width, int height, int depth) |
7c78e7c7 | 146 | { |
01b2eeec | 147 | UnRef(); |
7c78e7c7 | 148 | |
01b2eeec KB |
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) | |
7c78e7c7 | 163 | { |
01b2eeec KB |
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) | |
7c78e7c7 | 176 | { |
01b2eeec KB |
177 | if (!M_BITMAPDATA) |
178 | m_refData = new wxBitmapRefData; | |
7c78e7c7 | 179 | |
01b2eeec KB |
180 | M_BITMAPDATA->m_width = w; |
181 | } | |
182 | ||
183 | void wxBitmap::SetHeight(int h) | |
7c78e7c7 | 184 | { |
01b2eeec KB |
185 | if (!M_BITMAPDATA) |
186 | m_refData = new wxBitmapRefData; | |
187 | ||
188 | M_BITMAPDATA->m_height = h; | |
189 | } | |
7c78e7c7 | 190 | |
01b2eeec | 191 | void wxBitmap::SetDepth(int d) |
7c78e7c7 | 192 | { |
01b2eeec KB |
193 | if (!M_BITMAPDATA) |
194 | m_refData = new wxBitmapRefData; | |
7c78e7c7 | 195 | |
01b2eeec KB |
196 | M_BITMAPDATA->m_depth = d; |
197 | } | |
198 | ||
199 | void wxBitmap::SetQuality(int q) | |
200 | { | |
201 | if (!M_BITMAPDATA) | |
202 | m_refData = new wxBitmapRefData; | |
7c78e7c7 | 203 | |
01b2eeec | 204 | M_BITMAPDATA->m_quality = q; |
7c78e7c7 | 205 | } |
01b2eeec KB |
206 | |
207 | void wxBitmap::SetOk(bool isOk) | |
7c78e7c7 | 208 | { |
01b2eeec KB |
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) | |
7c78e7c7 | 216 | { |
01b2eeec KB |
217 | if (!M_BITMAPDATA) |
218 | m_refData = new wxBitmapRefData; | |
219 | ||
220 | M_BITMAPDATA->m_bitmapPalette = palette ; | |
221 | } | |
222 | ||
223 | void wxBitmap::SetMask(wxMask *mask) | |
7c78e7c7 | 224 | { |
01b2eeec KB |
225 | if (!M_BITMAPDATA) |
226 | m_refData = new wxBitmapRefData; | |
227 | ||
228 | M_BITMAPDATA->m_bitmapMask = mask ; | |
229 | } | |
230 | ||
231 | void wxBitmap::AddHandler(wxBitmapHandler *handler) | |
7c78e7c7 | 232 | { |
01b2eeec KB |
233 | sm_handlers.Append(handler); |
234 | } | |
235 | ||
236 | void wxBitmap::InsertHandler(wxBitmapHandler *handler) | |
7c78e7c7 | 237 | { |
01b2eeec KB |
238 | sm_handlers.Insert(handler); |
239 | } | |
240 | ||
241 | bool wxBitmap::RemoveHandler(const wxString& name) | |
7c78e7c7 | 242 | { |
01b2eeec KB |
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 | } | |
7c78e7c7 | 265 | |
01b2eeec KB |
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() | |
7c78e7c7 | 298 | { |
01b2eeec KB |
299 | /* TODO |
300 | m_maskBitmap = 0; | |
301 | */ | |
302 | } | |
7c78e7c7 | 303 | |
01b2eeec KB |
304 | // Construct a mask from a bitmap and a colour indicating |
305 | // the transparent area | |
306 | wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour) | |
7c78e7c7 | 307 | { |
01b2eeec KB |
308 | /* TODO |
309 | m_maskBitmap = 0; | |
310 | */ | |
311 | Create(bitmap, colour); | |
312 | } | |
7c78e7c7 | 313 | |
01b2eeec KB |
314 | // Construct a mask from a bitmap and a palette index indicating |
315 | // the transparent area | |
316 | wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex) | |
7c78e7c7 | 317 | { |
01b2eeec KB |
318 | /* TODO |
319 | m_maskBitmap = 0; | |
320 | */ | |
321 | ||
322 | Create(bitmap, paletteIndex); | |
323 | } | |
7c78e7c7 | 324 | |
01b2eeec KB |
325 | // Construct a mask from a mono bitmap (copies the bitmap). |
326 | wxMask::wxMask(const wxBitmap& bitmap) | |
7c78e7c7 | 327 | { |
01b2eeec KB |
328 | /* TODO |
329 | m_maskBitmap = 0; | |
330 | */ | |
331 | ||
332 | Create(bitmap); | |
333 | } | |
7c78e7c7 | 334 | |
01b2eeec | 335 | wxMask::~wxMask() |
7c78e7c7 | 336 | { |
01b2eeec KB |
337 | // TODO: delete mask bitmap |
338 | } | |
7c78e7c7 | 339 | |
01b2eeec KB |
340 | // Create a mask from a mono bitmap (copies the bitmap). |
341 | bool wxMask::Create(const wxBitmap& bitmap) | |
7c78e7c7 | 342 | { |
01b2eeec KB |
343 | // TODO |
344 | return FALSE; | |
345 | } | |
7c78e7c7 | 346 | |
01b2eeec KB |
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) | |
7c78e7c7 | 350 | { |
01b2eeec KB |
351 | // TODO |
352 | return FALSE; | |
353 | } | |
7c78e7c7 | 354 | |
01b2eeec KB |
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) | |
7c78e7c7 | 358 | { |
01b2eeec KB |
359 | // TODO |
360 | return FALSE; | |
361 | } | |
7c78e7c7 | 362 | |
01b2eeec KB |
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) | |
7c78e7c7 | 370 | { |
01b2eeec KB |
371 | return FALSE; |
372 | } | |
7c78e7c7 | 373 | |
01b2eeec KB |
374 | bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long type, |
375 | int desiredWidth, int desiredHeight) | |
7c78e7c7 | 376 | { |
01b2eeec KB |
377 | return FALSE; |
378 | } | |
379 | ||
380 | bool wxBitmapHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette) | |
7c78e7c7 | 381 | { |
01b2eeec KB |
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); | |
7c78e7c7 | 403 | }; |
01b2eeec KB |
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 | } | |
7c78e7c7 | 419 | |
01b2eeec KB |
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 | } |