1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/frame.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include "wx/dcclient.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"
27 #include "wx/osx/private.h"
29 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
30 EVT_ACTIVATE(wxFrame::OnActivate
)
31 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
34 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
36 #define WX_MAC_STATUSBAR_HEIGHT 18
38 // ----------------------------------------------------------------------------
39 // creation/destruction
40 // ----------------------------------------------------------------------------
44 m_winLastFocused
= NULL
;
47 bool wxFrame::Create(wxWindow
*parent
,
49 const wxString
& title
,
56 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
64 m_isBeingDeleted
= true;
68 // get the origin of the client area in the client coordinates
69 wxPoint
wxFrame::GetClientAreaOrigin() const
71 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
73 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
74 wxToolBar
*toolbar
= GetToolBar();
75 if ( toolbar
&& toolbar
->IsShown() )
78 toolbar
->GetSize(&w
, &h
);
80 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
86 #if !wxOSX_USE_NATIVE_TOOLBAR
96 bool wxFrame::Enable(bool enable
)
98 if ( !wxWindow::Enable(enable
) )
102 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
104 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
105 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
107 m_frameMenuBar
->EnableTop( i
, enable
) ;
115 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
116 const wxString
& name
)
118 wxStatusBar
*statusBar
;
120 statusBar
= new wxStatusBar(this, id
, style
, name
);
121 statusBar
->SetSize(100, WX_MAC_STATUSBAR_HEIGHT
);
122 statusBar
->SetFieldsCount(number
);
127 void wxFrame::PositionStatusBar()
129 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
132 GetClientSize(&w
, &h
);
134 // Since we wish the status bar to be directly under the client area,
135 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
136 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
139 #endif // wxUSE_STATUSBAR
141 // Responds to colour changes, and passes event on to children.
142 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
144 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
148 if ( m_frameStatusBar
)
150 wxSysColourChangedEvent event2
;
152 event2
.SetEventObject( m_frameStatusBar
);
153 m_frameStatusBar
->ProcessEvent(event2
);
155 #endif // wxUSE_STATUSBAR
157 // Propagate the event to the non-top-level children
158 wxWindow::OnSysColourChanged(event
);
161 // Default activation behaviour - set the focus for the first child
163 void wxFrame::OnActivate(wxActivateEvent
& event
)
165 if ( !event
.GetActive() )
167 // remember the last focused child if it is our child
168 m_winLastFocused
= FindFocus();
170 // so we NULL it out if it's a child from some other frame
171 wxWindow
*win
= m_winLastFocused
;
174 if ( win
->IsTopLevel() )
177 m_winLastFocused
= NULL
;
182 win
= win
->GetParent();
189 // restore focus to the child which was last focused
190 wxWindow
*parent
= m_winLastFocused
191 ? m_winLastFocused
->GetParent()
197 wxSetFocusToChild(parent
, &m_winLastFocused
);
200 if (m_frameMenuBar
!= NULL
)
202 m_frameMenuBar
->MacInstallMenuBar();
206 wxFrame
*tlf
= wxDynamicCast( wxTheApp
->GetTopWindow(), wxFrame
);
209 // Trying top-level frame membar
210 if (tlf
->GetMenuBar())
211 tlf
->GetMenuBar()->MacInstallMenuBar();
218 void wxFrame::HandleResized( double timestampsec
)
220 // according to the other ports we handle this within the OS level
221 // resize event, not within a wxSizeEvent
225 wxNonOwnedWindow::HandleResized( timestampsec
);
229 void wxFrame::DetachMenuBar()
231 if ( m_frameMenuBar
)
232 m_frameMenuBar
->UnsetInvokingWindow();
234 wxFrameBase::DetachMenuBar();
237 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
240 wxFrame
* tlf
= wxDynamicCast( wxNonOwnedWindow::GetFromWXWindow( (WXWindow
) FrontNonFloatingWindow() ) , wxFrame
);
242 wxFrame
* tlf
= (wxFrame
*) wxTheApp
->GetTopWindow();
244 bool makeCurrent
= false;
246 // if this is already the current menubar or we are the frontmost window
247 if ( (tlf
== this) || (m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar()) )
249 // or there is an app-level menubar like MDI
250 else if ( tlf
&& (tlf
->GetMenuBar() == NULL
) && (((wxFrame
*)wxTheApp
->GetTopWindow()) == this) )
253 wxFrameBase::AttachMenuBar( menuBar
);
257 m_frameMenuBar
->SetInvokingWindow( this );
259 m_frameMenuBar
->MacInstallMenuBar();
264 void wxFrame::DoGetClientSize(int *x
, int *y
) const
266 wxTopLevelWindow::DoGetClientSize( x
, y
);
269 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
270 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
274 wxToolBar
*toolbar
= GetToolBar();
275 if ( toolbar
&& toolbar
->IsShown() )
278 toolbar
->GetSize(&w
, &h
);
280 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
287 #if !wxOSX_USE_NATIVE_TOOLBAR
296 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
299 if ( child
== GetStatusBar() )
304 if ( child
== GetToolBar() )
308 return wxFrameBase::MacIsChildOfClientArea( child
) ;
311 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
313 int currentclientwidth
, currentclientheight
;
314 int currentwidth
, currentheight
;
316 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
317 if ( clientwidth
== -1 )
318 clientwidth
= currentclientwidth
;
319 if ( clientheight
== -1 )
320 clientheight
= currentclientheight
;
321 GetSize( ¤twidth
, ¤theight
) ;
323 // find the current client size
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
) ;
332 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
334 if ( m_frameToolBar
== toolbar
)
337 #if wxOSX_USE_NATIVE_TOOLBAR
338 if ( m_frameToolBar
)
339 m_frameToolBar
->MacInstallNativeToolbar( false ) ;
342 m_frameToolBar
= toolbar
;
344 #if wxOSX_USE_NATIVE_TOOLBAR
346 toolbar
->MacInstallNativeToolbar( true ) ;
350 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
352 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
355 return m_frameToolBar
;
358 void wxFrame::PositionToolBar()
362 GetSize( &cw
, &ch
) ;
368 if (GetStatusBar() && GetStatusBar()->IsShown())
370 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
380 GetToolBar()->GetSize(&tw
, &th
);
381 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
383 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
384 // means, pretend we don't have toolbar/status bar, so we
385 // have the original client size.
386 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
388 else if (GetToolBar()->GetWindowStyleFlag() & wxTB_BOTTOM
)
390 //FIXME: this positions the tool bar almost correctly, but still it doesn't work right yet,
391 //as 1) the space for the 'old' top toolbar is still taken up, and 2) the toolbar
392 //doesn't extend it's width to the width of the frame.
394 ty
= ch
- (th
+ statusY
);
395 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
399 #if !wxOSX_USE_NATIVE_TOOLBAR
400 // Use the 'real' position
401 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
406 #endif // wxUSE_TOOLBAR
408 void wxFrame::PositionBars()