+void wxInsertMenuItemsInMenu(wxMenu* menu, MenuRef wm, MenuItemIndex insertAfter)
+{
+ wxMenuItemList::compatibility_iterator node;
+ wxMenuItem *item;
+ wxMenu *subMenu = NULL ;
+ bool newItems = false;
+
+ for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext())
+ {
+ item = (wxMenuItem *)node->GetData();
+ subMenu = item->GetSubMenu() ;
+ if (subMenu)
+ {
+ wxInsertMenuItemsInMenu(subMenu, (MenuRef)subMenu->GetHMenu(), 0);
+ }
+ if ( item->IsSeparator() )
+ {
+ if ( wm && newItems)
+ InsertMenuItemTextWithCFString( wm,
+ CFSTR(""), insertAfter, kMenuItemAttrSeparator, 0);
+
+ newItems = false;
+ }
+ else
+ {
+ wxAcceleratorEntry*
+ entry = wxAcceleratorEntry::Create( item->GetText() ) ;
+
+ MenuItemIndex winListPos = (MenuItemIndex)-1;
+ OSStatus err = GetIndMenuItemWithCommandID(wm,
+ wxIdToMacCommand ( item->GetId() ), 1, NULL, &winListPos);
+
+ if ( wm && err == menuItemNotFoundErr )
+ {
+ // NB: the only way to determine whether or not we should add
+ // a separator is to know if we've added menu items to the menu
+ // before the separator.
+ newItems = true;
+ UMAInsertMenuItem(wm, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding(), insertAfter, entry);
+ SetMenuItemCommandID( wm , insertAfter+1 , wxIdToMacCommand ( item->GetId() ) ) ;
+ SetMenuItemRefCon( wm , insertAfter+1 , (URefCon) item ) ;
+ }
+
+ delete entry ;
+ }
+ }
+}