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 .
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
25 #include <o3tl/deleter.hxx>
26 #include <rtl/ustring.hxx>
27 #include <redline.hxx>
40 class IShellCursorSupplier
;
43 class SwRedlineSaveData
: public SwUndRng
, public SwRedlineData
, private SwUndoSaveSection
47 SwComparePosition eCmpPos
,
48 const SwPosition
& rSttPos
,
49 const SwPosition
& rEndPos
,
50 SwRangeRedline
& rRedl
,
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
;
67 class SwRedlineSaveDatas
{
69 std::vector
<std::unique_ptr
<SwRedlineSaveData
, o3tl::default_delete
<SwRedlineSaveData
>>> m_Data
;
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
]; }
84 : public SfxUndoContext
87 UndoRedoContext(SwDoc
& rDoc
, IShellCursorSupplier
& rCursorSupplier
)
89 , m_rCursorSupplier(rCursorSupplier
)
90 , m_pSelFormat(nullptr)
91 , m_pMarkList(nullptr)
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
;
111 IShellCursorSupplier
& m_rCursorSupplier
;
112 SwFrameFormat
* m_pSelFormat
;
113 SdrMarkList
* m_pMarkList
;
117 : public SfxRepeatTarget
120 RepeatContext(SwDoc
& rDoc
, SwPaM
& rPaM
)
122 , m_pCurrentPaM(& rPaM
)
123 , m_bDeleteRepeated(false)
126 SwDoc
& GetDoc() const { return m_rDoc
; }
128 SwPaM
& GetRepeatPaM()
130 return *m_pCurrentPaM
;
134 friend class ::sw::UndoManager
;
135 friend class ::SwUndoDelete
;
138 SwPaM
* m_pCurrentPaM
;
139 bool m_bDeleteRepeated
; /// has a delete action been repeated?
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.
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
);
159 SwUndoFormatColl( const SwPaM
&, const SwFormatColl
*,
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
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
);
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
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,
242 <last rearLength characters of rStr>)
245 - nLength - length(rFillStr) >= 2
247 @return the shortened string
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
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: */