X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f288c87b3df1e24c5e1b3727c539744e0710c4c1..af86380553169606c985e0053a1630e9514e18b6:/src/mac/carbon/bitmap.cpp diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 5abc83eb77..706db8ac40 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: bitmap.cpp +// Name: src/mac/carbon/bitmap.cpp // Purpose: wxBitmap // Author: Stefan Csomor // Modified by: @@ -12,9 +12,14 @@ #include "wx/wxprec.h" #include "wx/bitmap.h" -#include "wx/icon.h" -#include "wx/log.h" -#include "wx/image.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/dcmemory.h" + #include "wx/icon.h" + #include "wx/image.h" +#endif + #include "wx/metafile.h" #include "wx/xpmdecod.h" @@ -22,7 +27,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) #ifdef __DARWIN__ #include @@ -31,7 +35,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) #endif #include "wx/mac/uma.h" -#include "wx/dcmemory.h" // Implementation Notes // -------------------- @@ -161,8 +164,8 @@ wxBitmapRefData::wxBitmapRefData( int w , int h , int d ) bool wxBitmapRefData::Create( int w , int h , int d ) { - m_width = w ; - m_height = h ; + m_width = wxMax(1, w); + m_height = wxMax(1, h); m_depth = d ; m_bytesPerRow = w * 4 ; @@ -392,9 +395,14 @@ IconRef wxBitmapRefData::GetIconRef() PicHandle pic = GetPictHandle() ; SetIconFamilyData( iconFamily, 'PICT' , (Handle) pic ) ; } - // 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 + HLock((Handle) iconFamily); + OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &m_iconRef ); + HUnlock((Handle) iconFamily); + wxASSERT_MSG( err == noErr , wxT("Error when constructing icon ref") ); +#else static int iconCounter = 2 ; OSStatus err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &m_iconRef ) ; @@ -403,8 +411,9 @@ IconRef wxBitmapRefData::GetIconRef() // we have to retain a reference, as Unregister will decrement it AcquireIconRef( m_iconRef ) ; UnregisterIconRef( 'WXNG' , (OSType) iconCounter ) ; - DisposeHandle( (Handle) iconFamily ) ; ++iconCounter ; +#endif + DisposeHandle( (Handle) iconFamily ) ; } return m_iconRef ; @@ -832,7 +841,7 @@ wxBitmap::wxBitmap(int w, int h, int d) (void)Create(w, h, d); } -wxBitmap::wxBitmap(void *data, wxBitmapType type, int width, int height, int depth) +wxBitmap::wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth) { (void) Create(data, type, width, height, depth); } @@ -842,16 +851,6 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type) LoadFile(filename, type); } -wxBitmap::wxBitmap(const char **bits) -{ - (void) CreateFromXpm(bits); -} - -wxBitmap::wxBitmap(char **bits) -{ - (void) CreateFromXpm((const char **)bits); -} - void * wxBitmap::GetRawAccess() const { wxCHECK_MSG( Ok() , NULL , wxT("invalid bitmap") ) ; @@ -873,24 +872,6 @@ void wxBitmap::EndRawAccess() M_BITMAPDATA->EndRawAccess() ; } -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 -} - #ifdef __WXMAC_OSX__ WXCGIMAGEREF wxBitmap::CGImageCreate() const { @@ -1005,7 +986,7 @@ bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type) return false; } -bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth) +bool wxBitmap::Create(const void* data, wxBitmapType type, int width, int height, int depth) { UnRef(); @@ -1027,7 +1008,7 @@ bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int wxBitmap::wxBitmap(const wxImage& image, int depth) { - wxCHECK_RET( image.Ok(), wxT("invalid image") ) + wxCHECK_RET( image.Ok(), wxT("invalid image") ); // width and height of the device-dependent bitmap int width = image.GetWidth(); @@ -1215,7 +1196,7 @@ bool wxBitmap::SaveFile( const wxString& filename, return success; } -bool wxBitmap::Ok() const +bool wxBitmap::IsOk() const { return (M_BITMAPDATA && M_BITMAPDATA->Ok()); } @@ -1526,25 +1507,7 @@ WXHBITMAP wxMask::GetHBITMAP() const // wxBitmapHandler // ---------------------------------------------------------------------------- -wxBitmapHandler::~wxBitmapHandler() -{ -} - -bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth) -{ - return false; -} - -bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth, int desiredHeight) -{ - return false; -} - -bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette) -{ - return false; -} +IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler, wxBitmapHandlerBase) // ---------------------------------------------------------------------------- // Standard Handlers @@ -1615,53 +1578,12 @@ void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp) data.m_height = GetHeight() ; data.m_stride = GetWidth() * 4 ; - return GetRawAccess() ; + return BeginRawAccess() ; } void wxBitmap::UngetRawData(wxPixelDataBase& dataBase) { - if ( !Ok() ) - return; - - // TODO: if we have some information about the API we should check - // this code looks strange... - - if ( !M_BITMAPDATA->HasAlpha() ) - return; - - wxAlphaPixelData& data = (wxAlphaPixelData&)dataBase; - int w = data.GetWidth(); - int h = data.GetHeight(); - - wxBitmap bmpMask( GetWidth(), GetHeight(), 32 ); - wxAlphaPixelData dataMask( bmpMask, data.GetOrigin(), wxSize( w, h ) ); - wxAlphaPixelData::Iterator pMask( dataMask ), p( data ); - - for ( int y = 0; y < h; y++ ) - { - wxAlphaPixelData::Iterator rowStartMask = pMask; - wxAlphaPixelData::Iterator rowStart = p; - - for ( int x = 0; x < w; x++ ) - { - const wxAlphaPixelData::Iterator::ChannelType alpha = p.Alpha(); - - pMask.Red() = alpha; - pMask.Green() = alpha; - pMask.Blue() = alpha; - - ++p; - ++pMask; - } - - p = rowStart; - p.OffsetY( data, 1 ); - - pMask = rowStartMask; - pMask.OffsetY( dataMask, 1 ); - } - - SetMask( new wxMask( bmpMask ) ); + EndRawAccess() ; } void wxBitmap::UseAlpha()