]>
git.saurik.com Git - wxWidgets.git/blob - src/stubs/bitmap.cpp
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"
23 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
24 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
26 wxBitmapRefData::wxBitmapRefData()
37 wxBitmapRefData::~wxBitmapRefData()
40 * TODO: delete the bitmap data here.
48 wxList
wxBitmap::sm_handlers
;
54 if ( wxTheBitmapList
)
55 wxTheBitmapList
->AddBitmap(this);
61 wxTheBitmapList
->DeleteObject(this);
64 wxBitmap::wxBitmap(const char bits
[], int the_width
, int the_height
, int no_bits
)
66 m_refData
= new wxBitmapRefData
;
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;
73 /* TODO: create the bitmap from data */
75 if ( wxTheBitmapList
)
76 wxTheBitmapList
->AddBitmap(this);
79 wxBitmap::wxBitmap(int w
, int h
, int d
)
81 (void)Create(w
, h
, d
);
83 if ( wxTheBitmapList
)
84 wxTheBitmapList
->AddBitmap(this);
87 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
89 (void) Create(data
, type
, width
, height
, depth
);
91 if ( wxTheBitmapList
)
92 wxTheBitmapList
->AddBitmap(this);
95 wxBitmap::wxBitmap(const wxString
& filename
, long type
)
97 LoadFile(filename
, (int)type
);
99 if ( wxTheBitmapList
)
100 wxTheBitmapList
->AddBitmap(this);
103 /* TODO: maybe allow creation from XPM
105 wxBitmap::wxBitmap(const char **data)
107 (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
111 bool wxBitmap::Create(int w
, int h
, int d
)
115 m_refData
= new wxBitmapRefData
;
117 M_BITMAPDATA
->m_width
= w
;
118 M_BITMAPDATA
->m_height
= h
;
119 M_BITMAPDATA
->m_depth
= d
;
121 /* TODO: create new bitmap */
123 return M_BITMAPDATA
->m_ok
;
126 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
130 m_refData
= new wxBitmapRefData
;
132 wxBitmapHandler
*handler
= FindHandler(type
);
134 if ( handler
== NULL
) {
135 wxLogWarning("no bitmap handler for type %d defined.", type
);
140 return handler
->LoadFile(this, filename
, type
, -1, -1);
143 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
147 m_refData
= new wxBitmapRefData
;
149 wxBitmapHandler
*handler
= FindHandler(type
);
151 if ( handler
== NULL
) {
152 wxLogWarning("no bitmap handler for type %d defined.", type
);
157 return handler
->Create(this, data
, type
, width
, height
, depth
);
160 bool wxBitmap::SaveFile(const wxString
& filename
, int type
, const wxPalette
*palette
)
162 wxBitmapHandler
*handler
= FindHandler(type
);
164 if ( handler
== NULL
) {
165 wxLogWarning("no bitmap handler for type %d defined.", type
);
170 return handler
->SaveFile(this, filename
, type
, palette
);
173 void wxBitmap::SetWidth(int w
)
176 m_refData
= new wxBitmapRefData
;
178 M_BITMAPDATA
->m_width
= w
;
181 void wxBitmap::SetHeight(int h
)
184 m_refData
= new wxBitmapRefData
;
186 M_BITMAPDATA
->m_height
= h
;
189 void wxBitmap::SetDepth(int d
)
192 m_refData
= new wxBitmapRefData
;
194 M_BITMAPDATA
->m_depth
= d
;
197 void wxBitmap::SetQuality(int q
)
200 m_refData
= new wxBitmapRefData
;
202 M_BITMAPDATA
->m_quality
= q
;
205 void wxBitmap::SetOk(bool isOk
)
208 m_refData
= new wxBitmapRefData
;
210 M_BITMAPDATA
->m_ok
= isOk
;
213 void wxBitmap::SetPalette(const wxPalette
& palette
)
216 m_refData
= new wxBitmapRefData
;
218 M_BITMAPDATA
->m_bitmapPalette
= palette
;
221 void wxBitmap::SetMask(wxMask
*mask
)
224 m_refData
= new wxBitmapRefData
;
226 M_BITMAPDATA
->m_bitmapMask
= mask
;
229 void wxBitmap::AddHandler(wxBitmapHandler
*handler
)
231 sm_handlers
.Append(handler
);
234 void wxBitmap::InsertHandler(wxBitmapHandler
*handler
)
236 sm_handlers
.Insert(handler
);
239 bool wxBitmap::RemoveHandler(const wxString
& name
)
241 wxBitmapHandler
*handler
= FindHandler(name
);
244 sm_handlers
.DeleteObject(handler
);
251 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& name
)
253 wxNode
*node
= sm_handlers
.First();
256 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
257 if ( handler
->GetName() == name
)
264 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& extension
, long bitmapType
)
266 wxNode
*node
= sm_handlers
.First();
269 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
270 if ( handler
->GetExtension() == extension
&&
271 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
278 wxBitmapHandler
*wxBitmap::FindHandler(long bitmapType
)
280 wxNode
*node
= sm_handlers
.First();
283 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
284 if (handler
->GetType() == bitmapType
)
302 // Construct a mask from a bitmap and a colour indicating
303 // the transparent area
304 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
309 Create(bitmap
, colour
);
312 // Construct a mask from a bitmap and a palette index indicating
313 // the transparent area
314 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
320 Create(bitmap
, paletteIndex
);
323 // Construct a mask from a mono bitmap (copies the bitmap).
324 wxMask::wxMask(const wxBitmap
& bitmap
)
335 // TODO: delete mask bitmap
338 // Create a mask from a mono bitmap (copies the bitmap).
339 bool wxMask::Create(const wxBitmap
& bitmap
)
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
)
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
)
365 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
367 bool wxBitmapHandler::Create(wxBitmap
*bitmap
, void *data
, long type
, int width
, int height
, int depth
)
372 bool wxBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long type
,
373 int desiredWidth
, int desiredHeight
)
378 bool wxBitmapHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
387 /* TODO: bitmap handlers, a bit like this:
388 class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
390 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
392 inline wxBMPResourceHandler()
394 m_name = "Windows bitmap resource";
396 m_type = wxBITMAP_TYPE_BMP_RESOURCE;
399 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
400 int desiredWidth, int desiredHeight);
402 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
405 void wxBitmap::CleanUpHandlers()
407 wxNode
*node
= sm_handlers
.First();
410 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
411 wxNode
*next
= node
->Next();
418 void wxBitmap::InitStandardHandlers()
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);