1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <tools/resid.hxx>
22 #include <tools/string.hxx>
24 #include <poolfmt.hxx>
25 #include <charfmt.hxx>
27 #include <SwUndoFmt.hxx>
28 #include <SwRewriter.hxx>
33 #include <IDocumentUndoRedo.hxx>
34 #include <comcore.hrc>
36 SwUndoFmtCreate::SwUndoFmtCreate
37 (SwUndoId nUndoId
, SwFmt
* _pNew
, SwFmt
* _pDerivedFrom
, SwDoc
* _pDoc
)
38 : SwUndo(nUndoId
), pNew(_pNew
),
39 pDoc(_pDoc
), pNewSet(NULL
), nId(0), bAuto(sal_False
)
42 sDerivedFrom
= _pDerivedFrom
->GetName();
45 SwUndoFmtCreate::~SwUndoFmtCreate()
49 void SwUndoFmtCreate::UndoImpl(::sw::UndoRedoContext
&)
53 if (sNewName
.Len() == 0 && pNew
)
54 sNewName
= pNew
->GetName();
56 if (sNewName
.Len() > 0)
57 pNew
= Find(sNewName
);
61 pNewSet
= new SfxItemSet(pNew
->GetAttrSet());
62 nId
= pNew
->GetPoolFmtId() & COLL_GET_RANGE_BITS
;
63 bAuto
= pNew
->IsAuto();
70 void SwUndoFmtCreate::RedoImpl(::sw::UndoRedoContext
&)
72 SwFmt
* pDerivedFrom
= Find(sDerivedFrom
);
73 SwFmt
* pFmt
= Create(pDerivedFrom
);
78 pDoc
->ChgFmt(*pFmt
, *pNewSet
);
79 pFmt
->SetPoolFmtId((pFmt
->GetPoolFmtId()
80 & ~COLL_GET_RANGE_BITS
)
89 SwRewriter
SwUndoFmtCreate::GetRewriter() const
91 if (sNewName
.Len() == 0 && pNew
)
92 sNewName
= pNew
->GetName();
96 aRewriter
.AddRule(UndoArg1
, sNewName
);
101 SwUndoFmtDelete::SwUndoFmtDelete
102 (SwUndoId nUndoId
, SwFmt
* _pOld
, SwDoc
* _pDoc
)
104 pDoc(_pDoc
), sOldName(_pOld
->GetName()),
105 aOldSet(_pOld
->GetAttrSet())
107 sDerivedFrom
= _pOld
->DerivedFrom()->GetName();
108 nId
= _pOld
->GetPoolFmtId() & COLL_GET_RANGE_BITS
;
109 bAuto
= _pOld
->IsAuto();
112 SwUndoFmtDelete::~SwUndoFmtDelete()
116 void SwUndoFmtDelete::UndoImpl(::sw::UndoRedoContext
&)
118 SwFmt
* pDerivedFrom
= Find(sDerivedFrom
);
120 SwFmt
* pFmt
= Create(pDerivedFrom
);
124 pDoc
->ChgFmt(*pFmt
, aOldSet
);
125 pFmt
->SetAuto(bAuto
);
126 pFmt
->SetPoolFmtId((pFmt
->GetPoolFmtId() &
127 ~COLL_GET_RANGE_BITS
)
132 void SwUndoFmtDelete::RedoImpl(::sw::UndoRedoContext
&)
134 SwFmt
* pOld
= Find(sOldName
);
142 SwRewriter
SwUndoFmtDelete::GetRewriter() const
144 SwRewriter aRewriter
;
146 aRewriter
.AddRule(UndoArg1
, sOldName
);
151 SwUndoRenameFmt::SwUndoRenameFmt(SwUndoId nUndoId
,
152 const String
& _sOldName
,
153 const String
& _sNewName
,
155 : SwUndo(nUndoId
), sOldName(_sOldName
),
156 sNewName(_sNewName
), pDoc(_pDoc
)
161 SwUndoRenameFmt::~SwUndoRenameFmt()
165 void SwUndoRenameFmt::UndoImpl(::sw::UndoRedoContext
&)
167 SwFmt
* pFmt
= Find(sNewName
);
171 pDoc
->RenameFmt(*pFmt
, sOldName
, true);
175 void SwUndoRenameFmt::RedoImpl(::sw::UndoRedoContext
&)
177 SwFmt
* pFmt
= Find(sOldName
);
181 pDoc
->RenameFmt(*pFmt
, sNewName
, true);
185 SwRewriter
SwUndoRenameFmt::GetRewriter() const
187 SwRewriter aRewriter
;
189 aRewriter
.AddRule(UndoArg1
, sOldName
);
190 aRewriter
.AddRule(UndoArg2
, SW_RES(STR_YIELDS
));
191 aRewriter
.AddRule(UndoArg3
, sNewName
);
196 SwUndoTxtFmtCollCreate::SwUndoTxtFmtCollCreate
197 (SwTxtFmtColl
* _pNew
, SwTxtFmtColl
* _pDerivedFrom
, SwDoc
* _pDoc
)
198 : SwUndoFmtCreate(UNDO_TXTFMTCOL_CREATE
, _pNew
, _pDerivedFrom
, _pDoc
)
202 SwFmt
* SwUndoTxtFmtCollCreate::Create(SwFmt
* pDerivedFrom
)
204 return pDoc
->MakeTxtFmtColl(sNewName
, (SwTxtFmtColl
*)pDerivedFrom
, sal_True
);
207 void SwUndoTxtFmtCollCreate::Delete()
209 pDoc
->DelTxtFmtColl((SwTxtFmtColl
*) pNew
, true);
212 SwFmt
* SwUndoTxtFmtCollCreate::Find(const String
& rName
) const
214 return pDoc
->FindTxtFmtCollByName(rName
);
217 SwUndoTxtFmtCollDelete::SwUndoTxtFmtCollDelete(SwTxtFmtColl
* _pOld
,
219 : SwUndoFmtDelete(UNDO_TXTFMTCOL_DELETE
, _pOld
, _pDoc
)
223 SwFmt
* SwUndoTxtFmtCollDelete::Create(SwFmt
* pDerivedFrom
)
225 return pDoc
->MakeTxtFmtColl(sOldName
, (SwTxtFmtColl
*) pDerivedFrom
, sal_True
);
228 void SwUndoTxtFmtCollDelete::Delete(SwFmt
* pOld
)
230 pDoc
->DelTxtFmtColl((SwTxtFmtColl
*) pOld
, true);
233 SwFmt
* SwUndoTxtFmtCollDelete::Find(const String
& rName
) const
235 return pDoc
->FindTxtFmtCollByName(rName
);
238 SwUndoRenameFmtColl::SwUndoRenameFmtColl(const String
& sInitOldName
,
239 const String
& sInitNewName
,
241 : SwUndoRenameFmt(UNDO_TXTFMTCOL_RENAME
, sInitOldName
, sInitNewName
, _pDoc
)
245 SwFmt
* SwUndoRenameFmtColl::Find(const String
& rName
) const
247 return pDoc
->FindTxtFmtCollByName(rName
);
250 SwUndoCharFmtCreate::SwUndoCharFmtCreate(SwCharFmt
* pNewFmt
,
251 SwCharFmt
* pDerivedFrom
,
253 : SwUndoFmtCreate(UNDO_CHARFMT_CREATE
, pNewFmt
, pDerivedFrom
, pDocument
)
257 SwFmt
* SwUndoCharFmtCreate::Create(SwFmt
* pDerivedFrom
)
259 return pDoc
->MakeCharFmt(sNewName
, (SwCharFmt
*) pDerivedFrom
, true);
262 void SwUndoCharFmtCreate::Delete()
264 pDoc
->DelCharFmt((SwCharFmt
*) pNew
, true);
267 SwFmt
* SwUndoCharFmtCreate::Find(const String
& rName
) const
269 return pDoc
->FindCharFmtByName(rName
);
272 SwUndoCharFmtDelete::SwUndoCharFmtDelete(SwCharFmt
* pOld
, SwDoc
* pDocument
)
273 : SwUndoFmtDelete(UNDO_CHARFMT_DELETE
, pOld
, pDocument
)
277 SwFmt
* SwUndoCharFmtDelete::Create(SwFmt
* pDerivedFrom
)
279 return pDoc
->MakeCharFmt(sOldName
, (SwCharFmt
*) pDerivedFrom
, true);
282 void SwUndoCharFmtDelete::Delete(SwFmt
* pFmt
)
284 pDoc
->DelCharFmt((SwCharFmt
*) pFmt
, true);
287 SwFmt
* SwUndoCharFmtDelete::Find(const String
& rName
) const
289 return pDoc
->FindCharFmtByName(rName
);
292 SwUndoRenameCharFmt::SwUndoRenameCharFmt(const String
& sInitOldName
,
293 const String
& sInitNewName
,
295 : SwUndoRenameFmt(UNDO_CHARFMT_RENAME
, sInitOldName
, sInitNewName
, pDocument
)
299 SwFmt
* SwUndoRenameCharFmt::Find(const String
& rName
) const
301 return pDoc
->FindCharFmtByName(rName
);
304 SwUndoFrmFmtCreate::SwUndoFrmFmtCreate(SwFrmFmt
* pNewFmt
,
305 SwFrmFmt
* pDerivedFrom
,
307 : SwUndoFmtCreate(UNDO_FRMFMT_CREATE
, pNewFmt
, pDerivedFrom
, pDocument
),
308 bAuto(pNewFmt
->IsAuto())
312 SwFmt
* SwUndoFrmFmtCreate::Create(SwFmt
* pDerivedFrom
)
314 return pDoc
->MakeFrmFmt(sNewName
, (SwFrmFmt
*) pDerivedFrom
, true, bAuto
);
317 void SwUndoFrmFmtCreate::Delete()
319 pDoc
->DelFrmFmt((SwFrmFmt
*) pNew
, true);
322 SwFmt
* SwUndoFrmFmtCreate::Find(const String
& rName
) const
324 return pDoc
->FindFrmFmtByName(rName
);
327 SwUndoFrmFmtDelete::SwUndoFrmFmtDelete(SwFrmFmt
* pOld
, SwDoc
* pDocument
)
328 : SwUndoFmtDelete(UNDO_FRMFMT_DELETE
, pOld
, pDocument
)
332 SwFmt
* SwUndoFrmFmtDelete::Create(SwFmt
* pDerivedFrom
)
334 return pDoc
->MakeFrmFmt(sOldName
, (SwFrmFmt
*) pDerivedFrom
, true);
337 void SwUndoFrmFmtDelete::Delete(SwFmt
* pFmt
)
339 pDoc
->DelFrmFmt((SwFrmFmt
*) pFmt
, true);
342 SwFmt
* SwUndoFrmFmtDelete::Find(const String
& rName
) const
344 return pDoc
->FindFrmFmtByName(rName
);
347 SwUndoRenameFrmFmt::SwUndoRenameFrmFmt(const String
& sInitOldName
,
348 const String
& sInitNewName
,
350 : SwUndoRenameFmt(UNDO_FRMFMT_RENAME
, sInitOldName
, sInitNewName
, pDocument
)
354 SwFmt
* SwUndoRenameFrmFmt::Find(const String
& rName
) const
356 return pDoc
->FindFrmFmtByName(rName
);
359 SwUndoNumruleCreate::SwUndoNumruleCreate(const SwNumRule
* _pNew
,
361 : SwUndo(UNDO_NUMRULE_CREATE
), pNew(_pNew
), aNew(*_pNew
), pDoc(_pDoc
),
366 void SwUndoNumruleCreate::UndoImpl(::sw::UndoRedoContext
&)
374 pDoc
->DelNumRule(aNew
.GetName(), true);
377 void SwUndoNumruleCreate::RedoImpl(::sw::UndoRedoContext
&)
379 pDoc
->MakeNumRule(aNew
.GetName(), &aNew
, true);
382 SwRewriter
SwUndoNumruleCreate::GetRewriter() const
392 aResult
.AddRule(UndoArg1
, aNew
.GetName());
397 SwUndoNumruleDelete::SwUndoNumruleDelete(const SwNumRule
& rRule
,
399 : SwUndo(UNDO_NUMRULE_DELETE
), aOld(rRule
), pDoc(_pDoc
)
403 void SwUndoNumruleDelete::UndoImpl(::sw::UndoRedoContext
&)
405 pDoc
->MakeNumRule(aOld
.GetName(), &aOld
, true);
408 void SwUndoNumruleDelete::RedoImpl(::sw::UndoRedoContext
&)
410 pDoc
->DelNumRule(aOld
.GetName(), true);
413 SwRewriter
SwUndoNumruleDelete::GetRewriter() const
417 aResult
.AddRule(UndoArg1
, aOld
.GetName());
422 SwUndoNumruleRename::SwUndoNumruleRename(const String
& _aOldName
,
423 const String
& _aNewName
,
425 : SwUndo(UNDO_NUMRULE_RENAME
), aOldName(_aOldName
), aNewName(_aNewName
),
430 void SwUndoNumruleRename::UndoImpl(::sw::UndoRedoContext
&)
432 pDoc
->RenameNumRule(aNewName
, aOldName
, true);
435 void SwUndoNumruleRename::RedoImpl(::sw::UndoRedoContext
&)
437 pDoc
->RenameNumRule(aOldName
, aNewName
, true);
440 SwRewriter
SwUndoNumruleRename::GetRewriter() const
442 SwRewriter aRewriter
;
444 aRewriter
.AddRule(UndoArg1
, aOldName
);
445 aRewriter
.AddRule(UndoArg2
, SW_RESSTR(STR_YIELDS
));
446 aRewriter
.AddRule(UndoArg3
, aNewName
);
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */