undo.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef _UNDO_H_
  25. #define _UNDO_H_
  26. class C_UndoStack;
  27. class C_UndoItem
  28. {
  29. friend C_UndoStack;
  30. public:
  31. C_UndoItem();
  32. ~C_UndoItem();
  33. C_UndoItem(const C_UndoItem& T);
  34. C_UndoItem(void *data, int length, bool isdirty);
  35. C_UndoItem & operator = (const C_UndoItem& T);
  36. bool operator == (const C_UndoItem& T) const;
  37. void set(void *data, int length, bool isdirty);
  38. void *get() const { return data; }
  39. int size() const { return length; }
  40. private:
  41. void *data;
  42. int length;
  43. bool isdirty;
  44. };
  45. class C_UndoStack
  46. {
  47. public:
  48. static void saveundo(int is2=0);
  49. static void cleardirty();
  50. static bool isdirty();
  51. static void undo();
  52. static void redo();
  53. static int can_undo();
  54. static int can_redo();
  55. static void clear();
  56. private:
  57. // sorry to do this mig, but that doubly linked lists made me scared. I think it
  58. // wasn't actually the source of my bug (I later fixed it), but doubly linked lists
  59. // are just plain hard to get right. :)
  60. static int list_pos;
  61. static C_UndoItem *list[256]; // only keep 256 elements in list at a time
  62. };
  63. #endif//_UNDO_H_