Cleanup restoring last position
[LibreOffice.git] / sw / inc / IDocumentMarkAccess.hxx
blob1243f5853e0b4e98fb797ff41cfd2cd16fd5992b
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 #ifndef INCLUDED_SW_INC_IDOCUMENTMARKACCESS_HXX
21 #define INCLUDED_SW_INC_IDOCUMENTMARKACCESS_HXX
23 #include <sal/types.h>
24 #include "IMark.hxx"
25 #include <memory>
26 #include <optional>
28 class SwPaM;
29 struct SwPosition;
30 class SwTextNode;
31 class SwCursorShell;
33 namespace sw::mark {
34 class SaveBookmark; // FIXME: Ugly: SaveBookmark is a core-internal class, and should not be used in the interface
35 class MarkBase;
38 /** Provides access to the marks of a document.
40 class IDocumentMarkAccess
42 public:
43 enum class MarkType
45 UNO_BOOKMARK,
46 DDE_BOOKMARK,
47 BOOKMARK,
48 CROSSREF_HEADING_BOOKMARK,
49 CROSSREF_NUMITEM_BOOKMARK,
50 ANNOTATIONMARK,
51 TEXT_FIELDMARK,
52 CHECKBOX_FIELDMARK,
53 DROPDOWN_FIELDMARK,
54 DATE_FIELDMARK,
55 NAVIGATOR_REMINDER
58 /** wrapper iterator: wraps iterator of implementation while hiding
59 MarkBase class; only IMark instances can be retrieved directly.
61 class SW_DLLPUBLIC iterator
63 private:
64 std::optional<std::vector<::sw::mark::MarkBase*>::const_iterator> m_pIter;
66 public:
67 // MarkManager implementation needs to get the real iterator
68 std::vector<::sw::mark::MarkBase*>::const_iterator const& get() const;
70 typedef std::ptrdiff_t difference_type;
71 typedef ::sw::mark::IMark* value_type;
72 typedef ::sw::mark::IMark* const* pointer;
73 typedef ::sw::mark::IMark* const& reference;
74 typedef std::random_access_iterator_tag iterator_category;
76 iterator();
77 iterator(std::vector<::sw::mark::MarkBase*>::const_iterator const& rIter);
78 iterator(iterator const& rOther);
79 iterator& operator=(iterator const& rOther);
80 iterator(iterator && rOther) noexcept;
81 iterator& operator=(iterator && rOther) noexcept;
83 // FIXME unfortunately there's a requirement on input iterator
84 // and forward iterator to return reference, which isn't
85 // possible because we have to return a temp value;
86 // let's try value_type instead, perhaps it's sufficient,
87 // for a const_iterator...
88 ::sw::mark::IMark* /*const&*/ operator*() const;
89 // nope can't do that :(
90 //::sw::mark::IMark* /* const* */ operator->() const;
91 iterator& operator++();
92 iterator operator++(int);
93 bool operator==(iterator const& rOther) const;
94 bool operator!=(iterator const& rOther) const;
95 iterator& operator--();
96 iterator operator--(int);
97 iterator& operator+=(difference_type);
98 iterator operator+(difference_type) const;
99 iterator& operator-=(difference_type);
100 iterator operator-(difference_type) const;
101 difference_type operator-(iterator const&) const;
102 value_type operator[](difference_type) const;
103 bool operator<(iterator const& rOther) const;
104 bool operator>(iterator const& rOther) const;
105 bool operator<=(iterator const& rOther) const;
106 bool operator>=(iterator const& rOther) const;
109 typedef iterator const_iterator_t;
111 /// To avoid recursive calls of deleteMark, the removal of dummy
112 /// characters of fieldmarks has to be delayed; this is the baseclass
113 /// that can be subclassed for that purpose.
114 struct ILazyDeleter { virtual ~ILazyDeleter() { } };
116 /** Generates a new mark in the document for a certain selection.
118 @param rPaM
119 [in] the selection being marked.
121 @param rProposedName
122 [in] the proposed name of the new mark.
124 @param eMark
125 [in] the type of the new mark.
127 @param eMode
128 [in] is the new mark part of a text copy operation
130 @returns
131 a pointer to the new mark (name might have changed).
133 virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM,
134 const OUString& rProposedName,
135 MarkType eMark, ::sw::mark::InsertMode eMode,
136 SwPosition const* pSepPos = nullptr) = 0;
138 virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM,
139 const OUString& rName,
140 const OUString& rType,
141 SwPosition const* pSepPos = nullptr) = 0;
142 virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM,
143 const OUString& rName,
144 const OUString& rType) = 0;
146 virtual sw::mark::IMark* makeAnnotationMark(
147 const SwPaM& rPaM,
148 const OUString& rName ) = 0;
150 /** Returns a mark in the document for a paragraph.
151 If there is none, a mark will be created.
153 @param rTextNode
154 [in] the paragraph being marked (a selection over the paragraph is marked)
156 @param eMark
157 [in] the type of the new mark.
159 @returns
160 a pointer to the new mark (name might have changed).
162 virtual ::sw::mark::IMark* getMarkForTextNode(const SwTextNode& rTextNode,
163 MarkType eMark) =0;
165 /** Moves an existing mark to a new selection and performs needed updates.
166 @param io_pMark
167 [in/out] the mark to be moved
169 @param rPaM
170 [in] new selection to be marked
173 virtual void repositionMark(::sw::mark::IMark* io_pMark,
174 const SwPaM& rPaM) =0;
176 /** Renames an existing Mark, if possible.
177 @param io_pMark
178 [in/out] the mark to be renamed
180 @param rNewName
181 [in] new name for the mark
183 @returns false, if renaming failed (because the name is already in use)
185 virtual bool renameMark(::sw::mark::IMark* io_pMark,
186 const OUString& rNewName) =0;
188 /** Corrects marks (absolute)
189 This method ignores the previous position of the mark in the paragraph
191 @param rOldNode
192 [in] the node from which nodes should be moved
194 @param rNewPos
195 [in] new position to which marks will be moved, if nOffset == 0
197 @param nOffset
198 [in] the offset by which the mark gets positioned of rNewPos
200 virtual void correctMarksAbsolute(const SwNodeIndex& rOldNode,
201 const SwPosition& rNewPos,
202 const sal_Int32 nOffset) =0;
204 /** Corrects marks (relative)
205 This method uses the previous position of the mark in the paragraph as offset
207 @param rOldNode
208 [in] the node from which nodes should be moved
210 @param rNewPos
211 [in] new position to which marks from the start of the paragraph will be
212 moved, if nOffset == 0
214 @param nOffset
215 [in] the offset by which the mark gets positioned of rNewPos in addition to
216 its old position in the paragraph
218 virtual void correctMarksRelative(const SwNodeIndex& rOldNode,
219 const SwPosition& rNewPos,
220 const sal_Int32 nOffset) =0;
222 /** Deletes marks in a range
224 Note: navigator reminders are excluded
227 virtual void deleteMarks(
228 const SwNodeIndex& rStt,
229 const SwNodeIndex& rEnd,
230 std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk, // Ugly: SaveBookmark is core-internal
231 const SwIndex* pSttIdx,
232 const SwIndex* pEndIdx) =0;
234 /** Deletes a mark.
236 @param ppMark
237 [in] an iterator pointing to the Mark to be deleted.
238 @param isMoveNodes
239 [in] the mark is deleted only temporarily for a node move, do not
240 remove fieldmark chars.
242 virtual std::unique_ptr<ILazyDeleter>
243 deleteMark(const IDocumentMarkAccess::const_iterator_t& ppMark, bool isMoveNodes) =0;
245 /** Deletes a mark.
247 @param ppMark
248 [in] the name of the mark to be deleted.
250 virtual void deleteMark(const ::sw::mark::IMark* const pMark) =0;
252 /** Clear (deletes) all marks.
254 virtual void clearAllMarks() =0;
256 virtual void assureSortedMarkContainers() const = 0;
258 /** returns a STL-like random access iterator to the begin of the sequence of marks.
260 virtual const_iterator_t getAllMarksBegin() const =0;
262 /** returns a STL-like random access iterator to the end of the sequence of marks.
264 virtual const_iterator_t getAllMarksEnd() const =0;
266 /** returns the number of marks.
268 Note: annotation marks are excluded
270 virtual sal_Int32 getAllMarksCount() const =0;
272 /** Finds a mark by name.
274 @param rName
275 [in] the name of the mark to find.
277 @returns
278 an iterator pointing to the mark, or pointing to getAllMarksEnd() if nothing was found.
280 virtual const_iterator_t findMark(const OUString& rMark) const =0;
282 // interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK )
284 /** check if the selection would delete a BOOKMARK */
285 virtual bool isBookmarkDeleted(SwPaM const& rPaM) const =0;
287 /** returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
289 virtual const_iterator_t getBookmarksBegin() const =0;
291 /** returns a STL-like random access iterator to the end of the sequence of IBookmarks.
293 virtual const_iterator_t getBookmarksEnd() const =0;
295 /** returns the number of IBookmarks.
297 virtual sal_Int32 getBookmarksCount() const =0;
299 /** Finds a bookmark by name.
301 @param rName
302 [in] the name of the bookmark to find.
304 @returns
305 an iterator pointing to the bookmark, or getBookmarksEnd() if nothing was found.
307 virtual const_iterator_t findBookmark(const OUString& rMark) const =0;
309 /** Finds the first mark that is starting after.
311 @returns
312 an iterator pointing to the mark, or pointing to getBookmarksEnd() if nothing was found.
314 virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const =0;
317 // Fieldmarks
318 /** returns a STL-like random access iterator to the begin of the sequence of fieldmarks.
320 virtual const_iterator_t getFieldmarksBegin() const =0;
322 /** returns a STL-like random access iterator to the end of the sequence of fieldmarks.
324 virtual const_iterator_t getFieldmarksEnd() const =0;
326 /// get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos
327 virtual ::sw::mark::IFieldmark* getFieldmarkAt(const SwPosition& rPos) const =0;
328 virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& pos) const =0;
329 virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& pos) const =0;
330 virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& pos) const =0;
332 virtual ::sw::mark::IFieldmark* getDropDownFor(const SwPosition& pos) const=0;
333 virtual std::vector<::sw::mark::IFieldmark*> getNoTextFieldmarksIn(const SwPaM &rPaM) const=0;
335 virtual void deleteFieldmarkAt(const SwPosition& rPos) = 0;
336 virtual ::sw::mark::IFieldmark* changeFormFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) = 0;
338 virtual void NotifyCursorUpdate(const SwCursorShell& rCursorShell) = 0;
339 virtual void ClearFieldActivation() = 0;
341 // Annotation Marks
342 virtual const_iterator_t getAnnotationMarksBegin() const = 0;
343 virtual const_iterator_t getAnnotationMarksEnd() const = 0;
344 virtual sal_Int32 getAnnotationMarksCount() const = 0;
345 virtual const_iterator_t findAnnotationMark( const OUString& rName ) const = 0;
346 virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPosition) const = 0;
347 // handle and restore text ranges of annotations of tracked deletions
348 // based on the helper bookmarks (which can survive I/O and hiding redlines)
349 virtual ::sw::mark::IMark* makeAnnotationBookmark(const SwPaM& rPaM,
350 const OUString& rProposedName,
351 MarkType eMark, ::sw::mark::InsertMode eMode,
352 SwPosition const* pSepPos = nullptr) = 0;
353 virtual const_iterator_t findAnnotationBookmark( const OUString& rName ) const = 0;
354 virtual void restoreAnnotationMarks(bool bDelete = true) = 0;
355 /** Finds the first mark that is starting after.
357 @returns
358 an iterator pointing to the mark, or pointing to getAnnotationMarksEnd() if nothing was found.
360 virtual const_iterator_t findFirstAnnotationStartsAfter(const SwPosition& rPos) const =0;
362 /** Returns the MarkType used to create the mark
364 static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark& rMark);
366 static SW_DLLPUBLIC OUString GetCrossRefHeadingBookmarkNamePrefix();
367 static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark( const SwPaM& rPaM );
368 static void DeleteFieldmarkCommand(::sw::mark::IFieldmark const& rMark);
370 protected:
371 virtual ~IDocumentMarkAccess() {};
374 #endif // IDOCUMENTBOOKMARKACCESS_HXX_INCLUDED
376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */