| 286 | |
| 287 | |
| 288 | ResultType Script::ScriptDeleteMenu(UserMenu *aMenu) |
| 289 | // Deletes a UserMenu object and all the UserMenuItem objects that belong to it. |
| 290 | // Any UserMenuItem object that has a submenu attached to it does not result in |
| 291 | // that submenu being deleted, even if no other menus are using that submenu |
| 292 | // (i.e. the user must delete all menus individually). Any menus which have |
| 293 | // aMenu as one of their submenus will have that menu item deleted from their |
| 294 | // menus to avoid any chance of problems due to non-existent or NULL submenus. |
| 295 | { |
| 296 | // Delete any other menu's menu item that has aMenu as its attached submenu: |
| 297 | // This is not done because reference counting ensures that submenus are not |
| 298 | // deleted before the parent menu, except when the script is exiting. |
| 299 | //UserMenuItem *mi, *mi_prev, *mi_to_delete; |
| 300 | //for (UserMenu *m = mFirstMenu; m; m = m->mNextMenu) |
| 301 | // if (m != aMenu) // Don't bother with this menu even if it's submenu of itself, since it will be destroyed anyway. |
| 302 | // for (mi = m->mFirstMenuItem, mi_prev = NULL; mi;) |
| 303 | // { |
| 304 | // mi_to_delete = mi; |
| 305 | // mi = mi->mNextMenuItem; |
| 306 | // if (mi_to_delete->mSubmenu == aMenu) |
| 307 | // m->DeleteItem(mi_to_delete, mi_prev); |
| 308 | // else |
| 309 | // mi_prev = mi_to_delete; |
| 310 | // } |
| 311 | // Remove aMenu from the linked list. |
| 312 | UserMenu *aMenu_prev; |
| 313 | if (aMenu == mFirstMenu) // Checked first since it's always true when called by ~Script(). |
| 314 | { |
| 315 | mFirstMenu = aMenu->mNextMenu; // Can be NULL if the list will now be empty. |
| 316 | aMenu_prev = NULL; |
| 317 | } |
| 318 | else // Find the item that occurs prior to aMenu in the list: |
| 319 | for (aMenu_prev = mFirstMenu; aMenu_prev; aMenu_prev = aMenu_prev->mNextMenu) |
| 320 | if (aMenu_prev->mNextMenu == aMenu) |
| 321 | { |
| 322 | aMenu_prev->mNextMenu = aMenu->mNextMenu; // Can be NULL if aMenu was the last one. |
| 323 | break; |
| 324 | } |
| 325 | if (aMenu == mLastMenu) |
| 326 | mLastMenu = aMenu_prev; // Can be NULL if the list will now be empty. |
| 327 | --mMenuCount; |
| 328 | // Do this last when its contents are no longer needed. It will delete all |
| 329 | // the items in the menu and destroy the OS menu itself: |
| 330 | aMenu->Dispose(); |
| 331 | return OK; |
| 332 | } |
| 333 | |
| 334 | |
| 335 | |