]> git.saurik.com Git - wxWidgets.git/commitdiff
wxCocoa: Preliminary wxMemoryDC implementation
authorDavid Elliott <dfe@tgwbd.org>
Mon, 21 Jul 2003 20:55:50 +0000 (20:55 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Mon, 21 Jul 2003 20:55:50 +0000 (20:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22212 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/dcmemory.h
src/cocoa/dcmemory.cpp [deleted file]
src/cocoa/dcmemory.mm [new file with mode: 0644]

index bb83332dfb2d2e0513a61b2668909ba64d31812a..d6ca56d8643c3986ca2083e6d186c976475eb20f 100644 (file)
@@ -4,15 +4,15 @@
 // Author:      David Elliott
 // Modified by:
 // Created:     2003/03/16
-// RCS-ID:      $Id:
+// RCS-ID:      $Id$
 // Copyright:   (c) 2003 David Elliott
-// Licence:    wxWindows license
+// Licence:    wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #ifndef __WX_COCOA_DCMEMORY_H__
 #define __WX_COCOA_DCMEMORY_H__
 
-#include "wx/dcclient.h"
+#include "wx/dc.h"
 
 class WXDLLEXPORT wxMemoryDC: public wxDC
 {
@@ -23,6 +23,9 @@ public:
     ~wxMemoryDC(void);
     virtual void SelectObject(const wxBitmap& bitmap);
     virtual void DoGetSize(int *width, int *height) const;
+protected:
+    wxBitmap m_selectedBitmap;
+    WX_NSImage m_cocoaNSImage;
 // DC stack
     virtual bool CocoaLockFocus();
     virtual bool CocoaUnlockFocus();
diff --git a/src/cocoa/dcmemory.cpp b/src/cocoa/dcmemory.cpp
deleted file mode 100644 (file)
index 377615b..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// Name:        src/cocoa/dcmemory.cpp
-// Purpose:     wxMemoryDC class
-// Author:      David Elliott
-// Modified by:
-// Created:     2003/03/16
-// RCS-ID:      $Id:
-// Copyright:   (c) 2002 David Elliott
-// Licence:    wxWindows license
-/////////////////////////////////////////////////////////////////////////////
-
-#include "wx/dcmemory.h"
-
-//-----------------------------------------------------------------------------
-// wxMemoryDC
-//-----------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxDC)
-
-wxMemoryDC::wxMemoryDC(void)
-{
-  m_ok = false;
-};
-
-wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
-{
-  m_ok = false;
-};
-
-wxMemoryDC::~wxMemoryDC(void)
-{
-}
-
-bool wxMemoryDC::CocoaLockFocus()
-{
-    return false;
-}
-
-bool wxMemoryDC::CocoaUnlockFocus()
-{
-    return false;
-}
-
-void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
-{
-}
-
-void wxMemoryDC::DoGetSize( int *width, int *height ) const
-{
-}
-
diff --git a/src/cocoa/dcmemory.mm b/src/cocoa/dcmemory.mm
new file mode 100644 (file)
index 0000000..e097fea
--- /dev/null
@@ -0,0 +1,79 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        src/cocoa/dcmemory.mm
+// Purpose:     wxMemoryDC class
+// Author:      David Elliott
+// Modified by:
+// Created:     2003/03/16
+// RCS-ID:      $Id$
+// Copyright:   (c) 2002 David Elliott
+// Licence:    wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#include "wx/dcmemory.h"
+
+#import <AppKit/NSImage.h>
+
+//-----------------------------------------------------------------------------
+// wxMemoryDC
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxDC)
+
+wxMemoryDC::wxMemoryDC(void)
+{
+    m_cocoaNSImage = NULL;
+    m_ok = false;
+}
+
+wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
+{
+    m_cocoaNSImage = NULL;
+    m_ok = false;
+}
+
+wxMemoryDC::~wxMemoryDC(void)
+{
+    CocoaUnwindStackAndLoseFocus();
+    [m_cocoaNSImage release];
+}
+
+bool wxMemoryDC::CocoaLockFocus()
+{
+    if(m_cocoaNSImage)
+    {
+        [m_cocoaNSImage lockFocusOnRepresentation: m_selectedBitmap.GetNSBitmapImageRep()];
+        sm_cocoaDCStack.Insert(this);
+        return true;
+    }
+    return false;
+}
+
+bool wxMemoryDC::CocoaUnlockFocus()
+{
+    [m_cocoaNSImage unlockFocus];
+    return true;
+}
+
+void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
+{
+    CocoaUnwindStackAndLoseFocus();
+    [m_cocoaNSImage release];
+    m_cocoaNSImage = nil;
+    m_selectedBitmap = bitmap;
+    if(m_selectedBitmap.Ok())
+    {
+        m_cocoaNSImage = [[NSImage alloc]
+                initWithSize:NSMakeSize(m_selectedBitmap.GetWidth(),
+                    m_selectedBitmap.GetHeight())];
+        [m_cocoaNSImage addRepresentation: m_selectedBitmap.GetNSBitmapImageRep()];
+    }
+}
+
+void wxMemoryDC::DoGetSize( int *width, int *height ) const
+{
+    if(width)
+        *width = m_selectedBitmap.GetWidth();
+    if(height)
+        *height = m_selectedBitmap.GetHeight();
+}
+