]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/dcclient.cpp
bd3bd1ed752b3306ad8d2f45cfc11e312face830
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/dcclient.cpp
3 // Purpose: wxClientDCImpl class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/dcclient.h"
18 #include "wx/window.h"
19 #include "wx/dcmemory.h"
20 #include "wx/settings.h"
21 #include "wx/toplevel.h"
23 #include "wx/region.h"
26 #include "wx/graphics.h"
27 #include "wx/rawbmp.h"
28 #include "wx/osx/private.h"
29 #include "wx/osx/dcclient.h"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl
, wxGCDCImpl
)
37 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
)
44 wxWindowDCImpl::wxWindowDCImpl( wxDC
*owner
, wxWindow
*window
)
51 m_window
->GetSize( &m_width
, &m_height
);
52 if ( !m_window
->IsShownOnScreen() )
53 m_width
= m_height
= 0;
55 CGContextRef cg
= (CGContextRef
) window
->MacGetCGContextRef();
60 SetGraphicsContext( wxGraphicsContext::Create( window
) ) ;
61 m_contentScaleFactor
= window
->GetContentScaleFactor();
62 SetDeviceOrigin(-window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize());
66 // determine content scale
67 CGRect userrect
= CGRectMake(0, 0, 10, 10);
69 devicerect
= CGContextConvertRectToDeviceSpace(cg
, userrect
);
70 m_contentScaleFactor
= devicerect
.size
.height
/ userrect
.size
.height
;
72 CGContextSaveGState( cg
);
74 // make sure the context is having its origin at the wx-window coordinates of the
75 // view (read at the top of window.cpp about the differences)
76 if ( window
->MacGetLeftBorderSize() != 0 || window
->MacGetTopBorderSize() != 0 )
77 CGContextTranslateCTM( cg
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
79 wxGraphicsContext
* context
= wxGraphicsContext::CreateFromNative( cg
);
80 context
->EnableOffset(true);
81 SetGraphicsContext( context
);
83 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
85 SetBackground(wxBrush(window
->GetBackgroundColour(),wxSOLID
));
87 SetFont( window
->GetFont() ) ;
90 wxWindowDCImpl::~wxWindowDCImpl()
94 // this must not necessarily be the current context, we must restore the state of the
95 // cg we started with above (before the CGContextTranslateCTM call)
96 CGContextRef cg
= (CGContextRef
) m_window
->MacGetCGContextRef();
97 CGContextRestoreGState(cg
);
101 void wxWindowDCImpl::DoGetSize( int* width
, int* height
) const
110 wxBitmap
wxWindowDCImpl::DoGetAsBitmap(const wxRect
*subrect
) const
112 // wxScreenDC is derived from wxWindowDC, so a screen dc will
113 // call this method when a Blit is performed with it as a source.
117 ControlRef handle
= (ControlRef
) m_window
->GetHandle();
123 CGContextRef context
;
125 HIViewCreateOffscreenImage( handle
, 0, &rect
, &image
);
128 int width
= subrect
!= NULL
? subrect
->width
: (int)rect
.size
.width
;
129 int height
= subrect
!= NULL
? subrect
->height
: (int)rect
.size
.height
;
131 wxBitmap bmp
= wxBitmap(width
, height
, 32);
133 context
= (CGContextRef
)bmp
.GetHBITMAP();
135 CGContextSaveGState(context
);
137 CGContextTranslateCTM( context
, 0, height
);
138 CGContextScaleCTM( context
, 1, -1 );
141 rect
= CGRectOffset( rect
, -subrect
->x
, -subrect
->y
) ;
142 CGContextDrawImage( context
, rect
, image
);
144 CGContextRestoreGState(context
);
153 IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl
, wxWindowDCImpl
)
155 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
)
156 : wxWindowDCImpl( owner
)
160 wxClientDCImpl::wxClientDCImpl( wxDC
*owner
, wxWindow
*window
) :
161 wxWindowDCImpl( owner
, window
)
163 wxCHECK_RET( window
, wxT("invalid window in wxClientDCImpl") );
164 wxPoint origin
= window
->GetClientAreaOrigin() ;
165 m_window
->GetClientSize( &m_width
, &m_height
);
166 if ( !m_window
->IsShownOnScreen() )
167 m_width
= m_height
= 0;
170 DoGetDeviceOrigin(&x0
,&y0
);
171 SetDeviceOrigin( origin
.x
+ x0
, origin
.y
+ y0
);
173 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
176 wxClientDCImpl::~wxClientDCImpl()
178 if( GetGraphicsContext() && GetGraphicsContext()->GetNativeContext() )
186 IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl
, wxWindowDCImpl
)
188 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
)
189 : wxWindowDCImpl( owner
)
193 wxPaintDCImpl::wxPaintDCImpl( wxDC
*owner
, wxWindow
*window
) :
194 wxWindowDCImpl( owner
, window
)
196 wxASSERT_MSG( window
->MacGetCGContextRef() != NULL
, wxT("using wxPaintDC without being in a native paint event") );
197 wxPoint origin
= window
->GetClientAreaOrigin() ;
198 m_window
->GetClientSize( &m_width
, &m_height
);
199 SetDeviceOrigin( origin
.x
, origin
.y
);
200 DoSetClippingRegion( 0 , 0 , m_width
, m_height
) ;
203 wxPaintDCImpl::~wxPaintDCImpl()