mac cleanup

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50194 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2007-11-23 19:25:21 +00:00
parent e06b0afba5
commit 968c951fe1
8 changed files with 170 additions and 62 deletions

View File

@@ -43,6 +43,83 @@ IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
// under Quartz then content is transformed into a CGImageRef representing the same data
// which can be transferred to the GPU by the OS for fast rendering
class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
{
friend class WXDLLIMPEXP_FWD_CORE wxIcon;
friend class WXDLLIMPEXP_FWD_CORE wxCursor;
public:
wxBitmapRefData(int width , int height , int depth);
wxBitmapRefData();
wxBitmapRefData(const wxBitmapRefData &tocopy);
virtual ~wxBitmapRefData();
void Free();
bool Ok() const { return IsOk(); }
bool IsOk() const { return m_ok; }
void SetOk( bool isOk) { m_ok = isOk; }
void SetWidth( int width ) { m_width = width; }
void SetHeight( int height ) { m_height = height; }
void SetDepth( int depth ) { m_depth = depth; }
int GetWidth() const { return m_width; }
int GetHeight() const { return m_height; }
int GetDepth() const { return m_depth; }
void *GetRawAccess() const;
void *BeginRawAccess();
void EndRawAccess();
bool HasAlpha() const { return m_hasAlpha; }
void UseAlpha( bool useAlpha );
public:
#if wxUSE_PALETTE
wxPalette m_bitmapPalette;
#endif // wxUSE_PALETTE
wxMask * m_bitmapMask; // Optional mask
CGImageRef CreateCGImage() const;
// returns true if the bitmap has a size that
// can be natively transferred into a true icon
// if no is returned GetIconRef will still produce
// an icon but it will be generated via a PICT and
// rescaled to 16 x 16
bool HasNativeSize();
// caller should increase ref count if needed longer
// than the bitmap exists
IconRef GetIconRef();
// returns a Pict from the bitmap content
PicHandle GetPictHandle();
CGContextRef GetBitmapContext() const;
int GetBytesPerRow() const { return m_bytesPerRow; }
private :
bool Create(int width , int height , int depth);
void Init();
int m_width;
int m_height;
int m_bytesPerRow;
int m_depth;
bool m_hasAlpha;
wxMemoryBuffer m_memBuf;
int m_rawAccessCount;
bool m_ok;
mutable CGImageRef m_cgImageRef;
IconRef m_iconRef;
PicHandle m_pictHandle;
CGContextRef m_hBitmap;
};
#define wxMAC_USE_PREMULTIPLIED_ALPHA 1
static const int kBestByteAlignement = 16;
static const int kMaskBytesPerPixel = 1;
@@ -52,7 +129,9 @@ static int GetBestBytesPerRow( int rawBytes )
return (((rawBytes)+kBestByteAlignement-1) & ~(kBestByteAlignement-1) );
}
#if wxUSE_BMPBUTTON
#if wxUSE_GUI
// this is used for more controls than just the wxBitmap button, also for notebooks etc
void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType )
{
@@ -95,7 +174,7 @@ void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bi
else if ( forceType == kControlContentCGImageRef )
{
info->contentType = kControlContentCGImageRef ;
info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ;
info->u.imageRef = (CGImageRef) bmap->CreateCGImage() ;
}
else
{
@@ -112,7 +191,7 @@ CGImageRef wxMacCreateCGImageFromBitmap( const wxBitmap& bitmap )
wxBitmapRefData * bmap = bitmap.GetBitmapData() ;
if ( bmap == NULL )
return NULL ;
return (CGImageRef) bmap->CGImageCreate();
return (CGImageRef) bmap->CreateCGImage();
}
void wxMacReleaseBitmapButton( ControlButtonContentInfo*info )
@@ -505,7 +584,7 @@ PicHandle wxBitmapRefData::GetPictHandle()
{
// QT does not correctly export the mask
// TODO if we get around to it create a synthetic PICT with the CopyBits and Mask commands
CGImageRef imageRef = CGImageCreate();
CGImageRef imageRef = CreateCGImage();
err = GraphicsExportSetInputCGImage( exporter, imageRef );
err = GraphicsExportSetOutputHandle(exporter, (Handle)m_pictHandle);
err = GraphicsExportDoExport(exporter, NULL);
@@ -536,7 +615,7 @@ void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t WXUNUSED(
delete membuf ;
}
CGImageRef wxBitmapRefData::CGImageCreate() const
CGImageRef wxBitmapRefData::CreateCGImage() const
{
wxASSERT( m_ok ) ;
wxASSERT( m_rawAccessCount >= 0 ) ;
@@ -902,11 +981,25 @@ void wxBitmap::EndRawAccess()
M_BITMAPDATA->EndRawAccess() ;
}
WXCGIMAGEREF wxBitmap::CGImageCreate() const
CGImageRef wxBitmap::CreateCGImage() const
{
wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ;
return M_BITMAPDATA->CGImageCreate() ;
return M_BITMAPDATA->CreateCGImage() ;
}
IconRef wxBitmap::GetIconRef() const
{
wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ;
return M_BITMAPDATA->GetIconRef() ;
}
IconRef wxBitmap::CreateIconRef() const
{
IconRef icon = GetIconRef();
verify_noerr( AcquireIconRef(icon) );
return icon;
}
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const

View File

@@ -24,16 +24,15 @@
#include "wx/mac/private.h"
IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap)
IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxGDIObject)
class WXDLLEXPORT wxCursorRefData: public wxBitmapRefData
class WXDLLEXPORT wxCursorRefData: public wxGDIRefData
{
DECLARE_NO_COPY_CLASS(wxCursorRefData)
friend class wxBitmap;
friend class wxCursor;
DECLARE_NO_COPY_CLASS(wxCursorRefData)
public:
wxCursorRefData();
virtual ~wxCursorRefData();
@@ -199,8 +198,6 @@ CursHandle wxGetStockCursor( int number )
wxCursorRefData::wxCursorRefData()
{
SetWidth( 16 );
SetHeight( 16 );
m_hCursor = NULL;
#if wxMAC_USE_COCOA
#else

View File

@@ -647,7 +647,7 @@ void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap )
wxBitmapDataObjectBase::SetBitmap( rBitmap );
if (m_bitmap.Ok())
{
CGImageRef cgImageRef = (CGImageRef) m_bitmap.CGImageCreate();
CGImageRef cgImageRef = (CGImageRef) m_bitmap.CreateCGImage();
CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
CGImageDestinationRef destination = CGImageDestinationCreateWithData( data , kUTTypeTIFF , 1 , NULL );

View File

@@ -169,7 +169,7 @@ static bool InitializeColumnDescription(DataBrowserListViewColumnDesc& columnDes
columnDescription.headerBtnDesc.btnFontStyle.style = normal;
columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
if (columnPtr->GetBitmap().Ok())
columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetBitmapData()->GetIconRef();
columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetIconRef();
// done:
return true;
} /* InitializeColumnDescription(DataBrowserListViewColumnDesc&, wxDataViewColumn const*, DataBrowserPropertyID, wxMacCFStringHolder const&) */
@@ -536,7 +536,7 @@ bool wxDataViewBitmapRenderer::Render(void)
bitmap << this->GetValue();
if (bitmap.Ok())
return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetBitmapData()->GetIconRef()) == noErr);
return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetIconRef()) == noErr);
else
return true;
} /* if */
@@ -734,7 +734,7 @@ void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
if (this->GetBitmap().Ok())
headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetBitmapData()->GetIconRef();
headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetIconRef();
else
headerDescription.btnContentInfo.u.iconRef = NULL;
wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));

