// we don't dare premultiplied alpha yet
#define wxMAC_USE_PREMULTIPLIED_ALPHA 0
+#if wxUSE_BMPBUTTON
+
void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType )
{
memset( info , 0 , sizeof(ControlButtonContentInfo) ) ;
if ( bitmap.Ok() )
{
- wxBitmapRefData * bmap = (wxBitmapRefData*) ( bitmap.GetRefData()) ;
+ wxBitmapRefData * bmap = bitmap.GetBitmapData() ;
if ( bmap == NULL )
return ;
- if ( bmap->HasNativeSize() )
+ if ( ( bmap->HasNativeSize() && forceType == 0 ) || forceType == kControlContentIconRef )
{
+ wxBitmap scaleBmp ;
+
+ wxBitmapRefData* bmp = bmap ;
+
+ if ( !bmap->HasNativeSize() )
+ {
+ // as PICT conversion will only result in a 16x16 icon, let's attempt
+ // a few scales for better results
+
+ int w = bitmap.GetWidth() ;
+ int h = bitmap.GetHeight() ;
+ int sz = wxMax( w , h ) ;
+ if ( sz == 24 || sz == 64)
+ {
+ scaleBmp = wxBitmap( bitmap.ConvertToImage().Scale( w * 2 , h * 2 ) ) ;
+ bmp = scaleBmp.GetBitmapData() ;
+ }
+ }
+
info->contentType = kControlContentIconRef ;
- info->u.iconRef = bmap->GetIconRef() ;
+ info->u.iconRef = bmp->GetIconRef() ;
+ AcquireIconRef( info->u.iconRef ) ;
}
+#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
+ else if ( forceType == kControlContentCGImageRef )
+ {
+ info->contentType = kControlContentCGImageRef ;
+ info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ;
+ }
+#endif
else
{
info->contentType = kControlContentPictHandle ;
info->u.picture = bmap->GetPictHandle() ;
}
-#if wxMAC_USE_CORE_GRAPHICS
- /*
- // only on 10.4 more controls will accept a CGImage
-
- info->contentType = kControlContentCGImageRef ;
- info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ;
- */
-#endif
}
}
{
if ( info->contentType == kControlContentIconRef )
{
- // as the bitmap is now the owner, no need to release here
+ ReleaseIconRef( info->u.iconRef ) ;
+ }
+ else if ( info->contentType == kControlNoContent )
+ {
+ // there's no bitmap at all, fall through silently
}
else if ( info->contentType == kControlContentPictHandle )
{
- // owned by the bitma, no release here
+ // owned by the bitmap, 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 )
}
}
+#endif //wxUSE_BMPBUTTON
+
#define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
void wxBitmapRefData::Init()
}
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 ) ;
+#ifdef __WXDEBUG__
+ OSStatus err =
+#endif
+ 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 ) ;
{
CGrafPtr origPort = NULL ;
GDHandle origDev = NULL ;
- PicHandle pict = NULL ;
GWorldPtr wp = NULL ;
GWorldPtr mask = NULL ;
int height = GetHeight() ;
return m_pictHandle ;
}
-#if wxMAC_USE_CORE_GRAPHICS
+#ifdef __WXMAC_OSX__
void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size)
{
wxMemoryBuffer* membuf = (wxMemoryBuffer*) info ;
bool wxBitmap::CreateFromXpm(const char **bits)
{
+#if wxUSE_IMAGE
wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )
wxXPMDecoder decoder;
wxImage img = decoder.ReadData(bits);
wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") )
*this = wxBitmap(img);
return TRUE;
+#else
+ return FALSE;
+#endif
}
-#if wxMAC_USE_CORE_GRAPHICS
+#ifdef __WXMAC_OSX__
WXCGIMAGEREF wxBitmap::CGImageCreate() const
{
wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ;
}
else
{
+#if wxUSE_IMAGE
wxImage loadimage(filename, type);
if (loadimage.Ok()) {
*this = loadimage;
return true;
}
+#endif
}
wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
return false;
return handler->Create(this, data, type, width, height, depth);
}
+#if wxUSE_IMAGE
+
wxBitmap::wxBitmap(const wxImage& image, int depth)
{
wxCHECK_RET( image.Ok(), wxT("invalid image") )
bool hasAlpha = false ;
bool hasMask = false ;
+ int maskBytesPerRow = 0 ;
unsigned char *alpha = NULL ;
unsigned char *mask = NULL ;
if ( HasAlpha() )
{
hasMask = true ;
mask = (unsigned char*) GetMask()->GetRawAccess() ;
+ maskBytesPerRow = GetMask()->GetBytesPerRow() ;
}
if ( hasAlpha )
static const int MASK_BLUE = 3;
static const int MASK_BLUE_REPLACEMENT = 2;
- for (int yy = 0; yy < height; yy++)
+ for (int yy = 0; yy < height; yy++ , mask += maskBytesPerRow )
{
+ unsigned char * maskp = mask ;
for (int xx = 0; xx < width; xx++)
{
long color = *((long*) source) ;
unsigned char b = (color&0x000000FF);
if ( hasMask )
{
- if ( *mask++ == 0 )
+ if ( *maskp++ == 0 )
{
if ( r == MASK_RED && g == MASK_GREEN && b == MASK_BLUE )
b = MASK_BLUE_REPLACEMENT ;
return image;
}
+#endif //wxUSE_IMAGE
bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type,
const wxPalette *palette) const
}
else
{
+#if wxUSE_IMAGE
wxImage image = ConvertToImage();
-
return image.SaveFile(filename, type);
+#endif
}
wxLogWarning(wxT("no bitmap handler for type %d defined."), type);