annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/tkUndo.h @ 69:33d812a61356

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