]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/frame.cpp
corrected wake up code
[wxWidgets.git] / src / mac / carbon / frame.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: frame.cpp
3 // Purpose: wxFrame
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/frame.h"
15 #include "wx/statusbr.h"
16 #include "wx/toolbar.h"
17 #include "wx/menuitem.h"
18 #include "wx/menu.h"
19 #include "wx/dcclient.h"
20 #include "wx/dialog.h"
21 #include "wx/settings.h"
22 #include "wx/app.h"
23
24 #include "wx/mac/uma.h"
25
26 extern wxWindowList wxModelessWindows;
27 extern wxList wxPendingDelete;
28
29 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
30 EVT_ACTIVATE(wxFrame::OnActivate)
31 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
32 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
33 // EVT_IDLE(wxFrame::OnIdle)
34 // EVT_CLOSE(wxFrame::OnCloseWindow)
35 END_EVENT_TABLE()
36
37 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
38
39 #define WX_MAC_STATUSBAR_HEIGHT 18
40 // ----------------------------------------------------------------------------
41 // creation/destruction
42 // ----------------------------------------------------------------------------
43
44 void wxFrame::Init()
45 {
46 m_frameMenuBar = NULL;
47
48 #if wxUSE_TOOLBAR
49 m_frameToolBar = NULL ;
50 #endif
51 m_frameStatusBar = NULL;
52 m_winLastFocused = NULL ;
53
54 m_iconized = false;
55
56 #if wxUSE_TOOLTIPS
57 m_hwndToolTip = 0;
58 #endif
59 }
60
61 bool wxFrame::Create(wxWindow *parent,
62 wxWindowID id,
63 const wxString& title,
64 const wxPoint& pos,
65 const wxSize& size,
66 long style,
67 const wxString& name)
68 {
69
70 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
71 return false;
72
73 wxModelessWindows.Append(this);
74
75 return true;
76 }
77
78 wxFrame::~wxFrame()
79 {
80 m_isBeingDeleted = true;
81 DeleteAllBars();
82 }
83
84 // get the origin of the client area in the client coordinates
85 wxPoint wxFrame::GetClientAreaOrigin() const
86 {
87 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
88
89 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
90 wxToolBar *toolbar = GetToolBar();
91 if ( toolbar && toolbar->IsShown() )
92 {
93 int w, h;
94 toolbar->GetSize(&w, &h);
95
96 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
97 {
98 pt.x += w;
99 }
100 else
101 {
102 #if !wxMAC_USE_NATIVE_TOOLBAR
103 pt.y += h;
104 #endif
105 }
106 }
107 #endif // wxUSE_TOOLBAR
108
109 return pt;
110 }
111
112 bool wxFrame::Enable(bool enable)
113 {
114 if ( !wxWindow::Enable(enable) )
115 return false;
116
117 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
118 {
119 int iMaxMenu = m_frameMenuBar->GetMenuCount();
120 for ( int i = 0 ; i < iMaxMenu ; ++ i )
121 {
122 m_frameMenuBar->EnableTop( i , enable ) ;
123 }
124 }
125
126 return true;
127 }
128
129 wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
130 const wxString& name)
131 {
132 wxStatusBar *statusBar = NULL;
133
134 statusBar = new wxStatusBar(this, id,
135 style, name);
136 statusBar->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT ) ;
137 statusBar->SetFieldsCount(number);
138 return statusBar;
139 }
140
141 void wxFrame::PositionStatusBar()
142 {
143 if (m_frameStatusBar && m_frameStatusBar->IsShown() )
144 {
145 int w, h;
146 GetClientSize(&w, &h);
147
148 // Since we wish the status bar to be directly under the client area,
149 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
150 m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT);
151 }
152 }
153
154 // Responds to colour changes, and passes event on to children.
155 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
156 {
157 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
158 Refresh();
159
160 if ( m_frameStatusBar )
161 {
162 wxSysColourChangedEvent event2;
163 event2.SetEventObject( m_frameStatusBar );
164 m_frameStatusBar->ProcessEvent(event2);
165 }
166
167 // Propagate the event to the non-top-level children
168 wxWindow::OnSysColourChanged(event);
169 }
170
171
172 // Default activation behaviour - set the focus for the first child
173 // subwindow found.
174 void wxFrame::OnActivate(wxActivateEvent& event)
175 {
176 if ( !event.GetActive() )
177 {
178 // remember the last focused child if it is our child
179 m_winLastFocused = FindFocus();
180
181 // so we NULL it out if it's a child from some other frame
182 wxWindow *win = m_winLastFocused;
183 while ( win )
184 {
185 if ( win->IsTopLevel() )
186 {
187 if ( win != this )
188 {
189 m_winLastFocused = NULL;
190 }
191
192 break;
193 }
194
195 win = win->GetParent();
196 }
197
198 event.Skip();
199 }
200 else
201 {
202 // restore focus to the child which was last focused
203 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
204 : NULL;
205 if ( !parent )
206 {
207 parent = this;
208 }
209
210 wxSetFocusToChild(parent, &m_winLastFocused);
211
212 if ( m_frameMenuBar != NULL )
213 {
214 m_frameMenuBar->MacInstallMenuBar() ;
215 }
216 else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
217 {
218 // Trying toplevel frame menbar
219 if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
220 ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
221 }
222 }
223 }
224
225 void wxFrame::DetachMenuBar()
226 {
227 if ( m_frameMenuBar )
228 {
229 m_frameMenuBar->UnsetInvokingWindow();
230 }
231
232 wxFrameBase::DetachMenuBar();
233 }
234
235 void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
236 {
237 wxFrameBase::AttachMenuBar(menuBar);
238
239 if (m_frameMenuBar)
240 {
241 m_frameMenuBar->SetInvokingWindow( this );
242 }
243 }
244
245 void wxFrame::DoGetClientSize(int *x, int *y) const
246 {
247 wxTopLevelWindow::DoGetClientSize( x , y ) ;
248
249 #if wxUSE_STATUSBAR
250 if ( GetStatusBar() && GetStatusBar()->IsShown() && y )
251 {
252 *y -= WX_MAC_STATUSBAR_HEIGHT;
253 }
254 #endif // wxUSE_STATUSBAR
255
256 #if wxUSE_TOOLBAR
257 wxToolBar *toolbar = GetToolBar();
258 if ( toolbar && toolbar->IsShown() )
259 {
260 int w, h;
261 toolbar->GetSize(&w, &h);
262
263 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
264 {
265 if ( x ) *x -= w;
266 }
267 else
268 {
269 #if !wxMAC_USE_NATIVE_TOOLBAR
270 if ( y ) *y -= h;
271 #endif
272 }
273 }
274 #endif // wxUSE_TOOLBAR
275 }
276
277 bool wxFrame::MacIsChildOfClientArea( const wxWindow* child ) const
278 {
279 #if wxUSE_STATUSBAR
280 if ( child == GetStatusBar() )
281 return false ;
282 #endif // wxUSE_STATUSBAR
283
284 #if wxUSE_TOOLBAR
285 if ( child == GetToolBar() )
286 return false ;
287 #endif // wxUSE_TOOLBAR
288
289 return wxFrameBase::MacIsChildOfClientArea( child ) ;
290 }
291
292 void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
293 {
294 int currentclientwidth , currentclientheight ;
295 int currentwidth , currentheight ;
296
297 GetClientSize( &currentclientwidth , &currentclientheight ) ;
298 if ( clientwidth == -1 )
299 clientwidth = currentclientwidth ;
300 if ( clientheight == -1 )
301 clientheight = currentclientheight ;
302 GetSize( &currentwidth , &currentheight ) ;
303
304 // find the current client size
305
306 // Find the difference between the entire window (title bar and all)
307 // and the client area; add this to the new client size to move the
308 // window
309
310 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
311 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
312 }
313
314
315 #if wxUSE_TOOLBAR
316 void wxFrame::SetToolBar(wxToolBar *toolbar)
317 {
318 if ( m_frameToolBar == toolbar )
319 return ;
320
321 #if wxMAC_USE_NATIVE_TOOLBAR
322 if ( m_frameToolBar )
323 m_frameToolBar->MacInstallNativeToolbar(false) ;
324 #endif
325
326 m_frameToolBar = toolbar ;
327 #if wxMAC_USE_NATIVE_TOOLBAR
328 if ( toolbar )
329 toolbar->MacInstallNativeToolbar( true ) ;
330 #endif
331 }
332
333 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
334 {
335 if ( wxFrameBase::CreateToolBar(style, id, name) )
336 {
337 PositionToolBar();
338 }
339
340 return m_frameToolBar;
341 }
342
343 void wxFrame::PositionToolBar()
344 {
345 int cw, ch;
346
347 GetSize( &cw , &ch ) ;
348
349 if ( GetStatusBar() && GetStatusBar()->IsShown())
350 {
351 int statusX, statusY;
352 GetStatusBar()->GetClientSize(&statusX, &statusY);
353 ch -= statusY;
354 }
355
356 if (GetToolBar())
357 {
358 int tx, ty, tw, th;
359 tx = ty = 0 ;
360
361 GetToolBar()->GetSize(& tw, & th);
362 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
363 {
364 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
365 // means, pretend we don't have toolbar/status bar, so we
366 // have the original client size.
367 GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
368 }
369 else
370 {
371 #if !wxMAC_USE_NATIVE_TOOLBAR
372 // Use the 'real' position
373 GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS );
374 #endif
375 }
376 }
377 }
378 #endif