1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/framecmn.cpp
3 // Purpose: common (for all platforms) wxFrame functions
4 // Author: Julian Smart, Vadim Zeitlin
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #pragma implementation "framebase.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
33 #include "wx/menuitem.h"
34 #include "wx/dcclient.h"
38 #include "wx/toolbar.h"
41 #include "wx/statusbr.h"
44 // FIXME - temporary hack in absence of wxTLW in all ports!
45 #ifndef wxTopLevelWindowNative
46 #define wxTopLevelWindow wxTopLevelWindowBase
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 BEGIN_EVENT_TABLE(wxFrameBase
, wxTopLevelWindow
)
54 EVT_IDLE(wxFrameBase::OnIdle
)
55 EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight
)
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
63 // construction/destruction
64 // ----------------------------------------------------------------------------
66 wxFrameBase::wxFrameBase()
69 m_frameMenuBar
= NULL
;
73 m_frameToolBar
= NULL
;
74 #endif // wxUSE_TOOLBAR
77 m_frameStatusBar
= NULL
;
78 #endif // wxUSE_STATUSBAR
81 wxFrame
*wxFrameBase::New(wxWindow
*parent
,
83 const wxString
& title
,
89 return new wxFrame(parent
, id
, title
, pos
, size
, style
, name
);
92 void wxFrameBase::DeleteAllBars()
97 delete m_frameMenuBar
;
98 m_frameMenuBar
= (wxMenuBar
*) NULL
;
100 #endif // wxUSE_MENUS
103 if ( m_frameStatusBar
)
105 delete m_frameStatusBar
;
106 m_frameStatusBar
= (wxStatusBar
*) NULL
;
108 #endif // wxUSE_STATUSBAR
111 if ( m_frameToolBar
)
113 delete m_frameToolBar
;
114 m_frameToolBar
= (wxToolBar
*) NULL
;
116 #endif // wxUSE_TOOLBAR
119 bool wxFrameBase::IsOneOfBars(const wxWindow
*win
) const
122 if ( win
== GetMenuBar() )
124 #endif // wxUSE_MENUS
127 if ( win
== GetStatusBar() )
129 #endif // wxUSE_STATUSBAR
132 if ( win
== GetToolBar() )
134 #endif // wxUSE_TOOLBAR
139 // ----------------------------------------------------------------------------
140 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
141 // from the client area, so the client area is what's really available for the
143 // ----------------------------------------------------------------------------
145 // get the origin of the client area in the client coordinates
146 wxPoint
wxFrameBase::GetClientAreaOrigin() const
148 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
151 if ( GetToolBar() && GetToolBar()->IsShown() )
154 GetToolBar()->GetSize(& w
, & h
);
156 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
165 #endif // wxUSE_TOOLBAR
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 bool wxFrameBase::ProcessCommand(int id
)
177 wxMenuBar
*bar
= GetMenuBar();
181 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
182 commandEvent
.SetEventObject(this);
184 wxMenuItem
*item
= bar
->FindItem(id
);
187 if (!item
->IsEnabled())
190 if (item
->IsCheckable())
194 commandEvent
.SetInt(item
->IsChecked());
198 return GetEventHandler()->ProcessEvent(commandEvent
);
199 #else // !wxUSE_MENUS
201 #endif // wxUSE_MENUS/!wxUSE_MENUS
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 void wxFrameBase::OnMenuHighlight(wxMenuEvent
& event
)
211 (void)ShowMenuHelp(GetStatusBar(), event
.GetMenuId());
212 #endif // wxUSE_STATUSBAR
215 void wxFrameBase::OnIdle(wxIdleEvent
& WXUNUSED(event
) )
219 #endif // wxUSE_MENUS
222 // ----------------------------------------------------------------------------
224 // ----------------------------------------------------------------------------
228 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
,
231 const wxString
& name
)
233 // the main status bar can only be created once (or else it should be
234 // deleted before calling CreateStatusBar() again)
235 wxCHECK_MSG( !m_frameStatusBar
, (wxStatusBar
*)NULL
,
236 wxT("recreating status bar in wxFrame") );
238 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
239 if ( m_frameStatusBar
)
242 return m_frameStatusBar
;
245 wxStatusBar
*wxFrameBase::OnCreateStatusBar(int number
,
248 const wxString
& name
)
250 wxStatusBar
*statusBar
= new wxStatusBar(this, id
, style
, name
);
252 statusBar
->SetFieldsCount(number
);
257 void wxFrameBase::SetStatusText(const wxString
& text
, int number
)
259 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
261 m_frameStatusBar
->SetStatusText(text
, number
);
264 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] )
266 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
268 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
273 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*statbar
, int menuId
)
279 // if no help string found, we will clear the status bar text
282 if ( menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */ )
284 wxMenuBar
*menuBar
= GetMenuBar();
287 // it's ok if we don't find the item because it might belong
289 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
291 helpString
= item
->GetHelp();
295 // set status text even if the string is empty - this will at least
296 // remove the string from the item which was previously selected
297 statbar
->SetStatusText(helpString
);
299 return !helpString
.IsEmpty();
300 #else // !wxUSE_MENUS
302 #endif // wxUSE_MENUS/!wxUSE_MENUS
305 #endif // wxUSE_STATUSBAR
307 // ----------------------------------------------------------------------------
309 // ----------------------------------------------------------------------------
313 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
315 const wxString
& name
)
317 // the main toolbar can't be recreated (unless it was explicitly deeleted
319 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
320 wxT("recreating toolbar in wxFrame") );
322 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
324 return m_frameToolBar
;
327 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
329 const wxString
& name
)
331 return new wxToolBar(this, id
,
332 wxDefaultPosition
, wxDefaultSize
,
336 #endif // wxUSE_TOOLBAR
338 // ----------------------------------------------------------------------------
340 // ----------------------------------------------------------------------------
345 void wxFrameBase::DoMenuUpdates()
347 wxMenuBar
* bar
= GetMenuBar();
350 wxWindow
* focusWin
= wxFindFocusDescendant((wxWindow
*) this);
352 wxWindow
* focusWin
= (wxWindow
*) NULL
;
356 int nCount
= bar
->GetMenuCount();
357 for (int n
= 0; n
< nCount
; n
++)
358 DoMenuUpdates(bar
->GetMenu(n
), focusWin
);
362 // update a menu and all submenus recursively
363 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
, wxWindow
* focusWin
)
365 wxEvtHandler
* evtHandler
= focusWin
? focusWin
->GetEventHandler() : GetEventHandler();
366 wxMenuItemList::Node
* node
= menu
->GetMenuItems().GetFirst();
369 wxMenuItem
* item
= node
->GetData();
370 if ( !item
->IsSeparator() )
372 wxWindowID id
= item
->GetId();
373 wxUpdateUIEvent
event(id
);
374 event
.SetEventObject( this );
376 if (evtHandler
->ProcessEvent(event
))
378 if (event
.GetSetText())
379 menu
->SetLabel(id
, event
.GetText());
380 if (event
.GetSetChecked())
381 menu
->Check(id
, event
.GetChecked());
382 if (event
.GetSetEnabled())
383 menu
->Enable(id
, event
.GetEnabled());
386 if (item
->GetSubMenu())
387 DoMenuUpdates(item
->GetSubMenu(), (wxWindow
*) NULL
);
389 node
= node
->GetNext();
393 void wxFrameBase::DetachMenuBar()
395 if ( m_frameMenuBar
)
397 m_frameMenuBar
->Detach();
398 m_frameMenuBar
= NULL
;
402 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
406 m_frameMenuBar
= menubar
;
407 menubar
->Attach((wxFrame
*)this);
411 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
413 if ( menubar
== GetMenuBar() )
421 AttachMenuBar(menubar
);
424 #endif // wxUSE_MENUS