Back to index

scribus-ng  1.3.4.dfsg+svn20071115
undostack.h
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Copyright (C) 2005 by Riku Leino                                      *
00009  *   riku@scribus.info                                                     *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025  ***************************************************************************/
00026 
00027 #ifndef UNDOSTACK_H
00028 #define UNDOSTACK_H
00029 
00030 #include <vector>
00031 
00032 class UndoState;
00033 class TransactionState;
00034 
00035 typedef std::vector<UndoState*> StateList;
00036 
00037 class SCRIBUS_API UndoStack
00038 {
00039 public:
00040     explicit UndoStack(int maxSize = 20);
00041     ~UndoStack();
00042 
00043     /* Used to push a new action to the stack. UndoState in the parameter will then
00044      * become the first undo action in the stack and all the redo actions will be
00045      * cleared. If maximum size of the stack is hit and an action needs to be removed
00046      * this function returns true. */
00047     bool action(UndoState *state);
00048 
00049     /* undo number of steps actions (these will then become redo actions) */
00050     bool undo(uint steps, int objectId);
00051     /* redo number of steps actions (these will then become undo actions) */
00052     bool redo(uint steps, int objectId);
00053 
00054     /* number of actions stored in the stack mostly for testing */
00055     uint size() const;
00056     uint undoItems() const;
00057     uint redoItems() const;
00058 
00059     /* maximum number of actions stored in the stack */
00060     uint  maxSize() const;
00061     /* Change the maximum number of actions stored in the stack. If there are
00062      * both undo and redo actions available and stack size is decreased redo
00063      * actions will be popped out first starting from the oldest one. 
00064      * 0 is used to mark infinite stack size. If one wants to disable undo/redo
00065      * function setUndoEnabled(bool) from UndoManager should be used */
00066     void setMaxSize(uint maxSize);
00067 
00068     void clear();
00069 
00070     UndoState* getNextUndo(int objectId);
00071     UndoState* getNextRedo(int objectId);
00072 
00073 private:
00074     /* When an action happens it is pushed to the undoActions_ and the redoActions_
00075      * is cleared. When undo is requested action is popped from undoActions_ and
00076      * pushed to the redoActions_ (and vice versa). */
00077     StateList undoActions_; /* stack would probably be enough for this but vector */
00078     StateList redoActions_; /* will give more options in future */
00079 
00080     /* maximum amount of actions stored, 0 for no limit */
00081     uint maxSize_;
00082 
00083     /* returns true if an action was popped from the stack */
00084     /* assures that we only hold the maxSize_ number of UndoStates */
00085     bool checkSize();
00086 
00087     friend class UndoManager; // UndoManager needs access to undoActions_ and redoActions_
00088                               // for updating the attached UndoGui widgets
00089 
00090 };
00091 
00092 #endif // UNDOSTACK_H