1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar, wxMenuItem
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
14 // headers & declarations
15 // ============================================================================
21 #pragma implementation "menu.h"
22 #pragma implementation "menuitem.h"
27 #include "wx/menuitem.h"
28 #include "wx/window.h"
32 #include "wx/mac/uma.h"
34 // other standard headers
35 // ----------------------
38 #if !USE_SHARED_LIBRARY
39 IMPLEMENT_DYNAMIC_CLASS(wxMenu
, wxEvtHandler
)
40 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
, wxEvtHandler
)
43 // the (popup) menu title has this special id
44 static const int idMenuTitle
= -2;
45 static MenuItemIndex firstUserHelpMenuItem
= 0 ;
47 const short kwxMacMenuBarResource
= 1 ;
48 const short kwxMacAppleMenuId
= 1 ;
50 // ============================================================================
52 // ============================================================================
57 // Construct a menu with optional title (then use append)
60 short wxMenu::s_macNextMenuId
= 3 ;
62 short wxMenu::s_macNextMenuId
= 2 ;
71 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, m_title
, false );
72 m_macMenuId
= s_macNextMenuId
++;
73 m_hMenu
= ::NewMenu(m_macMenuId
, label
);
77 wxLogLastError("CreatePopupMenu");
80 // if we have a title, insert it in the beginning of the menu
83 Append(idMenuTitle
, m_title
) ;
90 if (MAC_WXHMENU(m_hMenu
))
91 ::DisposeMenu(MAC_WXHMENU(m_hMenu
));
95 WX_CLEAR_ARRAY(m_accels
);
101 // not available on the mac platform
106 int wxMenu::FindAccel(int id
) const
108 size_t n
, count
= m_accels
.GetCount();
109 for ( n
= 0; n
< count
; n
++ )
111 if ( m_accels
[n
]->m_command
== id
)
118 void wxMenu::UpdateAccel(wxMenuItem
*item
)
120 // find the (new) accel for this item
121 wxAcceleratorEntry
*accel
= wxGetAccelFromString(item
->GetText());
123 accel
->m_command
= item
->GetId();
126 int n
= FindAccel(item
->GetId());
127 if ( n
== wxNOT_FOUND
)
129 // no old, add new if any
133 return; // skipping RebuildAccelTable() below
137 // replace old with new or just remove the old one if no new
142 m_accels
.RemoveAt(n
);
147 m_menuBar
->RebuildAccelTable();
151 #endif // wxUSE_ACCEL
153 // function appends a new item or submenu to the menu
154 // append a new item or submenu to the menu
155 bool wxMenu::DoInsertOrAppend(wxMenuItem
*pItem
, size_t pos
)
157 wxASSERT_MSG( pItem
!= NULL
, "can't append NULL item to the menu" );
160 #endif // wxUSE_ACCEL
162 if ( pItem
->IsSeparator() )
164 if ( pos
== (size_t)-1 )
166 MacAppendMenu(MAC_WXHMENU(m_hMenu
), "\p-");
170 MacInsertMenuItem(MAC_WXHMENU(m_hMenu
), "\p-" , pos
);
175 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
176 if ( pSubMenu
!= NULL
)
179 wxASSERT_MSG( pSubMenu
->m_hMenu
!= NULL
, "invalid submenu added");
180 pSubMenu
->m_menuParent
= this ;
181 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, pItem
->GetText() ,false);
183 if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar
)
185 ::InsertMenu( MAC_WXHMENU( pSubMenu
->m_hMenu
) , -1 ) ;
188 if ( pos
== (size_t)-1 )
190 UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu
), label
, pSubMenu
->m_macMenuId
);
194 UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu
), label
, pos
, pSubMenu
->m_macMenuId
);
202 wxMenuItem::MacBuildMenuString( label
, &key
, &modifiers
, pItem
->GetText(), pItem
->GetId() == wxApp::s_macAboutMenuItemId
);
205 // we cannot add empty menus on mac
209 if ( pos
== (size_t)-1 )
211 UMAAppendMenuItem(MAC_WXHMENU(m_hMenu
), label
,key
,modifiers
);
215 UMAInsertMenuItem(MAC_WXHMENU(m_hMenu
), label
, pos
,key
,modifiers
);
217 if ( pItem
->GetId() == idMenuTitle
)
219 if ( pos
== (size_t)-1 )
221 UMADisableMenuItem(MAC_WXHMENU(m_hMenu
) , CountMenuItems(MAC_WXHMENU(m_hMenu
) ) ) ;
225 UMADisableMenuItem(MAC_WXHMENU(m_hMenu
) , pos
+ 1 ) ;
230 // if we're already attached to the menubar, we must update it
233 m_menuBar
->Refresh();
238 bool wxMenu::DoAppend(wxMenuItem
*item
)
240 return wxMenuBase::DoAppend(item
) && DoInsertOrAppend(item
);
243 bool wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
245 return wxMenuBase::DoInsert(pos
, item
) && DoInsertOrAppend(item
, pos
);
248 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
250 // we need to find the items position in the child list
252 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
253 for ( pos
= 0; node
; pos
++ )
255 if ( node
->GetData() == item
)
258 node
= node
->GetNext();
261 // DoRemove() (unlike Remove) can only be called for existing item!
262 wxCHECK_MSG( node
, NULL
, wxT("bug in wxMenu::Remove logic") );
265 // remove the corresponding accel from the accel table
266 int n
= FindAccel(item
->GetId());
267 if ( n
!= wxNOT_FOUND
)
271 m_accels
.RemoveAt(n
);
273 //else: this item doesn't have an accel, nothing to do
274 #endif // wxUSE_ACCEL
276 ::DeleteMenuItem(MAC_WXHMENU(m_hMenu
) , pos
+ 1);
280 // otherwise, the chane won't be visible
281 m_menuBar
->Refresh();
284 // and from internal data structures
285 return wxMenuBase::DoRemove(item
);
288 // ---------------------------------------------------------------------------
289 // accelerator helpers
290 // ---------------------------------------------------------------------------
294 // create the wxAcceleratorEntries for our accels and put them into provided
295 // array - return the number of accels we have
296 size_t wxMenu::CopyAccels(wxAcceleratorEntry
*accels
) const
298 size_t count
= GetAccelCount();
299 for ( size_t n
= 0; n
< count
; n
++ )
301 *accels
++ = *m_accels
[n
];
307 #endif // wxUSE_ACCEL
309 void wxMenu::SetTitle(const wxString
& label
)
313 wxMenuItem::MacBuildMenuString( title
, NULL
, NULL
, label
, false );
314 UMASetMenuTitle(MAC_WXHMENU(m_hMenu
) , title
) ;
316 bool wxMenu::ProcessCommand(wxCommandEvent
& event
)
318 bool processed
= FALSE
;
320 #if WXWIN_COMPATIBILITY
324 (void)(*(m_callback
))(*this, event
);
327 #endif WXWIN_COMPATIBILITY
329 // Try the menu's event handler
330 if ( !processed
&& GetEventHandler())
332 processed
= GetEventHandler()->ProcessEvent(event
);
335 // Try the window the menu was popped up from (and up through the
337 wxWindow
*win
= GetInvokingWindow();
338 if ( !processed
&& win
)
339 processed
= win
->GetEventHandler()->ProcessEvent(event
);
345 // ---------------------------------------------------------------------------
347 // ---------------------------------------------------------------------------
349 wxWindow
*wxMenu::GetWindow() const
351 if ( m_invokingWindow
!= NULL
)
352 return m_invokingWindow
;
353 else if ( m_menuBar
!= NULL
)
354 return (wxWindow
*) m_menuBar
->GetFrame();
359 // helper functions returning the mac menu position for a certain item, note that this is
360 // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0
362 int wxMenu::MacGetIndexFromId( int id
)
365 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
366 for ( pos
= 0; node
; pos
++ )
368 if ( node
->GetData()->GetId() == id
)
371 node
= node
->GetNext();
380 int wxMenu::MacGetIndexFromItem( wxMenuItem
*pItem
)
383 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
384 for ( pos
= 0; node
; pos
++ )
386 if ( node
->GetData() == pItem
)
389 node
= node
->GetNext();
398 void wxMenu::MacEnableMenu( bool bDoEnable
)
401 UMAEnableMenuItem(MAC_WXHMENU(m_hMenu
) , 0 ) ;
403 UMADisableMenuItem(MAC_WXHMENU(m_hMenu
) , 0 ) ;
408 bool wxMenu::MacMenuSelect( wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
413 if ( m_macMenuId
== macMenuId
)
415 node
= GetMenuItems().Nth(macMenuItemNum
-1);
418 wxMenuItem
*pItem
= (wxMenuItem
*)node
->Data();
420 if (pItem
->IsCheckable())
421 pItem
->Check(! pItem
->IsChecked());
423 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
424 event
.m_timeStamp
= when
;
425 event
.SetEventObject(handler
);
426 event
.SetInt( pItem
->GetId() );
428 bool processed
= false ;
430 #if WXWIN_COMPATIBILITY
434 (void) (*(m_callback
)) (*this, event
);
438 // Try the menu's event handler
439 if ( !processed
&& handler
)
441 processed
= handler
->ProcessEvent(event
);
444 // Try the window the menu was popped up from (and up
445 // through the hierarchy)
446 if ( !processed
&& GetInvokingWindow())
447 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
452 else if ( macMenuId
== kHMHelpMenuID
)
454 int menuItem
= firstUserHelpMenuItem
-1 ;
455 for (pos
= 0, node
= GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
457 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
459 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
460 if ( pSubMenu
!= NULL
)
465 if ( pItem
->GetId() != wxApp::s_macAboutMenuItemId
)
468 if ( menuItem
== macMenuItemNum
)
470 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
471 event
.m_timeStamp
= when
;
472 event
.SetEventObject(handler
);
473 event
.SetInt( pItem
->GetId() );
475 bool processed
= false ;
476 #if WXWIN_COMPATIBILITY
480 (void) (*(m_callback
)) (*this, event
);
484 // Try the menu's event handler
485 if ( !processed
&& handler
)
487 processed
= handler
->ProcessEvent(event
);
490 // Try the window the menu was popped up from (and up
491 // through the hierarchy)
492 if ( !processed
&& GetInvokingWindow())
493 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
501 for (pos
= 0, node
= GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
503 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
505 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
506 if ( pSubMenu
!= NULL
)
508 if ( pSubMenu
->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
520 Mac Implementation note :
522 The Mac has only one global menubar, so we attempt to install the currently
523 active menubar from a frame, we currently don't take into account mdi-frames
524 which would ask for menu-merging
526 Secondly there is no mac api for changing a menubar that is not the current
527 menubar, so we have to wait for preparing the actual menubar until the
528 wxMenubar is to be used
530 We can in subsequent versions use MacInstallMenuBar to provide some sort of
531 auto-merge for MDI in case this will be necessary
535 wxMenuBar
* wxMenuBar::s_macInstalledMenuBar
= NULL
;
537 void wxMenuBar::Init()
539 m_eventHandler
= this;
540 m_menuBarFrame
= NULL
;
543 wxMenuBar::wxMenuBar()
548 wxMenuBar::wxMenuBar( long WXUNUSED(style
) )
554 wxMenuBar::wxMenuBar(int count
, wxMenu
*menus
[], const wxString titles
[])
558 m_titles
.Alloc(count
);
560 for ( int i
= 0; i
< count
; i
++ )
562 m_menus
.Append(menus
[i
]);
563 m_titles
.Add(titles
[i
]);
565 menus
[i
]->Attach(this);
569 wxMenuBar::~wxMenuBar()
571 if (s_macInstalledMenuBar
== this)
574 s_macInstalledMenuBar
= NULL
;
579 void wxMenuBar::Refresh(bool WXUNUSED(eraseBackground
), const wxRect
*WXUNUSED(rect
))
581 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
588 void wxMenuBar::RebuildAccelTable()
590 // merge the accelerators of all menus into one accel table
591 size_t nAccelCount
= 0;
592 size_t i
, count
= GetMenuCount();
593 for ( i
= 0; i
< count
; i
++ )
595 nAccelCount
+= m_menus
[i
]->GetAccelCount();
600 wxAcceleratorEntry
*accelEntries
= new wxAcceleratorEntry
[nAccelCount
];
603 for ( i
= 0; i
< count
; i
++ )
605 nAccelCount
+= m_menus
[i
]->CopyAccels(&accelEntries
[nAccelCount
]);
608 m_accelTable
= wxAcceleratorTable(nAccelCount
, accelEntries
);
610 delete [] accelEntries
;
614 #endif // wxUSE_ACCEL
616 void wxMenuBar::MacInstallMenuBar()
618 if ( s_macInstalledMenuBar
== this )
621 wxStAppResource resload
;
623 Handle menubar
= ::GetNewMBar( kwxMacMenuBarResource
) ;
625 wxCHECK_RET( menubar
!= NULL
, "can't read MBAR resource" );
626 ::SetMenuBar( menubar
) ;
627 #if TARGET_API_MAC_CARBON
628 ::DisposeMenuBar( menubar
) ;
630 ::DisposeHandle( menubar
) ;
633 #if TARGET_API_MAC_OS8
634 MenuHandle menu
= ::GetMenuHandle( kwxMacAppleMenuId
) ;
635 if ( CountMenuItems( menu
) == 2 )
637 ::AppendResMenu(menu
, 'DRVR');
641 for (size_t i
= 0; i
< m_menus
.GetCount(); i
++)
647 wxMenu
* menu
= m_menus
[i
] , *subMenu
= NULL
;
649 if( m_titles
[i
] == "?" || m_titles
[i
] == "&?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
)
651 MenuHandle mh
= NULL
;
652 if ( UMAGetHelpMenu( &mh
, &firstUserHelpMenuItem
) != noErr
)
657 for ( int i
= CountMenuItems( mh
) ; i
>= firstUserHelpMenuItem
; --i
)
659 DeleteMenuItem( mh
, i
) ;
662 for (pos
= 0 , node
= menu
->GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
664 item
= (wxMenuItem
*)node
->Data();
665 subMenu
= item
->GetSubMenu() ;
668 // we don't support hierarchical menus in the help menu yet
672 if ( item
->IsSeparator() )
675 MacAppendMenu(mh
, "\p-" );
682 wxMenuItem::MacBuildMenuString( label
, &key
, &modifiers
, item
->GetText(), item
->GetId() != wxApp::s_macAboutMenuItemId
); // no shortcut in about menu
685 // we cannot add empty menus on mac
689 if ( item
->GetId() == wxApp::s_macAboutMenuItemId
)
691 ::SetMenuItemText( GetMenuHandle( kwxMacAppleMenuId
) , 1 , label
);
692 UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId
) , 1 );
697 UMAAppendMenuItem(mh
, label
, key
, modifiers
);
705 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, m_titles
[i
] , false );
706 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , label
) ;
707 wxArrayPtrVoid submenus
;
709 for (pos
= 0, node
= menu
->GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
711 item
= (wxMenuItem
*)node
->Data();
712 subMenu
= item
->GetSubMenu() ;
715 submenus
.Add(subMenu
) ;
718 ::InsertMenu(MAC_WXHMENU(m_menus
[i
]->GetHMenu()), 0);
719 for ( size_t i
= 0 ; i
< submenus
.GetCount() ; ++i
)
721 wxMenu
* submenu
= (wxMenu
*) submenus
[i
] ;
725 for ( subpos
= 0 , subnode
= submenu
->GetMenuItems().First(); subnode
; subnode
= subnode
->Next(), subpos
++)
727 subitem
= (wxMenuItem
*)subnode
->Data();
728 wxMenu
* itsSubMenu
= subitem
->GetSubMenu() ;
731 submenus
.Add(itsSubMenu
) ;
734 ::InsertMenu( MAC_WXHMENU(submenu
->GetHMenu()) , -1 ) ;
739 s_macInstalledMenuBar
= this;
742 void wxMenuBar::EnableTop(size_t pos
, bool enable
)
744 wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
745 m_menus
[pos
]->MacEnableMenu( enable
) ;
749 void wxMenuBar::SetLabelTop(size_t pos
, const wxString
& label
)
751 wxCHECK_RET( pos
< GetMenuCount(), wxT("invalid menu index") );
753 m_titles
[pos
] = label
;
760 m_menus
[pos
]->SetTitle( label
) ;
761 if (wxMenuBar::s_macInstalledMenuBar
== this) // are we currently installed ?
763 ::SetMenuBar( GetMenuBar() ) ;
768 wxString
wxMenuBar::GetLabelTop(size_t pos
) const
770 wxCHECK_MSG( pos
< GetMenuCount(), wxEmptyString
,
771 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
773 return m_titles
[pos
];
776 int wxMenuBar::FindMenu(const wxString
& title
)
778 wxString menuTitle
= wxStripMenuCodes(title
);
780 size_t count
= GetMenuCount();
781 for ( size_t i
= 0; i
< count
; i
++ )
783 wxString title
= wxStripMenuCodes(m_titles
[i
]);
784 if ( menuTitle
== title
)
793 // ---------------------------------------------------------------------------
794 // wxMenuBar construction
795 // ---------------------------------------------------------------------------
797 // ---------------------------------------------------------------------------
798 // wxMenuBar construction
799 // ---------------------------------------------------------------------------
801 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
803 wxMenu
*menuOld
= wxMenuBarBase::Replace(pos
, menu
, title
);
806 m_titles
[pos
] = title
;
810 if (s_macInstalledMenuBar
== this)
812 ::DeleteMenu( menuOld
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
815 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, title
, false );
816 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , label
) ;
817 if ( pos
== m_menus
.GetCount() - 1)
819 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
823 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , m_menus
[pos
+1]->MacGetMenuId() ) ;
830 if ( menuOld
->HasAccels() || menu
->HasAccels() )
832 // need to rebuild accell table
835 #endif // wxUSE_ACCEL
843 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
845 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
848 m_titles
.Insert(title
, pos
);
851 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, title
, false );
852 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , label
) ;
856 if ( pos
== (size_t) -1 || pos
+ 1 == m_menus
.GetCount() )
858 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
862 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , m_menus
[pos
+1]->MacGetMenuId() ) ;
866 if ( menu
->HasAccels() )
868 // need to rebuild accell table
871 #endif // wxUSE_ACCEL
879 void wxMenuBar::MacMenuSelect(wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
881 // first scan fast for direct commands, i.e. menus which have these commands directly in their own list
883 if ( macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
== 1 )
885 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, wxApp::s_macAboutMenuItemId
);
886 event
.m_timeStamp
= when
;
887 event
.SetEventObject(handler
);
888 event
.SetInt( wxApp::s_macAboutMenuItemId
);
889 handler
->ProcessEvent(event
);
893 for (size_t i
= 0; i
< m_menus
.GetCount() ; i
++)
895 if ( m_menus
[i
]->MacGetMenuId() == macMenuId
|| ( macMenuId
== kHMHelpMenuID
&& ( m_titles
[i
] == "?" || m_titles
[i
] == "&?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
) ) )
897 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
901 //TODO flag this as an error since it must contain the item
907 for (size_t i
= 0; i
< m_menus
.GetCount(); i
++)
909 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
917 wxMenu
*wxMenuBar::Remove(size_t pos
)
919 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
925 if (s_macInstalledMenuBar
== this)
927 ::DeleteMenu( menu
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
933 if ( menu
->HasAccels() )
935 // need to rebuild accell table
938 #endif // wxUSE_ACCEL
943 m_titles
.Remove(pos
);
948 bool wxMenuBar::Append(wxMenu
*menu
, const wxString
& title
)
950 WXHMENU submenu
= menu
? menu
->GetHMenu() : 0;
951 wxCHECK_MSG( submenu
, FALSE
, wxT("can't append invalid menu to menubar") );
953 if ( !wxMenuBarBase::Append(menu
, title
) )
959 wxMenuItem::MacBuildMenuString( label
, NULL
, NULL
, title
, false );
960 UMASetMenuTitle( MAC_WXHMENU(menu
->GetHMenu()) , label
) ;
964 if (s_macInstalledMenuBar
== this)
966 ::InsertMenu( MAC_WXHMENU(menu
->GetHMenu()) , 0 ) ;
970 if ( menu
->HasAccels() )
972 // need to rebuild accell table
975 #endif // wxUSE_ACCEL
983 void wxMenuBar::Detach()
985 wxMenuBarBase::Detach() ;
988 void wxMenuBar::Attach(wxFrame
*frame
)
990 wxMenuBarBase::Attach( frame
) ;
994 #endif // wxUSE_ACCEL
996 // ---------------------------------------------------------------------------
997 // wxMenuBar searching for menu items
998 // ---------------------------------------------------------------------------
1000 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
1001 int wxMenuBar::FindMenuItem(const wxString
& menuString
,
1002 const wxString
& itemString
) const
1004 wxString menuLabel
= wxStripMenuCodes(menuString
);
1005 size_t count
= GetMenuCount();
1006 for ( size_t i
= 0; i
< count
; i
++ )
1008 wxString title
= wxStripMenuCodes(m_titles
[i
]);
1009 if ( menuString
== title
)
1010 return m_menus
[i
]->FindItem(itemString
);
1016 wxMenuItem
*wxMenuBar::FindItem(int id
, wxMenu
**itemMenu
) const
1021 wxMenuItem
*item
= NULL
;
1022 size_t count
= GetMenuCount();
1023 for ( size_t i
= 0; !item
&& (i
< count
); i
++ )
1025 item
= m_menus
[i
]->FindItem(id
, itemMenu
);