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
83 wxFrameBase::~wxFrameBase()
85 // this destructor is required for Darwin
88 wxFrame
*wxFrameBase::New(wxWindow
*parent
,
90 const wxString
& title
,
96 return new wxFrame(parent
, id
, title
, pos
, size
, style
, name
);
99 void wxFrameBase::DeleteAllBars()
102 if ( m_frameMenuBar
)
104 delete m_frameMenuBar
;
105 m_frameMenuBar
= (wxMenuBar
*) NULL
;
107 #endif // wxUSE_MENUS
110 if ( m_frameStatusBar
)
112 delete m_frameStatusBar
;
113 m_frameStatusBar
= (wxStatusBar
*) NULL
;
115 #endif // wxUSE_STATUSBAR
118 if ( m_frameToolBar
)
120 delete m_frameToolBar
;
121 m_frameToolBar
= (wxToolBar
*) NULL
;
123 #endif // wxUSE_TOOLBAR
126 bool wxFrameBase::IsOneOfBars(const wxWindow
*win
) const
129 if ( win
== GetMenuBar() )
131 #endif // wxUSE_MENUS
134 if ( win
== GetStatusBar() )
136 #endif // wxUSE_STATUSBAR
139 if ( win
== GetToolBar() )
141 #endif // wxUSE_TOOLBAR
146 // ----------------------------------------------------------------------------
147 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
148 // from the client area, so the client area is what's really available for the
150 // ----------------------------------------------------------------------------
152 // get the origin of the client area in the client coordinates
153 wxPoint
wxFrameBase::GetClientAreaOrigin() const
155 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
157 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
158 wxToolBar
*toolbar
= GetToolBar();
159 if ( toolbar
&& toolbar
->IsShown() )
162 toolbar
->GetSize(&w
, &h
);
164 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
173 #endif // wxUSE_TOOLBAR
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 bool wxFrameBase::ProcessCommand(int id
)
185 wxMenuBar
*bar
= GetMenuBar();
189 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
190 commandEvent
.SetEventObject(this);
192 wxMenuItem
*item
= bar
->FindItem(id
);
195 if (!item
->IsEnabled())
198 if (item
->IsCheckable())
203 commandEvent
.SetInt(item
->IsChecked());
207 return GetEventHandler()->ProcessEvent(commandEvent
);
208 #else // !wxUSE_MENUS
210 #endif // wxUSE_MENUS/!wxUSE_MENUS
213 // ----------------------------------------------------------------------------
215 // ----------------------------------------------------------------------------
217 void wxFrameBase::OnMenuHighlight(wxMenuEvent
& event
)
220 (void)ShowMenuHelp(GetStatusBar(), event
.GetMenuId());
221 #endif // wxUSE_STATUSBAR
224 void wxFrameBase::OnIdle(wxIdleEvent
& WXUNUSED(event
) )
228 #endif // wxUSE_MENUS
231 // ----------------------------------------------------------------------------
233 // ----------------------------------------------------------------------------
237 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
,
240 const wxString
& name
)
242 // the main status bar can only be created once (or else it should be
243 // deleted before calling CreateStatusBar() again)
244 wxCHECK_MSG( !m_frameStatusBar
, (wxStatusBar
*)NULL
,
245 wxT("recreating status bar in wxFrame") );
247 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
248 if ( m_frameStatusBar
)
251 return m_frameStatusBar
;
254 wxStatusBar
*wxFrameBase::OnCreateStatusBar(int number
,
257 const wxString
& name
)
259 wxStatusBar
*statusBar
= new wxStatusBar(this, id
, style
, name
);
261 statusBar
->SetFieldsCount(number
);
266 void wxFrameBase::SetStatusText(const wxString
& text
, int number
)
268 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
270 m_frameStatusBar
->SetStatusText(text
, number
);
273 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] )
275 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
277 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
282 void wxFrameBase::PushStatusText(const wxString
& text
, int number
)
284 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
286 m_frameStatusBar
->PushStatusText(text
, number
);
289 void wxFrameBase::PopStatusText(int number
)
291 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
293 m_frameStatusBar
->PopStatusText(number
);
296 void wxFrameBase::DoGiveHelp(const wxString
& text
, bool show
)
299 if ( m_statusBarPane
< 0 ) return;
300 wxStatusBar
* statbar
= GetStatusBar();
301 if ( !statbar
) return;
303 wxString help
= show
? text
: wxString();
304 statbar
->SetStatusText( help
, m_statusBarPane
);
305 #endif // wxUSE_STATUSBAR
308 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*WXUNUSED(statbar
), int menuId
)
311 // if no help string found, we will clear the status bar text
313 bool show
= menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */;
317 wxMenuBar
*menuBar
= GetMenuBar();
320 // it's ok if we don't find the item because it might belong
322 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
324 helpString
= item
->GetHelp();
328 DoGiveHelp(helpString
, show
);
330 return !helpString
.IsEmpty();
331 #else // !wxUSE_MENUS
333 #endif // wxUSE_MENUS/!wxUSE_MENUS
336 #endif // wxUSE_STATUSBAR
338 // ----------------------------------------------------------------------------
340 // ----------------------------------------------------------------------------
344 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
346 const wxString
& name
)
348 // the main toolbar can't be recreated (unless it was explicitly deeleted
350 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
351 wxT("recreating toolbar in wxFrame") );
353 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
355 return m_frameToolBar
;
358 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
360 const wxString
& name
)
362 return new wxToolBar(this, id
,
363 wxDefaultPosition
, wxDefaultSize
,
367 #endif // wxUSE_TOOLBAR
369 // ----------------------------------------------------------------------------
371 // ----------------------------------------------------------------------------
376 void wxFrameBase::DoMenuUpdates()
378 wxMenuBar
* bar
= GetMenuBar();
381 wxWindow
* focusWin
= wxFindFocusDescendant((wxWindow
*) this);
383 wxWindow
* focusWin
= (wxWindow
*) NULL
;
387 int nCount
= bar
->GetMenuCount();
388 for (int n
= 0; n
< nCount
; n
++)
389 DoMenuUpdates(bar
->GetMenu(n
), focusWin
);
393 // update a menu and all submenus recursively
394 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
, wxWindow
* focusWin
)
396 wxEvtHandler
* evtHandler
= focusWin
? focusWin
->GetEventHandler() : GetEventHandler();
397 wxMenuItemList::Node
* node
= menu
->GetMenuItems().GetFirst();
400 wxMenuItem
* item
= node
->GetData();
401 if ( !item
->IsSeparator() )
403 wxWindowID id
= item
->GetId();
404 wxUpdateUIEvent
event(id
);
405 event
.SetEventObject( this );
407 if (evtHandler
->ProcessEvent(event
))
409 if (event
.GetSetText())
410 menu
->SetLabel(id
, event
.GetText());
411 if (event
.GetSetChecked())
412 menu
->Check(id
, event
.GetChecked());
413 if (event
.GetSetEnabled())
414 menu
->Enable(id
, event
.GetEnabled());
417 if (item
->GetSubMenu())
418 DoMenuUpdates(item
->GetSubMenu(), (wxWindow
*) NULL
);
420 node
= node
->GetNext();
424 void wxFrameBase::DetachMenuBar()
426 if ( m_frameMenuBar
)
428 m_frameMenuBar
->Detach();
429 m_frameMenuBar
= NULL
;
433 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
437 menubar
->Attach((wxFrame
*)this);
438 m_frameMenuBar
= menubar
;
442 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
444 if ( menubar
== GetMenuBar() )
452 AttachMenuBar(menubar
);
455 #endif // wxUSE_MENUS