]> git.saurik.com Git - wxWidgets.git/blob - src/common/menucmn.cpp
assert if ShowModal() is called after a previous Show() (#1416)
[wxWidgets.git] / src / common / menucmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/menucmn.cpp
3 // Purpose: wxMenu and wxMenuBar methods common to all ports
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 26.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_MENUS
28
29 #ifndef WX_PRECOMP
30 #include "wx/intl.h"
31 #include "wx/log.h"
32 #include "wx/menu.h"
33 #endif
34
35 #include "wx/stockitem.h"
36
37 // ----------------------------------------------------------------------------
38 // template lists
39 // ----------------------------------------------------------------------------
40
41 #include "wx/listimpl.cpp"
42
43 WX_DEFINE_LIST(wxMenuList)
44 WX_DEFINE_LIST(wxMenuItemList)
45
46 // ============================================================================
47 // implementation
48 // ============================================================================
49
50 // ----------------------------------------------------------------------------
51 // wxMenuItemBase
52 // ----------------------------------------------------------------------------
53
54 wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu,
55 int id,
56 const wxString& text,
57 const wxString& help,
58 wxItemKind kind,
59 wxMenu *subMenu)
60 {
61 wxASSERT_MSG( parentMenu != NULL, wxT("menuitem should have a menu") );
62
63 m_parentMenu = parentMenu;
64 m_subMenu = subMenu;
65 m_isEnabled = true;
66 m_isChecked = false;
67 m_id = id;
68 m_kind = kind;
69 if (m_id == wxID_ANY)
70 m_id = wxWindow::NewControlId();
71 if (m_id == wxID_SEPARATOR)
72 m_kind = wxITEM_SEPARATOR;
73
74 SetItemLabel(text);
75 SetHelp(help);
76 }
77
78 wxMenuItemBase::~wxMenuItemBase()
79 {
80 delete m_subMenu;
81 }
82
83 #if wxUSE_ACCEL
84
85 wxAcceleratorEntry *wxMenuItemBase::GetAccel() const
86 {
87 return wxAcceleratorEntry::Create(GetItemLabel());
88 }
89
90 void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel)
91 {
92 wxString text = m_text.BeforeFirst(wxT('\t'));
93 if ( accel )
94 {
95 text += wxT('\t');
96 text += accel->ToString();
97 }
98
99 SetItemLabel(text);
100 }
101
102 #endif // wxUSE_ACCEL
103
104 void wxMenuItemBase::SetItemLabel(const wxString& str)
105 {
106 m_text = str;
107
108 if ( m_text.empty() && !IsSeparator() )
109 {
110 wxASSERT_MSG( wxIsStockID(GetId()),
111 wxT("A non-stock menu item with an empty label?") );
112 m_text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR |
113 wxSTOCK_WITH_MNEMONIC);
114 }
115 }
116
117 void wxMenuItemBase::SetHelp(const wxString& str)
118 {
119 m_help = str;
120
121 if ( m_help.empty() && !IsSeparator() && wxIsStockID(GetId()) )
122 {
123 // get a stock help string
124 m_help = wxGetStockHelpString(GetId());
125 }
126 }
127
128 #ifndef __WXPM__
129 wxString wxMenuItemBase::GetLabelText(const wxString& text)
130 {
131 return wxStripMenuCodes(text);
132 }
133 #endif
134
135 #if WXWIN_COMPATIBILITY_2_8
136 wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
137 {
138 return GetLabelText(text);
139 }
140 #endif
141
142 bool wxMenuBase::ms_locked = true;
143
144 // ----------------------------------------------------------------------------
145 // wxMenu ctor and dtor
146 // ----------------------------------------------------------------------------
147
148 void wxMenuBase::Init(long style)
149 {
150 m_menuBar = (wxMenuBar *)NULL;
151 m_menuParent = (wxMenu *)NULL;
152
153 m_invokingWindow = (wxWindow *)NULL;
154 m_style = style;
155 m_clientData = (void *)NULL;
156 m_eventHandler = this;
157 }
158
159 wxMenuBase::~wxMenuBase()
160 {
161 WX_CLEAR_LIST(wxMenuItemList, m_items);
162 }
163
164 // ----------------------------------------------------------------------------
165 // wxMenu item adding/removing
166 // ----------------------------------------------------------------------------
167
168 void wxMenuBase::AddSubMenu(wxMenu *submenu)
169 {
170 wxCHECK_RET( submenu, _T("can't add a NULL submenu") );
171
172 submenu->SetParent((wxMenu *)this);
173 }
174
175 wxMenuItem* wxMenuBase::DoAppend(wxMenuItem *item)
176 {
177 wxCHECK_MSG( item, NULL, wxT("invalid item in wxMenu::Append()") );
178
179 m_items.Append(item);
180 item->SetMenu((wxMenu*)this);
181 if ( item->IsSubMenu() )
182 {
183 AddSubMenu(item->GetSubMenu());
184 }
185
186 return item;
187 }
188
189 wxMenuItem* wxMenuBase::Insert(size_t pos, wxMenuItem *item)
190 {
191 wxCHECK_MSG( item, NULL, wxT("invalid item in wxMenu::Insert") );
192
193 if ( pos == GetMenuItemCount() )
194 {
195 return DoAppend(item);
196 }
197 else
198 {
199 wxCHECK_MSG( pos < GetMenuItemCount(), NULL,
200 wxT("invalid index in wxMenu::Insert") );
201
202 return DoInsert(pos, item);
203 }
204 }
205
206 wxMenuItem* wxMenuBase::DoInsert(size_t pos, wxMenuItem *item)
207 {
208 wxCHECK_MSG( item, NULL, wxT("invalid item in wxMenu::Insert()") );
209
210 wxMenuItemList::compatibility_iterator node = m_items.Item(pos);
211 wxCHECK_MSG( node, NULL, wxT("invalid index in wxMenu::Insert()") );
212
213 m_items.Insert(node, item);
214 item->SetMenu((wxMenu*)this);
215 if ( item->IsSubMenu() )
216 {
217 AddSubMenu(item->GetSubMenu());
218 }
219
220 return item;
221 }
222
223 wxMenuItem *wxMenuBase::Remove(wxMenuItem *item)
224 {
225 wxCHECK_MSG( item, NULL, wxT("invalid item in wxMenu::Remove") );
226
227 return DoRemove(item);
228 }
229
230 wxMenuItem *wxMenuBase::DoRemove(wxMenuItem *item)
231 {
232 wxMenuItemList::compatibility_iterator node = m_items.Find(item);
233
234 // if we get here, the item is valid or one of Remove() functions is broken
235 wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") );
236
237 // we detach the item, but we do delete the list node (i.e. don't call
238 // DetachNode() here!)
239 m_items.Erase(node);
240
241 // item isn't attached to anything any more
242 item->SetMenu((wxMenu *)NULL);
243 wxMenu *submenu = item->GetSubMenu();
244 if ( submenu )
245 {
246 submenu->SetParent((wxMenu *)NULL);
247 if ( submenu->IsAttached() )
248 submenu->Detach();
249 }
250
251 return item;
252 }
253
254 bool wxMenuBase::Delete(wxMenuItem *item)
255 {
256 wxCHECK_MSG( item, false, wxT("invalid item in wxMenu::Delete") );
257
258 return DoDelete(item);
259 }
260
261 bool wxMenuBase::DoDelete(wxMenuItem *item)
262 {
263 wxMenuItem *item2 = DoRemove(item);
264 wxCHECK_MSG( item2, false, wxT("failed to delete menu item") );
265
266 // don't delete the submenu
267 item2->SetSubMenu((wxMenu *)NULL);
268
269 delete item2;
270
271 return true;
272 }
273
274 bool wxMenuBase::Destroy(wxMenuItem *item)
275 {
276 wxCHECK_MSG( item, false, wxT("invalid item in wxMenu::Destroy") );
277
278 return DoDestroy(item);
279 }
280
281 bool wxMenuBase::DoDestroy(wxMenuItem *item)
282 {
283 wxMenuItem *item2 = DoRemove(item);
284 wxCHECK_MSG( item2, false, wxT("failed to delete menu item") );
285
286 delete item2;
287
288 return true;
289 }
290
291 // ----------------------------------------------------------------------------
292 // wxMenu searching for items
293 // ----------------------------------------------------------------------------
294
295 // Finds the item id matching the given string, wxNOT_FOUND if not found.
296 int wxMenuBase::FindItem(const wxString& text) const
297 {
298 wxString label = wxMenuItem::GetLabelText(text);
299 for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
300 node;
301 node = node->GetNext() )
302 {
303 wxMenuItem *item = node->GetData();
304 if ( item->IsSubMenu() )
305 {
306 int rc = item->GetSubMenu()->FindItem(label);
307 if ( rc != wxNOT_FOUND )
308 return rc;
309 }
310
311 // we execute this code for submenus as well to alllow finding them by
312 // name just like the ordinary items
313 if ( !item->IsSeparator() )
314 {
315 if ( item->GetItemLabelText() == label )
316 return item->GetId();
317 }
318 }
319
320 return wxNOT_FOUND;
321 }
322
323 // recursive search for item by id
324 wxMenuItem *wxMenuBase::FindItem(int itemId, wxMenu **itemMenu) const
325 {
326 if ( itemMenu )
327 *itemMenu = NULL;
328
329 wxMenuItem *item = NULL;
330 for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
331 node && !item;
332 node = node->GetNext() )
333 {
334 item = node->GetData();
335
336 if ( item->GetId() == itemId )
337 {
338 if ( itemMenu )
339 *itemMenu = (wxMenu *)this;
340 }
341 else if ( item->IsSubMenu() )
342 {
343 item = item->GetSubMenu()->FindItem(itemId, itemMenu);
344 }
345 else
346 {
347 // don't exit the loop
348 item = NULL;
349 }
350 }
351
352 return item;
353 }
354
355 // non recursive search
356 wxMenuItem *wxMenuBase::FindChildItem(int id, size_t *ppos) const
357 {
358 wxMenuItem *item = (wxMenuItem *)NULL;
359 wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
360
361 size_t pos;
362 for ( pos = 0; node; pos++ )
363 {
364 if ( node->GetData()->GetId() == id )
365 {
366 item = node->GetData();
367
368 break;
369 }
370
371 node = node->GetNext();
372 }
373
374 if ( ppos )
375 {
376 *ppos = item ? pos : (size_t)wxNOT_FOUND;
377 }
378
379 return item;
380 }
381
382 // find by position
383 wxMenuItem* wxMenuBase::FindItemByPosition(size_t position) const
384 {
385 wxCHECK_MSG( position < m_items.GetCount(), NULL,
386 _T("wxMenu::FindItemByPosition(): invalid menu index") );
387
388 return m_items.Item( position )->GetData();
389 }
390
391 // ----------------------------------------------------------------------------
392 // wxMenu helpers used by derived classes
393 // ----------------------------------------------------------------------------
394
395 // Update a menu and all submenus recursively. source is the object that has
396 // the update event handlers defined for it. If NULL, the menu or associated
397 // window will be used.
398 void wxMenuBase::UpdateUI(wxEvtHandler* source)
399 {
400 if (GetInvokingWindow())
401 {
402 // Don't update menus if the parent
403 // frame is about to get deleted
404 wxWindow *tlw = wxGetTopLevelParent( GetInvokingWindow() );
405 if (tlw && wxPendingDelete.Member(tlw))
406 return;
407 }
408
409 if ( !source && GetInvokingWindow() )
410 source = GetInvokingWindow()->GetEventHandler();
411 if ( !source )
412 source = GetEventHandler();
413 if ( !source )
414 source = this;
415
416 wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
417 while ( node )
418 {
419 wxMenuItem* item = node->GetData();
420 if ( !item->IsSeparator() )
421 {
422 wxWindowID id = item->GetId();
423 wxUpdateUIEvent event(id);
424 event.SetEventObject( source );
425
426 if ( source->ProcessEvent(event) )
427 {
428 // if anything changed, update the changed attribute
429 if (event.GetSetText())
430 SetLabel(id, event.GetText());
431 if (event.GetSetChecked())
432 Check(id, event.GetChecked());
433 if (event.GetSetEnabled())
434 Enable(id, event.GetEnabled());
435 }
436
437 // recurse to the submenus
438 if ( item->GetSubMenu() )
439 item->GetSubMenu()->UpdateUI(source);
440 }
441 //else: item is a separator (which doesn't process update UI events)
442
443 node = node->GetNext();
444 }
445 }
446
447 bool wxMenuBase::SendEvent(int id, int checked)
448 {
449 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, id);
450 event.SetEventObject(this);
451 event.SetInt(checked);
452
453 bool processed = false;
454
455 // Try the menu's event handler
456 // if ( !processed )
457 {
458 wxEvtHandler *handler = GetEventHandler();
459 if ( handler )
460 processed = handler->SafelyProcessEvent(event);
461 }
462
463 // Try the window the menu was popped up from (and up through the
464 // hierarchy)
465 if ( !processed )
466 {
467 const wxMenuBase *menu = this;
468 while ( menu )
469 {
470 wxWindow *win = menu->GetInvokingWindow();
471 if ( win )
472 {
473 processed = win->HandleWindowEvent(event);
474 break;
475 }
476
477 menu = menu->GetParent();
478 }
479 }
480
481 return processed;
482 }
483
484 // ----------------------------------------------------------------------------
485 // wxMenu attaching/detaching to/from menu bar
486 // ----------------------------------------------------------------------------
487
488 wxMenuBar* wxMenuBase::GetMenuBar() const
489 {
490 if(GetParent())
491 return GetParent()->GetMenuBar();
492 return m_menuBar;
493 }
494
495 void wxMenuBase::Attach(wxMenuBarBase *menubar)
496 {
497 // use Detach() instead!
498 wxASSERT_MSG( menubar, _T("menu can't be attached to NULL menubar") );
499
500 // use IsAttached() to prevent this from happening
501 wxASSERT_MSG( !m_menuBar, _T("attaching menu twice?") );
502
503 m_menuBar = (wxMenuBar *)menubar;
504 }
505
506 void wxMenuBase::Detach()
507 {
508 // use IsAttached() to prevent this from happening
509 wxASSERT_MSG( m_menuBar, _T("detaching unattached menu?") );
510
511 m_menuBar = NULL;
512 }
513
514 // ----------------------------------------------------------------------------
515 // wxMenu functions forwarded to wxMenuItem
516 // ----------------------------------------------------------------------------
517
518 void wxMenuBase::Enable( int id, bool enable )
519 {
520 wxMenuItem *item = FindItem(id);
521
522 wxCHECK_RET( item, wxT("wxMenu::Enable: no such item") );
523
524 item->Enable(enable);
525 }
526
527 bool wxMenuBase::IsEnabled( int id ) const
528 {
529 wxMenuItem *item = FindItem(id);
530
531 wxCHECK_MSG( item, false, wxT("wxMenu::IsEnabled: no such item") );
532
533 return item->IsEnabled();
534 }
535
536 void wxMenuBase::Check( int id, bool enable )
537 {
538 wxMenuItem *item = FindItem(id);
539
540 wxCHECK_RET( item, wxT("wxMenu::Check: no such item") );
541
542 item->Check(enable);
543 }
544
545 bool wxMenuBase::IsChecked( int id ) const
546 {
547 wxMenuItem *item = FindItem(id);
548
549 wxCHECK_MSG( item, false, wxT("wxMenu::IsChecked: no such item") );
550
551 return item->IsChecked();
552 }
553
554 void wxMenuBase::SetLabel( int id, const wxString &label )
555 {
556 wxMenuItem *item = FindItem(id);
557
558 wxCHECK_RET( item, wxT("wxMenu::SetLabel: no such item") );
559
560 item->SetItemLabel(label);
561 }
562
563 wxString wxMenuBase::GetLabel( int id ) const
564 {
565 wxMenuItem *item = FindItem(id);
566
567 wxCHECK_MSG( item, wxEmptyString, wxT("wxMenu::GetLabel: no such item") );
568
569 return item->GetItemLabel();
570 }
571
572 void wxMenuBase::SetHelpString( int id, const wxString& helpString )
573 {
574 wxMenuItem *item = FindItem(id);
575
576 wxCHECK_RET( item, wxT("wxMenu::SetHelpString: no such item") );
577
578 item->SetHelp( helpString );
579 }
580
581 wxString wxMenuBase::GetHelpString( int id ) const
582 {
583 wxMenuItem *item = FindItem(id);
584
585 wxCHECK_MSG( item, wxEmptyString, wxT("wxMenu::GetHelpString: no such item") );
586
587 return item->GetHelp();
588 }
589
590 // ----------------------------------------------------------------------------
591 // wxMenuBarBase ctor and dtor
592 // ----------------------------------------------------------------------------
593
594 wxMenuBarBase::wxMenuBarBase()
595 {
596 // not attached yet
597 m_menuBarFrame = NULL;
598 }
599
600 wxMenuBarBase::~wxMenuBarBase()
601 {
602 WX_CLEAR_LIST(wxMenuList, m_menus);
603 }
604
605 // ----------------------------------------------------------------------------
606 // wxMenuBar item access: the base class versions manage m_menus list, the
607 // derived class should reflect the changes in the real menubar
608 // ----------------------------------------------------------------------------
609
610 wxMenu *wxMenuBarBase::GetMenu(size_t pos) const
611 {
612 wxMenuList::compatibility_iterator node = m_menus.Item(pos);
613 wxCHECK_MSG( node, NULL, wxT("bad index in wxMenuBar::GetMenu()") );
614
615 return node->GetData();
616 }
617
618 bool wxMenuBarBase::Append(wxMenu *menu, const wxString& WXUNUSED(title))
619 {
620 wxCHECK_MSG( menu, false, wxT("can't append NULL menu") );
621
622 m_menus.Append(menu);
623 menu->Attach(this);
624
625 return true;
626 }
627
628 bool wxMenuBarBase::Insert(size_t pos, wxMenu *menu,
629 const wxString& title)
630 {
631 if ( pos == m_menus.GetCount() )
632 {
633 return wxMenuBarBase::Append(menu, title);
634 }
635 else // not at the end
636 {
637 wxCHECK_MSG( menu, false, wxT("can't insert NULL menu") );
638
639 wxMenuList::compatibility_iterator node = m_menus.Item(pos);
640 wxCHECK_MSG( node, false, wxT("bad index in wxMenuBar::Insert()") );
641
642 m_menus.Insert(node, menu);
643 menu->Attach(this);
644
645 return true;
646 }
647 }
648
649 wxMenu *wxMenuBarBase::Replace(size_t pos, wxMenu *menu,
650 const wxString& WXUNUSED(title))
651 {
652 wxCHECK_MSG( menu, NULL, wxT("can't insert NULL menu") );
653
654 wxMenuList::compatibility_iterator node = m_menus.Item(pos);
655 wxCHECK_MSG( node, NULL, wxT("bad index in wxMenuBar::Replace()") );
656
657 wxMenu *menuOld = node->GetData();
658 node->SetData(menu);
659
660 menu->Attach(this);
661 menuOld->Detach();
662
663 return menuOld;
664 }
665
666 wxMenu *wxMenuBarBase::Remove(size_t pos)
667 {
668 wxMenuList::compatibility_iterator node = m_menus.Item(pos);
669 wxCHECK_MSG( node, NULL, wxT("bad index in wxMenuBar::Remove()") );
670
671 wxMenu *menu = node->GetData();
672 m_menus.Erase(node);
673 menu->Detach();
674
675 return menu;
676 }
677
678 int wxMenuBarBase::FindMenu(const wxString& title) const
679 {
680 wxString label = wxMenuItem::GetLabelText(title);
681
682 size_t count = GetMenuCount();
683 for ( size_t i = 0; i < count; i++ )
684 {
685 wxString title2 = GetMenuLabel(i);
686 if ( (title2 == title) ||
687 (wxMenuItem::GetLabelText(title2) == label) )
688 {
689 // found
690 return (int)i;
691 }
692 }
693
694 return wxNOT_FOUND;
695
696 }
697
698 // ----------------------------------------------------------------------------
699 // wxMenuBar attaching/detaching to/from the frame
700 // ----------------------------------------------------------------------------
701
702 void wxMenuBarBase::Attach(wxFrame *frame)
703 {
704 wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") );
705
706 m_menuBarFrame = frame;
707 }
708
709 void wxMenuBarBase::Detach()
710 {
711 wxASSERT_MSG( IsAttached(), wxT("detaching unattached menubar") );
712
713 m_menuBarFrame = NULL;
714 }
715
716 // ----------------------------------------------------------------------------
717 // wxMenuBar searching for items
718 // ----------------------------------------------------------------------------
719
720 wxMenuItem *wxMenuBarBase::FindItem(int id, wxMenu **menu) const
721 {
722 if ( menu )
723 *menu = NULL;
724
725 wxMenuItem *item = NULL;
726 size_t count = GetMenuCount(), i;
727 wxMenuList::const_iterator it;
728 for ( i = 0, it = m_menus.begin(); !item && (i < count); i++, it++ )
729 {
730 item = (*it)->FindItem(id, menu);
731 }
732
733 return item;
734 }
735
736 int wxMenuBarBase::FindMenuItem(const wxString& menu, const wxString& item) const
737 {
738 wxString label = wxMenuItem::GetLabelText(menu);
739
740 int i = 0;
741 wxMenuList::compatibility_iterator node;
742 for ( node = m_menus.GetFirst(); node; node = node->GetNext(), i++ )
743 {
744 if ( label == wxMenuItem::GetLabelText(GetMenuLabel(i)) )
745 return node->GetData()->FindItem(item);
746 }
747
748 return wxNOT_FOUND;
749 }
750
751 // ---------------------------------------------------------------------------
752 // wxMenuBar functions forwarded to wxMenuItem
753 // ---------------------------------------------------------------------------
754
755 void wxMenuBarBase::Enable(int id, bool enable)
756 {
757 wxMenuItem *item = FindItem(id);
758
759 wxCHECK_RET( item, wxT("attempt to enable an item which doesn't exist") );
760
761 item->Enable(enable);
762 }
763
764 void wxMenuBarBase::Check(int id, bool check)
765 {
766 wxMenuItem *item = FindItem(id);
767
768 wxCHECK_RET( item, wxT("attempt to check an item which doesn't exist") );
769 wxCHECK_RET( item->IsCheckable(), wxT("attempt to check an uncheckable item") );
770
771 item->Check(check);
772 }
773
774 bool wxMenuBarBase::IsChecked(int id) const
775 {
776 wxMenuItem *item = FindItem(id);
777
778 wxCHECK_MSG( item, false, wxT("wxMenuBar::IsChecked(): no such item") );
779
780 return item->IsChecked();
781 }
782
783 bool wxMenuBarBase::IsEnabled(int id) const
784 {
785 wxMenuItem *item = FindItem(id);
786
787 wxCHECK_MSG( item, false, wxT("wxMenuBar::IsEnabled(): no such item") );
788
789 return item->IsEnabled();
790 }
791
792 void wxMenuBarBase::SetLabel(int id, const wxString& label)
793 {
794 wxMenuItem *item = FindItem(id);
795
796 wxCHECK_RET( item, wxT("wxMenuBar::SetLabel(): no such item") );
797
798 item->SetItemLabel(label);
799 }
800
801 wxString wxMenuBarBase::GetLabel(int id) const
802 {
803 wxMenuItem *item = FindItem(id);
804
805 wxCHECK_MSG( item, wxEmptyString,
806 wxT("wxMenuBar::GetLabel(): no such item") );
807
808 return item->GetItemLabel();
809 }
810
811 void wxMenuBarBase::SetHelpString(int id, const wxString& helpString)
812 {
813 wxMenuItem *item = FindItem(id);
814
815 wxCHECK_RET( item, wxT("wxMenuBar::SetHelpString(): no such item") );
816
817 item->SetHelp(helpString);
818 }
819
820 wxString wxMenuBarBase::GetHelpString(int id) const
821 {
822 wxMenuItem *item = FindItem(id);
823
824 wxCHECK_MSG( item, wxEmptyString,
825 wxT("wxMenuBar::GetHelpString(): no such item") );
826
827 return item->GetHelp();
828 }
829
830 void wxMenuBarBase::UpdateMenus( void )
831 {
832 wxEvtHandler* source;
833 wxMenu* menu;
834 int nCount = GetMenuCount();
835 for (int n = 0; n < nCount; n++)
836 {
837 menu = GetMenu( n );
838 if (menu != NULL)
839 {
840 source = menu->GetEventHandler();
841 if (source != NULL)
842 menu->UpdateUI( source );
843 }
844 }
845 }
846
847 #if WXWIN_COMPATIBILITY_2_8
848 // get or change the label of the menu at given position
849 void wxMenuBarBase::SetLabelTop(size_t pos, const wxString& label)
850 {
851 SetMenuLabel(pos, label);
852 }
853
854 wxString wxMenuBarBase::GetLabelTop(size_t pos) const
855 {
856 return GetMenuLabelText(pos);
857 }
858 #endif
859
860 #endif // wxUSE_MENUS