// $Revision: 1.2 $ // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. // TilesCommands.h #ifndef TaligentSample_TILESCOMMANDS #define TaligentSample_TILESCOMMANDS // Include for Presentation Framework commands #ifndef Taligent_GUICOMPOUNDDOCUMENTCOMMAND #include #endif #ifndef TaligentSample_TILESMODEL #include "TilesModel.h" #endif #ifndef TaligentSample_TILESSELECTIONS #include "TilesSelections.h" #endif // The TCreateTileCommand will add a TTile of a specific type to the TModel. class TCreateTileCommand : public TCommandOn { public: // The following macro must be called within class declarations in order to use Taligent // Type Extensions.The macro defines a set of Taligent Type Extension utility functions. // This macro call matches a macro call to TaligentTypeExtensionMacro in TilesCommands.C TaligentTypeExtensionDeclarationsMacro (TCreateTileCommand) // The type of tile to create and its location is specified once in the constructor TCreateTileCommand(TTile::EType tileType, const TGPoint& position, const TGPoint& size); // A true default (void) constructor is also needed by TaligentTypeExtension. TCreateTileCommand (); virtual ~TCreateTileCommand (); // TaligentTypeExtension require that copy constructors be defined as well as assignment // and streaming operators. TCreateTileCommand (const TCreateTileCommand ©); virtual TStream& operator>>= (TStream& toStream) const; virtual TStream& operator<<= (TStream& fromStream); protected: // These are the primary methods to concern yourself with. For // incremental commands you would also need to override HandleDoIncrement(). // HandleDoBegin() will start (and, in this case, also finish) // the command. Information which will be useful for undo will // also be saved. virtual void HandleDoBegin (TTilesSelection& target); // HandleUndo() uses the information saved from HandleDoBegin() // to undo the operation. virtual void HandleUndo (TTilesSelection& target); // HandleRedo() works like HandleDoBegin() except that it will // not need to save information for HandleUndo(). virtual void HandleRedo (TTilesSelection& target); private: // Version number used for streaming. enum {kOriginalVersion}; // The type of tile to create. TTile::EType fNewTileType; TGPoint fNewTilePosition, fNewTileSize; // The index of the newly created tile, used by undo to remove the tile TileIndex fNewTileIndex; // Place operator= in private section to prevent it from being called. TCreateTileCommand& operator= (const TCreateTileCommand& copy) {return *this;} }; // TChangeColorCommand will change the color of all the TTiles referred to // by a TTilesSelection. TTilesSelection is a model selection which can specify // either the whole model or just one tile. A TTilesSelection can also be empty. class TChangeColorCommand : public TCommandOn { public: // The following macro must be called within class declarations in order to use Taligent // Type Extensions.The macro defines a set of Taligent Type Extension utility functions. // This macro call matches a macro call to TaligentTypeExtensionMacro in TilesCommands.C TaligentTypeExtensionDeclarationsMacro (TChangeColorCommand) // The color to change to is specified once in the constructor TChangeColorCommand (const TRGBColor& newColor); // A true default (void) constructor is also needed by TaligentTypeExtension. TChangeColorCommand (); virtual ~TChangeColorCommand (); // TaligentTypeExtension require that copy constructors be defined as well as assignment // and streaming operators. TChangeColorCommand (const TChangeColorCommand ©); TChangeColorCommand& operator= (const TChangeColorCommand& copy); virtual TStream& operator>>= (TStream& toStream) const; virtual TStream& operator<<= (TStream& fromStream); protected: // These are the primary methods to concern yourself with. For // incremental commands you would also need to override HandleDoIncrement(). // HandleDoBegin() will start (and, in this case, also finish) // the command. Information which will be useful for undo will // also be saved. virtual void HandleDoBegin (TTilesSelection& target); // HandleUndo() uses the information saved from HandleDoBegin() // to undo the operation. virtual void HandleUndo (TTilesSelection& target); // HandleRedo() works like HandleDoBegin() except that it will // not need to save information for HandleUndo(). virtual void HandleRedo (TTilesSelection& target); // HandleCanDo() returns true when the command can be performed, in // this case, when the target is not empty. HandleCanDo is used by // the Presentation Framework to activate/deactive menu items when // the command is bound to the menu item with a TCommandControlStateOn<>. virtual bool HandleCanDo (const TTilesSelection& target) const; private: // Version number enum {kOriginalVersion}; // The color to change to. TRGBColor fNewColor; // The number of tiles in the model (needed for whole model selections). TileIndex fNumTiles; // A pointer so we can allocated enough memory to store all the old colors. TRGBColor* fOldColor; }; // TMoveCommand is an incremental command which changes the position of a TTile. // TMoveCommand assumes the selection selects only one TTile in the model. Incremental // commands modify their target incrementally but undo all in one step. Thus, // TMoveCommand's undo will move the TTile back to the original position. // Not that TMoveCommand is not dependent on the user interface. Mouse events // are handled by the TMoveInteractor (see TilesInterators.h). This way, TMoveCommand // could be used to move the TTile by other user interface methods like keyboard // commands (arrow keys). class TMoveCommand : public TCommandOn { public: // The following macro must be called within class declarations in order to use Taligent // Type Extensions.The macro defines a set of Taligent Type Extension utility functions. // This macro call matches a macro call to TaligentTypeExtensionMacro in TilesCommands.C TaligentTypeExtensionDeclarationsMacro (TMoveCommand) // A true default (void) constructor is needed by TaligentTypeExtension. // No special constructors are needed for the TMoveCommand TMoveCommand (); virtual ~TMoveCommand (); // TaligentTypeExtension require that copy constructors be defined as well as assignment // and streaming operators. TMoveCommand (const TMoveCommand ©); TMoveCommand& operator= (const TMoveCommand& copy); virtual TStream& operator>>= (TStream& toStream) const; virtual TStream& operator<<= (TStream& fromStream); // MoveBy will changed the delta position by which this command will // move the target. void MoveBy (const TGPoint& delta); protected: // These are the primary methods to concern yourself with. This is // an incremental command, so HandleDoIncrement() is defined. // HandleDoBegin() will start the command. Information which will // be useful for undo will also be saved. The information stored // should allow the entire incremental command to be undone, not // just a single step. virtual void HandleDoBegin (TTilesSelection& target); // HandleUndo() uses the information saved from HandleDoBegin() // to undo the operation. virtual void HandleUndo (TTilesSelection& target); // HandleRedo() works like HandleDoBegin() plus all the HandleDoIncrements() // except that it will not need to save information for HandleUndo(). virtual void HandleRedo (TTilesSelection& target); // HandleDoIncrement() performs the incremental steps in the command. virtual void HandleDoIncrement (TTilesSelection& target); private: // Version number enum {kOriginalVersion}; // The original position, stored once at HandleDoBegin. TGPoint fOldPosition; // The new position stored as a delta from the original position, updated incrementally. TGPoint fDelta; }; // The command binding binds an command instance to a selection instance. // The document adopts the command binding and invokes the command.Do(selection) // operation. The document then streams out the command/selection pair for undo/redo, // saveless model, etc. typedef TGUIDocumentComponentCommandBindingTo TTilesCommandBinding; // TCommandControlStates are not used in the Constructerized version #ifndef USE_ARCHIVES // A TCommandControlStateOn is a default momentary control state which initiates a // command on the current selection. The TCommandControlStateOn<> constructor takes // in its constructor the TGUIBundle, an undo/redo label and a command prototype. When // the control state is Select()'ed, it will get the current selection from the TGUIBundle, // clone the command prototype and bind it to the current selection. It will then call the // document's AdoptAndDo() to perform the command. typedef TCommandControlStateOn TTilesControlState; #endif // ifndef USE_ARCHIVES #endif // TaligentSample_TILESCOMMANDS