diff options
Diffstat (limited to 'generic/tkUndo.c')
-rw-r--r-- | generic/tkUndo.c | 83 |
1 files changed, 65 insertions, 18 deletions
diff --git a/generic/tkUndo.c b/generic/tkUndo.c index bf2ed7c..c66905d 100644 --- a/generic/tkUndo.c +++ b/generic/tkUndo.c @@ -94,7 +94,7 @@ TkUndoInsertSeparator( TkUndoAtom *separator; if (*stack!=NULL && (*stack)->type!=TK_UNDO_SEPARATOR) { - separator = (TkUndoAtom *) ckalloc(sizeof(TkUndoAtom)); + separator = ckalloc(sizeof(TkUndoAtom)); separator->type = TK_UNDO_SEPARATOR; TkUndoPushStack(stack,separator); return 1; @@ -135,7 +135,7 @@ TkUndoClearStack( if (sub->action != NULL) { Tcl_DecrRefCount(sub->action); } - ckfree((char *)sub); + ckfree(sub); sub = next; } @@ -146,11 +146,11 @@ TkUndoClearStack( if (sub->action != NULL) { Tcl_DecrRefCount(sub->action); } - ckfree((char *)sub); + ckfree(sub); sub = next; } } - ckfree((char *)elem); + ckfree(elem); } *stack = NULL; } @@ -181,7 +181,7 @@ TkUndoPushAction( { TkUndoAtom *atom; - atom = (TkUndoAtom *) ckalloc(sizeof(TkUndoAtom)); + atom = ckalloc(sizeof(TkUndoAtom)); atom->type = TK_UNDO_ACTION; atom->apply = apply; atom->revert = revert; @@ -237,7 +237,7 @@ TkUndoMakeCmdSubAtom( Tcl_Panic("NULL command and actionScript in TkUndoMakeCmdSubAtom"); } - atom = (TkUndoSubAtom *) ckalloc(sizeof(TkUndoSubAtom)); + atom = ckalloc(sizeof(TkUndoSubAtom)); atom->command = command; atom->funcPtr = NULL; atom->clientData = NULL; @@ -299,7 +299,7 @@ TkUndoMakeSubAtom( Tcl_Panic("NULL funcPtr in TkUndoMakeSubAtom"); } - atom = (TkUndoSubAtom *) ckalloc(sizeof(TkUndoSubAtom)); + atom = ckalloc(sizeof(TkUndoSubAtom)); atom->command = NULL; atom->funcPtr = funcPtr; atom->clientData = clientData; @@ -341,7 +341,7 @@ TkUndoInitStack( { TkUndoRedoStack *stack; /* An Undo/Redo stack */ - stack = (TkUndoRedoStack *) ckalloc(sizeof(TkUndoRedoStack)); + stack = ckalloc(sizeof(TkUndoRedoStack)); stack->undoStack = NULL; stack->redoStack = NULL; stack->interp = interp; @@ -353,7 +353,7 @@ TkUndoInitStack( /* *---------------------------------------------------------------------- * - * TkUndoSetDepth -- + * TkUndoSetMaxDepth -- * * Set the maximum depth of stack. * @@ -368,7 +368,7 @@ TkUndoInitStack( */ void -TkUndoSetDepth( +TkUndoSetMaxDepth( TkUndoRedoStack *stack, /* An Undo/Redo stack */ int maxdepth) /* The maximum stack depth */ { @@ -392,6 +392,7 @@ TkUndoSetDepth( prevelem = elem; elem = elem->next; } + CLANG_ASSERT(prevelem); prevelem->next = NULL; while (elem != NULL) { prevelem = elem; @@ -403,7 +404,7 @@ TkUndoSetDepth( if (sub->action != NULL) { Tcl_DecrRefCount(sub->action); } - ckfree((char *)sub); + ckfree(sub); sub = next; } sub = elem->revert; @@ -413,12 +414,12 @@ TkUndoSetDepth( if (sub->action != NULL) { Tcl_DecrRefCount(sub->action); } - ckfree((char *)sub); + ckfree(sub); sub = next; } } elem = elem->next; - ckfree((char *) prevelem); + ckfree(prevelem); } stack->depth = stack->maxdepth; } @@ -471,7 +472,53 @@ TkUndoFreeStack( TkUndoRedoStack *stack) /* An Undo/Redo stack */ { TkUndoClearStacks(stack); - ckfree((char *) stack); + ckfree(stack); +} + +/* + *---------------------------------------------------------------------- + * + * TkUndoCanRedo -- + * + * Returns true if redo is possible, i.e. if the redo stack is not empty. + * + * Results: + * A boolean. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +TkUndoCanRedo( + TkUndoRedoStack *stack) /* An Undo/Redo stack */ +{ + return stack->redoStack != NULL; +} + +/* + *---------------------------------------------------------------------- + * + * TkUndoCanUndo -- + * + * Returns true if undo is possible, i.e. if the undo stack is not empty. + * + * Results: + * A boolean. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +TkUndoCanUndo( + TkUndoRedoStack *stack) /* An Undo/Redo stack */ +{ + return stack->undoStack != NULL; } /* @@ -497,7 +544,7 @@ TkUndoInsertUndoSeparator( { if (TkUndoInsertSeparator(&stack->undoStack)) { stack->depth++; - TkUndoSetDepth(stack, stack->maxdepth); + TkUndoSetMaxDepth(stack, stack->maxdepth); } } @@ -540,7 +587,7 @@ TkUndoRevert( } if (elem->type == TK_UNDO_SEPARATOR) { - ckfree((char *) elem); + ckfree(elem); elem = TkUndoPopStack(&stack->undoStack); } @@ -602,7 +649,7 @@ TkUndoApply( } if (elem->type == TK_UNDO_SEPARATOR) { - ckfree((char *) elem); + ckfree(elem); elem = TkUndoPopStack(&stack->redoStack); } @@ -654,7 +701,7 @@ EvaluateActionList( while (action != NULL) { if (action->funcPtr != NULL) { - result = (*action->funcPtr)(interp, action->clientData, + result = action->funcPtr(interp, action->clientData, action->action); } else if (action->command != NULL) { Tcl_Obj *cmdNameObj, *evalObj; |