-
- m_pMenu = menu;
- menu->SetEventHandler(this);
-
- //note to self - a MenuRef IS A MenuHandle
- MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu());
-
- //When we call SetEventParameter it will decrement
- //the reference count of the menu - we need to make
- //sure it stays around in the wxMenu class here
- RetainMenu(hMenu);
-
- //set the actual dock menu
- OSStatus err = SetEventParameter((EventRef) m_pEvent, kEventParamMenuRef,
- typeMenuRef, sizeof(MenuRef),
- &hMenu);
- wxASSERT(err == 0);
-
- return err == noErr;
+ m_pMenu = NULL;
+ }
+
+ //
+ // NB: Here we have to perform a deep copy of the menu,
+ // copying each and every menu item from menu to m_pMenu.
+ // Other implementations use wxWindow::PopupMenu here,
+ // which idle execution until the user selects something,
+ // but since the mac handles this internally, we can't -
+ // and have no way at all to idle it while the dock menu
+ // is being shown before menu goes out of scope (it may
+ // not be on the heap, and may expire right after this function
+ // is done - we need it to last until the carbon event is triggered -
+ // that's when the user right clicks).
+ //
+ // Also, since there is no equal (assignment) operator
+ // on either wxMenu or wxMenuItem, we have to do all the
+ // dirty work ourselves.
+ //
+
+ //Perform a deep copy of the menu
+ wxMenuItemList& theList = menu->GetMenuItems();
+ wxMenuItemList::compatibility_iterator theNode = theList.GetFirst();
+
+ //create the main menu
+ m_pMenu = new wxMenu(menu->GetTitle());
+
+ while(theNode != NULL)
+ {
+ wxMenuItem* theItem = theNode->GetData();
+ m_pMenu->Append(new wxMenuItem( m_pMenu, //parent menu
+ theItem->GetId(), //id
+ theItem->GetText(), //text label
+ theItem->GetHelp(), //status bar help string
+ theItem->GetKind(), //menu flags - checkable, seperator, etc.
+ theItem->GetSubMenu() //submenu
+ ));
+ theNode = theNode->GetNext();
+ }
+
+ m_pMenu->SetEventHandler(this);
+ return true;