From ab13160e71d925cd16c561574af5a9cd4af69268 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 8 Aug 2003 14:49:53 +0000 Subject: [PATCH] * When cloning the ref data, copy the NSBitmapImageRep instead of retaining it * Added SetNSBitmapImageRep so that wxMemoryDC can update the contents by replacing the entire NSBitmapImageRep. * Added ability to create bitmaps from width/height git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22704 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/bitmap.h | 1 + src/cocoa/bitmap.mm | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/wx/cocoa/bitmap.h b/include/wx/cocoa/bitmap.h index 42a6f408c8..5715478e2a 100644 --- a/include/wx/cocoa/bitmap.h +++ b/include/wx/cocoa/bitmap.h @@ -144,6 +144,7 @@ public: // wxCocoa WX_NSBitmapImageRep GetNSBitmapImageRep(); + void SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep); static void InitStandardHandlers() { } static void CleanUpHandlers() { } diff --git a/src/cocoa/bitmap.mm b/src/cocoa/bitmap.mm index ca82c1a4e4..1c6b4cb021 100644 --- a/src/cocoa/bitmap.mm +++ b/src/cocoa/bitmap.mm @@ -70,8 +70,7 @@ wxBitmapRefData::wxBitmapRefData( const wxBitmapRefData& data) m_numColors = data.m_numColors; m_bitmapPalette = data.m_bitmapPalette; m_quality = data.m_quality; - m_cocoaNSBitmapImageRep = data.m_cocoaNSBitmapImageRep; - [m_cocoaNSBitmapImageRep retain]; + m_cocoaNSBitmapImageRep = [data.m_cocoaNSBitmapImageRep copyWithZone:nil]; m_bitmapMask = data.m_bitmapMask?new wxMask(*data.m_bitmapMask):NULL; } @@ -142,6 +141,16 @@ WX_NSBitmapImageRep wxBitmap::GetNSBitmapImageRep() return M_BITMAPDATA->m_cocoaNSBitmapImageRep; } +void wxBitmap::SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep) +{ + if(!M_BITMAPDATA) + return; + // NOTE: No checking is done to make sure width/height agree + [bitmapImageRep retain]; + [M_BITMAPDATA->m_cocoaNSBitmapImageRep release]; + M_BITMAPDATA->m_cocoaNSBitmapImageRep = bitmapImageRep; +} + void wxBitmap::SetWidth(int w) { if (!M_BITMAPDATA) @@ -249,6 +258,23 @@ bool wxBitmap::Create(int w, int h, int d) M_BITMAPDATA->m_depth = d; /* TODO: create new bitmap */ + M_BITMAPDATA->m_cocoaNSBitmapImageRep = [[NSBitmapImageRep alloc] + initWithBitmapDataPlanes: NULL + pixelsWide: w + pixelsHigh: h + bitsPerSample: 8 + samplesPerPixel: 3 + hasAlpha: NO + isPlanar: NO + colorSpaceName: NSCalibratedRGBColorSpace + bytesPerRow: 0 + bitsPerPixel: 0]; + + wxLogDebug("M_BITMAPDATA=%p NSBitmapImageRep bitmapData=%p", M_BITMAPDATA, [M_BITMAPDATA->m_cocoaNSBitmapImageRep bitmapData]); + M_BITMAPDATA->m_ok = true; + M_BITMAPDATA->m_numColors = 0; + M_BITMAPDATA->m_quality = 0; + M_BITMAPDATA->m_bitmapMask = NULL; return M_BITMAPDATA->m_ok; } -- 2.45.2