]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/dcscreen.cpp
use WXSIZEOF(x) instead of sizeof(x)/sizeof(x[0]) (closes #10701)
[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 CGRect cgbounds ;
34 cgbounds = CGDisplayBounds(CGMainDisplayID());
35 m_width = (wxCoord)cgbounds.size.width;
36 m_height = (wxCoord)cgbounds.size.height;
37 #if wxOSX_USE_COCOA_OR_IPHONE
38 SetGraphicsContext( wxGraphicsContext::Create() );
39 #else
40 Rect bounds;
41 bounds.top = (short)cgbounds.origin.y;
42 bounds.left = (short)cgbounds.origin.x;
43 bounds.bottom = bounds.top + (short)cgbounds.size.height;
44 bounds.right = bounds.left + (short)cgbounds.size.width;
45 WindowAttributes overlayAttributes = kWindowIgnoreClicksAttribute;
46 CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, (WindowRef*) &m_overlayWindow );
47 ShowWindow((WindowRef)m_overlayWindow);
48 SetGraphicsContext( wxGraphicsContext::CreateFromNativeWindow( m_overlayWindow ) );
49 #endif
50 m_ok = true ;
51 }
52
53 wxScreenDCImpl::~wxScreenDCImpl()
54 {
55 delete m_graphicContext;
56 m_graphicContext = NULL;
57 #if wxOSX_USE_COCOA_OR_IPHONE
58 #else
59 DisposeWindow((WindowRef) m_overlayWindow );
60 #endif
61 }
62
63 // TODO Switch to CGWindowListCreateImage for 10.5 and above
64
65 wxBitmap wxScreenDCImpl::DoGetAsBitmap(const wxRect *subrect) const
66 {
67 wxRect rect = subrect ? *subrect : wxRect(0, 0, m_width, m_height);
68
69 wxBitmap bmp(rect.GetSize(), 32);
70
71 #if !wxOSX_USE_IPHONE
72 CGRect srcRect = CGRectMake(rect.x, rect.y, rect.width, rect.height);
73
74 CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
75
76 CGContextSaveGState(context);
77
78 CGContextTranslateCTM( context, 0, m_height );
79 CGContextScaleCTM( context, 1, -1 );
80
81 if ( subrect )
82 srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ;
83
84 CGImageRef image = grabViaOpenGL(kCGNullDirectDisplay, srcRect);
85
86 wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot."));
87
88 CGContextDrawImage(context, srcRect, image);
89
90 CGContextRestoreGState(context);
91 #endif
92 return bmp;
93 }