]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/dcscreen.cpp
bringing back utf32 encoding for wchar, fixes #10666
[wxWidgets.git] / src / osx / carbon / dcscreen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/dcscreen.cpp
3 // Purpose: wxScreenDC class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/dcscreen.h"
15 #include "wx/osx/dcscreen.h"
16
17 #include "wx/osx/private.h"
18 #include "wx/graphics.h"
19 #if wxOSX_USE_COCOA_OR_CARBON
20 #include "wx/osx/private/glgrab.h"
21 #endif
22
23 IMPLEMENT_ABSTRACT_CLASS(wxScreenDCImpl, wxWindowDCImpl)
24
25 // TODO : for the Screenshot use case, which doesn't work in Quartz
26 // we should do a GetAsBitmap using something like
27 // http://www.cocoabuilder.com/archive/message/cocoa/2005/8/13/144256
28
29 // Create a DC representing the whole screen
30 wxScreenDCImpl::wxScreenDCImpl( wxDC *owner ) :
31 wxWindowDCImpl( owner )
32 {
33 #if wxOSX_USE_COCOA_OR_IPHONE
34 m_graphicContext = NULL;
35 m_ok = false ;
36 #else
37 CGRect cgbounds ;
38 cgbounds = CGDisplayBounds(CGMainDisplayID());
39 Rect bounds;
40 bounds.top = (short)cgbounds.origin.y;
41 bounds.left = (short)cgbounds.origin.x;
42 bounds.bottom = bounds.top + (short)cgbounds.size.height;
43 bounds.right = bounds.left + (short)cgbounds.size.width;
44 WindowAttributes overlayAttributes = kWindowIgnoreClicksAttribute;
45 CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, (WindowRef*) &m_overlayWindow );
46 ShowWindow((WindowRef)m_overlayWindow);
47 SetGraphicsContext( wxGraphicsContext::CreateFromNativeWindow( m_overlayWindow ) );
48 m_width = (wxCoord)cgbounds.size.width;
49 m_height = (wxCoord)cgbounds.size.height;
50 m_ok = true ;
51 #endif
52 }
53
54 wxScreenDCImpl::~wxScreenDCImpl()
55 {
56 delete m_graphicContext;
57 m_graphicContext = NULL;
58 #if wxOSX_USE_COCOA_OR_IPHONE
59 #else
60 DisposeWindow((WindowRef) m_overlayWindow );
61 #endif
62 }
63
64 wxBitmap wxScreenDCImpl::DoGetAsBitmap(const wxRect *subrect) const
65 {
66 CGRect srcRect = CGRectMake(0, 0, m_width, m_height);
67 if (subrect)
68 {
69 srcRect.origin.x = subrect->GetX();
70 srcRect.origin.y = subrect->GetY();
71 srcRect.size.width = subrect->GetWidth();
72 srcRect.size.height = subrect->GetHeight();
73 }
74 wxBitmap bmp = wxBitmap(srcRect.size.width, srcRect.size.height, 32);
75 #if wxOSX_USE_IPHONE
76 #else
77 CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
78
79 CGContextSaveGState(context);
80
81 CGContextTranslateCTM( context, 0, m_height );
82 CGContextScaleCTM( context, 1, -1 );
83
84 if ( subrect )
85 srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ;
86
87 CGImageRef image = grabViaOpenGL(kCGNullDirectDisplay, srcRect);
88
89 wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot."));
90
91 CGContextDrawImage(context, srcRect, image);
92
93 CGContextRestoreGState(context);
94 #endif
95 return bmp;
96 }