1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/statusbr.h"
16 #include "wx/toolbar.h"
17 #include "wx/menuitem.h"
19 #include "wx/dcclient.h"
20 #include "wx/dialog.h"
21 #include "wx/settings.h"
24 #include "wx/mac/uma.h"
26 extern wxWindowList wxModelessWindows
;
27 extern wxList wxPendingDelete
;
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_frameMenuBar
= NULL
;
48 m_frameStatusBar
= NULL
;
49 m_winLastFocused
= NULL
;
52 m_frameToolBar
= NULL
;
56 // NB: is this used anywhere?
63 bool wxFrame::Create(wxWindow
*parent
,
65 const wxString
& title
,
72 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
75 wxModelessWindows
.Append(this);
82 m_isBeingDeleted
= true;
86 // get the origin of the client area in the client coordinates
87 wxPoint
wxFrame::GetClientAreaOrigin() const
89 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
91 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
92 wxToolBar
*toolbar
= GetToolBar();
93 if ( toolbar
&& toolbar
->IsShown() )
96 toolbar
->GetSize(&w
, &h
);
98 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
104 #if !wxMAC_USE_NATIVE_TOOLBAR
114 bool wxFrame::Enable(bool enable
)
116 if ( !wxWindow::Enable(enable
) )
119 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
121 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
122 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
124 m_frameMenuBar
->EnableTop( i
, enable
) ;
131 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
132 const wxString
& name
)
134 wxStatusBar
*statusBar
;
136 statusBar
= new wxStatusBar(this, id
, style
, name
);
137 statusBar
->SetSize(100 , WX_MAC_STATUSBAR_HEIGHT
);
138 statusBar
->SetFieldsCount(number
);
143 void wxFrame::PositionStatusBar()
145 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
148 GetClientSize(&w
, &h
);
150 // Since we wish the status bar to be directly under the client area,
151 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
152 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
156 // Responds to colour changes, and passes event on to children.
157 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
159 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
162 if ( m_frameStatusBar
)
164 wxSysColourChangedEvent event2
;
166 event2
.SetEventObject( m_frameStatusBar
);
167 m_frameStatusBar
->ProcessEvent(event2
);
170 // Propagate the event to the non-top-level children
171 wxWindow::OnSysColourChanged(event
);
174 // Default activation behaviour - set the focus for the first child
176 void wxFrame::OnActivate(wxActivateEvent
& event
)
178 if ( !event
.GetActive() )
180 // remember the last focused child if it is our child
181 m_winLastFocused
= FindFocus();
183 // so we NULL it out if it's a child from some other frame
184 wxWindow
*win
= m_winLastFocused
;
187 if ( win
->IsTopLevel() )
190 m_winLastFocused
= NULL
;
195 win
= win
->GetParent();
202 // restore focus to the child which was last focused
203 wxWindow
*parent
= m_winLastFocused
204 ? m_winLastFocused
->GetParent()
210 wxSetFocusToChild(parent
, &m_winLastFocused
);
212 if (m_frameMenuBar
!= NULL
)
214 m_frameMenuBar
->MacInstallMenuBar() ;
216 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
218 // Trying toplevel frame membar
219 if (((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar())
220 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
225 void wxFrame::DetachMenuBar()
227 if ( m_frameMenuBar
)
228 m_frameMenuBar
->UnsetInvokingWindow();
230 wxFrameBase::DetachMenuBar();
233 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
235 wxFrameBase::AttachMenuBar(menuBar
);
238 m_frameMenuBar
->SetInvokingWindow( this );
241 void wxFrame::DoGetClientSize(int *x
, int *y
) const
243 wxTopLevelWindow::DoGetClientSize( x
, y
);
246 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
247 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
251 wxToolBar
*toolbar
= GetToolBar();
252 if ( toolbar
&& toolbar
->IsShown() )
255 toolbar
->GetSize(&w
, &h
);
257 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
264 #if !wxMAC_USE_NATIVE_TOOLBAR
273 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
276 if ( child
== GetStatusBar() )
281 if ( child
== GetToolBar() )
285 return wxFrameBase::MacIsChildOfClientArea( child
) ;
288 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
290 int currentclientwidth
, currentclientheight
;
291 int currentwidth
, currentheight
;
293 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
294 if ( clientwidth
== -1 )
295 clientwidth
= currentclientwidth
;
296 if ( clientheight
== -1 )
297 clientheight
= currentclientheight
;
298 GetSize( ¤twidth
, ¤theight
) ;
300 // find the current client size
302 // Find the difference between the entire window (title bar and all) and
303 // the client area; add this to the new client size to move the window
304 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
305 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
309 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
311 if ( m_frameToolBar
== toolbar
)
314 #if wxMAC_USE_NATIVE_TOOLBAR
315 if ( m_frameToolBar
)
316 m_frameToolBar
->MacInstallNativeToolbar( false ) ;
319 m_frameToolBar
= toolbar
;
321 #if wxMAC_USE_NATIVE_TOOLBAR
323 toolbar
->MacInstallNativeToolbar( true ) ;
327 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
329 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
332 return m_frameToolBar
;
335 void wxFrame::PositionToolBar()
339 GetSize( &cw
, &ch
) ;
341 if (GetStatusBar() && GetStatusBar()->IsShown())
343 int statusX
, statusY
;
345 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
354 GetToolBar()->GetSize(&tw
, &th
);
355 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
357 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
358 // means, pretend we don't have toolbar/status bar, so we
359 // have the original client size.
360 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
364 #if !wxMAC_USE_NATIVE_TOOLBAR
365 // Use the 'real' position
366 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);