+void wxAssociateMenuWithMacMenu(MenuRef inMenuRef, wxMenu *menu) ;
+void wxAssociateMenuWithMacMenu(MenuRef inMenuRef, wxMenu *menu)
+{
+ // adding NULL MenuRef is (first) surely a result of an error and
+ // (secondly) breaks menu command processing
+ wxCHECK_RET( inMenuRef != (MenuRef) NULL, wxT("attempt to add a NULL MenuRef to menu list") );
+
+ wxWinMacMenuList[inMenuRef] = menu;
+}
+
+void wxRemoveMacMenuAssociation(wxMenu *menu) ;
+void wxRemoveMacMenuAssociation(wxMenu *menu)
+{
+ // iterate over all the elements in the class
+ MacMenuMap::iterator it;
+ for ( it = wxWinMacMenuList.begin(); it != wxWinMacMenuList.end(); ++it )
+ {
+ if ( it->second == menu )
+ {
+ wxWinMacMenuList.erase(it);
+ break;
+ }
+ }
+}
+
+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->GetItemLabel() ) ;
+
+ 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->GetItemLabel()) , wxFont::GetDefaultEncoding(), insertAfter, entry);
+ SetMenuItemCommandID( wm , insertAfter+1 , wxIdToMacCommand ( item->GetId() ) ) ;
+ SetMenuItemRefCon( wm , insertAfter+1 , (URefCon) item ) ;
+ }
+
+ delete entry ;
+ }
+ }
+}