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 static 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
, 5) == 0)
122 inItemName
= inItemName
+ 5;
123 macShortCut
= *inItemName
;
125 else if (strncmp("Alt+", inItemName
, 4) == 0)
127 inItemName
= inItemName
+ 4;
128 macModifiers
|= kMenuOptionModifier
;
129 macShortCut
= *inItemName
;
131 else if (strncmp("Shift+", inItemName
, 6) == 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 ;
181 wxMenu::wxMenu(const wxString
& title
, const wxFunction func
)
185 m_eventHandler
= this;
188 m_pInvokingWindow
= NULL
;
189 m_clientData
= (void*) NULL
;
192 Append(idMenuTitle
, m_title
) ;
199 wxMacBuildMenuString( label
, NULL
, NULL
, title
, false );
200 m_macMenuId
= s_macNextMenuId
++;
201 wxCHECK_RET( s_macNextMenuId
< 236 , "menu ids > 235 cannot be used for submenus on mac" );
202 m_macMenuHandle
= ::NewMenu(m_macMenuId
, label
);
203 m_macMenuEnabled
= true ;
206 // The wxWindow destructor will take care of deleting the submenus.
209 wxNode
*node
= m_menuItems
.First();
212 wxMenuItem
*item
= (wxMenuItem
*)node
->Data();
214 // Delete child menus.
215 // Beware: they must not be appended to children list!!!
216 // (because order of delete is significant)
217 if (item
->GetSubMenu())
218 item
->DeleteSubMenu();
220 wxNode
*next
= node
->Next();
226 ::DisposeMenu(m_macMenuHandle
);
231 // not available on the mac platform
234 // function appends a new item or submenu to the menu
235 void wxMenu::Append(wxMenuItem
*pItem
)
237 wxCHECK_RET( pItem
!= NULL
, "can't append NULL item to the menu" );
239 m_menuItems
.Append(pItem
);
241 if ( pItem
->IsSeparator() )
243 MacAppendMenu(m_macMenuHandle
, "\p-");
247 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
248 if ( pSubMenu
!= NULL
)
251 wxCHECK_RET( pSubMenu
->m_macMenuHandle
!= NULL
, "invalid submenu added");
252 pSubMenu
->m_parent
= this ;
253 wxMacBuildMenuString( label
, NULL
, NULL
, pItem
->GetName() ,false);
255 // hardcoded adding of the submenu combination for mac
257 int theEnd
= label
[0] + 1;
259 theEnd
= 251; // mac allows only 255 characters
260 label
[theEnd
++] = '/';
261 label
[theEnd
++] = hMenuCmd
;
262 label
[theEnd
++] = '!';
263 label
[theEnd
++] = pSubMenu
->m_macMenuId
;
264 label
[theEnd
] = 0x00;
267 if (wxMenuBar::s_macInstalledMenuBar
== m_menuBar
)
269 ::InsertMenu( pSubMenu
->m_macMenuHandle
, -1 ) ;
272 ::AppendMenu(m_macMenuHandle
, label
);
277 wxMacBuildMenuString( label
, NULL
, NULL
, pItem
->GetName(), pItem
->GetId() == wxApp::s_macAboutMenuItemId
);
280 // we cannot add empty menus on mac
284 ::AppendMenu(m_macMenuHandle
, label
);
285 if ( pItem
->GetId() == idMenuTitle
)
287 UMADisableMenuItem( m_macMenuHandle
, CountMItems( m_macMenuHandle
) ) ;
295 void wxMenu::AppendSeparator()
297 Append(new wxMenuItem(this, ID_SEPARATOR
));
301 void wxMenu::Append(int Id
, const wxString
& label
, wxMenu
*SubMenu
,
302 const wxString
& helpString
)
304 Append(new wxMenuItem(this, Id
, label
, helpString
, FALSE
, SubMenu
));
307 // Ordinary menu item
308 void wxMenu::Append(int Id
, const wxString
& label
,
309 const wxString
& helpString
, bool checkable
)
311 // 'checkable' parameter is useless for Windows.
312 Append(new wxMenuItem(this, Id
, label
, helpString
, checkable
));
315 void wxMenu::Delete(int id
)
321 for (pos
= 0, node
= m_menuItems
.First(); node
; node
= node
->Next(), pos
++) {
322 item
= (wxMenuItem
*)node
->Data();
323 if (item
->GetId() == id
)
330 int index
= pos
+ 1 ;
335 wxMenu
*pSubMenu
= item
->GetSubMenu();
336 if ( pSubMenu
!= NULL
)
338 ::DeleteMenuItem( m_macMenuHandle
, index
);
339 pSubMenu
->m_parent
= NULL
;
340 // TODO: Why isn't subMenu deleted here???
341 // Will put this in for now. Assuming this is supposed
342 // to delete the menu, not just remove it.
343 item
->DeleteSubMenu();
347 ::DeleteMenuItem( m_macMenuHandle
, index
);
350 m_menuItems
.DeleteNode(node
);
351 // TODO shouldn't we do this ? \8e_m_noItems--;
355 void wxMenu::Enable(int Id
, bool Flag
)
357 wxMenuItem
*item
= FindItemForId(Id
);
358 wxCHECK_RET( item
!= NULL
, "can't enable non-existing menu item" );
363 bool wxMenu::Enabled(int Id
) const
365 wxMenuItem
*item
= FindItemForId(Id
);
366 wxCHECK( item
!= NULL
, FALSE
);
368 return item
->IsEnabled();
371 void wxMenu::Check(int Id
, bool Flag
)
373 wxMenuItem
*item
= FindItemForId(Id
);
374 wxCHECK_RET( item
!= NULL
, "can't get status of non-existing menu item" );
379 bool wxMenu::Checked(int Id
) const
381 wxMenuItem
*item
= FindItemForId(Id
);
382 wxCHECK( item
!= NULL
, FALSE
);
384 return item
->IsChecked();
387 void wxMenu::SetTitle(const wxString
& label
)
391 wxMacBuildMenuString( title
, NULL
, NULL
, label
, false );
392 UMASetMenuTitle( m_macMenuHandle
, title
) ;
393 if (wxMenuBar::s_macInstalledMenuBar
== m_menuBar
) // are we currently installed ?
395 ::SetMenuBar( GetMenuBar() ) ;
398 // TODO:for submenus -> their parent item text must be corrected
401 const wxString
wxMenu::GetTitle() const
406 void wxMenu::SetLabel(int id
, const wxString
& label
)
410 wxMenuItem
*item
= FindItemForId(id
) ;
414 index
= MacGetIndexFromItem( item
) ;
418 if (item
->GetSubMenu()==NULL
)
420 wxMacBuildMenuString( maclabel
, NULL
, NULL
, label
, false );
421 ::SetMenuItemText( m_macMenuHandle
, index
, maclabel
) ;
425 wxMacBuildMenuString( maclabel
, NULL
, NULL
, label
, false );
426 ::SetMenuItemText( m_macMenuHandle
, index
, maclabel
) ;
428 item
->SetName(label
);
431 wxString
wxMenu::GetLabel(int Id
) const
433 wxMenuItem
*pItem
= FindItemForId(Id
) ;
434 return pItem
->GetName() ;
437 // Finds the item id matching the given string, -1 if not found.
438 int wxMenu::FindItem (const wxString
& itemString
) const
442 wxStripMenuCodes ((char *)(const char *)itemString
, buf1
);
444 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
446 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
447 if (item
->GetSubMenu())
449 int ans
= item
->GetSubMenu()->FindItem(itemString
);
453 if ( !item
->IsSeparator() )
455 wxStripMenuCodes((char *)item
->GetName().c_str(), buf2
);
456 if (strcmp(buf1
, buf2
) == 0)
457 return item
->GetId();
464 wxMenuItem
*wxMenu::FindItemForId(int itemId
, wxMenu
** itemMenu
) const
468 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
470 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
472 if (item
->GetId() == itemId
)
475 *itemMenu
= (wxMenu
*) this;
479 if (item
->GetSubMenu())
481 wxMenuItem
*ans
= item
->GetSubMenu()->FindItemForId (itemId
, itemMenu
);
492 void wxMenu::SetHelpString(int itemId
, const wxString
& helpString
)
494 wxMenuItem
*item
= FindItemForId (itemId
);
496 item
->SetHelp(helpString
);
499 wxString
wxMenu::GetHelpString (int itemId
) const
501 wxMenuItem
*item
= FindItemForId (itemId
);
503 return (item
== NULL
) ? str
: item
->GetHelp();
506 void wxMenu::ProcessCommand(wxCommandEvent
& event
)
508 bool processed
= FALSE
;
513 (void) (*(m_callback
)) (*this, event
);
517 // Try the menu's event handler
518 if ( !processed
&& GetEventHandler())
520 processed
= GetEventHandler()->ProcessEvent(event
);
523 // Try the window the menu was popped up from (and up
524 // through the hierarchy)
525 if ( !processed
&& GetInvokingWindow())
526 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
529 bool wxWindow::PopupMenu(wxMenu
*menu
, int x
, int y
)
531 menu
->SetInvokingWindow(this);
532 ClientToScreen( &x
, &y
) ;
534 ::InsertMenu( menu
->m_macMenuHandle
, -1 ) ;
535 long menuResult
= ::PopUpMenuSelect(menu
->m_macMenuHandle
,y
,x
, 0) ;
536 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
537 ::DeleteMenu( menu
->m_macMenuId
) ;
538 menu
->SetInvokingWindow(NULL
);
543 // helper functions returning the mac menu position for a certain item, note that this is
544 // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0
546 int wxMenu::MacGetIndexFromId( int id
)
552 for (pos
= 0, node
= m_menuItems
.First(); node
; node
= node
->Next(), pos
++)
554 item
= (wxMenuItem
*)node
->Data();
555 if (item
->GetId() == id
)
565 int wxMenu::MacGetIndexFromItem( wxMenuItem
*pItem
)
570 for (pos
= 0, node
= m_menuItems
.First(); node
; node
= node
->Next(), pos
++)
572 if ((wxMenuItem
*)node
->Data() == pItem
)
582 void wxMenu::MacEnableMenu( bool bDoEnable
)
584 m_macMenuEnabled
= bDoEnable
;
586 UMAEnableMenuItem( m_macMenuHandle
, 0 ) ;
588 UMADisableMenuItem( m_macMenuHandle
, 0 ) ;
593 bool wxMenu::MacMenuSelect( wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
598 if ( m_macMenuId
== macMenuId
)
600 node
= m_menuItems
.Nth(macMenuItemNum
-1);
603 wxMenuItem
*pItem
= (wxMenuItem
*)node
->Data();
605 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
606 event
.m_timeStamp
= when
;
607 event
.SetEventObject(handler
);
608 event
.SetInt( pItem
->GetId() );
611 bool processed
= false ;
616 (void) (*(m_callback
)) (*this, event
);
620 // Try the menu's event handler
621 if ( !processed
&& handler
)
623 processed
= handler
->ProcessEvent(event
);
626 // Try the window the menu was popped up from (and up
627 // through the hierarchy)
628 if ( !processed
&& GetInvokingWindow())
629 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
634 else if ( macMenuId
== kHMHelpMenuID
)
636 int menuItem
= formerHelpMenuItems
;
637 for (pos
= 0, node
= m_menuItems
.First(); node
; node
= node
->Next(), pos
++)
639 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
641 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
642 if ( pSubMenu
!= NULL
)
647 if ( pItem
->GetId() != wxApp::s_macAboutMenuItemId
)
650 if ( menuItem
== macMenuItemNum
)
652 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, pItem
->GetId());
653 event
.m_timeStamp
= when
;
654 event
.SetEventObject(handler
);
655 event
.SetInt( pItem
->GetId() );
658 bool processed
= false ;
662 (void) (*(m_callback
)) (*this, event
);
666 // Try the menu's event handler
667 if ( !processed
&& handler
)
669 processed
= handler
->ProcessEvent(event
);
672 // Try the window the menu was popped up from (and up
673 // through the hierarchy)
674 if ( !processed
&& GetInvokingWindow())
675 processed
= GetInvokingWindow()->GetEventHandler()->ProcessEvent(event
);
684 for (pos
= 0, node
= m_menuItems
.First(); node
; node
= node
->Next(), pos
++)
686 wxMenuItem
* pItem
= (wxMenuItem
*) node
->Data() ;
688 wxMenu
*pSubMenu
= pItem
->GetSubMenu() ;
689 if ( pSubMenu
!= NULL
)
691 if ( pSubMenu
->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
703 Mac Implementation note :
705 The Mac has only one global menubar, so we attempt to install the currently
706 active menubar from a frame, we currently don't take into account mdi-frames
707 which would ask for menu-merging
709 Secondly there is no mac api for changing a menubar that is not the current
710 menubar, so we have to wait for preparing the actual menubar until the
711 wxMenubar is to be used
713 We can in subsequent versions use MacInstallMenuBar to provide some sort of
714 auto-merge for MDI in case this will be necessary
718 wxMenuBar
* wxMenuBar::s_macInstalledMenuBar
= NULL
;
720 wxMenuBar::wxMenuBar()
722 m_eventHandler
= this;
726 m_menuBarFrame
= NULL
;
729 wxMenuBar::wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[])
731 m_eventHandler
= this;
734 m_titles
= new wxString
[n
];
736 for ( i
= 0; i
< n
; i
++ )
737 m_titles
[i
] = titles
[i
];
738 m_menuBarFrame
= NULL
;
741 wxMenuBar::~wxMenuBar()
743 if (s_macInstalledMenuBar
== this)
746 s_macInstalledMenuBar
= NULL
;
750 for (i
= 0; i
< m_menuCount
; i
++)
759 void wxMenuBar::MacInstallMenuBar()
761 Handle menubar
= ::GetNewMBar( kwxMacMenuBarResource
) ;
763 wxCHECK_RET( menubar
!= NULL
, "can't read MBAR resource" );
764 ::SetMenuBar( menubar
) ;
765 ::DisposeHandle( menubar
) ;
767 MenuHandle menu
= ::GetMenuHandle( kwxMacAppleMenuId
) ;
768 ::AppendResMenu(menu
, 'DRVR');
770 for (int i
= 0; i
< m_menuCount
; i
++)
776 wxMenu
* menu
= m_menus
[i
] , *subMenu
= NULL
;
779 if( m_titles
[i
] == "?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
)
781 MenuHandle mh
= NULL
;
782 if ( HMGetHelpMenuHandle( &mh
) != noErr
)
786 if ( formerHelpMenuItems
== 0 )
789 formerHelpMenuItems
= CountMenuItems( mh
) ;
792 for (pos
= 0 , node
= menu
->m_menuItems
.First(); node
; node
= node
->Next(), pos
++)
794 item
= (wxMenuItem
*)node
->Data();
795 subMenu
= item
->GetSubMenu() ;
798 // we don't support hierarchical menus in the help menu yet
803 wxMacBuildMenuString( label
, NULL
, NULL
, item
->GetName(), item
->GetId() != wxApp::s_macAboutMenuItemId
); // no shortcut in about menu
806 // we cannot add empty menus on mac
810 if ( item
->GetId() == wxApp::s_macAboutMenuItemId
)
812 ::SetMenuItemText( GetMenuHandle( kwxMacAppleMenuId
) , 1 , label
);
813 // ::EnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 );
814 ::EnableItem( GetMenuHandle( kwxMacAppleMenuId
) , 1 );
819 ::AppendMenu(mh
, label
);
826 wxMacBuildMenuString( label
, NULL
, NULL
, m_titles
[i
] , false );
827 UMASetMenuTitle( menu
->m_macMenuHandle
, label
) ;
828 for (pos
= 0, node
= menu
->m_menuItems
.First(); node
; node
= node
->Next(), pos
++)
830 item
= (wxMenuItem
*)node
->Data();
831 subMenu
= item
->GetSubMenu() ;
834 ::InsertMenu( subMenu
->m_macMenuHandle
, -1 ) ;
837 ::InsertMenu(m_menus
[i
]->m_macMenuHandle
, 0);
842 s_macInstalledMenuBar
= this;
846 // Must only be used AFTER menu has been attached to frame,
847 // otherwise use individual menus to enable/disable items
848 void wxMenuBar::Enable(int id
, bool flag
)
850 wxMenu
*itemMenu
= NULL
;
851 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
855 item
->Enable( flag
) ;
858 void wxMenuBar::EnableTop(int pos
, bool flag
)
860 m_menus
[pos
]->MacEnableMenu( flag
) ;
863 // Must only be used AFTER menu has been attached to frame,
864 // otherwise use individual menus
865 void wxMenuBar::Check(int id
, bool flag
)
867 wxMenu
*itemMenu
= NULL
;
868 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
872 if (!item
->IsCheckable())
875 item
->Check( flag
) ;
878 bool wxMenuBar::Checked(int id
) const
880 wxMenu
*itemMenu
= NULL
;
881 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
885 if (!item
->IsCheckable())
888 return item
->IsChecked() ;
891 bool wxMenuBar::Enabled(int id
) const
893 wxMenu
*itemMenu
= NULL
;
894 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
898 if ( !item
->IsEnabled() )
901 if ( itemMenu
->m_macMenuEnabled
== false )
904 while( itemMenu
->m_parent
)
906 itemMenu
= (wxMenu
*) itemMenu
->m_parent
;
907 if ( itemMenu
->IsKindOf( CLASSINFO( wxMenu
) ) )
909 if ( itemMenu
->m_macMenuEnabled
== false )
918 void wxMenuBar::SetLabel(int id
, const wxString
& label
)
920 wxMenu
*itemMenu
= NULL
;
921 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
926 itemMenu
->SetLabel( id
, label
) ;
929 wxString
wxMenuBar::GetLabel(int id
) const
931 wxMenu
*itemMenu
= NULL
;
932 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
937 return itemMenu
->GetLabel( id
) ;
940 void wxMenuBar::SetLabelTop(int pos
, const wxString
& label
)
942 m_menus
[pos
]->SetTitle( label
) ;
945 wxString
wxMenuBar::GetLabelTop(int pos
) const
947 return m_menus
[pos
]->GetTitle() ;
950 bool wxMenuBar::OnDelete(wxMenu
*a_menu
, int pos
)
952 if (s_macInstalledMenuBar
== this)
954 ::DeleteMenu( a_menu
->m_macMenuId
/* m_menus[pos]->m_macMenuId */ ) ;
964 bool wxMenuBar::OnAppend(wxMenu
*a_menu
, const char *title
)
966 if (!a_menu
->m_macMenuHandle
)
969 if (s_macInstalledMenuBar
== this)
972 wxMacBuildMenuString( label
, NULL
, NULL
, title
, false );
973 UMASetMenuTitle( a_menu
->m_macMenuHandle
, label
) ;
974 ::InsertMenu( a_menu
->m_macMenuHandle
, 0 ) ;
984 void wxMenuBar::Append (wxMenu
* menu
, const wxString
& title
)
986 if (!OnAppend(menu
, title
))
990 wxMenu
**new_menus
= new wxMenu
*[m_menuCount
];
991 wxString
*new_titles
= new wxString
[m_menuCount
];
994 for (i
= 0; i
< m_menuCount
- 1; i
++)
996 new_menus
[i
] = m_menus
[i
];
998 new_titles
[i
] = m_titles
[i
];
1006 m_menus
= new_menus
;
1007 m_titles
= new_titles
;
1009 m_menus
[m_menuCount
- 1] = (wxMenu
*)menu
;
1010 m_titles
[m_menuCount
- 1] = title
;
1012 ((wxMenu
*)menu
)->m_menuBar
= (wxMenuBar
*) this;
1013 ((wxMenu
*)menu
)->SetParent(this);
1016 void wxMenuBar::Delete(wxMenu
* menu
, int i
)
1023 for (ii
= 0; ii
< m_menuCount
; ii
++)
1025 if (m_menus
[ii
] == menu
)
1028 if (ii
>= m_menuCount
)
1032 if (ii
< 0 || ii
>= m_menuCount
)
1037 if (!OnDelete(menu
, ii
))
1040 menu
->SetParent(NULL
);
1043 for (j
= ii
; j
< m_menuCount
; j
++)
1045 m_menus
[j
] = m_menus
[j
+ 1];
1046 m_titles
[j
] = m_titles
[j
+ 1];
1050 // Find the menu menuString, item itemString, and return the item id.
1051 // Returns -1 if none found.
1052 int wxMenuBar::FindMenuItem (const wxString
& menuString
, const wxString
& itemString
) const
1056 wxStripMenuCodes ((char *)(const char *)menuString
, buf1
);
1058 for (i
= 0; i
< m_menuCount
; i
++)
1060 wxStripMenuCodes ((char *)(const char *)m_titles
[i
], buf2
);
1061 if (strcmp (buf1
, buf2
) == 0)
1062 return m_menus
[i
]->FindItem (itemString
);
1067 wxMenuItem
*wxMenuBar::FindItemForId (int Id
, wxMenu
** itemMenu
) const
1072 wxMenuItem
*item
= NULL
;
1074 for (i
= 0; i
< m_menuCount
; i
++)
1075 if ((item
= m_menus
[i
]->FindItemForId (Id
, itemMenu
)))
1080 void wxMenuBar::SetHelpString (int Id
, const wxString
& helpString
)
1083 for (i
= 0; i
< m_menuCount
; i
++)
1085 if (m_menus
[i
]->FindItemForId (Id
))
1087 m_menus
[i
]->SetHelpString (Id
, helpString
);
1093 wxString
wxMenuBar::GetHelpString (int Id
) const
1096 for (i
= 0; i
< m_menuCount
; i
++)
1098 if (m_menus
[i
]->FindItemForId (Id
))
1099 return wxString(m_menus
[i
]->GetHelpString (Id
));
1101 return wxString("");
1104 void wxMenuBar::MacMenuSelect(wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
)
1106 // first scan fast for direct commands, i.e. menus which have these commands directly in their own list
1108 if ( macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
== 1 )
1110 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, wxApp::s_macAboutMenuItemId
);
1111 event
.m_timeStamp
= when
;
1112 event
.SetEventObject(handler
);
1113 event
.SetInt( wxApp::s_macAboutMenuItemId
);
1114 handler
->ProcessEvent(event
);
1118 for (int i
= 0; i
< m_menuCount
; i
++)
1120 if ( m_menus
[i
]->m_macMenuId
== macMenuId
||
1121 ( macMenuId
== kHMHelpMenuID
&& ( m_titles
[i
] == "?" || m_titles
[i
] == wxApp::s_macHelpMenuTitleName
) )
1124 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )
1128 //TODO flag this as an error since it must contain the item
1134 for (int i
= 0; i
< m_menuCount
; i
++)
1136 if ( m_menus
[i
]->MacMenuSelect( handler
, when
, macMenuId
, macMenuItemNum
) )