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 IMPLEMENT_DYNAMIC_CLASS(wxMenu
, wxEvtHandler
)
37 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
, wxEvtHandler
)
39 // the (popup) menu title has this special id
40 static const int idMenuTitle
= -2;
41 static int formerHelpMenuItems
= 0 ;
43 const short kwxMacMenuBarResource
= 1 ;
44 const short kwxMacAppleMenuId
= 1 ;
46 // ============================================================================
48 // ============================================================================
51 // Helper Functions to get Mac Menus the way they should be ;-)
54 void wxMacCtoPString(const char* theCString
, Str255 thePString
);
56 // remove inappropriate characters, if useShortcuts is false, the ampersand will not auto-generate a mac menu-shortcut
58 void wxMacBuildMenuString(StringPtr outMacItemText
, char *outMacShortcutChar
, short *outMacModifiers
, const char *inItemName
, bool useShortcuts
)
60 char *p
= (char *) &outMacItemText
[1] ;
61 short macModifiers
= 0 ;
62 char macShortCut
= 0 ;
64 if ( useShortcuts
&& !wxApp::s_macSupportPCMenuShortcuts
)
65 useShortcuts
= false ;
67 // we have problems with a leading hypen - it will be taken as a separator
69 while ( *inItemName
== '-' )
74 switch ( *inItemName
)
76 // special characters for macintosh menus -> use some replacement
106 macShortCut
= *inItemName
;
112 // win-like accelerators
118 if (strncmp("Ctrl", inItemName
, 4) == 0)
120 inItemName
= inItemName
+ 5;
121 macShortCut
= *inItemName
;
123 else if (strncmp("Alt", inItemName
, 3) == 0)
125 inItemName
= inItemName
+ 4;
126 macModifiers
|= kMenuOptionModifier
;
127 macShortCut
= *inItemName
;
129 else if (strncmp("Shift", inItemName
, 5) == 0)
131 inItemName
= inItemName
+ 6;
132 macModifiers
|= kMenuShiftModifier
;
133 macShortCut
= *inItemName
;
135 else if (strncmp("F", inItemName
, 1) == 0)
137 inItemName
+= strlen( inItemName
) ;
138 // no function keys at the moment
139 // macModifiers |= kMenuShiftModifier ;
140 // macShortCut = *inItemName ;
148 if ( *inItemName
== 0 )
159 outMacItemText
[0] = (p
- (char *)outMacItemText
) - 1;
160 if ( outMacShortcutChar
)
161 *outMacShortcutChar
= macShortCut
;
162 if ( outMacModifiers
)
163 *outMacModifiers
= macModifiers
;
166 int pos
= outMacItemText
[0] ;
167 outMacItemText
[++pos
] = '/';
168 outMacItemText
[++pos
] = toupper( macShortCut
);
169 outMacItemText
[0] = pos
;
175 // Construct a menu with optional title (then use append)
177 short wxMenu::s_macNextMenuId
= 2 ;
185 wxMacBuildMenuString( label
, NULL
, NULL
, m_title
, false );
186 m_macMenuId
= s_macNextMenuId
++;
187 wxCHECK_RET( s_macNextMenuId
< 236 , "menu ids > 235 cannot be used for submenus on mac" );
188 m_hMenu
= ::NewMenu(m_macMenuId
, label
);
192 wxLogLastError("CreatePopupMenu");
195 // if we have a title, insert it in the beginning of the menu
198 Append(idMenuTitle
, m_title
) ;
206 ::DisposeMenu(m_hMenu
);
210 WX_CLEAR_ARRAY(m_accels
);
211 #endif // wxUSE_ACCEL
216 // not available on the mac platform
221 int wxMenu::FindAccel(int id
) const
223 size_t n
, count
= m_accels
.GetCount();
224 for ( n
= 0; n
< count
; n
++ )
226 if ( m_accels
[n
]->m_command
== id
)
233 void wxMenu::UpdateAccel(wxMenuItem
*item
)
235 // find the (new) accel for this item
236 wxAcceleratorEntry
*accel
= wxGetAccelFromString(item
->GetText());
238 accel
->m_command
= item
->GetId();
241 int n
= FindAccel(item
->GetId());
242 if ( n
== wxNOT_FOUND
)
244 // no old, add new if any
248 return; // skipping RebuildAccelTable() below
252 // replace old with new or just remove the old one if no new
262 m_menuBar
->RebuildAccelTable();
266 #endif // wxUSE_ACCEL
268 // function appends a new item or submenu to the menu
269 // append a new item or submenu to the menu
270 bool wxMenu::DoInsertOrAppend(wxMenuItem
*pItem
, size_t pos
)
272 wxASSERT_MSG( pItem
!= NULL
, "can't append NULL item to the menu" );
275 #endif // wxUSE_ACCEL
277 if ( pItem
->IsSeparator() )
279 if ( pos
== (size_t)-1 )
281 MacAppendMenu(m_hMenu
, "\p-");
285 MacInsertMenuItem(m_hMenu
, "\p-" , pos
);
290 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
291 if ( pSubMenu
!= NULL
)
294 wxASSERT_MSG( pSubMenu
->m_hMenu
!= NULL
, "invalid submenu added");
295 pSubMenu
->m_menuParent
= this ;
296 wxMacBuildMenuString( label
, NULL
, NULL
, pItem
->GetText() ,false);
298 // hardcoded adding of the submenu combination for mac
300 int theEnd
= label
[0] + 1;
302 theEnd
= 251; // mac allows only 255 characters
303 label
[theEnd
++] = '/';
304 label
[theEnd
++] = hMenuCmd
;
305 label
[theEnd
++] = '!';
306 label
[theEnd
++] = pSubMenu
->m_macMenuId
;
307 label
[theEnd
] = 0x00;
310 if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar
)
312 ::InsertMenu( pSubMenu
->m_hMenu
, -1 ) ;
315 if ( pos
== (size_t)-1 )
317 MacAppendMenu(m_hMenu
, label
);
321 MacInsertMenuItem(m_hMenu
, label
, pos
);
327 wxMacBuildMenuString( label
, NULL
, NULL
, pItem
->GetText(), pItem
->GetId() == wxApp::s_macAboutMenuItemId
);
330 // we cannot add empty menus on mac
334 if ( pos
== (size_t)-1 )
336 MacAppendMenu(m_hMenu
, label
);
340 MacInsertMenuItem(m_hMenu
, label
, pos
);
342 if ( pItem
->GetId() == idMenuTitle
)
344 if ( pos
== (size_t)-1 )
346 UMADisableMenuItem( m_hMenu
, CountMItems( m_hMenu
) ) ;
350 UMADisableMenuItem( m_hMenu
, pos
+ 1 ) ;
355 // if we're already attached to the menubar, we must update it
358 m_menuBar
->Refresh();
363 bool wxMenu::DoAppend(wxMenuItem
*item
)
365 return wxMenuBase::DoAppend(item
) && DoInsertOrAppend(item
);
368 bool wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
370 return wxMenuBase::DoInsert(pos
, item
) && DoInsertOrAppend(item
, pos
);
373 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
375 // we need to find the items position in the child list
377 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
378 for ( pos
= 0; node
; pos
++ )
380 if ( node
->GetData() == item
)
383 node
= node
->GetNext();
386 // DoRemove() (unlike Remove) can only be called for existing item!
387 wxCHECK_MSG( node
, NULL
, wxT("bug in wxMenu::Remove logic") );
390 // remove the corresponding accel from the accel table
391 int n
= FindAccel(item
->GetId());
392 if ( n
!= wxNOT_FOUND
)
398 //else: this item doesn't have an accel, nothing to do
399 #endif // wxUSE_ACCEL
401 ::DeleteMenuItem( m_hMenu
, pos
+ 1);
405 // otherwise, the chane won't be visible
406 m_menuBar
->Refresh();
409 // and from internal data structures
410 return wxMenuBase::DoRemove(item
);
413 // ---------------------------------------------------------------------------
414 // accelerator helpers
415 // ---------------------------------------------------------------------------
419 // create the wxAcceleratorEntries for our accels and put them into provided
420 // array - return the number of accels we have
421 size_t wxMenu::CopyAccels(wxAcceleratorEntry
*accels
) const
423 size_t count
= GetAccelCount();
424 for ( size_t n
= 0; n
< count
; n
++ )
426 *accels
++ = *m_accels
[n
];
432 #endif // wxUSE_ACCEL
434 void wxMenu::SetTitle(const wxString
& label
)
438 wxMacBuildMenuString( title
, NULL
, NULL
, label
, false );
439 UMASetMenuTitle( m_hMenu
, title
) ;
444 void wxMenu::SetLabel(int id, const wxString& label)
448 wxMenuItem *item = FindItemForId(id) ;
452 index = MacGetIndexFromItem( item ) ;
456 if (item->GetSubMenu()==NULL)
458 wxMacBuildMenuString( maclabel , NULL , NULL , label , false );
459 ::SetMenuItemText( m_hMenu , index , maclabel ) ;
463 wxMacBuildMenuString( maclabel , NULL , NULL , label , false );
464 ::SetMenuItemText( m_hMenu , index , maclabel ) ;
466 item->SetName(label);
469 wxString wxMenu::GetLabel(int Id) const
471 wxMenuItem *pItem = FindItemForId(Id) ;
472 return pItem->GetName() ;
475 // Finds the item id matching the given string, -1 if not found.
476 int wxMenu::FindItem (const wxString& itemString) const
480 wxStripMenuCodes ((char *)(const char *)itemString, buf1);
482 for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
484 wxMenuItem *item = (wxMenuItem *) node->Data ();
485 if (item->GetSubMenu())
487 int ans = item->GetSubMenu()->FindItem(itemString);
491 if ( !item->IsSeparator() )
493 wxStripMenuCodes((char *)item->GetName().c_str(), buf2);
494 if (strcmp(buf1, buf2) == 0)
495 return item->GetId();
502 wxMenuItem *wxMenu::FindItemForId(int itemId, wxMenu ** itemMenu) const
506 for (wxNode * node = m_menuItems.First (); node; node = node->Next ())
508 wxMenuItem *item = (wxMenuItem *) node->Data ();
510 if (item->GetId() == itemId)
513 *itemMenu = (wxMenu *) this;
517 if (item->GetSubMenu())
519 wxMenuItem *ans = item->GetSubMenu()->FindItemForId (itemId, itemMenu);
530 void wxMenu::SetHelpString(int itemId, const wxString& helpString)
532 wxMenuItem *item = FindItemForId (itemId);
534 item->SetHelp(helpString);
537 wxString wxMenu::GetHelpString (int itemId) const
539 wxMenuItem *item = FindItemForId (itemId);
541 return (item == NULL) ? str : item->GetHelp();
545 bool wxMenu::ProcessCommand(wxCommandEvent
& event
)
547 bool processed
= FALSE
;
549 #if WXWIN_COMPATIBILITY
553 (void)(*(m_callback
))(*this, event
);
556 #endif WXWIN_COMPATIBILITY
558 // Try the menu's event handler
559 if ( !processed
&& GetEventHandler())
561 processed
= GetEventHandler()->ProcessEvent(event
);
564 // Try the window the menu was popped up from (and up through the
566 wxWindow
*win
= GetInvokingWindow();
567 if ( !processed
&& win
)
568 processed
= win
->GetEventHandler()->ProcessEvent(event
);
574 // ---------------------------------------------------------------------------
576 // ---------------------------------------------------------------------------
578 void wxMenu::Attach(wxMenuBar
*menubar
)
580 // menu can be in at most one menubar because otherwise they would both
581 // delete the menu pointer
582 wxASSERT_MSG( !m_menuBar
, wxT("menu belongs to 2 menubars, expect a crash") );
587 void wxMenu::Detach()
589 wxASSERT_MSG( m_menuBar
, wxT("can't detach menu if it's not attached") );
594 wxWindow
*wxMenu::GetWindow() const
596 if ( m_invokingWindow
!= NULL
)
597 return m_invokingWindow
;
598 else if ( m_menuBar
!= NULL
)
599 return m_menuBar
->GetFrame();
604 // helper functions returning the mac menu position for a certain item, note that this is
605 // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0
607 int wxMenu::MacGetIndexFromId( int id
)
610 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
611 for ( pos
= 0; node
; pos
++ )
613 if ( node
->GetData()->GetId() == id
)
616 node
= node
->GetNext();
625 int wxMenu::MacGetIndexFromItem( wxMenuItem
*pItem
)
628 wxMenuItemList::Node
*node
= GetMenuItems().GetFirst();
629 for ( pos
= 0; node
; pos
++ )
631 if ( node
->GetData() == pItem
)
634 node
= node
->GetNext();
643 void wxMenu::MacEnableMenu( bool bDoEnable
)
646 UMAEnableMenuItem( m_hMenu
, 0 ) ;
648 UMADisableMenuItem( m_hMenu
, 0 ) ;
653 bool wxMenu::MacMenuSelect( wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
658 if ( m_macMenuId
== macMenuId
)
660 node
= GetMenuItems().Nth(macMenuItemNum
-1);
663 wxMenuItem
*pItem
= (wxMenuItem
*)node
->Data();
665 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
666 event
.m_timeStamp
= when
;
667 event
.SetEventObject(handler
);
668 event
.SetInt( pItem
->GetId() );
670 bool processed
= false ;
672 #if WXWIN_COMPATIBILITY
676 (void) (*(m_callback
)) (*this, event
);
680 // Try the menu's event handler
681 if ( !processed
&& handler
)
683 processed
= handler
->ProcessEvent(event
);
686 // Try the window the menu was popped up from (and up
687 // through the hierarchy)
688 if ( !processed
&& GetInvokingWindow())
689 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
694 else if ( macMenuId
== kHMHelpMenuID
)
696 int menuItem
= formerHelpMenuItems
;
697 for (pos
= 0, node
= GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
699 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
701 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
702 if ( pSubMenu
!= NULL
)
707 if ( pItem
->GetId() != wxApp::s_macAboutMenuItemId
)
710 if ( menuItem
== macMenuItemNum
)
712 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
713 event
.m_timeStamp
= when
;
714 event
.SetEventObject(handler
);
715 event
.SetInt( pItem
->GetId() );
717 bool processed
= false ;
718 #if WXWIN_COMPATIBILITY
722 (void) (*(m_callback
)) (*this, event
);
726 // Try the menu's event handler
727 if ( !processed
&& handler
)
729 processed
= handler
->ProcessEvent(event
);
732 // Try the window the menu was popped up from (and up
733 // through the hierarchy)
734 if ( !processed
&& GetInvokingWindow())
735 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
743 for (pos
= 0, node
= GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
745 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
747 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
748 if ( pSubMenu
!= NULL
)
750 if ( pSubMenu
->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
762 Mac Implementation note :
764 The Mac has only one global menubar, so we attempt to install the currently
765 active menubar from a frame, we currently don't take into account mdi-frames
766 which would ask for menu-merging
768 Secondly there is no mac api for changing a menubar that is not the current
769 menubar, so we have to wait for preparing the actual menubar until the
770 wxMenubar is to be used
772 We can in subsequent versions use MacInstallMenuBar to provide some sort of
773 auto-merge for MDI in case this will be necessary
777 wxMenuBar
* wxMenuBar::s_macInstalledMenuBar
= NULL
;
779 void wxMenuBar::Init()
781 m_eventHandler
= this;
782 m_menuBarFrame
= NULL
;
785 wxMenuBar::wxMenuBar()
790 wxMenuBar::wxMenuBar( long WXUNUSED(style
) )
796 wxMenuBar::wxMenuBar(int count
, wxMenu
*menus
[], const wxString titles
[])
800 m_titles
.Alloc(count
);
802 for ( int i
= 0; i
< count
; i
++ )
804 m_menus
.Append(menus
[i
]);
805 m_titles
.Add(titles
[i
]);
807 menus
[i
]->Attach(this);
811 wxMenuBar::~wxMenuBar()
813 if (s_macInstalledMenuBar
== this)
816 s_macInstalledMenuBar
= NULL
;
821 void wxMenuBar::Refresh()
823 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
830 void wxMenuBar::RebuildAccelTable()
832 // merge the accelerators of all menus into one accel table
833 size_t nAccelCount
= 0;
834 size_t i
, count
= GetMenuCount();
835 for ( i
= 0; i
< count
; i
++ )
837 nAccelCount
+= m_menus
[i
]->GetAccelCount();
842 wxAcceleratorEntry
*accelEntries
= new wxAcceleratorEntry
[nAccelCount
];
845 for ( i
= 0; i
< count
; i
++ )
847 nAccelCount
+= m_menus
[i
]->CopyAccels(&accelEntries
[nAccelCount
]);
850 m_accelTable
= wxAcceleratorTable(nAccelCount
, accelEntries
);
852 delete [] accelEntries
;
856 #endif // wxUSE_ACCEL
859 void wxMenuBar::MacInstallMenuBar()
861 Handle menubar
= ::GetNewMBar( kwxMacMenuBarResource
) ;
863 wxCHECK_RET( menubar
!= NULL
, "can't read MBAR resource" );
864 ::SetMenuBar( menubar
) ;
865 ::DisposeHandle( menubar
) ;
867 MenuHandle menu
= ::GetMenuHandle( kwxMacAppleMenuId
) ;
868 ::AppendResMenu(menu
, 'DRVR');
870 for (int i
= 0; i
< m_menus
.GetCount(); i
++)
876 wxMenu
* menu
= m_menus
[i
] , *subMenu
= NULL
;
879 if( m_titles
[i
] == "?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
)
881 MenuHandle mh
= NULL
;
882 if ( HMGetHelpMenuHandle( &mh
) != noErr
)
886 if ( formerHelpMenuItems
== 0 )
889 formerHelpMenuItems
= CountMenuItems( mh
) ;
892 for (pos
= 0 , node
= menu
->GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
894 item
= (wxMenuItem
*)node
->Data();
895 subMenu
= item
->GetSubMenu() ;
898 // we don't support hierarchical menus in the help menu yet
903 wxMacBuildMenuString( label
, NULL
, NULL
, item
->GetText(), item
->GetId() != wxApp::s_macAboutMenuItemId
); // no shortcut in about menu
906 // we cannot add empty menus on mac
910 if ( item
->GetId() == wxApp::s_macAboutMenuItemId
)
912 ::SetMenuItemText( GetMenuHandle( kwxMacAppleMenuId
) , 1 , label
);
913 // ::EnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 );
914 ::EnableItem( GetMenuHandle( kwxMacAppleMenuId
) , 1 );
919 ::AppendMenu(mh
, label
);
926 wxMacBuildMenuString( label
, NULL
, NULL
, m_titles
[i
] , false );
927 UMASetMenuTitle( menu
->GetHMenu() , label
) ;
928 for (pos
= 0, node
= menu
->GetMenuItems().First(); node
; node
= node
->Next(), pos
++)
930 item
= (wxMenuItem
*)node
->Data();
931 subMenu
= item
->GetSubMenu() ;
934 ::InsertMenu( subMenu
->GetHMenu() , -1 ) ;
937 ::InsertMenu(m_menus
[i
]->GetHMenu(), 0);
942 s_macInstalledMenuBar
= this;
945 void wxMenuBar::EnableTop(size_t pos
, bool enable
)
947 wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
948 m_menus
[pos
]->MacEnableMenu( enable
) ;
952 void wxMenuBar::SetLabelTop(size_t pos
, const wxString
& label
)
954 wxCHECK_RET( pos
< GetMenuCount(), wxT("invalid menu index") );
956 m_titles
[pos
] = label
;
963 m_menus
[pos
]->SetTitle( label
) ;
964 if (wxMenuBar::s_macInstalledMenuBar
== this) // are we currently installed ?
966 ::SetMenuBar( GetMenuBar() ) ;
971 wxString
wxMenuBar::GetLabelTop(size_t pos
) const
973 wxCHECK_MSG( pos
< GetMenuCount(), wxEmptyString
,
974 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
976 return m_titles
[pos
];
979 int wxMenuBar::FindMenu(const wxString
& title
)
981 wxString menuTitle
= wxStripMenuCodes(title
);
983 size_t count
= GetMenuCount();
984 for ( size_t i
= 0; i
< count
; i
++ )
986 wxString title
= wxStripMenuCodes(m_titles
[i
]);
987 if ( menuTitle
== title
)
996 // ---------------------------------------------------------------------------
997 // wxMenuBar construction
998 // ---------------------------------------------------------------------------
1000 // ---------------------------------------------------------------------------
1001 // wxMenuBar construction
1002 // ---------------------------------------------------------------------------
1004 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
1006 wxMenu
*menuOld
= wxMenuBarBase::Replace(pos
, menu
, title
);
1009 m_titles
[pos
] = title
;
1013 if (s_macInstalledMenuBar
== this)
1015 ::DeleteMenu( menuOld
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
1018 wxMacBuildMenuString( label
, NULL
, NULL
, title
, false );
1019 UMASetMenuTitle( menu
->GetHMenu() , label
) ;
1020 if ( pos
== m_menus
.GetCount() - 1)
1022 ::InsertMenu( menu
->GetHMenu() , 0 ) ;
1026 ::InsertMenu( menu
->GetHMenu() , m_menus
[pos
+1]->MacGetMenuId() ) ;
1033 if ( menuOld
->HasAccels() || menu
->HasAccels() )
1035 // need to rebuild accell table
1036 RebuildAccelTable();
1038 #endif // wxUSE_ACCEL
1046 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
1048 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
1051 m_titles
.Insert(title
, pos
);
1057 if ( pos
== (size_t) -1 )
1059 ::InsertMenu( menu
->GetHMenu() , 0 ) ;
1063 ::InsertMenu( menu
->GetHMenu() , m_menus
[pos
+1]->MacGetMenuId() ) ;
1067 if ( menu
->HasAccels() )
1069 // need to rebuild accell table
1070 RebuildAccelTable();
1072 #endif // wxUSE_ACCEL
1080 void wxMenuBar::MacMenuSelect(wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
1082 // first scan fast for direct commands, i.e. menus which have these commands directly in their own list
1084 if ( macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
== 1 )
1086 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, wxApp::s_macAboutMenuItemId
);
1087 event
.m_timeStamp
= when
;
1088 event
.SetEventObject(handler
);
1089 event
.SetInt( wxApp::s_macAboutMenuItemId
);
1090 handler
->ProcessEvent(event
);
1094 for (int i
= 0; i
< m_menus
.GetCount() ; i
++)
1096 if ( m_menus
[i
]->MacGetMenuId() == macMenuId
||
1097 ( macMenuId
== kHMHelpMenuID
&& ( m_titles
[i
] == "?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
) )
1100 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
1104 //TODO flag this as an error since it must contain the item
1110 for (int i
= 0; i
< m_menus
.GetCount(); i
++)
1112 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
1120 wxMenu
*wxMenuBar::Remove(size_t pos
)
1122 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
1128 if (s_macInstalledMenuBar
== this)
1130 ::DeleteMenu( menu
->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
1136 if ( menu
->HasAccels() )
1138 // need to rebuild accell table
1139 RebuildAccelTable();
1141 #endif // wxUSE_ACCEL
1146 m_titles
.Remove(pos
);
1151 bool wxMenuBar::Append(wxMenu
*menu
, const wxString
& title
)
1153 WXHMENU submenu
= menu
? menu
->GetHMenu() : 0;
1154 wxCHECK_MSG( submenu
, FALSE
, wxT("can't append invalid menu to menubar") );
1156 if ( !wxMenuBarBase::Append(menu
, title
) )
1161 m_titles
.Add(title
);
1165 if (s_macInstalledMenuBar
== this)
1167 ::InsertMenu( menu
->GetHMenu() , 0 ) ;
1171 if ( menu
->HasAccels() )
1173 // need to rebuild accell table
1174 RebuildAccelTable();
1176 #endif // wxUSE_ACCEL
1184 // ---------------------------------------------------------------------------
1185 // wxMenuBar searching for menu items
1186 // ---------------------------------------------------------------------------
1188 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
1189 int wxMenuBar::FindMenuItem(const wxString
& menuString
,
1190 const wxString
& itemString
) const
1192 wxString menuLabel
= wxStripMenuCodes(menuString
);
1193 size_t count
= GetMenuCount();
1194 for ( size_t i
= 0; i
< count
; i
++ )
1196 wxString title
= wxStripMenuCodes(m_titles
[i
]);
1197 if ( menuString
== title
)
1198 return m_menus
[i
]->FindItem(itemString
);
1204 wxMenuItem
*wxMenuBar::FindItem(int id
, wxMenu
**itemMenu
) const
1209 wxMenuItem
*item
= NULL
;
1210 size_t count
= GetMenuCount();
1211 for ( size_t i
= 0; !item
&& (i
< count
); i
++ )
1213 item
= m_menus
[i
]->FindItem(id
, itemMenu
);