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
40 // ----------------------------------------------------------------------------
41 // creation/destruction
42 // ----------------------------------------------------------------------------
46 m_frameMenuBar
= NULL
;
49 m_frameToolBar
= NULL
;
51 m_frameStatusBar
= NULL
;
52 m_winLastFocused
= NULL
;
61 bool wxFrame::Create(wxWindow
*parent
,
63 const wxString
& title
,
70 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
73 wxModelessWindows
.Append(this);
80 m_isBeingDeleted
= true;
84 // get the origin of the client area in the client coordinates
85 wxPoint
wxFrame::GetClientAreaOrigin() const
87 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
89 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
90 wxToolBar
*toolbar
= GetToolBar();
91 if ( toolbar
&& toolbar
->IsShown() )
94 toolbar
->GetSize(&w
, &h
);
96 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
102 #if !wxMAC_USE_NATIVE_TOOLBAR
107 #endif // wxUSE_TOOLBAR
112 bool wxFrame::Enable(bool enable
)
114 if ( !wxWindow::Enable(enable
) )
117 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
119 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
120 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
122 m_frameMenuBar
->EnableTop( i
, enable
) ;
129 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
130 const wxString
& name
)
132 wxStatusBar
*statusBar
= NULL
;
134 statusBar
= new wxStatusBar(this, id
,
136 statusBar
->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT
) ;
137 statusBar
->SetFieldsCount(number
);
141 void wxFrame::PositionStatusBar()
143 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
146 GetClientSize(&w
, &h
);
148 // Since we wish the status bar to be directly under the client area,
149 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
150 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
154 // Responds to colour changes, and passes event on to children.
155 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
157 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
160 if ( m_frameStatusBar
)
162 wxSysColourChangedEvent event2
;
163 event2
.SetEventObject( m_frameStatusBar
);
164 m_frameStatusBar
->ProcessEvent(event2
);
167 // Propagate the event to the non-top-level children
168 wxWindow::OnSysColourChanged(event
);
172 // Default activation behaviour - set the focus for the first child
174 void wxFrame::OnActivate(wxActivateEvent
& event
)
176 if ( !event
.GetActive() )
178 // remember the last focused child if it is our child
179 m_winLastFocused
= FindFocus();
181 // so we NULL it out if it's a child from some other frame
182 wxWindow
*win
= m_winLastFocused
;
185 if ( win
->IsTopLevel() )
189 m_winLastFocused
= NULL
;
195 win
= win
->GetParent();
202 // restore focus to the child which was last focused
203 wxWindow
*parent
= m_winLastFocused
? 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 menbar
219 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
220 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
225 void wxFrame::DetachMenuBar()
227 if ( m_frameMenuBar
)
229 m_frameMenuBar
->UnsetInvokingWindow();
232 wxFrameBase::DetachMenuBar();
235 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
237 wxFrameBase::AttachMenuBar(menuBar
);
241 m_frameMenuBar
->SetInvokingWindow( this );
245 void wxFrame::DoGetClientSize(int *x
, int *y
) const
247 wxTopLevelWindow::DoGetClientSize( x
, y
) ;
250 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
252 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
254 #endif // wxUSE_STATUSBAR
257 wxToolBar
*toolbar
= GetToolBar();
258 if ( toolbar
&& toolbar
->IsShown() )
261 toolbar
->GetSize(&w
, &h
);
263 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
269 #if !wxMAC_USE_NATIVE_TOOLBAR
274 #endif // wxUSE_TOOLBAR
277 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
280 if ( child
== GetStatusBar() )
282 #endif // wxUSE_STATUSBAR
285 if ( child
== GetToolBar() )
287 #endif // wxUSE_TOOLBAR
289 return wxFrameBase::MacIsChildOfClientArea( child
) ;
292 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
294 int currentclientwidth
, currentclientheight
;
295 int currentwidth
, currentheight
;
297 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
298 if ( clientwidth
== -1 )
299 clientwidth
= currentclientwidth
;
300 if ( clientheight
== -1 )
301 clientheight
= currentclientheight
;
302 GetSize( ¤twidth
, ¤theight
) ;
304 // find the current client size
306 // Find the difference between the entire window (title bar and all)
307 // and the client area; add this to the new client size to move the
310 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
311 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
;
327 #if wxMAC_USE_NATIVE_TOOLBAR
329 toolbar
->MacInstallNativeToolbar( true ) ;
333 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
335 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
340 return m_frameToolBar
;
343 void wxFrame::PositionToolBar()
347 GetSize( &cw
, &ch
) ;
349 if ( GetStatusBar() && GetStatusBar()->IsShown())
351 int statusX
, statusY
;
352 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
361 GetToolBar()->GetSize(& tw
, & th
);
362 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
364 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
365 // means, pretend we don't have toolbar/status bar, so we
366 // have the original client size.
367 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
371 #if !wxMAC_USE_NATIVE_TOOLBAR
372 // Use the 'real' position
373 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);