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();
218 wxFrame
*tlf
= wxDynamicCast( wxTheApp
->GetTopWindow(), wxFrame
);
221 // Trying top-level frame membar
222 if (tlf
->GetMenuBar())
223 tlf
->GetMenuBar()->MacInstallMenuBar();
229 void wxFrame::DetachMenuBar()
231 if ( m_frameMenuBar
)
232 m_frameMenuBar
->UnsetInvokingWindow();
234 wxFrameBase::DetachMenuBar();
237 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
239 wxFrame
* tlf
= wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame
);
240 bool makeCurrent
= false;
242 // if this is already the current menubar or we are the frontmost window
243 if ( (tlf
== this) || (m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar()) )
245 // or there is an app-level menubar like MDI
246 else if ( tlf
&& (tlf
->GetMenuBar() == NULL
) && (((wxFrame
*)wxTheApp
->GetTopWindow()) == this) )
249 wxFrameBase::AttachMenuBar( menuBar
);
253 m_frameMenuBar
->SetInvokingWindow( this );
255 m_frameMenuBar
->MacInstallMenuBar();
259 void wxFrame::DoGetClientSize(int *x
, int *y
) const
261 wxTopLevelWindow::DoGetClientSize( x
, y
);
264 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
265 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
269 wxToolBar
*toolbar
= GetToolBar();
270 if ( toolbar
&& toolbar
->IsShown() )
273 toolbar
->GetSize(&w
, &h
);
275 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
282 #if !wxMAC_USE_NATIVE_TOOLBAR
291 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
294 if ( child
== GetStatusBar() )
299 if ( child
== GetToolBar() )
303 return wxFrameBase::MacIsChildOfClientArea( child
) ;
306 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
308 int currentclientwidth
, currentclientheight
;
309 int currentwidth
, currentheight
;
311 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
312 if ( clientwidth
== -1 )
313 clientwidth
= currentclientwidth
;
314 if ( clientheight
== -1 )
315 clientheight
= currentclientheight
;
316 GetSize( ¤twidth
, ¤theight
) ;
318 // find the current client size
320 // Find the difference between the entire window (title bar and all) and
321 // the client area; add this to the new client size to move the window
322 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
323 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
327 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
329 if ( m_frameToolBar
== toolbar
)
332 #if wxMAC_USE_NATIVE_TOOLBAR
333 if ( m_frameToolBar
)
334 m_frameToolBar
->MacInstallNativeToolbar( false ) ;
337 m_frameToolBar
= toolbar
;
339 #if wxMAC_USE_NATIVE_TOOLBAR
341 toolbar
->MacInstallNativeToolbar( true ) ;
345 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
347 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
350 return m_frameToolBar
;
353 void wxFrame::PositionToolBar()
357 GetSize( &cw
, &ch
) ;
359 if (GetStatusBar() && GetStatusBar()->IsShown())
361 int statusX
, statusY
;
363 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
372 GetToolBar()->GetSize(&tw
, &th
);
373 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
375 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
376 // means, pretend we don't have toolbar/status bar, so we
377 // have the original client size.
378 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
382 #if !wxMAC_USE_NATIVE_TOOLBAR
383 // Use the 'real' position
384 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
390 void wxFrame::PositionBars()