LibreOffice Module sw (master)  1
unfmco.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <doc.hxx>
21 #include <swundo.hxx>
22 #include <pam.hxx>
23 #include <UndoCore.hxx>
24 #include <rolbck.hxx>
25 
27  const SwFormatColl* pColl,
28  const bool bReset,
29  const bool bResetListAttrs )
30  : SwUndo( SwUndoId::SETFMTCOLL, rRange.GetDoc() ),
31  SwUndRng( rRange ),
32  pHistory( new SwHistory ),
33  mbReset( bReset ),
34  mbResetListAttrs( bResetListAttrs )
35 {
36  // #i31191#
37  if ( pColl )
38  aFormatName = pColl->GetName();
39 }
40 
42 {
43 }
44 
46 {
47  // restore old values
48  pHistory->TmpRollback(& rContext.GetDoc(), 0);
49  pHistory->SetTmpEnd( pHistory->Count() );
50 
51  // create cursor for undo range
52  AddUndoRedoPaM(rContext);
53 }
54 
56 {
57  SwPaM & rPam = AddUndoRedoPaM(rContext);
58 
59  DoSetFormatColl(rContext.GetDoc(), rPam);
60 }
61 
63 {
64  DoSetFormatColl(rContext.GetDoc(), rContext.GetRepeatPaM());
65 }
66 
67 void SwUndoFormatColl::DoSetFormatColl(SwDoc & rDoc, SwPaM const & rPaM)
68 {
69  // Only one TextFrameColl can be applied to a section, thus request only in
70  // this array.
72  if (pFormatColl)
73  {
74  rDoc.SetTextFormatColl(rPaM, pFormatColl, mbReset, mbResetListAttrs);
75  }
76 }
77 
79 {
80  SwRewriter aResult;
81 
82  aResult.AddRule(UndoArg1, aFormatName );
83 
84  return aResult;
85 }
86 
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwPaM & AddUndoRedoPaM(::sw::UndoRedoContext &, bool const bCorrToContent=false) const
Definition: undobj.cxx:105
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unfmco.cxx:55
SwUndoId
Definition: swundo.hxx:29
SwTextFormatColl * FindTextFormatCollByName(const OUString &rName) const
Definition: doc.hxx:796
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:128
Definition: doc.hxx:185
virtual ~SwUndoFormatColl() override
Definition: unfmco.cxx:41
bool SetTextFormatColl(const SwPaM &rRg, SwTextFormatColl *pFormat, const bool bReset=true, const bool bResetListAttrs=false, SwRootFrame const *pLayout=nullptr)
Add 4th optional parameter .
Definition: docfmt.cxx:1064
SwDoc & GetDoc() const
Definition: UndoCore.hxx:126
const OUString & GetName() const
Definition: format.hxx:111
SwDoc & GetDoc() const
Definition: UndoCore.hxx:94
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
std::unique_ptr< SwHistory > pHistory
Definition: UndoCore.hxx:147
const bool mbReset
Definition: UndoCore.hxx:151
const bool mbResetListAttrs
Definition: UndoCore.hxx:154
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:29
SwUndoFormatColl(const SwPaM &, const SwFormatColl *, const bool bReset, const bool bResetListAttrs)
Definition: unfmco.cxx:26
OUString aFormatName
Definition: UndoCore.hxx:146
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unfmco.cxx:45
void DoSetFormatColl(SwDoc &rDoc, SwPaM const &rPaM)
Definition: unfmco.cxx:67
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unfmco.cxx:62
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this undo object.
Definition: unfmco.cxx:78