1 /**************************************************************************** 2 Copyright (C) 1987-2015 by Jeffery P. Hansen 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with this program; if not, write to the Free Software Foundation, Inc., 16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 ****************************************************************************/ 18 #ifndef __object_h 19 #define __object_h 20 21 /** \brief Object manager modes */ 22 typedef enum { 23 OM_DISABLED = 0, /** No object management */ 24 OM_ENABLED, /** Undoable object management */ 25 OM_START /** Start doing object management */ 26 } ob_OMMode_t; 27 28 /** \brief Frame flags */ 29 typedef enum { 30 FF_TRANSPARENT = 0x1, /** Transparent frames are not directly visible */ 31 FF_STICKY = 0x2, /** Sticky frames stick together */ 32 FF_BACKGROUND = 0x4 /** Background frames do not clear redo stack */ 33 } FrameFlags_t; 34 35 /******************************************************************************* 36 * \brief Allocate an undoable object 37 * 38 * \param s size of the object 39 * \param name typename string 40 * 41 * Allocates memory for an undoable object and tags it with a string for its 42 * type. The string passed is used as is and may not be modified or freed. 43 * by the calling program. The string is only for informational purposes and 44 * a null may be passed in its place. 45 * 46 * Typical usage is: 47 * 48 * Fooby *f = (Fooby*) ob_malloc(sizeof(Fooby),"Fooby"); 49 ******************************************************************************/ 50 void *ob_malloc(size_t s,const char *name); 51 52 /** 53 * Template macro for ob_malloc 54 */ 55 #define OM_MALLOC(T) ((T*) ob_malloc(sizeof (T), #T)) 56 57 /******************************************************************************* 58 * \brief Undoable object replacement for calloc() 59 * 60 * \param n number of the instances 61 * \param s size of the instance 62 * \param name typename for the instances 63 * 64 * Allocate a known number of similar undoable objects 65 ******************************************************************************/ 66 void *ob_calloc(unsigned n,size_t s,const char *name); 67 68 /******************************************************************************* 69 * \brief Undoable object replacement for realloc() 70 * 71 * \param vo object to be reallocated 72 * \param s new size 73 * 74 * Reallocate an undoable object 75 ******************************************************************************/ 76 void *ob_realloc(void *vo,size_t s); 77 78 /******************************************************************************* 79 * \brief Undoable object replacement for free() 80 * 81 * \param vo object to be freed 82 * 83 * Free an undoable object 84 ******************************************************************************/ 85 void ob_free(void *vo); 86 87 /******************************************************************************* 88 * \brief An "undoable" version of strdup() 89 * 90 * \param s string to be duplicated 91 * \return duplicated string 92 * 93 * Duplicate a string object 94 ******************************************************************************/ 95 char *ob_strdup(const char *s); 96 97 /****************************************************************************** 98 * \brief Initialize object handling 99 * 100 * Initialize undo/redo object management. Must be called on program start 101 * up before any calls to object handling functions. 102 ******************************************************************************/ 103 void ob_init(); 104 105 /****************************************************************************** 106 *\brief Set object handling mode 107 ******************************************************************************/ 108 109 void ob_set_mode(ob_OMMode_t m); 110 /****************************************************************************** 111 * \brief Get object handling mode 112 ******************************************************************************/ 113 ob_OMMode_t ob_get_mode(); 114 115 void ob_flush_undo(); /* Flush all undo data */ 116 void ob_touch(void*); /* Mark an object as touched */ 117 118 void ob_undo(int); /* Undo all changes in change group */ 119 void ob_redo(int); /* Redo all changes in change group */ 120 void ob_clear(); /* Clear all undo/redo data */ 121 122 void ob_begin_frame(const char*); /* Begin a set of changes */ 123 void ob_begin_framef(const char*,unsigned); /* Begin a set of changes */ 124 void ob_append_frame(const char*); /* Append a set of changes */ 125 void ob_suggest_name(const char*); /* Suggest a new name for current frame */ 126 void ob_end_frame(); /* End a set of changes */ 127 void ob_unstick(); /* Un stick the top undo frame */ 128 129 int ob_getUndoList(const char **L,int N); /* Get list of undo commands */ 130 int ob_getRedoList(const char **L,int N); /* Get list of undo commands */ 131 132 #endif 133