home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / state_change_set.h < prev    next >
C/C++ Source or Header  |  2008-01-23  |  4KB  |  105 lines

  1. #ifndef K3DSDK_STATE_CHANGE_SET_H
  2. #define K3DSDK_STATE_CHANGE_SET_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2005, Timothy M. Shead
  6. //
  7. // Contact: tshead@k-3d.com
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. // General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public
  20. // License along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. /** \file
  24.     \author Tim Shead (tshead@k-3d.com)
  25. */
  26.  
  27. #include "signal_system.h"
  28.  
  29. #include <memory>
  30. #include <string>
  31.  
  32. namespace k3d
  33. {
  34.  
  35. class idocument;
  36. class istate_container;
  37.  
  38. /// Stores an atomic set of state changes that can be undone / redone
  39. class state_change_set
  40. {
  41. public:
  42.     state_change_set();
  43.     ~state_change_set();
  44.  
  45.     /// Records an original state that should be restored as part of an "undo" operation (assumes ownership of the given state container)
  46.     void record_old_state(k3d::istate_container* const OldState);
  47.     /// Records a new state that should be restored as part of a "redo" operation (assumes ownership of the given state container)
  48.     void record_new_state(k3d::istate_container* const NewState);
  49.  
  50.     /// Connects a slot that will be called if this change set is undone
  51.     sigc::connection connect_undo_signal(const sigc::slot<void>& Slot);
  52.     /// Connects a slot that will be called if this change set is redone
  53.     sigc::connection connect_redo_signal(const sigc::slot<void>& Slot);
  54.  
  55.     /// Restores original states and emits the undo_signal
  56.     void undo();
  57.     /// Restores new states and emits the redo signal
  58.     void redo();
  59.  
  60.     /// Returns the number of stored undo state containers (mainly for debugging)
  61.     const size_t undo_count() const;
  62.     /// Returns the number of stored redo state containers (mainly for debugging)
  63.     const size_t redo_count() const;
  64.     
  65. private:
  66.     state_change_set(const state_change_set&);
  67.     state_change_set& operator=(const state_change_set&);
  68.  
  69.     class implementation;
  70.     implementation* const m_implementation;
  71. };
  72.  
  73. #define K3D_CHANGE_SET_CONTEXT_STRINGIZE2(x) #x
  74. #define K3D_CHANGE_SET_CONTEXT_STRINGIZE(x) K3D_CHANGE_SET_CONTEXT_STRINGIZE2(x)
  75. #define K3D_CHANGE_SET_CONTEXT __FILE__ " (" K3D_CHANGE_SET_CONTEXT_STRINGIZE(__LINE__) ")"
  76.  
  77. /// Factory function for creating standard state change set objects
  78. std::auto_ptr<state_change_set> create_state_change_set(const char* const Context);
  79. /// Convenience function that starts recording a state change set for undo/redo purposes
  80. void start_state_change_set(idocument& Document, const char* const Context);
  81. /// Convenience function that cancels recording the current state change set
  82. void cancel_state_change_set(idocument& Document, const char* const Context);
  83. /// Convenience function that finishes recording a state change set for undo/redo purposes
  84. void finish_state_change_set(idocument& Document, const std::string& Label, const char* const Context);
  85.  
  86. /** \brief RAII helper class that provides  a return- and exception-safe way to record state changes for UNDO purposes
  87.     \note You should prefer to use this class whenever possible, instead of start_state_change_set() / finish_state_change_set()
  88. */
  89. class record_state_change_set
  90. {
  91. public:
  92.     record_state_change_set(idocument& Document, const std::string& Label, const char* const Context);
  93.     ~record_state_change_set();
  94.  
  95. private:
  96.     idocument& m_document;
  97.     const std::string m_label;
  98.     const char* const m_context;
  99. };
  100.  
  101. } // namespace k3d
  102.  
  103. #endif // !K3DSDK_STATE_CHANGE_SET_H
  104.  
  105.