home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / include / undo.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.6 KB  |  127 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.  
  20. /*
  21.   undo.h --- creating and maintaining an undo list.
  22.   Created: Terry Weissman <terry@netscape.com>, 9-Sept-95.
  23. */
  24.  
  25. #ifndef _UNDO_H_
  26. #define _UNDO_H_
  27.  
  28.  
  29.  
  30. typedef struct UndoState UndoState;
  31.  
  32.  
  33. XP_BEGIN_PROTOS
  34.  
  35. /* Create a new undo state. (Returns NULL if no memory available). State will
  36.    be saved to execute up to "maxdepth" undos in a row.*/
  37. extern UndoState* UNDO_Create(int maxdepth);
  38.  
  39.  
  40. /* Throw away the undo state. */
  41. extern void UNDO_Destroy(UndoState* state);
  42.  
  43.  
  44. /* Throw away all the queued events in the undo state.  If we are in the middle
  45.    of a batch (there are outstanding calls to UNDO_StartBatch()), then future
  46.    events in the batch are also thrown away. */
  47. extern void UNDO_DiscardAll(UndoState* state);
  48.  
  49. /* Mark the beginning of a bunch of actions that should be undone as one user
  50.    action.  Should always be matched by a later call to UNDO_EndBatch().
  51.    These calls can nest.  They fail only if running out of memory, in which
  52.    case they will call UNDO_DiscardAll(). */
  53.    
  54. /* Note you can use the tag arguments to associate a batch of events with 
  55.    some user defined tag e.g., a name or object identifying the batch of events */
  56.    
  57. extern int UNDO_StartBatch(UndoState* state);
  58.  
  59. extern int UNDO_EndBatch(UndoState* state, void (*freetag)(void*), void* tag);
  60.  
  61.  
  62. /* Returns TRUE if undoing will do something (i.e., the menu item for "Undo"
  63.    should be selectable). */
  64.  
  65. extern XP_Bool UNDO_CanUndo(UndoState* state);
  66.  
  67.  
  68. /* Returns TRUE if redoing will do something (i.e., the menu item for "Redo"
  69.    should be selectable). */
  70.  
  71. extern XP_Bool UNDO_CanRedo(UndoState* state);
  72.  
  73.  
  74. /* Actually do an undo.  Should only be called if UNDO_CanUndo returned TRUE.
  75.    May not be called if there are any pending calls to UNDO_StartBatch. */
  76.  
  77. extern int UNDO_DoUndo(UndoState* state);
  78.  
  79.  
  80. /* Actually do an redo.  Should only be called if UNDO_CanRedo returned TRUE.
  81.    May not be called if there are any pending calls to UNDO_StartBatch. */
  82.  
  83. extern int UNDO_DoRedo(UndoState* state);
  84.  
  85.  
  86. /* Log an event.  The "undoit" function is to be called with the closure to
  87.    undo an event that just happened.  It returns a success code; if negative,
  88.    the code will be propagated up to the call to UNDO_DoUndo and UNDO_DoRedo,
  89.    and UNDO_DiscardAll will be called.  Note that the undoit function almost
  90.    always ends up calling UNDO_LogEvent again, to log the function to undo thie
  91.    undoing of this action.  If you get my drift.
  92.  
  93.    The "freeit" function is called when the undo library decides it will never
  94.    ever call undoit function.  It is called with the closure to free storage
  95.    used by the closure.
  96.  
  97.    If this fails (we ran out of memory), then it will return a negative failure
  98.    code, and call UNDO_DiscardAll() and the freeit func. */
  99.    
  100. /* Note you can use the tag arguments to associate the event with 
  101.    some user defined tag e.g., a name or object identifying the event. */
  102.  
  103. #ifdef XP_OS2
  104. typedef int (*PNSLUFN)(void *);
  105. typedef void (*PNSLFFN)(void *);
  106. extern int UNDO_LogEvent(UndoState* state, PNSLUFN undoit,
  107.                          PNSLFFN freeit, void* closure,
  108.                          PNSLFFN freetag, void* tag);
  109. #else
  110. extern int UNDO_LogEvent(UndoState* state, int (*undoit)(void*),
  111.                          void (*freeit)(void*), void* closure,
  112.                          void (*freetag)(void*), void* tag);
  113. #endif
  114.  
  115. /* Retrieve the undo/redo tag from the top of the corresponding stack.  The
  116.    tag is the "thing" YOU assigned during either an UNDO_EndBatch() or
  117.    UNDO_LogEvent call.  You most likely use the tag to identify the event[s]
  118.    that can be undone/redone.
  119.    e.g., Label the Edit|Undo menu item with, say, Edit|Undo Delete. */
  120.    
  121. extern void *UNDO_PeekUndoTag(UndoState* state);
  122. extern void *UNDO_PeekRedoTag(UndoState* state);
  123.  
  124. XP_END_PROTOS
  125.  
  126. #endif /* !_UNDO_H_ */
  127.