]> git.saurik.com Git - wxWidgets.git/blame - src/osx/core/dcmemory.cpp
wxMessageBox off the main thread lost result code.
[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
489468fe
SC
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
13#include "wx/dcmemory.h"
14#include "wx/graphics.h"
1f0c8f31 15#include "wx/osx/dcmemory.h"
489468fe 16
1f0c8f31 17#include "wx/osx/private.h"
489468fe
SC
18
19//-----------------------------------------------------------------------------
20// wxMemoryDCImpl
21//-----------------------------------------------------------------------------
22
23IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl,wxPaintDCImpl)
24
25
26wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner )
27 : wxPaintDCImpl( owner )
28{
29 Init();
30}
31
32wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap )
33 : wxPaintDCImpl( owner )
34{
35 Init();
36 DoSelect(bitmap);
37}
38
39wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC *owner, wxDC * WXUNUSED(dc) )
40 : wxPaintDCImpl( owner )
41{
42 Init();
43}
44
45void wxMemoryDCImpl::Init()
46{
47 m_ok = true;
48 SetBackground(*wxWHITE_BRUSH);
49 SetBrush(*wxWHITE_BRUSH);
50 SetPen(*wxBLACK_PEN);
51 SetFont(*wxNORMAL_FONT);
52 m_ok = false;
53}
54
55wxMemoryDCImpl::~wxMemoryDCImpl()
56{
a1b806b9 57 if ( m_selected.IsOk() )
489468fe
SC
58 {
59 m_selected.EndRawAccess() ;
5276b0a5 60 wxDELETE(m_graphicContext);
489468fe
SC
61 }
62}
63
64void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
65{
a1b806b9 66 if ( m_selected.IsOk() )
489468fe
SC
67 {
68 m_selected.EndRawAccess() ;
5276b0a5 69 wxDELETE(m_graphicContext);
489468fe
SC
70 }
71
72 m_selected = bitmap;
a1b806b9 73 if (m_selected.IsOk())
489468fe
SC
74 {
75 if ( m_selected.GetDepth() != 1 )
76 m_selected.UseAlpha() ;
77 m_selected.BeginRawAccess() ;
7e0fda87
SC
78 m_width = bitmap.GetScaledWidth();
79 m_height = bitmap.GetScaledHeight();
80 m_contentScaleFactor = bitmap.GetScaleFactor();
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)
7e0fda87 103 (*width) = m_selected.GetScaledWidth();
489468fe 104 if (height)
7e0fda87 105 (*height) = m_selected.GetScaledHeight();
489468fe
SC
106 }
107 else
108 {
109 if (width)
110 (*width) = 0;
111 if (height)
112 (*height) = 0;
113 }
114}