1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
/***************************************************************
* Name: CanvasHistory.h
* Purpose: Defines manager for stored canvas states
* Author: Michal Bližňák (michal.bliznak@tiscali.cz)
* Created: 2007-07-22
* Copyright: Michal Bližňák
* License: wxWidgets license (www.wxwidgets.org)
* Notes:
**************************************************************/
#ifndef _WXSFCANVASHISTORY_H
#define _WXSFCANVASHISTORY_H
#include <wx/wxsf/CanvasState.h>
#define sfDEFAULT_MAX_CANVAS_STATES 25
class WXDLLIMPEXP_SF wxSFShapeCanvas;
/*! \brief
* Container class that manages stored canvas states (canvas snapshots) and implements
* basic Undo/Redo functionality.
*
* Two different working modes are available: 'histUSE_SERIALIZATION' mode uses basic
* serialization functionality encapsulated by a diagram manager for storing
* of current canvas content, but in the 'histUSE_CLONING' mode full copy of
* diagram manager content is done via its copy constructor. The first mode is
* slower than the second one, but do not require implementation of xsSerializable::Clone()
* virtual function in all classes derived from xsSerializable like the second
* posible working mode.
* \sa wxSFCanvasState, wxSFCanvasHistory::MODE, xsSerializable::Clone, wxXmlSerializer::CopyItems
*/
class WXDLLIMPEXP_SF wxSFCanvasHistory : public wxObject
{
public:
enum MODE
{
/*! \brief Use serialization for storing of a canvas content */
histUSE_SERIALIZATION,
/*! \brief Use diagram manager's copy constructor for storing of a canvas content */
histUSE_CLONING
};
/*!
* \brief Default constructor.
* \param hmode Working mode (see MODE enumeration for more details)
*/
wxSFCanvasHistory(MODE hmode = histUSE_SERIALIZATION);
/*!
* \brief User constructor.
* \param canvas Pointer to managed canvas
* \param hmode Working mode (see MODE enumeration for more details)
* \sa MODE
*/
wxSFCanvasHistory(wxSFShapeCanvas *canvas, MODE hmode = histUSE_SERIALIZATION);
/*! \brief Destructor. */
~wxSFCanvasHistory(void);
// public member data accessors
/*!
* \brief Set history working mode.
*
* For more details about available working modes see the wxSFCanvasHistory class
* description. Note that all stored canvas history will be cleared after
* usage of this function.
* \param hmode Working mode
* \sa MODE
*/
void SetMode(MODE hmode);
/*! \brief
* Set total number of stored canvas states.
* \param depth Number of stored canvas states
* \sa GetHistoryDepth
*/
void SetHistoryDepth(size_t depth){m_nHistoryDepth = depth;}
/*! \brief
* Set pointer to the parent shapes canvas. All Undo/Redo operation defined by this class
* will be performed on this shape canvas instance.
* \param canvas Pointer to parent shape canvas
*/
void SetParentCanvas(wxSFShapeCanvas* canvas){m_pParentCanvas = canvas;}
/*! \brief Get currently used working mode */
MODE GetMode(){return m_nWorkingMode;}
/*! \brief
* Get total number of canvas states which can be stored at the same time.
* \return Number of allowed concuretly stored canvas states
* \sa SetHistoryDepth
*/
size_t GetHistoryDepth(){return m_nHistoryDepth;}
// public functions
/*! \brief Save current canvas state. */
void SaveCanvasState();
/*! \brief Perform the 'Undo' operation. */
void RestoreOlderState();
/*! \brief Perform the 'Redo' operation. */
void RestoreNewerState();
/*! \brief Clear all canvas history. */
void Clear();
/*! \brief
* The function gives information whether the 'Undo' operation is available
* (exists any stored canvas state older than the current one.
* \return TRUE if the 'Undo' operation can be performed, otherwise FALSE
*/
bool CanUndo();
/*! \brief
* The function gives information whether the 'Redo' operation is available
* (exists any stored canvas state newer than the current one.
* \return TRUE if the 'Undo' operation can be performed, otherwise FALSE
*/
bool CanRedo();
protected:
// protected data members
/*! \brief Pointer to the parent canvas. */
wxSFShapeCanvas * m_pParentCanvas;
/*! \brief
* List of stored canvas state instances.
* \sa wxSFCanvasState
*/
StateList m_lstCanvasStates;
/*! \brief Auxilary pointer to current canvas state. */
wxSFCanvasState *m_pCurrentCanvasState;
/*! \brief Canvas history mode */
MODE m_nWorkingMode;
/*! \brief Total allowed amount of stored canvas states. */
size_t m_nHistoryDepth;
};
#endif //_WXSFCANVASHISTORY_H
|