]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/toplevel.cpp
popup activation scope and l&f
[wxWidgets.git] / src / mac / carbon / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 24.09.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: 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/toplevel.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #include "wx/frame.h"
32 #include "wx/string.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35 #include "wx/settings.h"
36 #include "wx/strconv.h"
37 #include "wx/control.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/mac/uma.h"
41 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
43 #include "wx/dnd.h"
44
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
47 #endif
48
49 #ifndef __DARWIN__
50 #include <ToolUtils.h>
51 #endif
52
53 // for targeting OSX
54 #include "wx/mac/private.h"
55
56 // ============================================================================
57 // wxTopLevelWindowMac implementation
58 // ============================================================================
59
60 BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase)
61 END_EVENT_TABLE()
62
63 // ----------------------------------------------------------------------------
64 // wxTopLevelWindowMac creation
65 // ----------------------------------------------------------------------------
66
67 typedef struct
68 {
69 wxPoint m_position ;
70 wxSize m_size ;
71 bool m_wasResizable ;
72 } FullScreenData ;
73
74 void wxTopLevelWindowMac::Init()
75 {
76 m_iconized =
77 m_maximizeOnShow = false;
78 m_macFullScreenData = NULL ;
79 }
80
81 bool wxTopLevelWindowMac::Create(wxWindow *parent,
82 wxWindowID id,
83 const wxString& title,
84 const wxPoint& pos,
85 const wxSize& size,
86 long style,
87 const wxString& name)
88 {
89 if ( !wxNonOwnedWindow::Create(parent, id, pos, size, style, name) )
90 return false;
91
92 wxWindow::SetLabel( title ) ;
93 SetWindowTitleWithCFString( (WindowRef) m_macWindow , wxCFStringRef( title , GetFont().GetEncoding() ) );
94 wxTopLevelWindows.Append(this);
95
96 return true;
97 }
98
99 wxTopLevelWindowMac::~wxTopLevelWindowMac()
100 {
101 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
102 delete data ;
103 m_macFullScreenData = NULL ;
104 }
105
106
107 // ----------------------------------------------------------------------------
108 // wxTopLevelWindowMac maximize/minimize
109 // ----------------------------------------------------------------------------
110
111 void wxTopLevelWindowMac::Maximize(bool maximize)
112 {
113 Point idealSize = { 0 , 0 } ;
114 if ( maximize )
115 {
116 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
117 HIRect bounds ;
118 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal,
119 &bounds);
120 idealSize.h = bounds.size.width;
121 idealSize.v = bounds.size.height;
122 #else
123 Rect rect ;
124 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ;
125 idealSize.h = rect.right - rect.left ;
126 idealSize.v = rect.bottom - rect.top ;
127 #endif
128 }
129 ZoomWindowIdeal( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , &idealSize ) ;
130 }
131
132 bool wxTopLevelWindowMac::IsMaximized() const
133 {
134 return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ;
135 }
136
137 void wxTopLevelWindowMac::Iconize(bool iconize)
138 {
139 if ( IsWindowCollapsable( (WindowRef)m_macWindow) )
140 CollapseWindow( (WindowRef)m_macWindow , iconize ) ;
141 }
142
143 bool wxTopLevelWindowMac::IsIconized() const
144 {
145 return IsWindowCollapsed((WindowRef)m_macWindow ) ;
146 }
147
148 void wxTopLevelWindowMac::Restore()
149 {
150 if ( IsMaximized() )
151 Maximize(false);
152 else if ( IsIconized() )
153 Iconize(false);
154 }
155
156 // ----------------------------------------------------------------------------
157 // wxTopLevelWindowMac misc
158 // ----------------------------------------------------------------------------
159
160 wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const
161 {
162 return wxPoint(0, 0) ;
163 }
164
165 void wxTopLevelWindowMac::SetTitle(const wxString& title)
166 {
167 wxWindow::SetLabel( title ) ;
168 SetWindowTitleWithCFString( (WindowRef) m_macWindow , wxCFStringRef( title , GetFont().GetEncoding() ) ) ;
169 }
170
171 wxString wxTopLevelWindowMac::GetTitle() const
172 {
173 return wxWindow::GetLabel();
174 }
175
176 bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style)
177 {
178 if ( show )
179 {
180 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
181 delete data ;
182 data = new FullScreenData() ;
183
184 m_macFullScreenData = data ;
185 data->m_position = GetPosition() ;
186 data->m_size = GetSize() ;
187 data->m_wasResizable = MacGetWindowAttributes() & kWindowResizableAttribute ;
188
189 if ( style & wxFULLSCREEN_NOMENUBAR )
190 HideMenuBar() ;
191
192 wxRect client = wxGetClientDisplayRect() ;
193
194 int left , top , right , bottom ;
195 int x, y, w, h ;
196
197 x = client.x ;
198 y = client.y ;
199 w = client.width ;
200 h = client.height ;
201
202 MacGetContentAreaInset( left , top , right , bottom ) ;
203
204 if ( style & wxFULLSCREEN_NOCAPTION )
205 {
206 y -= top ;
207 h += top ;
208 }
209
210 if ( style & wxFULLSCREEN_NOBORDER )
211 {
212 x -= left ;
213 w += left + right ;
214 h += bottom ;
215 }
216
217 if ( style & wxFULLSCREEN_NOTOOLBAR )
218 {
219 // TODO
220 }
221
222 if ( style & wxFULLSCREEN_NOSTATUSBAR )
223 {
224 // TODO
225 }
226
227 SetSize( x , y , w, h ) ;
228 if ( data->m_wasResizable )
229 MacChangeWindowAttributes( kWindowNoAttributes , kWindowResizableAttribute ) ;
230 }
231 else
232 {
233 ShowMenuBar() ;
234 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
235 if ( data->m_wasResizable )
236 MacChangeWindowAttributes( kWindowResizableAttribute , kWindowNoAttributes ) ;
237 SetPosition( data->m_position ) ;
238 SetSize( data->m_size ) ;
239
240 delete data ;
241 m_macFullScreenData = NULL ;
242 }
243
244 return false;
245 }
246
247 bool wxTopLevelWindowMac::IsFullScreen() const
248 {
249 return m_macFullScreenData != NULL ;
250 }
251
252 // Attracts the users attention to this window if the application is
253 // inactive (should be called when a background event occurs)
254
255 static pascal void wxMacNMResponse( NMRecPtr ptr )
256 {
257 NMRemove( ptr ) ;
258 DisposePtr( (Ptr)ptr ) ;
259 }
260
261 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags))
262 {
263 NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ;
264 static wxMacNMUPP nmupp( wxMacNMResponse );
265
266 memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ;
267 notificationRequest->qType = nmType ;
268 notificationRequest->nmMark = 1 ;
269 notificationRequest->nmIcon = 0 ;
270 notificationRequest->nmSound = 0 ;
271 notificationRequest->nmStr = NULL ;
272 notificationRequest->nmResp = nmupp ;
273
274 verify_noerr( NMInstall( notificationRequest ) ) ;
275 }