]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/overlay.mm
Update AUI pane resizable status even when it is floating.
[wxWidgets.git] / src / osx / cocoa / overlay.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/overlay.mm
3 // Purpose: common wxOverlay code
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 2006-10-20
7 // RCS-ID: $Id: overlay.cpp 55419 2008-09-02 16:53:23Z SC $
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/overlay.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/dcclient.h"
31 #endif
32
33 #include "wx/dcgraph.h"
34
35 #include "wx/private/overlay.h"
36
37 #ifdef wxHAS_NATIVE_OVERLAY
38
39 // ============================================================================
40 // implementation
41 // ============================================================================
42
43 wxOverlayImpl::wxOverlayImpl()
44 {
45 m_window = NULL ;
46 m_overlayContext = NULL ;
47 m_overlayWindow = NULL ;
48 }
49
50 wxOverlayImpl::~wxOverlayImpl()
51 {
52 Reset();
53 }
54
55 bool wxOverlayImpl::IsOk()
56 {
57 return m_overlayWindow != NULL ;
58 }
59
60 void wxOverlayImpl::CreateOverlayWindow()
61 {
62 if ( m_window )
63 {
64 m_overlayParentWindow = m_window->MacGetTopLevelWindowRef();
65 [m_overlayParentWindow makeKeyAndOrderFront:nil];
66
67 NSView* view = m_window->GetHandle();
68
69 NSPoint viewOriginBase, viewOriginScreen;
70 viewOriginBase = [view convertPoint:NSMakePoint(0, 0) toView:nil];
71 viewOriginScreen = [m_overlayParentWindow convertBaseToScreen:viewOriginBase];
72
73 NSSize viewSize = [view frame].size;
74 if ( [view isFlipped] )
75 viewOriginScreen.y -= viewSize.height;
76
77 m_overlayWindow=[[NSWindow alloc] initWithContentRect:NSMakeRect(viewOriginScreen.x,viewOriginScreen.y,
78 viewSize.width,
79 viewSize.height)
80 styleMask:NSBorderlessWindowMask
81 backing:NSBackingStoreBuffered
82 defer:YES];
83
84 [m_overlayParentWindow addChildWindow:m_overlayWindow ordered:NSWindowAbove];
85 }
86 else
87 {
88 m_overlayParentWindow = NULL ;
89 CGRect cgbounds ;
90 cgbounds = CGDisplayBounds(CGMainDisplayID());
91
92 m_overlayWindow=[[NSWindow alloc] initWithContentRect:NSMakeRect(cgbounds.origin.x,cgbounds.origin.y,
93 cgbounds.size.width,
94 cgbounds.size.height)
95 styleMask:NSBorderlessWindowMask
96 backing:NSBackingStoreBuffered
97 defer:YES];
98 }
99 [m_overlayWindow setOpaque:NO];
100 [m_overlayWindow setHasShadow:YES];
101 [m_overlayWindow setIgnoresMouseEvents:YES];
102 [m_overlayWindow setAlphaValue:0.5];
103
104 [m_overlayWindow orderFront:nil];
105 }
106
107 void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height )
108 {
109 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
110
111 m_window = dc->GetWindow();
112 m_x = x ;
113 m_y = y ;
114 if ( dc->IsKindOf( CLASSINFO( wxClientDC ) ))
115 {
116 wxPoint origin = m_window->GetClientAreaOrigin();
117 m_x += origin.x;
118 m_y += origin.y;
119 }
120 m_width = width ;
121 m_height = height ;
122
123 CreateOverlayWindow();
124 wxASSERT_MSG( m_overlayWindow != NULL , _("Couldn't create the overlay window") );
125 m_overlayContext = (CGContextRef) [[m_overlayWindow graphicsContext] graphicsPort];
126 wxASSERT_MSG( m_overlayContext != NULL , _("Couldn't init the context on the overlay window") );
127
128 int ySize = 0;
129 if ( m_window )
130 {
131 NSView* view = m_window->GetHandle();
132 NSSize viewSize = [view frame].size;
133 ySize = viewSize.height;
134 }
135 else
136 {
137 CGRect cgbounds ;
138 cgbounds = CGDisplayBounds(CGMainDisplayID());
139 ySize = cgbounds.size.height;
140
141
142
143 }
144 CGContextTranslateCTM( m_overlayContext, 0, ySize );
145 CGContextScaleCTM( m_overlayContext, 1, -1 );
146 CGContextTranslateCTM( m_overlayContext, -m_x , -m_y );
147 }
148
149 void wxOverlayImpl::BeginDrawing( wxDC* dc)
150 {
151 wxDCImpl *impl = dc->GetImpl();
152 wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl);
153 if (win_impl)
154 {
155 win_impl->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
156 dc->SetClippingRegion( m_x , m_y , m_width , m_height ) ;
157 }
158 }
159
160 void wxOverlayImpl::EndDrawing( wxDC* dc)
161 {
162 wxDCImpl *impl = dc->GetImpl();
163 wxGCDCImpl *win_impl = wxDynamicCast(impl,wxGCDCImpl);
164 if (win_impl)
165 win_impl->SetGraphicsContext(NULL);
166
167 CGContextFlush( m_overlayContext );
168 }
169
170 void wxOverlayImpl::Clear(wxDC* WXUNUSED(dc))
171 {
172 wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
173 CGRect box = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 );
174 CGContextClearRect( m_overlayContext, box );
175 }
176
177 void wxOverlayImpl::Reset()
178 {
179 if ( m_overlayContext )
180 {
181 m_overlayContext = NULL ;
182 }
183
184 // todo : don't dispose, only hide and reposition on next run
185 if (m_overlayWindow)
186 {
187 [m_overlayParentWindow removeChildWindow:m_overlayWindow];
188 [m_overlayWindow release];
189 m_overlayWindow = NULL ;
190 }
191 }
192
193 #endif // wxHAS_NATIVE_OVERLAY