+ size = sz * sz * 4 ;
+ data = NewHandle( size) ;
+ HLock( data ) ;
+ ptr = (unsigned char*) *data ;
+ memset( ptr , 0, size ) ;
+
+ masksize = sz * sz ;
+ maskdata = NewHandle( masksize ) ;
+ HLock( maskdata ) ;
+ maskptr = (unsigned char*) *maskdata ;
+ memset( maskptr , 0 , masksize ) ;
+
+ unsigned char * source = (unsigned char*) bmp.GetRawAccess() ;
+ unsigned char * masksource = mask ? (unsigned char*) mask->GetRawAccess() : NULL ;
+ for ( int y = 0 ; y < h ; ++y )
+ {
+ unsigned char * dest = ptr + y * sz * 4 ;
+ unsigned char * maskdest = maskptr + y * sz ;
+ for ( int x = 0 ; x < w ; ++x )
+ {
+ unsigned char a = *source ++ ;
+ unsigned char r = *source ++ ;
+ unsigned char g = *source ++ ;
+ unsigned char b = *source ++ ;
+
+ *dest++ = 0 ;
+ *dest++ = r ;
+ *dest++ = g ;
+ *dest++ = b ;
+
+ if ( mask )
+ *maskdest++ = *masksource++ ;
+ else if ( hasAlpha )
+ *maskdest++ = a ;
+ else
+ *maskdest++ = 0xFF ;
+ }
+ }
+
+ OSStatus err = SetIconFamilyData( iconFamily, dataType , data ) ;
+ wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ;
+
+ err = SetIconFamilyData( iconFamily, maskType , maskdata ) ;
+ wxASSERT_MSG( err == noErr , wxT("Error when adding mask") ) ;
+ HUnlock( data ) ;
+ HUnlock( maskdata ) ;
+ DisposeHandle( data ) ;
+ DisposeHandle( maskdata ) ;
+ return iconFamily ;
+}
+
+IconRef wxMacCreateIconRef(const wxBitmap& bmp)
+{
+ IconFamilyHandle iconFamily = wxMacCreateIconFamily( bmp ) ;
+ IconRef iconRef ;
+ static int iconCounter = 2 ;
+
+ OSStatus err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &iconRef ) ;
+ UInt16 owners ;
+ err = GetIconRefOwners(iconRef , &owners ) ;
+
+ wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ;
+ // we have to retain a reference, as Unregister will decrement it
+ AcquireIconRef( iconRef ) ;
+ UnregisterIconRef( 'WXNG' , (OSType) iconCounter ) ;
+ DisposeHandle( (Handle) iconFamily ) ;
+ ++iconCounter ;
+
+ return iconRef ;
+}
+
+PicHandle wxMacCreatePicHandle( const wxBitmap &bmp )
+{
+ CGrafPtr origPort = NULL ;
+ GDHandle origDev = NULL ;
+ PicHandle pict = NULL ;
+ GWorldPtr wp = NULL ;
+ GWorldPtr mask = NULL ;
+
+ GetGWorld( &origPort , &origDev ) ;
+
+ wp = (GWorldPtr) bmp.GetHBITMAP( (WXHBITMAP*) &mask ) ;
+
+ SetGWorld( wp , NULL ) ;
+ Rect portRect ;
+ GetPortBounds( wp , &portRect ) ;
+ pict = OpenPicture(&portRect);
+
+ if(pict)