]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/bitmap.mm
mingw compilation fix
[wxWidgets.git] / src / cocoa / bitmap.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.cpp
3 // Purpose: wxBitmap
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "bitmap.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/utils.h"
18 #include "wx/palette.h"
19 #include "wx/bitmap.h"
20 #include "wx/icon.h"
21 #include "wx/log.h"
22 #include "wx/image.h"
23
24 #if !USE_SHARED_LIBRARIES
25 IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
26 IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
27 #endif
28
29 wxBitmapRefData::wxBitmapRefData()
30 {
31 m_ok = FALSE;
32 m_width = 0;
33 m_height = 0;
34 m_depth = 0;
35 m_quality = 0;
36 m_numColors = 0;
37 m_bitmapMask = NULL;
38 }
39
40 wxBitmapRefData::~wxBitmapRefData()
41 {
42 /*
43 * TODO: delete the bitmap data here.
44 */
45
46 if (m_bitmapMask)
47 delete m_bitmapMask;
48 m_bitmapMask = NULL;
49 }
50
51 wxBitmap::wxBitmap()
52 {
53 m_refData = NULL;
54
55 if ( wxTheBitmapList )
56 wxTheBitmapList->AddBitmap(this);
57 }
58
59 wxBitmap::~wxBitmap()
60 {
61 if (wxTheBitmapList)
62 wxTheBitmapList->DeleteObject(this);
63 }
64
65 wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
66 {
67 m_refData = new wxBitmapRefData;
68
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;
73
74 /* TODO: create the bitmap from data */
75
76 if ( wxTheBitmapList )
77 wxTheBitmapList->AddBitmap(this);
78 }
79
80 wxBitmap::wxBitmap(int w, int h, int d)
81 {
82 (void)Create(w, h, d);
83
84 if ( wxTheBitmapList )
85 wxTheBitmapList->AddBitmap(this);
86 }
87
88 wxBitmap::wxBitmap(void *data, wxBitmapType type, int width, int height, int depth)
89 {
90 (void) Create(data, type, width, height, depth);
91
92 if ( wxTheBitmapList )
93 wxTheBitmapList->AddBitmap(this);
94 }
95
96 wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
97 {
98 LoadFile(filename, type);
99
100 if ( wxTheBitmapList )
101 wxTheBitmapList->AddBitmap(this);
102 }
103
104 wxBitmap::wxBitmap(const wxImage& image, int depth)
105 {
106 }
107
108 wxBitmap::wxBitmap(char **bits)
109 {
110 }
111
112 /* TODO: maybe allow creation from XPM
113 // Create from data
114 wxBitmap::wxBitmap(const char **data)
115 {
116 (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
117 }
118 */
119
120 bool wxBitmap::Create(int w, int h, int d)
121 {
122 UnRef();
123
124 m_refData = new wxBitmapRefData;
125
126 M_BITMAPDATA->m_width = w;
127 M_BITMAPDATA->m_height = h;
128 M_BITMAPDATA->m_depth = d;
129
130 /* TODO: create new bitmap */
131
132 return M_BITMAPDATA->m_ok;
133 }
134
135 bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
136 {
137 UnRef();
138
139 m_refData = new wxBitmapRefData;
140
141 wxBitmapHandler *handler = FindHandler(type);
142
143 if ( handler == NULL ) {
144 wxLogWarning("no bitmap handler for type %d defined.", type);
145
146 return FALSE;
147 }
148
149 return handler->LoadFile(this, filename, type, -1, -1);
150 }
151
152 bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
153 {
154 UnRef();
155
156 m_refData = new wxBitmapRefData;
157
158 wxBitmapHandler *handler = FindHandler(type);
159
160 if ( handler == NULL ) {
161 wxLogWarning("no bitmap handler for type %d defined.", type);
162
163 return FALSE;
164 }
165
166 return handler->Create(this, data, type, width, height, depth);
167 }
168
169 bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
170 {
171 wxBitmapHandler *handler = FindHandler(type);
172
173 if ( handler == NULL ) {
174 wxLogWarning("no bitmap handler for type %d defined.", type);
175
176 return FALSE;
177 }
178
179 return handler->SaveFile(this, filename, type, palette);
180 }
181
182 void wxBitmap::SetWidth(int w)
183 {
184 if (!M_BITMAPDATA)
185 m_refData = new wxBitmapRefData;
186
187 M_BITMAPDATA->m_width = w;
188 }
189
190 void wxBitmap::SetHeight(int h)
191 {
192 if (!M_BITMAPDATA)
193 m_refData = new wxBitmapRefData;
194
195 M_BITMAPDATA->m_height = h;
196 }
197
198 void wxBitmap::SetDepth(int d)
199 {
200 if (!M_BITMAPDATA)
201 m_refData = new wxBitmapRefData;
202
203 M_BITMAPDATA->m_depth = d;
204 }
205
206 void wxBitmap::SetQuality(int q)
207 {
208 if (!M_BITMAPDATA)
209 m_refData = new wxBitmapRefData;
210
211 M_BITMAPDATA->m_quality = q;
212 }
213
214 void wxBitmap::SetOk(bool isOk)
215 {
216 if (!M_BITMAPDATA)
217 m_refData = new wxBitmapRefData;
218
219 M_BITMAPDATA->m_ok = isOk;
220 }
221
222 void wxBitmap::SetPalette(const wxPalette& palette)
223 {
224 if (!M_BITMAPDATA)
225 m_refData = new wxBitmapRefData;
226
227 M_BITMAPDATA->m_bitmapPalette = palette ;
228 }
229
230 void wxBitmap::SetMask(wxMask *mask)
231 {
232 if (!M_BITMAPDATA)
233 m_refData = new wxBitmapRefData;
234
235 M_BITMAPDATA->m_bitmapMask = mask ;
236 }
237
238 /*
239 * wxMask
240 */
241
242 wxMask::wxMask()
243 {
244 /* TODO
245 m_maskBitmap = 0;
246 */
247 }
248
249 // Construct a mask from a bitmap and a colour indicating
250 // the transparent area
251 wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
252 {
253 /* TODO
254 m_maskBitmap = 0;
255 */
256 Create(bitmap, colour);
257 }
258
259 // Construct a mask from a bitmap and a palette index indicating
260 // the transparent area
261 wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
262 {
263 /* TODO
264 m_maskBitmap = 0;
265 */
266
267 Create(bitmap, paletteIndex);
268 }
269
270 // Construct a mask from a mono bitmap (copies the bitmap).
271 wxMask::wxMask(const wxBitmap& bitmap)
272 {
273 /* TODO
274 m_maskBitmap = 0;
275 */
276
277 Create(bitmap);
278 }
279
280 wxMask::~wxMask()
281 {
282 // TODO: delete mask bitmap
283 }
284
285 // Create a mask from a mono bitmap (copies the bitmap).
286 bool wxMask::Create(const wxBitmap& bitmap)
287 {
288 // TODO
289 return FALSE;
290 }
291
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)
295 {
296 // TODO
297 return FALSE;
298 }
299
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)
303 {
304 // TODO
305 return FALSE;
306 }
307
308 /*
309 * wxBitmapHandler
310 */
311
312 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject)
313
314 wxBitmapHandler::~wxBitmapHandler()
315 {
316 }
317
318 bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
319 {
320 return FALSE;
321 }
322
323 bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long type,
324 int desiredWidth, int desiredHeight)
325 {
326 return FALSE;
327 }
328
329 bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
330 {
331 return FALSE;
332 }
333
334 /*
335 * Standard handlers
336 */
337
338 /* TODO: bitmap handlers, a bit like this:
339 class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
340 {
341 DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
342 public:
343 inline wxBMPResourceHandler()
344 {
345 m_name = "Windows bitmap resource";
346 m_extension = "";
347 m_type = wxBITMAP_TYPE_BMP_RESOURCE;
348 };
349
350 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
351 int desiredWidth, int desiredHeight);
352 };
353 IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
354 */
355
356 void wxBitmap::InitStandardHandlers()
357 {
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);
365 */
366 }
367
368 bool wxBitmap::CopyFromIcon(const wxIcon& icno)
369 {
370 return false;
371 }
372
373 wxPalette* wxBitmap::GetPalette() const
374 {
375 return NULL;
376 }
377
378 wxBitmap wxBitmap::GetSubBitmap(wxRect const&) const
379 {
380 return wxNullBitmap;
381 }
382
383 wxImage wxBitmap::ConvertToImage() const
384 {
385 return wxNullImage;
386 }
387
388 bool wxBitmap::Ok() const
389 {
390 return FALSE;
391 }
392
393 wxMask* wxBitmap::GetMask() const
394 {
395 return NULL;
396 }
397
398 int wxBitmap::GetDepth() const
399 {
400 return 0;
401 }
402
403 int wxBitmap::GetWidth() const
404 {
405 return 0;
406 }
407
408 int wxBitmap::GetHeight() const
409 {
410 return 0;
411 }
412
413
414 bool wxBitmap::CreateFromXpm(const char **)
415 {
416 return false;
417 }
418
419 // vim:sts=4:sw=4:syn=cpp:et