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