]> git.saurik.com Git - wxWidgets.git/blame - src/osx/core/dcmemory.cpp
use wxOSX_USE_COCOA instead of __WXOSX_COCOA__ (which was checked incorrectly)
[wxWidgets.git] / src / osx / core / dcmemory.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
96dabe43 2// Name: src/osx/core/dcmemory.cpp
489468fe
SC
3// Purpose: wxMemoryDC class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/dcmemory.h"
15#include "wx/graphics.h"
1f0c8f31 16#include "wx/osx/dcmemory.h"
489468fe 17
1f0c8f31 18#include "wx/osx/private.h"
489468fe
SC
19
20//-----------------------------------------------------------------------------
21// wxMemoryDCImpl
22//-----------------------------------------------------------------------------
23
24IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl,wxPaintDCImpl)
25
26
27wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
28 : wxPaintDCImpl( owner )
29{
30 Init();
31}
32
33wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap )
34 : wxPaintDCImpl( owner )
35{
36 Init();
37 DoSelect(bitmap);
38}
39
40wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC * WXUNUSED(dc) )
41 : wxPaintDCImpl( owner )
42{
43 Init();
44}
45
46void wxMemoryDCImpl::Init()
47{
48 m_ok = true;
49 SetBackground(*wxWHITE_BRUSH);
50 SetBrush(*wxWHITE_BRUSH);
51 SetPen(*wxBLACK_PEN);
52 SetFont(*wxNORMAL_FONT);
53 m_ok = false;
54}
55
56wxMemoryDCImpl::~wxMemoryDCImpl()
57{
58 if ( m_selected.Ok() )
59 {
60 m_selected.EndRawAccess() ;
61 delete m_graphicContext ;
62 m_graphicContext = NULL ;
63 }
64}
65
66void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
67{
68 if ( m_selected.Ok() )
69 {
70 m_selected.EndRawAccess() ;
71 delete m_graphicContext ;
72 m_graphicContext = NULL ;
73 }
74
75 m_selected = bitmap;
76 if (m_selected.Ok())
77 {
78 if ( m_selected.GetDepth() != 1 )
79 m_selected.UseAlpha() ;
80 m_selected.BeginRawAccess() ;
81 m_width = bitmap.GetWidth();
82 m_height = bitmap.GetHeight();
83 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
84 CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP();
85
86 if ( bmCtx )
87 {
88 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
89 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
90 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
91 }
92 m_ok = (m_graphicContext != NULL) ;
93 }
94 else
95 {
96 m_ok = false;
97 }
98}
99
100void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
101{
102 if (m_selected.Ok())
103 {
104 if (width)
105 (*width) = m_selected.GetWidth();
106 if (height)
107 (*height) = m_selected.GetHeight();
108 }
109 else
110 {
111 if (width)
112 (*width) = 0;
113 if (height)
114 (*height) = 0;
115 }
116}