-// The wxWindow destructor will take care of deleting the submenus.
-wxMenu::~wxMenu(void)
-{
- if (m_hMenu)
- DestroyMenu((HMENU) m_hMenu);
- m_hMenu = 0;
-
- // Windows seems really bad on Menu de-allocation...
- // After many try, here is what I do: RemoveMenu() will ensure
- // that popup are "disconnected" from their parent; then call
- // delete method on each child (which in turn do a recursive job),
- // and finally, DestroyMenu()
- //
- // With that, BoundCheckers is happy, and no complaints...
-/*
- int N = 0 ;
- if (m_hMenu)
- N = GetMenuItemCount(m_hMenu);
- int i;
- for (i = N-1; i >= 0; i--)
- RemoveMenu(m_hMenu, i, MF_BYPOSITION);
-*/
-
- // How is deleting submenus in this loop any different from deleting
- // the submenus in the children list, via ~wxWindow ?
- // I'll reinstate this deletion for now and remove addition
- // from children list (which doesn't exist now)
- // Julian 1/3/97
- wxNode *node = m_menuItems.First();
- while (node)
- {
- wxMenuItem *item = (wxMenuItem *)node->Data();
-
- // Delete child menus.
- // Beware: they must not be appended to children list!!!
- // (because order of delete is significant)
- if (item->GetSubMenu())
- item->DeleteSubMenu();
-
- wxNode *next = node->Next();
- delete item;
- delete node;
- node = next;
- }
-/*
- if (m_hMenu)
- DestroyMenu(m_hMenu);
- m_hMenu = 0;
-*/
-}
-
-void wxMenu::Break(void)
-{
- m_doBreak = TRUE ;
-}
-
-// function appends a new item or submenu to the menu
-void wxMenu::Append(wxMenuItem *pItem)
-{
- wxCHECK_RET( pItem != NULL, "can't append NULL item to the menu" );
-
- m_menuItems.Append(pItem);
-
- UINT flags = 0;
-
- if ( m_doBreak ) {
- flags |= MF_MENUBREAK;
- m_doBreak = FALSE;
- }
-
- if ( pItem->IsSeparator() ) {
- flags |= MF_SEPARATOR;
- }
-
- // id is the numeric id for normal menu items and HMENU for submenus
- UINT id;
- wxMenu *SubMenu = pItem->GetSubMenu();
- if ( SubMenu != NULL ) {
- wxASSERT( SubMenu->m_hMenu != NULL );
-
- id = (UINT)SubMenu->m_hMenu;
-
- SubMenu->m_topLevelMenu = m_topLevelMenu;
- SubMenu->m_parent = this;
- SubMenu->m_savehMenu = (WXHMENU)id;
- SubMenu->m_hMenu = 0;
-
- flags |= MF_POPUP;
- }
- else {
- id = pItem->GetId();
- }
-
- LPCSTR pData;
- wxString name("");
-
-#if USE_OWNER_DRAWN
- if ( pItem->IsOwnerDrawn() ) { // want to get {Measure|Draw}Item messages?
- // item draws itself, pass pointer to it in data parameter
- flags |= MF_OWNERDRAW;
- pData = (LPCSTR)pItem;
- }
- else
-#endif
- {
- // menu is just a normal string (passed in data parameter)
- flags |= MF_STRING;
- name = pItem->GetName();
- pData = (const char*) name;
- }