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 <rtl/ustring.hxx>
26 #include <redline.hxx>
27 #include <numrule.hxx>
40 class IShellCursorSupplier
;
43 class SwRedlineSaveData final
: 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 const SwNodeIndex
* GetMvSttIdx() const
59 return SwUndoSaveSection::GetMvSttIdx();
62 #if OSL_DEBUG_LEVEL > 0
63 sal_uInt16 m_nRedlineCount
;
68 class SwRedlineSaveDatas
{
70 std::vector
<std::unique_ptr
<SwRedlineSaveData
>> m_Data
;
73 SwRedlineSaveDatas() : m_Data() {}
75 void clear() { m_Data
.clear(); }
76 bool empty() const { return m_Data
.empty(); }
77 size_t size() const { return m_Data
.size(); }
78 void push_back(std::unique_ptr
<SwRedlineSaveData
> pNew
) { m_Data
.push_back(std::move(pNew
)); }
79 const SwRedlineSaveData
& operator[](size_t const nIdx
) const { return *m_Data
[ nIdx
]; }
80 SwRedlineSaveData
& operator[](size_t const nIdx
) { return *m_Data
[ nIdx
]; }
84 class UndoRedoContext final
85 : public SfxUndoContext
88 UndoRedoContext(SwDoc
& rDoc
, IShellCursorSupplier
& rCursorSupplier
)
90 , m_rCursorSupplier(rCursorSupplier
)
91 , m_pSelFormat(nullptr)
92 , m_pMarkList(nullptr)
95 SwDoc
& GetDoc() const { return m_rDoc
; }
97 IShellCursorSupplier
& GetCursorSupplier() { return m_rCursorSupplier
; }
99 void SetSelections(SwFrameFormat
*const pSelFormat
, SdrMarkList
*const pMarkList
)
101 m_pSelFormat
= pSelFormat
;
102 m_pMarkList
= pMarkList
;
104 void GetSelections(SwFrameFormat
*& o_rpSelFormat
, SdrMarkList
*& o_rpMarkList
)
106 o_rpSelFormat
= m_pSelFormat
;
107 o_rpMarkList
= m_pMarkList
;
110 void SetUndoOffset(size_t nUndoOffset
) { m_nUndoOffset
= nUndoOffset
; }
112 size_t GetUndoOffset() override
{ return m_nUndoOffset
; }
116 IShellCursorSupplier
& m_rCursorSupplier
;
117 SwFrameFormat
* m_pSelFormat
;
118 SdrMarkList
* m_pMarkList
;
119 size_t m_nUndoOffset
= 0;
122 class RepeatContext final
123 : public SfxRepeatTarget
126 RepeatContext(SwDoc
& rDoc
, SwPaM
& rPaM
)
128 , m_pCurrentPaM(& rPaM
)
129 , m_bDeleteRepeated(false)
132 SwDoc
& GetDoc() const { return m_rDoc
; }
134 SwPaM
& GetRepeatPaM()
136 return *m_pCurrentPaM
;
140 friend class ::sw::UndoManager
;
141 friend class ::SwUndoDelete
;
144 SwPaM
* m_pCurrentPaM
;
145 bool m_bDeleteRepeated
; /// has a delete action been repeated?
150 class SwUndoFormatColl final
: public SwUndo
, private SwUndRng
152 OUString maFormatName
;
153 std::unique_ptr
<SwHistory
> mpHistory
;
154 // for correct <ReDo(..)> and <Repeat(..)>
155 // boolean, which indicates that the attributes are reset at the nodes
156 // before the format has been applied.
158 // boolean, which indicates that the list attributes had been reset at
159 // the nodes before the format has been applied.
160 const bool mbResetListAttrs
;
162 void DoSetFormatColl(SwDoc
& rDoc
, SwPaM
const & rPaM
);
165 SwUndoFormatColl( const SwPaM
&, const SwFormatColl
*,
167 const bool bResetListAttrs
);
168 virtual ~SwUndoFormatColl() override
;
170 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
171 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
172 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
175 Returns the rewriter for this undo object.
177 The rewriter contains one rule:
179 $1 -> <name of format collection>
181 <name of format collection> is the name of the format
182 collection that is applied by the action recorded by this undo
185 @return the rewriter for this undo object
187 virtual SwRewriter
GetRewriter() const override
;
189 SwHistory
* GetHistory() { return mpHistory
.get(); }
193 class SwUndoSetFlyFormat final
: public SwUndo
, public SwClient
195 SwFrameFormat
* m_pFrameFormat
; // saved FlyFormat
196 const OUString m_DerivedFromFormatName
;
197 const OUString m_NewFormatName
;
198 std::optional
<SfxItemSet
> m_oItemSet
; // the re-/ set attributes
199 SwNodeOffset m_nOldNode
, m_nNewNode
;
200 sal_Int32 m_nOldContent
, m_nNewContent
;
201 RndStdIds m_nOldAnchorType
, m_nNewAnchorType
;
202 bool m_bAnchorChanged
;
204 void PutAttr( sal_uInt16 nWhich
, const SfxPoolItem
* pItem
);
205 void SwClientNotify(const SwModify
&, const SfxHint
&) override
;
206 void GetAnchor( SwFormatAnchor
& rAnhor
, SwNodeOffset nNode
, sal_Int32 nContent
);
209 SwUndoSetFlyFormat( SwFrameFormat
& rFlyFormat
, const SwFrameFormat
& rNewFrameFormat
);
210 virtual ~SwUndoSetFlyFormat() override
;
212 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
213 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
215 virtual SwRewriter
GetRewriter() const override
;
218 class SwUndoOutlineLeftRight final
: public SwUndo
, private SwUndRng
223 SwUndoOutlineLeftRight( const SwPaM
& rPam
, short nOffset
);
225 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
226 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
227 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
230 class SwUndoOutlineEdit final
: public SwUndo
, private SwUndRng
232 SwNumRule m_aNewNumRule
;
233 SwNumRule m_aOldNumRule
;
236 SwUndoOutlineEdit(const SwNumRule
& rOldRule
, const SwNumRule
& rNewRule
, const SwDoc
& rDoc
);
238 virtual void UndoImpl(::sw::UndoRedoContext
&) override
;
239 virtual void RedoImpl(::sw::UndoRedoContext
&) override
;
240 virtual void RepeatImpl(::sw::RepeatContext
&) override
;
243 const int nUndoStringLength
= 20;
246 Shortens a string to a maximum length.
248 @param rStr the string to be shortened
249 @param nLength the maximum length for rStr
250 @param aFillStr string to replace cut out characters with
252 If rStr has less than nLength characters it will be returned unaltered.
254 If rStr has more than nLength characters the following algorithm
255 generates the shortened string:
257 frontLength = (nLength - length(aFillStr)) / 2
258 rearLength = nLength - length(aFillStr) - frontLength
259 shortenedString = concat(<first frontLength characters of rStr,
261 <last rearLength characters of rStr>)
264 - nLength - length(aFillStr) >= 2
266 @return the shortened string
269 ShortenString(const OUString
& rStr
, sal_Int32 nLength
, std::u16string_view aFillStr
);
271 Denotes special characters in a string.
273 The rStr is split into parts containing special characters and
274 parts not containing special characters. In a part containing
275 special characters all characters are equal. These parts are
278 @param aStr the string to denote in
279 @param bQuoted add quotation marks to the text
281 The resulting string is generated by concatenating the found
282 parts. The parts without special characters are surrounded by
283 "'". The parts containing special characters are denoted as "n x",
284 where n is the length of the part and x is the representation of
285 the special character (i. e. "tab(s)").
287 @return the denoted string
289 OUString
DenoteSpecialCharacters(std::u16string_view aStr
, bool bQuoted
= true);
291 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */