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 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
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 , 15 ) ;
116 statusBar
->SetFieldsCount(number
);
120 void wxFrame::PositionStatusBar()
122 if (m_frameStatusBar
)
125 GetClientSize(&w
, &h
);
127 m_frameStatusBar
->GetSize(&sw
, &sh
);
129 // Since we wish the status bar to be directly under the client area,
130 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
131 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
135 // Responds to colour changes, and passes event on to children.
136 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
138 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
141 if ( m_frameStatusBar
)
143 wxSysColourChangedEvent event2
;
144 event2
.SetEventObject( m_frameStatusBar
);
145 m_frameStatusBar
->ProcessEvent(event2
);
148 // Propagate the event to the non-top-level children
149 wxWindow::OnSysColourChanged(event
);
153 // Default activation behaviour - set the focus for the first child
155 void wxFrame::OnActivate(wxActivateEvent
& event
)
157 if ( !event
.GetActive() )
159 // remember the last focused child if it is our child
160 m_winLastFocused
= FindFocus();
162 // so we NULL it out if it's a child from some other frame
163 wxWindow
*win
= m_winLastFocused
;
166 if ( win
->IsTopLevel() )
170 m_winLastFocused
= NULL
;
176 win
= win
->GetParent();
183 // restore focus to the child which was last focused
184 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
191 wxSetFocusToChild(parent
, &m_winLastFocused
);
193 if ( m_frameMenuBar
!= NULL
)
195 m_frameMenuBar
->MacInstallMenuBar() ;
197 else if (wxTheApp
->GetTopWindow() && wxTheApp
->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame
)))
199 // Trying toplevel frame menbar
200 if( ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar() )
201 ((wxFrame
*)wxTheApp
->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
206 void wxFrame::DetachMenuBar()
208 if ( m_frameMenuBar
)
210 m_frameMenuBar
->UnsetInvokingWindow();
213 wxFrameBase::DetachMenuBar();
216 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
218 wxFrameBase::AttachMenuBar(menuBar
);
222 m_frameMenuBar
->SetInvokingWindow( this );
226 void wxFrame::DoGetClientSize(int *x
, int *y
) const
228 wxTopLevelWindow::DoGetClientSize( x
, y
) ;
231 if ( GetStatusBar() && y
)
233 int statusX
, statusY
;
234 GetStatusBar()->GetSize(&statusX
, &statusY
);
235 if ( y
) *y
-= statusY
;
237 #endif // wxUSE_STATUSBAR
240 wxToolBar
*toolbar
= GetToolBar();
241 if ( toolbar
&& toolbar
->IsShown() )
244 toolbar
->GetSize(&w
, &h
);
246 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
255 #endif // wxUSE_TOOLBAR
258 void wxFrame::DoSetClientSize(int clientwidth
, int clientheight
)
260 int currentclientwidth
, currentclientheight
;
261 int currentwidth
, currentheight
;
263 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
264 if ( clientwidth
== -1 )
265 clientwidth
= currentclientwidth
;
266 if ( clientheight
== -1 )
267 clientheight
= currentclientheight
;
268 GetSize( ¤twidth
, ¤theight
) ;
270 // find the current client size
272 // Find the difference between the entire window (title bar and all)
273 // and the client area; add this to the new client size to move the
276 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
277 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
282 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
284 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
289 return m_frameToolBar
;
292 void wxFrame::PositionToolBar()
296 GetSize( &cw
, &ch
) ;
298 if ( GetStatusBar() )
300 int statusX
, statusY
;
301 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
310 GetToolBar()->GetSize(& tw
, & th
);
311 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
313 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
314 // means, pretend we don't have toolbar/status bar, so we
315 // have the original client size.
316 GetToolBar()->SetSize(tx
, ty
, tw
, ch
, wxSIZE_NO_ADJUSTMENTS
);
320 // Use the 'real' position
321 GetToolBar()->SetSize(tx
, ty
, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);