//-----------------------------------------------------------------------------
// wxDeepCopyMenu
//
// Performs a top-to-bottom copy of the input menu and all of its
// submenus.
//
// This is mostly needed for 2.4 compatibility. However wxPython and others
// still use this way of setting the taskbarmenu.
//-----------------------------------------------------------------------------
wxMenu * wxDeepCopyMenu( wxMenu *menu )
{
    if (menu == NULL)
        return 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
    wxMenu *m_pMenu = new wxMenu(menu->GetTitle());

#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    while (theNode != NULL)
    {
        wxMenuItem* theItem = theNode->GetData();
        m_pMenu->Append(
            new wxMenuItem(
                m_pMenu, // parent menu
                theItem->GetId(), // id
                theItem->GetItemLabel(), // text label
                theItem->GetHelp(), // status bar help string
                theItem->GetKind(), // menu flags - checkable, separator, etc.
                wxDeepCopyMenu(theItem->GetSubMenu()) )); // submenu

        theNode = theNode->GetNext();
    }

    return m_pMenu;
}
Exemple #2
0
//-----------------------------------------------------------------------------
// wxDockTaskBarIcon::PopupMenu
//
// 2.4 and wxPython method that "pops of the menu in the taskbar".
//
// In reality because of the way the dock menu works in carbon
// we just save the menu, and if the user didn't override CreatePopupMenu
// return the menu passed here, thus sort of getting the same effect.
//-----------------------------------------------------------------------------
bool wxDockTaskBarIcon::PopupMenu(wxMenu *menu)
{
    wxASSERT(menu != NULL);

    delete m_pMenu;

    // start copy of menu
    m_pMenu = wxDeepCopyMenu(menu);

    // finish up
    m_pMenu->SetInvokingWindow(m_menuEventWindow);

    return true;
}