1 /***********************************************************************/ 2 /* Open Visualization Data Explorer */ 3 /* (C) Copyright IBM Corp. 1989,1999 */ 4 /* ALL RIGHTS RESERVED */ 5 /* This code licensed under the */ 6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ 7 /***********************************************************************/ 8 9 #include <dxconfig.h> 10 #include "../base/defines.h" 11 12 13 14 15 #ifndef _Command_h 16 #define _Command_h 17 18 19 #include "Server.h" 20 #include "List.h" 21 22 23 // 24 // Class name definition: 25 // 26 #define ClassCommand "Command" 27 28 29 // 30 // Referenced classes: 31 // 32 class CommandScope; 33 class CommandInterface; 34 35 // 36 // Command class definition: 37 // 38 class Command : public Server 39 { 40 private: 41 // 42 // Private class data: 43 // 44 static boolean CommandClassInitialized; // Command class initialized? 45 46 // 47 // Private member data: 48 // 49 char* name; // name of the command 50 boolean active; // is the command active? 51 List activateCmds; // Commands to activate on success 52 List deactivateCmds; // Commands to activate on success 53 List autoActivators; // Commands that automatically 54 // (de)activate this command. 55 void addActivator(Command*); 56 void removeActivator(Command*); 57 58 protected: 59 // 60 // Protected member data: 61 // 62 boolean hasUndo; // TRUE if this Command supports undo 63 List scopeList; // list of command scopes 64 65 // 66 // To be defined by subclasses: 67 // This function will be called by execute() function to perform 68 // the actual work done by the command. 69 // As per the definition of execute(), if available, the CommandInterface 70 // that initiated the execution is provided, otherwise ci will be NULL. 71 // NULL. So, if this method uses ci, it may also need to be prepared to 72 // handle the case where ci==NULL. 73 // 74 virtual boolean doIt(CommandInterface *ci) = 0; 75 76 // 77 // To be defined by subclasses: 78 // This function will be called by undo() function to perform 79 // the actual undo work. 80 // 81 virtual boolean undoIt() = 0; 82 83 // 84 // Constructor: 85 // Protected to prevent direct instantiation. 86 // 87 Command(const char* name, 88 CommandScope* scope, 89 boolean active); 90 91 public: 92 // 93 // Notification messages: 94 // 95 static Symbol MsgActivate; 96 static Symbol MsgDeactivate; 97 static Symbol MsgDisassociate; 98 static Symbol MsgBeginExecuting; 99 static Symbol MsgEndExecuting; 100 101 // 102 // Destructor: 103 // 104 ~Command(); 105 106 // 107 // Implementation of registerClient() for this class: 108 // Sends activation/deactivation message to client interfaces 109 // to sync it with the current state of the Command object. 110 // 111 virtual boolean registerClient(Client* client); 112 113 // 114 // Intiates the action or actions supported by this Command object. 115 // This function provides the public interface through which 116 // any command is executed. It notifies all clients of the application 117 // when the command begins and ends. If available, then the 118 // CommandInterface that initiated the execution is provided, otherwise 119 // ci is passed as NULL. 120 // 121 virtual boolean execute(CommandInterface *ci = NULL); 122 123 // 124 // Causes the action initiated by the execute() member function to be 125 // reversed. This funciton provides the public interface through 126 // which any command is be reversed. 127 // 128 boolean undo(); 129 130 // 131 // Enables the command and any user interface component associated 132 // with this Command object. Command objects can be executed only 133 // if they are enabled. 134 // 135 virtual void activate(); 136 137 // 138 // Disables the command and any user interface component associated 139 // with this Command object. 140 // 141 virtual void deactivate(const char *reason = NULL); 142 143 // 144 // Registers a new scope to this command. 145 // Returns TRUE if successful; FALSE, otherwise. 146 // 147 virtual boolean registerScope(CommandScope* scope); 148 149 // 150 // Unregisters a scope from this command. 151 // Returns TRUE if successful; FALSE, otherwise. 152 // 153 virtual boolean unregisterScope(CommandScope* scope); 154 155 // 156 // Returns active status. 157 // isActive()158 boolean isActive() 159 { 160 return this->active; 161 } 162 163 // 164 // Returns undo capability status. 165 // canUndo()166 boolean canUndo() 167 { 168 return this->hasUndo; 169 } 170 171 // 172 // Functions to append a command to either the activation or deactivation 173 // list. 174 // 175 void autoActivate(Command *c); 176 void autoDeactivate(Command *c); 177 void removeAutoCmd(Command *c); 178 179 // 180 // Returns the command name. 181 // getName()182 const char* getName() 183 { 184 return this->name; 185 } 186 187 // 188 // Returns a pointer to the class name. 189 // getClassName()190 const char* getClassName() 191 { 192 return ClassCommand; 193 } 194 }; 195 196 197 #endif // _Command_h 198