]> git.saurik.com Git - wxWidgets.git/blame - src/osx/core/dcmemory.cpp
adding magnification API into the wxWindow classes for best retina support
[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{
a1b806b9 58 if ( m_selected.IsOk() )
489468fe
SC
59 {
60 m_selected.EndRawAccess() ;
5276b0a5 61 wxDELETE(m_graphicContext);
489468fe
SC
62 }
63}
64
65void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
66{
a1b806b9 67 if ( m_selected.IsOk() )
489468fe
SC
68 {
69 m_selected.EndRawAccess() ;
5276b0a5 70 wxDELETE(m_graphicContext);
489468fe
SC
71 }
72
73 m_selected = bitmap;
a1b806b9 74 if (m_selected.IsOk())
489468fe
SC
75 {
76 if ( m_selected.GetDepth() != 1 )
77 m_selected.UseAlpha() ;
78 m_selected.BeginRawAccess() ;
03647350
VZ
79 m_width = bitmap.GetWidth();
80 m_height = bitmap.GetHeight();
489468fe
SC
81 CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace();
82 CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP();
83
84 if ( bmCtx )
85 {
86 CGContextSetFillColorSpace( bmCtx, genericColorSpace );
87 CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
03647350 88 SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
489468fe
SC
89 }
90 m_ok = (m_graphicContext != NULL) ;
91 }
92 else
93 {
94 m_ok = false;
95 }
96}
97
98void wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
99{
a1b806b9 100 if (m_selected.IsOk())
489468fe
SC
101 {
102 if (width)
103 (*width) = m_selected.GetWidth();
104 if (height)
105 (*height) = m_selected.GetHeight();
106 }
107 else
108 {
109 if (width)
110 (*width) = 0;
111 if (height)
112 (*height) = 0;
113 }
114}