1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "bitmap.h"
18 #include "wx/palette.h"
19 #include "wx/bitmap.h"
24 #if !USE_SHARED_LIBRARIES
25 IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
26 IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
29 wxBitmapRefData::wxBitmapRefData()
40 wxBitmapRefData::~wxBitmapRefData()
43 * TODO: delete the bitmap data here.
55 if ( wxTheBitmapList )
56 wxTheBitmapList->AddBitmap(this);
62 wxTheBitmapList->DeleteObject(this);
65 wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
67 m_refData = new wxBitmapRefData;
69 M_BITMAPDATA->m_width = the_width ;
70 M_BITMAPDATA->m_height = the_height ;
71 M_BITMAPDATA->m_depth = no_bits ;
72 M_BITMAPDATA->m_numColors = 0;
74 /* TODO: create the bitmap from data */
76 if ( wxTheBitmapList )
77 wxTheBitmapList->AddBitmap(this);
80 wxBitmap::wxBitmap(int w, int h, int d)
82 (void)Create(w, h, d);
84 if ( wxTheBitmapList )
85 wxTheBitmapList->AddBitmap(this);
88 wxBitmap::wxBitmap(void *data, wxBitmapType type, int width, int height, int depth)
90 (void) Create(data, type, width, height, depth);
92 if ( wxTheBitmapList )
93 wxTheBitmapList->AddBitmap(this);
96 wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
98 LoadFile(filename, type);
100 if ( wxTheBitmapList )
101 wxTheBitmapList->AddBitmap(this);
104 wxBitmap::wxBitmap(const wxImage& image, int depth)
108 wxBitmap::wxBitmap(char **bits)
112 /* TODO: maybe allow creation from XPM
114 wxBitmap::wxBitmap(const char **data)
116 (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
120 bool wxBitmap::Create(int w, int h, int d)
124 m_refData = new wxBitmapRefData;
126 M_BITMAPDATA->m_width = w;
127 M_BITMAPDATA->m_height = h;
128 M_BITMAPDATA->m_depth = d;
130 /* TODO: create new bitmap */
132 return M_BITMAPDATA->m_ok;
135 bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
139 m_refData = new wxBitmapRefData;
141 wxBitmapHandler *handler = FindHandler(type);
143 if ( handler == NULL ) {
144 wxLogWarning("no bitmap handler for type %d defined.", type);
149 return handler->LoadFile(this, filename, type, -1, -1);
152 bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
156 m_refData = new wxBitmapRefData;
158 wxBitmapHandler *handler = FindHandler(type);
160 if ( handler == NULL ) {
161 wxLogWarning("no bitmap handler for type %d defined.", type);
166 return handler->Create(this, data, type, width, height, depth);
169 bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
171 wxBitmapHandler *handler = FindHandler(type);
173 if ( handler == NULL ) {
174 wxLogWarning("no bitmap handler for type %d defined.", type);
179 return handler->SaveFile(this, filename, type, palette);
182 void wxBitmap::SetWidth(int w)
185 m_refData = new wxBitmapRefData;
187 M_BITMAPDATA->m_width = w;
190 void wxBitmap::SetHeight(int h)
193 m_refData = new wxBitmapRefData;
195 M_BITMAPDATA->m_height = h;
198 void wxBitmap::SetDepth(int d)
201 m_refData = new wxBitmapRefData;
203 M_BITMAPDATA->m_depth = d;
206 void wxBitmap::SetQuality(int q)
209 m_refData = new wxBitmapRefData;
211 M_BITMAPDATA->m_quality = q;
214 void wxBitmap::SetOk(bool isOk)
217 m_refData = new wxBitmapRefData;
219 M_BITMAPDATA->m_ok = isOk;
222 void wxBitmap::SetPalette(const wxPalette& palette)
225 m_refData = new wxBitmapRefData;
227 M_BITMAPDATA->m_bitmapPalette = palette ;
230 void wxBitmap::SetMask(wxMask *mask)
233 m_refData = new wxBitmapRefData;
235 M_BITMAPDATA->m_bitmapMask = mask ;
249 // Construct a mask from a bitmap and a colour indicating
250 // the transparent area
251 wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
256 Create(bitmap, colour);
259 // Construct a mask from a bitmap and a palette index indicating
260 // the transparent area
261 wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
267 Create(bitmap, paletteIndex);
270 // Construct a mask from a mono bitmap (copies the bitmap).
271 wxMask::wxMask(const wxBitmap& bitmap)
282 // TODO: delete mask bitmap
285 // Create a mask from a mono bitmap (copies the bitmap).
286 bool wxMask::Create(const wxBitmap& bitmap)
292 // Create a mask from a bitmap and a palette index indicating
293 // the transparent area
294 bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex)
300 // Create a mask from a bitmap and a colour indicating
301 // the transparent area
302 bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
312 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject)
314 wxBitmapHandler::~wxBitmapHandler()
318 bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
323 bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long type,
324 int desiredWidth, int desiredHeight)
329 bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
338 /* TODO: bitmap handlers, a bit like this:
339 class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
341 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
343 inline wxBMPResourceHandler()
345 m_name = "Windows bitmap resource";
347 m_type = wxBITMAP_TYPE_BMP_RESOURCE;
350 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
351 int desiredWidth, int desiredHeight);
353 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
356 void wxBitmap::InitStandardHandlers()
358 /* TODO: initialize all standard bitmap or derive class handlers here.
359 AddHandler(new wxBMPResourceHandler);
360 AddHandler(new wxBMPFileHandler);
361 AddHandler(new wxXPMFileHandler);
362 AddHandler(new wxXPMDataHandler);
363 AddHandler(new wxICOResourceHandler);
364 AddHandler(new wxICOFileHandler);
368 bool wxBitmap::CopyFromIcon(const wxIcon& icno)
373 wxPalette* wxBitmap::GetPalette() const
378 wxBitmap wxBitmap::GetSubBitmap(wxRect const&) const
383 wxImage wxBitmap::ConvertToImage() const
388 bool wxBitmap::Ok() const
393 wxMask* wxBitmap::GetMask() const
398 int wxBitmap::GetDepth() const
403 int wxBitmap::GetWidth() const
408 int wxBitmap::GetHeight() const
414 bool wxBitmap::CreateFromXpm(const char **)
419 // vim:sts=4:sw=4:syn=cpp:et