]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/dcscreen.cpp
minor fixes; replace references to Windows95 with references to wxMSW where possible
[wxWidgets.git] / src / osx / carbon / dcscreen.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/dcscreen.cpp
489468fe
SC
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"
b2680ced 15#include "wx/osx/dcscreen.h"
489468fe 16
b2680ced 17#include "wx/osx/private.h"
489468fe 18#include "wx/graphics.h"
4fcb208a 19#include "wx/osx/private/glgrab.h"
489468fe
SC
20
21IMPLEMENT_ABSTRACT_CLASS(wxScreenDCImpl, wxWindowDCImpl)
22
23// TODO : for the Screenshot use case, which doesn't work in Quartz
24// we should do a GetAsBitmap using something like
25// http://www.cocoabuilder.com/archive/message/cocoa/2005/8/13/144256
26
27// Create a DC representing the whole screen
28wxScreenDCImpl::wxScreenDCImpl( wxDC *owner ) :
29 wxWindowDCImpl( owner )
30{
b2680ced 31#if wxOSX_USE_COCOA_OR_IPHONE
489468fe
SC
32 m_graphicContext = NULL;
33 m_ok = false ;
34#else
35 CGRect cgbounds ;
36 cgbounds = CGDisplayBounds(CGMainDisplayID());
37 Rect bounds;
38 bounds.top = (short)cgbounds.origin.y;
39 bounds.left = (short)cgbounds.origin.x;
40 bounds.bottom = bounds.top + (short)cgbounds.size.height;
41 bounds.right = bounds.left + (short)cgbounds.size.width;
42 WindowAttributes overlayAttributes = kWindowIgnoreClicksAttribute;
43 CreateNewWindow( kOverlayWindowClass, overlayAttributes, &bounds, (WindowRef*) &m_overlayWindow );
44 ShowWindow((WindowRef)m_overlayWindow);
45 SetGraphicsContext( wxGraphicsContext::CreateFromNativeWindow( m_overlayWindow ) );
46 m_width = (wxCoord)cgbounds.size.width;
47 m_height = (wxCoord)cgbounds.size.height;
48 m_ok = true ;
49#endif
50}
51
52wxScreenDCImpl::~wxScreenDCImpl()
53{
54 delete m_graphicContext;
55 m_graphicContext = NULL;
b2680ced 56#if wxOSX_USE_COCOA_OR_IPHONE
489468fe
SC
57#else
58 DisposeWindow((WindowRef) m_overlayWindow );
59#endif
60}
4fcb208a
SC
61
62wxBitmap wxScreenDCImpl::DoGetAsBitmap(const wxRect *subrect) const
63{
64 CGRect srcRect = CGRectMake(0, 0, m_width, m_height);
65 if (subrect)
66 {
67 srcRect.origin.x = subrect->GetX();
68 srcRect.origin.y = subrect->GetY();
69 srcRect.size.width = subrect->GetWidth();
70 srcRect.size.height = subrect->GetHeight();
71 }
72
73 wxBitmap bmp = wxBitmap(srcRect.size.width, srcRect.size.height, 32);
74
75 CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
76
77 CGContextSaveGState(context);
78
79 CGContextTranslateCTM( context, 0, m_height );
80 CGContextScaleCTM( context, 1, -1 );
81
82 if ( subrect )
83 srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ;
84
85 CGImageRef image = grabViaOpenGL(kCGNullDirectDisplay, srcRect);
86
87 wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot."));
88
89 CGContextDrawImage(context, srcRect, image);
90
91 CGContextRestoreGState(context);
92
93 return bmp;
94}