Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FX::FXCommand Class Referenceabstract

Base class for undoable commands records. More...

#include <FXUndoList.h>

Inheritance diagram for FX::FXCommand:
FX::FXObject FX::FXCommandGroup FX::FXUndoList

Public Member Functions

FXival nrefs () const
 
void ref ()
 
void unref ()
 
virtual void undo ()=0
 Undo this command.
 
virtual void redo ()=0
 Redo this command.
 
virtual FXuval size () const
 Return the size of the information in the undo record. More...
 
virtual FXString undoName () const
 Name of the undo command to be shown on a button; for example, "Undo Delete".
 
virtual FXString redoName () const
 Name of the redo command to be shown on a button; for example, "Redo Delete".
 
virtual FXbool canMerge () const
 Return true if this command could possibly be merged with a previous undo command. More...
 
virtual FXuint mergeWith (FXCommand *command)
 Called by the undo system to try and merge the new incoming command with this command. More...
 
- Public Member Functions inherited from FX::FXObject
const FXchar * getClassName () const
 Get class name of some object.
 
FXbool isMemberOf (const FXMetaClass *metaclass) const
 Check if object is member of metaclass.
 
virtual long tryHandle (FXObject *sender, FXSelector sel, void *ptr)
 Try handle message safely, catching certain exceptions.
 
virtual long onDefault (FXObject *, FXSelector, void *)
 Called for unhandled messages.
 
virtual void save (FXStream &store) const
 Save object to stream.
 
virtual void load (FXStream &store)
 Load object from stream.
 
virtual ~FXObject ()
 Virtual destructor.
 

Detailed Description

Base class for undoable commands records.

Each undo records all the information necessary to undo, as well as redo, a given operation. Since commands are derived from FXObject, subclassed commands may be able to implement their behaviour by sending messages (like ID_SETINTVALUE, etc) as well as simple API calls to objects to be modified. Small, incremental undo commands may sometimes be consolidated into larger ones, by merging consecutive commands. A merge is effected by calling the mergeWith() API after first establishing that merging is possible with canMerge(). When commands are merged, the incoming (new) command is deleted and not added to the undo list. In some cases, the incoming command may completely cancel the existing commands, causing both to be deleted. In that case the prior command will be removed from the undo list. To allow UndoList to manage memory, your subclassed Command should re-implement size() and return the amount of memory used by your undo command. This way, bookkeeping periodically pare down undo commands to keep memory usage in check.

Member Function Documentation

◆ canMerge()

virtual FXbool FX::FXCommand::canMerge ( ) const
virtual

Return true if this command could possibly be merged with a previous undo command.

This is useful to combine e.g. multiple consecutive single-character text changes into a single block change. The default implementation returns false.

◆ mergeWith()

virtual FXuint FX::FXCommand::mergeWith ( FXCommand command)
virtual

Called by the undo system to try and merge the new incoming command with this command.

When overriding this API, return:

0 if incoming command could not be merged into this command, 1 if incoming command could be merged into this command, 2 if incoming command completely cancels effect of this command.

The default implementation returns 0.

◆ size()

virtual FXuval FX::FXCommand::size ( ) const
virtual

Return the size of the information in the undo record.

The undo list may be periodically trimmed to limit memory usage to a certain limit. For proper accounting, value returned should include the size of the command record itself as well as any data linked from it.

Reimplemented in FX::FXUndoList, and FX::FXCommandGroup.


The documentation for this class was generated from the following file:

Copyright © 1997-2022 Jeroen van der Zijp