+ bool created = false ;
+ int w = icon.GetWidth() ;
+ int h = icon.GetHeight() ;
+
+ Create( icon.GetWidth() , icon.GetHeight() ) ;
+
+ if ( w == h && ( w == 16 || w == 32 || w == 48 || w == 128 ) )
+ {
+ IconFamilyHandle iconFamily = NULL ;
+ Handle imagehandle = NewHandle( 0 ) ;
+ Handle maskhandle = NewHandle( 0 ) ;
+
+ OSType maskType = 0;
+ OSType dataType = 0;
+ IconSelectorValue selector = 0 ;
+
+ switch (w)
+ {
+ case 128:
+ dataType = kThumbnail32BitData ;
+ maskType = kThumbnail8BitMask ;
+ selector = kSelectorAllAvailableData ;
+ break;
+
+ case 48:
+ dataType = kHuge32BitData ;
+ maskType = kHuge8BitMask ;
+ selector = kSelectorHuge32Bit | kSelectorHuge8BitMask ;
+ break;
+
+ case 32:
+ dataType = kLarge32BitData ;
+ maskType = kLarge8BitMask ;
+ selector = kSelectorLarge32Bit | kSelectorLarge8BitMask ;
+ break;
+
+ case 16:
+ dataType = kSmall32BitData ;
+ maskType = kSmall8BitMask ;
+ selector = kSelectorSmall32Bit | kSelectorSmall8BitMask ;
+ break;
+
+ default:
+ break;
+ }
+
+ OSStatus err = IconRefToIconFamily( MAC_WXHICON(icon.GetHICON()) , selector , &iconFamily ) ;
+
+ err = GetIconFamilyData( iconFamily , dataType , imagehandle ) ;
+ err = GetIconFamilyData( iconFamily , maskType , maskhandle ) ;
+ size_t imagehandlesize = GetHandleSize( imagehandle ) ;
+ size_t maskhandlesize = GetHandleSize( maskhandle ) ;
+
+ if ( imagehandlesize != 0 && maskhandlesize != 0 )
+ {
+ wxASSERT( GetHandleSize( imagehandle ) == w * 4 * h ) ;
+ wxASSERT( GetHandleSize( maskhandle ) == w * h ) ;
+
+ UseAlpha() ;
+
+ unsigned char *source = (unsigned char *) *imagehandle ;
+ unsigned char *sourcemask = (unsigned char *) *maskhandle ;
+ unsigned char* destination = (unsigned char*) BeginRawAccess() ;
+
+ for ( int y = 0 ; y < h ; ++y )
+ {
+ for ( int x = 0 ; x < w ; ++x )
+ {
+ unsigned char a = *sourcemask++;
+ *destination++ = a;
+ source++ ;
+#if wxMAC_USE_PREMULTIPLIED_ALPHA
+ *destination++ = ( (*source++) * a + 127 ) / 255;
+ *destination++ = ( (*source++) * a + 127 ) / 255;
+ *destination++ = ( (*source++) * a + 127 ) / 255;
+#else
+ *destination++ = *source++ ;
+ *destination++ = *source++ ;
+ *destination++ = *source++ ;
+#endif
+ }
+ }
+
+ EndRawAccess() ;
+ DisposeHandle( imagehandle ) ;
+ DisposeHandle( maskhandle ) ;
+ created = true ;
+ }
+
+ DisposeHandle( (Handle) iconFamily ) ;
+ }
+
+ if ( !created )
+ {
+ wxMemoryDC dc ;
+ dc.SelectObject( *this ) ;
+ dc.DrawIcon( icon , 0 , 0 ) ;
+ dc.SelectObject( wxNullBitmap ) ;
+ }
+
+ return true;
+}
+
+wxBitmap::wxBitmap()
+{
+}
+
+wxBitmap::~wxBitmap()
+{
+}
+
+wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
+{
+ wxBitmapRefData* bitmapRefData;
+
+ m_refData = bitmapRefData = new wxBitmapRefData( the_width , the_height , no_bits ) ;
+
+ if (bitmapRefData->IsOk())
+ {
+ if ( no_bits == 1 )
+ {
+ int linesize = ( the_width / (sizeof(unsigned char) * 8)) ;
+ if ( the_width % (sizeof(unsigned char) * 8) )
+ linesize += sizeof(unsigned char);
+
+ unsigned char* linestart = (unsigned char*) bits ;
+ unsigned char* destptr = (unsigned char*) BeginRawAccess() ;
+
+ for ( int y = 0 ; y < the_height ; ++y , linestart += linesize, destptr += M_BITMAPDATA->GetBytesPerRow() )
+ {
+ unsigned char* destination = destptr;
+ int index, bit, mask;
+
+ for ( int x = 0 ; x < the_width ; ++x )
+ {
+ index = x / 8 ;
+ bit = x % 8 ;
+ mask = 1 << bit ;
+
+ if ( linestart[index] & mask )
+ {
+ *destination++ = 0xFF ;
+ *destination++ = 0 ;
+ *destination++ = 0 ;
+ *destination++ = 0 ;
+ }
+ else
+ {
+ *destination++ = 0xFF ;
+ *destination++ = 0xFF ;
+ *destination++ = 0xFF ;
+ *destination++ = 0xFF ;
+ }
+ }
+ }
+
+ EndRawAccess() ;
+ }
+ else
+ {
+ wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
+ }
+ } /* bitmapRefData->IsOk() */
+}
+
+wxBitmap::wxBitmap(int w, int h, int d)
+{
+ (void)Create(w, h, d);