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  pFormatColl( pColl ),
36  mbReset( bReset ),
37  mbResetListAttrs( bResetListAttrs )
38 {
39  // #i31191#
40  if ( pColl )
41  aFormatName = pColl->GetName();
42 }
43 
45 {
46 }
47 
49 {
50  // restore old values
51  pHistory->TmpRollback(& rContext.GetDoc(), 0);
52  pHistory->SetTmpEnd( pHistory->Count() );
53 
54  // create cursor for undo range
55  AddUndoRedoPaM(rContext);
56 }
57 
59 {
60  SwPaM & rPam = AddUndoRedoPaM(rContext);
61 
62  DoSetFormatColl(rContext.GetDoc(), rPam);
63 }
64 
66 {
67  DoSetFormatColl(rContext.GetDoc(), rContext.GetRepeatPaM());
68 }
69 
70 void SwUndoFormatColl::DoSetFormatColl(SwDoc & rDoc, SwPaM const & rPaM)
71 {
72  // Only one TextFrameColl can be applied to a section, thus request only in
73  // this array.
74 
75  // does the format still exist?
76  if (rDoc.GetTextFormatColls()->IsAlive(static_cast<SwTextFormatColl*>(pFormatColl)))
77  {
78  rDoc.SetTextFormatColl(rPaM, static_cast<SwTextFormatColl*>(pFormatColl), mbReset,
80  }
81 }
82 
84 {
85  SwRewriter aResult;
86 
87  // #i31191# Use stored format name instead of
88  // pFormatColl->GetName(), because pFormatColl does not have to be available
89  // anymore.
90  aResult.AddRule(UndoArg1, aFormatName );
91 
92  return aResult;
93 }
94 
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwPaM & AddUndoRedoPaM(::sw::UndoRedoContext &, bool const bCorrToContent=false) const
Definition: undobj.cxx:106
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unfmco.cxx:58
SwUndoId
Definition: swundo.hxx:29
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:128
Definition: doc.hxx:185
virtual ~SwUndoFormatColl() override
Definition: unfmco.cxx:44
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
bool IsAlive(typename std::remove_pointer< Value >::type const *const p) const
check that given format is still alive (i.e. contained here)
Definition: docary.hxx:144
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:152
const bool mbResetListAttrs
Definition: UndoCore.hxx:155
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:48
void DoSetFormatColl(SwDoc &rDoc, SwPaM const &rPaM)
Definition: unfmco.cxx:70
const SwTextFormatColls * GetTextFormatColls() const
Definition: doc.hxx:773
SwFormatColl *const pFormatColl
Definition: UndoCore.hxx:148
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unfmco.cxx:65
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this undo object.
Definition: unfmco.cxx:83