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 <vcl/graph.hxx>
29 #include <swtypes.hxx>
30 #include <ndindex.hxx>
31 #include <IDocumentContentOperations.hxx>
36 class SwUndoFormatAttr
;
38 namespace sw
{ class DocumentContentOperationsManager
; }
39 enum class MirrorGraph
;
41 /// Typing one or more characters to a single paragraph.
42 class SwUndoInsert final
: public SwUndo
, private SwUndoSaveContent
44 /// start of Content in UndoNodes for Redo
45 std::optional
<SwNodeIndex
> m_oUndoNodeIndex
;
46 std::optional
<OUString
> maText
;
47 std::optional
<OUString
> maUndoText
;
48 std::unique_ptr
<SwRedlineData
> m_pRedlData
;
50 sal_Int32 m_nContent
, m_nLen
;
51 bool m_bIsWordDelim
: 1;
55 const SwInsertFlags m_nInsertFlags
;
57 friend class ::sw::DocumentContentOperationsManager
; // actually only DocumentContentOperationsManager::InsertString, because it uses CanGrouping
58 bool CanGrouping( sal_Unicode cIns
);
59 bool CanGrouping( const SwPosition
& rPos
);
63 void Init(const SwNode
& rNode
);
64 std::optional
<OUString
> GetTextFromDoc() const;
67 SwUndoInsert( const SwNode
& rNode
, sal_Int32 nContent
, sal_Int32 nLen
,
68 const SwInsertFlags nInsertFlags
,
69 bool bWDelim
= true );
70 SwUndoInsert( const SwNode
& rNode
);
71 virtual ~SwUndoInsert() override
;
73 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
74 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
75 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
78 Returns rewriter for this undo object.
80 The returned rewriter has the following rule:
82 $1 -> '<inserted text>'
84 <inserted text> is shortened to a length of nUndoStringLength.
86 @return rewriter for this undo object
88 virtual SwRewriter
GetRewriter() const override
;
90 void SetWithRsid() { m_bWithRsid
= true; }
92 bool IsIndependent(const SwUndoInsert
& rOther
) const;
96 MakeUndoReplaceRewriter(sal_uLong
const occurrences
,
97 OUString
const& sOld
, OUString
const& sNew
);
99 class SwUndoReplace final
103 SwUndoReplace(SwPaM
const& rPam
,
104 OUString
const& rInsert
, bool const bRegExp
);
106 virtual ~SwUndoReplace() override
;
108 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
109 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
112 Returns the rewriter of this undo object.
114 If this undo object represents several replacements the
115 rewriter contains the following rules:
117 $1 -> <number of replacements>
119 $3 -> <replaced text>
121 If this undo object represents one replacement the rewriter
122 contains these rules:
124 $1 -> <replaced text>
125 $2 -> "->" (STR_YIELDS)
126 $3 -> <replacing text>
128 @return the rewriter of this undo object
130 virtual SwRewriter
GetRewriter() const override
;
132 void SetEnd( const SwPaM
& rPam
);
136 std::unique_ptr
<Impl
> m_pImpl
;
139 /// Handles the undo/redo of the 'Replace...' context menu item for an image.
140 class SwUndoReRead final
: public SwUndo
142 std::optional
<Graphic
> moGraphic
;
143 std::optional
<OUString
> maNm
;
144 std::optional
<OUString
> maFltr
;
145 SwNodeOffset mnPosition
;
146 MirrorGraph mnMirror
;
148 void SaveGraphicData( const SwGrfNode
& );
149 void SetAndSave( ::sw::UndoRedoContext
& );
152 SwUndoReRead( const SwPaM
& rPam
, const SwGrfNode
& pGrfNd
);
154 virtual ~SwUndoReRead() override
;
156 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
157 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
160 class SwUndoInsertLabel final
: public SwUndo
165 SwUndoInsLayFormat
* pUndoFly
;
166 SwUndoFormatAttr
* pUndoAttr
;
169 // for tables or TextFrames
170 SwUndoDelete
* pUndoInsNd
;
176 // #i39983# the separator is drawn with a character style
177 OUString m_sSeparator
;
178 OUString m_sNumberSeparator
;
179 OUString m_sCharacterStyle
;
180 // #i26791# - re-store of drawing object position no longer needed
181 sal_uInt16 m_nFieldId
;
183 SdrLayerID m_nLayerId
; // for character objects
186 bool m_bCopyBorder
:1;
189 SwUndoInsertLabel( const SwLabelType eTyp
, OUString rText
,
190 // #i39983# the separator is drawn with a character style
192 OUString aNumberSeparator
, //#i61007# order of captions
193 const bool bBefore
, const sal_uInt16 nId
,
194 OUString aCharacterStyle
,
197 virtual ~SwUndoInsertLabel() override
;
199 virtual void UndoImpl( ::sw::UndoRedoContext
& ) override
;
200 virtual void RedoImpl( ::sw::UndoRedoContext
& ) override
;
201 virtual void RepeatImpl( ::sw::RepeatContext
& ) override
;
204 Returns the rewriter of this undo object.
206 The rewriter contains this rule:
208 $1 -> '<text of inserted label>'
210 <text of inserted label> is shortened to nUndoStringLength
213 @return the rewriter of this undo object
215 virtual SwRewriter
GetRewriter() const override
;
216 static SwRewriter
CreateRewriter(const OUString
&rStr
);
218 void SetNodePos( SwNodeOffset nNd
)
219 { if( SwLabelType::Object
!= m_eType
) NODE
.nNode
= nNd
; }
221 void SetUndoKeep() { m_bUndoKeep
= true; }
222 void SetFlys( SwFrameFormat
& rOldFly
, SfxItemSet
const & rChgSet
, SwFrameFormat
& rNewFly
);
223 void SetDrawObj( SdrLayerID nLayerId
);
226 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOINSERT_HXX
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */