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 void wxFrameBase::DoGiveHelp(const wxString
& text
, bool show
)
295 if ( m_statusBarPane
< 0 ) return;
296 wxStatusBar
* statbar
= GetStatusBar();
297 if ( !statbar
) return;
299 wxString help
= show
? text
: wxString();
300 statbar
->SetStatusText( help
, m_statusBarPane
);
301 #endif // wxUSE_STATUSBAR
304 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*WXUNUSED(statbar
), int menuId
)
307 // if no help string found, we will clear the status bar text
309 bool show
= menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */;
313 wxMenuBar
*menuBar
= GetMenuBar();
316 // it's ok if we don't find the item because it might belong
318 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
320 helpString
= item
->GetHelp();
324 DoGiveHelp(helpString
, show
);
326 return !helpString
.IsEmpty();
327 #else // !wxUSE_MENUS
329 #endif // wxUSE_MENUS/!wxUSE_MENUS
332 #endif // wxUSE_STATUSBAR
334 // ----------------------------------------------------------------------------
336 // ----------------------------------------------------------------------------
340 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
342 const wxString
& name
)
344 // the main toolbar can't be recreated (unless it was explicitly deeleted
346 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
347 wxT("recreating toolbar in wxFrame") );
349 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
351 return m_frameToolBar
;
354 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
356 const wxString
& name
)
358 return new wxToolBar(this, id
,
359 wxDefaultPosition
, wxDefaultSize
,
363 #endif // wxUSE_TOOLBAR
365 // ----------------------------------------------------------------------------
367 // ----------------------------------------------------------------------------
372 void wxFrameBase::DoMenuUpdates()
374 wxMenuBar
* bar
= GetMenuBar();
377 wxWindow
* focusWin
= wxFindFocusDescendant((wxWindow
*) this);
379 wxWindow
* focusWin
= (wxWindow
*) NULL
;
383 int nCount
= bar
->GetMenuCount();
384 for (int n
= 0; n
< nCount
; n
++)
385 DoMenuUpdates(bar
->GetMenu(n
), focusWin
);
389 // update a menu and all submenus recursively
390 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
, wxWindow
* focusWin
)
392 wxEvtHandler
* evtHandler
= focusWin
? focusWin
->GetEventHandler() : GetEventHandler();
393 wxMenuItemList::Node
* node
= menu
->GetMenuItems().GetFirst();
396 wxMenuItem
* item
= node
->GetData();
397 if ( !item
->IsSeparator() )
399 wxWindowID id
= item
->GetId();
400 wxUpdateUIEvent
event(id
);
401 event
.SetEventObject( this );
403 if (evtHandler
->ProcessEvent(event
))
405 if (event
.GetSetText())
406 menu
->SetLabel(id
, event
.GetText());
407 if (event
.GetSetChecked())
408 menu
->Check(id
, event
.GetChecked());
409 if (event
.GetSetEnabled())
410 menu
->Enable(id
, event
.GetEnabled());
413 if (item
->GetSubMenu())
414 DoMenuUpdates(item
->GetSubMenu(), (wxWindow
*) NULL
);
416 node
= node
->GetNext();
420 void wxFrameBase::DetachMenuBar()
422 if ( m_frameMenuBar
)
424 m_frameMenuBar
->Detach();
425 m_frameMenuBar
= NULL
;
429 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
433 menubar
->Attach((wxFrame
*)this);
434 m_frameMenuBar
= menubar
;
438 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
440 if ( menubar
== GetMenuBar() )
448 AttachMenuBar(menubar
);
451 #endif // wxUSE_MENUS