]> git.saurik.com Git - wxWidgets.git/blame - src/qt/bitmap.cpp
Busy cursor don't need wxYield(), SendIdleEvents()
[wxWidgets.git] / src / qt / bitmap.cpp
CommitLineData
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
23IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
24IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
01b2eeec
KB
25
26wxBitmapRefData::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}
7c78e7c7 36
01b2eeec
KB
37wxBitmapRefData::~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}
7c78e7c7 47
01b2eeec 48wxList wxBitmap::sm_handlers;
7c78e7c7 49
01b2eeec 50wxBitmap::wxBitmap()
7c78e7c7 51{
01b2eeec 52 m_refData = NULL;
7c78e7c7 53
01b2eeec
KB
54 if ( wxTheBitmapList )
55 wxTheBitmapList->AddBitmap(this);
56}
57
58wxBitmap::~wxBitmap()
7c78e7c7 59{
01b2eeec
KB
60 if (wxTheBitmapList)
61 wxTheBitmapList->DeleteObject(this);
62}
7c78e7c7 63
01b2eeec 64wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
7c78e7c7 65{
01b2eeec
KB
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;
7c78e7c7 72
01b2eeec
KB
73 /* TODO: create the bitmap from data */
74
75 if ( wxTheBitmapList )
76 wxTheBitmapList->AddBitmap(this);
77}
78
79wxBitmap::wxBitmap(int w, int h, int d)
7c78e7c7 80{
01b2eeec
KB
81 (void)Create(w, h, d);
82
83 if ( wxTheBitmapList )
84 wxTheBitmapList->AddBitmap(this);
85}
7c78e7c7 86
01b2eeec 87wxBitmap::wxBitmap(void *data, long type, int width, int height, int depth)
7c78e7c7 88{
01b2eeec 89 (void) Create(data, type, width, height, depth);
7c78e7c7 90
01b2eeec
KB
91 if ( wxTheBitmapList )
92 wxTheBitmapList->AddBitmap(this);
93}
7c78e7c7 94
01b2eeec 95wxBitmap::wxBitmap(const wxString& filename, long type)
7c78e7c7 96{
01b2eeec 97 LoadFile(filename, (int)type);
7c78e7c7 98
01b2eeec
KB
99 if ( wxTheBitmapList )
100 wxTheBitmapList->AddBitmap(this);
101}
102
103/* TODO: maybe allow creation from XPM
104// Create from data
105wxBitmap::wxBitmap(const char **data)
7c78e7c7 106{
01b2eeec
KB
107 (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
108}
109*/
110
111bool wxBitmap::Create(int w, int h, int d)
112{
113 UnRef();
114
115 m_refData = new wxBitmapRefData;
7c78e7c7 116
01b2eeec
KB
117 M_BITMAPDATA->m_width = w;
118 M_BITMAPDATA->m_height = h;
119 M_BITMAPDATA->m_depth = d;
7c78e7c7 120
01b2eeec 121 /* TODO: create new bitmap */
7c78e7c7 122
01b2eeec
KB
123 return M_BITMAPDATA->m_ok;
124}
7c78e7c7 125
01b2eeec 126bool wxBitmap::LoadFile(const wxString& filename, long type)
7c78e7c7 127{
01b2eeec
KB
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}
7c78e7c7 142
01b2eeec 143bool wxBitmap::Create(void *data, long type, int width, int height, int depth)
7c78e7c7 144{
01b2eeec 145 UnRef();
7c78e7c7 146
01b2eeec
KB
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
160bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *palette)
7c78e7c7 161{
01b2eeec
KB
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
173void wxBitmap::SetWidth(int w)
7c78e7c7 174{
01b2eeec
KB
175 if (!M_BITMAPDATA)
176 m_refData = new wxBitmapRefData;
7c78e7c7 177
01b2eeec
KB
178 M_BITMAPDATA->m_width = w;
179}
180
181void wxBitmap::SetHeight(int h)
7c78e7c7 182{
01b2eeec
KB
183 if (!M_BITMAPDATA)
184 m_refData = new wxBitmapRefData;
185
186 M_BITMAPDATA->m_height = h;
187}
7c78e7c7 188
01b2eeec 189void wxBitmap::SetDepth(int d)
7c78e7c7 190{
01b2eeec
KB
191 if (!M_BITMAPDATA)
192 m_refData = new wxBitmapRefData;
7c78e7c7 193
01b2eeec
KB
194 M_BITMAPDATA->m_depth = d;
195}
196
197void wxBitmap::SetQuality(int q)
198{
199 if (!M_BITMAPDATA)
200 m_refData = new wxBitmapRefData;
7c78e7c7 201
01b2eeec 202 M_BITMAPDATA->m_quality = q;
7c78e7c7 203}
01b2eeec
KB
204
205void wxBitmap::SetOk(bool isOk)
7c78e7c7 206{
01b2eeec
KB
207 if (!M_BITMAPDATA)
208 m_refData = new wxBitmapRefData;
209
210 M_BITMAPDATA->m_ok = isOk;
211}
212
213void wxBitmap::SetPalette(const wxPalette& palette)
7c78e7c7 214{
01b2eeec
KB
215 if (!M_BITMAPDATA)
216 m_refData = new wxBitmapRefData;
217
218 M_BITMAPDATA->m_bitmapPalette = palette ;
219}
220
221void wxBitmap::SetMask(wxMask *mask)
7c78e7c7 222{
01b2eeec
KB
223 if (!M_BITMAPDATA)
224 m_refData = new wxBitmapRefData;
225
226 M_BITMAPDATA->m_bitmapMask = mask ;
227}
228
229void wxBitmap::AddHandler(wxBitmapHandler *handler)
7c78e7c7 230{
01b2eeec
KB
231 sm_handlers.Append(handler);
232}
233
234void wxBitmap::InsertHandler(wxBitmapHandler *handler)
7c78e7c7 235{
01b2eeec
KB
236 sm_handlers.Insert(handler);
237}
238
239bool wxBitmap::RemoveHandler(const wxString& name)
7c78e7c7 240{
01b2eeec
KB
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
251wxBitmapHandler *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}
7c78e7c7 263
01b2eeec
KB
264wxBitmapHandler *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
278wxBitmapHandler *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
295wxMask::wxMask()
7c78e7c7 296{
01b2eeec
KB
297/* TODO
298 m_maskBitmap = 0;
299*/
300}
7c78e7c7 301
01b2eeec
KB
302// Construct a mask from a bitmap and a colour indicating
303// the transparent area
304wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
7c78e7c7 305{
01b2eeec
KB
306/* TODO
307 m_maskBitmap = 0;
308*/
309 Create(bitmap, colour);
310}
7c78e7c7 311
01b2eeec
KB
312// Construct a mask from a bitmap and a palette index indicating
313// the transparent area
314wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
7c78e7c7 315{
01b2eeec
KB
316/* TODO
317 m_maskBitmap = 0;
318*/
319
320 Create(bitmap, paletteIndex);
321}
7c78e7c7 322
01b2eeec
KB
323// Construct a mask from a mono bitmap (copies the bitmap).
324wxMask::wxMask(const wxBitmap& bitmap)
7c78e7c7 325{
01b2eeec
KB
326/* TODO
327 m_maskBitmap = 0;
328*/
329
330 Create(bitmap);
331}
7c78e7c7 332
01b2eeec 333wxMask::~wxMask()
7c78e7c7 334{
01b2eeec
KB
335// TODO: delete mask bitmap
336}
7c78e7c7 337
01b2eeec
KB
338// Create a mask from a mono bitmap (copies the bitmap).
339bool wxMask::Create(const wxBitmap& bitmap)
7c78e7c7 340{
01b2eeec
KB
341// TODO
342 return FALSE;
343}
7c78e7c7 344
01b2eeec
KB
345// Create a mask from a bitmap and a palette index indicating
346// the transparent area
347bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex)
7c78e7c7 348{
01b2eeec
KB
349// TODO
350 return FALSE;
351}
7c78e7c7 352
01b2eeec
KB
353// Create a mask from a bitmap and a colour indicating
354// the transparent area
355bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
7c78e7c7 356{
01b2eeec
KB
357// TODO
358 return FALSE;
359}
7c78e7c7 360
01b2eeec
KB
361/*
362 * wxBitmapHandler
363 */
364
365IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject)
366
367bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
7c78e7c7 368{
01b2eeec
KB
369 return FALSE;
370}
7c78e7c7 371
01b2eeec
KB
372bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long type,
373 int desiredWidth, int desiredHeight)
7c78e7c7 374{
01b2eeec
KB
375 return FALSE;
376}
377
378bool wxBitmapHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
7c78e7c7 379{
01b2eeec
KB
380 return FALSE;
381}
382
383/*
384 * Standard handlers
385 */
386
387/* TODO: bitmap handlers, a bit like this:
388class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
389{
390 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
391public:
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);
7c78e7c7 401};
01b2eeec
KB
402IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
403*/
404
405void 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}
7c78e7c7 417
01b2eeec
KB
418void 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}