Bump version to 21.06.18.1
[LibreOffice.git] / sw / inc / IDocumentMarkAccess.hxx
blob1ad39701d02bb1905413a8060c0cce4272b45042
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>
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::unique_ptr<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;
81 ~iterator();
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.
239 virtual std::unique_ptr<ILazyDeleter>
240 deleteMark(const IDocumentMarkAccess::const_iterator_t& ppMark) =0;
242 /** Deletes a mark.
244 @param ppMark
245 [in] the name of the mark to be deleted.
247 virtual void deleteMark(const ::sw::mark::IMark* const pMark) =0;
249 /** Clear (deletes) all marks.
251 virtual void clearAllMarks() =0;
253 virtual void assureSortedMarkContainers() const = 0;
255 /** returns a STL-like random access iterator to the begin of the sequence of marks.
257 virtual const_iterator_t getAllMarksBegin() const =0;
259 /** returns a STL-like random access iterator to the end of the sequence of marks.
261 virtual const_iterator_t getAllMarksEnd() const =0;
263 /** returns the number of marks.
265 Note: annotation marks are excluded
267 virtual sal_Int32 getAllMarksCount() const =0;
269 /** Finds a mark by name.
271 @param rName
272 [in] the name of the mark to find.
274 @returns
275 an iterator pointing to the mark, or pointing to getAllMarksEnd() if nothing was found.
277 virtual const_iterator_t findMark(const OUString& rMark) const =0;
279 // interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK )
281 /** check if the selection would delete a BOOKMARK */
282 virtual bool isBookmarkDeleted(SwPaM const& rPaM) const =0;
284 /** returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
286 virtual const_iterator_t getBookmarksBegin() const =0;
288 /** returns a STL-like random access iterator to the end of the sequence of IBookmarks.
290 virtual const_iterator_t getBookmarksEnd() const =0;
292 /** returns the number of IBookmarks.
294 virtual sal_Int32 getBookmarksCount() const =0;
296 /** Finds a bookmark by name.
298 @param rName
299 [in] the name of the bookmark to find.
301 @returns
302 an iterator pointing to the bookmark, or getBookmarksEnd() if nothing was found.
304 virtual const_iterator_t findBookmark(const OUString& rMark) const =0;
306 /** Finds the first mark that is starting after.
308 @returns
309 an iterator pointing to the mark, or pointing to getBookmarksEnd() if nothing was found.
311 virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const =0;
314 // Fieldmarks
315 /** returns a STL-like random access iterator to the begin of the sequence of fieldmarks.
317 virtual const_iterator_t getFieldmarksBegin() const =0;
319 /** returns a STL-like random access iterator to the end of the sequence of fieldmarks.
321 virtual const_iterator_t getFieldmarksEnd() const =0;
323 /// get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos
324 virtual ::sw::mark::IFieldmark* getFieldmarkAt(const SwPosition& rPos) const =0;
325 virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& pos) const =0;
326 virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& pos) const =0;
327 virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& pos) const =0;
329 virtual ::sw::mark::IFieldmark* getDropDownFor(const SwPosition& pos) const=0;
330 virtual std::vector< ::sw::mark::IFieldmark* > getDropDownsFor(const SwPaM &rPaM) const=0;
332 virtual void deleteFieldmarkAt(const SwPosition& rPos) = 0;
333 virtual ::sw::mark::IFieldmark* changeFormFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) = 0;
335 virtual void NotifyCursorUpdate(const SwCursorShell& rCursorShell) = 0;
336 virtual void ClearFieldActivation() = 0;
338 // Annotation Marks
339 virtual const_iterator_t getAnnotationMarksBegin() const = 0;
340 virtual const_iterator_t getAnnotationMarksEnd() const = 0;
341 virtual sal_Int32 getAnnotationMarksCount() const = 0;
342 virtual const_iterator_t findAnnotationMark( const OUString& rName ) const = 0;
343 virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPosition) const = 0;
344 /** Finds the first mark that is starting after.
346 @returns
347 an iterator pointing to the mark, or pointing to getAnnotationMarksEnd() if nothing was found.
349 virtual const_iterator_t findFirstAnnotationStartsAfter(const SwPosition& rPos) const =0;
351 /** Returns the MarkType used to create the mark
353 static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark& rMark);
355 static SW_DLLPUBLIC OUString GetCrossRefHeadingBookmarkNamePrefix();
356 static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark( const SwPaM& rPaM );
357 static void DeleteFieldmarkCommand(::sw::mark::IFieldmark const& rMark);
359 protected:
360 virtual ~IDocumentMarkAccess() {};
363 #endif // IDOCUMENTBOOKMARKACCESS_HXX_INCLUDED
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */