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 wxToolBar
*toolbar
= GetToolBar();
152 if ( toolbar
&& toolbar
->IsShown() )
155 toolbar
->GetSize(&w
, &h
);
157 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
166 #endif // wxUSE_TOOLBAR
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 bool wxFrameBase::ProcessCommand(int id
)
178 wxMenuBar
*bar
= GetMenuBar();
182 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
183 commandEvent
.SetEventObject(this);
185 wxMenuItem
*item
= bar
->FindItem(id
);
188 if (!item
->IsEnabled())
191 if (item
->IsCheckable())
195 commandEvent
.SetInt(item
->IsChecked());
199 return GetEventHandler()->ProcessEvent(commandEvent
);
200 #else // !wxUSE_MENUS
202 #endif // wxUSE_MENUS/!wxUSE_MENUS
205 // ----------------------------------------------------------------------------
207 // ----------------------------------------------------------------------------
209 void wxFrameBase::OnMenuHighlight(wxMenuEvent
& event
)
212 (void)ShowMenuHelp(GetStatusBar(), event
.GetMenuId());
213 #endif // wxUSE_STATUSBAR
216 void wxFrameBase::OnIdle(wxIdleEvent
& WXUNUSED(event
) )
220 #endif // wxUSE_MENUS
223 // ----------------------------------------------------------------------------
225 // ----------------------------------------------------------------------------
229 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
,
232 const wxString
& name
)
234 // the main status bar can only be created once (or else it should be
235 // deleted before calling CreateStatusBar() again)
236 wxCHECK_MSG( !m_frameStatusBar
, (wxStatusBar
*)NULL
,
237 wxT("recreating status bar in wxFrame") );
239 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
240 if ( m_frameStatusBar
)
243 return m_frameStatusBar
;
246 wxStatusBar
*wxFrameBase::OnCreateStatusBar(int number
,
249 const wxString
& name
)
251 wxStatusBar
*statusBar
= new wxStatusBar(this, id
, style
, name
);
253 statusBar
->SetFieldsCount(number
);
258 void wxFrameBase::SetStatusText(const wxString
& text
, int number
)
260 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
262 m_frameStatusBar
->SetStatusText(text
, number
);
265 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] )
267 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
269 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
274 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*statbar
, int menuId
)
280 // if no help string found, we will clear the status bar text
283 if ( menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */ )
285 wxMenuBar
*menuBar
= GetMenuBar();
288 // it's ok if we don't find the item because it might belong
290 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
292 helpString
= item
->GetHelp();
296 // set status text even if the string is empty - this will at least
297 // remove the string from the item which was previously selected
298 statbar
->SetStatusText(helpString
);
300 return !helpString
.IsEmpty();
301 #else // !wxUSE_MENUS
303 #endif // wxUSE_MENUS/!wxUSE_MENUS
306 #endif // wxUSE_STATUSBAR
308 // ----------------------------------------------------------------------------
310 // ----------------------------------------------------------------------------
314 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
316 const wxString
& name
)
318 // the main toolbar can't be recreated (unless it was explicitly deeleted
320 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
321 wxT("recreating toolbar in wxFrame") );
323 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
325 return m_frameToolBar
;
328 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
330 const wxString
& name
)
332 return new wxToolBar(this, id
,
333 wxDefaultPosition
, wxDefaultSize
,
337 #endif // wxUSE_TOOLBAR
339 // ----------------------------------------------------------------------------
341 // ----------------------------------------------------------------------------
346 void wxFrameBase::DoMenuUpdates()
348 wxMenuBar
* bar
= GetMenuBar();
351 wxWindow
* focusWin
= wxFindFocusDescendant((wxWindow
*) this);
353 wxWindow
* focusWin
= (wxWindow
*) NULL
;
357 int nCount
= bar
->GetMenuCount();
358 for (int n
= 0; n
< nCount
; n
++)
359 DoMenuUpdates(bar
->GetMenu(n
), focusWin
);
363 // update a menu and all submenus recursively
364 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
, wxWindow
* focusWin
)
366 wxEvtHandler
* evtHandler
= focusWin
? focusWin
->GetEventHandler() : GetEventHandler();
367 wxMenuItemList::Node
* node
= menu
->GetMenuItems().GetFirst();
370 wxMenuItem
* item
= node
->GetData();
371 if ( !item
->IsSeparator() )
373 wxWindowID id
= item
->GetId();
374 wxUpdateUIEvent
event(id
);
375 event
.SetEventObject( this );
377 if (evtHandler
->ProcessEvent(event
))
379 if (event
.GetSetText())
380 menu
->SetLabel(id
, event
.GetText());
381 if (event
.GetSetChecked())
382 menu
->Check(id
, event
.GetChecked());
383 if (event
.GetSetEnabled())
384 menu
->Enable(id
, event
.GetEnabled());
387 if (item
->GetSubMenu())
388 DoMenuUpdates(item
->GetSubMenu(), (wxWindow
*) NULL
);
390 node
= node
->GetNext();
394 void wxFrameBase::DetachMenuBar()
396 if ( m_frameMenuBar
)
398 m_frameMenuBar
->Detach();
399 m_frameMenuBar
= NULL
;
403 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
407 m_frameMenuBar
= menubar
;
408 menubar
->Attach((wxFrame
*)this);
412 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
414 if ( menubar
== GetMenuBar() )
422 AttachMenuBar(menubar
);
425 #endif // wxUSE_MENUS