]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcscreen.cpp
a19dc36477a03e1157c1ee9bb04633e9c703436c
[wxWidgets.git] / src / mac / carbon / dcscreen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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
16 #include "wx/mac/uma.h"
17
18 IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
19
20 // Create a DC representing the whole screen
21 wxScreenDC::wxScreenDC()
22 {
23 #if wxMAC_USE_CORE_GRAPHICS
24 CGrafPtr grafptr = CreateNewPort() ;
25 m_displayId = (UInt32) grafptr;
26 CGContextRef cg = NULL;
27 OSStatus status = QDBeginCGContext( grafptr , &cg );
28
29 CGRect bounds ;
30 bounds = CGDisplayBounds(CGMainDisplayID());
31
32 SInt16 height;
33 GetThemeMenuBarHeight( &height );
34 m_minY = height;
35 m_minX = 0;
36 m_maxX = bounds.size.width;
37 m_maxY = bounds.size.height - height;
38 CGContextTranslateCTM( cg , 0 , bounds.size.height );
39 CGContextScaleCTM( cg , 1 , -1 );
40
41 SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
42 m_width = bounds.size.width;
43 m_height = bounds.size.height - height;
44 #else
45 m_macPort = CreateNewPort() ;
46 GrafPtr port ;
47 GetPort( &port ) ;
48 SetPort( (GrafPtr) m_macPort ) ;
49 Point pt = { 0,0 } ;
50 LocalToGlobal( &pt ) ;
51 SetPort( port ) ;
52 m_macLocalOrigin.x = -pt.h ;
53 m_macLocalOrigin.y = -pt.v ;
54
55 BitMap screenBits;
56 GetQDGlobalsScreenBits( &screenBits );
57 m_minX = screenBits.bounds.left ;
58
59 SInt16 height ;
60 GetThemeMenuBarHeight( &height ) ;
61 m_minY = screenBits.bounds.top + height ;
62
63 m_maxX = screenBits.bounds.right ;
64 m_maxY = screenBits.bounds.bottom ;
65
66 MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ;
67 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
68 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
69 #endif
70 m_ok = true ;
71 }
72
73 wxScreenDC::~wxScreenDC()
74 {
75 #if wxMAC_USE_CORE_GRAPHICS
76 CGrafPtr grafptr = (CGrafPtr) m_displayId;
77 m_displayId = (UInt32) grafptr;
78 CGContextRef cg = (CGContextRef) m_graphicContext->GetNativeContext();
79 QDEndCGContext(grafptr, &cg );
80
81 delete m_graphicContext;
82 m_graphicContext = NULL;
83 #else
84 if ( m_macPort )
85 DisposePort( (CGrafPtr) m_macPort ) ;
86 #endif
87 }