1/* 2 * tkUndo.h -- 3 * 4 * Declarations shared among the files that implement an undo stack. 5 * 6 * Copyright (c) 2002 Ludwig Callewaert. 7 * 8 * See the file "license.terms" for information on usage and redistribution of 9 * this file, and for a DISCLAIMER OF ALL WARRANTIES. 10 * 11 * RCS: @(#) $Id$ 12 */ 13 14#ifndef _TKUNDO 15#define _TKUNDO 16 17#ifndef _TKINT 18#include "tkInt.h" 19#endif 20 21#ifdef BUILD_tk 22# undef TCL_STORAGE_CLASS 23# define TCL_STORAGE_CLASS DLLEXPORT 24#endif 25 26/* 27 * Enum definining the types used in an undo stack. 28 */ 29 30typedef enum { 31 TK_UNDO_SEPARATOR, /* Marker */ 32 TK_UNDO_ACTION /* Command */ 33} TkUndoAtomType; 34 35/* 36 * Callback proc type to carry out an undo or redo action via C code. (Actions 37 * can also be defined by Tcl scripts). 38 */ 39 40typedef int (TkUndoProc)(Tcl_Interp *interp, ClientData clientData, 41 Tcl_Obj *objPtr); 42 43/* 44 * Struct defining a single action, one or more of which may be defined (and 45 * stored in a linked list) separately for each undo and redo action of an 46 * undo atom. 47 */ 48 49typedef struct TkUndoSubAtom { 50 Tcl_Command command; /* Tcl token used to get the current Tcl 51 * command name which will be used to execute 52 * apply/revert scripts. If NULL then it is 53 * assumed the apply/revert scripts already 54 * contain everything. */ 55 TkUndoProc *funcPtr; /* Function pointer for callback to perform 56 * undo/redo actions. */ 57 ClientData clientData; /* Data for 'funcPtr'. */ 58 Tcl_Obj *action; /* Command to apply the action that was 59 * taken. */ 60 struct TkUndoSubAtom *next; /* Pointer to the next element in the linked 61 * list. */ 62} TkUndoSubAtom; 63 64/* 65 * Struct representing a single undo+redo atom to be placed in the stack. 66 */ 67 68typedef struct TkUndoAtom { 69 TkUndoAtomType type; /* The type that will trigger the required 70 * action. */ 71 TkUndoSubAtom *apply; /* Linked list of 'apply' actions to perform 72 * for this operation. */ 73 TkUndoSubAtom *revert; /* Linked list of 'revert' actions to perform 74 * for this operation. */ 75 struct TkUndoAtom *next; /* Pointer to the next element in the 76 * stack. */ 77} TkUndoAtom; 78 79/* 80 * Struct defining a single undo+redo stack. 81 */ 82 83typedef struct TkUndoRedoStack { 84 TkUndoAtom *undoStack; /* The undo stack. */ 85 TkUndoAtom *redoStack; /* The redo stack. */ 86 Tcl_Interp *interp; /* The interpreter in which to execute the 87 * revert and apply scripts. */ 88 int maxdepth; 89 int depth; 90} TkUndoRedoStack; 91 92/* 93 * Basic functions. 94 */ 95 96MODULE_SCOPE void TkUndoPushStack(TkUndoAtom **stack, TkUndoAtom *elem); 97MODULE_SCOPE TkUndoAtom *TkUndoPopStack(TkUndoAtom **stack); 98MODULE_SCOPE int TkUndoInsertSeparator(TkUndoAtom **stack); 99MODULE_SCOPE void TkUndoClearStack(TkUndoAtom **stack); 100 101/* 102 * Functions for working on an undo/redo stack. 103 */ 104 105MODULE_SCOPE TkUndoRedoStack *TkUndoInitStack(Tcl_Interp *interp, int maxdepth); 106MODULE_SCOPE void TkUndoSetDepth(TkUndoRedoStack *stack, int maxdepth); 107MODULE_SCOPE void TkUndoClearStacks(TkUndoRedoStack *stack); 108MODULE_SCOPE void TkUndoFreeStack(TkUndoRedoStack *stack); 109MODULE_SCOPE void TkUndoInsertUndoSeparator(TkUndoRedoStack *stack); 110MODULE_SCOPE TkUndoSubAtom *TkUndoMakeCmdSubAtom(Tcl_Command command, 111 Tcl_Obj *actionScript, TkUndoSubAtom *subAtomList); 112MODULE_SCOPE TkUndoSubAtom *TkUndoMakeSubAtom(TkUndoProc *funcPtr, 113 ClientData clientData, Tcl_Obj *actionScript, 114 TkUndoSubAtom *subAtomList); 115MODULE_SCOPE void TkUndoPushAction(TkUndoRedoStack *stack, 116 TkUndoSubAtom *apply, TkUndoSubAtom *revert); 117MODULE_SCOPE int TkUndoRevert(TkUndoRedoStack *stack); 118MODULE_SCOPE int TkUndoApply(TkUndoRedoStack *stack); 119 120# undef TCL_STORAGE_CLASS 121# define TCL_STORAGE_CLASS DLLIMPORT 122 123#endif /* _TKUNDO */ 124