1
// --------------------------------------------------------------------
3
// --------------------------------------------------------------------
6
This file is part of the extensible drawing editor Ipe.
7
Copyright (C) 1993-2007 Otfried Cheong
9
Ipe is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
As a special exception, you have permission to link Ipe with the
15
CGAL library and distribute executables, as long as you follow the
16
requirements of the Gnu General Public License in regard to all of
17
the software in the executable aside from CGAL.
19
Ipe is distributed in the hope that it will be useful, but WITHOUT
20
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
22
License for more details.
24
You should have received a copy of the GNU General Public License
25
along with Ipe; if not, you can find it at
26
"http://www.gnu.org/copyleft/gpl.html", or write to the Free
27
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33
// --------------------------------------------------------------------
35
/*! \class IpeUndoItem
37
\brief Abstract base class for items on the undo stack.
40
// Implementation of pure virtual destructor.
41
IpeUndoItem::~IpeUndoItem()
46
// --------------------------------------------------------------------
48
/*! \class IpeUndoStack
50
\brief An undo stack for Ipe.
53
//! Create empty undo stack.
54
IpeUndoStack::IpeUndoStack()
59
//! Destructor destroys all items on stack.
60
IpeUndoStack::~IpeUndoStack()
62
for (uint i = 0; i < iStack.size(); ++i)
66
//! Clears the complete undo stack.
67
void IpeUndoStack::Clear()
69
for (uint i = 0; i < iStack.size(); ++i)
75
//! Add an undo item to the stack.
76
/*! If the stack is not at the end, discard remaining items.
77
Takes ownership of item. */
78
void IpeUndoStack::Add(IpeUndoItem *item)
80
for (uint i = iCur; i < iStack.size(); ++i)
83
iStack.push_back(item);
87
//! Perform an undo operation.
88
int IpeUndoStack::Undo(IpeDocument *doc)
92
return iStack[iCur]->Undo(doc);
95
//! Perform a redo operation.
96
int IpeUndoStack::Redo(IpeDocument *doc)
100
return iStack[iCur - 1]->Redo(doc);
103
//! Return text for possible undo operation.
104
IpeString IpeUndoStack::UndoText() const
107
return iStack[iCur - 1]->Text();
110
//! Return text for possible redo operation.
111
IpeString IpeUndoStack::RedoText() const
114
return iStack[iCur]->Text();
117
// --------------------------------------------------------------------
119
/*! \class IpeUndoPageEdit
121
\brief Undo item for a modification to the current page.
124
//! Takes ownership of page (a copy of the page before the modification).
125
IpeUndoPageEdit::IpeUndoPageEdit(int pno, IpePage *page, IpeString text)
132
IpeUndoPageEdit::~IpeUndoPageEdit()
137
IpeString IpeUndoPageEdit::Text() const
142
int IpeUndoPageEdit::Undo(IpeDocument *doc)
144
IpePage *p = doc->page(iPno);
145
doc->setPage(iPno, iPage);
150
// Undo swaps, so redo is identical.
151
int IpeUndoPageEdit::Redo(IpeDocument *doc)
156
// --------------------------------------------------------------------
158
/*! \class IpeUndoObjInsertion
160
\brief Undo item for the insertion of a single object.
163
IpeUndoObjInsertion::IpeUndoObjInsertion(int pno, IpeString text)
169
IpeString IpeUndoObjInsertion::Text() const
174
int IpeUndoObjInsertion::Undo(IpeDocument *doc)
176
iObj.push_back(doc->page(iPno)->back());
177
doc->page(iPno)->pop_back();
181
int IpeUndoObjInsertion::Redo(IpeDocument *doc)
183
doc->page(iPno)->push_back(iObj.back());
188
// --------------------------------------------------------------------
190
/*! \class IpeUndoPageIns
192
\brief Undo item for the insertion of a page.
195
IpeUndoPageIns::IpeUndoPageIns(int pno, IpeString text)
202
IpeString IpeUndoPageIns::Text() const
207
int IpeUndoPageIns::Undo(IpeDocument *doc)
210
iPage = doc->removePage(iPno);
214
int IpeUndoPageIns::Redo(IpeDocument *doc)
216
doc->addPage(iPno, iPage);
221
// --------------------------------------------------------------------
223
/*! \class IpeUndoPageDel
225
\brief Undo item for the deletion of an empty page.
228
IpeUndoPageDel::IpeUndoPageDel(int pno, IpePage *page, IpeString text)
235
IpeUndoPageDel::~IpeUndoPageDel()
240
IpeString IpeUndoPageDel::Text() const
245
int IpeUndoPageDel::Undo(IpeDocument *doc)
247
doc->addPage(iPno, iPage);
252
int IpeUndoPageDel::Redo(IpeDocument *doc)
255
iPage = doc->removePage(iPno);
259
// --------------------------------------------------------------------
262
/*! \class IpeUndoViews
264
\brief Undo item for change to views of a page.
267
IpeUndoViews::IpeUndoViews(int pno, IpeViewSeq views, IpeString text)
274
IpeString IpeUndoViews::Text() const
279
int IpeUndoViews::Undo(IpeDocument *doc)
281
IpeViewSeq views = doc->page(iPno)->Views();
282
doc->page(iPno)->SetViews(iViews);
287
// Undo swaps, so redo is identical.
288
int IpeUndoViews::Redo(IpeDocument *doc)
294
// --------------------------------------------------------------------
296
/*! \class IpeUndoObjectEdit
298
\brief Undo item for change to a single object.
301
IpeUndoObjectEdit::IpeUndoObjectEdit(int pno, IpePage::iterator it,
302
IpePage *page, const IpePgObject &obj,
305
IpePage::iterator it1 = page->begin();
312
iObject.push_back(obj);
316
IpeString IpeUndoObjectEdit::Text() const
321
int IpeUndoObjectEdit::Undo(IpeDocument *doc)
323
IpePage *page = doc->page(iPno);
324
IpePage::iterator it = page->begin();
325
for (int i = 0; i < iObjNum; ++i)
327
iObject.push_back(*it);
328
*it = iObject.front();
333
// Undo swaps, so redo is identical.
334
int IpeUndoObjectEdit::Redo(IpeDocument *doc)
339
// --------------------------------------------------------------------