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"
26 #include "wx/menuitem.h"
30 #include "wx/mac/uma.h"
32 // other standard headers
33 // ----------------------
36 #if !USE_SHARED_LIBRARY
37 IMPLEMENT_DYNAMIC_CLASS(wxMenu
, wxEvtHandler
)
38 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
, wxEvtHandler
)
41 // the (popup) menu title has this special id
42 static const int idMenuTitle
= -2;
43 static int formerHelpMenuItems
= 0 ;
45 const short kwxMacMenuBarResource
= 1 ;
46 const short kwxMacAppleMenuId
= 1 ;
48 // ============================================================================
50 // ============================================================================
53 // Helper Functions to get Mac Menus the way they should be ;-)
56 void wxMacCtoPString(const char* theCString
, Str255 thePString
);
58 // remove inappropriate characters, if useShortcuts is false, the ampersand will not auto-generate a mac menu-shortcut
60 void wxMacBuildMenuString(StringPtr outMacItemText
, char *outMacShortcutChar
, short *outMacModifiers
, const char *inItemName
, bool useShortcuts
)
62 char *p
= (char *) &outMacItemText
[1] ;
63 short macModifiers
= 0 ;
64 char macShortCut
= 0 ;
66 if ( useShortcuts
&& !wxApp::s_macSupportPCMenuShortcuts
)
67 useShortcuts
= false ;
69 // we have problems with a leading hypen - it will be taken as a separator
71 while ( *inItemName
== '-' )
76 switch ( *inItemName
)
78 // special characters for macintosh menus -> use some replacement
108 macShortCut
= *inItemName
;
114 // win-like accelerators
120 if (strncmp("Ctrl", inItemName
, 4) == 0)
122 inItemName
= inItemName
+ 5;
123 macShortCut
= *inItemName
;
125 else if (strncmp("Alt", inItemName
, 3) == 0)
127 inItemName
= inItemName
+ 4;
128 macModifiers
|= kMenuOptionModifier
;
129 macShortCut
= *inItemName
;
131 else if (strncmp("Shift", inItemName
, 5) == 0)
133 inItemName
= inItemName
+ 6;
134 macModifiers
|= kMenuShiftModifier
;
135 macShortCut
= *inItemName
;
137 else if (strncmp("F", inItemName
, 1) == 0)
139 inItemName
+= strlen( inItemName
) ;
140 // no function keys at the moment
141 // macModifiers |= kMenuShiftModifier ;
142 // macShortCut = *inItemName ;
150 if ( *inItemName
== 0 )
161 outMacItemText
[0] = (p
- (char *)outMacItemText
) - 1;
162 if ( outMacShortcutChar
)
163 *outMacShortcutChar
= macShortCut
;
164 if ( outMacModifiers
)
165 *outMacModifiers
= macModifiers
;
168 int pos
= outMacItemText
[0] ;
169 outMacItemText
[++pos
] = '/';
170 outMacItemText
[++pos
] = toupper( macShortCut
);
171 outMacItemText
[0] = pos
;
177 // Construct a menu with optional title (then use append)
179 short wxMenu::s_macNextMenuId
= 2 ;
187 wxMacBuildMenuString( label
, NULL
, NULL
, m_title
, false );
188 m_macMenuId
= s_macNextMenuId
++;
189 wxCHECK_RET( s_macNextMenuId
< 236 , "menu ids > 235 cannot be used for submenus on mac" );
190 m_hMenu
= ::NewMenu(m_macMenuId
, label
);
194 wxLogLastError("CreatePopupMenu");
197 // if we have a title, insert it in the beginning of the menu
200 Append(idMenuTitle
, m_title
) ;
208 ::DisposeMenu(m_hMenu
);
212 WX_CLEAR_ARRAY(m_accels
);
213 #endif // wxUSE_ACCEL
218 // not available on the mac platform
223 int wxMenu::FindAccel(int id
) const
225 size_t n
, count
= m_accels
.GetCount();
226 for ( n
= 0; n
< count
; n
++ )
228 if ( m_accels
[n
]->m_command
== id
)
235 void wxMenu::UpdateAccel(wxMenuItem
*item
)
237 // find the (new) accel for this item
238 wxAcceleratorEntry
*accel
= wxGetAccelFromString(item
->GetText());
240 accel
->m_command
= item
->GetId();
243 int n
= FindAccel(item
->GetId());
244 if ( n
== wxNOT_FOUND
)
246 // no old, add new if any
250 return; // skipping RebuildAccelTable() below
254 // replace old with new or just remove the old one if no new
264 m_menuBar
->RebuildAccelTable();
268 #endif // wxUSE_ACCEL
270 // function appends a new item or submenu to the menu
271 // append a new item or submenu to the menu
272 bool wxMenu::DoInsertOrAppend(wxMenuItem
*pItem
, size_t pos
)
274 wxASSERT_MSG( pItem
!= NULL
, "can't append NULL item to the menu" );
277 #endif // wxUSE_ACCEL
279 if ( pItem
->IsSeparator() )
281 if ( pos
== (size_t)-1 )
283 MacAppendMenu(m_hMenu
, "\p-");
287 MacInsertMenuItem(m_hMenu
, "\p-" , pos
);
292 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
293 if ( pSubMenu
!= NULL
)
296 wxASSERT_MSG( pSubMenu
->m_hMenu
!= NULL
, "invalid submenu added");
297 pSubMenu
->m_menuParent
= this ;
298 wxMacBuildMenuString( label
, NULL
, NULL
, pItem
->GetText() ,false);
300 // hardcoded adding of the submenu combination for mac
302 int theEnd
= label
[0] + 1;
304 theEnd
= 251; // mac allows only 255 characters
305 label
[theEnd
++] = '/';
306 label
[theEnd
++] = hMenuCmd
;
307 label
[theEnd
++] = '!';
308 label
[theEnd
++] = pSubMenu
->m_macMenuId
;
309 label
[theEnd
] = 0x00;
312 if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar
)
314 ::InsertMenu( pSubMenu
->m_hMenu
, -1 ) ;
317 if ( pos
== (size_t)-1 )
319 MacAppendMenu(m_hMenu
, label
);
323 MacInsertMenuItem(m_hMenu
, label
, pos
);
329 wxMacBuildMenuString( label
, NULL
, NULL
, pItem
->GetText(), pItem
->GetId() == wxApp::s_macAboutMenuItemId
);
332 // we cannot add empty menus on mac
336 if ( pos
== (size_t)-1 )
338 MacAppendMenu(m_hMenu
, label
);
342 MacInsertMenuItem(m_hMenu
, label
, pos
);
344 if ( pItem
->GetId() == idMenuTitle
)
346 if ( pos
== (size_t)-1 )
348 UMADisableMenuItem( m_hMenu
, CountMItems( m_hMenu
) ) ;
352 UMADisableMenuItem( m_hMenu
, pos
+ 1 ) ;
357 // if we're already attached to the menubar, we must update it
360 m_menuBar
->Refresh();
365 bool wxMenu::DoAppend(wxMenuItem
*item
)
367 return wxMenuBase::DoAppend(item
) && DoInsertOrAppend(item
);
370 bool wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
372 return wxMenuBase::DoInsert(pos
, item
) && DoInsertOrAppend(item
, pos
);
375 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
377 // we need to find the items position in the child list
379 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
380 for ( pos
= 0; node
; pos
++ )
382 if ( node
->GetData() == item
)
385 node
= node
->GetNext();
388 // DoRemove() (unlike Remove) can only be called for existing item!
389 wxCHECK_MSG( node
, NULL
, wxT("bug in wxMenu::Remove logic") );
392 // remove the corresponding accel from the accel table
393 int n
= FindAccel(item
->GetId());
394 if ( n
!= wxNOT_FOUND
)
400 //else: this item doesn't have an accel, nothing to do
401 #endif // wxUSE_ACCEL
403 ::DeleteMenuItem( m_hMenu
, pos
+ 1);
407 // otherwise, the chane won't be visible
408 m_menuBar
->Refresh();
411 // and from internal data structures
412 return wxMenuBase::DoRemove(item
);
415 // ---------------------------------------------------------------------------
416 // accelerator helpers
417 // ---------------------------------------------------------------------------
421 // create the wxAcceleratorEntries for our accels and put them into provided
422 // array - return the number of accels we have
423 size_t wxMenu::CopyAccels(wxAcceleratorEntry
*accels
) const
425 size_t count
= GetAccelCount();
426 for ( size_t n
= 0; n
< count
; n
++ )
428 *accels
++ = *m_accels
[n
];
434 #endif // wxUSE_ACCEL
436 void wxMenu::SetTitle(const wxString
& label
)
440 wxMacBuildMenuString( title
, NULL
, NULL
, label
, false );
441 UMASetMenuTitle( m_hMenu
, title
) ;
446 void wxMenu::SetLabel(int id, const wxString& label)
450 wxMenuItem *item = FindItemForId(id) ;
454 index = MacGetIndexFromItem( item ) ;
458 if (item->GetSubMenu()==NULL)
460 wxMacBuildMenuString( maclabel , NULL , NULL , label , false );
461 ::SetMenuItemText( m_hMenu , index , maclabel ) ;
465 wxMacBuildMenuString( maclabel , NULL , NULL , label , false );
466 ::SetMenuItemText( m_hMenu , index , maclabel ) ;
468 item->SetName(label);
471 wxString wxMenu::GetLabel(int Id) const
473 wxMenuItem *pItem = FindItemForId(Id) ;
474 return pItem->GetName() ;
477 // Finds the item id matching the given string, -1 if not found.
478 int wxMenu::FindItem (const wxString& itemString) const
482 wxStripMenuCodes ((char *)(const char *)itemString, buf1);
484 for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
486 wxMenuItem *item = (wxMenuItem *) node->Data ();
487 if (item->GetSubMenu())
489 int ans = item->GetSubMenu()->FindItem(itemString);
493 if ( !item->IsSeparator() )
495 wxStripMenuCodes((char *)item->GetName().c_str(), buf2);
496 if (strcmp(buf1, buf2) == 0)
497 return item->GetId();
504 wxMenuItem *wxMenu::FindItemForId(int itemId, wxMenu ** itemMenu) const
508 for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
510 wxMenuItem *item = (wxMenuItem *) node->Data ();
512 if (item->GetId() == itemId)
515 *itemMenu = (wxMenu *) this;
519 if (item->GetSubMenu())
521 wxMenuItem *ans = item->GetSubMenu()->FindItemForId (itemId, itemMenu);
532 void wxMenu::SetHelpString(int itemId, const wxString& helpString)
534 wxMenuItem *item = FindItemForId (itemId);
536 item->SetHelp(helpString);
539 wxString wxMenu::GetHelpString (int itemId) const
541 wxMenuItem *item = FindItemForId (itemId);
543 return (item == NULL) ? str : item->GetHelp();
547 bool wxMenu::ProcessCommand(wxCommandEvent
& event
)
549 bool processed
= FALSE
;
551 #if WXWIN_COMPATIBILITY
555 (void)(*(m_callback
))(*this, event
);
558 #endif WXWIN_COMPATIBILITY
560 // Try the menu's event handler
561 if ( !processed
&& GetEventHandler())
563 processed
= GetEventHandler()->ProcessEvent(event
);
566 // Try the window the menu was popped up from (and up through the
568 wxWindow
*win
= GetInvokingWindow();
569 if ( !processed
&& win
)
570 processed
= win
->GetEventHandler()->ProcessEvent(event
);
576 // ---------------------------------------------------------------------------
578 // ---------------------------------------------------------------------------
580 void wxMenu::Attach(wxMenuBar
*menubar
)
582 // menu can be in at most one menubar because otherwise they would both
583 // delete the menu pointer
584 wxASSERT_MSG( !m_menuBar
, wxT("menu belongs to 2 menubars, expect a crash") );
589 void wxMenu::Detach()
591 wxASSERT_MSG( m_menuBar
, wxT("can't detach menu if it's not attached") );
596 wxWindow
*wxMenu::GetWindow() const
598 if ( m_invokingWindow
!= NULL
)
599 return m_invokingWindow
;
600 else if ( m_menuBar
!= NULL
)
601 return m_menuBar
->GetFrame();
606 // helper functions returning the mac menu position for a certain item, note that this is
607 // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0
609 int wxMenu::MacGetIndexFromId( int id
)
612 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
613 for ( pos
= 0; node
; pos
++ )
615 if ( node
->GetData()->GetId() == id
)
618 node
= node
->GetNext();
627 int wxMenu::MacGetIndexFromItem( wxMenuItem
*pItem
)
630 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
631 for ( pos
= 0; node
; pos
++ )
633 if ( node
->GetData() == pItem
)
636 node
= node
->GetNext();
645 void wxMenu::MacEnableMenu( bool bDoEnable
)
648 UMAEnableMenuItem( m_hMenu
, 0 ) ;
650 UMADisableMenuItem( m_hMenu
, 0 ) ;
655 bool wxMenu::MacMenuSelect( wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
660 if ( m_macMenuId
== macMenuId
)
662 node
= GetMenuItems().Nth(macMenuItemNum
-1);
665 wxMenuItem
*pItem
= (wxMenuItem
*)node
->Data();
667 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
668 event
.m_timeStamp
= when
;
669 event
.SetEventObject(handler
);
670 event
.SetInt( pItem
->GetId() );
672 bool processed
= false ;
674 #if WXWIN_COMPATIBILITY
678 (void) (*(m_callback
)) (*this, event
);
682 // Try the menu's event handler
683 if ( !processed
&& handler
)
685 processed
= handler
->ProcessEvent(event
);
688 // Try the window the menu was popped up from (and up
689 // through the hierarchy)
690 if ( !processed
&& GetInvokingWindow())
691 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
696 else if ( macMenuId
== kHMHelpMenuID
)
698 int menuItem
= formerHelpMenuItems
;
699 for (pos
= 0, node
= GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
701 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
703 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
704 if ( pSubMenu
!= NULL
)
709 if ( pItem
->GetId() != wxApp::s_macAboutMenuItemId
)
712 if ( menuItem
== macMenuItemNum
)
714 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
715 event
.m_timeStamp
= when
;
716 event
.SetEventObject(handler
);
717 event
.SetInt( pItem
->GetId() );
719 bool processed
= false ;
720 #if WXWIN_COMPATIBILITY
724 (void) (*(m_callback
)) (*this, event
);
728 // Try the menu's event handler
729 if ( !processed
&& handler
)
731 processed
= handler
->ProcessEvent(event
);
734 // Try the window the menu was popped up from (and up
735 // through the hierarchy)
736 if ( !processed
&& GetInvokingWindow())
737 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
745 for (pos
= 0, node
= GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
747 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
749 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
750 if ( pSubMenu
!= NULL
)
752 if ( pSubMenu
->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
764 Mac Implementation note :
766 The Mac has only one global menubar, so we attempt to install the currently
767 active menubar from a frame, we currently don't take into account mdi-frames
768 which would ask for menu-merging
770 Secondly there is no mac api for changing a menubar that is not the current
771 menubar, so we have to wait for preparing the actual menubar until the
772 wxMenubar is to be used
774 We can in subsequent versions use MacInstallMenuBar to provide some sort of
775 auto-merge for MDI in case this will be necessary
779 wxMenuBar
* wxMenuBar::s_macInstalledMenuBar
= NULL
;
781 void wxMenuBar::Init()
783 m_eventHandler
= this;
784 m_menuBarFrame
= NULL
;
787 wxMenuBar::wxMenuBar()
792 wxMenuBar::wxMenuBar( long WXUNUSED(style
) )
798 wxMenuBar::wxMenuBar(int count
, wxMenu
*menus
[], const wxString titles
[])
802 m_titles
.Alloc(count
);
804 for ( int i
= 0; i
< count
; i
++ )
806 m_menus
.Append(menus
[i
]);
807 m_titles
.Add(titles
[i
]);
809 menus
[i
]->Attach(this);
813 wxMenuBar::~wxMenuBar()
815 if (s_macInstalledMenuBar
== this)
818 s_macInstalledMenuBar
= NULL
;
823 void wxMenuBar::Refresh()
825 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
832 void wxMenuBar::RebuildAccelTable()
834 // merge the accelerators of all menus into one accel table
835 size_t nAccelCount
= 0;
836 size_t i
, count
= GetMenuCount();
837 for ( i
= 0; i
< count
; i
++ )
839 nAccelCount
+= m_menus
[i
]->GetAccelCount();
844 wxAcceleratorEntry
*accelEntries
= new wxAcceleratorEntry
[nAccelCount
];
847 for ( i
= 0; i
< count
; i
++ )
849 nAccelCount
+= m_menus
[i
]->CopyAccels(&accelEntries
[nAccelCount
]);
852 m_accelTable
= wxAcceleratorTable(nAccelCount
, accelEntries
);
854 delete [] accelEntries
;
858 #endif // wxUSE_ACCEL
861 void wxMenuBar::MacInstallMenuBar()
863 Handle menubar
= ::GetNewMBar( kwxMacMenuBarResource
) ;
865 wxCHECK_RET( menubar
!= NULL
, "can't read MBAR resource" );
866 ::SetMenuBar( menubar
) ;
867 ::DisposeHandle( menubar
) ;
869 MenuHandle menu
= ::GetMenuHandle( kwxMacAppleMenuId
) ;
870 ::AppendResMenu(menu
, 'DRVR');
872 for (int i
= 0; i
< m_menus
.GetCount(); i
++)
878 wxMenu
* menu
= m_menus
[i
] , *subMenu
= NULL
;
881 if( m_titles
[i
] == "?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
)
883 MenuHandle mh
= NULL
;
884 if ( HMGetHelpMenuHandle( &mh
) != noErr
)
888 if ( formerHelpMenuItems
== 0 )
891 formerHelpMenuItems
= CountMenuItems( mh
) ;
894 for (pos
= 0 , node
= menu
->GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
896 item
= (wxMenuItem
*)node
->Data();
897 subMenu
= item
->GetSubMenu() ;
900 // we don't support hierarchical menus in the help menu yet
905 wxMacBuildMenuString( label
, NULL
, NULL
, item
->GetText(), item
->GetId() != wxApp::s_macAboutMenuItemId
); // no shortcut in about menu
908 // we cannot add empty menus on mac
912 if ( item
->GetId() == wxApp::s_macAboutMenuItemId
)
914 ::SetMenuItemText( GetMenuHandle( kwxMacAppleMenuId
) , 1 , label
);
915 // ::EnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 );
916 ::EnableItem( GetMenuHandle( kwxMacAppleMenuId
) , 1 );
921 ::AppendMenu(mh
, label
);
928 wxMacBuildMenuString( label
, NULL
, NULL
, m_titles
[i
] , false );
929 UMASetMenuTitle( menu
->GetHMenu() , label
) ;
930 for (pos
= 0, node
= menu
->GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
932 item
= (wxMenuItem
*)node
->Data();
933 subMenu
= item
->GetSubMenu() ;
936 ::InsertMenu( subMenu
->GetHMenu() , -1 ) ;
939 ::InsertMenu(m_menus
[i
]->GetHMenu(), 0);
944 s_macInstalledMenuBar
= this;
947 void wxMenuBar::EnableTop(size_t pos
, bool enable
)
949 wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
950 m_menus
[pos
]->MacEnableMenu( enable
) ;
954 void wxMenuBar::SetLabelTop(size_t pos
, const wxString
& label
)
956 wxCHECK_RET( pos
< GetMenuCount(), wxT("invalid menu index") );
958 m_titles
[pos
] = label
;
965 m_menus
[pos
]->SetTitle( label
) ;
966 if (wxMenuBar::s_macInstalledMenuBar
== this) // are we currently installed ?
968 ::SetMenuBar( GetMenuBar() ) ;
973 wxString
wxMenuBar::GetLabelTop(size_t pos
) const
975 wxCHECK_MSG( pos
< GetMenuCount(), wxEmptyString
,
976 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
978 return m_titles
[pos
];
981 int wxMenuBar::FindMenu(const wxString
& title
)
983 wxString menuTitle
= wxStripMenuCodes(title
);
985 size_t count
= GetMenuCount();
986 for ( size_t i
= 0; i
< count
; i
++ )
988 wxString title
= wxStripMenuCodes(m_titles
[i
]);
989 if ( menuTitle
== title
)
998 // ---------------------------------------------------------------------------
999 // wxMenuBar construction
1000 // ---------------------------------------------------------------------------
1002 // ---------------------------------------------------------------------------
1003 // wxMenuBar construction
1004 // ---------------------------------------------------------------------------
1006 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
1008 wxMenu
*menuOld
= wxMenuBarBase::Replace(pos
, menu
, title
);
1011 m_titles
[pos
] = title
;
1015 if (s_macInstalledMenuBar
== this)
1017 ::DeleteMenu( menuOld
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
1020 wxMacBuildMenuString( label
, NULL
, NULL
, title
, false );
1021 UMASetMenuTitle( menu
->GetHMenu() , label
) ;
1022 if ( pos
== m_menus
.GetCount() - 1)
1024 ::InsertMenu( menu
->GetHMenu() , 0 ) ;
1028 ::InsertMenu( menu
->GetHMenu() , m_menus
[pos
+1]->MacGetMenuId() ) ;
1035 if ( menuOld
->HasAccels() || menu
->HasAccels() )
1037 // need to rebuild accell table
1038 RebuildAccelTable();
1040 #endif // wxUSE_ACCEL
1048 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
1050 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
1053 m_titles
.Insert(title
, pos
);
1059 if ( pos
== (size_t) -1 )
1061 ::InsertMenu( menu
->GetHMenu() , 0 ) ;
1065 ::InsertMenu( menu
->GetHMenu() , m_menus
[pos
+1]->MacGetMenuId() ) ;
1069 if ( menu
->HasAccels() )
1071 // need to rebuild accell table
1072 RebuildAccelTable();
1074 #endif // wxUSE_ACCEL
1082 void wxMenuBar::MacMenuSelect(wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
1084 // first scan fast for direct commands, i.e. menus which have these commands directly in their own list
1086 if ( macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
== 1 )
1088 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, wxApp::s_macAboutMenuItemId
);
1089 event
.m_timeStamp
= when
;
1090 event
.SetEventObject(handler
);
1091 event
.SetInt( wxApp::s_macAboutMenuItemId
);
1092 handler
->ProcessEvent(event
);
1096 for (int i
= 0; i
< m_menus
.GetCount() ; i
++)
1098 if ( m_menus
[i
]->MacGetMenuId() == macMenuId
||
1099 ( macMenuId
== kHMHelpMenuID
&& ( m_titles
[i
] == "?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
) )
1102 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
1106 //TODO flag this as an error since it must contain the item
1112 for (int i
= 0; i
< m_menus
.GetCount(); i
++)
1114 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
1122 wxMenu
*wxMenuBar::Remove(size_t pos
)
1124 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
1130 if (s_macInstalledMenuBar
== this)
1132 ::DeleteMenu( menu
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
1138 if ( menu
->HasAccels() )
1140 // need to rebuild accell table
1141 RebuildAccelTable();
1143 #endif // wxUSE_ACCEL
1148 m_titles
.Remove(pos
);
1153 bool wxMenuBar::Append(wxMenu
*menu
, const wxString
& title
)
1155 WXHMENU submenu
= menu
? menu
->GetHMenu() : 0;
1156 wxCHECK_MSG( submenu
, FALSE
, wxT("can't append invalid menu to menubar") );
1158 if ( !wxMenuBarBase::Append(menu
, title
) )
1163 m_titles
.Add(title
);
1167 if (s_macInstalledMenuBar
== this)
1169 ::InsertMenu( menu
->GetHMenu() , 0 ) ;
1173 if ( menu
->HasAccels() )
1175 // need to rebuild accell table
1176 RebuildAccelTable();
1178 #endif // wxUSE_ACCEL
1186 // ---------------------------------------------------------------------------
1187 // wxMenuBar searching for menu items
1188 // ---------------------------------------------------------------------------
1190 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
1191 int wxMenuBar::FindMenuItem(const wxString
& menuString
,
1192 const wxString
& itemString
) const
1194 wxString menuLabel
= wxStripMenuCodes(menuString
);
1195 size_t count
= GetMenuCount();
1196 for ( size_t i
= 0; i
< count
; i
++ )
1198 wxString title
= wxStripMenuCodes(m_titles
[i
]);
1199 if ( menuString
== title
)
1200 return m_menus
[i
]->FindItem(itemString
);
1206 wxMenuItem
*wxMenuBar::FindItem(int id
, wxMenu
**itemMenu
) const
1211 wxMenuItem
*item
= NULL
;
1212 size_t count
= GetMenuCount();
1213 for ( size_t i
= 0; !item
&& (i
< count
); i
++ )
1215 item
= m_menus
[i
]->FindItem(id
, itemMenu
);