jpayne@69: /* jpayne@69: * tkUndo.h -- jpayne@69: * jpayne@69: * Declarations shared among the files that implement an undo stack. jpayne@69: * jpayne@69: * Copyright (c) 2002 Ludwig Callewaert. jpayne@69: * jpayne@69: * See the file "license.terms" for information on usage and redistribution of jpayne@69: * this file, and for a DISCLAIMER OF ALL WARRANTIES. jpayne@69: */ jpayne@69: jpayne@69: #ifndef _TKUNDO jpayne@69: #define _TKUNDO jpayne@69: jpayne@69: #ifndef _TKINT jpayne@69: #include "tkInt.h" jpayne@69: #endif jpayne@69: jpayne@69: /* jpayne@69: * Enum defining the types used in an undo stack. jpayne@69: */ jpayne@69: jpayne@69: typedef enum { jpayne@69: TK_UNDO_SEPARATOR, /* Marker */ jpayne@69: TK_UNDO_ACTION /* Command */ jpayne@69: } TkUndoAtomType; jpayne@69: jpayne@69: /* jpayne@69: * Callback proc type to carry out an undo or redo action via C code. (Actions jpayne@69: * can also be defined by Tcl scripts). jpayne@69: */ jpayne@69: jpayne@69: typedef int (TkUndoProc)(Tcl_Interp *interp, ClientData clientData, jpayne@69: Tcl_Obj *objPtr); jpayne@69: jpayne@69: /* jpayne@69: * Struct defining a single action, one or more of which may be defined (and jpayne@69: * stored in a linked list) separately for each undo and redo action of an jpayne@69: * undo atom. jpayne@69: */ jpayne@69: jpayne@69: typedef struct TkUndoSubAtom { jpayne@69: Tcl_Command command; /* Tcl token used to get the current Tcl jpayne@69: * command name which will be used to execute jpayne@69: * apply/revert scripts. If NULL then it is jpayne@69: * assumed the apply/revert scripts already jpayne@69: * contain everything. */ jpayne@69: TkUndoProc *funcPtr; /* Function pointer for callback to perform jpayne@69: * undo/redo actions. */ jpayne@69: ClientData clientData; /* Data for 'funcPtr'. */ jpayne@69: Tcl_Obj *action; /* Command to apply the action that was jpayne@69: * taken. */ jpayne@69: struct TkUndoSubAtom *next; /* Pointer to the next element in the linked jpayne@69: * list. */ jpayne@69: } TkUndoSubAtom; jpayne@69: jpayne@69: /* jpayne@69: * Struct representing a single undo+redo atom to be placed in the stack. jpayne@69: */ jpayne@69: jpayne@69: typedef struct TkUndoAtom { jpayne@69: TkUndoAtomType type; /* The type that will trigger the required jpayne@69: * action. */ jpayne@69: TkUndoSubAtom *apply; /* Linked list of 'apply' actions to perform jpayne@69: * for this operation. */ jpayne@69: TkUndoSubAtom *revert; /* Linked list of 'revert' actions to perform jpayne@69: * for this operation. */ jpayne@69: struct TkUndoAtom *next; /* Pointer to the next element in the jpayne@69: * stack. */ jpayne@69: } TkUndoAtom; jpayne@69: jpayne@69: /* jpayne@69: * Struct defining a single undo+redo stack. jpayne@69: */ jpayne@69: jpayne@69: typedef struct TkUndoRedoStack { jpayne@69: TkUndoAtom *undoStack; /* The undo stack. */ jpayne@69: TkUndoAtom *redoStack; /* The redo stack. */ jpayne@69: Tcl_Interp *interp; /* The interpreter in which to execute the jpayne@69: * revert and apply scripts. */ jpayne@69: int maxdepth; jpayne@69: int depth; jpayne@69: } TkUndoRedoStack; jpayne@69: jpayne@69: /* jpayne@69: * Basic functions. jpayne@69: */ jpayne@69: jpayne@69: MODULE_SCOPE void TkUndoPushStack(TkUndoAtom **stack, TkUndoAtom *elem); jpayne@69: MODULE_SCOPE TkUndoAtom *TkUndoPopStack(TkUndoAtom **stack); jpayne@69: MODULE_SCOPE int TkUndoInsertSeparator(TkUndoAtom **stack); jpayne@69: MODULE_SCOPE void TkUndoClearStack(TkUndoAtom **stack); jpayne@69: jpayne@69: /* jpayne@69: * Functions for working on an undo/redo stack. jpayne@69: */ jpayne@69: jpayne@69: MODULE_SCOPE TkUndoRedoStack *TkUndoInitStack(Tcl_Interp *interp, int maxdepth); jpayne@69: MODULE_SCOPE void TkUndoSetMaxDepth(TkUndoRedoStack *stack, int maxdepth); jpayne@69: MODULE_SCOPE void TkUndoClearStacks(TkUndoRedoStack *stack); jpayne@69: MODULE_SCOPE void TkUndoFreeStack(TkUndoRedoStack *stack); jpayne@69: MODULE_SCOPE int TkUndoCanRedo(TkUndoRedoStack *stack); jpayne@69: MODULE_SCOPE int TkUndoCanUndo(TkUndoRedoStack *stack); jpayne@69: MODULE_SCOPE void TkUndoInsertUndoSeparator(TkUndoRedoStack *stack); jpayne@69: MODULE_SCOPE TkUndoSubAtom *TkUndoMakeCmdSubAtom(Tcl_Command command, jpayne@69: Tcl_Obj *actionScript, TkUndoSubAtom *subAtomList); jpayne@69: MODULE_SCOPE TkUndoSubAtom *TkUndoMakeSubAtom(TkUndoProc *funcPtr, jpayne@69: ClientData clientData, Tcl_Obj *actionScript, jpayne@69: TkUndoSubAtom *subAtomList); jpayne@69: MODULE_SCOPE void TkUndoPushAction(TkUndoRedoStack *stack, jpayne@69: TkUndoSubAtom *apply, TkUndoSubAtom *revert); jpayne@69: MODULE_SCOPE int TkUndoRevert(TkUndoRedoStack *stack); jpayne@69: MODULE_SCOPE int TkUndoApply(TkUndoRedoStack *stack); jpayne@69: jpayne@69: #endif /* _TKUNDO */