]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/dcclient.cpp
3 // Purpose: wxClientDCImpl class
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/dcclient.h"
17 #include "wx/window.h"
18 #include "wx/dcmemory.h"
19 #include "wx/settings.h"
20 #include "wx/toplevel.h"
22 #include "wx/region.h"
25 #include "wx/graphics.h"
26 #include "wx/rawbmp.h"
27 #include "wx/osx/private.h"
28 #include "wx/osx/dcclient.h"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGCDCImpl
)
36 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
)
43 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
)
50 m_window
->GetSize( &m_width
, &m_height
);
51 if ( !m_window
->IsShownOnScreen() )
52 m_width
= m_height
= 0;
54 CGContextRef cg
= (CGContextRef
) window
->MacGetCGContextRef();
59 SetGraphicsContext( wxGraphicsContext::Create( window
) ) ;
60 m_contentScaleFactor
= window
->GetContentScaleFactor();
61 SetDeviceOrigin(-window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize());
65 // determine content scale
66 CGRect userrect
= CGRectMake(0, 0, 10, 10);
68 devicerect
= CGContextConvertRectToDeviceSpace(cg
, userrect
);
69 m_contentScaleFactor
= devicerect
.size
.height
/ userrect
.size
.height
;
71 CGContextSaveGState( cg
);
73 // make sure the context is having its origin at the wx-window coordinates of the
74 // view (read at the top of window.cpp about the differences)
75 if ( window
->MacGetLeftBorderSize() != 0 || window
->MacGetTopBorderSize() != 0 )
76 CGContextTranslateCTM( cg
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
78 wxGraphicsContext
* context
= wxGraphicsContext::CreateFromNative( cg
);
79 context
->EnableOffset(true);
80 SetGraphicsContext( context
);
82 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
84 SetBackground(wxBrush(window
->GetBackgroundColour(),wxSOLID
));
86 SetFont( window
->GetFont() ) ;
89 wxWindowDCImpl::~wxWindowDCImpl()
93 // this must not necessarily be the current context, we must restore the state of the
94 // cg we started with above (before the CGContextTranslateCTM call)
95 CGContextRef cg
= (CGContextRef
) m_window
->MacGetCGContextRef();
96 CGContextRestoreGState(cg
);
100 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
109 wxBitmap
wxWindowDCImpl::DoGetAsBitmap(const wxRect
*subrect
) const
111 // wxScreenDC is derived from wxWindowDC, so a screen dc will
112 // call this method when a Blit is performed with it as a source.
116 ControlRef handle
= (ControlRef
) m_window
->GetHandle();
122 CGContextRef context
;
124 HIViewCreateOffscreenImage( handle
, 0, &rect
, &image
);
127 int width
= subrect
!= NULL
? subrect
->width
: (int)rect
.size
.width
;
128 int height
= subrect
!= NULL
? subrect
->height
: (int)rect
.size
.height
;
130 wxBitmap bmp
= wxBitmap(width
, height
, 32);
132 context
= (CGContextRef
)bmp
.GetHBITMAP();
134 CGContextSaveGState(context
);
136 CGContextTranslateCTM( context
, 0, height
);
137 CGContextScaleCTM( context
, 1, -1 );
140 rect
= CGRectOffset( rect
, -subrect
->x
, -subrect
->y
) ;
141 CGContextDrawImage( context
, rect
, image
);
143 CGContextRestoreGState(context
);
152 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
154 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
155 : wxWindowDCImpl( owner
)
159 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*window
) :
160 wxWindowDCImpl( owner
, window
)
162 wxCHECK_RET( window
, wxT("invalid window in wxClientDCImpl") );
163 wxPoint origin
= window
->GetClientAreaOrigin() ;
164 m_window
->GetClientSize( &m_width
, &m_height
);
165 if ( !m_window
->IsShownOnScreen() )
166 m_width
= m_height
= 0;
169 DoGetDeviceOrigin(&x0
,&y0
);
170 SetDeviceOrigin( origin
.x
+ x0
, origin
.y
+ y0
);
172 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
175 wxClientDCImpl::~wxClientDCImpl()
177 if( GetGraphicsContext() && GetGraphicsContext()->GetNativeContext() )
185 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxWindowDCImpl
)
187 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
188 : wxWindowDCImpl( owner
)
192 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*window
) :
193 wxWindowDCImpl( owner
, window
)
195 wxASSERT_MSG( window
->MacGetCGContextRef() != NULL
, wxT("using wxPaintDC without being in a native paint event") );
196 wxPoint origin
= window
->GetClientAreaOrigin() ;
197 m_window
->GetClientSize( &m_width
, &m_height
);
198 SetDeviceOrigin( origin
.x
, origin
.y
);
199 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
202 wxPaintDCImpl::~wxPaintDCImpl()