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_UNDOINSERT_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_UNDOINSERT_HXX
26 #include <svx/svdtypes.hxx>
27 #include <rtl/ustring.hxx>
28 #include <swtypes.hxx>
29 #include <IDocumentContentOperations.hxx>
35 class SwUndoFormatAttr
;
37 namespace sw
{ class DocumentContentOperationsManager
; }
38 enum class MirrorGraph
;
40 class SwUndoInsert
: public SwUndo
, private SwUndoSaveContent
42 /// start of Content in UndoNodes for Redo
43 std::unique_ptr
<SwNodeIndex
> m_pUndoNodeIndex
;
44 std::optional
<OUString
> maText
;
45 std::optional
<OUString
> maUndoText
;
46 std::unique_ptr
<SwRedlineData
> m_pRedlData
;
48 sal_Int32 m_nContent
, m_nLen
;
49 bool m_bIsWordDelim
: 1;
53 const SwInsertFlags m_nInsertFlags
;
55 friend class ::sw::DocumentContentOperationsManager
; // actually only DocumentContentOperationsManager::InsertString, because it uses CanGrouping
56 bool CanGrouping( sal_Unicode cIns
);
57 bool CanGrouping( const SwPosition
& rPos
);
61 void Init(const SwNodeIndex
& rNode
);
62 std::optional
<OUString
> GetTextFromDoc() const;
65 SwUndoInsert( const SwNodeIndex
& rNode
, sal_Int32 nContent
, sal_Int32 nLen
,
66 const SwInsertFlags nInsertFlags
,
67 bool bWDelim
= true );
68 SwUndoInsert( const SwNodeIndex
& rNode
);
69 virtual ~SwUndoInsert() override
;
71 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
72 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
73 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
76 Returns rewriter for this undo object.
78 The returned rewriter has the following rule:
80 $1 -> '<inserted text>'
82 <inserted text> is shortened to a length of nUndoStringLength.
84 @return rewriter for this undo object
86 virtual SwRewriter
GetRewriter() const override
;
88 void SetWithRsid() { m_bWithRsid
= true; }
92 MakeUndoReplaceRewriter(sal_uLong
const occurrences
,
93 OUString
const& sOld
, OUString
const& sNew
);
99 SwUndoReplace(SwPaM
const& rPam
,
100 OUString
const& rInsert
, bool const bRegExp
);
102 virtual ~SwUndoReplace() override
;
104 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
105 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
108 Returns the rewriter of this undo object.
110 If this undo object represents several replacements the
111 rewriter contains the following rules:
113 $1 -> <number of replacements>
115 $3 -> <replaced text>
117 If this undo object represents one replacement the rewriter
118 contains these rules:
120 $1 -> <replaced text>
121 $2 -> "->" (STR_YIELDS)
122 $3 -> <replacing text>
124 @return the rewriter of this undo object
126 virtual SwRewriter
GetRewriter() const override
;
128 void SetEnd( const SwPaM
& rPam
);
132 std::unique_ptr
<Impl
> m_pImpl
;
135 class SwUndoReRead
: public SwUndo
137 std::unique_ptr
<Graphic
> mpGraphic
;
138 std::optional
<OUString
> maNm
;
139 std::optional
<OUString
> maFltr
;
140 sal_uLong mnPosition
;
141 MirrorGraph mnMirror
;
143 void SaveGraphicData( const SwGrfNode
& );
144 void SetAndSave( ::sw::UndoRedoContext
& );
147 SwUndoReRead( const SwPaM
& rPam
, const SwGrfNode
& pGrfNd
);
149 virtual ~SwUndoReRead() override
;
151 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
152 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
155 class SwUndoInsertLabel
: public SwUndo
160 SwUndoInsLayFormat
* pUndoFly
;
161 SwUndoFormatAttr
* pUndoAttr
;
164 // for tables or TextFrames
165 SwUndoDelete
* pUndoInsNd
;
171 // #i39983# the separator is drawn with a character style
172 OUString m_sSeparator
;
173 OUString m_sNumberSeparator
;
174 OUString m_sCharacterStyle
;
175 // #i26791# - re-store of drawing object position no longer needed
176 sal_uInt16 m_nFieldId
;
178 SdrLayerID m_nLayerId
; // for character objects
181 bool m_bCopyBorder
:1;
184 SwUndoInsertLabel( const SwLabelType eTyp
, const OUString
&rText
,
185 // #i39983# the separator is drawn with a character style
186 const OUString
& rSeparator
,
187 const OUString
& rNumberSeparator
, //#i61007# order of captions
188 const bool bBefore
, const sal_uInt16 nId
,
189 const OUString
& rCharacterStyle
,
192 virtual ~SwUndoInsertLabel() override
;
194 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
195 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
196 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
199 Returns the rewriter of this undo object.
201 The rewriter contains this rule:
203 $1 -> '<text of inserted label>'
205 <text of inserted label> is shortened to nUndoStringLength
208 @return the rewriter of this undo object
210 virtual SwRewriter
GetRewriter() const override
;
211 static SwRewriter
CreateRewriter(const OUString
&rStr
);
213 void SetNodePos( sal_uLong nNd
)
214 { if( SwLabelType::Object
!= m_eType
) NODE
.nNode
= nNd
; }
216 void SetUndoKeep() { m_bUndoKeep
= true; }
217 void SetFlys( SwFrameFormat
& rOldFly
, SfxItemSet
const & rChgSet
, SwFrameFormat
& rNewFly
);
218 void SetDrawObj( SdrLayerID nLayerId
);
221 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOINSERT_HXX
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */