Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <tools/resid.hxx>
31 : : #include <tools/string.hxx>
32 : :
33 : : #include <poolfmt.hxx>
34 : : #include <charfmt.hxx>
35 : : #include <frmfmt.hxx>
36 : : #include <SwUndoFmt.hxx>
37 : : #include <SwRewriter.hxx>
38 : : #include <swundo.hxx>
39 : : #include <undobj.hxx>
40 : : #include <fmtcol.hxx>
41 : : #include <doc.hxx>
42 : : #include <IDocumentUndoRedo.hxx>
43 : : #include <comcore.hrc>
44 : :
45 : 14 : SwUndoFmtCreate::SwUndoFmtCreate
46 : : (SwUndoId nUndoId, SwFmt * _pNew, SwFmt * _pDerivedFrom, SwDoc * _pDoc)
47 : : : SwUndo(nUndoId), pNew(_pNew),
48 [ + - ][ + - ]: 14 : pDoc(_pDoc), pNewSet(NULL), nId(0), bAuto(sal_False)
49 : : {
50 [ + - ]: 14 : if (_pDerivedFrom)
51 [ + - ]: 14 : sDerivedFrom = _pDerivedFrom->GetName();
52 : 14 : }
53 : :
54 [ + - ][ + - ]: 14 : SwUndoFmtCreate::~SwUndoFmtCreate()
55 : : {
56 [ - + ]: 14 : }
57 : :
58 : 0 : void SwUndoFmtCreate::UndoImpl(::sw::UndoRedoContext &)
59 : : {
60 [ # # ]: 0 : if (pNew)
61 : : {
62 [ # # ][ # # ]: 0 : if (sNewName.Len() == 0 && pNew)
[ # # ]
63 : 0 : sNewName = pNew->GetName();
64 : :
65 [ # # ]: 0 : if (sNewName.Len() > 0)
66 : 0 : pNew = Find(sNewName);
67 : :
68 [ # # ]: 0 : if (pNew)
69 : : {
70 [ # # ]: 0 : pNewSet = new SfxItemSet(pNew->GetAttrSet());
71 : 0 : nId = pNew->GetPoolFmtId() & COLL_GET_RANGE_BITS;
72 : 0 : bAuto = pNew->IsAuto();
73 : :
74 : 0 : Delete();
75 : : }
76 : : }
77 : 0 : }
78 : :
79 : 0 : void SwUndoFmtCreate::RedoImpl(::sw::UndoRedoContext &)
80 : : {
81 : 0 : SwFmt * pDerivedFrom = Find(sDerivedFrom);
82 : 0 : SwFmt * pFmt = Create(pDerivedFrom);
83 : :
84 [ # # ][ # # ]: 0 : if (pFmt && pNewSet)
85 : : {
86 : 0 : pFmt->SetAuto(bAuto);
87 : 0 : pDoc->ChgFmt(*pFmt, *pNewSet);
88 : 0 : pFmt->SetPoolFmtId((pFmt->GetPoolFmtId()
89 : : & ~COLL_GET_RANGE_BITS)
90 : 0 : | nId);
91 : :
92 : 0 : pNew = pFmt;
93 : : }
94 : : else
95 : 0 : pNew = NULL;
96 : 0 : }
97 : :
98 : 14 : SwRewriter SwUndoFmtCreate::GetRewriter() const
99 : : {
100 [ + - ][ + - ]: 14 : if (sNewName.Len() == 0 && pNew)
[ + - ]
101 : 14 : sNewName = pNew->GetName();
102 : :
103 : 14 : SwRewriter aRewriter;
104 : :
105 [ + - ]: 14 : aRewriter.AddRule(UndoArg1, sNewName);
106 : :
107 : 14 : return aRewriter;
108 : : }
109 : :
110 : 1271 : SwUndoFmtDelete::SwUndoFmtDelete
111 : : (SwUndoId nUndoId, SwFmt * _pOld, SwDoc * _pDoc)
112 : : : SwUndo(nUndoId),
113 : 1271 : pDoc(_pDoc), sOldName(_pOld->GetName()),
114 [ + - + - ]: 2542 : aOldSet(_pOld->GetAttrSet())
[ + - ]
115 : : {
116 [ + - ]: 1271 : sDerivedFrom = _pOld->DerivedFrom()->GetName();
117 : 1271 : nId = _pOld->GetPoolFmtId() & COLL_GET_RANGE_BITS;
118 : 1271 : bAuto = _pOld->IsAuto();
119 : 1271 : }
120 : :
121 [ + - ][ + - ]: 1269 : SwUndoFmtDelete::~SwUndoFmtDelete()
[ + - ]
122 : : {
123 [ - + ]: 1269 : }
124 : :
125 : 0 : void SwUndoFmtDelete::UndoImpl(::sw::UndoRedoContext &)
126 : : {
127 : 0 : SwFmt * pDerivedFrom = Find(sDerivedFrom);
128 : :
129 : 0 : SwFmt * pFmt = Create(pDerivedFrom);
130 : :
131 [ # # ]: 0 : if (pFmt)
132 : : {
133 : 0 : pDoc->ChgFmt(*pFmt, aOldSet);
134 : 0 : pFmt->SetAuto(bAuto);
135 : 0 : pFmt->SetPoolFmtId((pFmt->GetPoolFmtId() &
136 : : ~COLL_GET_RANGE_BITS)
137 : 0 : | nId);
138 : : }
139 : 0 : }
140 : :
141 : 0 : void SwUndoFmtDelete::RedoImpl(::sw::UndoRedoContext &)
142 : : {
143 : 0 : SwFmt * pOld = Find(sOldName);
144 : :
145 [ # # ]: 0 : if (pOld)
146 : : {
147 : 0 : Delete(pOld);
148 : : }
149 : 0 : }
150 : :
151 : 1271 : SwRewriter SwUndoFmtDelete::GetRewriter() const
152 : : {
153 : 1271 : SwRewriter aRewriter;
154 : :
155 [ + - ]: 1271 : aRewriter.AddRule(UndoArg1, sOldName);
156 : :
157 : 1271 : return aRewriter;
158 : : }
159 : :
160 : 4 : SwUndoRenameFmt::SwUndoRenameFmt(SwUndoId nUndoId,
161 : : const String & _sOldName,
162 : : const String & _sNewName,
163 : : SwDoc * _pDoc)
164 : : : SwUndo(nUndoId), sOldName(_sOldName),
165 [ + - ][ + - ]: 4 : sNewName(_sNewName), pDoc(_pDoc)
166 : : {
167 : 4 : }
168 : :
169 : :
170 [ + - ][ + - ]: 4 : SwUndoRenameFmt::~SwUndoRenameFmt()
171 : : {
172 [ - + ]: 4 : }
173 : :
174 : 0 : void SwUndoRenameFmt::UndoImpl(::sw::UndoRedoContext &)
175 : : {
176 : 0 : SwFmt * pFmt = Find(sNewName);
177 : :
178 [ # # ]: 0 : if (pFmt)
179 : : {
180 : 0 : pDoc->RenameFmt(*pFmt, sOldName, sal_True);
181 : : }
182 : 0 : }
183 : :
184 : 0 : void SwUndoRenameFmt::RedoImpl(::sw::UndoRedoContext &)
185 : : {
186 : 0 : SwFmt * pFmt = Find(sOldName);
187 : :
188 [ # # ]: 0 : if (pFmt)
189 : : {
190 : 0 : pDoc->RenameFmt(*pFmt, sNewName, sal_True);
191 : : }
192 : 0 : }
193 : :
194 : 4 : SwRewriter SwUndoRenameFmt::GetRewriter() const
195 : : {
196 : 4 : SwRewriter aRewriter;
197 : :
198 [ + - ]: 4 : aRewriter.AddRule(UndoArg1, sOldName);
199 [ + - ][ + - ]: 4 : aRewriter.AddRule(UndoArg2, SW_RES(STR_YIELDS));
[ + - ]
200 [ + - ]: 4 : aRewriter.AddRule(UndoArg3, sNewName);
201 : :
202 : 4 : return aRewriter;
203 : : }
204 : :
205 : 2 : SwUndoTxtFmtCollCreate::SwUndoTxtFmtCollCreate
206 : : (SwTxtFmtColl * _pNew, SwTxtFmtColl * _pDerivedFrom, SwDoc * _pDoc)
207 : 2 : : SwUndoFmtCreate(UNDO_TXTFMTCOL_CREATE, _pNew, _pDerivedFrom, _pDoc)
208 : : {
209 : 2 : }
210 : :
211 : 0 : SwFmt * SwUndoTxtFmtCollCreate::Create(SwFmt * pDerivedFrom)
212 : : {
213 : 0 : return pDoc->MakeTxtFmtColl(sNewName, (SwTxtFmtColl *)pDerivedFrom, sal_True);
214 : : }
215 : :
216 : 0 : void SwUndoTxtFmtCollCreate::Delete()
217 : : {
218 : 0 : pDoc->DelTxtFmtColl((SwTxtFmtColl *) pNew, sal_True);
219 : 0 : }
220 : :
221 : 0 : SwFmt * SwUndoTxtFmtCollCreate::Find(const String & rName) const
222 : : {
223 : 0 : return pDoc->FindTxtFmtCollByName(rName);
224 : : }
225 : :
226 : 0 : SwUndoTxtFmtCollDelete::SwUndoTxtFmtCollDelete(SwTxtFmtColl * _pOld,
227 : : SwDoc * _pDoc)
228 : 0 : : SwUndoFmtDelete(UNDO_TXTFMTCOL_DELETE, _pOld, _pDoc)
229 : : {
230 : 0 : }
231 : :
232 : 0 : SwFmt * SwUndoTxtFmtCollDelete::Create(SwFmt * pDerivedFrom)
233 : : {
234 : 0 : return pDoc->MakeTxtFmtColl(sOldName, (SwTxtFmtColl *) pDerivedFrom, sal_True);
235 : : }
236 : :
237 : 0 : void SwUndoTxtFmtCollDelete::Delete(SwFmt * pOld)
238 : : {
239 : 0 : pDoc->DelTxtFmtColl((SwTxtFmtColl *) pOld, sal_True);
240 : 0 : }
241 : :
242 : 0 : SwFmt * SwUndoTxtFmtCollDelete::Find(const String & rName) const
243 : : {
244 : 0 : return pDoc->FindTxtFmtCollByName(rName);
245 : : }
246 : :
247 : 4 : SwUndoRenameFmtColl::SwUndoRenameFmtColl(const String & sInitOldName,
248 : : const String & sInitNewName,
249 : : SwDoc * _pDoc)
250 : 4 : : SwUndoRenameFmt(UNDO_TXTFMTCOL_RENAME, sInitOldName, sInitNewName, _pDoc)
251 : : {
252 : 4 : }
253 : :
254 : 0 : SwFmt * SwUndoRenameFmtColl::Find(const String & rName) const
255 : : {
256 : 0 : return pDoc->FindTxtFmtCollByName(rName);
257 : : }
258 : :
259 : 12 : SwUndoCharFmtCreate::SwUndoCharFmtCreate(SwCharFmt * pNewFmt,
260 : : SwCharFmt * pDerivedFrom,
261 : : SwDoc * pDocument)
262 : 12 : : SwUndoFmtCreate(UNDO_CHARFMT_CREATE, pNewFmt, pDerivedFrom, pDocument)
263 : : {
264 : 12 : }
265 : :
266 : 0 : SwFmt * SwUndoCharFmtCreate::Create(SwFmt * pDerivedFrom)
267 : : {
268 : 0 : return pDoc->MakeCharFmt(sNewName, (SwCharFmt *) pDerivedFrom, sal_True);
269 : : }
270 : :
271 : 0 : void SwUndoCharFmtCreate::Delete()
272 : : {
273 : 0 : pDoc->DelCharFmt((SwCharFmt *) pNew, sal_True);
274 : 0 : }
275 : :
276 : 0 : SwFmt * SwUndoCharFmtCreate::Find(const String & rName) const
277 : : {
278 : 0 : return pDoc->FindCharFmtByName(rName);
279 : : }
280 : :
281 : 2 : SwUndoCharFmtDelete::SwUndoCharFmtDelete(SwCharFmt * pOld, SwDoc * pDocument)
282 : 2 : : SwUndoFmtDelete(UNDO_CHARFMT_DELETE, pOld, pDocument)
283 : : {
284 : 2 : }
285 : :
286 : 0 : SwFmt * SwUndoCharFmtDelete::Create(SwFmt * pDerivedFrom)
287 : : {
288 : 0 : return pDoc->MakeCharFmt(sOldName, (SwCharFmt *) pDerivedFrom, sal_True);
289 : : }
290 : :
291 : 0 : void SwUndoCharFmtDelete::Delete(SwFmt * pFmt)
292 : : {
293 : 0 : pDoc->DelCharFmt((SwCharFmt *) pFmt, sal_True);
294 : 0 : }
295 : :
296 : 0 : SwFmt * SwUndoCharFmtDelete::Find(const String & rName) const
297 : : {
298 : 0 : return pDoc->FindCharFmtByName(rName);
299 : : }
300 : :
301 : 0 : SwUndoRenameCharFmt::SwUndoRenameCharFmt(const String & sInitOldName,
302 : : const String & sInitNewName,
303 : : SwDoc * pDocument)
304 : 0 : : SwUndoRenameFmt(UNDO_CHARFMT_RENAME, sInitOldName, sInitNewName, pDocument)
305 : : {
306 : 0 : }
307 : :
308 : 0 : SwFmt * SwUndoRenameCharFmt::Find(const String & rName) const
309 : : {
310 : 0 : return pDoc->FindCharFmtByName(rName);
311 : : }
312 : :
313 : 0 : SwUndoFrmFmtCreate::SwUndoFrmFmtCreate(SwFrmFmt * pNewFmt,
314 : : SwFrmFmt * pDerivedFrom,
315 : : SwDoc * pDocument)
316 : : : SwUndoFmtCreate(UNDO_FRMFMT_CREATE, pNewFmt, pDerivedFrom, pDocument),
317 : 0 : bAuto(pNewFmt->IsAuto())
318 : : {
319 : 0 : }
320 : :
321 : 0 : SwFmt * SwUndoFrmFmtCreate::Create(SwFmt * pDerivedFrom)
322 : : {
323 : 0 : return pDoc->MakeFrmFmt(sNewName, (SwFrmFmt *) pDerivedFrom, sal_True, bAuto);
324 : : }
325 : :
326 : 0 : void SwUndoFrmFmtCreate::Delete()
327 : : {
328 : 0 : pDoc->DelFrmFmt((SwFrmFmt *) pNew, sal_True);
329 : 0 : }
330 : :
331 : 0 : SwFmt * SwUndoFrmFmtCreate::Find(const String & rName) const
332 : : {
333 : 0 : return pDoc->FindFrmFmtByName(rName);
334 : : }
335 : :
336 : 1269 : SwUndoFrmFmtDelete::SwUndoFrmFmtDelete(SwFrmFmt * pOld, SwDoc * pDocument)
337 : 1269 : : SwUndoFmtDelete(UNDO_FRMFMT_DELETE, pOld, pDocument)
338 : : {
339 : 1269 : }
340 : :
341 : 0 : SwFmt * SwUndoFrmFmtDelete::Create(SwFmt * pDerivedFrom)
342 : : {
343 : 0 : return pDoc->MakeFrmFmt(sOldName, (SwFrmFmt *) pDerivedFrom, sal_True);
344 : : }
345 : :
346 : 0 : void SwUndoFrmFmtDelete::Delete(SwFmt * pFmt)
347 : : {
348 : 0 : pDoc->DelFrmFmt((SwFrmFmt *) pFmt, sal_True);
349 : 0 : }
350 : :
351 : 0 : SwFmt * SwUndoFrmFmtDelete::Find(const String & rName) const
352 : : {
353 : 0 : return pDoc->FindFrmFmtByName(rName);
354 : : }
355 : :
356 : 0 : SwUndoRenameFrmFmt::SwUndoRenameFrmFmt(const String & sInitOldName,
357 : : const String & sInitNewName,
358 : : SwDoc * pDocument)
359 : 0 : : SwUndoRenameFmt(UNDO_FRMFMT_RENAME, sInitOldName, sInitNewName, pDocument)
360 : : {
361 : 0 : }
362 : :
363 : 0 : SwFmt * SwUndoRenameFrmFmt::Find(const String & rName) const
364 : : {
365 : 0 : return pDoc->FindFrmFmtByName(rName);
366 : : }
367 : :
368 : 2 : SwUndoNumruleCreate::SwUndoNumruleCreate(const SwNumRule * _pNew,
369 : : SwDoc * _pDoc)
370 : : : SwUndo(UNDO_NUMRULE_CREATE), pNew(_pNew), aNew(*_pNew), pDoc(_pDoc),
371 [ + - ]: 2 : bInitialized(false)
372 : : {
373 : 2 : }
374 : :
375 : 0 : void SwUndoNumruleCreate::UndoImpl(::sw::UndoRedoContext &)
376 : : {
377 [ # # ]: 0 : if (! bInitialized)
378 : : {
379 : 0 : aNew = *pNew;
380 : 0 : bInitialized = true;
381 : : }
382 : :
383 : 0 : pDoc->DelNumRule(aNew.GetName(), sal_True);
384 : 0 : }
385 : :
386 : 0 : void SwUndoNumruleCreate::RedoImpl(::sw::UndoRedoContext &)
387 : : {
388 : 0 : pDoc->MakeNumRule(aNew.GetName(), &aNew, sal_True);
389 : 0 : }
390 : :
391 : 2 : SwRewriter SwUndoNumruleCreate::GetRewriter() const
392 : : {
393 : 2 : SwRewriter aResult;
394 : :
395 [ + - ]: 2 : if (! bInitialized)
396 : : {
397 [ + - ]: 2 : aNew = *pNew;
398 : 2 : bInitialized = true;
399 : : }
400 : :
401 [ + - ]: 2 : aResult.AddRule(UndoArg1, aNew.GetName());
402 : :
403 : 2 : return aResult;
404 : : }
405 : :
406 : 0 : SwUndoNumruleDelete::SwUndoNumruleDelete(const SwNumRule & rRule,
407 : : SwDoc * _pDoc)
408 [ # # ]: 0 : : SwUndo(UNDO_NUMRULE_DELETE), aOld(rRule), pDoc(_pDoc)
409 : : {
410 : 0 : }
411 : :
412 : 0 : void SwUndoNumruleDelete::UndoImpl(::sw::UndoRedoContext &)
413 : : {
414 : 0 : pDoc->MakeNumRule(aOld.GetName(), &aOld, sal_True);
415 : 0 : }
416 : :
417 : 0 : void SwUndoNumruleDelete::RedoImpl(::sw::UndoRedoContext &)
418 : : {
419 : 0 : pDoc->DelNumRule(aOld.GetName(), sal_True);
420 : 0 : }
421 : :
422 : 0 : SwRewriter SwUndoNumruleDelete::GetRewriter() const
423 : : {
424 : 0 : SwRewriter aResult;
425 : :
426 [ # # ]: 0 : aResult.AddRule(UndoArg1, aOld.GetName());
427 : :
428 : 0 : return aResult;
429 : : }
430 : :
431 : 0 : SwUndoNumruleRename::SwUndoNumruleRename(const String & _aOldName,
432 : : const String & _aNewName,
433 : : SwDoc * _pDoc)
434 : : : SwUndo(UNDO_NUMRULE_RENAME), aOldName(_aOldName), aNewName(_aNewName),
435 [ # # ][ # # ]: 0 : pDoc(_pDoc)
436 : : {
437 : 0 : }
438 : :
439 : 0 : void SwUndoNumruleRename::UndoImpl(::sw::UndoRedoContext &)
440 : : {
441 : 0 : pDoc->RenameNumRule(aNewName, aOldName, sal_True);
442 : 0 : }
443 : :
444 : 0 : void SwUndoNumruleRename::RedoImpl(::sw::UndoRedoContext &)
445 : : {
446 : 0 : pDoc->RenameNumRule(aOldName, aNewName, sal_True);
447 : 0 : }
448 : :
449 : 0 : SwRewriter SwUndoNumruleRename::GetRewriter() const
450 : : {
451 : 0 : SwRewriter aRewriter;
452 : :
453 [ # # ]: 0 : aRewriter.AddRule(UndoArg1, aOldName);
454 [ # # ][ # # ]: 0 : aRewriter.AddRule(UndoArg2, SW_RESSTR(STR_YIELDS));
[ # # ][ # # ]
455 [ # # ]: 0 : aRewriter.AddRule(UndoArg3, aNewName);
456 : :
457 : 0 : return aRewriter;
458 : : }
459 : :
460 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|