sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / sw / inc / IDocumentMarkAccess.hxx
blobbfec4c53bfcddd768021e65efbaa70ed08f6c8bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <sal/types.h>
23 #include "IMark.hxx"
24 #include <memory>
25 #include <optional>
27 class SwPaM;
28 struct SwPosition;
29 class SwTextNode;
30 class SwCursorShell;
32 namespace sw::mark {
33 class AnnotationMark;
34 class SaveBookmark; // FIXME: Ugly: SaveBookmark is a core-internal class, and should not be used in the interface
35 class MarkBase;
36 class Fieldmark;
39 /** Provides access to the marks of a document.
41 class IDocumentMarkAccess
43 public:
44 enum class MarkType
46 UNO_BOOKMARK,
47 DDE_BOOKMARK,
48 BOOKMARK,
49 CROSSREF_HEADING_BOOKMARK,
50 CROSSREF_NUMITEM_BOOKMARK,
51 ANNOTATIONMARK,
52 TEXT_FIELDMARK,
53 CHECKBOX_FIELDMARK,
54 DROPDOWN_FIELDMARK,
55 DATE_FIELDMARK,
56 NAVIGATOR_REMINDER
59 typedef std::vector<::sw::mark::MarkBase*>::const_iterator const_iterator;
60 typedef std::vector<::sw::mark::MarkBase*>::iterator iterator;
62 /// To avoid recursive calls of deleteMark, the removal of dummy
63 /// characters of fieldmarks has to be delayed; this is the baseclass
64 /// that can be subclassed for that purpose.
65 struct ILazyDeleter { virtual ~ILazyDeleter() { } };
67 /** Generates a new mark in the document for a certain selection.
69 @param rPaM
70 [in] the selection being marked.
72 @param rProposedName
73 [in] the proposed name of the new mark.
75 @param eMark
76 [in] the type of the new mark.
78 @param eMode
79 [in] is the new mark part of a text copy operation
81 @returns
82 a pointer to the new mark (name might have changed).
84 virtual ::sw::mark::MarkBase* makeMark(const SwPaM& rPaM,
85 const OUString& rProposedName,
86 MarkType eMark, ::sw::mark::InsertMode eMode,
87 SwPosition const* pSepPos = nullptr) = 0;
89 virtual sw::mark::Fieldmark* makeFieldBookmark( const SwPaM& rPaM,
90 const OUString& rName,
91 const OUString& rType,
92 SwPosition const* pSepPos = nullptr) = 0;
93 virtual sw::mark::Fieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM,
94 const OUString& rName,
95 const OUString& rType) = 0;
97 virtual sw::mark::MarkBase* makeAnnotationMark(
98 const SwPaM& rPaM,
99 const OUString& rName ) = 0;
101 /** Returns a mark in the document for a paragraph.
102 If there is none, a mark will be created.
104 @param rTextNode
105 [in] the paragraph being marked (a selection over the paragraph is marked)
107 @param eMark
108 [in] the type of the new mark.
110 @returns
111 a pointer to the new mark (name might have changed).
113 virtual ::sw::mark::MarkBase* getMarkForTextNode(const SwTextNode& rTextNode,
114 MarkType eMark) =0;
116 /** Moves an existing mark to a new selection and performs needed updates.
117 @param io_pMark
118 [in/out] the mark to be moved
120 @param rPaM
121 [in] new selection to be marked
124 virtual void repositionMark(::sw::mark::MarkBase* io_pMark,
125 const SwPaM& rPaM) =0;
127 /** Renames an existing Mark, if possible.
128 @param io_pMark
129 [in/out] the mark to be renamed
131 @param rNewName
132 [in] new name for the mark
134 @returns false, if renaming failed (because the name is already in use)
136 virtual bool renameMark(::sw::mark::MarkBase* io_pMark,
137 const OUString& rNewName) =0;
139 /** Corrects marks (absolute)
140 This method ignores the previous position of the mark in the paragraph
142 @param rOldNode
143 [in] the node from which nodes should be moved
145 @param rNewPos
146 [in] new position to which marks will be moved, if nOffset == 0
148 @param nOffset
149 [in] the offset by which the mark gets positioned of rNewPos
151 virtual void correctMarksAbsolute(const SwNode& rOldNode,
152 const SwPosition& rNewPos,
153 const sal_Int32 nOffset) =0;
155 /** Corrects marks (relative)
156 This method uses the previous position of the mark in the paragraph as offset
158 @param rOldNode
159 [in] the node from which nodes should be moved
161 @param rNewPos
162 [in] new position to which marks from the start of the paragraph will be
163 moved, if nOffset == 0
165 @param nOffset
166 [in] the offset by which the mark gets positioned of rNewPos in addition to
167 its old position in the paragraph
169 virtual void correctMarksRelative(const SwNode& rOldNode,
170 const SwPosition& rNewPos,
171 const sal_Int32 nOffset) =0;
173 /** Deletes marks in a range
175 Note: navigator reminders are excluded
178 virtual void deleteMarks(
179 const SwNode& rStt,
180 const SwNode& rEnd,
181 std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk, // Ugly: SaveBookmark is core-internal
182 std::optional<sal_Int32> oStartContentIdx,
183 std::optional<sal_Int32> oEndContentIdx,
184 bool isReplace) = 0;
186 /** Deletes a mark.
188 @param ppMark
189 [in] an iterator pointing to the Mark to be deleted.
190 @param isMoveNodes
191 [in] the mark is deleted only temporarily for a node move, do not
192 remove fieldmark chars.
194 virtual std::unique_ptr<ILazyDeleter>
195 deleteMark(const IDocumentMarkAccess::const_iterator& ppMark, bool isMoveNodes) =0;
197 /** Deletes a mark.
199 @param ppMark
200 [in] the name of the mark to be deleted.
202 virtual void deleteMark(const ::sw::mark::MarkBase* const pMark) =0;
204 /** Clear (deletes) all marks.
206 virtual void clearAllMarks() =0;
208 virtual void assureSortedMarkContainers() const = 0;
211 * called when we need to sort a sub-range of the container, elements starting
212 * at nMinIndexModified where modified. This is used from ContentIdxStoreImpl::RestoreBkmks,
213 * where we are only modifying a small range at the end of the container.
215 virtual void assureSortedMarkContainers(sal_Int32 nMinIndexModified) const = 0;
217 /** returns a STL-like random access iterator to the begin of the sequence of marks.
219 virtual const_iterator getAllMarksBegin() const =0;
221 /** returns a STL-like random access iterator to the end of the sequence of marks.
223 virtual const_iterator getAllMarksEnd() const =0;
225 /** returns the number of marks.
227 Note: annotation marks are excluded
229 virtual sal_Int32 getAllMarksCount() const =0;
231 /** Finds a mark by name.
233 @param rName
234 [in] the name of the mark to find.
236 @returns
237 an iterator pointing to the mark, or pointing to getAllMarksEnd() if nothing was found.
239 virtual const_iterator findMark(const OUString& rMark) const =0;
241 /** Find the first Bookmark that does not start before.
243 @returns
244 an iterator pointing to the mark, or pointing to getAllMarksEnd() if nothing was found.
246 virtual std::vector<sw::mark::Bookmark*>::const_iterator findFirstBookmarkNotStartsBefore(const SwPosition& rPos) const =0;
248 // interface Bookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK )
250 /** check if the selection would delete a BOOKMARK */
251 virtual bool isBookmarkDeleted(SwPaM const& rPaM, bool isReplace) const =0;
253 /** returns a STL-like random access iterator to the begin of the sequence the Bookmarks.
255 virtual std::vector<sw::mark::Bookmark*>::const_iterator getBookmarksBegin() const =0;
257 /** returns a STL-like random access iterator to the end of the sequence of Bookmarks.
259 virtual std::vector<sw::mark::Bookmark*>::const_iterator getBookmarksEnd() const =0;
261 /** returns the number of Bookmarks.
263 virtual sal_Int32 getBookmarksCount() const =0;
265 /** Finds a bookmark by name.
267 @param rName
268 [in] the name of the bookmark to find.
270 @returns
271 an iterator pointing to the bookmark, or getBookmarksEnd() if nothing was found.
273 virtual std::vector<sw::mark::Bookmark*>::const_iterator findBookmark(const OUString& rMark) const =0;
275 /** Finds the first mark that is starting after.
277 @returns
278 an iterator pointing to the mark, or pointing to getBookmarksEnd() if nothing was found.
280 virtual std::vector<sw::mark::Bookmark*>::const_iterator findFirstBookmarkStartsAfter(const SwPosition& rPos) const =0;
282 /// Get the innermost bookmark that contains rPos.
283 virtual sw::mark::Bookmark* getOneInnermostBookmarkFor(const SwPosition& rPos) const = 0;
285 // Fieldmarks
286 /** returns a STL-like random access iterator to the begin of the sequence of fieldmarks.
288 virtual std::vector<sw::mark::Fieldmark*>::const_iterator getFieldmarksBegin() const =0;
290 /** returns a STL-like random access iterator to the end of the sequence of fieldmarks.
292 virtual std::vector<sw::mark::Fieldmark*>::const_iterator getFieldmarksEnd() const =0;
294 /// returns the number of Fieldmarks.
295 virtual sal_Int32 getFieldmarksCount() const = 0;
297 /// get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos
298 virtual ::sw::mark::Fieldmark* getFieldmarkAt(const SwPosition& rPos) const =0;
299 virtual sw::mark::Fieldmark* getInnerFieldmarkFor(const SwPosition& pos) const = 0;
300 virtual sw::mark::Fieldmark* getFieldmarkBefore(const SwPosition& pos, bool bLoop) const =0;
301 virtual sw::mark::Fieldmark* getFieldmarkAfter(const SwPosition& pos, bool bLoop) const =0;
303 virtual ::sw::mark::Fieldmark* getDropDownFor(const SwPosition& pos) const=0;
304 virtual std::vector<::sw::mark::Fieldmark*> getNoTextFieldmarksIn(const SwPaM &rPaM) const=0;
306 virtual void deleteFieldmarkAt(const SwPosition& rPos) = 0;
307 virtual ::sw::mark::Fieldmark* changeFormFieldmarkType(::sw::mark::Fieldmark* pFieldmark, const OUString& rNewType) = 0;
309 virtual void NotifyCursorUpdate(const SwCursorShell& rCursorShell) = 0;
310 virtual void ClearFieldActivation() = 0;
312 // Annotation Marks
313 virtual std::vector<sw::mark::AnnotationMark*>::const_iterator getAnnotationMarksBegin() const = 0;
314 virtual std::vector<sw::mark::AnnotationMark*>::const_iterator getAnnotationMarksEnd() const = 0;
315 virtual sal_Int32 getAnnotationMarksCount() const = 0;
316 virtual std::vector<sw::mark::AnnotationMark*>::const_iterator findAnnotationMark( const OUString& rName ) const = 0;
317 virtual sw::mark::AnnotationMark* getAnnotationMarkFor(const SwPosition& rPosition) const = 0;
318 // handle and restore text ranges of annotations of tracked deletions
319 // based on the helper bookmarks (which can survive I/O and hiding redlines)
320 virtual ::sw::mark::Bookmark* makeAnnotationBookmark(const SwPaM& rPaM,
321 const OUString& rProposedName,
322 ::sw::mark::InsertMode eMode,
323 SwPosition const* pSepPos = nullptr) = 0;
324 /** Find the first AnnotationMark that does not start before.
326 @returns
327 an iterator pointing to the mark, or pointing to getAnnotationMarksEnd() if nothing was found.
329 virtual std::vector<sw::mark::AnnotationMark*>::const_iterator findFirstAnnotationMarkNotStartsBefore(const SwPosition& rPos) const =0;
330 virtual std::vector<sw::mark::AnnotationMark*>::const_iterator findFirstAnnotationMarkNotStartsBefore(const SwNode& rPos) const =0;
331 virtual std::vector<sw::mark::Bookmark*>::const_iterator findAnnotationBookmark( const OUString& rName ) const = 0;
332 virtual void restoreAnnotationMarks(bool bDelete = true) = 0;
334 /** Returns the MarkType used to create the mark
336 static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::MarkBase& rMark);
338 static SW_DLLPUBLIC OUString GetCrossRefHeadingBookmarkNamePrefix();
339 static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark( const SwPaM& rPaM );
340 static void DeleteFieldmarkCommand(::sw::mark::Fieldmark const& rMark);
342 protected:
343 virtual ~IDocumentMarkAccess() {};
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */