1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <sal/types.h>
34 class SaveBookmark
; // FIXME: Ugly: SaveBookmark is a core-internal class, and should not be used in the interface
39 /** Provides access to the marks of a document.
41 class IDocumentMarkAccess
49 CROSSREF_HEADING_BOOKMARK
,
50 CROSSREF_NUMITEM_BOOKMARK
,
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.
70 [in] the selection being marked.
73 [in] the proposed name of the new mark.
76 [in] the type of the new mark.
79 [in] is the new mark part of a text copy operation
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(
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.
105 [in] the paragraph being marked (a selection over the paragraph is marked)
108 [in] the type of the new mark.
111 a pointer to the new mark (name might have changed).
113 virtual ::sw::mark::MarkBase
* getMarkForTextNode(const SwTextNode
& rTextNode
,
116 /** Moves an existing mark to a new selection and performs needed updates.
118 [in/out] the mark to be moved
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.
129 [in/out] the mark to be renamed
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
143 [in] the node from which nodes should be moved
146 [in] new position to which marks will be moved, if nOffset == 0
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
159 [in] the node from which nodes should be moved
162 [in] new position to which marks from the start of the paragraph will be
163 moved, if nOffset == 0
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(
181 std::vector
< ::sw::mark::SaveBookmark
>* pSaveBkmk
, // Ugly: SaveBookmark is core-internal
182 std::optional
<sal_Int32
> oStartContentIdx
,
183 std::optional
<sal_Int32
> oEndContentIdx
,
189 [in] an iterator pointing to the Mark to be deleted.
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;
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.
234 [in] the name of the mark to find.
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.
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.
268 [in] the name of the bookmark to find.
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.
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;
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;
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.
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
);
343 virtual ~IDocumentMarkAccess() {};
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */