]> git.saurik.com Git - wxWidgets.git/blame - src/common/framecmn.cpp
Added wxAbort() which can also be used under Windows CE.
[wxWidgets.git] / src / common / framecmn.cpp
CommitLineData
63fec618 1/////////////////////////////////////////////////////////////////////////////
76b49cf4 2// Name: src/common/framecmn.cpp
63fec618
VZ
3// Purpose: common (for all platforms) wxFrame functions
4// Author: Julian Smart, Vadim Zeitlin
5// Created: 01/02/97
439b3bf1 6// Id: $Id$
55d99c7a 7// Copyright: (c) 1998 Robert Roebling and Julian Smart
65571936 8// Licence: wxWindows licence
63fec618
VZ
9/////////////////////////////////////////////////////////////////////////////
10
7c0ea335
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
f701d7ab
JS
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
7c0ea335 23 #pragma hdrstop
f701d7ab
JS
24#endif
25
76b49cf4
WS
26#include "wx/frame.h"
27
1e6feb95 28#ifndef WX_PRECOMP
1e6feb95
VZ
29 #include "wx/menu.h"
30 #include "wx/menuitem.h"
31 #include "wx/dcclient.h"
4e3e485b 32 #include "wx/toolbar.h"
7c0ea335 33 #include "wx/statusbr.h"
3304646d 34#endif // WX_PRECOMP
7c0ea335 35
f313deaa
PC
36extern WXDLLEXPORT_DATA(const char) wxFrameNameStr[] = "frame";
37extern WXDLLEXPORT_DATA(const char) wxStatusLineNameStr[] = "status_line";
38
7c0ea335
VZ
39// ----------------------------------------------------------------------------
40// event table
41// ----------------------------------------------------------------------------
42
96ac065f
VZ
43#if wxUSE_MENUS && wxUSE_STATUSBAR
44
7d9f12f3 45BEGIN_EVENT_TABLE(wxFrameBase, wxTopLevelWindow)
0b30bb0b 46 EVT_MENU_OPEN(wxFrameBase::OnMenuOpen)
96ac065f
VZ
47 EVT_MENU_CLOSE(wxFrameBase::OnMenuClose)
48
7c0ea335 49 EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight)
7c0ea335
VZ
50END_EVENT_TABLE()
51
96ac065f
VZ
52#endif // wxUSE_MENUS && wxUSE_STATUSBAR
53
7c0ea335
VZ
54// ============================================================================
55// implementation
56// ============================================================================
57
28953245
SC
58// ----------------------------------------------------------------------------
59// XTI
60// ----------------------------------------------------------------------------
61
62wxDEFINE_FLAGS( wxFrameStyle )
63wxBEGIN_FLAGS( wxFrameStyle )
64// new style border flags, we put them first to
65// use them for streaming out
66wxFLAGS_MEMBER(wxBORDER_SIMPLE)
67wxFLAGS_MEMBER(wxBORDER_SUNKEN)
68wxFLAGS_MEMBER(wxBORDER_DOUBLE)
69wxFLAGS_MEMBER(wxBORDER_RAISED)
70wxFLAGS_MEMBER(wxBORDER_STATIC)
71wxFLAGS_MEMBER(wxBORDER_NONE)
72
73// old style border flags
74wxFLAGS_MEMBER(wxSIMPLE_BORDER)
75wxFLAGS_MEMBER(wxSUNKEN_BORDER)
76wxFLAGS_MEMBER(wxDOUBLE_BORDER)
77wxFLAGS_MEMBER(wxRAISED_BORDER)
78wxFLAGS_MEMBER(wxSTATIC_BORDER)
79wxFLAGS_MEMBER(wxBORDER)
80
81// standard window styles
82wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
83wxFLAGS_MEMBER(wxCLIP_CHILDREN)
84wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
85wxFLAGS_MEMBER(wxWANTS_CHARS)
86wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
87wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
88wxFLAGS_MEMBER(wxVSCROLL)
89wxFLAGS_MEMBER(wxHSCROLL)
90
91// frame styles
92wxFLAGS_MEMBER(wxSTAY_ON_TOP)
93wxFLAGS_MEMBER(wxCAPTION)
94#if WXWIN_COMPATIBILITY_2_6
95wxFLAGS_MEMBER(wxTHICK_FRAME)
96#endif // WXWIN_COMPATIBILITY_2_6
97wxFLAGS_MEMBER(wxSYSTEM_MENU)
98wxFLAGS_MEMBER(wxRESIZE_BORDER)
99#if WXWIN_COMPATIBILITY_2_6
100wxFLAGS_MEMBER(wxRESIZE_BOX)
101#endif // WXWIN_COMPATIBILITY_2_6
102wxFLAGS_MEMBER(wxCLOSE_BOX)
103wxFLAGS_MEMBER(wxMAXIMIZE_BOX)
104wxFLAGS_MEMBER(wxMINIMIZE_BOX)
105
106wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW)
107wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT)
108
109wxFLAGS_MEMBER(wxFRAME_SHAPED)
110wxEND_FLAGS( wxFrameStyle )
111
112wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow, "wx/frame.h")
113
114wxBEGIN_PROPERTIES_TABLE(wxFrame)
115wxEVENT_PROPERTY( Menu, wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent)
116
117wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString(), 0 /*flags*/, \
118 wxT("Helpstring"), wxT("group"))
119wxPROPERTY_FLAGS( WindowStyle, wxFrameStyle, long, SetWindowStyleFlag, \
120 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
121 wxT("Helpstring"), wxT("group")) // style
122wxPROPERTY( MenuBar, wxMenuBar *, SetMenuBar, GetMenuBar, wxEMPTY_PARAMETER_VALUE, \
123 0 /*flags*/, wxT("Helpstring"), wxT("group"))
124wxEND_PROPERTIES_TABLE()
125
126wxEMPTY_HANDLERS_TABLE(wxFrame)
127
128wxCONSTRUCTOR_6( wxFrame, wxWindow*, Parent, wxWindowID, Id, wxString, Title, \
129 wxPoint, Position, wxSize, Size, long, WindowStyle)
130
7c0ea335
VZ
131// ----------------------------------------------------------------------------
132// construction/destruction
133// ----------------------------------------------------------------------------
134
135wxFrameBase::wxFrameBase()
136{
1e6feb95 137#if wxUSE_MENUS
7c0ea335 138 m_frameMenuBar = NULL;
1e6feb95 139#endif // wxUSE_MENUS
7c0ea335
VZ
140
141#if wxUSE_TOOLBAR
142 m_frameToolBar = NULL;
143#endif // wxUSE_TOOLBAR
144
145#if wxUSE_STATUSBAR
146 m_frameStatusBar = NULL;
147#endif // wxUSE_STATUSBAR
1f361cdd
MB
148
149 m_statusBarPane = 0;
7c0ea335
VZ
150}
151
799ea011
GD
152wxFrameBase::~wxFrameBase()
153{
154 // this destructor is required for Darwin
155}
156
7c0ea335
VZ
157wxFrame *wxFrameBase::New(wxWindow *parent,
158 wxWindowID id,
159 const wxString& title,
160 const wxPoint& pos,
161 const wxSize& size,
162 long style,
163 const wxString& name)
164{
165 return new wxFrame(parent, id, title, pos, size, style, name);
166}
167
168void wxFrameBase::DeleteAllBars()
169{
1e6feb95 170#if wxUSE_MENUS
5276b0a5 171 wxDELETE(m_frameMenuBar);
1e6feb95 172#endif // wxUSE_MENUS
7c0ea335
VZ
173
174#if wxUSE_STATUSBAR
5276b0a5 175 wxDELETE(m_frameStatusBar);
7c0ea335
VZ
176#endif // wxUSE_STATUSBAR
177
178#if wxUSE_TOOLBAR
5276b0a5 179 wxDELETE(m_frameToolBar);
7c0ea335
VZ
180#endif // wxUSE_TOOLBAR
181}
182
1e6feb95
VZ
183bool wxFrameBase::IsOneOfBars(const wxWindow *win) const
184{
185#if wxUSE_MENUS
186 if ( win == GetMenuBar() )
d1b20379 187 return true;
1e6feb95
VZ
188#endif // wxUSE_MENUS
189
190#if wxUSE_STATUSBAR
191 if ( win == GetStatusBar() )
d1b20379 192 return true;
1e6feb95
VZ
193#endif // wxUSE_STATUSBAR
194
195#if wxUSE_TOOLBAR
196 if ( win == GetToolBar() )
d1b20379 197 return true;
1e6feb95
VZ
198#endif // wxUSE_TOOLBAR
199
8d22935d
VZ
200 wxUnusedVar(win);
201
d1b20379 202 return false;
1e6feb95
VZ
203}
204
1c4f8f8d
VZ
205// ----------------------------------------------------------------------------
206// wxFrame size management: we exclude the areas taken by menu/status/toolbars
207// from the client area, so the client area is what's really available for the
208// frame contents
209// ----------------------------------------------------------------------------
210
211// get the origin of the client area in the client coordinates
212wxPoint wxFrameBase::GetClientAreaOrigin() const
213{
7d9f12f3 214 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
1c4f8f8d 215
a9928e9d 216#if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
d4597e13
VZ
217 wxToolBar *toolbar = GetToolBar();
218 if ( toolbar && toolbar->IsShown() )
1c4f8f8d
VZ
219 {
220 int w, h;
d4597e13 221 toolbar->GetSize(&w, &h);
1c4f8f8d 222
d4597e13 223 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
1c4f8f8d
VZ
224 {
225 pt.x += w;
226 }
227 else
228 {
229 pt.y += h;
230 }
231 }
232#endif // wxUSE_TOOLBAR
233
234 return pt;
235}
236
7c0ea335
VZ
237// ----------------------------------------------------------------------------
238// misc
239// ----------------------------------------------------------------------------
240
a6ac49b1
VZ
241#if wxUSE_MENUS
242
7c0ea335
VZ
243bool wxFrameBase::ProcessCommand(int id)
244{
245 wxMenuBar *bar = GetMenuBar();
246 if ( !bar )
d1b20379 247 return false;
7c0ea335 248
a6ac49b1
VZ
249 wxMenuItem *item = bar->FindItem(id);
250 if ( !item )
251 return false;
252
253 return ProcessCommand(item);
254}
255
256bool wxFrameBase::ProcessCommand(wxMenuItem *item)
257{
258 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, item->GetId());
3ca6a5f0
BP
259 commandEvent.SetEventObject(this);
260
a6ac49b1
VZ
261 if (!item->IsEnabled())
262 return true;
d4597e13 263
a6ac49b1
VZ
264 if ((item->GetKind() == wxITEM_RADIO) && item->IsChecked() )
265 return true;
26c36d75 266
a6ac49b1
VZ
267 if (item->IsCheckable())
268 {
269 item->Toggle();
0472ece7 270
a6ac49b1
VZ
271 // use the new value
272 commandEvent.SetInt(item->IsChecked());
3ca6a5f0 273 }
e23e368b
VZ
274 else // Uncheckable item.
275 {
276 commandEvent.SetInt(-1);
277 }
7c0ea335 278
e047f594 279 return HandleWindowEvent(commandEvent);
7c0ea335
VZ
280}
281
a6ac49b1
VZ
282#endif // wxUSE_MENUS
283
e39af974
JS
284// Do the UI update processing for this window. This is
285// provided for the application to call if it wants to
286// force a UI update, particularly for the menus and toolbar.
287void wxFrameBase::UpdateWindowUI(long flags)
288{
289 wxWindowBase::UpdateWindowUI(flags);
a62848fd 290
e39af974
JS
291#if wxUSE_TOOLBAR
292 if (GetToolBar())
293 GetToolBar()->UpdateWindowUI(flags);
294#endif
295
296#if wxUSE_MENUS
297 if (GetMenuBar())
298 {
a2289551
VZ
299 // If coming from an idle event, we only want to update the menus if
300 // we're in the wxUSE_IDLEMENUUPDATES configuration, otherwise they
301 // will be update when the menu is opened later
302#if !wxUSE_IDLEMENUUPDATES
303 if ( !(flags & wxUPDATE_UI_FROMIDLE) )
304#endif // wxUSE_IDLEMENUUPDATES
e39af974
JS
305 DoMenuUpdates();
306 }
96ac065f 307#endif // wxUSE_MENUS
e39af974
JS
308}
309
7c0ea335 310// ----------------------------------------------------------------------------
96ac065f 311// event handlers for status bar updates from menus
7c0ea335
VZ
312// ----------------------------------------------------------------------------
313
96ac065f
VZ
314#if wxUSE_MENUS && wxUSE_STATUSBAR
315
7c0ea335
VZ
316void wxFrameBase::OnMenuHighlight(wxMenuEvent& event)
317{
318#if wxUSE_STATUSBAR
722ed5be 319 (void)ShowMenuHelp(event.GetMenuId());
7c0ea335
VZ
320#endif // wxUSE_STATUSBAR
321}
322
96ac065f
VZ
323void wxFrameBase::OnMenuOpen(wxMenuEvent& event)
324{
a2289551
VZ
325#if wxUSE_IDLEMENUUPDATES
326 wxUnusedVar(event);
327#else // !wxUSE_IDLEMENUUPDATES
328 // as we didn't update the menus from idle time, do it now
96ac065f 329 DoMenuUpdates(event.GetMenu());
a2289551 330#endif // wxUSE_IDLEMENUUPDATES/!wxUSE_IDLEMENUUPDATES
96ac065f
VZ
331}
332
333void wxFrameBase::OnMenuClose(wxMenuEvent& WXUNUSED(event))
334{
6d99eb3e 335 DoGiveHelp(wxEmptyString, false);
96ac065f
VZ
336}
337
338#endif // wxUSE_MENUS && wxUSE_STATUSBAR
339
e39af974
JS
340// Implement internal behaviour (menu updating on some platforms)
341void wxFrameBase::OnInternalIdle()
6522713c 342{
e2b6d07d 343 wxTopLevelWindow::OnInternalIdle();
a62848fd 344
0b30bb0b 345#if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES
e39af974 346 if (wxUpdateUIEvent::CanUpdate(this))
0b30bb0b
JS
347 DoMenuUpdates();
348#endif
349}
350
7c0ea335
VZ
351// ----------------------------------------------------------------------------
352// status bar stuff
353// ----------------------------------------------------------------------------
354
355#if wxUSE_STATUSBAR
356
357wxStatusBar* wxFrameBase::CreateStatusBar(int number,
358 long style,
359 wxWindowID id,
360 const wxString& name)
361{
362 // the main status bar can only be created once (or else it should be
363 // deleted before calling CreateStatusBar() again)
d3b9f782 364 wxCHECK_MSG( !m_frameStatusBar, NULL,
7c0ea335
VZ
365 wxT("recreating status bar in wxFrame") );
366
a4f01f05 367 SetStatusBar(OnCreateStatusBar(number, style, id, name));
7c0ea335
VZ
368
369 return m_frameStatusBar;
370}
371
372wxStatusBar *wxFrameBase::OnCreateStatusBar(int number,
373 long style,
374 wxWindowID id,
375 const wxString& name)
376{
ed791986 377 wxStatusBar *statusBar = new wxStatusBar(this, id, style, name);
7c0ea335 378
7c0ea335
VZ
379 statusBar->SetFieldsCount(number);
380
381 return statusBar;
382}
383
384void wxFrameBase::SetStatusText(const wxString& text, int number)
385{
7c0ea335
VZ
386 wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
387
388 m_frameStatusBar->SetStatusText(text, number);
389}
390
391void wxFrameBase::SetStatusWidths(int n, const int widths_field[] )
392{
7c0ea335
VZ
393 wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") );
394
395 m_frameStatusBar->SetStatusWidths(n, widths_field);
396
397 PositionStatusBar();
398}
399
1f361cdd 400void wxFrameBase::PushStatusText(const wxString& text, int number)
f6bcfd97 401{
1f361cdd
MB
402 wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
403
404 m_frameStatusBar->PushStatusText(text, number);
405}
f6bcfd97 406
1f361cdd
MB
407void wxFrameBase::PopStatusText(int number)
408{
409 wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
410
411 m_frameStatusBar->PopStatusText(number);
412}
413
722ed5be 414bool wxFrameBase::ShowMenuHelp(int menuId)
1f361cdd
MB
415{
416#if wxUSE_MENUS
f6bcfd97 417 // if no help string found, we will clear the status bar text
29c7962a
VZ
418 //
419 // NB: wxID_NONE is used for (sub)menus themselves by wxMSW
f6bcfd97 420 wxString helpString;
29c7962a 421 if ( menuId != wxID_SEPARATOR && menuId != wxID_NONE )
f6bcfd97 422 {
10816efb 423 const wxMenuItem * const item = FindItemInMenuBar(menuId);
fa7134b0 424 if ( item && !item->IsSeparator() )
10816efb
VZ
425 helpString = item->GetHelp();
426
427 // notice that it's ok if we don't find the item because it might
428 // belong to the popup menu, so don't assert here
f6bcfd97
BP
429 }
430
6d99eb3e 431 DoGiveHelp(helpString, true);
f6bcfd97 432
1729813a 433 return !helpString.empty();
3379ed37 434#else // !wxUSE_MENUS
d1b20379 435 return false;
3379ed37 436#endif // wxUSE_MENUS/!wxUSE_MENUS
f6bcfd97
BP
437}
438
a4f01f05
VZ
439void wxFrameBase::SetStatusBar(wxStatusBar *statBar)
440{
441 bool hadBar = m_frameStatusBar != NULL;
442 m_frameStatusBar = statBar;
443
444 if ( (m_frameStatusBar != NULL) != hadBar )
445 {
446 PositionStatusBar();
447
448 DoLayout();
449 }
450}
451
7c0ea335
VZ
452#endif // wxUSE_STATUSBAR
453
f257ac87 454#if wxUSE_MENUS || wxUSE_TOOLBAR
6d99eb3e 455void wxFrameBase::DoGiveHelp(const wxString& help, bool show)
c60a36d5
VZ
456{
457#if wxUSE_STATUSBAR
96ac065f
VZ
458 if ( m_statusBarPane < 0 )
459 {
460 // status bar messages disabled
461 return;
462 }
463
464 wxStatusBar *statbar = GetStatusBar();
465 if ( !statbar )
466 return;
467
6d99eb3e
VZ
468 wxString text;
469 if ( show )
4cbc928a 470 {
6d99eb3e
VZ
471 // remember the old status bar text if this is the first time we're
472 // called since the menu has been opened as we're going to overwrite it
473 // in our DoGiveHelp() and we want to restore it when the menu is
474 // closed
475 //
476 // note that it would be logical to do this in OnMenuOpen() but under
477 // MSW we get an EVT_MENU_HIGHLIGHT before EVT_MENU_OPEN, strangely
478 // enough, and so this doesn't work and instead we use the ugly trick
479 // with using special m_oldStatusText value as "menu opened" (but it is
480 // arguably better than adding yet another member variable to wxFrame
481 // on all platforms)
96ac065f
VZ
482 if ( m_oldStatusText.empty() )
483 {
6d99eb3e
VZ
484 m_oldStatusText = statbar->GetStatusText(m_statusBarPane);
485 if ( m_oldStatusText.empty() )
486 {
487 // use special value to prevent us from doing this the next time
9a83f860 488 m_oldStatusText += wxT('\0');
6d99eb3e 489 }
96ac065f 490 }
6d99eb3e 491
f0f03f32 492 m_lastHelpShown =
6d99eb3e
VZ
493 text = help;
494 }
495 else // hide help, restore the original text
496 {
f0f03f32
VZ
497 // clear the last shown help string but remember its value
498 wxString lastHelpShown;
499 lastHelpShown.swap(m_lastHelpShown);
500
501 // also clear the old status text but remember it too to restore it
502 // below
503 text.swap(m_oldStatusText);
504
505 if ( statbar->GetStatusText(m_statusBarPane) != lastHelpShown )
506 {
507 // if the text was changed with an explicit SetStatusText() call
508 // from the user code in the meanwhile, do not overwrite it with
509 // the old status bar contents -- this is almost certainly not what
510 // the user expects and would be very hard to avoid from user code
511 return;
512 }
96ac065f 513 }
c60a36d5 514
6d99eb3e 515 statbar->SetStatusText(text, m_statusBarPane);
f428e6c5 516#else
3b257996 517 wxUnusedVar(help);
f428e6c5 518 wxUnusedVar(show);
c60a36d5
VZ
519#endif // wxUSE_STATUSBAR
520}
f257ac87 521#endif // wxUSE_MENUS || wxUSE_TOOLBAR
c60a36d5
VZ
522
523
7c0ea335
VZ
524// ----------------------------------------------------------------------------
525// toolbar stuff
526// ----------------------------------------------------------------------------
527
528#if wxUSE_TOOLBAR
529
530wxToolBar* wxFrameBase::CreateToolBar(long style,
531 wxWindowID id,
532 const wxString& name)
533{
6a17b868 534 // the main toolbar can't be recreated (unless it was explicitly deleted
7c0ea335 535 // before)
d3b9f782 536 wxCHECK_MSG( !m_frameToolBar, NULL,
7c0ea335
VZ
537 wxT("recreating toolbar in wxFrame") );
538
f9dae779
VZ
539 if ( style == -1 )
540 {
541 // use default style
542 //
543 // NB: we don't specify the default value in the method declaration
544 // because
545 // a) this allows us to have different defaults for different
546 // platforms (even if we don't have them right now)
547 // b) we don't need to include wx/toolbar.h in the header then
548 style = wxBORDER_NONE | wxTB_HORIZONTAL | wxTB_FLAT;
549 }
550
a4f01f05 551 SetToolBar(OnCreateToolBar(style, id, name));
7c0ea335
VZ
552
553 return m_frameToolBar;
554}
555
556wxToolBar* wxFrameBase::OnCreateToolBar(long style,
557 wxWindowID id,
558 const wxString& name)
559{
a9102b36
JS
560#if defined(__WXWINCE__) && defined(__POCKETPC__)
561 return new wxToolMenuBar(this, id,
562 wxDefaultPosition, wxDefaultSize,
563 style, name);
564#else
7c0ea335
VZ
565 return new wxToolBar(this, id,
566 wxDefaultPosition, wxDefaultSize,
567 style, name);
a9102b36 568#endif
7c0ea335
VZ
569}
570
a4f01f05
VZ
571void wxFrameBase::SetToolBar(wxToolBar *toolbar)
572{
62f6be44 573 if ( (toolbar != NULL) != (m_frameToolBar != NULL) )
a4f01f05 574 {
62f6be44
VZ
575 // the toolbar visibility must have changed so we need to both position
576 // the toolbar itself (if it appeared) and to relayout the frame
577 // contents in any case
578
579 if ( toolbar )
580 {
581 // we need to assign it to m_frameToolBar for PositionToolBar() to
582 // do anything
583 m_frameToolBar = toolbar;
584 PositionToolBar();
585 }
586 //else: tricky: do not reset m_frameToolBar yet as otherwise DoLayout()
587 // wouldn't recognize the (still existing) toolbar as one of our
588 // bars and wouldn't layout the single child of the frame correctly
589
590
591 // and this is even more tricky: we want DoLayout() to recognize the
592 // old toolbar for the purpose of not counting it among our non-bar
593 // children but we don't want to reserve any more space for it so we
594 // temporarily hide it
595 if ( m_frameToolBar )
596 m_frameToolBar->Hide();
a4f01f05
VZ
597
598 DoLayout();
62f6be44
VZ
599
600 if ( m_frameToolBar )
601 m_frameToolBar->Show();
a4f01f05 602 }
62f6be44
VZ
603
604 // this might have been already done above but it's simpler to just always
605 // do it unconditionally instead of testing for whether we already did it
606 m_frameToolBar = toolbar;
a4f01f05
VZ
607}
608
7c0ea335
VZ
609#endif // wxUSE_TOOLBAR
610
611// ----------------------------------------------------------------------------
6522713c 612// menus
7c0ea335
VZ
613// ----------------------------------------------------------------------------
614
1e6feb95
VZ
615#if wxUSE_MENUS
616
63fec618 617// update all menus
92f1a59c 618void wxFrameBase::DoMenuUpdates(wxMenu* menu)
63fec618 619{
92f1a59c 620 if (menu)
4d538595
DS
621 {
622 wxEvtHandler* source = GetEventHandler();
92f1a59c 623 menu->UpdateUI(source);
4d538595
DS
624 }
625 else
54517652 626 {
4d538595
DS
627 wxMenuBar* bar = GetMenuBar();
628 if (bar != NULL)
629 bar->UpdateMenus();
63fec618 630 }
63fec618 631}
1e6feb95 632
6522713c
VZ
633void wxFrameBase::DetachMenuBar()
634{
635 if ( m_frameMenuBar )
636 {
637 m_frameMenuBar->Detach();
638 m_frameMenuBar = NULL;
639 }
640}
641
642void wxFrameBase::AttachMenuBar(wxMenuBar *menubar)
643{
644 if ( menubar )
645 {
6522713c 646 menubar->Attach((wxFrame *)this);
3dbe38c3 647 m_frameMenuBar = menubar;
6522713c
VZ
648 }
649}
650
651void wxFrameBase::SetMenuBar(wxMenuBar *menubar)
652{
653 if ( menubar == GetMenuBar() )
654 {
655 // nothing to do
656 return;
657 }
658
659 DetachMenuBar();
660
a96b4743 661 this->AttachMenuBar(menubar);
6522713c
VZ
662}
663
79f9ea05 664wxMenuItem *wxFrameBase::FindItemInMenuBar(int menuId) const
10816efb
VZ
665{
666 const wxMenuBar * const menuBar = GetMenuBar();
667
668 return menuBar ? menuBar->FindItem(menuId) : NULL;
669}
670
1e6feb95 671#endif // wxUSE_MENUS