]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/bitmap.cpp
865b319997a2c4091c6862a8d70fa7abd83105b8
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
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()
38 m_pixmap
= (WXPixmap
) 0;
39 m_display
= (WXDisplay
*) 0;
42 wxBitmapRefData::~wxBitmapRefData()
45 * TODO: delete the bitmap data here.
53 wxList
wxBitmap::sm_handlers
;
59 if ( wxTheBitmapList
)
60 wxTheBitmapList
->AddBitmap(this);
66 wxTheBitmapList
->DeleteObject(this);
69 wxBitmap::wxBitmap(const char bits
[], int the_width
, int the_height
, int no_bits
)
71 m_refData
= new wxBitmapRefData
;
73 M_BITMAPDATA
->m_width
= the_width
;
74 M_BITMAPDATA
->m_height
= the_height
;
75 M_BITMAPDATA
->m_depth
= no_bits
;
76 M_BITMAPDATA
->m_numColors
= 0;
78 /* TODO: create the bitmap from data */
80 if ( wxTheBitmapList
)
81 wxTheBitmapList
->AddBitmap(this);
84 wxBitmap::wxBitmap(int w
, int h
, int d
)
86 (void)Create(w
, h
, d
);
88 if ( wxTheBitmapList
)
89 wxTheBitmapList
->AddBitmap(this);
92 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
94 (void) Create(data
, type
, width
, height
, depth
);
96 if ( wxTheBitmapList
)
97 wxTheBitmapList
->AddBitmap(this);
100 wxBitmap::wxBitmap(const wxString
& filename
, long type
)
102 LoadFile(filename
, (int)type
);
104 if ( wxTheBitmapList
)
105 wxTheBitmapList
->AddBitmap(this);
108 /* TODO: maybe allow creation from XPM
110 wxBitmap::wxBitmap(const char **data)
112 (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
116 bool wxBitmap::Create(int w
, int h
, int d
)
120 m_refData
= new wxBitmapRefData
;
122 M_BITMAPDATA
->m_width
= w
;
123 M_BITMAPDATA
->m_height
= h
;
124 M_BITMAPDATA
->m_depth
= d
;
126 /* TODO: create new bitmap */
128 return M_BITMAPDATA
->m_ok
;
131 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
135 m_refData
= new wxBitmapRefData
;
137 wxBitmapHandler
*handler
= FindHandler(type
);
139 if ( handler
== NULL
) {
140 wxLogWarning("no bitmap handler for type %d defined.", type
);
145 return handler
->LoadFile(this, filename
, type
, -1, -1);
148 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
152 m_refData
= new wxBitmapRefData
;
154 wxBitmapHandler
*handler
= FindHandler(type
);
156 if ( handler
== NULL
) {
157 wxLogWarning("no bitmap handler for type %d defined.", type
);
162 return handler
->Create(this, data
, type
, width
, height
, depth
);
165 bool wxBitmap::SaveFile(const wxString
& filename
, int type
, const wxPalette
*palette
)
167 wxBitmapHandler
*handler
= FindHandler(type
);
169 if ( handler
== NULL
) {
170 wxLogWarning("no bitmap handler for type %d defined.", type
);
175 return handler
->SaveFile(this, filename
, type
, palette
);
178 void wxBitmap::SetWidth(int w
)
181 m_refData
= new wxBitmapRefData
;
183 M_BITMAPDATA
->m_width
= w
;
186 void wxBitmap::SetHeight(int h
)
189 m_refData
= new wxBitmapRefData
;
191 M_BITMAPDATA
->m_height
= h
;
194 void wxBitmap::SetDepth(int d
)
197 m_refData
= new wxBitmapRefData
;
199 M_BITMAPDATA
->m_depth
= d
;
202 void wxBitmap::SetQuality(int q
)
205 m_refData
= new wxBitmapRefData
;
207 M_BITMAPDATA
->m_quality
= q
;
210 void wxBitmap::SetOk(bool isOk
)
213 m_refData
= new wxBitmapRefData
;
215 M_BITMAPDATA
->m_ok
= isOk
;
218 void wxBitmap::SetPalette(const wxPalette
& palette
)
221 m_refData
= new wxBitmapRefData
;
223 M_BITMAPDATA
->m_bitmapPalette
= palette
;
226 void wxBitmap::SetMask(wxMask
*mask
)
229 m_refData
= new wxBitmapRefData
;
231 M_BITMAPDATA
->m_bitmapMask
= mask
;
234 void wxBitmap::AddHandler(wxBitmapHandler
*handler
)
236 sm_handlers
.Append(handler
);
239 void wxBitmap::InsertHandler(wxBitmapHandler
*handler
)
241 sm_handlers
.Insert(handler
);
244 bool wxBitmap::RemoveHandler(const wxString
& name
)
246 wxBitmapHandler
*handler
= FindHandler(name
);
249 sm_handlers
.DeleteObject(handler
);
256 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& name
)
258 wxNode
*node
= sm_handlers
.First();
261 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
262 if ( handler
->GetName() == name
)
269 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& extension
, long bitmapType
)
271 wxNode
*node
= sm_handlers
.First();
274 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
275 if ( handler
->GetExtension() == extension
&&
276 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
283 wxBitmapHandler
*wxBitmap::FindHandler(long bitmapType
)
285 wxNode
*node
= sm_handlers
.First();
288 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
289 if (handler
->GetType() == bitmapType
)
302 m_pixmap
= (WXPixmap
) 0;
305 // Construct a mask from a bitmap and a colour indicating
306 // the transparent area
307 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
309 m_pixmap
= (WXPixmap
) 0;
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
)
318 m_pixmap
= (WXPixmap
) 0;
320 Create(bitmap
, paletteIndex
);
323 // Construct a mask from a mono bitmap (copies the bitmap).
324 wxMask::wxMask(const wxBitmap
& bitmap
)
326 m_pixmap
= (WXPixmap
) 0;
333 // TODO: delete mask bitmap
336 // Create a mask from a mono bitmap (copies the bitmap).
337 bool wxMask::Create(const wxBitmap
& bitmap
)
343 // Create a mask from a bitmap and a palette index indicating
344 // the transparent area
345 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
351 // Create a mask from a bitmap and a colour indicating
352 // the transparent area
353 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
363 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
365 bool wxBitmapHandler::Create(wxBitmap
*bitmap
, void *data
, long type
, int width
, int height
, int depth
)
370 bool wxBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long type
,
371 int desiredWidth
, int desiredHeight
)
376 bool wxBitmapHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
385 /* TODO: bitmap handlers, a bit like this:
386 class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
388 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
390 inline wxBMPResourceHandler()
392 m_name = "Windows bitmap resource";
394 m_type = wxBITMAP_TYPE_BMP_RESOURCE;
397 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
398 int desiredWidth, int desiredHeight);
400 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
403 void wxBitmap::CleanUpHandlers()
405 wxNode
*node
= sm_handlers
.First();
408 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
409 wxNode
*next
= node
->Next();
416 void wxBitmap::InitStandardHandlers()
418 /* TODO: initialize all standard bitmap or derive class handlers here.
419 AddHandler(new wxBMPResourceHandler);
420 AddHandler(new wxBMPFileHandler);
421 AddHandler(new wxXPMFileHandler);
422 AddHandler(new wxXPMDataHandler);
423 AddHandler(new wxICOResourceHandler);
424 AddHandler(new wxICOFileHandler);