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