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 #if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES
50 EVT_MENU_OPEN(wxFrameBase::OnMenuOpen
)
52 EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight
)
55 // ============================================================================
57 // ============================================================================
59 // ----------------------------------------------------------------------------
60 // construction/destruction
61 // ----------------------------------------------------------------------------
63 wxFrameBase::wxFrameBase()
66 m_frameMenuBar
= NULL
;
70 m_frameToolBar
= NULL
;
71 #endif // wxUSE_TOOLBAR
74 m_frameStatusBar
= NULL
;
75 #endif // wxUSE_STATUSBAR
80 wxFrameBase::~wxFrameBase()
82 // this destructor is required for Darwin
85 wxFrame
*wxFrameBase::New(wxWindow
*parent
,
87 const wxString
& title
,
93 return new wxFrame(parent
, id
, title
, pos
, size
, style
, name
);
96 void wxFrameBase::DeleteAllBars()
101 delete m_frameMenuBar
;
102 m_frameMenuBar
= (wxMenuBar
*) NULL
;
104 #endif // wxUSE_MENUS
107 if ( m_frameStatusBar
)
109 delete m_frameStatusBar
;
110 m_frameStatusBar
= (wxStatusBar
*) NULL
;
112 #endif // wxUSE_STATUSBAR
115 if ( m_frameToolBar
)
117 delete m_frameToolBar
;
118 m_frameToolBar
= (wxToolBar
*) NULL
;
120 #endif // wxUSE_TOOLBAR
123 bool wxFrameBase::IsOneOfBars(const wxWindow
*win
) const
126 if ( win
== GetMenuBar() )
128 #endif // wxUSE_MENUS
131 if ( win
== GetStatusBar() )
133 #endif // wxUSE_STATUSBAR
136 if ( win
== GetToolBar() )
138 #endif // wxUSE_TOOLBAR
143 // ----------------------------------------------------------------------------
144 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
145 // from the client area, so the client area is what's really available for the
147 // ----------------------------------------------------------------------------
149 // get the origin of the client area in the client coordinates
150 wxPoint
wxFrameBase::GetClientAreaOrigin() const
152 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
154 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
155 wxToolBar
*toolbar
= GetToolBar();
156 if ( toolbar
&& toolbar
->IsShown() )
159 toolbar
->GetSize(&w
, &h
);
161 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
170 #endif // wxUSE_TOOLBAR
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
179 bool wxFrameBase::ProcessCommand(int id
)
182 wxMenuBar
*bar
= GetMenuBar();
186 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
187 commandEvent
.SetEventObject(this);
189 wxMenuItem
*item
= bar
->FindItem(id
);
192 if (!item
->IsEnabled())
195 if (item
->IsCheckable())
200 commandEvent
.SetInt(item
->IsChecked());
204 GetEventHandler()->ProcessEvent(commandEvent
);
206 #else // !wxUSE_MENUS
208 #endif // wxUSE_MENUS/!wxUSE_MENUS
211 // Do the UI update processing for this window. This is
212 // provided for the application to call if it wants to
213 // force a UI update, particularly for the menus and toolbar.
214 void wxFrameBase::UpdateWindowUI(long flags
)
216 wxWindowBase::UpdateWindowUI(flags
);
220 GetToolBar()->UpdateWindowUI(flags
);
226 if ((flags
& wxUPDATE_UI_FROMIDLE
) && !wxUSE_IDLEMENUUPDATES
)
228 // If coming from an idle event, we only
229 // want to update the menus if we're
230 // in the wxUSE_IDLEMENUUPDATES configuration:
231 // so if we're not, do nothing
239 // ----------------------------------------------------------------------------
241 // ----------------------------------------------------------------------------
243 void wxFrameBase::OnMenuHighlight(wxMenuEvent
& event
)
246 (void)ShowMenuHelp(GetStatusBar(), event
.GetMenuId());
247 #endif // wxUSE_STATUSBAR
250 // Implement internal behaviour (menu updating on some platforms)
251 void wxFrameBase::OnInternalIdle()
253 wxTopLevelWindow::OnInternalIdle();
255 #if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES
256 if (wxUpdateUIEvent::CanUpdate(this))
261 void wxFrameBase::OnMenuOpen(wxMenuEvent
& event
)
263 #if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES
264 DoMenuUpdates(event
.GetMenu());
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
274 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
,
277 const wxString
& name
)
279 // the main status bar can only be created once (or else it should be
280 // deleted before calling CreateStatusBar() again)
281 wxCHECK_MSG( !m_frameStatusBar
, (wxStatusBar
*)NULL
,
282 wxT("recreating status bar in wxFrame") );
284 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
285 if ( m_frameStatusBar
)
288 return m_frameStatusBar
;
291 wxStatusBar
*wxFrameBase::OnCreateStatusBar(int number
,
294 const wxString
& name
)
296 wxStatusBar
*statusBar
= new wxStatusBar(this, id
, style
, name
);
298 statusBar
->SetFieldsCount(number
);
303 void wxFrameBase::SetStatusText(const wxString
& text
, int number
)
305 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
307 m_frameStatusBar
->SetStatusText(text
, number
);
310 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] )
312 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
314 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
319 void wxFrameBase::PushStatusText(const wxString
& text
, int number
)
321 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
323 m_frameStatusBar
->PushStatusText(text
, number
);
326 void wxFrameBase::PopStatusText(int number
)
328 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
330 m_frameStatusBar
->PopStatusText(number
);
333 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*WXUNUSED(statbar
), int menuId
)
336 // if no help string found, we will clear the status bar text
338 bool show
= menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */;
342 wxMenuBar
*menuBar
= GetMenuBar();
345 // it's ok if we don't find the item because it might belong
347 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
349 helpString
= item
->GetHelp();
353 DoGiveHelp(helpString
, show
);
355 return !helpString
.IsEmpty();
356 #else // !wxUSE_MENUS
358 #endif // wxUSE_MENUS/!wxUSE_MENUS
361 #endif // wxUSE_STATUSBAR
363 void wxFrameBase::DoGiveHelp(const wxString
& text
, bool show
)
366 if ( m_statusBarPane
< 0 ) return;
367 wxStatusBar
* statbar
= GetStatusBar();
368 if ( !statbar
) return;
370 wxString help
= show
? text
: wxString();
371 statbar
->SetStatusText( help
, m_statusBarPane
);
372 #endif // wxUSE_STATUSBAR
376 // ----------------------------------------------------------------------------
378 // ----------------------------------------------------------------------------
382 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
384 const wxString
& name
)
386 // the main toolbar can't be recreated (unless it was explicitly deeleted
388 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
389 wxT("recreating toolbar in wxFrame") );
395 // NB: we don't specify the default value in the method declaration
397 // a) this allows us to have different defaults for different
398 // platforms (even if we don't have them right now)
399 // b) we don't need to include wx/toolbar.h in the header then
400 style
= wxBORDER_NONE
| wxTB_HORIZONTAL
| wxTB_FLAT
;
403 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
405 return m_frameToolBar
;
408 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
410 const wxString
& name
)
412 return new wxToolBar(this, id
,
413 wxDefaultPosition
, wxDefaultSize
,
417 #endif // wxUSE_TOOLBAR
419 // ----------------------------------------------------------------------------
421 // ----------------------------------------------------------------------------
426 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
)
428 wxEvtHandler
* source
= GetEventHandler();
429 wxMenuBar
* bar
= GetMenuBar();
432 menu
->UpdateUI(source
);
433 else if ( bar
!= NULL
)
435 int nCount
= bar
->GetMenuCount();
436 for (int n
= 0; n
< nCount
; n
++)
437 bar
->GetMenu(n
)->UpdateUI(source
);
441 void wxFrameBase::DetachMenuBar()
443 if ( m_frameMenuBar
)
445 m_frameMenuBar
->Detach();
446 m_frameMenuBar
= NULL
;
450 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
454 menubar
->Attach((wxFrame
*)this);
455 m_frameMenuBar
= menubar
;
459 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
461 if ( menubar
== GetMenuBar() )
469 AttachMenuBar(menubar
);
472 #endif // wxUSE_MENUS