]>
Commit | Line | Data |
---|---|---|
a15eb0a5 | 1 | /////////////////////////////////////////////////////////////////////////////// |
fb5246be | 2 | // Name: src/mac/carbon/toplevel.cpp |
d66c3960 SC |
3 | // Purpose: implements wxTopLevelWindow for Mac |
4 | // Author: Stefan Csomor | |
a15eb0a5 SC |
5 | // Modified by: |
6 | // Created: 24.09.01 | |
7 | // RCS-ID: $Id$ | |
d66c3960 | 8 | // Copyright: (c) 2001-2004 Stefan Csomor |
65571936 | 9 | // License: wxWindows licence |
a15eb0a5 SC |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
a15eb0a5 SC |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
1832043f WS |
27 | #include "wx/toplevel.h" |
28 | ||
a15eb0a5 SC |
29 | #ifndef WX_PRECOMP |
30 | #include "wx/app.h" | |
422644a3 | 31 | #include "wx/frame.h" |
a15eb0a5 SC |
32 | #include "wx/string.h" |
33 | #include "wx/log.h" | |
34 | #include "wx/intl.h" | |
37ec2bd3 | 35 | #include "wx/settings.h" |
2d17efa9 | 36 | #include "wx/strconv.h" |
179e085f | 37 | #include "wx/control.h" |
a15eb0a5 SC |
38 | #endif //WX_PRECOMP |
39 | ||
5f0b2f22 | 40 | #include "wx/mac/uma.h" |
422644a3 | 41 | #include "wx/mac/aga.h" |
5f0b2f22 | 42 | #include "wx/tooltip.h" |
a07c1212 | 43 | #include "wx/dnd.h" |
a979e444 | 44 | |
1f90939c SC |
45 | #if wxUSE_SYSTEM_OPTIONS |
46 | #include "wx/sysopt.h" | |
47 | #endif | |
5f0b2f22 | 48 | |
3c393c0a | 49 | #ifndef __DARWIN__ |
7f0c3a63 | 50 | #include <ToolUtils.h> |
3c393c0a | 51 | #endif |
dd49c691 | 52 | |
a979e444 | 53 | // for targeting OSX |
eab19a7c RN |
54 | #include "wx/mac/private.h" |
55 | ||
a15eb0a5 SC |
56 | // ============================================================================ |
57 | // wxTopLevelWindowMac implementation | |
58 | // ============================================================================ | |
59 | ||
facd6764 SC |
60 | BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase) |
61 | END_EVENT_TABLE() | |
62 | ||
a15eb0a5 SC |
63 | // ---------------------------------------------------------------------------- |
64 | // wxTopLevelWindowMac creation | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
902725ee | 67 | typedef struct |
c5985061 SC |
68 | { |
69 | wxPoint m_position ; | |
902725ee | 70 | wxSize m_size ; |
f3b2e2d7 | 71 | bool m_wasResizable ; |
716d0327 | 72 | } FullScreenData ; |
c5985061 | 73 | |
a15eb0a5 SC |
74 | void wxTopLevelWindowMac::Init() |
75 | { | |
76 | m_iconized = | |
902725ee | 77 | m_maximizeOnShow = false; |
c5985061 | 78 | m_macFullScreenData = NULL ; |
a15eb0a5 SC |
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 | { | |
5a011158 SC |
89 | if ( !wxNonOwnedWindow::Create(parent, id, pos, size, style, name) ) |
90 | return false; | |
f83b6761 | 91 | |
5a011158 | 92 | wxWindow::SetLabel( title ) ; |
34a3ed01 | 93 | SetWindowTitleWithCFString( (WindowRef) m_macWindow , wxCFStringRef( title , GetFont().GetEncoding() ) ); |
328f0df8 | 94 | wxTopLevelWindows.Append(this); |
893727e5 | 95 | |
5a011158 SC |
96 | return true; |
97 | } | |
6239ee05 | 98 | |
5a011158 SC |
99 | wxTopLevelWindowMac::~wxTopLevelWindowMac() |
100 | { | |
101 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
102 | delete data ; | |
103 | m_macFullScreenData = NULL ; | |
104 | } | |
b19bf058 | 105 | |
14c96cf2 | 106 | |
5a011158 SC |
107 | // ---------------------------------------------------------------------------- |
108 | // wxTopLevelWindowMac maximize/minimize | |
109 | // ---------------------------------------------------------------------------- | |
6a7e6411 | 110 | |
5a011158 SC |
111 | void wxTopLevelWindowMac::Maximize(bool maximize) |
112 | { | |
113 | Point idealSize = { 0 , 0 } ; | |
114 | if ( maximize ) | |
6a7e6411 | 115 | { |
5a011158 SC |
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 | |
6a7e6411 | 128 | } |
5a011158 | 129 | ZoomWindowIdeal( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , &idealSize ) ; |
5f0b2f22 SC |
130 | } |
131 | ||
5a011158 | 132 | bool wxTopLevelWindowMac::IsMaximized() const |
5f0b2f22 | 133 | { |
5a011158 | 134 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; |
5f0b2f22 SC |
135 | } |
136 | ||
5a011158 | 137 | void wxTopLevelWindowMac::Iconize(bool iconize) |
5f0b2f22 | 138 | { |
5a011158 SC |
139 | if ( IsWindowCollapsable( (WindowRef)m_macWindow) ) |
140 | CollapseWindow( (WindowRef)m_macWindow , iconize ) ; | |
5f0b2f22 SC |
141 | } |
142 | ||
5a011158 | 143 | bool wxTopLevelWindowMac::IsIconized() const |
5f0b2f22 | 144 | { |
5a011158 | 145 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
146 | } |
147 | ||
5a011158 | 148 | void wxTopLevelWindowMac::Restore() |
245f3581 | 149 | { |
5a011158 SC |
150 | if ( IsMaximized() ) |
151 | Maximize(false); | |
152 | else if ( IsIconized() ) | |
153 | Iconize(false); | |
245f3581 DE |
154 | } |
155 | ||
5a011158 SC |
156 | // ---------------------------------------------------------------------------- |
157 | // wxTopLevelWindowMac misc | |
158 | // ---------------------------------------------------------------------------- | |
52c3df99 | 159 | |
5a011158 SC |
160 | wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const |
161 | { | |
162 | return wxPoint(0, 0) ; | |
5f0b2f22 SC |
163 | } |
164 | ||
165 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
166 | { | |
fb5246be | 167 | wxWindow::SetLabel( title ) ; |
34a3ed01 | 168 | SetWindowTitleWithCFString( (WindowRef) m_macWindow , wxCFStringRef( title , GetFont().GetEncoding() ) ) ; |
5f0b2f22 SC |
169 | } |
170 | ||
d4bd6c97 | 171 | wxString wxTopLevelWindowMac::GetTitle() const |
fb5246be WS |
172 | { |
173 | return wxWindow::GetLabel(); | |
174 | } | |
175 | ||
c5985061 | 176 | bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) |
902725ee | 177 | { |
c5985061 SC |
178 | if ( show ) |
179 | { | |
180 | FullScreenData *data = (FullScreenData *)m_macFullScreenData ; | |
181 | delete data ; | |
182 | data = new FullScreenData() ; | |
902725ee | 183 | |
c5985061 SC |
184 | m_macFullScreenData = data ; |
185 | data->m_position = GetPosition() ; | |
186 | data->m_size = GetSize() ; | |
f3b2e2d7 | 187 | data->m_wasResizable = MacGetWindowAttributes() & kWindowResizableAttribute ; |
902725ee | 188 | |
c5985061 | 189 | if ( style & wxFULLSCREEN_NOMENUBAR ) |
52c3df99 DS |
190 | HideMenuBar() ; |
191 | ||
c5985061 SC |
192 | wxRect client = wxGetClientDisplayRect() ; |
193 | ||
52c3df99 | 194 | int left , top , right , bottom ; |
c5985061 | 195 | int x, y, w, h ; |
902725ee | 196 | |
c5985061 SC |
197 | x = client.x ; |
198 | y = client.y ; | |
199 | w = client.width ; | |
200 | h = client.height ; | |
902725ee | 201 | |
c5985061 SC |
202 | MacGetContentAreaInset( left , top , right , bottom ) ; |
203 | ||
204 | if ( style & wxFULLSCREEN_NOCAPTION ) | |
205 | { | |
206 | y -= top ; | |
207 | h += top ; | |
208 | } | |
52c3df99 | 209 | |
c5985061 SC |
210 | if ( style & wxFULLSCREEN_NOBORDER ) |
211 | { | |
212 | x -= left ; | |
213 | w += left + right ; | |
214 | h += bottom ; | |
215 | } | |
52c3df99 | 216 | |
c5985061 SC |
217 | if ( style & wxFULLSCREEN_NOTOOLBAR ) |
218 | { | |
3c86150d SC |
219 | // TODO |
220 | } | |
52c3df99 | 221 | |
3c86150d SC |
222 | if ( style & wxFULLSCREEN_NOSTATUSBAR ) |
223 | { | |
224 | // TODO | |
c5985061 | 225 | } |
52c3df99 | 226 | |
c5985061 | 227 | SetSize( x , y , w, h ) ; |
172da31f | 228 | if ( data->m_wasResizable ) |
f3b2e2d7 | 229 | MacChangeWindowAttributes( kWindowNoAttributes , kWindowResizableAttribute ) ; |
c5985061 SC |
230 | } |
231 | else | |
232 | { | |
233 | ShowMenuBar() ; | |
234 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
172da31f | 235 | if ( data->m_wasResizable ) |
f3b2e2d7 | 236 | MacChangeWindowAttributes( kWindowResizableAttribute , kWindowNoAttributes ) ; |
c5985061 SC |
237 | SetPosition( data->m_position ) ; |
238 | SetSize( data->m_size ) ; | |
52c3df99 | 239 | |
c5985061 SC |
240 | delete data ; |
241 | m_macFullScreenData = NULL ; | |
242 | } | |
52c3df99 | 243 | |
902725ee | 244 | return false; |
c5985061 SC |
245 | } |
246 | ||
902725ee WS |
247 | bool wxTopLevelWindowMac::IsFullScreen() const |
248 | { | |
249 | return m_macFullScreenData != NULL ; | |
c5985061 SC |
250 | } |
251 | ||
3feeb1e1 SC |
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 ) ; | |
a979e444 | 258 | DisposePtr( (Ptr)ptr ) ; |
3feeb1e1 SC |
259 | } |
260 | ||
89954433 | 261 | void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags)) |
3feeb1e1 SC |
262 | { |
263 | NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ; | |
52c3df99 DS |
264 | static wxMacNMUPP nmupp( wxMacNMResponse ); |
265 | ||
3feeb1e1 SC |
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 ; | |
52c3df99 | 273 | |
3feeb1e1 SC |
274 | verify_noerr( NMInstall( notificationRequest ) ) ; |
275 | } |