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