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 , WX_MAC_STATUSBAR_HEIGHT
) ;
114 statusBar
->SetFieldsCount(number
);
118 void wxFrame::PositionStatusBar()
120 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() )
123 GetClientSize(&w
, &h
);
125 // Since we wish the status bar to be directly under the client area,
126 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
127 m_frameStatusBar
->SetSize(0, h
, w
, WX_MAC_STATUSBAR_HEIGHT
);
131 // Responds to colour changes, and passes event on to children.
132 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
134 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
137 if ( m_frameStatusBar
)
139 wxSysColourChangedEvent event2
;
140 event2
.SetEventObject( m_frameStatusBar
);
141 m_frameStatusBar
->ProcessEvent(event2
);
144 // Propagate the event to the non-top-level children
145 wxWindow::OnSysColourChanged(event
);
149 // Default activation behaviour - set the focus for the first child
151 void wxFrame::OnActivate(wxActivateEvent
& event
)
153 if ( !event
.GetActive() )
155 // remember the last focused child if it is our child
156 m_winLastFocused
= FindFocus();
158 // so we NULL it out if it's a child from some other frame
159 wxWindow
*win
= m_winLastFocused
;
162 if ( win
->IsTopLevel() )
166 m_winLastFocused
= NULL
;
172 win
= win
->GetParent();
179 // restore focus to the child which was last focused
180 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
187 wxSetFocusToChild(parent
, &m_winLastFocused
);
189 if ( m_frameMenuBar
!= NULL
)
191 m_frameMenuBar
->MacInstallMenuBar() ;
193 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
195 // Trying toplevel frame menbar
196 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
197 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
202 void wxFrame::DetachMenuBar()
204 if ( m_frameMenuBar
)
206 m_frameMenuBar
->UnsetInvokingWindow();
209 wxFrameBase::DetachMenuBar();
212 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
214 wxFrameBase::AttachMenuBar(menuBar
);
218 m_frameMenuBar
->SetInvokingWindow( this );
222 void wxFrame::DoGetClientSize(int *x
, int *y
) const
224 wxTopLevelWindow::DoGetClientSize( x
, y
) ;
227 if ( GetStatusBar() && GetStatusBar()->IsShown() && y
)
229 if ( y
) *y
-= WX_MAC_STATUSBAR_HEIGHT
;
231 #endif // wxUSE_STATUSBAR
234 wxToolBar
*toolbar
= GetToolBar();
235 if ( toolbar
&& toolbar
->IsShown() )
238 toolbar
->GetSize(&w
, &h
);
240 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
249 #endif // wxUSE_TOOLBAR
252 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
254 int currentclientwidth
, currentclientheight
;
255 int currentwidth
, currentheight
;
257 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
258 if ( clientwidth
== -1 )
259 clientwidth
= currentclientwidth
;
260 if ( clientheight
== -1 )
261 clientheight
= currentclientheight
;
262 GetSize( ¤twidth
, ¤theight
) ;
264 // find the current client size
266 // Find the difference between the entire window (title bar and all)
267 // and the client area; add this to the new client size to move the
270 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
271 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
276 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
278 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
283 return m_frameToolBar
;
286 void wxFrame::PositionToolBar()
290 GetSize( &cw
, &ch
) ;
292 if ( GetStatusBar() && GetStatusBar()->IsShown())
294 int statusX
, statusY
;
295 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
304 GetToolBar()->GetSize(& tw
, & th
);
305 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
307 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
308 // means, pretend we don't have toolbar/status bar, so we
309 // have the original client size.
310 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
314 // Use the 'real' position
315 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);