Coverage Report

Created: 2025-12-08 09:28

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