~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipelib/ipeundo.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2009-12-11 21:22:35 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091211212235-5iio4nzpra64snab
Tags: 7.0.10-1
* New upstream.  Closes: #551192.
  - New build-depends: libcairo2-dev, liblua5.1-0-dev, gsfonts
  - patches/config.diff: Remove.  Upstream build system replaced.
  - Runtime lib package changed to libipe7.0.10 from libipe1c2a
  - Devel package renamed to libipe-dev (from libipe1-dev)
  - Package ipe depends on lua5.1 due to ipe-update-master.

* rules: Re-write to use dh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// --------------------------------------------------------------------
2
 
// Undo
3
 
// --------------------------------------------------------------------
4
 
/*
5
 
 
6
 
    This file is part of the extensible drawing editor Ipe.
7
 
    Copyright (C) 1993-2007  Otfried Cheong
8
 
 
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.
13
 
 
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.
18
 
 
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.
23
 
 
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.
28
 
 
29
 
*/
30
 
 
31
 
#include "ipeundo.h"
32
 
 
33
 
// --------------------------------------------------------------------
34
 
 
35
 
/*! \class IpeUndoItem
36
 
  \ingroup high
37
 
  \brief Abstract base class for items on the undo stack.
38
 
*/
39
 
 
40
 
// Implementation of pure virtual destructor.
41
 
IpeUndoItem::~IpeUndoItem()
42
 
{
43
 
  // nothing
44
 
}
45
 
 
46
 
// --------------------------------------------------------------------
47
 
 
48
 
/*! \class IpeUndoStack
49
 
  \ingroup high
50
 
  \brief An undo stack for Ipe.
51
 
*/
52
 
 
53
 
//! Create empty undo stack.
54
 
IpeUndoStack::IpeUndoStack()
55
 
{
56
 
  iCur = 0;
57
 
}
58
 
 
59
 
//! Destructor destroys all items on stack.
60
 
IpeUndoStack::~IpeUndoStack()
61
 
{
62
 
  for (uint i = 0; i < iStack.size(); ++i)
63
 
    delete iStack[i];
64
 
}
65
 
 
66
 
//! Clears the complete undo stack.
67
 
void IpeUndoStack::Clear()
68
 
{
69
 
  for (uint i = 0; i < iStack.size(); ++i)
70
 
    delete iStack[i];
71
 
  iStack.clear();
72
 
  iCur = 0;
73
 
}
74
 
 
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)
79
 
{
80
 
  for (uint i = iCur; i < iStack.size(); ++i)
81
 
    delete iStack[i];
82
 
  iStack.resize(iCur);
83
 
  iStack.push_back(item);
84
 
  iCur = iStack.size();
85
 
}
86
 
 
87
 
//! Perform an undo operation.
88
 
int IpeUndoStack::Undo(IpeDocument *doc)
89
 
{
90
 
  assert(CanUndo());
91
 
  --iCur;
92
 
  return iStack[iCur]->Undo(doc);
93
 
}
94
 
 
95
 
//! Perform a redo operation.
96
 
int IpeUndoStack::Redo(IpeDocument *doc)
97
 
{
98
 
  assert(CanRedo());
99
 
  ++iCur;
100
 
  return iStack[iCur - 1]->Redo(doc);
101
 
}
102
 
 
103
 
//! Return text for possible undo operation.
104
 
IpeString IpeUndoStack::UndoText() const
105
 
{
106
 
  assert(CanUndo());
107
 
  return iStack[iCur - 1]->Text();
108
 
}
109
 
 
110
 
//! Return text for possible redo operation.
111
 
IpeString IpeUndoStack::RedoText() const
112
 
{
113
 
  assert(CanRedo());
114
 
  return iStack[iCur]->Text();
115
 
}
116
 
 
117
 
// --------------------------------------------------------------------
118
 
 
119
 
/*! \class IpeUndoPageEdit
120
 
  \ingroup high
121
 
  \brief Undo item for a modification to the current page.
122
 
*/
123
 
 
124
 
//! Takes ownership of page (a copy of the page before the modification).
125
 
IpeUndoPageEdit::IpeUndoPageEdit(int pno, IpePage *page, IpeString text)
126
 
{
127
 
  iPno = pno;
128
 
  iPage = page;
129
 
  iText = text;
130
 
}
131
 
 
132
 
IpeUndoPageEdit::~IpeUndoPageEdit()
133
 
{
134
 
  delete iPage;
135
 
}
136
 
 
137
 
IpeString IpeUndoPageEdit::Text() const
138
 
{
139
 
  return iText;
140
 
}
141
 
 
142
 
int IpeUndoPageEdit::Undo(IpeDocument *doc)
143
 
{
144
 
  IpePage *p = doc->page(iPno);
145
 
  doc->setPage(iPno, iPage);
146
 
  iPage = p;
147
 
  return iPno;
148
 
}
149
 
 
150
 
// Undo swaps, so redo is identical.
151
 
int IpeUndoPageEdit::Redo(IpeDocument *doc)
152
 
{
153
 
  return Undo(doc);
154
 
}
155
 
 
156
 
// --------------------------------------------------------------------
157
 
 
158
 
/*! \class IpeUndoObjInsertion
159
 
  \ingroup high
160
 
  \brief Undo item for the insertion of a single object.
161
 
*/
162
 
 
163
 
IpeUndoObjInsertion::IpeUndoObjInsertion(int pno, IpeString text)
164
 
{
165
 
  iPno = pno;
166
 
  iText = text;
167
 
}
168
 
 
169
 
IpeString IpeUndoObjInsertion::Text() const
170
 
{
171
 
  return iText;
172
 
}
173
 
 
174
 
