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 wxFrame
* tlf
= wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame
);
236 bool makeCurrent
= false;
238 // if this is already the current menubar or we are the frontmost window
239 if ( (tlf
== this) || (m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar()) )
241 // or there is an app-level menubar like MDI
242 else if ( tlf
&& (tlf
->GetMenuBar() == NULL
) && (((wxFrame
*)wxTheApp
->GetTopWindow()) == this) )
245 wxFrameBase::AttachMenuBar( menuBar
);
249 m_frameMenuBar
->SetInvokingWindow( this );
251 m_frameMenuBar
->MacInstallMenuBar();
255 void wxFrame::DoGetClientSize(int *x
, int *y
) const
257 wxTopLevelWindow::DoGetClientSize( x
, y
);
260 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
261 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
265 wxToolBar
*toolbar
= GetToolBar();
266 if ( toolbar
&& toolbar
->IsShown() )
269 toolbar
->GetSize(&w
, &h
);
271 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
278 #if !wxMAC_USE_NATIVE_TOOLBAR
287 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
290 if ( child
== GetStatusBar() )
295 if ( child
== GetToolBar() )
299 return wxFrameBase::MacIsChildOfClientArea( child
) ;
302 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
304 int currentclientwidth
, currentclientheight
;
305 int currentwidth
, currentheight
;
307 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
308 if ( clientwidth
== -1 )
309 clientwidth
= currentclientwidth
;
310 if ( clientheight
== -1 )
311 clientheight
= currentclientheight
;
312 GetSize( ¤twidth
, ¤theight
) ;
314 // find the current client size
316 // Find the difference between the entire window (title bar and all) and
317 // the client area; add this to the new client size to move the window
318 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
319 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
323 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
325 if ( m_frameToolBar
== toolbar
)
328 #if wxMAC_USE_NATIVE_TOOLBAR
329 if ( m_frameToolBar
)
330 m_frameToolBar
->MacInstallNativeToolbar( false ) ;
333 m_frameToolBar
= toolbar
;
335 #if wxMAC_USE_NATIVE_TOOLBAR
337 toolbar
->MacInstallNativeToolbar( true ) ;
341 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
343 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
346 return m_frameToolBar
;
349 void wxFrame::PositionToolBar()
353 GetSize( &cw
, &ch
) ;
355 if (GetStatusBar() && GetStatusBar()->IsShown())
357 int statusX
, statusY
;
359 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
368 GetToolBar()->GetSize(&tw
, &th
);
369 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
371 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
372 // means, pretend we don't have toolbar/status bar, so we
373 // have the original client size.
374 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
378 #if !wxMAC_USE_NATIVE_TOOLBAR
379 // Use the 'real' position
380 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
386 void wxFrame::PositionBars()