Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / inc / IDocumentMarkAccess.hxx
blobd53f180d3fe9dbf3b157aea05450e74c1bb3d7bb
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 SaveBookmark; // FIXME: Ugly: SaveBookmark is a core-internal class, and should not be used in the interface
34 class MarkBase;
37 /** Provides access to the marks of a document.
39 class IDocumentMarkAccess
41 public:
42 enum class MarkType
44 UNO_BOOKMARK,
45 DDE_BOOKMARK,
46 BOOKMARK,
47 CROSSREF_HEADING_BOOKMARK,
48 CROSSREF_NUMITEM_BOOKMARK,
49 ANNOTATIONMARK,
50 TEXT_FIELDMARK,
51 CHECKBOX_FIELDMARK,
52 DROPDOWN_FIELDMARK,
53 DATE_FIELDMARK,
54 NAVIGATOR_REMINDER
57 /** wrapper iterator: wraps iterator of implementation while hiding
58 MarkBase class; only IMark instances can be retrieved directly.
60 class SW_DLLPUBLIC iterator
62 private:
63 std::optional<std::vector<::sw::mark::MarkBase*>::const_iterator> m_pIter;
65 public:
66 // MarkManager implementation needs to get the real iterator
67 std::vector<::sw::mark::MarkBase*>::const_iterator const& get() const;
69 typedef std::ptrdiff_t difference_type;
70 typedef ::sw::mark::IMark* value_type;
71 typedef ::sw::mark::IMark* const* pointer;
72 typedef ::sw::mark::IMark* const& reference;
73 typedef std::random_access_iterator_tag iterator_category;
75 iterator();
76 iterator(std::vector<::sw::mark::MarkBase*>::const_iterator const& rIter);
77 iterator(iterator const& rOther);
78 iterator& operator=(iterator const& rOther);
79 iterator(iterator && rOther) noexcept;
80 iterator& operator=(iterator && rOther) noexcept;
82 // FIXME unfortunately there's a requirement on input iterator
83 // and forward iterator to return reference, which isn't
84 // possible because we have to return a temp value;
85 // let's try value_type instead, perhaps it's sufficient,
86 // for a const_iterator...
87 ::sw::mark::IMark* /*const&*/ operator*() const;
88 // nope can't do that :(
89 //::sw::mark::IMark* /* const* */ operator->() const;
90 iterator& operator++();
91 iterator operator++(int);
92 bool operator==(iterator const& rOther) const;
93 bool operator!=(iterator const& rOther) const;
94 iterator& operator--();
95 iterator operator--(int);
96 iterator& operator+=(difference_type);
97 iterator operator+(difference_type) const;
98 iterator& operator-=(difference_type);
99 iterator operator-(difference_type) const;
100 difference_type operator-(iterator const&) const;
101 value_type operator[](difference_type) const;
102 bool operator<(iterator const& rOther) const;
103 bool operator>(iterator const& rOther) const;
104 bool operator<=(iterator const& rOther) const;
105 bool operator>=(iterator const& rOther) const;
108 typedef iterator const_iterator_t;
110 /// To avoid recursive calls of deleteMark, the removal of dummy
111 /// characters of fieldmarks has to be delayed; this is the baseclass
112 /// that can be subclassed for that purpose.
113 struct ILazyDeleter { virtual ~ILazyDeleter() { } };
115 /** Generates a new mark in the document for a certain selection.
117 @param rPaM
118 [in] the selection being marked.
120 @param rProposedName
121 [in] the proposed name of the new mark.
123 @param eMark
124 [in] the type of the new mark.
126 @param eMode
127 [in] is the new mark part of a text copy operation
129 @returns
130 a pointer to the new mark (name might have changed).
132 virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM,
133 const OUString& rProposedName,
134 MarkType eMark, ::sw::mark::InsertMode eMode,
135 SwPosition const* pSepPos = nullptr) = 0;
137 virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM,
138 const OUString& rName,
139 const OUString& rType,
140 SwPosition const* pSepPos = nullptr) = 0;
141 virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM,
142 const OUString& rName,
143 const OUString& rType) = 0;
145 virtual sw::mark::IMark* makeAnnotationMark(
146 const SwPaM& rPaM,
147 const OUString& rName ) = 0;
149 /** Returns a mark in the document for a paragraph.
150 If there is none, a mark will be created.
152 @param rTextNode
153 [in] the paragraph being marked (a selection over the paragraph is marked)
155 @param eMark
156 [in] the type of the new mark.
158 @returns
159 a pointer to the new mark (name might have changed).
161 virtual ::sw::mark::IMark* getMarkForTextNode(const SwTextNode& rTextNode,
162 MarkType eMark) =0;
164 /** Moves an existing mark to a new selection and performs needed updates.
165 @param io_pMark
166 [in/out] the mark to be moved
168 @param rPaM
169 [in] new selection to be marked
172 virtual void repositionMark(::sw::mark::IMark* io_pMark,
173 const SwPaM& rPaM) =0;
175 /** Renames an existing Mark, if possible.
176 @param io_pMark
177 [in/out] the mark to be renamed
179 @param rNewName
180 [in] new name for the mark
182 @returns false, if renaming failed (because the name is already in use)
184 virtual bool renameMark(::sw::mark::IMark* io_pMark,
185 const OUString& rNewName) =0;
187 /** Corrects marks (absolute)
188 This method ignores the previous position of the mark in the paragraph
190 @param rOldNode
191 [in] the node from which nodes should be moved
193 @param rNewPos
194 [in] new position to which marks will be moved, if nOffset == 0
196 @param nOffset
197 [in] the offset by which the mark gets positioned of rNewPos
199 virtual void correctMarksAbsolute(const SwNode& rOldNode,
200 const SwPosition& rNewPos,
201 const sal_Int32 nOffset) =0;
203 /** Corrects marks (relative)
204 This method uses the previous position of the mark in the paragraph as offset
206 @param rOldNode
207 [in] the node from which nodes should be moved
209 @param rNewPos
210 [in] new position to which marks from the start of the paragraph will be
211 moved, if nOffset == 0
213 @param nOffset
214 [in] the offset by which the mark gets positioned of rNewPos in addition to
215 its old position in the paragraph
217 virtual void correctMarksRelative(const SwNode& rOldNode,
218 const SwPosition& rNewPos,
219 const sal_Int32 nOffset) =0;
221 /** Deletes marks in a range
223 Note: navigator reminders are excluded
226 virtual void deleteMarks(
227 const SwNode& rStt,
228 const SwNode& rEnd,
229 std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk, // Ugly: SaveBookmark is core-internal
230 std::optional<sal_Int32> oStartContentIdx,
231 std::optional<sal_Int32> oEndContentIdx) =0;
233 /** Deletes a mark.
235 @param ppMark
236 [in] an iterator pointing to the Mark to be deleted.
237 @param isMoveNodes
238 [in] the mark is deleted only temporarily for a node move, do not
239 remove fieldmark chars.
241 virtual std::unique_ptr<ILazyDeleter>
242 deleteMark(const IDocumentMarkAccess::const_iterator_t& ppMark, bool isMoveNodes) =0;
244 /** Deletes a mark.
246 @param ppMark
247 [in] the name of the mark to be deleted.
249 virtual void deleteMark(const ::sw::mark::IMark* const pMark) =0;
251 /** Clear (deletes) all marks.
253 virtual void clearAllMarks() =0;
255 virtual void assureSortedMarkContainers() const = 0;
257 /** returns a STL-like random access iterator to the begin of the sequence of marks.
259 virtual const_iterator_t getAllMarksBegin() const =0;
261 /** returns a STL-like random access iterator to the end of the sequence of marks.
263 virtual const_iterator_t getAllMarksEnd() const =0;
265 /** returns the number of marks.
267 Note: annotation marks are excluded
269 virtual sal_Int32 getAllMarksCount() const =0;
271 /** Finds a mark by name.
273 @param rName
274 [in] the name of the mark to find.
276 @returns
277 an iterator pointing to the mark, or pointing to getAllMarksEnd() if nothing was found.
279 virtual const_iterator_t findMark(const OUString& rMark) const =0;
281 // interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK )
283 /** check if the selection would delete a BOOKMARK */
284 virtual bool isBookmarkDeleted(SwPaM const& rPaM, bool isReplace) const =0;
286 /** returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
288 virtual const_iterator_t getBookmarksBegin() const =0;
290 /** returns a STL-like random access iterator to the end of the sequence of IBookmarks.
292 virtual const_iterator_t getBookmarksEnd() const =0;
294 /** returns the number of IBookmarks.
296 virtual sal_Int32 getBookmarksCount() const =0;
298 /** Finds a bookmark by name.
300 @param rName
301 [in] the name of the bookmark to find.
303 @returns
304 an iterator pointing to the bookmark, or getBookmarksEnd() if nothing was found.
306 virtual const_iterator_t findBookmark(const OUString& rMark) const =0;
308 /** Finds the first mark that is starting after.
310 @returns
311 an iterator pointing to the mark, or pointing to getBookmarksEnd() if nothing was found.
313 virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const =0;
315 /// Get the innermost bookmark that contains rPos.
316 virtual sw::mark::IMark* getOneInnermostBookmarkFor(const SwPosition& rPos) const = 0;
318 // Fieldmarks
319 /** returns a STL-like random access iterator to the begin of the sequence of fieldmarks.
321 virtual const_iterator_t getFieldmarksBegin() const =0;
323 /** returns a STL-like random access iterator to the end of the sequence of fieldmarks.
325 virtual const_iterator_t getFieldmarksEnd() const =0;
327 /// returns the number of IFieldmarks.
328 virtual sal_Int32 getFieldmarksCount() const = 0;
330 /// get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos
331 virtual ::sw::mark::IFieldmark* getFieldmarkAt(const SwPosition& rPos) const =0;
332 virtual sw::mark::IFieldmark* getInnerFieldmarkFor(const SwPosition& pos) const = 0;
333 virtual sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& pos, bool bLoop) const =0;
334 virtual sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& pos, bool bLoop) const =0;
336 virtual ::sw::mark::IFieldmark* getDropDownFor(const SwPosition& pos) const=0;
337 virtual std::vector<::sw::mark::IFieldmark*> getNoTextFieldmarksIn(const SwPaM &rPaM) const=0;
339 virtual void deleteFieldmarkAt(const SwPosition& rPos) = 0;
340 virtual ::sw::mark::IFieldmark* changeFormFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) = 0;
342 virtual void NotifyCursorUpdate(const SwCursorShell& rCursorShell) = 0;
343 virtual void ClearFieldActivation() = 0;
345 // Annotation Marks
346 virtual const_iterator_t getAnnotationMarksBegin() const = 0;
347 virtual const_iterator_t getAnnotationMarksEnd() const = 0;
348 virtual sal_Int32 getAnnotationMarksCount() const = 0;
349 virtual const_iterator_t findAnnotationMark( const OUString& rName ) const = 0;
350 virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPosition) const = 0;
351 // handle and restore text ranges of annotations of tracked deletions
352 // based on the helper bookmarks (which can survive I/O and hiding redlines)
353 virtual ::sw::mark::IMark* makeAnnotationBookmark(const SwPaM& rPaM,
354 const OUString& rProposedName,
355 MarkType eMark, ::sw::mark::InsertMode eMode,
356 SwPosition const* pSepPos = nullptr) = 0;
357 virtual const_iterator_t findAnnotationBookmark( const OUString& rName ) const = 0;
358 virtual void restoreAnnotationMarks(bool bDelete = true) = 0;
359 /** Finds the first mark that is starting after.
361 @returns
362 an iterator pointing to the mark, or pointing to getAnnotationMarksEnd() if nothing was found.
364 virtual const_iterator_t findFirstAnnotationStartsAfter(const SwPosition& rPos) const =0;
366 /** Returns the MarkType used to create the mark
368 static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark& rMark);
370 static SW_DLLPUBLIC OUString GetCrossRefHeadingBookmarkNamePrefix();
371 static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark( const SwPaM& rPaM );
372 static void DeleteFieldmarkCommand(::sw::mark::IFieldmark const& rMark);
374 protected:
375 virtual ~IDocumentMarkAccess() {};
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */