1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/dcmemory.mm
3 // Purpose: wxMemoryDC class
4 // Author: David Elliott
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/dcmemory.h"
14 #import <AppKit/NSImage.h>
16 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
20 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxDC)
22 wxMemoryDC::wxMemoryDC(void)
24 m_cocoaNSImage = NULL;
28 wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
30 m_cocoaNSImage = NULL;
34 wxMemoryDC::~wxMemoryDC(void)
36 CocoaUnwindStackAndLoseFocus();
37 [m_cocoaNSImage release];
40 bool wxMemoryDC::CocoaLockFocus()
44 [m_cocoaNSImage lockFocusOnRepresentation: m_selectedBitmap.GetNSBitmapImageRep()];
45 sm_cocoaDCStack.Insert(this);
51 bool wxMemoryDC::CocoaUnlockFocus()
53 [m_cocoaNSImage unlockFocus];
57 void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
59 CocoaUnwindStackAndLoseFocus();
60 [m_cocoaNSImage release];
62 m_selectedBitmap = bitmap;
63 if(m_selectedBitmap.Ok())
65 m_cocoaNSImage = [[NSImage alloc]
66 initWithSize:NSMakeSize(m_selectedBitmap.GetWidth(),
67 m_selectedBitmap.GetHeight())];
68 [m_cocoaNSImage addRepresentation: m_selectedBitmap.GetNSBitmapImageRep()];
72 void wxMemoryDC::DoGetSize( int *width, int *height ) const
75 *width = m_selectedBitmap.GetWidth();
77 *height = m_selectedBitmap.GetHeight();