cleanup for Core Graphics / removing QD
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@46072 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -49,6 +49,19 @@ IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
|
|||||||
// we don't dare use premultiplied alpha yet
|
// we don't dare use premultiplied alpha yet
|
||||||
#define wxMAC_USE_PREMULTIPLIED_ALPHA 0
|
#define wxMAC_USE_PREMULTIPLIED_ALPHA 0
|
||||||
|
|
||||||
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
static const int kBestByteAlignement = 16;
|
||||||
|
static const int kMaskBytesPerPixel = 1;
|
||||||
|
#else
|
||||||
|
static const int kBestByteAlignement = 4;
|
||||||
|
static const int kMaskBytesPerPixel = 4;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int GetBestBytesPerRow( int rawBytes )
|
||||||
|
{
|
||||||
|
return (((rawBytes)+kBestByteAlignement-1) & ~(kBestByteAlignement-1) );
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_BMPBUTTON
|
#if wxUSE_BMPBUTTON
|
||||||
|
|
||||||
void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType )
|
void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType )
|
||||||
@@ -60,7 +73,20 @@ void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bi
|
|||||||
if ( bmap == NULL )
|
if ( bmap == NULL )
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
if ( ( bmap->HasNativeSize() && forceType == 0 ) || forceType == kControlContentIconRef )
|
if ( forceType == 0 )
|
||||||
|
{
|
||||||
|
if ( UMAGetSystemVersion() > 0x1040 )
|
||||||
|
{
|
||||||
|
// as soon as it is supported, it's a better default
|
||||||
|
forceType = kControlContentCGImageRef;
|
||||||
|
}
|
||||||
|
else if ( bmap->HasNativeSize() )
|
||||||
|
{
|
||||||
|
forceType = kControlContentIconRef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( forceType == kControlContentIconRef )
|
||||||
{
|
{
|
||||||
wxBitmap scaleBmp ;
|
wxBitmap scaleBmp ;
|
||||||
wxBitmapRefData* bmp = bmap ;
|
wxBitmapRefData* bmp = bmap ;
|
||||||
@@ -84,13 +110,11 @@ void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bi
|
|||||||
info->u.iconRef = bmp->GetIconRef() ;
|
info->u.iconRef = bmp->GetIconRef() ;
|
||||||
AcquireIconRef( info->u.iconRef ) ;
|
AcquireIconRef( info->u.iconRef ) ;
|
||||||
}
|
}
|
||||||
#if defined( __WXMAC_OSX__ ) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
|
|
||||||
else if ( forceType == kControlContentCGImageRef )
|
else if ( forceType == kControlContentCGImageRef )
|
||||||
{
|
{
|
||||||
info->contentType = kControlContentCGImageRef ;
|
info->contentType = kControlContentCGImageRef ;
|
||||||
info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ;
|
info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifndef __LP64__
|
#ifndef __LP64__
|
||||||
@@ -146,8 +170,10 @@ void wxBitmapRefData::Init()
|
|||||||
m_iconRef = NULL ;
|
m_iconRef = NULL ;
|
||||||
m_pictHandle = NULL ;
|
m_pictHandle = NULL ;
|
||||||
m_hBitmap = NULL ;
|
m_hBitmap = NULL ;
|
||||||
|
#if! wxMAC_USE_CORE_GRAPHICS
|
||||||
m_hMaskBitmap = NULL;
|
m_hMaskBitmap = NULL;
|
||||||
m_maskBytesPerRow = 0 ;
|
m_maskBytesPerRow = 0 ;
|
||||||
|
#endif
|
||||||
|
|
||||||
m_rawAccessCount = 0 ;
|
m_rawAccessCount = 0 ;
|
||||||
m_hasAlpha = false;
|
m_hasAlpha = false;
|
||||||
@@ -171,8 +197,6 @@ wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData &tocopy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
UseAlpha(tocopy.m_hasAlpha);
|
UseAlpha(tocopy.m_hasAlpha);
|
||||||
|
|
||||||
// TODO: Copy palette?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmapRefData::wxBitmapRefData()
|
wxBitmapRefData::wxBitmapRefData()
|
||||||
@@ -192,15 +216,15 @@ bool wxBitmapRefData::Create( int w , int h , int d )
|
|||||||
m_height = wxMax(1, h);
|
m_height = wxMax(1, h);
|
||||||
m_depth = d ;
|
m_depth = d ;
|
||||||
|
|
||||||
m_bytesPerRow = w * 4 ;
|
m_bytesPerRow = GetBestBytesPerRow( w * 4 ) ;
|
||||||
size_t size = m_bytesPerRow * h ;
|
size_t size = m_bytesPerRow * h ;
|
||||||
void* data = m_memBuf.GetWriteBuf( size ) ;
|
void* data = m_memBuf.GetWriteBuf( size ) ;
|
||||||
memset( data , 0 , size ) ;
|
memset( data , 0 , size ) ;
|
||||||
m_memBuf.UngetWriteBuf( size ) ;
|
m_memBuf.UngetWriteBuf( size ) ;
|
||||||
|
|
||||||
m_hBitmap = NULL ;
|
m_hBitmap = NULL ;
|
||||||
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
Rect rect = { 0 , 0 , m_height , m_width } ;
|
Rect rect = { 0 , 0 , m_height , m_width } ;
|
||||||
#ifndef __LP64__
|
|
||||||
verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
|
verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
|
||||||
(char*) data , m_bytesPerRow ) ) ;
|
(char*) data , m_bytesPerRow ) ) ;
|
||||||
wxASSERT_MSG( m_hBitmap , wxT("Unable to create GWorld context") ) ;
|
wxASSERT_MSG( m_hBitmap , wxT("Unable to create GWorld context") ) ;
|
||||||
@@ -219,38 +243,41 @@ void wxBitmapRefData::UseAlpha( bool use )
|
|||||||
return ;
|
return ;
|
||||||
|
|
||||||
m_hasAlpha = use ;
|
m_hasAlpha = use ;
|
||||||
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
CGContextRelease( m_hBitmap );
|
||||||
|
m_hBitmap = CGBitmapContextCreate((char*) m_memBuf.GetData(), m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), m_hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst );
|
||||||
|
wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
|
||||||
|
#else
|
||||||
if ( m_hasAlpha )
|
if ( m_hasAlpha )
|
||||||
{
|
{
|
||||||
wxASSERT( m_hMaskBitmap == NULL ) ;
|
wxASSERT( m_hMaskBitmap == NULL ) ;
|
||||||
|
|
||||||
int width = GetWidth() ;
|
int width = GetWidth() ;
|
||||||
int height = GetHeight() ;
|
int height = GetHeight() ;
|
||||||
m_maskBytesPerRow = ( width * 4 + 3 ) & 0xFFFFFFC ;
|
m_maskBytesPerRow = GetBestBytesPerRow( width * kMaskBytesPerPixel );
|
||||||
size_t size = height * m_maskBytesPerRow ;
|
size_t size = height * m_maskBytesPerRow ;
|
||||||
unsigned char * data = (unsigned char * ) m_maskMemBuf.GetWriteBuf( size ) ;
|
unsigned char * data = (unsigned char * ) m_maskMemBuf.GetWriteBuf( size ) ;
|
||||||
wxASSERT( data != NULL ) ;
|
wxASSERT( data != NULL ) ;
|
||||||
|
|
||||||
memset( data , 0 , size ) ;
|
memset( data , 0 , size ) ;
|
||||||
Rect rect = { 0 , 0 , height , width } ;
|
Rect rect = { 0 , 0 , height , width } ;
|
||||||
#ifndef __LP64__
|
|
||||||
verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hMaskBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
|
verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hMaskBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
|
||||||
(char*) data , m_maskBytesPerRow ) ) ;
|
(char*) data , m_maskBytesPerRow ) ) ;
|
||||||
wxASSERT_MSG( m_hMaskBitmap , wxT("Unable to create GWorld context for alpha mask") ) ;
|
wxASSERT_MSG( m_hMaskBitmap , wxT("Unable to create GWorld context for alpha mask") ) ;
|
||||||
#endif
|
|
||||||
m_maskMemBuf.UngetWriteBuf(size) ;
|
m_maskMemBuf.UngetWriteBuf(size) ;
|
||||||
|
|
||||||
#if !wxMAC_USE_CORE_GRAPHICS
|
|
||||||
UpdateAlphaMask() ;
|
UpdateAlphaMask() ;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifndef __LP64__
|
|
||||||
DisposeGWorld( m_hMaskBitmap ) ;
|
DisposeGWorld( m_hMaskBitmap ) ;
|
||||||
#endif
|
|
||||||
m_hMaskBitmap = NULL ;
|
m_hMaskBitmap = NULL ;
|
||||||
m_maskBytesPerRow = 0 ;
|
m_maskBytesPerRow = 0 ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void *wxBitmapRefData::GetRawAccess() const
|
void *wxBitmapRefData::GetRawAccess() const
|
||||||
@@ -331,39 +358,59 @@ IconRef wxBitmapRefData::GetIconRef()
|
|||||||
switch (sz)
|
switch (sz)
|
||||||
{
|
{
|
||||||
case 128:
|
case 128:
|
||||||
#if 0 // for later
|
#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||||
dataType = kIconServices128PixelDataARGB ;
|
if ( UMAGetSystemVersion() >= 0x1050 )
|
||||||
#else
|
{
|
||||||
dataType = kThumbnail32BitData ;
|
dataType = kIconServices128PixelDataARGB ;
|
||||||
maskType = kThumbnail8BitMask ;
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
dataType = kThumbnail32BitData ;
|
||||||
|
maskType = kThumbnail8BitMask ;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 48:
|
case 48:
|
||||||
#if 0 // for later
|
#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||||
dataType = kIconServices48PixelDataARGB ;
|
if ( UMAGetSystemVersion() >= 0x1050 )
|
||||||
#else
|
{
|
||||||
dataType = kHuge32BitData ;
|
dataType = kIconServices48PixelDataARGB ;
|
||||||
maskType = kHuge8BitMask ;
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
dataType = kHuge32BitData ;
|
||||||
|
maskType = kHuge8BitMask ;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 32:
|
case 32:
|
||||||
#if 0 // for later
|
#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||||
dataType = kIconServices32PixelDataARGB ;
|
if ( UMAGetSystemVersion() >= 0x1050 )
|
||||||
#else
|
{
|
||||||
dataType = kLarge32BitData ;
|
dataType = kIconServices32PixelDataARGB ;
|
||||||
maskType = kLarge8BitMask ;
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
dataType = kLarge32BitData ;
|
||||||
|
maskType = kLarge8BitMask ;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 16:
|
case 16:
|
||||||
#if 0 // for later
|
#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||||
dataType = kIconServices16PixelDataARGB ;
|
if ( UMAGetSystemVersion() >= 0x1050 )
|
||||||
#else
|
{
|
||||||
dataType = kSmall32BitData ;
|
dataType = kIconServices16PixelDataARGB ;
|
||||||
maskType = kSmall8BitMask ;
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
dataType = kSmall32BitData ;
|
||||||
|
maskType = kSmall8BitMask ;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -372,81 +419,90 @@ IconRef wxBitmapRefData::GetIconRef()
|
|||||||
|
|
||||||
if ( dataType != 0 )
|
if ( dataType != 0 )
|
||||||
{
|
{
|
||||||
#if 0 // for later
|
#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
||||||
Handle data = NULL ;
|
if ( UMAGetSystemVersion() >= 0x1050 )
|
||||||
PtrToHand(GetRawAccess(), &data, sz * sz * 4);
|
|
||||||
OSStatus err = SetIconFamilyData( iconFamily, dataType , data );
|
|
||||||
wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") );
|
|
||||||
DisposeHandle( data );
|
|
||||||
#else
|
|
||||||
// setup the header properly
|
|
||||||
|
|
||||||
Handle data = NULL ;
|
|
||||||
Handle maskdata = NULL ;
|
|
||||||
unsigned char * maskptr = NULL ;
|
|
||||||
unsigned char * ptr = NULL ;
|
|
||||||
size_t datasize, masksize ;
|
|
||||||
|
|
||||||
datasize = sz * sz * 4 ;
|
|
||||||
data = NewHandle( datasize ) ;
|
|
||||||
HLock( data ) ;
|
|
||||||
ptr = (unsigned char*) *data ;
|
|
||||||
memset( ptr , 0, datasize ) ;
|
|
||||||
|
|
||||||
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 ;
|
Handle data = NULL ;
|
||||||
unsigned char * maskdest = maskptr + y * sz ;
|
PtrToHand(GetRawAccess(), &data, sz * sz * 4);
|
||||||
unsigned char a, r, g, b;
|
OSStatus err = SetIconFamilyData( iconFamily, dataType , data );
|
||||||
|
wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") );
|
||||||
for ( int x = 0 ; x < w ; ++x )
|
DisposeHandle( data );
|
||||||
{
|
|
||||||
a = *source ++ ;
|
|
||||||
r = *source ++ ;
|
|
||||||
g = *source ++ ;
|
|
||||||
b = *source ++ ;
|
|
||||||
|
|
||||||
*dest++ = 0 ;
|
|
||||||
*dest++ = r ;
|
|
||||||
*dest++ = g ;
|
|
||||||
*dest++ = b ;
|
|
||||||
|
|
||||||
if ( mask )
|
|
||||||
{
|
|
||||||
*maskdest++ = 0xFF - *masksource++ ;
|
|
||||||
masksource++ ;
|
|
||||||
masksource++ ;
|
|
||||||
masksource++ ;
|
|
||||||
}
|
|
||||||
else if ( hasAlpha )
|
|
||||||
*maskdest++ = a ;
|
|
||||||
else
|
|
||||||
*maskdest++ = 0xFF ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
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 ) ;
|
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
// setup the header properly
|
||||||
|
|
||||||
|
Handle data = NULL ;
|
||||||
|
Handle maskdata = NULL ;
|
||||||
|
unsigned char * maskptr = NULL ;
|
||||||
|
unsigned char * ptr = NULL ;
|
||||||
|
size_t datasize, masksize ;
|
||||||
|
|
||||||
|
datasize = sz * sz * 4 ;
|
||||||
|
data = NewHandle( datasize ) ;
|
||||||
|
HLock( data ) ;
|
||||||
|
ptr = (unsigned char*) *data ;
|
||||||
|
memset( ptr , 0, datasize ) ;
|
||||||
|
|
||||||
|
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 * sourcePtr = (unsigned char*) GetRawAccess() ;
|
||||||
|
unsigned char * masksourcePtr = mask ? (unsigned char*) mask->GetRawAccess() : NULL ;
|
||||||
|
|
||||||
|
for ( int y = 0 ; y < h ; ++y, sourcePtr += m_bytesPerRow , masksourcePtr += mask->GetBytesPerRow() )
|
||||||
|
{
|
||||||
|
unsigned char * source = sourcePtr;
|
||||||
|
unsigned char * masksource = masksourcePtr;
|
||||||
|
unsigned char * dest = ptr + y * sz * 4 ;
|
||||||
|
unsigned char * maskdest = maskptr + y * sz ;
|
||||||
|
unsigned char a, r, g, b;
|
||||||
|
|
||||||
|
for ( int x = 0 ; x < w ; ++x )
|
||||||
|
{
|
||||||
|
a = *source ++ ;
|
||||||
|
r = *source ++ ;
|
||||||
|
g = *source ++ ;
|
||||||
|
b = *source ++ ;
|
||||||
|
|
||||||
|
*dest++ = 0 ;
|
||||||
|
*dest++ = r ;
|
||||||
|
*dest++ = g ;
|
||||||
|
*dest++ = b ;
|
||||||
|
|
||||||
|
if ( mask )
|
||||||
|
{
|
||||||
|
*maskdest++ = 0xFF - *masksource++ ;
|
||||||
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
|
masksource++ ;
|
||||||
|
masksource++ ;
|
||||||
|
masksource++ ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -454,23 +510,12 @@ IconRef wxBitmapRefData::GetIconRef()
|
|||||||
SetIconFamilyData( iconFamily, 'PICT' , (Handle) pic ) ;
|
SetIconFamilyData( iconFamily, 'PICT' , (Handle) pic ) ;
|
||||||
}
|
}
|
||||||
// transform into IconRef
|
// transform into IconRef
|
||||||
#if defined( __WXMAC_OSX__ ) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
|
|
||||||
// cleaner version existing from 10.3 upwards
|
// cleaner version existing from 10.3 upwards
|
||||||
HLock((Handle) iconFamily);
|
HLock((Handle) iconFamily);
|
||||||
OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &m_iconRef );
|
OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &m_iconRef );
|
||||||
HUnlock((Handle) iconFamily);
|
HUnlock((Handle) iconFamily);
|
||||||
wxASSERT_MSG( err == noErr , wxT("Error when constructing icon ref") );
|
wxASSERT_MSG( err == noErr , wxT("Error when constructing icon ref") );
|
||||||
#else
|
|
||||||
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 ) ;
|
|
||||||
++iconCounter ;
|
|
||||||
#endif
|
|
||||||
DisposeHandle( (Handle) iconFamily ) ;
|
DisposeHandle( (Handle) iconFamily ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,7 +526,7 @@ PicHandle wxBitmapRefData::GetPictHandle()
|
|||||||
{
|
{
|
||||||
if ( m_pictHandle == NULL )
|
if ( m_pictHandle == NULL )
|
||||||
{
|
{
|
||||||
#ifndef __LP64__
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
CGrafPtr origPort = NULL ;
|
CGrafPtr origPort = NULL ;
|
||||||
GDHandle origDev = NULL ;
|
GDHandle origDev = NULL ;
|
||||||
GWorldPtr wp = NULL ;
|
GWorldPtr wp = NULL ;
|
||||||
@@ -574,7 +619,7 @@ CGImageRef wxBitmapRefData::CGImageCreate() const
|
|||||||
CGImageRef image ;
|
CGImageRef image ;
|
||||||
if ( m_rawAccessCount > 0 || m_cgImageRef == NULL )
|
if ( m_rawAccessCount > 0 || m_cgImageRef == NULL )
|
||||||
{
|
{
|
||||||
size_t imageSize = m_width * m_height * 4 ;
|
size_t imageSize = m_height * m_bytesPerRow ;
|
||||||
void * dataBuffer = m_memBuf.GetData() ;
|
void * dataBuffer = m_memBuf.GetData() ;
|
||||||
int w = m_width ;
|
int w = m_width ;
|
||||||
int h = m_height ;
|
int h = m_height ;
|
||||||
@@ -588,11 +633,12 @@ CGImageRef wxBitmapRefData::CGImageCreate() const
|
|||||||
memcpy( membuf->GetData() , dataBuffer , imageSize ) ;
|
memcpy( membuf->GetData() , dataBuffer , imageSize ) ;
|
||||||
unsigned char *sourcemaskstart = (unsigned char *) m_bitmapMask->GetRawAccess() ;
|
unsigned char *sourcemaskstart = (unsigned char *) m_bitmapMask->GetRawAccess() ;
|
||||||
int maskrowbytes = m_bitmapMask->GetBytesPerRow() ;
|
int maskrowbytes = m_bitmapMask->GetBytesPerRow() ;
|
||||||
unsigned char *destalpha = (unsigned char *) membuf->GetData() ;
|
unsigned char *destalphastart = (unsigned char *) membuf->GetData() ;
|
||||||
for ( int y = 0 ; y < h ; ++y , sourcemaskstart += maskrowbytes)
|
for ( int y = 0 ; y < h ; ++y , destalphastart += m_bytesPerRow, sourcemaskstart += maskrowbytes)
|
||||||
{
|
{
|
||||||
unsigned char *sourcemask = sourcemaskstart ;
|
unsigned char *sourcemask = sourcemaskstart ;
|
||||||
for ( int x = 0 ; x < w ; ++x , sourcemask += 4 , destalpha += 4 )
|
unsigned char *destalpha = destalphastart ;
|
||||||
|
for ( int x = 0 ; x < w ; ++x , sourcemask += kMaskBytesPerPixel , destalpha += 4 )
|
||||||
{
|
{
|
||||||
*destalpha = 0xFF - *sourcemask ;
|
*destalpha = 0xFF - *sourcemask ;
|
||||||
}
|
}
|
||||||
@@ -640,7 +686,7 @@ CGImageRef wxBitmapRefData::CGImageCreate() const
|
|||||||
wxMacMemoryBufferReleaseProc );
|
wxMacMemoryBufferReleaseProc );
|
||||||
image =
|
image =
|
||||||
::CGImageCreate(
|
::CGImageCreate(
|
||||||
w, h, 8 , 32 , 4 * m_width , colorSpace, alphaInfo ,
|
w, h, 8 , 32 , m_bytesPerRow , colorSpace, alphaInfo ,
|
||||||
dataProvider, NULL , false , kCGRenderingIntentDefault );
|
dataProvider, NULL , false , kCGRenderingIntentDefault );
|
||||||
}
|
}
|
||||||
CGDataProviderRelease( dataProvider);
|
CGDataProviderRelease( dataProvider);
|
||||||
@@ -662,11 +708,13 @@ CGImageRef wxBitmapRefData::CGImageCreate() const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __LP64__
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
GWorldPtr wxBitmapRefData::GetHBITMAP(GWorldPtr* mask) const
|
CGContextRef wxBitmapRefData::GetBitmapContext() const
|
||||||
|
{
|
||||||
|
return m_hBitmap;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
CGContextRef wxBitmapRefData::GetHBITMAP(CGContextRef* mask) const
|
GWorldPtr wxBitmapRefData::GetHBITMAP(GWorldPtr* mask) const
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
|
wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
|
||||||
if ( mask )
|
if ( mask )
|
||||||
@@ -674,32 +722,21 @@ CGContextRef wxBitmapRefData::GetHBITMAP(CGContextRef* mask) const
|
|||||||
*mask = NULL ;
|
*mask = NULL ;
|
||||||
if ( m_bitmapMask )
|
if ( m_bitmapMask )
|
||||||
{
|
{
|
||||||
*mask =
|
*mask = (GWorldPtr) m_bitmapMask->GetHBITMAP() ;
|
||||||
#ifndef __LP64__
|
|
||||||
(GWorldPtr)
|
|
||||||
#else
|
|
||||||
(CGContextRef)
|
|
||||||
#endif
|
|
||||||
m_bitmapMask->GetHBITMAP() ;
|
|
||||||
}
|
}
|
||||||
else if ( m_hasAlpha )
|
else if ( m_hasAlpha )
|
||||||
{
|
{
|
||||||
#if !wxMAC_USE_CORE_GRAPHICS
|
|
||||||
if ( m_rawAccessCount > 0 )
|
if ( m_rawAccessCount > 0 )
|
||||||
UpdateAlphaMask() ;
|
UpdateAlphaMask() ;
|
||||||
#else
|
|
||||||
// this structure is not kept in synch when using CG, so if something
|
|
||||||
// is really accessing the GrafPorts, we have to sync it
|
|
||||||
UpdateAlphaMask() ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*mask = m_hMaskBitmap ;
|
*mask = m_hMaskBitmap ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_hBitmap ;
|
return m_hBitmap ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
void wxBitmapRefData::UpdateAlphaMask() const
|
void wxBitmapRefData::UpdateAlphaMask() const
|
||||||
{
|
{
|
||||||
if ( m_hasAlpha )
|
if ( m_hasAlpha )
|
||||||
@@ -725,6 +762,7 @@ void wxBitmapRefData::UpdateAlphaMask() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void wxBitmapRefData::Free()
|
void wxBitmapRefData::Free()
|
||||||
{
|
{
|
||||||
@@ -754,7 +792,7 @@ void wxBitmapRefData::Free()
|
|||||||
|
|
||||||
if ( m_hBitmap )
|
if ( m_hBitmap )
|
||||||
{
|
{
|
||||||
#ifndef __LP64__
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
DisposeGWorld( MAC_WXHBITMAP(m_hBitmap) ) ;
|
DisposeGWorld( MAC_WXHBITMAP(m_hBitmap) ) ;
|
||||||
#else
|
#else
|
||||||
CGContextRelease(m_hBitmap);
|
CGContextRelease(m_hBitmap);
|
||||||
@@ -762,15 +800,13 @@ void wxBitmapRefData::Free()
|
|||||||
m_hBitmap = NULL ;
|
m_hBitmap = NULL ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
if ( m_hMaskBitmap )
|
if ( m_hMaskBitmap )
|
||||||
{
|
{
|
||||||
#ifndef __LP64__
|
|
||||||
DisposeGWorld( MAC_WXHBITMAP(m_hMaskBitmap) ) ;
|
DisposeGWorld( MAC_WXHBITMAP(m_hMaskBitmap) ) ;
|
||||||
#else
|
|
||||||
CGContextRelease(m_hMaskBitmap);
|
|
||||||
#endif
|
|
||||||
m_hMaskBitmap = NULL ;
|
m_hMaskBitmap = NULL ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (m_bitmapMask)
|
if (m_bitmapMask)
|
||||||
{
|
{
|
||||||
delete m_bitmapMask;
|
delete m_bitmapMask;
|
||||||
@@ -900,10 +936,11 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
|
|||||||
linesize += sizeof(unsigned char);
|
linesize += sizeof(unsigned char);
|
||||||
|
|
||||||
unsigned char* linestart = (unsigned char*) bits ;
|
unsigned char* linestart = (unsigned char*) bits ;
|
||||||
unsigned char* destination = (unsigned char*) BeginRawAccess() ;
|
unsigned char* destptr = (unsigned char*) BeginRawAccess() ;
|
||||||
|
|
||||||
for ( int y = 0 ; y < the_height ; ++y , linestart += linesize )
|
for ( int y = 0 ; y < the_height ; ++y , linestart += linesize, destptr += M_BITMAPDATA->GetBytesPerRow() )
|
||||||
{
|
{
|
||||||
|
unsigned char* destination = destptr;
|
||||||
int index, bit, mask;
|
int index, bit, mask;
|
||||||
|
|
||||||
for ( int x = 0 ; x < the_width ; ++x )
|
for ( int x = 0 ; x < the_width ; ++x )
|
||||||
@@ -1143,14 +1180,14 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
|
|||||||
if ( hasAlpha )
|
if ( hasAlpha )
|
||||||
UseAlpha() ;
|
UseAlpha() ;
|
||||||
|
|
||||||
unsigned char* destination = (unsigned char*) BeginRawAccess() ;
|
unsigned char* destinationstart = (unsigned char*) BeginRawAccess() ;
|
||||||
register unsigned char* data = image.GetData();
|
register unsigned char* data = image.GetData();
|
||||||
if ( destination != NULL && data != NULL )
|
if ( destinationstart != NULL && data != NULL )
|
||||||
{
|
{
|
||||||
const unsigned char *alpha = hasAlpha ? image.GetAlpha() : NULL ;
|
const unsigned char *alpha = hasAlpha ? image.GetAlpha() : NULL ;
|
||||||
|
for (int y = 0; y < height; destinationstart += M_BITMAPDATA->GetBytesPerRow(), y++)
|
||||||
for (int y = 0; y < height; y++)
|
|
||||||
{
|
{
|
||||||
|
unsigned char * destination = destinationstart;
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
if ( hasAlpha )
|
if ( hasAlpha )
|
||||||
@@ -1198,7 +1235,7 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
unsigned char *data = image.GetData();
|
unsigned char *data = image.GetData();
|
||||||
wxCHECK_MSG( data, wxNullImage, wxT("Could not allocate data for image") );
|
wxCHECK_MSG( data, wxNullImage, wxT("Could not allocate data for image") );
|
||||||
|
|
||||||
unsigned char* source = (unsigned char*) GetRawAccess() ;
|
unsigned char* sourcestart = (unsigned char*) GetRawAccess() ;
|
||||||
|
|
||||||
bool hasAlpha = false ;
|
bool hasAlpha = false ;
|
||||||
bool hasMask = false ;
|
bool hasMask = false ;
|
||||||
@@ -1232,9 +1269,10 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
static const int MASK_BLUE = 3;
|
static const int MASK_BLUE = 3;
|
||||||
static const int MASK_BLUE_REPLACEMENT = 2;
|
static const int MASK_BLUE_REPLACEMENT = 2;
|
||||||
|
|
||||||
for (int yy = 0; yy < height; yy++ , mask += maskBytesPerRow )
|
for (int yy = 0; yy < height; yy++ , sourcestart += M_BITMAPDATA->GetBytesPerRow() , mask += maskBytesPerRow )
|
||||||
{
|
{
|
||||||
unsigned char * maskp = mask ;
|
unsigned char * maskp = mask ;
|
||||||
|
unsigned char * source = sourcestart;
|
||||||
unsigned char a, r, g, b;
|
unsigned char a, r, g, b;
|
||||||
long color;
|
long color;
|
||||||
|
|
||||||
@@ -1411,10 +1449,10 @@ void wxBitmap::SetMask(wxMask *mask)
|
|||||||
|
|
||||||
WXHBITMAP wxBitmap::GetHBITMAP(WXHBITMAP* mask) const
|
WXHBITMAP wxBitmap::GetHBITMAP(WXHBITMAP* mask) const
|
||||||
{
|
{
|
||||||
#ifdef __LP64__
|
#ifndef __LP64__
|
||||||
return WXHBITMAP(M_BITMAPDATA->GetHBITMAP((CGContextRef*)mask));
|
return WXHBITMAP(M_BITMAPDATA->GetHBITMAP((CGContextRef*)mask));
|
||||||
#else
|
#else
|
||||||
return WXHBITMAP(M_BITMAPDATA->GetHBITMAP((GWorldPtr*)mask));
|
return WXHBITMAP(M_BITMAPDATA->GetBitmapContext());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1472,13 +1510,15 @@ wxMask::wxMask( const wxMemoryBuffer& data, int width , int height , int bytesPe
|
|||||||
|
|
||||||
wxMask::~wxMask()
|
wxMask::~wxMask()
|
||||||
{
|
{
|
||||||
#ifndef __LP64__
|
|
||||||
if ( m_maskBitmap )
|
if ( m_maskBitmap )
|
||||||
{
|
{
|
||||||
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
CGContextRelease( (CGContextRef) m_maskBitmap );
|
||||||
|
#else
|
||||||
DisposeGWorld( (GWorldPtr)m_maskBitmap ) ;
|
DisposeGWorld( (GWorldPtr)m_maskBitmap ) ;
|
||||||
|
#endif
|
||||||
m_maskBitmap = NULL ;
|
m_maskBitmap = NULL ;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMask::Init()
|
void wxMask::Init()
|
||||||
@@ -1497,13 +1537,21 @@ void *wxMask::GetRawAccess() const
|
|||||||
|
|
||||||
void wxMask::RealizeNative()
|
void wxMask::RealizeNative()
|
||||||
{
|
{
|
||||||
#ifndef __LP64__
|
|
||||||
if ( m_maskBitmap )
|
if ( m_maskBitmap )
|
||||||
{
|
{
|
||||||
DisposeGWorld( (GWorldPtr)m_maskBitmap ) ;
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
m_maskBitmap = NULL ;
|
CGContextRelease( (CGContextRef) m_maskBitmap );
|
||||||
|
#else
|
||||||
|
DisposeGWorld( (GWorldPtr)m_maskBitmap ) ;
|
||||||
|
#endif
|
||||||
|
m_maskBitmap = NULL ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
m_maskBitmap = CGBitmapContextCreate((char*) m_memBuf.GetData(), m_width, m_height, 8, m_bytesPerRow, NULL,
|
||||||
|
kCGImageAlphaOnly );
|
||||||
|
wxASSERT_MSG( m_maskBitmap , wxT("Unable to create CGBitmapContext context") ) ;
|
||||||
|
#else
|
||||||
Rect rect = { 0 , 0 , m_height , m_width } ;
|
Rect rect = { 0 , 0 , m_height , m_width } ;
|
||||||
|
|
||||||
OSStatus err = NewGWorldFromPtr(
|
OSStatus err = NewGWorldFromPtr(
|
||||||
@@ -1534,7 +1582,7 @@ bool wxMask::Create(const wxBitmap& bitmap)
|
|||||||
{
|
{
|
||||||
m_width = bitmap.GetWidth() ;
|
m_width = bitmap.GetWidth() ;
|
||||||
m_height = bitmap.GetHeight() ;
|
m_height = bitmap.GetHeight() ;
|
||||||
m_bytesPerRow = ( m_width * 4 + 3 ) & 0xFFFFFFC ;
|
m_bytesPerRow = GetBestBytesPerRow( m_width * kMaskBytesPerPixel ) ;
|
||||||
|
|
||||||
size_t size = m_bytesPerRow * m_height ;
|
size_t size = m_bytesPerRow * m_height ;
|
||||||
unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
|
unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
|
||||||
@@ -1558,16 +1606,20 @@ bool wxMask::Create(const wxBitmap& bitmap)
|
|||||||
if ( ( r + g + b ) > 0x10 )
|
if ( ( r + g + b ) > 0x10 )
|
||||||
{
|
{
|
||||||
*destdata++ = 0xFF ;
|
*destdata++ = 0xFF ;
|
||||||
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
*destdata++ = 0xFF ;
|
*destdata++ = 0xFF ;
|
||||||
*destdata++ = 0xFF ;
|
*destdata++ = 0xFF ;
|
||||||
*destdata++ = 0xFF ;
|
*destdata++ = 0xFF ;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*destdata++ = 0x00 ;
|
*destdata++ = 0x00 ;
|
||||||
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
*destdata++ = 0x00 ;
|
*destdata++ = 0x00 ;
|
||||||
*destdata++ = 0x00 ;
|
*destdata++ = 0x00 ;
|
||||||
*destdata++ = 0x00 ;
|
*destdata++ = 0x00 ;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1584,7 +1636,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
|
|||||||
{
|
{
|
||||||
m_width = bitmap.GetWidth() ;
|
m_width = bitmap.GetWidth() ;
|
||||||
m_height = bitmap.GetHeight() ;
|
m_height = bitmap.GetHeight() ;
|
||||||
m_bytesPerRow = ( m_width * 4 + 3 ) & 0xFFFFFFC ;
|
m_bytesPerRow = GetBestBytesPerRow( m_width * 4 ) ;
|
||||||
|
|
||||||
size_t size = m_bytesPerRow * m_height ;
|
size_t size = m_bytesPerRow * m_height ;
|
||||||
unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
|
unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
|
||||||
@@ -1608,16 +1660,20 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
|
|||||||
if ( colour == wxColour( r , g , b ) )
|
if ( colour == wxColour( r , g , b ) )
|
||||||
{
|
{
|
||||||
*destdata++ = 0xFF ;
|
*destdata++ = 0xFF ;
|
||||||
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
*destdata++ = 0xFF ;
|
*destdata++ = 0xFF ;
|
||||||
*destdata++ = 0xFF ;
|
*destdata++ = 0xFF ;
|
||||||
*destdata++ = 0xFF ;
|
*destdata++ = 0xFF ;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*destdata++ = 0x00 ;
|
*destdata++ = 0x00 ;
|
||||||
|
#if !wxMAC_USE_CORE_GRAPHICS
|
||||||
*destdata++ = 0x00 ;
|
*destdata++ = 0x00 ;
|
||||||
*destdata++ = 0x00 ;
|
*destdata++ = 0x00 ;
|
||||||
*destdata++ = 0x00 ;
|
*destdata++ = 0x00 ;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -284,7 +284,11 @@ bool wxClipboard::AddData( wxDataObject *data )
|
|||||||
|
|
||||||
case wxDF_BITMAP:
|
case wxDF_BITMAP:
|
||||||
case wxDF_DIB:
|
case wxDF_DIB:
|
||||||
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
mactype = 'TIFF';
|
||||||
|
#else
|
||||||
mactype = kScrapFlavorTypePicture;
|
mactype = kScrapFlavorTypePicture;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
#ifndef __DARWIN__
|
#ifndef __DARWIN__
|
||||||
#include <Scrap.h>
|
#include <Scrap.h>
|
||||||
|
#else
|
||||||
|
#include <QuickTime/QuickTime.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -79,6 +81,12 @@ void wxDataFormat::SetType( wxDataFormatId dataType )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case wxDF_BITMAP:
|
case wxDF_BITMAP:
|
||||||
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
m_format = 'TIFF';
|
||||||
|
#else
|
||||||
|
m_format = kScrapFlavorTypePicture;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
case wxDF_METAFILE:
|
case wxDF_METAFILE:
|
||||||
m_format = kScrapFlavorTypePicture;
|
m_format = kScrapFlavorTypePicture;
|
||||||
break;
|
break;
|
||||||
@@ -119,9 +127,14 @@ void wxDataFormat::SetId( NativeFormat format )
|
|||||||
m_type = wxDF_UNICODETEXT;
|
m_type = wxDF_UNICODETEXT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kScrapFlavorTypePicture:
|
#if wxMAC_USE_CORE_GRAPHCIS
|
||||||
|
case 'TIFF':
|
||||||
m_type = wxDF_BITMAP;
|
m_type = wxDF_BITMAP;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
case kScrapFlavorTypePicture:
|
||||||
|
m_type = wxDF_METAFILE;
|
||||||
|
break;
|
||||||
|
|
||||||
case kDragFlavorTypeHFS:
|
case kDragFlavorTypeHFS:
|
||||||
m_type = wxDF_FILENAME;
|
m_type = wxDF_FILENAME;
|
||||||
@@ -280,8 +293,12 @@ wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& rBitmap )
|
|||||||
|
|
||||||
if (m_bitmap.Ok())
|
if (m_bitmap.Ok())
|
||||||
{
|
{
|
||||||
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
SetBitmap( rBitmap );
|
||||||
|
#else
|
||||||
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
|
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
|
||||||
m_pictCreated = false;
|
m_pictCreated = false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,8 +313,30 @@ void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap )
|
|||||||
wxBitmapDataObjectBase::SetBitmap( rBitmap );
|
wxBitmapDataObjectBase::SetBitmap( rBitmap );
|
||||||
if (m_bitmap.Ok())
|
if (m_bitmap.Ok())
|
||||||
{
|
{
|
||||||
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
#ifdef __LP64__
|
||||||
|
#else
|
||||||
|
// export as TIFF
|
||||||
|
GraphicsExportComponent exporter = 0;
|
||||||
|
OSStatus err = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeTIFF, &exporter);
|
||||||
|
if (noErr == err)
|
||||||
|
{
|
||||||
|
m_pictHandle = NewHandle(0);
|
||||||
|
if ( m_pictHandle )
|
||||||
|
{
|
||||||
|
CGImageRef cgImageRef = (CGImageRef) m_bitmap.CGImageCreate();
|
||||||
|
err = GraphicsExportSetInputCGImage( exporter, cgImageRef);
|
||||||
|
err = GraphicsExportSetOutputHandle(exporter, (Handle)m_pictHandle);
|
||||||
|
err = GraphicsExportDoExport(exporter, NULL);
|
||||||
|
CGImageRelease(cgImageRef);
|
||||||
|
}
|
||||||
|
CloseComponent( exporter );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
|
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
|
||||||
m_pictCreated = false;
|
m_pictCreated = false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,13 +350,14 @@ void wxBitmapDataObject::Clear()
|
|||||||
{
|
{
|
||||||
if (m_pictHandle != NULL)
|
if (m_pictHandle != NULL)
|
||||||
{
|
{
|
||||||
#ifndef __LP64__
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
DisposeHandle( (Handle) m_pictHandle );
|
||||||
|
#else
|
||||||
if (m_pictCreated)
|
if (m_pictCreated)
|
||||||
KillPicture( (PicHandle)m_pictHandle );
|
KillPicture( (PicHandle)m_pictHandle );
|
||||||
#endif
|
#endif
|
||||||
m_pictHandle = NULL;
|
m_pictHandle = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pictCreated = false;
|
m_pictCreated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,6 +385,17 @@ size_t wxBitmapDataObject::GetDataSize() const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Handle MacCreateDataReferenceHandle(Handle theDataHandle)
|
||||||
|
{
|
||||||
|
Handle dataRef = NULL;
|
||||||
|
OSErr err = noErr;
|
||||||
|
|
||||||
|
// Create a data reference handle for our data.
|
||||||
|
err = PtrToHand( &theDataHandle, &dataRef, sizeof(Handle));
|
||||||
|
|
||||||
|
return dataRef;
|
||||||
|
}
|
||||||
|
|
||||||
bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf )
|
bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf )
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
@@ -352,10 +403,40 @@ bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf )
|
|||||||
if ((pBuf == NULL) || (nSize == 0))
|
if ((pBuf == NULL) || (nSize == 0))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
|
Handle picHandle = NewHandle( nSize );
|
||||||
|
memcpy( *picHandle, pBuf, nSize );
|
||||||
|
m_pictHandle = picHandle;
|
||||||
|
#ifdef __LP64__
|
||||||
|
#else
|
||||||
|
|
||||||
|
// import from TIFF
|
||||||
|
GraphicsImportComponent importer = 0;
|
||||||
|
OSStatus err = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypeTIFF, &importer);
|
||||||
|
if (noErr == err)
|
||||||
|
{
|
||||||
|
if ( picHandle )
|
||||||
|
{
|
||||||
|
ComponentResult result = GraphicsImportSetDataHandle(importer, picHandle);
|
||||||
|
if ( result == noErr )
|
||||||
|
{
|
||||||
|
Rect frame;
|
||||||
|
GraphicsImportGetNaturalBounds( importer, &frame );
|
||||||
|
CGImageRef cgImageRef = 0;
|
||||||
|
GraphicsImportCreateCGImage( importer, &cgImageRef, kGraphicsImportCreateCGImageUsingCurrentSettings );
|
||||||
|
m_bitmap.Create( frame.right - frame.left, frame.bottom - frame.top );
|
||||||
|
CGRect r = CGRectMake( 0 , 0 , frame.right - frame.left , frame.bottom - frame.top );
|
||||||
|
CGContextDrawImage( (CGContextRef) m_bitmap.GetHBITMAP() , r, cgImageRef ) ;
|
||||||
|
CGImageRelease(cgImageRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CloseComponent( importer );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
PicHandle picHandle = (PicHandle)NewHandle( nSize );
|
PicHandle picHandle = (PicHandle)NewHandle( nSize );
|
||||||
memcpy( *picHandle, pBuf, nSize );
|
memcpy( *picHandle, pBuf, nSize );
|
||||||
m_pictHandle = picHandle;
|
m_pictHandle = picHandle;
|
||||||
|
|
||||||
// ownership is transferred to the bitmap
|
// ownership is transferred to the bitmap
|
||||||
m_pictCreated = false;
|
m_pictCreated = false;
|
||||||
#ifndef __LP64__
|
#ifndef __LP64__
|
||||||
@@ -372,6 +453,7 @@ bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf )
|
|||||||
mf.Play( &mdc );
|
mf.Play( &mdc );
|
||||||
#endif
|
#endif
|
||||||
mdc.SelectObject( wxNullBitmap );
|
mdc.SelectObject( wxNullBitmap );
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return m_bitmap.Ok();
|
return m_bitmap.Ok();
|
||||||
|
@@ -44,10 +44,8 @@ wxMemoryDC::~wxMemoryDC()
|
|||||||
{
|
{
|
||||||
#if wxMAC_USE_CORE_GRAPHICS
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
m_selected.EndRawAccess() ;
|
m_selected.EndRawAccess() ;
|
||||||
CGContextRef bmCtx = (CGContextRef) m_graphicContext->GetNativeContext() ;
|
|
||||||
delete m_graphicContext ;
|
delete m_graphicContext ;
|
||||||
m_graphicContext = NULL ;
|
m_graphicContext = NULL ;
|
||||||
CGContextRelease( bmCtx ) ;
|
|
||||||
#else
|
#else
|
||||||
// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
|
// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
|
||||||
#endif
|
#endif
|
||||||
@@ -60,10 +58,8 @@ void wxMemoryDC::DoSelect( const wxBitmap& bitmap )
|
|||||||
{
|
{
|
||||||
#if wxMAC_USE_CORE_GRAPHICS
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
m_selected.EndRawAccess() ;
|
m_selected.EndRawAccess() ;
|
||||||
CGContextRef bmCtx = (CGContextRef) m_graphicContext->GetNativeContext() ;
|
|
||||||
delete m_graphicContext ;
|
delete m_graphicContext ;
|
||||||
m_graphicContext = NULL ;
|
m_graphicContext = NULL ;
|
||||||
CGContextRelease( bmCtx ) ;
|
|
||||||
#else
|
#else
|
||||||
// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
|
// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
|
||||||
#endif
|
#endif
|
||||||
@@ -75,21 +71,11 @@ void wxMemoryDC::DoSelect( const wxBitmap& bitmap )
|
|||||||
#if wxMAC_USE_CORE_GRAPHICS
|
#if wxMAC_USE_CORE_GRAPHICS
|
||||||
if ( m_selected.GetDepth() != 1 )
|
if ( m_selected.GetDepth() != 1 )
|
||||||
m_selected.UseAlpha() ;
|
m_selected.UseAlpha() ;
|
||||||
void * data = m_selected.BeginRawAccess() ;
|
m_selected.BeginRawAccess() ;
|
||||||
|
m_width = bitmap.GetWidth();
|
||||||
int bitsPerComp = 8 ;
|
m_height = bitmap.GetHeight();
|
||||||
int bytesPerPixel = 4 ;
|
|
||||||
int w = bitmap.GetWidth() ;
|
|
||||||
int h = bitmap.GetHeight() ;
|
|
||||||
m_width = w;
|
|
||||||
m_height = h;
|
|
||||||
|
|
||||||
// TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
|
|
||||||
CGImageAlphaInfo a = kCGImageAlphaNoneSkipFirst ;
|
|
||||||
|
|
||||||
CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
|
CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
|
||||||
CGContextRef bmCtx = CGBitmapContextCreate( data , w, h, bitsPerComp , bytesPerPixel * w , genericColorSpace, a );
|
CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP();
|
||||||
wxASSERT_MSG( bmCtx , wxT("Unable to create bitmap context") ) ;
|
|
||||||
|
|
||||||
if ( bmCtx )
|
if ( bmCtx )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user