+ 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 ) ;
+ }
+