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
);
185 if ( item
&& item
->IsCheckable() )
190 commandEvent
.SetInt(item
->IsChecked());
193 return GetEventHandler()->ProcessEvent(commandEvent
);
194 #else // !wxUSE_MENUS
196 #endif // wxUSE_MENUS/!wxUSE_MENUS
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 void wxFrameBase::OnMenuHighlight(wxMenuEvent
& event
)
206 (void)ShowMenuHelp(GetStatusBar(), event
.GetMenuId());
207 #endif // wxUSE_STATUSBAR
210 void wxFrameBase::OnIdle(wxIdleEvent
& WXUNUSED(event
) )
214 #endif // wxUSE_MENUS
217 // ----------------------------------------------------------------------------
219 // ----------------------------------------------------------------------------
223 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
,
226 const wxString
& name
)
228 // the main status bar can only be created once (or else it should be
229 // deleted before calling CreateStatusBar() again)
230 wxCHECK_MSG( !m_frameStatusBar
, (wxStatusBar
*)NULL
,
231 wxT("recreating status bar in wxFrame") );
233 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
234 if ( m_frameStatusBar
)
237 return m_frameStatusBar
;
240 wxStatusBar
*wxFrameBase::OnCreateStatusBar(int number
,
243 const wxString
& name
)
245 wxStatusBar
*statusBar
= new wxStatusBar(this, id
, style
, name
);
247 statusBar
->SetFieldsCount(number
);
252 void wxFrameBase::SetStatusText(const wxString
& text
, int number
)
254 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
256 m_frameStatusBar
->SetStatusText(text
, number
);
259 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] )
261 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
263 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
268 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*statbar
, int menuId
)
274 // if no help string found, we will clear the status bar text
277 if ( menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */ )
279 wxMenuBar
*menuBar
= GetMenuBar();
282 // it's ok if we don't find the item because it might belong
284 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
286 helpString
= item
->GetHelp();
290 // set status text even if the string is empty - this will at least
291 // remove the string from the item which was previously selected
292 statbar
->SetStatusText(helpString
);
294 return !helpString
.IsEmpty();
295 #else // !wxUSE_MENUS
297 #endif // wxUSE_MENUS/!wxUSE_MENUS
300 #endif // wxUSE_STATUSBAR
302 // ----------------------------------------------------------------------------
304 // ----------------------------------------------------------------------------
308 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
310 const wxString
& name
)
312 // the main toolbar can't be recreated (unless it was explicitly deeleted
314 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
315 wxT("recreating toolbar in wxFrame") );
317 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
319 return m_frameToolBar
;
322 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
324 const wxString
& name
)
326 return new wxToolBar(this, id
,
327 wxDefaultPosition
, wxDefaultSize
,
331 #endif // wxUSE_TOOLBAR
333 // ----------------------------------------------------------------------------
335 // ----------------------------------------------------------------------------
340 void wxFrameBase::DoMenuUpdates()
342 wxMenuBar
* bar
= GetMenuBar();
345 wxWindow
* focusWin
= wxFindFocusDescendant((wxWindow
*) this);
347 wxWindow
* focusWin
= (wxWindow
*) NULL
;
351 int nCount
= bar
->GetMenuCount();
352 for (int n
= 0; n
< nCount
; n
++)
353 DoMenuUpdates(bar
->GetMenu(n
), focusWin
);
357 // update a menu and all submenus recursively
358 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
, wxWindow
* focusWin
)
360 wxEvtHandler
* evtHandler
= focusWin
? focusWin
->GetEventHandler() : GetEventHandler();
361 wxMenuItemList::Node
* node
= menu
->GetMenuItems().GetFirst();
364 wxMenuItem
* item
= node
->GetData();
365 if ( !item
->IsSeparator() )
367 wxWindowID id
= item
->GetId();
368 wxUpdateUIEvent
event(id
);
369 event
.SetEventObject( this );
371 if (evtHandler
->ProcessEvent(event
))
373 if (event
.GetSetText())
374 menu
->SetLabel(id
, event
.GetText());
375 if (event
.GetSetChecked())
376 menu
->Check(id
, event
.GetChecked());
377 if (event
.GetSetEnabled())
378 menu
->Enable(id
, event
.GetEnabled());
381 if (item
->GetSubMenu())
382 DoMenuUpdates(item
->GetSubMenu(), (wxWindow
*) NULL
);
384 node
= node
->GetNext();
388 void wxFrameBase::DetachMenuBar()
390 if ( m_frameMenuBar
)
392 m_frameMenuBar
->Detach();
393 m_frameMenuBar
= NULL
;
397 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
401 m_frameMenuBar
= menubar
;
402 menubar
->Attach((wxFrame
*)this);
406 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
408 if ( menubar
== GetMenuBar() )
416 AttachMenuBar(menubar
);
419 #endif // wxUSE_MENUS