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