X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/20b6985553b4e01e7960847e3211d940aeff8742..1a87edf286921de9b182f3d19adb6bb63ba85ebd:/src/mac/carbon/bitmap.cpp diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index d98e6fd2dd..3e1761ba73 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -36,6 +36,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject ) #include "wx/mac/uma.h" +#include "wx/dcmemory.h" + // Implementation Notes // -------------------- // @@ -49,126 +51,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject ) // we don't dare premultiplied alpha yet #define wxMAC_USE_PREMULTIPLIED_ALPHA 0 -IconRef wxMacCreateIconRef(const wxBitmap& bmp) -{ - // setup the header properly - - IconFamilyHandle iconFamily = (IconFamilyHandle) NewHandle(8) ; - (**iconFamily).resourceType = kIconFamilyType ; - (**iconFamily).resourceSize = sizeof(OSType) + sizeof(Size); - - int w = bmp.GetWidth() ; - int h = bmp.GetHeight() ; - int sz = wxMax( w , h ) ; - if ( sz > 128 ) - { - wxFAIL_MSG( wxT("Currently only 128 pixels wide images are supported") ) ; - } - - Handle data = NULL ; - Handle maskdata = NULL ; - unsigned char * maskptr = NULL ; - unsigned char * ptr = NULL ; - size_t size ; - size_t masksize ; - OSType dataType ; - OSType maskType ; - - bool hasAlpha = bmp.HasAlpha() ; - wxMask *mask = bmp.GetMask() ; - // thumbnail is 128 x 128 with 32 bits per pixel - - if ( sz > 48 ) - { - sz = 128 ; - dataType = kThumbnail32BitData ; - maskType = kThumbnail8BitMask ; - } - else if ( sz > 32 ) - { - sz = 48 ; - dataType = kHuge32BitData ; - maskType = kHuge8BitMask ; - } - else if ( sz > 16 ) - { - sz = 32 ; - dataType = kLarge32BitData ; - maskType = kLarge8BitMask ; - } - else - { - sz = 16 ; - dataType = kSmall32BitData ; - maskType = kSmall8BitMask ; - } - - 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 ) ; - - IconRef iconRef ; - static int iconCounter = 2 ; - - 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 ; -} - void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType ) { memset( info , 0 , sizeof(ControlButtonContentInfo) ) ; @@ -177,9 +59,17 @@ void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bi wxBitmapRefData * bmap = (wxBitmapRefData*) ( bitmap.GetRefData()) ; if ( bmap == NULL ) return ; - info->contentType = kControlContentIconRef ; - info->u.iconRef = wxMacCreateIconRef( bitmap ) ; - + + if ( bmap->HasNativeSize() ) + { + info->contentType = kControlContentIconRef ; + info->u.iconRef = bmap->GetIconRef() ; + } + else + { + info->contentType = kControlContentPictHandle ; + info->u.picture = bmap->GetPictHandle() ; + } #if wxMAC_USE_CORE_GRAPHICS /* // only on 10.4 more controls will accept a CGImage @@ -195,9 +85,13 @@ void wxMacReleaseBitmapButton( ControlButtonContentInfo*info ) { if ( info->contentType == kControlContentIconRef ) { - ReleaseIconRef(info->u.iconRef) ; + // as the bitmap is now the owner, no need to release here } -#if wxMAC_USE_CORE_GRAPHICS + else if ( info->contentType == kControlContentPictHandle ) + { + // owned by the bitma, no release here + } +#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 else if ( info->contentType == kControlContentCGImageRef ) { CGImageRelease( info->u.imageRef ) ; @@ -209,6 +103,7 @@ void wxMacReleaseBitmapButton( ControlButtonContentInfo*info ) } } +#define M_BITMAPDATA ((wxBitmapRefData *)m_refData) void wxBitmapRefData::Init() { @@ -219,11 +114,13 @@ void wxBitmapRefData::Init() m_bitmapMask = NULL ; #if wxMAC_USE_CORE_GRAPHICS m_cgImageRef = NULL ; -#else +#endif + m_iconRef = NULL ; + m_pictHandle = NULL ; m_hBitmap = NULL ; m_hMaskBitmap = NULL; m_maskBytesPerRow = NULL ; -#endif + m_rawAccessCount = 0 ; m_hasAlpha = false; } @@ -250,16 +147,14 @@ bool wxBitmapRefData::Create( int w , int h , int d ) 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 ; } @@ -269,22 +164,23 @@ void wxBitmapRefData::UseAlpha( bool use ) return ; m_hasAlpha = use ; -#if !wxMAC_USE_CORE_GRAPHICS if ( m_hasAlpha ) { int width = GetWidth() ; int height = GetHeight() ; - m_maskBytesPerRow = ( width + 3 ) & 0xFFFFFFC ; + m_maskBytesPerRow = ( width * 4 + 3 ) & 0xFFFFFFC ; size_t size = height * m_maskBytesPerRow ; unsigned char * data = (unsigned char * ) m_maskMemBuf.GetWriteBuf( size ) ; memset( data , 0 , size ) ; wxASSERT( m_hMaskBitmap == NULL ) ; Rect rect = { 0 , 0 , height , width } ; - verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hMaskBitmap , k8IndexedGrayPixelFormat , &rect , NULL , NULL , 0 , + verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hMaskBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 , (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 { @@ -292,7 +188,6 @@ void wxBitmapRefData::UseAlpha( bool use ) m_hMaskBitmap = NULL ; m_maskBytesPerRow = 0 ; } -#endif } void *wxBitmapRefData::GetRawAccess() const @@ -306,9 +201,11 @@ void *wxBitmapRefData::BeginRawAccess() wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ) ; wxASSERT( m_rawAccessCount == 0 ) ; ++m_rawAccessCount ; -#if wxMAC_USE_CORE_GRAPHICS - // we must destroy an existing cached image, as + // we must destroy an existing cached image, as // the bitmap data may change now + wxASSERT_MSG( m_pictHandle == NULL && m_iconRef == NULL , + wxT("Currently, modifing bitmaps that are used in controls already is not supported") ) ; +#if wxMAC_USE_CORE_GRAPHICS if ( m_cgImageRef ) { CGImageRelease( m_cgImageRef ) ; @@ -328,11 +225,222 @@ void wxBitmapRefData::EndRawAccess() #endif } +bool wxBitmapRefData::HasNativeSize() +{ + int w = GetWidth() ; + int h = GetHeight() ; + int sz = wxMax( w , h ) ; + + if ( sz == 128 || sz == 48 || sz == 32 || sz == 16 ) + return true ; + return false ; +} + +IconRef wxBitmapRefData::GetIconRef() +{ + if ( m_iconRef == NULL ) + { + // Create Icon Family Handle + + IconFamilyHandle iconFamily = NULL ; + + iconFamily = (IconFamilyHandle) NewHandle(8) ; + (**iconFamily).resourceType = kIconFamilyType ; + (**iconFamily).resourceSize = sizeof(OSType) + sizeof(Size); + + int w = GetWidth() ; + int h = GetHeight() ; + int sz = wxMax( w , h ) ; + + OSType dataType = 0 ; + OSType maskType = 0 ; + + if ( sz == 128 ) + { + dataType = kThumbnail32BitData ; + maskType = kThumbnail8BitMask ; + } + else if ( sz == 48 ) + { + dataType = kHuge32BitData ; + maskType = kHuge8BitMask ; + } + else if ( sz == 32 ) + { + dataType = kLarge32BitData ; + maskType = kLarge8BitMask ; + } + else if ( sz == 16 ) + { + dataType = kSmall32BitData ; + maskType = kSmall8BitMask ; + } + + if ( dataType != 0 ) + { + // setup the header properly + + Handle data = NULL ; + Handle maskdata = NULL ; + unsigned char * maskptr = NULL ; + unsigned char * ptr = NULL ; + size_t size ; + size_t masksize ; + + 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 ) ; + + bool hasAlpha = HasAlpha() ; + wxMask *mask = m_bitmapMask ; + unsigned char * source = (unsigned char*) 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 ) ; + } + else + { + iconFamily = (IconFamilyHandle) NewHandle(8) ; + (**iconFamily).resourceType = kIconFamilyType ; + (**iconFamily).resourceSize = sizeof(OSType) + sizeof(Size); + PicHandle pic = GetPictHandle() ; + SetIconFamilyData( iconFamily, 'PICT' , (Handle) pic ) ; + } + + // transform into IconRef + + static int iconCounter = 2 ; + OSStatus err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &m_iconRef ) ; + wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ; + // we have to retain a reference, as Unregister will decrement it + AcquireIconRef( m_iconRef ) ; + UnregisterIconRef( 'WXNG' , (OSType) iconCounter ) ; + DisposeHandle( (Handle) iconFamily ) ; + ++iconCounter ; + } + return m_iconRef ; +} + +PicHandle wxBitmapRefData::GetPictHandle() +{ + if ( m_pictHandle == NULL ) + { + CGrafPtr origPort = NULL ; + GDHandle origDev = NULL ; + GWorldPtr wp = NULL ; + GWorldPtr mask = NULL ; + int height = GetHeight() ; + int width = GetWidth() ; + + Rect rect = { 0 , 0 , height , width } ; + + GetGWorld( &origPort , &origDev ) ; + + wp = GetHBITMAP( &mask ) ; + + RgnHandle clipRgn = NULL ; + + if ( mask ) + { + GWorldPtr monoworld ; + clipRgn = NewRgn() ; + OSStatus err = NewGWorld( &monoworld , 1 , &rect , NULL , NULL , 0 ) ; + verify_noerr(err) ; + LockPixels( GetGWorldPixMap( monoworld ) ) ; + LockPixels( GetGWorldPixMap( mask ) ) ; + SetGWorld( monoworld , NULL ) ; + RGBColor white = { 0xffff ,0xffff , 0xffff } ; + RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ; + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + CopyBits(GetPortBitMapForCopyBits(mask), + GetPortBitMapForCopyBits(monoworld), + &rect, + &rect, + srcCopy,NULL); + BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( monoworld ) ) ; + UnlockPixels( GetGWorldPixMap( monoworld ) ) ; + UnlockPixels( GetGWorldPixMap( mask ) ) ; + DisposeGWorld( monoworld ) ; + } + + SetGWorld( wp , NULL ) ; + Rect portRect ; + GetPortBounds( wp , &portRect ) ; + m_pictHandle = OpenPicture(&portRect); + + if(m_pictHandle) + { + RGBColor white = { 0xffff ,0xffff , 0xffff } ; + RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ; + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + + if ( clipRgn ) + SetClip( clipRgn ) ; + + LockPixels( GetGWorldPixMap( wp ) ) ; + CopyBits(GetPortBitMapForCopyBits(wp), + GetPortBitMapForCopyBits(wp), + &portRect, + &portRect, + srcCopy,clipRgn); + UnlockPixels( GetGWorldPixMap( wp ) ) ; + ClosePicture(); + } + SetGWorld( origPort , origDev ) ; + if ( clipRgn ) + DisposeRgn( clipRgn ) ; + } + return m_pictHandle ; +} #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 @@ -381,7 +489,8 @@ 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 ); @@ -402,7 +511,6 @@ CGImageRef wxBitmapRefData::CGImageCreate() const } #endif -#if !wxMAC_USE_CORE_GRAPHICS GWorldPtr wxBitmapRefData::GetHBITMAP(GWorldPtr* mask) const { wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ); @@ -413,8 +521,14 @@ GWorldPtr wxBitmapRefData::GetHBITMAP(GWorldPtr* mask) const *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 ; } } @@ -434,16 +548,18 @@ void wxBitmapRefData::UpdateAlphaMask() const for ( int y = 0 ; y < h ; ++y , destalphabase += m_maskBytesPerRow ) { unsigned char* destalpha = destalphabase ; - for( int x = 0 ; x < w ; ++x , sourcemask += 4, ++destalpha ) + for( int x = 0 ; x < w ; ++x , sourcemask += 4 ) { - *destalpha = *sourcemask ; + // we must have 24 bit depth for non quartz smooth alpha + *destalpha++ = 255 ; + *destalpha++ = 255 - *sourcemask ; + *destalpha++ = 255 - *sourcemask ; + *destalpha++ = 255 - *sourcemask ; } } } } -#endif - void wxBitmapRefData::Free() { wxASSERT_MSG( m_rawAccessCount == 0 , wxT("Bitmap still selected when destroyed") ) ; @@ -454,7 +570,17 @@ void wxBitmapRefData::Free() CGImageRelease( m_cgImageRef ) ; m_cgImageRef = NULL ; } -#else +#endif + if ( m_iconRef ) + { + ReleaseIconRef( m_iconRef ) ; + m_iconRef = NULL ; + } + if ( m_pictHandle ) + { + KillPicture( m_pictHandle ) ; + m_pictHandle = NULL ; + } if ( m_hBitmap ) { DisposeGWorld( MAC_WXHBITMAP(m_hBitmap) ) ; @@ -465,7 +591,6 @@ void wxBitmapRefData::Free() DisposeGWorld( MAC_WXHBITMAP(m_hMaskBitmap) ) ; m_hMaskBitmap = NULL ; } -#endif if (m_bitmapMask) { @@ -483,39 +608,83 @@ bool wxBitmap::CopyFromIcon(const wxIcon& icon) { int w = icon.GetWidth() ; int h = icon.GetHeight() ; + + Create( icon.GetWidth() , icon.GetHeight() ) ; - if ( w == h && w == 32 ) + bool created = false ; + + 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 ) ) ; - 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 ) + OSType maskType = 0; + OSType dataType = 0; + IconSelectorValue selector = 0 ; + if ( w == 128 ) + { + dataType = kThumbnail32BitData ; + maskType = kThumbnail8BitMask ; + selector = kSelectorAllAvailableData ; + } + else if ( w == 48 ) { - for ( int x = 0 ; x < w ; ++x ) + 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 ; + } + + + 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 ) { - *destination++ = *sourcemask++ ; - source++ ; - *destination++ = *source++ ; - *destination++ = *source++ ; - *destination++ = *source++ ; + for ( int x = 0 ; x < w ; ++x ) + { + *destination++ = *sourcemask++ ; + source++ ; + *destination++ = *source++ ; + *destination++ = *source++ ; + *destination++ = *source++ ; + } } + EndRawAccess() ; + DisposeHandle( imagehandle ) ; + DisposeHandle( maskhandle ) ; } - EndRawAccess() ; - DisposeHandle( imagehandle ) ; - DisposeHandle( maskhandle ) ; + DisposeHandle( (Handle) iconFamily ) ; + } - else + + if ( !created ) { wxMemoryDC dc ; dc.SelectObject( *this ) ; @@ -871,12 +1040,12 @@ wxImage wxBitmap::ConvertToImage() const { if ( r == MASK_RED && g == MASK_GREEN && b == MASK_BLUE ) b = MASK_BLUE_REPLACEMENT ; - } - else - { - r = MASK_RED ; - g = MASK_GREEN ; - b = MASK_BLUE ; + else + { + r = MASK_RED ; + g = MASK_GREEN ; + b = MASK_BLUE ; + } } } else if ( hasAlpha ) @@ -941,11 +1110,15 @@ int wxBitmap::GetDepth() const return M_BITMAPDATA->GetDepth(); } +#if WXWIN_COMPATIBILITY_2_4 + int wxBitmap::GetQuality() const { return 0; } +#endif + wxMask *wxBitmap::GetMask() const { wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") ); @@ -984,10 +1157,14 @@ void wxBitmap::SetDepth(int d) M_BITMAPDATA->SetDepth(d); } +#if WXWIN_COMPATIBILITY_2_4 + void wxBitmap::SetQuality(int WXUNUSED(quality)) { } +#endif + void wxBitmap::SetOk(bool isOk) { if (!M_BITMAPDATA) @@ -1024,12 +1201,10 @@ void wxBitmap::SetMask(wxMask *mask) 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 @@ -1064,22 +1239,17 @@ wxMask::wxMask(const wxMemoryBuffer& data, int width , int height , int bytesPer 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 @@ -1087,9 +1257,11 @@ void *wxMask::GetRawAccess() const return m_memBuf.GetData() ; } +// this can be a k8IndexedGrayPixelFormat GWorld, because it never stores other values than black or white +// so no rainbox colors will be created by QD when blitting + void wxMask::RealizeNative() { -#if !wxMAC_USE_CORE_GRAPHICS if ( m_maskBitmap ) { DisposeGWorld( (GWorldPtr) m_maskBitmap ) ; @@ -1098,7 +1270,6 @@ void wxMask::RealizeNative() 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). @@ -1175,12 +1346,10 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) return TRUE; } -#if !wxMAC_USE_CORE_GRAPHICS WXHBITMAP wxMask::GetHBITMAP() const { return m_maskBitmap ; } -#endif // ---------------------------------------------------------------------------- // wxBitmapHandler @@ -1226,9 +1395,11 @@ public: }; IMPLEMENT_DYNAMIC_CLASS(wxPICTResourceHandler, wxBitmapHandler) + bool wxPICTResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, int desiredWidth, int desiredHeight) { +#if wxUSE_METAFILE Str255 theName ; wxMacStringToPascal( name , theName ) ; @@ -1244,9 +1415,11 @@ bool wxPICTResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, lo dc.SelectObject( wxNullBitmap ) ; return TRUE ; } +#endif //wxUSE_METAFILE return FALSE ; } + void wxBitmap::InitStandardHandlers() { AddHandler(new wxPICTResourceHandler) ;