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