// we don't dare premultiplied alpha yet
#define wxMAC_USE_PREMULTIPLIED_ALPHA 0
-IconRef wxMacCreateIconRef(const wxBitmap& bmp)
+IconFamilyHandle wxMacCreateIconFamily(const wxBitmap& bmp)
{
// setup the header properly
HUnlock( maskdata ) ;
DisposeHandle( data ) ;
DisposeHandle( maskdata ) ;
+ return iconFamily ;
+}
+IconRef wxMacCreateIconRef(const wxBitmap& bmp)
+{
+ IconFamilyHandle iconFamily = wxMacCreateIconFamily( bmp ) ;
IconRef iconRef ;
static int iconCounter = 2 ;
- err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &iconRef ) ;
+ OSStatus err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &iconRef ) ;
UInt16 owners ;
err = GetIconRefOwners(iconRef , &owners ) ;
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)
+ {
+ RGBColor white = { 0xffff ,0xffff , 0xffff } ;
+ RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ;
+ RGBForeColor( &black ) ;
+ RGBBackColor( &white ) ;
+
+ LockPixels( GetGWorldPixMap( wp ) ) ;
+ CopyBits(GetPortBitMapForCopyBits(wp),
+ GetPortBitMapForCopyBits(wp),
+ &portRect,
+ &portRect,
+ srcCopy,NULL);
+ UnlockPixels( GetGWorldPixMap( wp ) ) ;
+ ClosePicture();
+ }
+ SetGWorld( origPort , origDev ) ;
+
+ return pict;
+}
+
void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType )
{
memset( info , 0 , sizeof(ControlButtonContentInfo) ) ;
m_bitmapMask = NULL ;
#if wxMAC_USE_CORE_GRAPHICS
m_cgImageRef = NULL ;
-#else
+#endif
m_hBitmap = NULL ;
m_hMaskBitmap = NULL;
m_maskBytesPerRow = NULL ;
-#endif
+
m_rawAccessCount = 0 ;
m_hasAlpha = false;
}
void* data = m_memBuf.GetWriteBuf(size) ;
memset( data , 0 , size) ;
m_memBuf.UngetWriteBuf(size) ;
-#if wxMAC_USE_CORE_GRAPHICS
- m_ok = true ;
-#else
+
m_hBitmap = NULL ;
Rect rect = { 0 , 0 , m_height , m_width } ;
verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
(char*) data , m_bytesPerRow ) ) ;
wxASSERT_MSG( m_hBitmap , wxT("Unable to create GWorld context") ) ;
m_ok = ( m_hBitmap != NULL ) ;
-#endif
+
return m_ok ;
}
return ;
m_hasAlpha = use ;
-#if !wxMAC_USE_CORE_GRAPHICS
if ( m_hasAlpha )
{
int width = GetWidth() ;
(char*) data , m_maskBytesPerRow ) ) ;
wxASSERT_MSG( m_hMaskBitmap , wxT("Unable to create GWorld context for alpha mask") ) ;
m_maskMemBuf.UngetWriteBuf(size) ;
+#if !wxMAC_USE_CORE_GRAPHICS
UpdateAlphaMask() ;
+#endif
}
else
{
m_hMaskBitmap = NULL ;
m_maskBytesPerRow = 0 ;
}
-#endif
}
void *wxBitmapRefData::GetRawAccess() const
#if wxMAC_USE_CORE_GRAPHICS
-static void FreeImageMemoryBufferInstance(void *info, const void *data, size_t size)
+void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size)
{
- delete ((wxMemoryBuffer*)info) ;
+ wxMemoryBuffer* membuf = (wxMemoryBuffer*) info ;
+ wxASSERT( data == membuf->GetData() ) ;
+ delete membuf ;
}
CGImageRef wxBitmapRefData::CGImageCreate() const
}
CGColorSpaceRef colorSpace = wxMacGetGenericRGBColorSpace();
CGDataProviderRef dataProvider =
- CGDataProviderCreateWithData( membuf , (const void *)membuf->GetData() , imageSize, FreeImageMemoryBufferInstance );
+ CGDataProviderCreateWithData( membuf , (const void *)membuf->GetData() , imageSize,
+ wxMacMemoryBufferReleaseProc );
image =
::CGImageCreate( w, h, 8 , 32 , 4 * m_width , colorSpace, alphaInfo ,
dataProvider, NULL , false , kCGRenderingIntentDefault );
}
#endif
-#if !wxMAC_USE_CORE_GRAPHICS
GWorldPtr wxBitmapRefData::GetHBITMAP(GWorldPtr* mask) const
{
wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
*mask = (GWorldPtr) m_bitmapMask->GetHBITMAP() ;
else if ( m_hasAlpha )
{
+#if !wxMAC_USE_CORE_GRAPHICS
if ( m_rawAccessCount > 0 )
UpdateAlphaMask() ;
+#else
+ // this structure is not kept in synch when using CG, so if someone
+ // is really accessing the Graphports, we have to sync it
+ UpdateAlphaMask() ;
+#endif
*mask = m_hMaskBitmap ;
}
}
}
}
-#endif
-
void wxBitmapRefData::Free()
{
wxASSERT_MSG( m_rawAccessCount == 0 , wxT("Bitmap still selected when destroyed") ) ;
CGImageRelease( m_cgImageRef ) ;
m_cgImageRef = NULL ;
}
-#else
+#endif
if ( m_hBitmap )
{
DisposeGWorld( MAC_WXHBITMAP(m_hBitmap) ) ;
DisposeGWorld( MAC_WXHBITMAP(m_hMaskBitmap) ) ;
m_hMaskBitmap = NULL ;
}
-#endif
if (m_bitmapMask)
{
int h = icon.GetHeight() ;
Create( icon.GetWidth() , icon.GetHeight() ) ;
- if ( w == h && w == 32 )
+ if ( w == h && ( w == 16 || w == 32 || w == 48 || w == 128 ) )
{
IconFamilyHandle iconFamily = NULL ;
Handle imagehandle = NewHandle(0) ;
Handle maskhandle = NewHandle(0) ;
- OSStatus err = ( IconRefToIconFamily( MAC_WXHICON(icon.GetHICON()) , kSelectorLarge32Bit | kSelectorLarge8BitMask , &iconFamily ) ) ;
- err =( GetIconFamilyData( iconFamily , kLarge32BitData , imagehandle ) ) ;
- err =( GetIconFamilyData( iconFamily , kLarge8BitMask , maskhandle ) ) ;
+
+ OSType maskType ;
+ OSType dataType ;
+ IconSelectorValue selector ;
+ if ( w == 128 )
+ {
+ dataType = kThumbnail32BitData ;
+ maskType = kThumbnail8BitMask ;
+ selector = kSelectorAllAvailableData ;
+ }
+ else if ( w == 48 )
+ {
+ dataType = kHuge32BitData ;
+ maskType = kHuge8BitMask ;
+ selector = kSelectorHuge32Bit | kSelectorHuge8BitMask ;
+ }
+ else if ( w == 32 )
+ {
+ dataType = kLarge32BitData ;
+ maskType = kLarge8BitMask ;
+ selector = kSelectorLarge32Bit | kSelectorLarge8BitMask ;
+ }
+ else if ( w == 16 )
+ {
+ dataType = kSmall32BitData ;
+ maskType = kSmall8BitMask ;
+ selector = kSelectorSmall32Bit | kSelectorSmall8BitMask ;
+ }
+ else
+ {
+ wxFAIL_MSG(wxT("Illegal icon size for conversion") ) ;
+ }
+
+
+ OSStatus err = ( IconRefToIconFamily( MAC_WXHICON(icon.GetHICON()) , selector , &iconFamily ) ) ;
+
+ err =( GetIconFamilyData( iconFamily , dataType , imagehandle ) ) ;
+ err =( GetIconFamilyData( iconFamily , maskType , maskhandle ) ) ;
wxASSERT( GetHandleSize( imagehandle ) == w * 4 * h ) ;
wxASSERT( GetHandleSize( maskhandle ) == w * h ) ;
UseAlpha() ;
M_BITMAPDATA->m_bitmapMask = mask ;
}
-#if !wxMAC_USE_CORE_GRAPHICS
WXHBITMAP wxBitmap::GetHBITMAP(WXHBITMAP* mask) const
{
return WXHBITMAP(M_BITMAPDATA->GetHBITMAP((GWorldPtr*)mask));
}
-#endif
// ----------------------------------------------------------------------------
// wxMask
wxMask::~wxMask()
{
-#if !wxMAC_USE_CORE_GRAPHICS
if ( m_maskBitmap )
{
DisposeGWorld( (GWorldPtr) m_maskBitmap ) ;
m_maskBitmap = NULL ;
}
-#endif
}
void wxMask::Init()
{
m_width = m_height = m_bytesPerRow = 0 ;
-#if !wxMAC_USE_CORE_GRAPHICS
m_maskBitmap = NULL ;
-#endif
-
}
void *wxMask::GetRawAccess() const
void wxMask::RealizeNative()
{
-#if !wxMAC_USE_CORE_GRAPHICS
if ( m_maskBitmap )
{
DisposeGWorld( (GWorldPtr) m_maskBitmap ) ;
Rect rect = { 0 , 0 , m_height , m_width } ;
verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_maskBitmap , k8IndexedGrayPixelFormat , &rect , NULL , NULL , 0 ,
(char*) m_memBuf.GetData() , m_bytesPerRow ) ) ;
-#endif
}
// Create a mask from a mono bitmap (copies the bitmap).
return TRUE;
}
-#if !wxMAC_USE_CORE_GRAPHICS
WXHBITMAP wxMask::GetHBITMAP() const
{
return m_maskBitmap ;
}
-#endif
// ----------------------------------------------------------------------------
// wxBitmapHandler