1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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/uma.h"
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)
37 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
39 #define WX_MAC_STATUSBAR_HEIGHT 18
41 // ----------------------------------------------------------------------------
42 // creation/destruction
43 // ----------------------------------------------------------------------------
47 m_winLastFocused
= NULL
;
50 bool wxFrame::Create(wxWindow
*parent
,
52 const wxString
& title
,
59 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
67 m_isBeingDeleted
= true;
71 // get the origin of the client area in the client coordinates
72 wxPoint
wxFrame::GetClientAreaOrigin() const
74 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
76 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
77 wxToolBar
*toolbar
= GetToolBar();
78 if ( toolbar
&& toolbar
->IsShown() )
81 toolbar
->GetSize(&w
, &h
);
83 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
89 #if !wxMAC_USE_NATIVE_TOOLBAR
99 bool wxFrame::Enable(bool enable
)
101 if ( !wxWindow::Enable(enable
) )
104 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
106 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
107 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
109 m_frameMenuBar
->EnableTop( i
, enable
) ;
117 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
118 const wxString
& name
)
120 wxStatusBar
*statusBar
;
122 statusBar
= new wxStatusBar(this, id
, style
, name
);
123 statusBar
->SetSize(100, WX_MAC_STATUSBAR_HEIGHT
);
124 statusBar
->SetFieldsCount(number
);
129 void wxFrame::PositionStatusBar()
131 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
134 GetClientSize(&w
, &h
);
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
);
141 #endif // wxUSE_STATUSBAR
143 // Responds to colour changes, and passes event on to children.
144 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
146 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
150 if ( m_frameStatusBar
)
152 wxSysColourChangedEvent event2
;
154 event2
.SetEventObject( m_frameStatusBar
);
155 m_frameStatusBar
->ProcessEvent(event2
);
157 #endif // wxUSE_STATUSBAR
159 // Propagate the event to the non-top-level children
160 wxWindow::OnSysColourChanged(event
);
163 // Default activation behaviour - set the focus for the first child
165 void wxFrame::OnActivate(wxActivateEvent
& event
)
167 if ( !event
.GetActive() )
169 // remember the last focused child if it is our child
170 m_winLastFocused
= FindFocus();
172 // so we NULL it out if it's a child from some other frame
173 wxWindow
*win
= m_winLastFocused
;
176 if ( win
->IsTopLevel() )
179 m_winLastFocused
= NULL
;
184 win
= win
->GetParent();
191 // restore focus to the child which was last focused
192 wxWindow
*parent
= m_winLastFocused
193 ? m_winLastFocused
->GetParent()
199 wxSetFocusToChild(parent
, &m_winLastFocused
);
201 if (m_frameMenuBar
!= NULL
)
203 m_frameMenuBar
->MacInstallMenuBar();
207 wxFrame
*tlf
= wxDynamicCast( wxTheApp
->GetTopWindow(), wxFrame
);
210 // Trying top-level frame membar
211 if (tlf
->GetMenuBar())
212 tlf
->GetMenuBar()->MacInstallMenuBar();
218 void wxFrame::DetachMenuBar()
220 if ( m_frameMenuBar
)
221 m_frameMenuBar
->UnsetInvokingWindow();
223 wxFrameBase::DetachMenuBar();
226 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
228 wxFrame
* tlf
= wxDynamicCast( wxNonOwnedWindow::GetFromWXWindow( (WXWindow
) FrontNonFloatingWindow() ) , wxFrame
);
229 bool makeCurrent
= false;
231 // if this is already the current menubar or we are the frontmost window
232 if ( (tlf
== this) || (m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar()) )
234 // or there is an app-level menubar like MDI
235 else if ( tlf
&& (tlf
->GetMenuBar() == NULL
) && (((wxFrame
*)wxTheApp
->GetTopWindow()) == this) )
238 wxFrameBase::AttachMenuBar( menuBar
);
242 m_frameMenuBar
->SetInvokingWindow( this );
244 m_frameMenuBar
->MacInstallMenuBar();
248 void wxFrame::DoGetClientSize(int *x
, int *y
) const
250 wxTopLevelWindow::DoGetClientSize( x
, y
);
253 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
254 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
258 wxToolBar
*toolbar
= GetToolBar();
259 if ( toolbar
&& toolbar
->IsShown() )
262 toolbar
->GetSize(&w
, &h
);
264 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
271 #if !wxMAC_USE_NATIVE_TOOLBAR
280 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
283 if ( child
== GetStatusBar() )
288 if ( child
== GetToolBar() )
292 return wxFrameBase::MacIsChildOfClientArea( child
) ;
295 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
297 int currentclientwidth
, currentclientheight
;
298 int currentwidth
, currentheight
;
300 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
301 if ( clientwidth
== -1 )
302 clientwidth
= currentclientwidth
;
303 if ( clientheight
== -1 )
304 clientheight
= currentclientheight
;
305 GetSize( ¤twidth
, ¤theight
) ;
307 // find the current client size
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
) ;
316 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
318 if ( m_frameToolBar
== toolbar
)
321 #if wxMAC_USE_NATIVE_TOOLBAR
322 if ( m_frameToolBar
)
323 m_frameToolBar
->MacInstallNativeToolbar( false ) ;
326 m_frameToolBar
= toolbar
;
328 #if wxMAC_USE_NATIVE_TOOLBAR
330 toolbar
->MacInstallNativeToolbar( true ) ;
334 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
336 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
339 return m_frameToolBar
;
342 void wxFrame::PositionToolBar()
346 GetSize( &cw
, &ch
) ;
352 if (GetStatusBar() && GetStatusBar()->IsShown())
354 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
364 GetToolBar()->GetSize(&tw
, &th
);
365 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
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
);
372 else if (GetToolBar()->GetWindowStyleFlag() & wxTB_BOTTOM
)
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.
378 ty
= ch
- (th
+ statusY
);
379 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
383 #if !wxMAC_USE_NATIVE_TOOLBAR
384 // Use the 'real' position
385 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
390 #endif // wxUSE_TOOLBAR
392 void wxFrame::PositionBars()