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