• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

px_ChangeHistory.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 1998 AbiSource, Inc.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 
00021 #ifndef PX_CHANGEHISTORY_H
00022 #define PX_CHANGEHISTORY_H
00023 
00024 #include "ut_types.h"
00025 #include "px_ChangeRecord.h"
00026 
00027 // px_ChangeHistory implements a history mechanism of PX_ChangeRecords.
00028 // This is used for undo and redo.  We implement a first-order undo/redo.
00029 // (We do not put undo commands into the undo history like emacs.)
00030 // As an editing operation is performed, one or more ChangeRecords will
00031 // be generated.  These are appended to the history.  The undo command
00032 // will take the last ChangeRecord and reverse its effect and decrement
00033 // the undo position.  ChangeRecords which are undone are not deleted
00034 // from the end of the history until a non-redo command is performed
00035 // (and thus invalidating what needs to be redone).  A redo command will
00036 // re-apply the ChangeRecord and advance the undo position.
00037 
00038 class pt_PieceTable;
00039 class PD_Document;
00040 
00041 class ABI_EXPORT px_ChangeHistory
00042 {
00043 public:
00044     px_ChangeHistory(pt_PieceTable * pT);
00045     ~px_ChangeHistory();
00046 
00047     // addChangeRecord -- append the given cr to the history
00048     //                    at the current position and advance
00049     //                    the current position.  also deletes
00050     //                    any (now) invalid redo items beyond
00051     //                    the current position.
00052     // getUndo -- fetch the cr immediately prior to the current
00053     //            position.
00054     // getRedo -- fetch the cr immediately after the current position.
00055     //
00056     // didUndo -- decrement the current position (to compensate for
00057     //            having just performed the undo).
00058     // didRedo -- increment the current position (to compensate for
00059     //            having just performed the redo).
00060 
00061     bool                    addChangeRecord(PX_ChangeRecord * pcr);
00062     bool                    canDo(bool bUndo) const;
00063 
00064     void                    setSavePosition(UT_sint32 savePosition);
00065     UT_sint32               getSavePosition(void) const;
00066 
00067     UT_uint32               getUndoPos(void) const;
00068 
00069     bool                    getUndo(PX_ChangeRecord ** ppcr, bool bStatic=false) const;
00070     bool                    getNthUndo(PX_ChangeRecord ** ppcr, UT_uint32 undoNdx) const;
00071     bool                    getRedo(PX_ChangeRecord ** ppcr) const;
00072     bool                    didUndo(void);
00073     bool                    didRedo(void);
00074     void                    coalesceHistory(const PX_ChangeRecord * pcr);
00075 
00076     void                    setClean(void);
00077     bool                    isDirty(void) const;
00078 
00079     void                    clearHistory();
00080     PD_Document *           getDoc(void) const;
00081     bool                    getCRRange(PX_ChangeRecord * pcr,PT_DocPosition & posLow, PT_DocPosition &posHigh) const;
00082     bool                    doesOverlap(PX_ChangeRecord * pcr, PT_DocPosition low, PT_DocPosition high) const;
00083     void                                    setScanningUndoGLOB(bool bTrue) const
00084     { m_bScanUndoGLOB = bTrue;}
00085     bool                                    isScanningUndoGLOB(void) const
00086     { return m_bScanUndoGLOB;}
00087 
00088 #ifdef PT_TEST
00089     void                    __dump(FILE* fp) const;
00090 #endif
00091 
00092 protected:
00093     void                    _invalidateRedo(void);
00094     void                    _invalidateHistory(void);
00095     void                                    _printHistory(UT_sint32 i) const;
00096 
00097     UT_GenericVector<PX_ChangeRecord *>     m_vecChangeRecords;
00098     UT_sint32               m_undoPosition;
00099     UT_sint32               m_savePosition;
00100     pt_PieceTable *         m_pPT;
00101     mutable UT_sint32       m_iAdjustOffset;
00102     mutable bool            m_bOverlap;
00103     mutable UT_sint32       m_iMinUndo;
00104     mutable bool                            m_bScanUndoGLOB;
00105 };
00106 
00107 #endif /* PX_CHANGEHISTORY_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1