1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "frame.h"
16 #include "wx/wxprec.h"
19 #include "wx/statusbr.h"
20 #include "wx/toolbar.h"
21 #include "wx/menuitem.h"
23 #include "wx/dcclient.h"
24 #include "wx/dialog.h"
25 #include "wx/settings.h"
28 #include "wx/mac/uma.h"
30 extern wxWindowList wxModelessWindows
;
31 extern wxList wxPendingDelete
;
33 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
34 EVT_ACTIVATE(wxFrame::OnActivate
)
35 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
36 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
37 // EVT_IDLE(wxFrame::OnIdle)
38 // EVT_CLOSE(wxFrame::OnCloseWindow)
41 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
43 #define WX_MAC_STATUSBAR_HEIGHT 18
44 // ----------------------------------------------------------------------------
45 // creation/destruction
46 // ----------------------------------------------------------------------------
50 m_frameMenuBar
= NULL
;
53 m_frameToolBar
= NULL
;
55 m_frameStatusBar
= NULL
;
56 m_winLastFocused
= NULL
;
65 bool wxFrame::Create(wxWindow
*parent
,
67 const wxString
& title
,
74 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
77 wxModelessWindows
.Append(this);
84 m_isBeingDeleted
= true;
88 // get the origin of the client area in the client coordinates
89 wxPoint
wxFrame::GetClientAreaOrigin() const
91 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
93 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
94 wxToolBar
*toolbar
= GetToolBar();
95 if ( toolbar
&& toolbar
->IsShown() )
98 toolbar
->GetSize(&w
, &h
);
100 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
106 #if !wxMAC_USE_NATIVE_TOOLBAR
111 #endif // wxUSE_TOOLBAR
116 bool wxFrame::Enable(bool enable
)
118 if ( !wxWindow::Enable(enable
) )
121 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
123 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
124 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
126 m_frameMenuBar
->EnableTop( i
, enable
) ;
133 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
134 const wxString
& name
)
136 wxStatusBar
*statusBar
= NULL
;
138 statusBar
= new wxStatusBar(this, id
,
140 statusBar
->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT
) ;
141 statusBar
->SetFieldsCount(number
);
145 void wxFrame::PositionStatusBar()
147 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
150 GetClientSize(&w
, &h
);
152 // Since we wish the status bar to be directly under the client area,
153 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
154 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
158 // Responds to colour changes, and passes event on to children.
159 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
161 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
164 if ( m_frameStatusBar
)
166 wxSysColourChangedEvent event2
;
167 event2
.SetEventObject( m_frameStatusBar
);
168 m_frameStatusBar
->ProcessEvent(event2
);
171 // Propagate the event to the non-top-level children
172 wxWindow::OnSysColourChanged(event
);
176 // Default activation behaviour - set the focus for the first child
178 void wxFrame::OnActivate(wxActivateEvent
& event
)
180 if ( !event
.GetActive() )
182 // remember the last focused child if it is our child
183 m_winLastFocused
= FindFocus();
185 // so we NULL it out if it's a child from some other frame
186 wxWindow
*win
= m_winLastFocused
;
189 if ( win
->IsTopLevel() )
193 m_winLastFocused
= NULL
;
199 win
= win
->GetParent();
206 // restore focus to the child which was last focused
207 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
214 wxSetFocusToChild(parent
, &m_winLastFocused
);
216 if ( m_frameMenuBar
!= NULL
)
218 m_frameMenuBar
->MacInstallMenuBar() ;
220 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
222 // Trying toplevel frame menbar
223 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
224 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
229 void wxFrame::DetachMenuBar()
231 if ( m_frameMenuBar
)
233 m_frameMenuBar
->UnsetInvokingWindow();
236 wxFrameBase::DetachMenuBar();
239 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
241 wxFrameBase::AttachMenuBar(menuBar
);
245 m_frameMenuBar
->SetInvokingWindow( this );
249 void wxFrame::DoGetClientSize(int *x
, int *y
) const
251 wxTopLevelWindow::DoGetClientSize( x
, y
) ;
254 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
256 *y
-= WX_MAC_STATUSBAR_HEIGHT
;
258 #endif // wxUSE_STATUSBAR
261 wxToolBar
*toolbar
= GetToolBar();
262 if ( toolbar
&& toolbar
->IsShown() )
265 toolbar
->GetSize(&w
, &h
);
267 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
273 #if !wxMAC_USE_NATIVE_TOOLBAR
278 #endif // wxUSE_TOOLBAR
281 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
284 if ( child
== GetStatusBar() )
286 #endif // wxUSE_STATUSBAR
289 if ( child
== GetToolBar() )
291 #endif // wxUSE_TOOLBAR
293 return wxFrameBase::MacIsChildOfClientArea( child
) ;
296 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
298 int currentclientwidth
, currentclientheight
;
299 int currentwidth
, currentheight
;
301 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
302 if ( clientwidth
== -1 )
303 clientwidth
= currentclientwidth
;
304 if ( clientheight
== -1 )
305 clientheight
= currentclientheight
;
306 GetSize( ¤twidth
, ¤theight
) ;
308 // find the current client size
310 // Find the difference between the entire window (title bar and all)
311 // and the client area; add this to the new client size to move the
314 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
315 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
320 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
322 if ( m_frameToolBar
== toolbar
)
325 #if wxMAC_USE_NATIVE_TOOLBAR
326 if ( m_frameToolBar
)
327 m_frameToolBar
->MacInstallNativeToolbar(false) ;
330 m_frameToolBar
= toolbar
;
331 #if wxMAC_USE_NATIVE_TOOLBAR
333 toolbar
->MacInstallNativeToolbar( true ) ;
337 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
339 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
344 return m_frameToolBar
;
347 void wxFrame::PositionToolBar()
351 GetSize( &cw
, &ch
) ;
353 if ( GetStatusBar() && GetStatusBar()->IsShown())
355 int statusX
, statusY
;
356 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
365 GetToolBar()->GetSize(& tw
, & th
);
366 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
368 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
369 // means, pretend we don't have toolbar/status bar, so we
370 // have the original client size.
371 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
375 #if !wxMAC_USE_NATIVE_TOOLBAR
376 // Use the 'real' position
377 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);