nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / inc / UndoCore.hxx
blob8fb5e8dcf3f7f25c3fa8e79b630dfbd9887800e3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
23 #include <undobj.hxx>
24 #include <calbck.hxx>
25 #include <o3tl/deleter.hxx>
26 #include <rtl/ustring.hxx>
27 #include <redline.hxx>
29 #include <memory>
30 #include <vector>
32 class SfxItemSet;
33 class SwFormatColl;
34 class SwFormatAnchor;
35 class SdrMarkList;
36 class SwUndoDelete;
38 namespace sw {
39 class UndoManager;
40 class IShellCursorSupplier;
43 class SwRedlineSaveData: public SwUndRng, public SwRedlineData, private SwUndoSaveSection
45 public:
46 SwRedlineSaveData(
47 SwComparePosition eCmpPos,
48 const SwPosition& rSttPos,
49 const SwPosition& rEndPos,
50 SwRangeRedline& rRedl,
51 bool bCopyNext );
53 ~SwRedlineSaveData();
55 void RedlineToDoc( SwPaM const & rPam );
57 SwNodeIndex* GetMvSttIdx() const
59 return SwUndoSaveSection::GetMvSttIdx();
62 #if OSL_DEBUG_LEVEL > 0
63 sal_uInt16 m_nRedlineCount;
64 #endif
67 class SwRedlineSaveDatas {
68 private:
69 std::vector<std::unique_ptr<SwRedlineSaveData, o3tl::default_delete<SwRedlineSaveData>>> m_Data;
71 public:
72 SwRedlineSaveDatas() : m_Data() {}
74 void clear() { m_Data.clear(); }
75 bool empty() const { return m_Data.empty(); }
76 size_t size() const { return m_Data.size(); }
77 void push_back(std::unique_ptr<SwRedlineSaveData, o3tl::default_delete<SwRedlineSaveData>> pNew) { m_Data.push_back(std::move(pNew)); }
78 const SwRedlineSaveData& operator[](size_t const nIdx) const { return *m_Data[ nIdx ]; }
79 SwRedlineSaveData& operator[](size_t const nIdx) { return *m_Data[ nIdx ]; }
82 namespace sw {
83 class UndoRedoContext
84 : public SfxUndoContext
86 public:
87 UndoRedoContext(SwDoc & rDoc, IShellCursorSupplier & rCursorSupplier)
88 : m_rDoc(rDoc)
89 , m_rCursorSupplier(rCursorSupplier)
90 , m_pSelFormat(nullptr)
91 , m_pMarkList(nullptr)
92 { }
94 SwDoc & GetDoc() const { return m_rDoc; }
96 IShellCursorSupplier & GetCursorSupplier() { return m_rCursorSupplier; }
98 void SetSelections(SwFrameFormat *const pSelFormat, SdrMarkList *const pMarkList)
100 m_pSelFormat = pSelFormat;
101 m_pMarkList = pMarkList;
103 void GetSelections(SwFrameFormat *& o_rpSelFormat, SdrMarkList *& o_rpMarkList)
105 o_rpSelFormat = m_pSelFormat;
106 o_rpMarkList = m_pMarkList;
109 private:
110 SwDoc & m_rDoc;
111 IShellCursorSupplier & m_rCursorSupplier;
112 SwFrameFormat * m_pSelFormat;
113 SdrMarkList * m_pMarkList;
116 class RepeatContext
117 : public SfxRepeatTarget
119 public:
120 RepeatContext(SwDoc & rDoc, SwPaM & rPaM)
121 : m_rDoc(rDoc)
122 , m_pCurrentPaM(& rPaM)
123 , m_bDeleteRepeated(false)
126 SwDoc & GetDoc() const { return m_rDoc; }
128 SwPaM & GetRepeatPaM()
130 return *m_pCurrentPaM;
133 private:
134 friend class ::sw::UndoManager;
135 friend class ::SwUndoDelete;
137 SwDoc & m_rDoc;
138 SwPaM * m_pCurrentPaM;
139 bool m_bDeleteRepeated; /// has a delete action been repeated?
142 } // namespace sw
144 class SwUndoFormatColl : public SwUndo, private SwUndRng
146 OUString maFormatName;
147 std::unique_ptr<SwHistory> mpHistory;
148 // for correct <ReDo(..)> and <Repeat(..)>
149 // boolean, which indicates that the attributes are reset at the nodes
150 // before the format has been applied.
151 const bool mbReset;
152 // boolean, which indicates that the list attributes had been reset at
153 // the nodes before the format has been applied.
154 const bool mbResetListAttrs;
156 void DoSetFormatColl(SwDoc & rDoc, SwPaM const & rPaM);
158 public:
159 SwUndoFormatColl( const SwPaM&, const SwFormatColl*,
160 const bool bReset,
161 const bool bResetListAttrs );
162 virtual ~SwUndoFormatColl() override;
164 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
165 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
166 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
169 Returns the rewriter for this undo object.
171 The rewriter contains one rule:
173 $1 -> <name of format collection>
175 <name of format collection> is the name of the format
176 collection that is applied by the action recorded by this undo
177 object.
179 @return the rewriter for this undo object
181 virtual SwRewriter GetRewriter() const override;
183 SwHistory* GetHistory() { return mpHistory.get(); }
187 class SwUndoSetFlyFormat : public SwUndo, public SwClient
189 SwFrameFormat* m_pFrameFormat; // saved FlyFormat
190 const OUString m_DerivedFromFormatName;
191 const OUString m_NewFormatName;
192 std::unique_ptr<SfxItemSet> m_pItemSet; // the re-/ set attributes
193 sal_uLong m_nOldNode, m_nNewNode;
194 sal_Int32 m_nOldContent, m_nNewContent;
195 RndStdIds m_nOldAnchorType, m_nNewAnchorType;
196 bool m_bAnchorChanged;
198 void PutAttr( sal_uInt16 nWhich, const SfxPoolItem* pItem );
199 void SwClientNotify(const SwModify&, const SfxHint&) override;
200 void GetAnchor( SwFormatAnchor& rAnhor, sal_uLong nNode, sal_Int32 nContent );
202 public:
203 SwUndoSetFlyFormat( SwFrameFormat& rFlyFormat, const SwFrameFormat& rNewFrameFormat );
204 virtual ~SwUndoSetFlyFormat() override;
206 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
207 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
209 virtual SwRewriter GetRewriter() const override;
212 class SwUndoOutlineLeftRight : public SwUndo, private SwUndRng
214 short m_nOffset;
216 public:
217 SwUndoOutlineLeftRight( const SwPaM& rPam, short nOffset );
219 virtual void UndoImpl( ::sw::UndoRedoContext & ) override;
220 virtual void RedoImpl( ::sw::UndoRedoContext & ) override;
221 virtual void RepeatImpl( ::sw::RepeatContext & ) override;
224 const int nUndoStringLength = 20;
227 Shortens a string to a maximum length.
229 @param rStr the string to be shortened
230 @param nLength the maximum length for rStr
231 @param rFillStr string to replace cut out characters with
233 If rStr has less than nLength characters it will be returned unaltered.
235 If rStr has more than nLength characters the following algorithm
236 generates the shortened string:
238 frontLength = (nLength - length(rFillStr)) / 2
239 rearLength = nLength - length(rFillStr) - frontLength
240 shortenedString = concat(<first frontLength characters of rStr,
241 rFillStr,
242 <last rearLength characters of rStr>)
244 Preconditions:
245 - nLength - length(rFillStr) >= 2
247 @return the shortened string
249 OUString
250 ShortenString(const OUString & rStr, sal_Int32 nLength, const OUString & rFillStr);
252 Denotes special characters in a string.
254 The rStr is split into parts containing special characters and
255 parts not containing special characters. In a part containing
256 special characters all characters are equal. These parts are
257 maximal.
259 @param rStr the string to denote in
260 @param bQuoted add quotation marks to the text
262 The resulting string is generated by concatenating the found
263 parts. The parts without special characters are surrounded by
264 "'". The parts containing special characters are denoted as "n x",
265 where n is the length of the part and x is the representation of
266 the special character (i. e. "tab(s)").
268 @return the denoted string
270 OUString DenoteSpecialCharacters(const OUString & rStr, bool bQuoted = true);
272 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */