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 <ndtxt.hxx>
24 #include <UndoCore.hxx>
25 #include <rolbck.hxx>
26 #include <docary.hxx>
27 
29  SwFormatColl* pColl,
30  const bool bReset,
31  const bool bResetListAttrs )
32  : SwUndo( SwUndoId::SETFMTCOLL, rRange.GetDoc() ),
33  SwUndRng( rRange ),
34  pHistory( new SwHistory ),
35  mbReset( bReset ),
36  mbResetListAttrs( bResetListAttrs )
37 {
38  // #i31191#
39  if ( pColl )
40  aFormatName = pColl->GetName();
41 }
42 
44 {
45 }
46 
48 {
49  // restore old values
50  pHistory->TmpRollback(& rContext.GetDoc(), 0);
51  pHistory->SetTmpEnd( pHistory->Count() );
52 
53  // create cursor for undo range
54  AddUndoRedoPaM(rContext);
55 }
56 
58 {
59  SwPaM & rPam = AddUndoRedoPaM(rContext);
60 
61  DoSetFormatColl(rContext.GetDoc(), rPam);
62 }
63 
65 {
66  DoSetFormatColl(rContext.GetDoc(), rContext.GetRepeatPaM());
67 }
68 
69 void SwUndoFormatColl::DoSetFormatColl(SwDoc & rDoc, SwPaM const & rPaM)
70 {
71  // Only one TextFrameColl can be applied to a section, thus request only in
72  // this array.
74  if (pFormatColl)
75  {
76  rDoc.SetTextFormatColl(rPaM, pFormatColl, mbReset, mbResetListAttrs);
77  }
78 }
79 
81 {
82  SwRewriter aResult;
83 
84  aResult.AddRule(UndoArg1, aFormatName );
85 
86  return aResult;
87 }
88 
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwPaM & AddUndoRedoPaM(::sw::UndoRedoContext &, bool const bCorrToContent=false) const
Definition: undobj.cxx:106
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unfmco.cxx:57
SwUndoId
Definition: swundo.hxx:29
SwTextFormatColl * FindTextFormatCollByName(const OUString &rName) const
Definition: doc.hxx:794
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:128
Definition: doc.hxx:185
virtual ~SwUndoFormatColl() override
Definition: unfmco.cxx:43
SwUndoFormatColl(const SwPaM &, SwFormatColl *, const bool bReset, const bool bResetListAttrs)
Definition: unfmco.cxx:28
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:1096
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
OUString aFormatName
Definition: UndoCore.hxx:146
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unfmco.cxx:47
void DoSetFormatColl(SwDoc &rDoc, SwPaM const &rPaM)
Definition: unfmco.cxx:69
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unfmco.cxx:64
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this undo object.
Definition: unfmco.cxx:80