int IpeUndoObjInsertion::Undo(IpeDocument *doc)
175
 
{
176
 
  iObj.push_back(doc->page(iPno)->back());
177
 
  doc->page(iPno)->pop_back();
178
 
  return iPno;
179
 
}
180
 
 
181
 
int IpeUndoObjInsertion::Redo(IpeDocument *doc)
182
 
{
183
 
  doc->page(iPno)->push_back(iObj.back());
184
 
  iObj.clear();
185
 
  return iPno;
186
 
}
187
 
 
188
 
// --------------------------------------------------------------------
189
 
 
190
 
/*! \class IpeUndoPageIns
191
 
  \ingroup high
192
 
  \brief Undo item for the insertion of a page.
193
 
*/
194
 
 
195
 
IpeUndoPageIns::IpeUndoPageIns(int pno, IpeString text)
196
 
{
197
 
  iPno = pno;
198
 
  iPage = 0;
199
 
  iText = text;
200
 
}
201
 
 
202
 
IpeString IpeUndoPageIns::Text() const
203
 
{
204
 
  return iText;
205
 
}
206
 
 
207
 
int IpeUndoPageIns::Undo(IpeDocument *doc)
208
 
{
209
 
  assert(iPage == 0);
210
 
  iPage = doc->removePage(iPno);
211
 
  return iPno;
212
 
}
213
 
 
214
 
int IpeUndoPageIns::Redo(IpeDocument *doc)
215
 
{
216
 
  doc->addPage(iPno, iPage);
217
 
  iPage = 0;
218
 
  return iPno;
219
 
}
220
 
 
221
 
// --------------------------------------------------------------------
222
 
 
223
 
/*! \class IpeUndoPageDel
224
 
  \ingroup high
225
 
  \brief Undo item for the deletion of an empty page.
226
 
*/
227
 
 
228
 
IpeUndoPageDel::IpeUndoPageDel(int pno, IpePage *page, IpeString text)
229
 
{
230
 
  iPno = pno;
231
 
  iPage = page;
232
 
  iText = text;
233
 
}
234
 
 
235
 
IpeUndoPageDel::~IpeUndoPageDel()
236
 
{
237
 
  delete iPage;
238
 
}
239
 
 
240
 
IpeString IpeUndoPageDel::Text() const
241
 
{
242
 
  return iText;
243
 
}
244
 
 
245
 
int IpeUndoPageDel::Undo(IpeDocument *doc)
246
 
{
247
 
  doc->addPage(iPno, iPage);
248
 
  iPage = 0;
249
 
  return iPno;
250
 
}
251
 
 
252
 
int IpeUndoPageDel::Redo(IpeDocument *doc)
253
 
{
254
 
  assert(iPage == 0);
255
 
  iPage = doc->removePage(iPno);
256
 
  return iPno;
257
 
}
258
 
 
259
 
// --------------------------------------------------------------------
260
 
 
261
 
#if 0
262
 
/*! \class IpeUndoViews
263
 
  \ingroup high
264
 
  \brief Undo item for change to views of a page.
265
 
*/
266
 
 
267
 
IpeUndoViews::IpeUndoViews(int pno, IpeViewSeq views, IpeString text)
268
 
{
269
 
  iPno = pno;
270
 
  iViews = views;
271
 
  iText = text;
272
 
}
273
 
 
274
 
IpeString IpeUndoViews::Text() const
275
 
{
276
 
  return iText;
277
 
}
278
 
 
279
 
int IpeUndoViews::Undo(IpeDocument *doc)
280
 
{
281
 
  IpeViewSeq views = doc->page(iPno)->Views();
282
 
  doc->page(iPno)->SetViews(iViews);
283
 
  iViews = views;
284
 
  return iPno;
285
 
}
286
 
 
287
 
// Undo swaps, so redo is identical.
288
 
int IpeUndoViews::Redo(IpeDocument *doc)
289
 
{
290
 
  return Undo(doc);
291
 
}
292
 
#endif
293
 
 
294
 
// --------------------------------------------------------------------
295
 
 
296
 
/*! \class IpeUndoObjectEdit
297
 
  \ingroup high
298
 
  \brief Undo item for change to a single object.
299
 
*/
300
 
 
301
 
IpeUndoObjectEdit::IpeUndoObjectEdit(int pno, IpePage::iterator it,
302
 
                                     IpePage *page, const IpePgObject &obj,
303
 
                                     IpeString text)
304
 
{
305
 
  IpePage::iterator it1 = page->begin();
306
 
  iObjNum = 0;
307
 
  while (it1 != it) {
308
 
    ++it1;
309
 
    ++iObjNum;
310
 
  }
311
 
  iPno = pno;
312
 
  iObject.push_back(obj);
313
 
  iText = text;
314
 
}
315
 
 
316
 
IpeString IpeUndoObjectEdit::Text() const
317
 
{
318
 
  return iText;
319
 
}
320
 
 
321
 
int IpeUndoObjectEdit::Undo(IpeDocument *doc)
322
 
{
323
 
  IpePage *page = doc->page(iPno);
324
 
  IpePage::iterator it = page->begin();
325
 
  for (int i = 0; i < iObjNum; ++i)
326
 
    ++it;
327
 
  iObject.push_back(*it);
328
 
  *it = iObject.front();
329
 
  iObject.pop_front();
330
 
  return iPno;
331
 
}
332
 
 
333
 
// Undo swaps, so redo is identical.
334
 
int IpeUndoObjectEdit::Redo(IpeDocument *doc)
335
 
{
336
 
  return Undo(doc);
337
 
}
338
 
 
339
 
// --------------------------------------------------------------------