| 449 | |
| 450 | |
| 451 | ResultType Script::ScriptDeleteMenu(UserMenu *aMenu) |
| 452 | // Deletes a UserMenu object and all the UserMenuItem objects that belong to it. |
| 453 | // Any UserMenuItem object that has a submenu attached to it does not result in |
| 454 | // that submenu being deleted, even if no other menus are using that submenu |
| 455 | // (i.e. the user must delete all menus individually). Any menus which have |
| 456 | // aMenu as one of their submenus will have that menu item deleted from their |
| 457 | // menus to avoid any chance of problems due to non-existent or NULL submenus. |
| 458 | { |
| 459 | // Delete any other menu's menu item that has aMenu as its attached submenu: |
| 460 | UserMenuItem *mi, *mi_prev, *mi_to_delete; |
| 461 | for (UserMenu *m = mFirstMenu; m; m = m->mNextMenu) |
| 462 | if (m != aMenu) // Don't bother with this menu even if it's submenu of itself, since it will be destroyed anyway. |
| 463 | for (mi = m->mFirstMenuItem, mi_prev = NULL; mi;) |
| 464 | { |
| 465 | mi_to_delete = mi; |
| 466 | mi = mi->mNextMenuItem; |
| 467 | if (mi_to_delete->mSubmenu == aMenu) |
| 468 | m->DeleteItem(mi_to_delete, mi_prev); |
| 469 | else |
| 470 | mi_prev = mi_to_delete; |
| 471 | } |
| 472 | // Remove aMenu from the linked list. First find the item that occurs prior the aMenu in the list: |
| 473 | UserMenu *aMenu_prev; |
| 474 | for (aMenu_prev = mFirstMenu; aMenu_prev; aMenu_prev = aMenu_prev->mNextMenu) |
| 475 | if (aMenu_prev->mNextMenu == aMenu) |
| 476 | break; |
| 477 | if (aMenu == mLastMenu) |
| 478 | mLastMenu = aMenu_prev; // Can be NULL if the list will now be empty. |
| 479 | if (aMenu_prev) // there is another item prior to aMenu in the linked list. |
| 480 | aMenu_prev->mNextMenu = aMenu->mNextMenu; // Can be NULL if aMenu was the last one. |
| 481 | else // aMenu was the first one in the list. |
| 482 | mFirstMenu = aMenu->mNextMenu; // Can be NULL if the list will now be empty. |
| 483 | // Do this last when its contents are no longer needed. Its destructor will delete all |
| 484 | // the items in the menu and destroy the OS menu itself: |
| 485 | aMenu->DeleteAllItems(); // This also calls Destroy() to free the menu's resources. |
| 486 | if (aMenu->mBrush) // Free the brush used for the menu's background color. |
| 487 | DeleteObject(aMenu->mBrush); |
| 488 | delete aMenu->mName; // Since it was separately allocated. |
| 489 | delete aMenu; |
| 490 | --mMenuCount; |
| 491 | return OK; |
| 492 | } |
| 493 | |
| 494 | |
| 495 |
nothing calls this directly
no test coverage detected