tkUndo.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #ifndef _TKUNDO
  12. #define _TKUNDO
  13. #ifndef _TKINT
  14. #include "tkInt.h"
  15. #endif
  16. /*
  17. * Enum defining the types used in an undo stack.
  18. */
  19. typedef enum {
  20. TK_UNDO_SEPARATOR, /* Marker */
  21. TK_UNDO_ACTION /* Command */
  22. } TkUndoAtomType;
  23. /*
  24. * Callback proc type to carry out an undo or redo action via C code. (Actions
  25. * can also be defined by Tcl scripts).
  26. */
  27. typedef int (TkUndoProc)(Tcl_Interp *interp, ClientData clientData,
  28. Tcl_Obj *objPtr);
  29. /*
  30. * Struct defining a single action, one or more of which may be defined (and
  31. * stored in a linked list) separately for each undo and redo action of an
  32. * undo atom.
  33. */
  34. typedef struct TkUndoSubAtom {
  35. Tcl_Command command; /* Tcl token used to get the current Tcl
  36. * command name which will be used to execute
  37. * apply/revert scripts. If NULL then it is
  38. * assumed the apply/revert scripts already
  39. * contain everything. */
  40. TkUndoProc *funcPtr; /* Function pointer for callback to perform
  41. * undo/redo actions. */
  42. ClientData clientData; /* Data for 'funcPtr'. */
  43. Tcl_Obj *action; /* Command to apply the action that was
  44. * taken. */
  45. struct TkUndoSubAtom *next; /* Pointer to the next element in the linked
  46. * list. */
  47. } TkUndoSubAtom;
  48. /*
  49. * Struct representing a single undo+redo atom to be placed in the stack.
  50. */
  51. typedef struct TkUndoAtom {
  52. TkUndoAtomType type; /* The type that will trigger the required
  53. * action. */
  54. TkUndoSubAtom *apply; /* Linked list of 'apply' actions to perform
  55. * for this operation. */
  56. TkUndoSubAtom *revert; /* Linked list of 'revert' actions to perform
  57. * for this operation. */
  58. struct TkUndoAtom *next; /* Pointer to the next element in the
  59. * stack. */
  60. } TkUndoAtom;
  61. /*
  62. * Struct defining a single undo+redo stack.
  63. */
  64. typedef struct TkUndoRedoStack {
  65. TkUndoAtom *undoStack; /* The undo stack. */
  66. TkUndoAtom *redoStack; /* The redo stack. */
  67. Tcl_Interp *interp; /* The interpreter in which to execute the
  68. * revert and apply scripts. */
  69. int maxdepth;
  70. int depth;
  71. } TkUndoRedoStack;
  72. /*
  73. * Basic functions.
  74. */
  75. MODULE_SCOPE void TkUndoPushStack(TkUndoAtom **stack, TkUndoAtom *elem);
  76. MODULE_SCOPE TkUndoAtom *TkUndoPopStack(TkUndoAtom **stack);
  77. MODULE_SCOPE int TkUndoInsertSeparator(TkUndoAtom **stack);
  78. MODULE_SCOPE void TkUndoClearStack(TkUndoAtom **stack);
  79. /*
  80. * Functions for working on an undo/redo stack.
  81. */
  82. MODULE_SCOPE TkUndoRedoStack *TkUndoInitStack(Tcl_Interp *interp, int maxdepth);
  83. MODULE_SCOPE void TkUndoSetMaxDepth(TkUndoRedoStack *stack, int maxdepth);
  84. MODULE_SCOPE void TkUndoClearStacks(TkUndoRedoStack *stack);
  85. MODULE_SCOPE void TkUndoFreeStack(TkUndoRedoStack *stack);
  86. MODULE_SCOPE int TkUndoCanRedo(TkUndoRedoStack *stack);
  87. MODULE_SCOPE int TkUndoCanUndo(TkUndoRedoStack *stack);
  88. MODULE_SCOPE void TkUndoInsertUndoSeparator(TkUndoRedoStack *stack);
  89. MODULE_SCOPE TkUndoSubAtom *TkUndoMakeCmdSubAtom(Tcl_Command command,
  90. Tcl_Obj *actionScript, TkUndoSubAtom *subAtomList);
  91. MODULE_SCOPE TkUndoSubAtom *TkUndoMakeSubAtom(TkUndoProc *funcPtr,
  92. ClientData clientData, Tcl_Obj *actionScript,
  93. TkUndoSubAtom *subAtomList);
  94. MODULE_SCOPE void TkUndoPushAction(TkUndoRedoStack *stack,
  95. TkUndoSubAtom *apply, TkUndoSubAtom *revert);
  96. MODULE_SCOPE int TkUndoRevert(TkUndoRedoStack *stack);
  97. MODULE_SCOPE int TkUndoApply(TkUndoRedoStack *stack);
  98. #endif /* _TKUNDO */