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 and Julian Smart
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 GetEventHandler()->ProcessEvent(commandEvent
);
204 #else // !wxUSE_MENUS
206 #endif // wxUSE_MENUS/!wxUSE_MENUS
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 void wxFrameBase::OnMenuHighlight(wxMenuEvent
& event
)
216 (void)ShowMenuHelp(GetStatusBar(), event
.GetMenuId());
217 #endif // wxUSE_STATUSBAR
220 void wxFrameBase::OnIdle(wxIdleEvent
& WXUNUSED(event
) )
224 #endif // wxUSE_MENUS
227 // ----------------------------------------------------------------------------
229 // ----------------------------------------------------------------------------
233 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
,
236 const wxString
& name
)
238 // the main status bar can only be created once (or else it should be
239 // deleted before calling CreateStatusBar() again)
240 wxCHECK_MSG( !m_frameStatusBar
, (wxStatusBar
*)NULL
,
241 wxT("recreating status bar in wxFrame") );
243 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
244 if ( m_frameStatusBar
)
247 return m_frameStatusBar
;
250 wxStatusBar
*wxFrameBase::OnCreateStatusBar(int number
,
253 const wxString
& name
)
255 wxStatusBar
*statusBar
= new wxStatusBar(this, id
, style
, name
);
257 statusBar
->SetFieldsCount(number
);
262 void wxFrameBase::SetStatusText(const wxString
& text
, int number
)
264 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
266 m_frameStatusBar
->SetStatusText(text
, number
);
269 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] )
271 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
273 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
278 void wxFrameBase::PushStatusText(const wxString
& text
, int number
)
280 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
282 m_frameStatusBar
->PushStatusText(text
, number
);
285 void wxFrameBase::PopStatusText(int number
)
287 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
289 m_frameStatusBar
->PopStatusText(number
);
292 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*WXUNUSED(statbar
), int menuId
)
295 // if no help string found, we will clear the status bar text
297 bool show
= menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */;
301 wxMenuBar
*menuBar
= GetMenuBar();
304 // it's ok if we don't find the item because it might belong
306 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
308 helpString
= item
->GetHelp();
312 DoGiveHelp(helpString
, show
);
314 return !helpString
.IsEmpty();
315 #else // !wxUSE_MENUS
317 #endif // wxUSE_MENUS/!wxUSE_MENUS
320 #endif // wxUSE_STATUSBAR
322 void wxFrameBase::DoGiveHelp(const wxString
& text
, bool show
)
325 if ( m_statusBarPane
< 0 ) return;
326 wxStatusBar
* statbar
= GetStatusBar();
327 if ( !statbar
) return;
329 wxString help
= show
? text
: wxString();
330 statbar
->SetStatusText( help
, m_statusBarPane
);
331 #endif // wxUSE_STATUSBAR
335 // ----------------------------------------------------------------------------
337 // ----------------------------------------------------------------------------
341 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
343 const wxString
& name
)
345 // the main toolbar can't be recreated (unless it was explicitly deeleted
347 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
348 wxT("recreating toolbar in wxFrame") );
350 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
352 return m_frameToolBar
;
355 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
357 const wxString
& name
)
359 return new wxToolBar(this, id
,
360 wxDefaultPosition
, wxDefaultSize
,
364 #endif // wxUSE_TOOLBAR
366 // ----------------------------------------------------------------------------
368 // ----------------------------------------------------------------------------
373 void wxFrameBase::DoMenuUpdates()
375 wxMenuBar
* bar
= GetMenuBar();
378 wxWindow
* focusWin
= wxFindFocusDescendant((wxWindow
*) this);
380 wxWindow
* focusWin
= (wxWindow
*) NULL
;
384 int nCount
= bar
->GetMenuCount();
385 for (int n
= 0; n
< nCount
; n
++)
386 DoMenuUpdates(bar
->GetMenu(n
), focusWin
);
390 // update a menu and all submenus recursively
391 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
, wxWindow
* focusWin
)
393 wxEvtHandler
* evtHandler
= focusWin
? focusWin
->GetEventHandler() : GetEventHandler();
394 wxMenuItemList::Node
* node
= menu
->GetMenuItems().GetFirst();
397 wxMenuItem
* item
= node
->GetData();
398 if ( !item
->IsSeparator() )
400 wxWindowID id
= item
->GetId();
401 wxUpdateUIEvent
event(id
);
402 event
.SetEventObject( this );
404 if (evtHandler
->ProcessEvent(event
))
406 if (event
.GetSetText())
407 menu
->SetLabel(id
, event
.GetText());
408 if (event
.GetSetChecked())
409 menu
->Check(id
, event
.GetChecked());
410 if (event
.GetSetEnabled())
411 menu
->Enable(id
, event
.GetEnabled());
414 if (item
->GetSubMenu())
415 DoMenuUpdates(item
->GetSubMenu(), focusWin
);
417 node
= node
->GetNext();
421 void wxFrameBase::DetachMenuBar()
423 if ( m_frameMenuBar
)
425 m_frameMenuBar
->Detach();
426 m_frameMenuBar
= NULL
;
430 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
434 menubar
->Attach((wxFrame
*)this);
435 m_frameMenuBar
= menubar
;
439 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
441 if ( menubar
== GetMenuBar() )
449 AttachMenuBar(menubar
);
452 #endif // wxUSE_MENUS