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 #if !USE_SHARED_LIBRARY
34 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
35 EVT_ACTIVATE(wxFrame::OnActivate
)
36 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
37 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
38 // EVT_IDLE(wxFrame::OnIdle)
39 // EVT_CLOSE(wxFrame::OnCloseWindow)
42 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
45 #define WX_MAC_STATUSBAR_HEIGHT 18
46 // ----------------------------------------------------------------------------
47 // creation/destruction
48 // ----------------------------------------------------------------------------
52 m_frameMenuBar
= NULL
;
55 m_frameToolBar
= NULL
;
57 m_frameStatusBar
= NULL
;
58 m_winLastFocused
= NULL
;
67 bool wxFrame::Create(wxWindow
*parent
,
69 const wxString
& title
,
76 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
79 wxModelessWindows
.Append(this);
86 m_isBeingDeleted
= TRUE
;
91 bool wxFrame::Enable(bool enable
)
93 if ( !wxWindow::Enable(enable
) )
96 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
98 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
99 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
101 m_frameMenuBar
->EnableTop( i
, enable
) ;
108 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
109 const wxString
& name
)
111 wxStatusBar
*statusBar
= NULL
;
113 statusBar
= new wxStatusBar(this, id
,
115 statusBar
->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT
) ;
116 statusBar
->SetFieldsCount(number
);
120 void wxFrame::PositionStatusBar()
122 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
125 GetClientSize(&w
, &h
);
127 // Since we wish the status bar to be directly under the client area,
128 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
129 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
133 // Responds to colour changes, and passes event on to children.
134 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
136 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
139 if ( m_frameStatusBar
)
141 wxSysColourChangedEvent event2
;
142 event2
.SetEventObject( m_frameStatusBar
);
143 m_frameStatusBar
->ProcessEvent(event2
);
146 // Propagate the event to the non-top-level children
147 wxWindow::OnSysColourChanged(event
);
151 // Default activation behaviour - set the focus for the first child
153 void wxFrame::OnActivate(wxActivateEvent
& event
)
155 if ( !event
.GetActive() )
157 // remember the last focused child if it is our child
158 m_winLastFocused
= FindFocus();
160 // so we NULL it out if it's a child from some other frame
161 wxWindow
*win
= m_winLastFocused
;
164 if ( win
->IsTopLevel() )
168 m_winLastFocused
= NULL
;
174 win
= win
->GetParent();
181 // restore focus to the child which was last focused
182 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
189 wxSetFocusToChild(parent
, &m_winLastFocused
);
191 if ( m_frameMenuBar
!= NULL
)
193 m_frameMenuBar
->MacInstallMenuBar() ;
195 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
197 // Trying toplevel frame menbar
198 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
199 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
204 void wxFrame::DetachMenuBar()
206 if ( m_frameMenuBar
)
208 m_frameMenuBar
->UnsetInvokingWindow();
211 wxFrameBase::DetachMenuBar();
214 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
216 wxFrameBase::AttachMenuBar(menuBar
);
220 m_frameMenuBar
->SetInvokingWindow( this );
224 void wxFrame::DoGetClientSize(int *x
, int *y
) const
226 wxTopLevelWindow::DoGetClientSize( x
, y
) ;
229 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
231 if ( y
) *y
-= WX_MAC_STATUSBAR_HEIGHT
;
233 #endif // wxUSE_STATUSBAR
236 wxToolBar
*toolbar
= GetToolBar();
237 if ( toolbar
&& toolbar
->IsShown() )
240 toolbar
->GetSize(&w
, &h
);
242 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
251 #endif // wxUSE_TOOLBAR
254 bool wxFrame::MacIsChildOfClientArea( const wxWindow
* child
) const
257 if ( child
== GetStatusBar() )
259 #endif // wxUSE_STATUSBAR
262 if ( child
== GetToolBar() )
264 #endif // wxUSE_TOOLBAR
266 return wxFrameBase::MacIsChildOfClientArea( child
) ;
269 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
271 int currentclientwidth
, currentclientheight
;
272 int currentwidth
, currentheight
;
274 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
275 if ( clientwidth
== -1 )
276 clientwidth
= currentclientwidth
;
277 if ( clientheight
== -1 )
278 clientheight
= currentclientheight
;
279 GetSize( ¤twidth
, ¤theight
) ;
281 // find the current client size
283 // Find the difference between the entire window (title bar and all)
284 // and the client area; add this to the new client size to move the
287 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
288 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
293 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
295 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
300 return m_frameToolBar
;
303 void wxFrame::PositionToolBar()
307 GetSize( &cw
, &ch
) ;
309 if ( GetStatusBar() && GetStatusBar()->IsShown())
311 int statusX
, statusY
;
312 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
321 GetToolBar()->GetSize(& tw
, & th
);
322 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
324 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
325 // means, pretend we don't have toolbar/status bar, so we
326 // have the original client size.
327 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
331 // Use the 'real' position
332 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);