]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/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 #if !USE_SHARED_LIBRARIES
24 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
25 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
28 wxBitmapRefData::wxBitmapRefData()
39 wxBitmapRefData::~wxBitmapRefData()
42 * TODO: delete the bitmap data here.
50 wxList
wxBitmap::sm_handlers
;
56 if ( wxTheBitmapList
)
57 wxTheBitmapList
->AddBitmap(this);
63 wxTheBitmapList
->DeleteObject(this);
66 wxBitmap::wxBitmap(const char bits
[], int the_width
, int the_height
, int no_bits
)
68 m_refData
= new wxBitmapRefData
;
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;
75 /* TODO: create the bitmap from data */
77 if ( wxTheBitmapList
)
78 wxTheBitmapList
->AddBitmap(this);
81 wxBitmap::wxBitmap(int w
, int h
, int d
)
83 (void)Create(w
, h
, d
);
85 if ( wxTheBitmapList
)
86 wxTheBitmapList
->AddBitmap(this);
89 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
91 (void) Create(data
, type
, width
, height
, depth
);
93 if ( wxTheBitmapList
)
94 wxTheBitmapList
->AddBitmap(this);
97 wxBitmap::wxBitmap(const wxString
& filename
, long type
)
99 LoadFile(filename
, (int)type
);
101 if ( wxTheBitmapList
)
102 wxTheBitmapList
->AddBitmap(this);
105 /* TODO: maybe allow creation from XPM
107 wxBitmap::wxBitmap(const char **data)
109 (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
113 bool wxBitmap::Create(int w
, int h
, int d
)
117 m_refData
= new wxBitmapRefData
;
119 M_BITMAPDATA
->m_width
= w
;
120 M_BITMAPDATA
->m_height
= h
;
121 M_BITMAPDATA
->m_depth
= d
;
123 /* TODO: create new bitmap */
125 return M_BITMAPDATA
->m_ok
;
128 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
132 m_refData
= new wxBitmapRefData
;
134 wxBitmapHandler
*handler
= FindHandler(type
);
136 if ( handler
== NULL
) {
137 wxLogWarning("no bitmap handler for type %d defined.", type
);
142 return handler
->LoadFile(this, filename
, type
, -1, -1);
145 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
149 m_refData
= new wxBitmapRefData
;
151 wxBitmapHandler
*handler
= FindHandler(type
);
153 if ( handler
== NULL
) {
154 wxLogWarning("no bitmap handler for type %d defined.", type
);
159 return handler
->Create(this, data
, type
, width
, height
, depth
);
162 bool wxBitmap::SaveFile(const wxString
& filename
, int type
, const wxPalette
*palette
)
164 wxBitmapHandler
*handler
= FindHandler(type
);
166 if ( handler
== NULL
) {
167 wxLogWarning("no bitmap handler for type %d defined.", type
);
172 return handler
->SaveFile(this, filename
, type
, palette
);
175 void wxBitmap::SetWidth(int w
)
178 m_refData
= new wxBitmapRefData
;
180 M_BITMAPDATA
->m_width
= w
;
183 void wxBitmap::SetHeight(int h
)
186 m_refData
= new wxBitmapRefData
;
188 M_BITMAPDATA
->m_height
= h
;
191 void wxBitmap::SetDepth(int d
)
194 m_refData
= new wxBitmapRefData
;
196 M_BITMAPDATA
->m_depth
= d
;
199 void wxBitmap::SetQuality(int q
)
202 m_refData
= new wxBitmapRefData
;
204 M_BITMAPDATA
->m_quality
= q
;
207 void wxBitmap::SetOk(bool isOk
)
210 m_refData
= new wxBitmapRefData
;
212 M_BITMAPDATA
->m_ok
= isOk
;
215 void wxBitmap::SetPalette(const wxPalette
& palette
)
218 m_refData
= new wxBitmapRefData
;
220 M_BITMAPDATA
->m_bitmapPalette
= palette
;
223 void wxBitmap::SetMask(wxMask
*mask
)
226 m_refData
= new wxBitmapRefData
;
228 M_BITMAPDATA
->m_bitmapMask
= mask
;
231 void wxBitmap::AddHandler(wxBitmapHandler
*handler
)
233 sm_handlers
.Append(handler
);
236 void wxBitmap::InsertHandler(wxBitmapHandler
*handler
)
238 sm_handlers
.Insert(handler
);
241 bool wxBitmap::RemoveHandler(const wxString
& name
)
243 wxBitmapHandler
*handler
= FindHandler(name
);
246 sm_handlers
.DeleteObject(handler
);
253 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& name
)
255 wxNode
*node
= sm_handlers
.First();
258 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
259 if ( handler
->GetName() == name
)
266 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& extension
, long bitmapType
)
268 wxNode
*node
= sm_handlers
.First();
271 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
272 if ( handler
->GetExtension() == extension
&&
273 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
280 wxBitmapHandler
*wxBitmap::FindHandler(long bitmapType
)
282 wxNode
*node
= sm_handlers
.First();
285 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
286 if (handler
->GetType() == bitmapType
)
304 // Construct a mask from a bitmap and a colour indicating
305 // the transparent area
306 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
311 Create(bitmap
, colour
);
314 // Construct a mask from a bitmap and a palette index indicating
315 // the transparent area
316 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
322 Create(bitmap
, paletteIndex
);
325 // Construct a mask from a mono bitmap (copies the bitmap).
326 wxMask::wxMask(const wxBitmap
& bitmap
)
337 // TODO: delete mask bitmap
340 // Create a mask from a mono bitmap (copies the bitmap).
341 bool wxMask::Create(const wxBitmap
& bitmap
)
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
)
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
)
367 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
369 bool wxBitmapHandler::Create(wxBitmap
*bitmap
, void *data
, long type
, int width
, int height
, int depth
)
374 bool wxBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long type
,
375 int desiredWidth
, int desiredHeight
)
380 bool wxBitmapHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
389 /* TODO: bitmap handlers, a bit like this:
390 class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
392 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
394 inline wxBMPResourceHandler()
396 m_name = "Windows bitmap resource";
398 m_type = wxBITMAP_TYPE_BMP_RESOURCE;
401 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
402 int desiredWidth, int desiredHeight);
404 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
407 void wxBitmap::CleanUpHandlers()
409 wxNode
*node
= sm_handlers
.First();
412 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
413 wxNode
*next
= node
->Next();
420 void wxBitmap::InitStandardHandlers()
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);