1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "frame.h"
17 #include "wx/statusbr.h"
18 #include "wx/toolbar.h"
19 #include "wx/menuitem.h"
21 #include "wx/dcclient.h"
22 #include "wx/dialog.h"
23 #include "wx/settings.h"
26 #include "wx/mac/uma.h"
28 extern wxWindowList wxModelessWindows
;
29 extern wxList wxPendingDelete
;
31 #if !USE_SHARED_LIBRARY
32 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
33 EVT_ACTIVATE(wxFrame::OnActivate
)
34 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
35 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
36 // EVT_IDLE(wxFrame::OnIdle)
37 // EVT_CLOSE(wxFrame::OnCloseWindow)
40 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
43 #define WX_MAC_STATUSBAR_HEIGHT 15
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
;
89 bool wxFrame::Enable(bool enable
)
91 if ( !wxWindow::Enable(enable
) )
94 if ( m_frameMenuBar
&& m_frameMenuBar
== wxMenuBar::MacGetInstalledMenuBar() )
96 int iMaxMenu
= m_frameMenuBar
->GetMenuCount();
97 for ( int i
= 0 ; i
< iMaxMenu
; ++ i
)
99 m_frameMenuBar
->EnableTop( i
, enable
) ;
106 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
107 const wxString
& name
)
109 wxStatusBar
*statusBar
= NULL
;
111 statusBar
= new wxStatusBar(this, id
,
113 statusBar
->SetSize( 100 , 15 ) ;
114 statusBar
->SetFieldsCount(number
);
118 void wxFrame::PositionStatusBar()
120 if (m_frameStatusBar
)
123 GetClientSize(&w
, &h
);
125 m_frameStatusBar
->GetSize(&sw
, &sh
);
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
, sh
);
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() && y
)
231 int statusX
, statusY
;
232 GetStatusBar()->GetSize(&statusX
, &statusY
);
233 if ( y
) *y
-= statusY
;
235 #endif // wxUSE_STATUSBAR
238 wxToolBar
*toolbar
= GetToolBar();
239 if ( toolbar
&& toolbar
->IsShown() )
242 toolbar
->GetSize(&w
, &h
);
244 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
253 #endif // wxUSE_TOOLBAR
256 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
258 int currentclientwidth
, currentclientheight
;
259 int currentwidth
, currentheight
;
261 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
262 if ( clientwidth
== -1 )
263 clientwidth
= currentclientwidth
;
264 if ( clientheight
== -1 )
265 clientheight
= currentclientheight
;
266 GetSize( ¤twidth
, ¤theight
) ;
268 // find the current client size
270 // Find the difference between the entire window (title bar and all)
271 // and the client area; add this to the new client size to move the
274 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
275 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
280 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
282 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
287 return m_frameToolBar
;
290 void wxFrame::PositionToolBar()
294 GetSize( &cw
, &ch
) ;
296 if ( GetStatusBar() )
298 int statusX
, statusY
;
299 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
308 GetToolBar()->GetSize(& tw
, & th
);
309 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
311 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
312 // means, pretend we don't have toolbar/status bar, so we
313 // have the original client size.
314 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
318 // Use the 'real' position
319 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);