]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/dcscreen.cpp
changing disclosure triangle to allow for label
[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"
ac50e694 19#if wxOSX_USE_COCOA_OR_CARBON
4fcb208a 20#include "wx/osx/private/glgrab.h"
ac50e694 21#endif
489468fe
SC
22
23IMPLEMENT_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
30wxScreenDCImpl::wxScreenDCImpl( wxDC *owner ) :
31 wxWindowDCImpl( owner )
32{
71c5a4d1
SC
33 CGRect cgbounds ;
34 cgbounds = CGDisplayBounds(CGMainDisplayID());
35 m_width = (wxCoord)cgbounds.size.width;
36 m_height = (wxCoord)cgbounds.size.height;
b2680ced 37#if wxOSX_USE_COCOA_OR_IPHONE
5a8ea512 38 SetGraphicsContext( wxGraphicsContext::Create() );
489468fe 39#else
489468fe
SC
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 ) );
489468fe 49#endif
71c5a4d1 50 m_ok = true ;
489468fe
SC
51}
52
53wxScreenDCImpl::~wxScreenDCImpl()
54{
55 delete m_graphicContext;
56 m_graphicContext = NULL;
b2680ced 57#if wxOSX_USE_COCOA_OR_IPHONE
489468fe
SC
58#else
59 DisposeWindow((WindowRef) m_overlayWindow );
60#endif
61}
4fcb208a 62
17db93e9
SC
63// TODO Switch to CGWindowListCreateImage for 10.5 and above
64
4fcb208a
SC
65wxBitmap wxScreenDCImpl::DoGetAsBitmap(const wxRect *subrect) const
66{
67 CGRect srcRect = CGRectMake(0, 0, m_width, m_height);
68 if (subrect)
69 {
70 srcRect.origin.x = subrect->GetX();
71 srcRect.origin.y = subrect->GetY();
72 srcRect.size.width = subrect->GetWidth();
73 srcRect.size.height = subrect->GetHeight();
74 }
4fcb208a 75 wxBitmap bmp = wxBitmap(srcRect.size.width, srcRect.size.height, 32);
ac50e694
SC
76#if wxOSX_USE_IPHONE
77#else
4fcb208a
SC
78 CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
79
80 CGContextSaveGState(context);
81
82 CGContextTranslateCTM( context, 0, m_height );
83 CGContextScaleCTM( context, 1, -1 );
84
85 if ( subrect )
86 srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ;
87
88 CGImageRef image = grabViaOpenGL(kCGNullDirectDisplay, srcRect);
89
90 wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot."));
91
92 CGContextDrawImage(context, srcRect, image);
93
94 CGContextRestoreGState(context);
ac50e694 95#endif
4fcb208a
SC
96 return bmp;
97}