The LEADTOOLS Automation features include an Undo/Redo engine for undoing and redoing automation operations. The undo level determines the number of operations that can be undone. For each undo that is performed, a redo operation can be performed. The undo level set for an automation handle applies to every container associated with that automation handle. For example, if an automation handle has four associated containers in four different windows, each container can have a maximum of 16 operations undone sequentially.
LEADTOOLS provides a number of functions for handling the undo/redo capabilities.
To determine the current undo level of the automation handle, call LAutomation::GetUndoLevel. The default value is DEF_AUTOMATION_UNDO_LEVEL . To set a new undo level for the automation handle, call LAutomation::SetUndoLevel.
The following example determines whether the last operation performed in the active automation container can be undone. If it can be undone, then LAutomation::Undo is called.
/* This example shows how simple it is to undo the last automation operation */
L_INT AutomationUndoTest (LAutomation &lauto)
if ( SUCCESS == lauto.IsValid () ) /* check the validity of the automation handle */
L_BOOL fCanUndo ;
/* Query the ability of undoing */
fCanUndo = lauto.CanUndo () ;
if ( fCanUndo )
/* undo the last automation operation */
lauto.Undo () ;
return SUCCESS ;
return FAILURE ;
Generally, operations are undone one operation at a time. If the last operation performed cut several objects from a container, undoing that operation would return the objects to the container. Occasionally, it may be best to group several operations together so that calling LAutomation::Undo undoes the whole group of operations and not just the last operation performed. This can be accomplished using the following steps:
Call LAutomation::AddUndoNode to add an undo node to the automation handle.
Disable the undo feature by calling LAutomation::SetUndoEnabled(FALSE).
Perform the operations to be combined into one undo.
Re-enable the undo feature by calling LAutomation::SetUndoEnabled(TRUE).
When LAutomation::Undo is called for this node, all of the combined operations will be undone.