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 #if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES
254 if (wxUpdateUIEvent::CanUpdate(this))
259 void wxFrameBase::OnMenuOpen(wxMenuEvent
& event
)
261 #if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES
262 DoMenuUpdates(event
.GetMenu());
266 // ----------------------------------------------------------------------------
268 // ----------------------------------------------------------------------------
272 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
,
275 const wxString
& name
)
277 // the main status bar can only be created once (or else it should be
278 // deleted before calling CreateStatusBar() again)
279 wxCHECK_MSG( !m_frameStatusBar
, (wxStatusBar
*)NULL
,
280 wxT("recreating status bar in wxFrame") );
282 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
283 if ( m_frameStatusBar
)
286 return m_frameStatusBar
;
289 wxStatusBar
*wxFrameBase::OnCreateStatusBar(int number
,
292 const wxString
& name
)
294 wxStatusBar
*statusBar
= new wxStatusBar(this, id
, style
, name
);
296 statusBar
->SetFieldsCount(number
);
301 void wxFrameBase::SetStatusText(const wxString
& text
, int number
)
303 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
305 m_frameStatusBar
->SetStatusText(text
, number
);
308 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] )
310 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
312 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
317 void wxFrameBase::PushStatusText(const wxString
& text
, int number
)
319 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
321 m_frameStatusBar
->PushStatusText(text
, number
);
324 void wxFrameBase::PopStatusText(int number
)
326 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
328 m_frameStatusBar
->PopStatusText(number
);
331 bool wxFrameBase::ShowMenuHelp(wxStatusBar
*WXUNUSED(statbar
), int menuId
)
334 // if no help string found, we will clear the status bar text
336 bool show
= menuId
!= wxID_SEPARATOR
&& menuId
!= -2 /* wxID_TITLE */;
340 wxMenuBar
*menuBar
= GetMenuBar();
343 // it's ok if we don't find the item because it might belong
345 wxMenuItem
*item
= menuBar
->FindItem(menuId
);
347 helpString
= item
->GetHelp();
351 DoGiveHelp(helpString
, show
);
353 return !helpString
.IsEmpty();
354 #else // !wxUSE_MENUS
356 #endif // wxUSE_MENUS/!wxUSE_MENUS
359 #endif // wxUSE_STATUSBAR
361 void wxFrameBase::DoGiveHelp(const wxString
& text
, bool show
)
364 if ( m_statusBarPane
< 0 ) return;
365 wxStatusBar
* statbar
= GetStatusBar();
366 if ( !statbar
) return;
368 wxString help
= show
? text
: wxString();
369 statbar
->SetStatusText( help
, m_statusBarPane
);
370 #endif // wxUSE_STATUSBAR
374 // ----------------------------------------------------------------------------
376 // ----------------------------------------------------------------------------
380 wxToolBar
* wxFrameBase::CreateToolBar(long style
,
382 const wxString
& name
)
384 // the main toolbar can't be recreated (unless it was explicitly deeleted
386 wxCHECK_MSG( !m_frameToolBar
, (wxToolBar
*)NULL
,
387 wxT("recreating toolbar in wxFrame") );
393 // NB: we don't specify the default value in the method declaration
395 // a) this allows us to have different defaults for different
396 // platforms (even if we don't have them right now)
397 // b) we don't need to include wx/toolbar.h in the header then
398 style
= wxBORDER_NONE
| wxTB_HORIZONTAL
| wxTB_FLAT
;
401 m_frameToolBar
= OnCreateToolBar(style
, id
, name
);
403 return m_frameToolBar
;
406 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
,
408 const wxString
& name
)
410 return new wxToolBar(this, id
,
411 wxDefaultPosition
, wxDefaultSize
,
415 #endif // wxUSE_TOOLBAR
417 // ----------------------------------------------------------------------------
419 // ----------------------------------------------------------------------------
424 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
)
426 wxEvtHandler
* source
= GetEventHandler();
427 wxMenuBar
* bar
= GetMenuBar();
430 menu
->UpdateUI(source
);
431 else if ( bar
!= NULL
)
433 int nCount
= bar
->GetMenuCount();
434 for (int n
= 0; n
< nCount
; n
++)
435 bar
->GetMenu(n
)->UpdateUI(source
);
439 void wxFrameBase::DetachMenuBar()
441 if ( m_frameMenuBar
)
443 m_frameMenuBar
->Detach();
444 m_frameMenuBar
= NULL
;
448 void wxFrameBase::AttachMenuBar(wxMenuBar
*menubar
)
452 menubar
->Attach((wxFrame
*)this);
453 m_frameMenuBar
= menubar
;
457 void wxFrameBase::SetMenuBar(wxMenuBar
*menubar
)
459 if ( menubar
== GetMenuBar() )
467 AttachMenuBar(menubar
);
470 #endif // wxUSE_MENUS