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, as follows:
To determine the current undo level of the automation handle, call L_AutGetUndoLevel. The default value is DEF_AUTOMATION_UNDO_LEVEL [16]. To set a new undo level for the automation handle, call L_AutSetUndoLevel.
To determine whether the last automation operation performed can be undone or redone, call L_AutCanUndo and L_AutCanRedo respectively.
L_AutUndo undoes the last automation operation performed, while L_AutRedo redoes the last automation operation undone.
The following example determines whether the last operation performed in the active automation container can be undone. If it can be undone, then L_AutUndo is called.
/* This example shows how simple it is to undo the last automation operation */
L_INT AutomationUndoTest(pAUTOMATIONHANDLE pAutomation)
{
if (SUCCESS == L_AutIsValid(pAutomation)) /* check the validity of the automation handle */
{
L_BOOL fCanUndo;
/* Query the ability of undoing */
L_AutCanUndo(pAutomation, &fCanUndo);
if (fCanUndo)
{
/* undo the last automation operation */
L_AutUndo(pAutomation, 0);
}
return SUCCESS;
}
else
{
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 L_AutUndo undoes the whole group of operations and not just the last operation performed. This can be accomplished by performing the following steps:
Call L_AutAddUndoNode to add an undo node to the automation handle.
Disable the undo feature by calling _AutSetUndoEnabled(pAutomation, FALSE).
Perform the operations to be combined into one undo.
Re-enable the undo feature by calling _AutSetUndoEnabled(pAutomation, TRUE).
When L_AutUndo is called for this node, all of the combined operations will be undone.