View File

@@ -117,7 +117,7 @@ public :
{
wxASSERT( bmp && bmp->Ok() );
Init( (CGImageRef) bmp->CGImageCreate() , transform );
Init( (CGImageRef) bmp->CreateCGImage() , transform );
}
// ImagePattern takes ownership of CGImageRef passed in
@@ -1650,7 +1650,7 @@ void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDo
{
EnsureIsValid();
CGImageRef image = (CGImageRef)( bmp.CGImageCreate() );
CGImageRef image = (CGImageRef)( bmp.CreateCGImage() );
HIRect r = CGRectMake( x , y , w , h );
if ( bmp.GetDepth() == 1 )
{

View File

@@ -23,6 +23,56 @@ IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
#define M_ICONDATA ((wxIconRefData *)m_refData)
class WXDLLEXPORT wxIconRefData : public wxGDIRefData
{
public:
wxIconRefData();
wxIconRefData( WXHICON iconref, int desiredWidth, int desiredHeight );
virtual ~wxIconRefData() { Free(); }
void Init();
virtual void Free();
void SetWidth( int width ) { m_width = width; }
void SetHeight( int height ) { m_height = height; }
int GetWidth() const { return m_width; }
int GetHeight() const { return m_height; }
WXHICON GetHICON() const { return (WXHICON) m_iconRef; }
private :
IconRef m_iconRef;
int m_width;
int m_height;
};
wxIconRefData::wxIconRefData( WXHICON icon, int desiredWidth, int desiredHeight )
{
m_iconRef = MAC_WXHICON( icon ) ;
// Standard sizes
SetWidth( desiredWidth == -1 ? 32 : desiredWidth ) ;
SetHeight( desiredHeight == -1 ? 32 : desiredHeight ) ;
}
void wxIconRefData::Init()
{
m_iconRef = NULL ;
}
void wxIconRefData::Free()
{
if ( m_iconRef )
{
ReleaseIconRef( m_iconRef ) ;
m_iconRef = NULL ;
}
}
//
//
//
wxIcon::wxIcon()
{
@@ -60,12 +110,7 @@ wxIcon::wxIcon(WXHICON icon, const wxSize& size)
if (icon)
AcquireIconRef( (IconRef) icon ) ;
m_refData = new wxIconRefData( icon ) ;
if ( (size.x != -1) && (size.y != -1) )
{
M_ICONDATA->SetWidth( size.x ) ;
M_ICONDATA->SetHeight( size.y ) ;
}
m_refData = new wxIconRefData( icon, size.x, size.y ) ;
}
wxIcon::~wxIcon()
@@ -180,7 +225,7 @@ bool wxIcon::LoadFile(
}
if ( iconRef )
{
m_refData = new wxIconRefData( (WXHICON) iconRef ) ;
m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight ) ;
return true ;
}
}
@@ -191,7 +236,7 @@ bool wxIcon::LoadFile(
verify_noerr( GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef ) ) ;
if ( iconRef )
{
m_refData = new wxIconRefData( (WXHICON) iconRef ) ;
m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight ) ;
return true ;
}
@@ -244,35 +289,8 @@ void wxIcon::CopyFromBitmap( const wxBitmap& bmp )
UnRef() ;
// as the bitmap owns that ref, we have to acquire it as well
IconRef iconRef = bmp.GetBitmapData()->GetIconRef() ;
AcquireIconRef( iconRef ) ;
m_refData = new wxIconRefData( (WXHICON) iconRef ) ;
M_ICONDATA->SetWidth( bmp.GetWidth() ) ;
M_ICONDATA->SetHeight( bmp.GetHeight() ) ;
}
wxIconRefData::wxIconRefData( WXHICON icon )
{
m_iconRef = MAC_WXHICON( icon ) ;
// Standard sizes
SetWidth( 32 ) ;
SetHeight( 32 ) ;
}
void wxIconRefData::Init()
{
m_iconRef = NULL ;
}
void wxIconRefData::Free()
{
if ( m_iconRef )
{
ReleaseIconRef( m_iconRef ) ;
m_iconRef = NULL ;
}
IconRef iconRef = bmp.CreateIconRef() ;
m_refData = new wxIconRefData( (WXHICON) iconRef, bmp.GetWidth(), bmp.GetHeight() ) ;
}
IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)

