+ if (tocopy.m_bitmapMask)
+ m_bitmapMask = new wxMask(*tocopy.m_bitmapMask);
+ else if (tocopy.m_hasAlpha)
+ UseAlpha(true);
+
+ unsigned char* dest = (unsigned char*)GetRawAccess();
+ unsigned char* source = (unsigned char*)tocopy.GetRawAccess();
+ size_t numbytes = m_bytesPerRow * m_height;
+ memcpy( dest, source, numbytes );
+}
+
+wxBitmapRefData::wxBitmapRefData()
+{
+ Init() ;
+}
+
+wxBitmapRefData::wxBitmapRefData( int w , int h , int d )
+{
+ Init() ;
+ Create( w , h , d ) ;
+}
+
+bool wxBitmapRefData::Create( int w , int h , int d )
+{
+ m_width = wxMax(1, w);
+ m_height = wxMax(1, h);
+ m_depth = d ;
+
+ m_bytesPerRow = GetBestBytesPerRow( w * 4 ) ;
+ size_t size = m_bytesPerRow * h ;
+ void* data = m_memBuf.GetWriteBuf( size ) ;
+ memset( data , 0 , size ) ;
+ m_memBuf.UngetWriteBuf( size ) ;
+
+ m_hBitmap = NULL ;
+ m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst );
+ wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
+ CGContextTranslateCTM( m_hBitmap, 0, m_height );
+ CGContextScaleCTM( m_hBitmap, 1, -1 );
+
+ m_ok = ( m_hBitmap != NULL ) ;
+
+ return m_ok ;
+}
+
+void wxBitmapRefData::UseAlpha( bool use )
+{
+ if ( m_hasAlpha == use )
+ return ;
+
+ m_hasAlpha = use ;
+
+ 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") ) ;
+ CGContextTranslateCTM( m_hBitmap, 0, m_height );
+ CGContextScaleCTM( m_hBitmap, 1, -1 );
+}
+
+void *wxBitmapRefData::GetRawAccess() const
+{
+ wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ;
+ return m_memBuf.GetData() ;
+}
+
+void *wxBitmapRefData::BeginRawAccess()
+{
+ wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ) ;
+ wxASSERT( m_rawAccessCount == 0 ) ;
+ wxASSERT_MSG( m_pictHandle == NULL && m_iconRef == NULL ,
+ wxT("Currently, modifing bitmaps that are used in controls already is not supported") ) ;
+
+ ++m_rawAccessCount ;
+
+ // we must destroy an existing cached image, as
+ // the bitmap data may change now
+ if ( m_cgImageRef )