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 wxFrameBase::~wxFrameBase()
83 // this destructor is required for Darwin
86 wxFrame
*wxFrameBase::New(wxWindow
*parent
,
88 const wxString
& title
,
94 return new wxFrame(parent
, id
, title
, pos
, size
, style
, name
);
97 void wxFrameBase::DeleteAllBars()
100 if ( m_frameMenuBar
)
102 delete m_frameMenuBar
;
103 m_frameMenuBar
= (wxMenuBar
*) NULL
;
105 #endif // wxUSE_MENUS
108 if ( m_frameStatusBar
)
110 delete m_frameStatusBar
;
111 m_frameStatusBar
= (wxStatusBar
*) NULL
;
113 #endif // wxUSE_STATUSBAR
116 if ( m_frameToolBar
)
118 delete m_frameToolBar
;
119 m_frameToolBar
= (wxToolBar
*) NULL
;
121 #endif // wxUSE_TOOLBAR
124 bool wxFrameBase::IsOneOfBars(const wxWindow
*win
) const
127 if ( win
== GetMenuBar() )
129 #endif // wxUSE_MENUS
132 if ( win
== GetStatusBar() )
134 #endif // wxUSE_STATUSBAR
137 if ( win
== GetToolBar() )
139 #endif // wxUSE_TOOLBAR
144 // ----------------------------------------------------------------------------
145 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
146 // from the client area, so the client area is what's really available for the
148 // ----------------------------------------------------------------------------
150 // get the origin of the client area in the client coordinates
151 wxPoint
wxFrameBase::GetClientAreaOrigin() const
153 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
156 wxToolBar
*toolbar
= GetToolBar();
157 if ( toolbar
&& toolbar
->IsShown() )
160 toolbar
->GetSize(&w
, &h
);
162 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
171 #endif // wxUSE_TOOLBAR
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 bool wxFrameBase::ProcessCommand(int id
)
183 wxMenuBar
*bar
= GetMenuBar();
187 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
188 commandEvent
.SetEventObject(this);
190 wxMenuItem
*item
= bar
->FindItem(id
);
193 if (!item
->IsEnabled())
196 if (item
->IsCheckable())
200 commandEvent
.SetInt(item
->IsChecked());
204 return GetEventHandler()->ProcessEvent(commandEvent
);
205 #else // !wxUSE_MENUS
207 #endif // wxUSE_MENUS/!wxUSE_MENUS
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 void wxFrameBase::OnMenuHighlight(wxMenuEvent
& event
)
217 (void)ShowMenuHelp(GetStatusBar(), event
.GetMenuId());
218 #endif // wxUSE_STATUSBAR
221 void wxFrameBase::OnIdle(wxIdleEvent
& WXUNUSED(event
) )
225 #endif // wxUSE_MENUS
228 // ----------------------------------------------------------------------------
230 // ----------------------------------------------------------------------------
234 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
,
237 const wxString
& name
)
239 // the main status bar can only be created once (or else it should be
240 // deleted before calling CreateStatusBar() again)
241 wxCHECK_MSG( !m_frameStatusBar
, (wxStatusBar
*)NULL
,
242 wxT("recreating status bar in wxFrame") );
244 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
245 if ( m_frameStatusBar
)
248 return m_frameStatusBar
;
251 wxStatusBar
*wxFrameBase::OnCreateStatusBar(int number
,
254 const wxString
& name
)
256 wxStatusBar
*statusBar
= new wxStatusBar(this, id
, style
, name
);
258 statusBar
->SetFieldsCount(number
);
263 void wxFrameBase::SetStatusText(const wxString
& text
, int number
)
265 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
267 m_frameStatusBar
->SetStatusText(text
, number
);
270 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] )
272 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
274 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
279 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*statbar
, int menuId
)
285 // if no help string found, we will clear the status bar text
288 if ( menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */ )
290 wxMenuBar
*menuBar
= GetMenuBar();
293 // it's ok if we don't find the item because it might belong
295 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
297 helpString
= item
->GetHelp();
301 // set status text even if the string is empty - this will at least
302 // remove the string from the item which was previously selected
303 statbar
->SetStatusText(helpString
);
305 return !helpString
.IsEmpty();
306 #else // !wxUSE_MENUS
308 #endif // wxUSE_MENUS/!wxUSE_MENUS
311 #endif // wxUSE_STATUSBAR
313 // ----------------------------------------------------------------------------
315 // ----------------------------------------------------------------------------
319 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
321 const wxString
& name
)
323 // the main toolbar can't be recreated (unless it was explicitly deeleted
325 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
326 wxT("recreating toolbar in wxFrame") );
328 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
330 return m_frameToolBar
;
333 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
335 const wxString
& name
)
337 return new wxToolBar(this, id
,
338 wxDefaultPosition
, wxDefaultSize
,
342 #endif // wxUSE_TOOLBAR
344 // ----------------------------------------------------------------------------
346 // ----------------------------------------------------------------------------
351 void wxFrameBase::DoMenuUpdates()
353 wxMenuBar
* bar
= GetMenuBar();
356 wxWindow
* focusWin
= wxFindFocusDescendant((wxWindow
*) this);
358 wxWindow
* focusWin
= (wxWindow
*) NULL
;
362 int nCount
= bar
->GetMenuCount();
363 for (int n
= 0; n
< nCount
; n
++)
364 DoMenuUpdates(bar
->GetMenu(n
), focusWin
);
368 // update a menu and all submenus recursively
369 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
, wxWindow
* focusWin
)
371 wxEvtHandler
* evtHandler
= focusWin
? focusWin
->GetEventHandler() : GetEventHandler();
372 wxMenuItemList::Node
* node
= menu
->GetMenuItems().GetFirst();
375 wxMenuItem
* item
= node
->GetData();
376 if ( !item
->IsSeparator() )
378 wxWindowID id
= item
->GetId();
379 wxUpdateUIEvent
event(id
);
380 event
.SetEventObject( this );
382 if (evtHandler
->ProcessEvent(event
))
384 if (event
.GetSetText())
385 menu
->SetLabel(id
, event
.GetText());
386 if (event
.GetSetChecked())
387 menu
->Check(id
, event
.GetChecked());
388 if (event
.GetSetEnabled())
389 menu
->Enable(id
, event
.GetEnabled());
392 if (item
->GetSubMenu())
393 DoMenuUpdates(item
->GetSubMenu(), (wxWindow
*) NULL
);
395 node
= node
->GetNext();
399 void wxFrameBase::DetachMenuBar()
401 if ( m_frameMenuBar
)
403 m_frameMenuBar
->Detach();
404 m_frameMenuBar
= NULL
;
408 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
412 m_frameMenuBar
= menubar
;
413 menubar
->Attach((wxFrame
*)this);
417 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
419 if ( menubar
== GetMenuBar() )
427 AttachMenuBar(menubar
);
430 #endif // wxUSE_MENUS