View File

@@ -980,13 +980,13 @@ bool wxListCtrl::SetColumn(int col, wxListItem& item)
if (item.GetMask() & wxLIST_MASK_IMAGE && item.GetImage() != -1 )
{
columnDesc.btnContentInfo.contentType = kControlContentIconRef;
wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL);
if (imageList && imageList->GetImageCount() > 0 )
{
wxBitmap bmp = imageList->GetBitmap( item.GetImage() );
IconRef icon = bmp.GetBitmapData()->GetIconRef();
IconRef icon = bmp.GetIconRef();
columnDesc.btnContentInfo.u.iconRef = icon;
columnDesc.btnContentInfo.contentType = kControlContentIconRef;
}
}
@@ -2754,7 +2754,7 @@ void wxMacDataBrowserListCtrlControl::DrawItem(
wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
if (imageList && imageList->GetImageCount() > 0){
wxBitmap bmp = imageList->GetBitmap(imgIndex);
IconRef icon = bmp.GetBitmapData()->GetIconRef();
IconRef icon = bmp.GetIconRef();
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0,iconCGRect.origin.y + CGRectGetMaxY(iconCGRect));
@@ -2895,7 +2895,7 @@ OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemI
wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
if (imageList && imageList->GetImageCount() > 0){
wxBitmap bmp = imageList->GetBitmap(imgIndex);
IconRef icon = bmp.GetBitmapData()->GetIconRef();
IconRef icon = bmp.GetIconRef();
::SetDataBrowserItemDataIcon(itemData, icon);
}
}

View File

@@ -380,7 +380,7 @@ bool wxDockTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& WXUNUSED(too
// get the CGImageRef for the wxBitmap:
// OSX builds only, but then the dock only exists in OSX
CGImageRef pImage = (CGImageRef) bmp.CGImageCreate();
CGImageRef pImage = (CGImageRef) bmp.CreateCGImage();
wxASSERT( pImage != NULL );
// actually set the dock image