home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CmdTable.cpp
-
- Contains: CommandTable and CommandTableEntry C++ classes.
-
- Owned by: Richard Rodseth
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 7/25/95 VL 1270320: Delete entry after removing it in
- UnregisterCommand.
- <3> 5/26/95 RR #1251403: Multithreading naming support
- <2> 5/25/95 jpa List.h --> LinkList.h [1253324]
- <1> 5/10/94 RR first checked in
- <2> 3/15/94 MB Changes to support SCpp/ASLM builds,
- #1150864.
- <1> 9/15/93 RR first checked in
-
- To Do:
- In Progress:
- */
-
- #ifndef _CMDTABLE_
- #include "CmdTable.h"
- #endif
-
-
- #pragma segment ODCmdTable
-
-
- //======================================================================================
- // Class CommandTableEntry - Definition & Implementation
- //======================================================================================
-
- class CommandTableEntry : public Link {
-
- public:
-
- CommandTableEntry(ODCommandID command,
- ODMenuID menu,
- ODMenuItemID menuItem);
-
- ODVMethod ~CommandTableEntry() {}
-
- ODCommandID GetCommandNumber() { return fCommandNumber;}
- void SetCommandNumber(ODCommandID command)
- { fCommandNumber = command;}
- void GetMenuAndItem(ODMenuID& menu,
- ODMenuItemID& menuItem) { menu = fMenu; menuItem = fMenuItem;}
- void SetMenuAndItem(ODMenuID menu,
- ODMenuItemID menuItem)
- { fMenu = menu; fMenuItem = menuItem; }
-
- ODBoolean Matches(ODCommandID command)
- { return (fCommandNumber == command); }
- ODBoolean Matches(ODMenuID menu,
- ODMenuItemID menuItem)
- { return (fMenu == menu) && (fMenuItem == menuItem); }
-
- private:
- ODCommandID fCommandNumber;
- ODMenuID fMenu;
- ODMenuItemID fMenuItem;
- };
-
-
- CommandTableEntry::CommandTableEntry(ODCommandID command,
- ODMenuID menu,
- ODMenuItemID menuItem)
- {
- fCommandNumber = command;
- fMenu = menu;
- fMenuItem = menuItem;
- }
-
- //======================================================================================
- // Class CommandTable
- //======================================================================================
-
- //------------------------------------------------------------------------------
- // CommandTable::CommandTable
- //
- // Description
- //------------------------------------------------------------------------------
-
- CommandTable::CommandTable()
- {
- }
-
- //------------------------------------------------------------------------------
- // CommandTable::~CommandTable
- //
- // Description
- //------------------------------------------------------------------------------
-
- CommandTable::~CommandTable()
- {
- this->UnregisterAll();
- }
-
- //------------------------------------------------------------------------------
- // CommandTable::Copy
- //
- // Description
- //------------------------------------------------------------------------------
-
- CommandTable* CommandTable::Copy()
- {
- CommandTable* copy = new CommandTable();
-
- LinkedListIterator iter(&fImplementation);
- CommandTableEntry* entry = (CommandTableEntry*) iter.First();
- while (entry != kODNULL)
- {
- ODCommandID command = entry->GetCommandNumber();
- ODMenuID menu;
- ODMenuItemID menuItem;
- entry->GetMenuAndItem(menu, menuItem);
- copy->RegisterCommand(command, menu, menuItem);
- entry = (CommandTableEntry*) iter.Next();
- }
- return copy;
- }
-
- //------------------------------------------------------------------------------
- // CommandTable::RegisterCommand
- //
- // Description
- //------------------------------------------------------------------------------
-
- void CommandTable::RegisterCommand(ODCommandID command,
- ODMenuID menu,
- ODMenuItemID menuItem)
- {
- if (this->IsCommandRegistered(command))
- ;// Throw exception
- else
- {
- CommandTableEntry* entry = new CommandTableEntry(command, menu, menuItem);
- if (entry)
- fImplementation.AddLast(entry);
- else
- ;
- }
- }
-
- //------------------------------------------------------------------------------
- // CommandTable::IsCommandRegistered
- //
- // Description
- //------------------------------------------------------------------------------
-
- ODBoolean CommandTable::IsCommandRegistered(ODCommandID command)
- {
- LinkedListIterator iter(&fImplementation);
- CommandTableEntry* entry = (CommandTableEntry*) iter.First();
- while (entry != kODNULL)
- {
- if (entry->Matches(command))
- {
- return kODTrue;
- }
- else
- entry = (CommandTableEntry*) iter.Next();
- }
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // CommandTable::GetCommand
- //
- // Description
- //------------------------------------------------------------------------------
-
- ODCommandID CommandTable::GetCommand(ODMenuID menu,
- ODMenuItemID menuItem)
- {
- ODCommandID result = kNoCommand;
-
- LinkedListIterator iter(&fImplementation);
- CommandTableEntry* entry = (CommandTableEntry*) iter.First();
- while (entry != kODNULL)
- {
- if (entry->Matches(menu,menuItem))
- {
- return entry->GetCommandNumber();
- }
- else
- entry = (CommandTableEntry*) iter.Next();
- }
- return kNoCommand;
- }
-
- //------------------------------------------------------------------------------
- // CommandTable::GetMenuAndItem
- //
- // Description
- //------------------------------------------------------------------------------
-
- ODBoolean CommandTable::GetMenuAndItem(ODCommandID command,
- ODMenuID& menu,
- ODMenuItemID& menuItem)
- {
- ODBoolean found = kODFalse;
-
- LinkedListIterator iter(&fImplementation);
- CommandTableEntry* entry = (CommandTableEntry*) iter.First();
- while (entry != kODNULL)
- {
- if (entry->Matches(command))
- {
- entry->GetMenuAndItem(menu, menuItem);
- found = kODTrue;
- break;
- }
- else
- entry = (CommandTableEntry*) iter.Next();
- }
- if (!found)
- {
- menu = 0;
- menuItem = -1;
- };
- return found;
- }
-
- //------------------------------------------------------------------------------
- // CommandTable::UnregisterCommand
- //
- // Description
- //------------------------------------------------------------------------------
-
- void CommandTable::UnregisterCommand(ODCommandID command)
- {
- LinkedListIterator iter(&fImplementation);
- CommandTableEntry* entry = (CommandTableEntry*) iter.First();
- while (entry != kODNULL)
- {
- if (entry->Matches(command))
- {
- fImplementation.Remove(*entry);
- ODDeleteObject(entry);
- break;
- }
- else
- entry = (CommandTableEntry*) iter.Next();
- }
- }
-
- //------------------------------------------------------------------------------
- // CommandTable::UnregisterAll
- //
- // Description
- //------------------------------------------------------------------------------
-
- void CommandTable::UnregisterAll()
- {
- Link* link = fImplementation.RemoveFirst();
- while (link != kODNULL)
- {
- delete link;
- link = fImplementation.RemoveFirst();
- }
- }
-
-