]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/bitmap.cpp
Made wxFileDialog PDA friendlier.
[wxWidgets.git] / src / mac / carbon / bitmap.cpp
CommitLineData
e9576ca5
SC
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
b698c8e9
GD
16#include "wx/defs.h"
17
e9576ca5
SC
18#include "wx/bitmap.h"
19#include "wx/icon.h"
20#include "wx/log.h"
fec19ea9 21#include "wx/image.h"
973b0afb 22#include "wx/xpmdecod.h"
e9576ca5 23
e9576ca5
SC
24IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
25IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
bb356c9e 26IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject )
e9576ca5 27
f5c6eb5c 28#ifdef __DARWIN__
5fde6fcc 29 #include <ApplicationServices/ApplicationServices.h>
03e11df5
GD
30#else
31 #include <PictUtils.h>
32#endif
519cb848 33
31d30995
SC
34#include "wx/mac/uma.h"
35
519cb848
SC
36CTabHandle wxMacCreateColorTable( int numColors )
37{
4e9ed364
RR
38 CTabHandle newColors; /* Handle to the new color table */
39
40 /* Allocate memory for the color table */
41 newColors = (CTabHandle)NewHandleClear( sizeof (ColorTable) +
42 sizeof (ColorSpec) * (numColors - 1) );
43 if (newColors != nil)
44 {
45 /* Initialize the fields */
46 (**newColors).ctSeed = GetCTSeed();
47 (**newColors).ctFlags = 0;
48 (**newColors).ctSize = numColors - 1;
49 /* Initialize the table of colors */
50 }
51 return newColors ;
519cb848
SC
52}
53
54void wxMacDestroyColorTable( CTabHandle colors )
55{
4e9ed364 56 DisposeHandle( (Handle) colors ) ;
519cb848
SC
57}
58
59void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue )
60{
4e9ed364
RR
61 (**newColors).ctTable[index].value = index;
62 (**newColors).ctTable[index].rgb.red = 0 ;// someRedValue;
63 (**newColors).ctTable[index].rgb.green = 0 ; // someGreenValue;
64 (**newColors).ctTable[index].rgb.blue = 0 ; // someBlueValue;
519cb848
SC
65}
66
03e11df5 67GWorldPtr wxMacCreateGWorld( int width , int height , int depth )
519cb848 68{
4e9ed364
RR
69 OSErr err = noErr ;
70 GWorldPtr port ;
71 Rect rect = { 0 , 0 , height , width } ;
72
73 if ( depth < 0 )
74 {
75 depth = wxDisplayDepth() ;
76 }
77
78 err = NewGWorld( &port , depth , &rect , NULL , NULL , 0 ) ;
79 if ( err == noErr )
80 {
81 return port ;
82 }
83 return NULL ;
03e11df5 84}
519cb848
SC
85
86void wxMacDestroyGWorld( GWorldPtr gw )
87{
4e9ed364
RR
88 if ( gw )
89 DisposeGWorld( gw ) ;
519cb848
SC
90}
91
72055702
SC
92#define kDefaultRes 0x00480000 /* Default resolution is 72 DPI; Fixed type */
93
94OSErr SetupCIconHandlePixMap( CIconHandle icon , short depth , Rect *bounds , CTabHandle colors )
5fde6fcc 95{
4e9ed364
RR
96 CTabHandle newColors; /* Color table used for the off-screen PixMap */
97 Ptr offBaseAddr; /* Pointer to the off-screen pixel image */
98 OSErr error; /* Returns error code */
99 short bytesPerRow; /* Number of bytes per row in the PixMap */
72055702
SC
100
101
102 error = noErr;
103 newColors = nil;
104 offBaseAddr = nil;
105
4e9ed364 106 bytesPerRow = ((depth * (bounds->right - bounds->left) + 31) / 32) * 4;
72055702
SC
107
108 /* Clone the clut if indexed color; allocate a dummy clut if direct color*/
109 if (depth <= 8)
110 {
111 newColors = colors;
112 error = HandToHand((Handle *) &newColors);
113 }
114 else
115 {
116 newColors = (CTabHandle) NewHandle(sizeof(ColorTable) -
117 sizeof(CSpecArray));
118 error = MemError();
119 }
120 if (error == noErr)
121 {
122 /* Allocate pixel image; long integer multiplication avoids overflow */
123 (**icon).iconData = NewHandle((unsigned long) bytesPerRow * (bounds->bottom -
124 bounds->top));
125 if ((**icon).iconData != nil)
5fde6fcc 126 {
72055702
SC
127 /* Initialize fields common to indexed and direct PixMaps */
128 (**icon).iconPMap.baseAddr = 0; /* Point to image */
129 (**icon).iconPMap.rowBytes = bytesPerRow | /* MSB set for PixMap */
130 0x8000;
131 (**icon).iconPMap.bounds = *bounds; /* Use given bounds */
132 (**icon).iconPMap.pmVersion = 0; /* No special stuff */
133 (**icon).iconPMap.packType = 0; /* Default PICT pack */
134 (**icon).iconPMap.packSize = 0; /* Always zero in mem */
135 (**icon).iconPMap.hRes = kDefaultRes; /* 72 DPI default res */
136 (**icon).iconPMap.vRes = kDefaultRes; /* 72 DPI default res */
137 (**icon).iconPMap.pixelSize = depth; /* Set # bits/pixel */
5fde6fcc 138
72055702
SC
139 /* Initialize fields specific to indexed and direct PixMaps */
140 if (depth <= 8)
141 {
142 /* PixMap is indexed */
143 (**icon).iconPMap.pixelType = 0; /* Indicates indexed */
144 (**icon).iconPMap.cmpCount = 1; /* Have 1 component */
145 (**icon).iconPMap.cmpSize = depth; /* Component size=depth */
146 (**icon).iconPMap.pmTable = newColors; /* Handle to CLUT */
147 }
148 else
149 {
150 /* PixMap is direct */
151 (**icon).iconPMap.pixelType = RGBDirect; /* Indicates direct */
152 (**icon).iconPMap.cmpCount = 3; /* Have 3 components */
153 if (depth == 16)
154 (**icon).iconPMap.cmpSize = 5; /* 5 bits/component */
155 else
156 (**icon).iconPMap.cmpSize = 8; /* 8 bits/component */
157 (**newColors).ctSeed = 3 * (**icon).iconPMap.cmpSize;
158 (**newColors).ctFlags = 0;
159 (**newColors).ctSize = 0;
160 (**icon).iconPMap.pmTable = newColors;
161 }
5fde6fcc 162 }
72055702
SC
163 else
164 error = MemError();
165 }
166 else
167 newColors = nil;
168
169 /* If no errors occured, return a handle to the new off-screen PixMap */
170 if (error != noErr)
171 {
172 if (newColors != nil)
173 DisposeCTable(newColors);
174 }
175
176 /* Return the error code */
177 return error;
178}
179
180CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize )
181{
4e9ed364
RR
182 GWorldPtr saveWorld;
183 GDHandle saveHandle;
72055702 184
4e9ed364
RR
185 GetGWorld(&saveWorld,&saveHandle); // save Graphics env state
186 SetGWorld(image,nil);
72055702
SC
187
188 Rect frame = { 0 , 0 , iconSize , iconSize } ;
189 Rect imageBounds = frame ;
4e9ed364 190 GetPortBounds( image , &imageBounds ) ;
72055702
SC
191
192 int bwSize = iconSize / 8 * iconSize ;
193 CIconHandle icon = (CIconHandle) NewHandleClear( sizeof ( CIcon ) + 2 * bwSize) ;
194 HLock((Handle)icon) ;
195 SetupCIconHandlePixMap( icon , dstDepth , &frame,GetCTable(dstDepth)) ;
196 HLock( (**icon).iconData ) ;
197 (**icon).iconPMap.baseAddr = *(**icon).iconData ;
198
4e9ed364
RR
199 LockPixels(GetGWorldPixMap(image));
200
201 CopyBits(GetPortBitMapForCopyBits(image),
202 (BitMapPtr)&((**icon).iconPMap),
203 &imageBounds,
204 &imageBounds,
205 srcCopy | ditherCopy, nil);
72055702
SC
206
207
4e9ed364 208 UnlockPixels(GetGWorldPixMap(image));
72055702
SC
209 HUnlock( (**icon).iconData ) ;
210
211 (**icon).iconMask.rowBytes = iconSize / 8 ;
212 (**icon).iconMask.bounds = frame ;
213
214 (**icon).iconBMap.rowBytes = iconSize / 8 ;
215 (**icon).iconBMap.bounds = frame ;
216 (**icon).iconMask.baseAddr = (char*) &(**icon).iconMaskData ;
217 (**icon).iconBMap.baseAddr = (char*) &(**icon).iconMaskData + bwSize ;
218
219 if ( mask )
220 {
221 LockPixels(GetGWorldPixMap(mask) ) ;
222 CopyBits(GetPortBitMapForCopyBits(mask) ,
223 &(**icon).iconBMap , &imageBounds , &imageBounds, srcCopy , nil ) ;
224 CopyBits(GetPortBitMapForCopyBits(mask) ,
225 &(**icon).iconMask , &imageBounds , &imageBounds, srcCopy , nil ) ;
226 UnlockPixels(GetGWorldPixMap( mask ) ) ;
227 }
228 else
229 {
4e9ed364 230 LockPixels(GetGWorldPixMap(image));
72055702
SC
231 CopyBits(GetPortBitMapForCopyBits(image) ,
232 &(**icon).iconBMap , &imageBounds , &imageBounds, srcCopy , nil ) ;
233 CopyBits(GetPortBitMapForCopyBits(image) ,
234 &(**icon).iconMask , &imageBounds , &imageBounds, srcCopy , nil ) ;
4e9ed364 235 UnlockPixels(GetGWorldPixMap(image));
72055702
SC
236 }
237
238 (**icon).iconMask.baseAddr = NULL ;
239 (**icon).iconBMap.baseAddr = NULL ;
240 (**icon).iconPMap.baseAddr = NULL ;
241 HUnlock((Handle)icon) ;
4e9ed364
RR
242 SetGWorld(saveWorld,saveHandle);
243
244 return icon;
72055702
SC
245}
246
247PicHandle wxMacCreatePict(GWorldPtr wp, GWorldPtr mask)
248{
249 CGrafPtr origPort ;
250 GDHandle origDev ;
251
252 PicHandle pict;
253
254 RGBColor white = { 0xffff ,0xffff , 0xffff } ;
255 RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ;
256
257 GetGWorld( &origPort , &origDev ) ;
258
259 RgnHandle clipRgn = NULL ;
260
261 if ( mask )
262 {
263 clipRgn = NewRgn() ;
264 LockPixels( GetGWorldPixMap( mask ) ) ;
265 BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( mask ) ) ;
266 UnlockPixels( GetGWorldPixMap( mask ) ) ;
267 }
4e9ed364 268
72055702
SC
269 SetGWorld( wp , NULL ) ;
270 Rect portRect ;
271 GetPortBounds( wp , &portRect ) ;
272
273 pict = OpenPicture(&portRect);
4e9ed364 274 if(pict)
72055702
SC
275 {
276 RGBForeColor( &black ) ;
277 RGBBackColor( &white ) ;
278
279 LockPixels( GetGWorldPixMap( wp ) ) ;
4e9ed364
RR
280 CopyBits(GetPortBitMapForCopyBits(wp),
281 GetPortBitMapForCopyBits(wp),
282 &portRect,
283 &portRect,
284 srcCopy,clipRgn);
72055702 285 UnlockPixels( GetGWorldPixMap( wp ) ) ;
4e9ed364 286 ClosePicture();
72055702
SC
287 }
288 SetGWorld( origPort , origDev ) ;
4e9ed364 289 return pict;
5fde6fcc
GD
290}
291
be295828
SC
292void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap )
293{
294 memset( info , 0 , sizeof(ControlButtonContentInfo) ) ;
295 if ( bitmap.Ok() )
296 {
297 wxBitmapRefData * bmap = (wxBitmapRefData*) ( bitmap.GetRefData()) ;
298 if ( bmap == NULL )
299 return ;
300
301 if ( bmap->m_bitmapType == kMacBitmapTypePict )
302 {
303 info->contentType = kControlContentPictHandle ;
304 info->u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
305 }
306 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
307 {
308 if ( (bmap->m_width == bmap->m_height) && (bmap->m_width & 0x3 == 0) )
309 {
310 info->contentType = kControlContentCIconHandle ;
311 if ( bitmap.GetMask() )
312 {
313 info->u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(bitmap.GetMask()->GetMaskBitmap()) ,
314 8 , bmap->m_width ) ;
315 }
316 else
317 {
318 info->u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
319 8 , bmap->m_width ) ;
320 }
321 }
322 else
323 {
324 info->contentType = kControlContentPictHandle ;
325 if ( bitmap.GetMask() )
326 {
327 info->u.picture = wxMacCreatePict( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(bitmap.GetMask()->GetMaskBitmap() ) ) ;
328 }
329 else
330 {
331 info->u.picture = wxMacCreatePict( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ) ;
332 }
333 }
334 }
335 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
336 {
337 info->contentType = kControlContentCIconHandle ;
338 info->u.cIconHandle = MAC_WXHICON(bmap->m_hIcon) ;
339 }
340 }
341}
342
e9576ca5
SC
343wxBitmapRefData::wxBitmapRefData()
344{
345 m_ok = FALSE;
346 m_width = 0;
347 m_height = 0;
348 m_depth = 0;
349 m_quality = 0;
350 m_numColors = 0;
351 m_bitmapMask = NULL;
973b0afb
GD
352 m_hBitmap = NULL ;
353 m_hPict = NULL ;
3dec57ad 354 m_hIcon = NULL ;
973b0afb 355 m_bitmapType = kMacBitmapTypeUnknownType ;
e9576ca5
SC
356}
357
85f296a3
SC
358// TODO move this do a public function of Bitmap Ref
359static void DisposeBitmapRefData(wxBitmapRefData *data)
e9576ca5 360{
4e9ed364
RR
361 switch (data->m_bitmapType)
362 {
363 case kMacBitmapTypePict :
364 {
365 if ( data->m_hPict )
366 {
76a5e5d2 367 KillPicture( MAC_WXHMETAFILE( data->m_hPict ) ) ;
4e9ed364
RR
368 data->m_hPict = NULL ;
369 }
370 }
371 break ;
372 case kMacBitmapTypeGrafWorld :
373 {
374 if ( data->m_hBitmap )
375 {
76a5e5d2 376 wxMacDestroyGWorld( MAC_WXHBITMAP(data->m_hBitmap) ) ;
4e9ed364
RR
377 data->m_hBitmap = NULL ;
378 }
379 }
380 break ;
381 case kMacBitmapTypeIcon :
382 if ( data->m_hIcon )
383 {
76a5e5d2 384 DisposeCIcon( MAC_WXHICON(data->m_hIcon) ) ;
4e9ed364
RR
385 data->m_hIcon = NULL ;
386 }
387
388 default :
389 // unkown type ?
390 break ;
391 }
392
85f296a3 393 if (data->m_bitmapMask)
519cb848 394 {
85f296a3
SC
395 delete data->m_bitmapMask;
396 data->m_bitmapMask = NULL;
519cb848 397 }
e9576ca5
SC
398}
399
85f296a3
SC
400wxBitmapRefData::~wxBitmapRefData()
401{
402 DisposeBitmapRefData( this ) ;
403}
404
90b959ae
SC
405bool wxBitmap::CopyFromIcon(const wxIcon& icon)
406{
407 Ref(icon) ;
125c389e 408 return true;
90b959ae
SC
409}
410
e9576ca5
SC
411wxBitmap::wxBitmap()
412{
413 m_refData = NULL;
e9576ca5
SC
414}
415
416wxBitmap::~wxBitmap()
417{
e9576ca5
SC
418}
419
420wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
421{
422 m_refData = new wxBitmapRefData;
423
424 M_BITMAPDATA->m_width = the_width ;
425 M_BITMAPDATA->m_height = the_height ;
426 M_BITMAPDATA->m_depth = no_bits ;
427 M_BITMAPDATA->m_numColors = 0;
d2c6d549
GD
428 if ( no_bits == 1 )
429 {
973b0afb 430 M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
76a5e5d2
SC
431 MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
432 M_BITMAPDATA->m_ok = (MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) != NULL ) ;
4e9ed364
RR
433
434 CGrafPtr origPort ;
435 GDHandle origDevice ;
436
973b0afb 437 GetGWorld( &origPort , &origDevice ) ;
76a5e5d2
SC
438 SetGWorld( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) , NULL ) ;
439 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) ) ) ;
4e9ed364 440
973b0afb 441 // bits is a char array
4e9ed364 442
973b0afb
GD
443 unsigned char* linestart = (unsigned char*) bits ;
444 int linesize = ( the_width / (sizeof(unsigned char) * 8)) ;
445 if ( the_width % (sizeof(unsigned char) * 8) ) {
446 linesize += sizeof(unsigned char);
447 }
4e9ed364 448
973b0afb
GD
449 RGBColor colors[2] = {
450 { 0xFFFF , 0xFFFF , 0xFFFF } ,
451 { 0, 0 , 0 }
452 } ;
4e9ed364 453
973b0afb
GD
454 for ( int y = 0 ; y < the_height ; ++y , linestart += linesize )
455 {
456 for ( int x = 0 ; x < the_width ; ++x )
457 {
458 int index = x / 8 ;
459 int bit = x % 8 ;
460 int mask = 1 << bit ;
461 if ( linestart[index] & mask )
462 {
463 SetCPixel( x , y , &colors[1] ) ;
464 }
465 else
466 {
467 SetCPixel( x , y , &colors[0] ) ;
468 }
469 }
470 }
76a5e5d2 471 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) ) ) ;
4e9ed364 472
973b0afb 473 SetGWorld( origPort , origDevice ) ;
d2c6d549
GD
474 }
475 else
476 {
973b0afb 477 wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
d2c6d549 478 }
e9576ca5
SC
479}
480
481wxBitmap::wxBitmap(int w, int h, int d)
482{
483 (void)Create(w, h, d);
e9576ca5
SC
484}
485
a8562f55 486wxBitmap::wxBitmap(void *data, wxBitmapType type, int width, int height, int depth)
e9576ca5
SC
487{
488 (void) Create(data, type, width, height, depth);
e9576ca5
SC
489}
490
a8562f55 491wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
e9576ca5 492{
a8562f55 493 LoadFile(filename, type);
e9576ca5
SC
494}
495
973b0afb 496bool wxBitmap::CreateFromXpm(const char **bits)
e9576ca5 497{
973b0afb
GD
498 wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )
499 wxXPMDecoder decoder;
500 wxImage img = decoder.ReadData(bits);
501 wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") )
502 *this = wxBitmap(img);
973b0afb
GD
503 return TRUE;
504}
505
506wxBitmap::wxBitmap(const char **bits)
507{
973b0afb 508 (void) CreateFromXpm(bits);
e9576ca5 509}
e9576ca5 510
973b0afb 511wxBitmap::wxBitmap(char **bits)
03e11df5 512{
973b0afb 513 (void) CreateFromXpm((const char **)bits);
03e11df5
GD
514}
515
5fde6fcc
GD
516wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
517{
518 wxCHECK_MSG( Ok() &&
519 (rect.x >= 0) && (rect.y >= 0) &&
520 (rect.x+rect.width <= GetWidth()) &&
521 (rect.y+rect.height <= GetHeight()),
522 wxNullBitmap, wxT("invalid bitmap or bitmap region") );
523
524
525 wxBitmap ret( rect.width, rect.height, GetDepth() );
526 wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
527
76a5e5d2 528 GWorldPtr origPort;
5fde6fcc
GD
529 GDHandle origDevice;
530
531 GetGWorld( &origPort, &origDevice );
532
533 // Update the subbitmaps reference data
534 wxBitmapRefData *ref = (wxBitmapRefData *)ret.GetRefData();
535
536 ref->m_numColors = M_BITMAPDATA->m_numColors;
537 ref->m_bitmapPalette = M_BITMAPDATA->m_bitmapPalette;
538 ref->m_bitmapType = M_BITMAPDATA->m_bitmapType;
539
540 // Copy sub region of this bitmap
541 if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypePict)
542 {
543 printf("GetSubBitmap: Copy a region of a Pict structure - TODO\n");
544 }
545 else if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypeGrafWorld)
546 {
547 // Copy mask
548 if(GetMask())
549 {
76a5e5d2 550 GWorldPtr submask, mask;
5fde6fcc
GD
551 RGBColor color;
552
76a5e5d2 553 mask = (GWorldPtr) GetMask()->GetMaskBitmap();
5fde6fcc
GD
554 submask = wxMacCreateGWorld(rect.width, rect.height, 1);
555 LockPixels(GetGWorldPixMap(mask));
556 LockPixels(GetGWorldPixMap(submask));
557
558 for(int yy = 0; yy < rect.height; yy++)
559 {
560 for(int xx = 0; xx < rect.width; xx++)
561 {
562 SetGWorld(mask, NULL);
563 GetCPixel(rect.x + xx, rect.y + yy, &color);
564 SetGWorld(submask, NULL);
565 SetCPixel(xx,yy, &color);
566 }
567 }
568 UnlockPixels(GetGWorldPixMap(mask));
569 UnlockPixels(GetGWorldPixMap(submask));
570 ref->m_bitmapMask = new wxMask;
571 ref->m_bitmapMask->SetMaskBitmap(submask);
572 }
573
574 // Copy bitmap
575 if(GetHBITMAP())
576 {
76a5e5d2 577 GWorldPtr subbitmap, bitmap;
5fde6fcc
GD
578 RGBColor color;
579
76a5e5d2
SC
580 bitmap = (GWorldPtr) GetHBITMAP();
581 subbitmap = (GWorldPtr) ref->m_hBitmap ;
5fde6fcc
GD
582 LockPixels(GetGWorldPixMap(bitmap));
583 LockPixels(GetGWorldPixMap(subbitmap));
584
585 for(int yy = 0; yy < rect.height; yy++)
586 {
587 for(int xx = 0; xx < rect.width; xx++)
588 {
589 SetGWorld(bitmap, NULL);
590 GetCPixel(rect.x + xx, rect.y + yy, &color);
591 SetGWorld(subbitmap, NULL);
592 SetCPixel(xx, yy, &color);
593 }
594 }
595 UnlockPixels(GetGWorldPixMap(bitmap));
596 UnlockPixels(GetGWorldPixMap(subbitmap));
5fde6fcc
GD
597 }
598 }
599 SetGWorld( origPort, origDevice );
600
601 return ret;
602}
603
e9576ca5
SC
604bool wxBitmap::Create(int w, int h, int d)
605{
606 UnRef();
607
608 m_refData = new wxBitmapRefData;
609
610 M_BITMAPDATA->m_width = w;
611 M_BITMAPDATA->m_height = h;
612 M_BITMAPDATA->m_depth = d;
613
519cb848
SC
614 M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
615 M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( w , h , d ) ;
76a5e5d2 616 M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hBitmap != NULL ) ;
e9576ca5
SC
617 return M_BITMAPDATA->m_ok;
618}
619
5fde6fcc
GD
620int wxBitmap::GetBitmapType() const
621{
622 wxCHECK_MSG( Ok(), kMacBitmapTypeUnknownType, wxT("invalid bitmap") );
623
624 return M_BITMAPDATA->m_bitmapType;
625}
626
519cb848
SC
627void wxBitmap::SetHBITMAP(WXHBITMAP bmp)
628{
85f296a3
SC
629 DisposeBitmapRefData( M_BITMAPDATA ) ;
630
519cb848
SC
631 M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
632 M_BITMAPDATA->m_hBitmap = bmp ;
76a5e5d2 633 M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hBitmap != NULL ) ;
519cb848
SC
634}
635
a8562f55 636bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
e9576ca5
SC
637{
638 UnRef();
639
e9576ca5
SC
640 wxBitmapHandler *handler = FindHandler(type);
641
a8562f55
GD
642 if ( handler )
643 {
4e9ed364 644 m_refData = new wxBitmapRefData;
e9576ca5 645
a8562f55 646 return handler->LoadFile(this, filename, type, -1, -1);
e9576ca5 647 }
a8562f55
GD
648 else
649 {
650 wxImage loadimage(filename, type);
651 if (loadimage.Ok()) {
652 *this = loadimage;
653 return true;
654 }
655 }
656 wxLogWarning("no bitmap handler for type %d defined.", type);
657 return false;
e9576ca5
SC
658}
659
a8562f55 660bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
e9576ca5
SC
661{
662 UnRef();
663
664 m_refData = new wxBitmapRefData;
665
666 wxBitmapHandler *handler = FindHandler(type);
667
668 if ( handler == NULL ) {
669 wxLogWarning("no bitmap handler for type %d defined.", type);
670
671 return FALSE;
672 }
673
674 return handler->Create(this, data, type, width, height, depth);
675}
676
fec19ea9
VS
677wxBitmap::wxBitmap(const wxImage& image, int depth)
678{
679 wxCHECK_RET( image.Ok(), wxT("invalid image") )
680 wxCHECK_RET( depth == -1, wxT("invalid bitmap depth") )
681
682 m_refData = new wxBitmapRefData();
683
fec19ea9
VS
684 // width and height of the device-dependent bitmap
685 int width = image.GetWidth();
686 int height = image.GetHeight();
687
688 // Create picture
689
71789654 690 Create( width , height , 32 ) ;
fec19ea9
VS
691
692 CGrafPtr origPort ;
693 GDHandle origDevice ;
694
76a5e5d2 695 PixMapHandle pixMap = GetGWorldPixMap((GWorldPtr)GetHBITMAP()) ;
71789654 696 LockPixels( pixMap );
fec19ea9
VS
697
698 GetGWorld( &origPort , &origDevice ) ;
76a5e5d2 699 SetGWorld( (GWorldPtr) GetHBITMAP() , NULL ) ;
fec19ea9
VS
700
701 // Render image
71789654 702 RGBColor colorRGB ;
fec19ea9
VS
703
704 register unsigned char* data = image.GetData();
71789654
SC
705 char* destinationBase = GetPixBaseAddr( pixMap );
706 register unsigned char* destination = (unsigned char*) destinationBase ;
fec19ea9
VS
707 for (int y = 0; y < height; y++)
708 {
709 for (int x = 0; x < width; x++)
710 {
71789654
SC
711 *destination++ = 0 ;
712 *destination++ = *data++ ;
713 *destination++ = *data++ ;
714 *destination++ = *data++ ;
fec19ea9 715 }
71789654
SC
716 destinationBase += ((**pixMap).rowBytes & 0x7fff);
717 destination = (unsigned char*) destinationBase ;
718 }
719 if ( image.HasMask() )
720 {
721 data = image.GetData();
722
723 wxColour maskcolor(image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
724 RGBColor white = { 0xffff, 0xffff, 0xffff };
725 RGBColor black = { 0 , 0 , 0 };
726 wxBitmap maskBitmap ;
fec19ea9 727
71789654 728 maskBitmap.Create( width, height, 1);
76a5e5d2
SC
729 LockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
730 SetGWorld( (GWorldPtr) maskBitmap.GetHBITMAP(), NULL);
71789654
SC
731
732 for (int y = 0; y < height; y++)
733 {
734 for (int x = 0; x < width; x++)
735 {
2af9ef13 736 if ( data[0] == image.GetMaskRed() && data[1] == image.GetMaskGreen() && data[2] == image.GetMaskBlue() )
71789654
SC
737 {
738 SetCPixel(x,y, &white);
739 }
740 else {
741 SetCPixel(x,y, &black);
742 }
743 data += 3 ;
744 }
745 } // for height
76a5e5d2 746 SetGWorld( (GWorldPtr) GetHBITMAP(), NULL);
71789654 747 SetMask(new wxMask( maskBitmap ));
76a5e5d2 748 UnlockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
fec19ea9
VS
749 }
750
76a5e5d2 751 UnlockPixels( GetGWorldPixMap( (GWorldPtr) GetHBITMAP()) );
fec19ea9
VS
752 SetGWorld( origPort, origDevice );
753}
754
755wxImage wxBitmap::ConvertToImage() const
756{
757 wxImage image;
758
759 wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
760
761 // create an wxImage object
762 int width = GetWidth();
763 int height = GetHeight();
764 image.Create( width, height );
765
766 unsigned char *data = image.GetData();
767
768 wxCHECK_MSG( data, wxNullImage, wxT("Could not allocate data for image") );
769
76a5e5d2 770 GWorldPtr origPort;
fec19ea9
VS
771 GDHandle origDevice;
772 int index;
773 RGBColor color;
774 // background color set to RGB(16,16,16) in consistent with wxGTK
775 unsigned char mask_r=16, mask_g=16, mask_b=16;
776 SInt16 r,g,b;
777 wxMask *mask = GetMask();
778
779 GetGWorld( &origPort, &origDevice );
76a5e5d2
SC
780 LockPixels(GetGWorldPixMap( (GWorldPtr) GetHBITMAP()));
781 SetGWorld( (GWorldPtr) GetHBITMAP(), NULL);
fec19ea9
VS
782
783 // Copy data into image
784 index = 0;
785 for (int yy = 0; yy < height; yy++)
786 {
787 for (int xx = 0; xx < width; xx++)
788 {
789 GetCPixel(xx,yy, &color);
790 r = ((color.red ) >> 8);
791 g = ((color.green ) >> 8);
792 b = ((color.blue ) >> 8);
793 data[index ] = r;
794 data[index + 1] = g;
795 data[index + 2] = b;
796 if (mask)
797 {
798 if (mask->PointMasked(xx,yy))
799 {
800 data[index ] = mask_r;
801 data[index + 1] = mask_g;
802 data[index + 2] = mask_b;
803 }
804 }
805 index += 3;
806 }
807 }
808 if (mask)
809 {
810 image.SetMaskColour( mask_r, mask_g, mask_b );
811 image.SetMask( true );
812 }
813
814 // Free resources
76a5e5d2 815 UnlockPixels(GetGWorldPixMap( (GWorldPtr) GetHBITMAP()));
fec19ea9
VS
816 SetGWorld(origPort, origDevice);
817
818 return image;
819}
820
821
a8562f55
GD
822bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type,
823 const wxPalette *palette) const
e9576ca5
SC
824{
825 wxBitmapHandler *handler = FindHandler(type);
826
a8562f55
GD
827 if ( handler )
828 {
829 return handler->SaveFile(this, filename, type, palette);
830 }
831 else
832 {
833 wxImage image = ConvertToImage();
e9576ca5 834
a8562f55
GD
835 return image.SaveFile(filename, type);
836 }
837
838 wxLogWarning("no bitmap handler for type %d defined.", type);
839 return false;
e9576ca5
SC
840}
841
5fde6fcc
GD
842bool wxBitmap::Ok() const
843{
844 return (M_BITMAPDATA && M_BITMAPDATA->m_ok);
845}
846
847int wxBitmap::GetHeight() const
848{
849 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
850
851 return M_BITMAPDATA->m_height;
852}
853
854int wxBitmap::GetWidth() const
855{
856 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
857
858 return M_BITMAPDATA->m_width;
859}
860
861int wxBitmap::GetDepth() const
862{
863 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
864
865 return M_BITMAPDATA->m_depth;
866}
867
868int wxBitmap::GetQuality() const
869{
870 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
871
872 return M_BITMAPDATA->m_quality;
873}
874
875wxMask *wxBitmap::GetMask() const
876{
877 wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") );
878
879 return M_BITMAPDATA->m_bitmapMask;
880}
881
e9576ca5
SC
882void wxBitmap::SetWidth(int w)
883{
884 if (!M_BITMAPDATA)
885 m_refData = new wxBitmapRefData;
886
887 M_BITMAPDATA->m_width = w;
888}
889
890void wxBitmap::SetHeight(int h)
891{
892 if (!M_BITMAPDATA)
893 m_refData = new wxBitmapRefData;
894
895 M_BITMAPDATA->m_height = h;
896}
897
898void wxBitmap::SetDepth(int d)
899{
900 if (!M_BITMAPDATA)
901 m_refData = new wxBitmapRefData;
902
903 M_BITMAPDATA->m_depth = d;
904}
905
906void wxBitmap::SetQuality(int q)
907{
908 if (!M_BITMAPDATA)
909 m_refData = new wxBitmapRefData;
910
911 M_BITMAPDATA->m_quality = q;
912}
913
914void wxBitmap::SetOk(bool isOk)
915{
916 if (!M_BITMAPDATA)
917 m_refData = new wxBitmapRefData;
918
919 M_BITMAPDATA->m_ok = isOk;
920}
921
5fde6fcc
GD
922wxPalette *wxBitmap::GetPalette() const
923{
924 wxCHECK_MSG( Ok(), NULL, wxT("Invalid bitmap GetPalette()") );
925
926 return &M_BITMAPDATA->m_bitmapPalette;
927}
928
e9576ca5
SC
929void wxBitmap::SetPalette(const wxPalette& palette)
930{
931 if (!M_BITMAPDATA)
932 m_refData = new wxBitmapRefData;
933
934 M_BITMAPDATA->m_bitmapPalette = palette ;
935}
936
937void wxBitmap::SetMask(wxMask *mask)
938{
939 if (!M_BITMAPDATA)
940 m_refData = new wxBitmapRefData;
941
a8562f55
GD
942 // Remove existing mask if there is one.
943 if (M_BITMAPDATA->m_bitmapMask)
944 delete M_BITMAPDATA->m_bitmapMask;
945
e9576ca5
SC
946 M_BITMAPDATA->m_bitmapMask = mask ;
947}
948
5fde6fcc
GD
949WXHBITMAP wxBitmap::GetHBITMAP() const
950{
951 wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
952
76a5e5d2 953 return MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap);
5fde6fcc
GD
954}
955
76a5e5d2 956WXHMETAFILE wxBitmap::GetPict() const
5fde6fcc
GD
957{
958 wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
959
960 PicHandle picture; // This is the returned picture
961
962 // If bitmap already in Pict format return pointer
963 if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypePict) {
964 return M_BITMAPDATA->m_hPict;
965 }
966 else if(M_BITMAPDATA->m_bitmapType != kMacBitmapTypeGrafWorld) {
967 // Invalid bitmap
968 return NULL;
969 }
970
971 RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ;
972 RGBColor white = { 0xffff ,0xffff , 0xffff } ;
973 RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ;
974 CGrafPtr origPort;
975 GDHandle origDev ;
976 wxMask *mask;
977 Rect portRect ;
978
76a5e5d2 979 GetPortBounds( (GWorldPtr) GetHBITMAP() , &portRect ) ;
5fde6fcc
GD
980 int width = portRect.right - portRect.left ;
981 int height = portRect.bottom - portRect.top ;
982
76a5e5d2 983 LockPixels( GetGWorldPixMap( (GWorldPtr) GetHBITMAP() ) ) ;
5fde6fcc
GD
984 GetGWorld( &origPort , &origDev ) ;
985
986 mask = GetMask();
987
76a5e5d2 988 SetGWorld( (GWorldPtr) GetHBITMAP() , NULL ) ;
5fde6fcc
GD
989
990 picture = OpenPicture(&portRect); // open a picture, this disables drawing
991 if(!picture) {
992 return NULL;
993 }
994
995 if( mask )
996 {
f5c6eb5c 997#ifdef __DARWIN__
5fde6fcc
GD
998 RGBColor trans = white;
999#else
1000 RGBBackColor( &gray );
1001 EraseRect( &portRect );
1002 RGBColor trans = gray;
1003#endif
1004 RGBForeColor( &black ) ;
1005 RGBBackColor( &white ) ;
1006 PenMode(transparent);
1007
1008 for ( int y = 0 ; y < height ; ++y )
1009 {
1010 for( int x = 0 ; x < width ; ++x )
1011 {
1012 if ( !mask->PointMasked(x,y) )
1013 {
1014 RGBColor col ;
1015
1016 GetCPixel( x + portRect.left , y + portRect.top , &col ) ;
1017 SetCPixel( x + portRect.left , y + portRect.top , &col ) ;
1018 }
1019 else {
1020 // With transparency this sets a blank pixel
1021 SetCPixel( x + portRect.left , y + portRect.top , &trans);
1022 }
1023 }
1024 }
1025 }
1026 else
1027 {
1028 RGBBackColor( &gray ) ;
1029 EraseRect(&portRect);
1030 RGBForeColor( &black ) ;
1031 RGBBackColor( &white ) ;
1032
76a5e5d2 1033 CopyBits(GetPortBitMapForCopyBits( (GWorldPtr) GetHBITMAP()),
5fde6fcc 1034 // src PixMap - we copy image over itself -
76a5e5d2 1035 GetPortBitMapForCopyBits( (GWorldPtr) GetHBITMAP()),
5fde6fcc
GD
1036 // dst PixMap - no drawing occurs
1037 &portRect, // srcRect - it will be recorded and compressed -
1038 &portRect, // dstRect - into the picture that is open -
1039 srcCopy,NULL); // copyMode and no clip region
1040 }
1041 ClosePicture(); // We are done recording the picture
76a5e5d2 1042 UnlockPixels( GetGWorldPixMap( (GWorldPtr) GetHBITMAP() ) ) ;
5fde6fcc
GD
1043 SetGWorld( origPort , origDev ) ;
1044
1045 return picture; // return our groovy pict handle
1046}
1047
e9576ca5
SC
1048/*
1049 * wxMask
1050 */
1051
1052wxMask::wxMask()
1053{
e9576ca5 1054 m_maskBitmap = 0;
e9576ca5
SC
1055}
1056
1057// Construct a mask from a bitmap and a colour indicating
1058// the transparent area
1059wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
1060{
e9576ca5 1061 m_maskBitmap = 0;
e9576ca5
SC
1062 Create(bitmap, colour);
1063}
1064
1065// Construct a mask from a bitmap and a palette index indicating
1066// the transparent area
1067wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
1068{
e9576ca5 1069 m_maskBitmap = 0;
e9576ca5
SC
1070 Create(bitmap, paletteIndex);
1071}
1072
1073// Construct a mask from a mono bitmap (copies the bitmap).
1074wxMask::wxMask(const wxBitmap& bitmap)
1075{
e9576ca5 1076 m_maskBitmap = 0;
e9576ca5
SC
1077 Create(bitmap);
1078}
1079
1080wxMask::~wxMask()
1081{
4e9ed364
RR
1082 if ( m_maskBitmap )
1083 {
76a5e5d2 1084 wxMacDestroyGWorld( (GWorldPtr) m_maskBitmap ) ;
4e9ed364
RR
1085 m_maskBitmap = NULL ;
1086 }
e9576ca5
SC
1087}
1088
1089// Create a mask from a mono bitmap (copies the bitmap).
1090bool wxMask::Create(const wxBitmap& bitmap)
1091{
5fde6fcc
GD
1092 if ( m_maskBitmap )
1093 {
76a5e5d2 1094 wxMacDestroyGWorld( (GWorldPtr) m_maskBitmap ) ;
5fde6fcc
GD
1095 m_maskBitmap = NULL ;
1096 }
1097 wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false,
1098 wxT("Cannot create mask from this bitmap type (TODO)"));
1099 // other types would require a temporary bitmap. not yet implemented
1100
1101 wxCHECK_MSG( bitmap.Ok(), false, wxT("Invalid bitmap"));
1102
1103 wxCHECK_MSG(bitmap.GetDepth() == 1, false,
1104 wxT("Cannot create mask from colour bitmap"));
1105
1106 m_maskBitmap = wxMacCreateGWorld(bitmap.GetWidth(), bitmap.GetHeight(), 1);
1107 Rect rect = { 0,0, bitmap.GetHeight(), bitmap.GetWidth() };
1108
76a5e5d2
SC
1109 LockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap) );
1110 LockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP()) );
1111 CopyBits(GetPortBitMapForCopyBits( (GWorldPtr) bitmap.GetHBITMAP()),
1112 GetPortBitMapForCopyBits( (GWorldPtr) m_maskBitmap),
5fde6fcc 1113 &rect, &rect, srcCopy, 0);
76a5e5d2
SC
1114 UnlockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap) );
1115 UnlockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP()) );
5fde6fcc
GD
1116
1117 return FALSE;
e9576ca5
SC
1118}
1119
1120// Create a mask from a bitmap and a palette index indicating
1121// the transparent area
1122bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex)
1123{
1124// TODO
5fde6fcc 1125 wxCHECK_MSG( 0, false, wxT("Not implemented"));
e9576ca5
SC
1126 return FALSE;
1127}
1128
1129// Create a mask from a bitmap and a colour indicating
1130// the transparent area
1131bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
1132{
4e9ed364
RR
1133 if ( m_maskBitmap )
1134 {
76a5e5d2 1135 wxMacDestroyGWorld( (GWorldPtr) m_maskBitmap ) ;
4e9ed364
RR
1136 m_maskBitmap = NULL ;
1137 }
1138 wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false,
5fde6fcc 1139 wxT("Cannot create mask from this bitmap type (TODO)"));
4e9ed364
RR
1140 // other types would require a temporary bitmap. not yet implemented
1141
5fde6fcc 1142 wxCHECK_MSG( bitmap.Ok(), false, wxT("Illigal bitmap"));
8208e181 1143
4e9ed364 1144 m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 );
76a5e5d2
SC
1145 LockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap ) );
1146 LockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP() ) );
1147 RGBColor maskColor = MAC_WXCOLORREF(colour.GetPixel());
8208e181
SC
1148
1149 // this is not very efficient, but I can't think
1150 // of a better way of doing it
4e9ed364
RR
1151 CGrafPtr origPort ;
1152 GDHandle origDevice ;
5fde6fcc
GD
1153 RGBColor col;
1154 RGBColor colors[2] = {
1155 { 0xFFFF, 0xFFFF, 0xFFFF },
1156 { 0, 0, 0 }};
4e9ed364
RR
1157
1158 GetGWorld( &origPort , &origDevice ) ;
1159 for (int w = 0; w < bitmap.GetWidth(); w++)
8208e181
SC
1160 {
1161 for (int h = 0; h < bitmap.GetHeight(); h++)
4e9ed364 1162 {
76a5e5d2 1163 SetGWorld( (GWorldPtr) bitmap.GetHBITMAP(), NULL ) ;
4e9ed364 1164 GetCPixel( w , h , &col ) ;
76a5e5d2 1165 SetGWorld( (GWorldPtr) m_maskBitmap , NULL ) ;
5fde6fcc 1166 if (col.red == maskColor.red && col.green == maskColor.green && col.blue == maskColor.blue)
8208e181 1167 {
4e9ed364 1168 SetCPixel( w , h , &colors[0] ) ;
8208e181
SC
1169 }
1170 else
1171 {
4e9ed364 1172 SetCPixel( w , h , &colors[1] ) ;
8208e181
SC
1173 }
1174 }
1175 }
4e9ed364 1176 UnlockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ;
76a5e5d2 1177 UnlockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP() ) ) ;
4e9ed364 1178 SetGWorld( origPort , origDevice ) ;
8208e181
SC
1179
1180 return TRUE;
e9576ca5
SC
1181}
1182
5fde6fcc
GD
1183bool wxMask::PointMasked(int x, int y)
1184{
76a5e5d2 1185 GWorldPtr origPort;
5fde6fcc
GD
1186 GDHandle origDevice;
1187 RGBColor color;
1188 bool masked = true;
1189
1190 GetGWorld( &origPort, &origDevice);
1191
1192 //Set port to mask and see if it masked (1) or not ( 0 )
76a5e5d2
SC
1193 SetGWorld( (GWorldPtr) m_maskBitmap, NULL);
1194 LockPixels(GetGWorldPixMap( (GWorldPtr) m_maskBitmap));
5fde6fcc
GD
1195 GetCPixel(x,y, &color);
1196 masked = !(color.red == 0 && color.green == 0 && color.blue == 0);
76a5e5d2 1197 UnlockPixels(GetGWorldPixMap( (GWorldPtr) m_maskBitmap));
5fde6fcc
GD
1198
1199 SetGWorld( origPort, origDevice);
1200
1201 return masked;
1202}
1203
e9576ca5
SC
1204/*
1205 * wxBitmapHandler
1206 */
1207
e9576ca5
SC
1208bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
1209{
1210 return FALSE;
1211}
1212
a8562f55 1213bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
e9576ca5
SC
1214 int desiredWidth, int desiredHeight)
1215{
1216 return FALSE;
1217}
1218
a8562f55 1219bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
e9576ca5
SC
1220{
1221 return FALSE;
1222}
1223
1224/*
1225 * Standard handlers
1226 */
1227
519cb848
SC
1228class WXDLLEXPORT wxPICTResourceHandler: public wxBitmapHandler
1229{
1230 DECLARE_DYNAMIC_CLASS(wxPICTResourceHandler)
1231public:
1232 inline wxPICTResourceHandler()
1233 {
1234 m_name = "Macintosh Pict resource";
1235 m_extension = "";
1236 m_type = wxBITMAP_TYPE_PICT_RESOURCE;
1237 };
1238
1239 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1240 int desiredWidth, int desiredHeight);
1241};
1242IMPLEMENT_DYNAMIC_CLASS(wxPICTResourceHandler, wxBitmapHandler)
1243
1244bool wxPICTResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1245 int desiredWidth, int desiredHeight)
1246{
4e9ed364
RR
1247 Str255 theName ;
1248
03e11df5 1249#if TARGET_CARBON
4e9ed364 1250 c2pstrcpy( (StringPtr) theName , name ) ;
03e11df5 1251#else
4e9ed364
RR
1252 strcpy( (char *) theName , name ) ;
1253 c2pstr( (char *)theName ) ;
03e11df5 1254#endif
4e9ed364
RR
1255
1256 PicHandle thePict = (PicHandle ) GetNamedResource( 'PICT' , theName ) ;
1257 if ( thePict )
1258 {
1259 PictInfo theInfo ;
1260
1261 GetPictInfo( thePict , &theInfo , 0 , 0 , systemMethod , 0 ) ;
1262 DetachResource( (Handle) thePict ) ;
1263 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypePict ;
1264 M_BITMAPHANDLERDATA->m_hPict = thePict ;
1265 M_BITMAPHANDLERDATA->m_width = theInfo.sourceRect.right - theInfo.sourceRect.left ;
1266 M_BITMAPHANDLERDATA->m_height = theInfo.sourceRect.bottom - theInfo.sourceRect.top ;
1267
1268 M_BITMAPHANDLERDATA->m_depth = theInfo.depth ;
1269 M_BITMAPHANDLERDATA->m_ok = true ;
1270 M_BITMAPHANDLERDATA->m_numColors = theInfo.uniqueColors ;
1271// M_BITMAPHANDLERDATA->m_bitmapPalette;
1272// M_BITMAPHANDLERDATA->m_quality;
1273 return TRUE ;
1274 }
1275 return FALSE ;
519cb848
SC
1276}
1277
e9576ca5
SC
1278void wxBitmap::InitStandardHandlers()
1279{
973b0afb
GD
1280 AddHandler(new wxPICTResourceHandler) ;
1281 AddHandler(new wxICONResourceHandler) ;
e9576ca5 1282}