1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_SW_INC_IDOCUMENTCONTENTOPERATIONS_HXX
21 #define INCLUDED_SW_INC_IDOCUMENTCONTENTOPERATIONS_HXX
22 
23 #include <sal/types.h>
24 #include <rtl/ustring.hxx>
25 #include "swtypes.hxx"
26 
27 class SwPaM;
28 struct SwPosition;
29 class SwNode;
30 class SwNodeRange;
31 class Graphic;
32 class SfxItemSet;
33 class SfxPoolItem;
34 class GraphicObject;
35 class SdrObject;
36 class SwFrameFormat;
37 class SwDrawFrameFormat;
38 class SwFlyFrameFormat;
39 class SwNodeIndex;
40 class SwRootFrame;
41 class SwTextAttr;
42 
43 namespace utl { class TransliterationWrapper; }
44 namespace svt { class EmbeddedObjectRef; }
45 
46 enum class SwMoveFlags
47 {
48     DEFAULT       = 0x00,
49     ALLFLYS       = 0x01,
50     CREATEUNDOOBJ = 0x02,
51     REDLINES      = 0x04,
52     NO_DELFRMS    = 0x08
53 };
54 namespace o3tl
55 {
56     template<> struct typed_flags<SwMoveFlags> : is_typed_flags<SwMoveFlags, 0x0f> {};
57 }
58 
59 // constants for inserting text
60 enum class SwInsertFlags
61 {
62     DEFAULT         = 0x00, // no extras
63     EMPTYEXPAND     = 0x01, // expand empty hints at insert position
64     NOHINTEXPAND    = 0x02, // do not expand any hints at insert pos
65     FORCEHINTEXPAND = 0x04 // expand all hints at insert position
66 };
67 namespace o3tl
68 {
69     template<> struct typed_flags<SwInsertFlags> : is_typed_flags<SwInsertFlags, 0x07> {};
70 }
71 
72 /** Text operation/manipulation interface
73 */
74 class IDocumentContentOperations
75 {
76 public:
77 public:
78     /** Copy a selected content range to a position
79 
80         The position can be in the same or in an another document. It can also
81         be within the range!
82 
83         \warning The range has to include at least two nodes or has to be a
84         SwDoc::IsColumnSelection, because the rPam is treated [mark, point[.
85 
86         Normally this function should work only with content nodes. But there
87         is a special case used by SwDoc::Paste, which starts the SwPaM at the
88         content start node. This position doesn't contain any content:
89 
90         @code
91         SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 1 );
92         @endcode
93 
94         This is important, because it prevents merging of the first node of
95         the range into the node pointed to by \p rPos.
96         As a result this keeps all properties of the first real content node,
97         which is the 2nd, including the Flys and the page description. In this
98         case the first (fake) node is silently dropped and all other nodes are
99         just copied.
100 
101         @param rPam
102         The source node range to copy
103 
104         @param rPos
105         The target copy destination
106 
107         @param bCheckPos
108         If this function should check if rPos is in a fly frame anchored in
109         rPam. If false, then no such check will be performed, and it is assumed
110         that the caller took care of verifying this constraint already.
111      */
112     virtual bool CopyRange(SwPaM& rPam, SwPosition& rPos, const bool bCopyAll, bool bCheckPos, bool bCopyText ) const = 0;
113 
114     /** Delete section containing the node.
115     */
116     virtual void DeleteSection(SwNode* pNode) = 0;
117 
118     /** Delete a range SwFlyFrameFormat.
119     */
120     virtual void DeleteRange(SwPaM&) = 0;
121 
122     /** Delete full paragraphs.
123     */
124     virtual bool DelFullPara(SwPaM&) = 0;
125 
126     /** complete delete of a given PaM
127 
128         #i100466#
129         Add optional parameter <bForceJoinNext>, default value <false>
130         Needed for hiding of deletion redlines
131     */
132     virtual bool DeleteAndJoin( SwPaM&,
133         const bool bForceJoinNext = false ) = 0;
134 
135     virtual bool MoveRange(SwPaM&, SwPosition&, SwMoveFlags) = 0;
136 
137     virtual bool MoveNodeRange(SwNodeRange&, SwNodeIndex&, SwMoveFlags) = 0;
138 
139     /** Move a range.
140     */
141     virtual bool MoveAndJoin(SwPaM&, SwPosition&) = 0;
142 
143     /** Overwrite string in an existing text node.
144     */
145     virtual bool Overwrite(const SwPaM &rRg, const OUString& rStr) = 0;
146 
147     /** Insert string into existing text node at position rRg.Point().
148      */
149     virtual bool InsertString(const SwPaM &rRg, const OUString&,
150               const SwInsertFlags nInsertMode = SwInsertFlags::EMPTYEXPAND ) = 0;
151 
152     /** change text to Upper/Lower/Hiragana/Katakana/...
153      */
154     virtual void TransliterateText(const SwPaM& rPaM, utl::TransliterationWrapper&) = 0;
155 
156     /** Insert graphic or formula. The XXXX are copied.
157      */
158     virtual SwFlyFrameFormat* InsertGraphic(
159         const SwPaM &rRg, const OUString& rGrfName,
160         const OUString& rFltName, const Graphic* pGraphic,
161         const SfxItemSet* pFlyAttrSet, const SfxItemSet* pGrfAttrSet,
162         SwFrameFormat*) = 0;
163 
164     virtual SwFlyFrameFormat* InsertGraphicObject(
165         const SwPaM& rRg, const GraphicObject& rGrfObj,
166         const SfxItemSet* pFlyAttrSet,
167         const SfxItemSet* pGrfAttrSet) = 0;
168 
169     /** Transpose graphic (with undo)
170      */
171     virtual void ReRead(SwPaM&, const OUString& rGrfName, const OUString& rFltName, const Graphic* pGraphic) = 0;
172 
173     /** Insert a DrawObject. The object must be already registered
174         in DrawModel.
175     */
176     virtual SwDrawFrameFormat* InsertDrawObj(
177         const SwPaM &rRg, SdrObject& rDrawObj, const SfxItemSet& rFlyAttrSet) = 0;
178 
179     /** Insert OLE-objects.
180     */
181     virtual SwFlyFrameFormat* InsertEmbObject(
182         const SwPaM &rRg, const svt::EmbeddedObjectRef& xObj,
183         SfxItemSet* pFlyAttrSet) = 0;
184 
185     virtual SwFlyFrameFormat* InsertOLE(
186         const SwPaM &rRg, const OUString& rObjName, sal_Int64 nAspect,
187         const SfxItemSet* pFlyAttrSet, const SfxItemSet* pGrfAttrSet) = 0;
188 
189     /** Split a node at rPos (implemented only for TextNode).
190     */
191     virtual bool SplitNode(const SwPosition &rPos, bool bChkTableStart) = 0;
192 
193     virtual bool AppendTextNode(SwPosition& rPos) = 0;
194 
195     /** Replace selected range in a TextNode with string.
196         Intended for search & replace.
197         bRegExpRplc - replace tabs (\\t) and insert the found string
198         ( not \& ). E.g.: Find: "zzz", Replace: "xx\t\\t..&..\&"
199         --> "xx\t<Tab>..zzz..&"
200     */
201     virtual bool ReplaceRange(SwPaM& rPam, const OUString& rNewStr,
202                               const bool bRegExReplace) = 0;
203 
204     /** Insert an attribute. If rRg spans several nodes the
205         attribute is split, provided it makes sense.
206         Nodes, where this attribute does not make sense are ignored.
207         In nodes completely enclosed in the selection the attribute
208         becomes hard-formatted, in all other (text-) nodes the attribute
209         is inserted into the attribute array.
210         For a character attribute, in cases where no selection exists
211         an "empty" hint is inserted. If there is a selection the attribute
212         is hard-formatted and added to the node at rRg.Start().
213         If the attribute could not be inserted, the method returns
214         false.
215     */
216     virtual bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem&,
217                                 const SetAttrMode nFlags = SetAttrMode::DEFAULT,
218                                 SwRootFrame const* pLayout = nullptr,
219                                 bool bExpandCharToPara = false,
220                                 SwTextAttr **ppNewTextAttr = nullptr) = 0;
221 
222     virtual void InsertItemSet (const SwPaM &rRg, const SfxItemSet&,
223         const SetAttrMode nFlags = SetAttrMode::DEFAULT,
224         SwRootFrame const* pLayout = nullptr) = 0;
225 
226     /** Removes any leading white space from the paragraph
227     */
228     virtual void RemoveLeadingWhiteSpace(const SwPosition & rPos ) = 0;
229 
230 protected:
~IDocumentContentOperations()231     virtual ~IDocumentContentOperations() {};
232 };
233 
234 #endif // INCLUDED_SW_INC_IDOCUMENTCONTENTOPERATIONS_HXX
235 
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
237