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 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 BEGIN_EVENT_TABLE(wxFrameBase
, wxTopLevelWindow
)
49 EVT_IDLE(wxFrameBase::OnIdle
)
50 EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight
)
53 // ============================================================================
55 // ============================================================================
57 // ----------------------------------------------------------------------------
58 // construction/destruction
59 // ----------------------------------------------------------------------------
61 wxFrameBase::wxFrameBase()
64 m_frameMenuBar
= NULL
;
68 m_frameToolBar
= NULL
;
69 #endif // wxUSE_TOOLBAR
72 m_frameStatusBar
= NULL
;
73 #endif // wxUSE_STATUSBAR
78 wxFrameBase::~wxFrameBase()
80 // this destructor is required for Darwin
83 wxFrame
*wxFrameBase::New(wxWindow
*parent
,
85 const wxString
& title
,
91 return new wxFrame(parent
, id
, title
, pos
, size
, style
, name
);
94 void wxFrameBase::DeleteAllBars()
99 delete m_frameMenuBar
;
100 m_frameMenuBar
= (wxMenuBar
*) NULL
;
102 #endif // wxUSE_MENUS
105 if ( m_frameStatusBar
)
107 delete m_frameStatusBar
;
108 m_frameStatusBar
= (wxStatusBar
*) NULL
;
110 #endif // wxUSE_STATUSBAR
113 if ( m_frameToolBar
)
115 delete m_frameToolBar
;
116 m_frameToolBar
= (wxToolBar
*) NULL
;
118 #endif // wxUSE_TOOLBAR
121 bool wxFrameBase::IsOneOfBars(const wxWindow
*win
) const
124 if ( win
== GetMenuBar() )
126 #endif // wxUSE_MENUS
129 if ( win
== GetStatusBar() )
131 #endif // wxUSE_STATUSBAR
134 if ( win
== GetToolBar() )
136 #endif // wxUSE_TOOLBAR
141 // ----------------------------------------------------------------------------
142 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
143 // from the client area, so the client area is what's really available for the
145 // ----------------------------------------------------------------------------
147 // get the origin of the client area in the client coordinates
148 wxPoint
wxFrameBase::GetClientAreaOrigin() const
150 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
152 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
153 wxToolBar
*toolbar
= GetToolBar();
154 if ( toolbar
&& toolbar
->IsShown() )
157 toolbar
->GetSize(&w
, &h
);
159 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
168 #endif // wxUSE_TOOLBAR
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 bool wxFrameBase::ProcessCommand(int id
)
180 wxMenuBar
*bar
= GetMenuBar();
184 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
185 commandEvent
.SetEventObject(this);
187 wxMenuItem
*item
= bar
->FindItem(id
);
190 if (!item
->IsEnabled())
193 if (item
->IsCheckable())
198 commandEvent
.SetInt(item
->IsChecked());
202 return GetEventHandler()->ProcessEvent(commandEvent
);
203 #else // !wxUSE_MENUS
205 #endif // wxUSE_MENUS/!wxUSE_MENUS
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 void wxFrameBase::OnMenuHighlight(wxMenuEvent
& event
)
215 (void)ShowMenuHelp(GetStatusBar(), event
.GetMenuId());
216 #endif // wxUSE_STATUSBAR
219 void wxFrameBase::OnIdle(wxIdleEvent
& WXUNUSED(event
) )
223 #endif // wxUSE_MENUS
226 // ----------------------------------------------------------------------------
228 // ----------------------------------------------------------------------------
232 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
,
235 const wxString
& name
)
237 // the main status bar can only be created once (or else it should be
238 // deleted before calling CreateStatusBar() again)
239 wxCHECK_MSG( !m_frameStatusBar
, (wxStatusBar
*)NULL
,
240 wxT("recreating status bar in wxFrame") );
242 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
243 if ( m_frameStatusBar
)
246 return m_frameStatusBar
;
249 wxStatusBar
*wxFrameBase::OnCreateStatusBar(int number
,
252 const wxString
& name
)
254 wxStatusBar
*statusBar
= new wxStatusBar(this, id
, style
, name
);
256 statusBar
->SetFieldsCount(number
);
261 void wxFrameBase::SetStatusText(const wxString
& text
, int number
)
263 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
265 m_frameStatusBar
->SetStatusText(text
, number
);
268 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] )
270 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
272 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
277 void wxFrameBase::PushStatusText(const wxString
& text
, int number
)
279 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
281 m_frameStatusBar
->PushStatusText(text
, number
);
284 void wxFrameBase::PopStatusText(int number
)
286 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
288 m_frameStatusBar
->PopStatusText(number
);
291 void wxFrameBase::DoGiveHelp(const wxString
& text
, bool show
)
294 if ( m_statusBarPane
< 0 ) return;
295 wxStatusBar
* statbar
= GetStatusBar();
296 if ( !statbar
) return;
298 wxString help
= show
? text
: wxString();
299 statbar
->SetStatusText( help
, m_statusBarPane
);
300 #endif // wxUSE_STATUSBAR
303 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*WXUNUSED(statbar
), int menuId
)
306 // if no help string found, we will clear the status bar text
308 bool show
= menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */;
312 wxMenuBar
*menuBar
= GetMenuBar();
315 // it's ok if we don't find the item because it might belong
317 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
319 helpString
= item
->GetHelp();
323 DoGiveHelp(helpString
, show
);
325 return !helpString
.IsEmpty();
326 #else // !wxUSE_MENUS
328 #endif // wxUSE_MENUS/!wxUSE_MENUS
331 #endif // wxUSE_STATUSBAR
333 // ----------------------------------------------------------------------------
335 // ----------------------------------------------------------------------------
339 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
341 const wxString
& name
)
343 // the main toolbar can't be recreated (unless it was explicitly deeleted
345 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
346 wxT("recreating toolbar in wxFrame") );
348 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
350 return m_frameToolBar
;
353 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
355 const wxString
& name
)
357 return new wxToolBar(this, id
,
358 wxDefaultPosition
, wxDefaultSize
,
362 #endif // wxUSE_TOOLBAR
364 // ----------------------------------------------------------------------------
366 // ----------------------------------------------------------------------------
371 void wxFrameBase::DoMenuUpdates()
373 wxMenuBar
* bar
= GetMenuBar();
376 wxWindow
* focusWin
= wxFindFocusDescendant((wxWindow
*) this);
378 wxWindow
* focusWin
= (wxWindow
*) NULL
;
382 int nCount
= bar
->GetMenuCount();
383 for (int n
= 0; n
< nCount
; n
++)
384 DoMenuUpdates(bar
->GetMenu(n
), focusWin
);
388 // update a menu and all submenus recursively
389 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
, wxWindow
* focusWin
)
391 wxEvtHandler
* evtHandler
= focusWin
? focusWin
->GetEventHandler() : GetEventHandler();
392 wxMenuItemList::Node
* node
= menu
->GetMenuItems().GetFirst();
395 wxMenuItem
* item
= node
->GetData();
396 if ( !item
->IsSeparator() )
398 wxWindowID id
= item
->GetId();
399 wxUpdateUIEvent
event(id
);
400 event
.SetEventObject( this );
402 if (evtHandler
->ProcessEvent(event
))
404 if (event
.GetSetText())
405 menu
->SetLabel(id
, event
.GetText());
406 if (event
.GetSetChecked())
407 menu
->Check(id
, event
.GetChecked());
408 if (event
.GetSetEnabled())
409 menu
->Enable(id
, event
.GetEnabled());
412 if (item
->GetSubMenu())
413 DoMenuUpdates(item
->GetSubMenu(), (wxWindow
*) NULL
);
415 node
= node
->GetNext();
419 void wxFrameBase::DetachMenuBar()
421 if ( m_frameMenuBar
)
423 m_frameMenuBar
->Detach();
424 m_frameMenuBar
= NULL
;
428 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
432 menubar
->Attach((wxFrame
*)this);
433 m_frameMenuBar
= menubar
;
437 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
439 if ( menubar
== GetMenuBar() )
447 AttachMenuBar(menubar
);
450 #endif // wxUSE_MENUS