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