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 .
20 #ifndef INCLUDED_SW_INC_IDOCUMENTMARKACCESS_HXX
21 #define INCLUDED_SW_INC_IDOCUMENTMARKACCESS_HXX
23 #include <sal/types.h>
32 namespace sw
{ namespace mark
{
33 class SaveBookmark
; // FIXME: Ugly: SaveBookmark is a core-internal class, and should not be used in the interface
37 /** Provides access to the marks of a document.
39 class IDocumentMarkAccess
47 CROSSREF_HEADING_BOOKMARK
,
48 CROSSREF_NUMITEM_BOOKMARK
,
57 /** wrapper iterator: wraps iterator of implementation while hiding
58 MarkBase class; only IMark instances can be retrieved directly.
60 class SW_DLLPUBLIC iterator
63 std::unique_ptr
<std::vector
<::sw::mark::MarkBase
*>::const_iterator
> m_pIter
;
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
;
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
;
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.
119 [in] the selection being marked.
122 [in] the proposed name of the new mark.
125 [in] the type of the new mark.
128 [in] is the new mark part of a text copy operation
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(
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.
154 [in] the paragraph being marked (a selection over the paragraph is marked)
157 [in] the type of the new mark.
160 a pointer to the new mark (name might have changed).
162 virtual ::sw::mark::IMark
* getMarkForTextNode(const SwTextNode
& rTextNode
,
165 /** Moves an existing mark to a new selection and performs needed updates.
167 [in/out] the mark to be moved
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.
178 [in/out] the mark to be renamed
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
192 [in] the node from which nodes should be moved
195 [in] new position to which marks will be moved, if nOffset == 0
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
208 [in] the node from which nodes should be moved
211 [in] new position to which marks from the start of the paragraph will be
212 moved, if nOffset == 0
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;
237 [in] an iterator pointing to the Mark to be deleted.
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;
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.
275 [in] the name of the mark to find.
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 /** 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.
299 [in] the name of the bookmark to find.
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.
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;
315 /// get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos
316 virtual ::sw::mark::IFieldmark
* getFieldmarkAt(const SwPosition
& rPos
) const =0;
317 virtual ::sw::mark::IFieldmark
* getFieldmarkFor(const SwPosition
& pos
) const =0;
318 virtual ::sw::mark::IFieldmark
* getFieldmarkBefore(const SwPosition
& pos
) const =0;
319 virtual ::sw::mark::IFieldmark
* getFieldmarkAfter(const SwPosition
& pos
) const =0;
321 virtual ::sw::mark::IFieldmark
* getDropDownFor(const SwPosition
& pos
) const=0;
322 virtual std::vector
< ::sw::mark::IFieldmark
* > getDropDownsFor(const SwPaM
&rPaM
) const=0;
324 virtual void deleteFieldmarkAt(const SwPosition
& rPos
) = 0;
325 virtual ::sw::mark::IFieldmark
* changeFormFieldmarkType(::sw::mark::IFieldmark
* pFieldmark
, const OUString
& rNewType
) = 0;
327 virtual void NotifyCursorUpdate(const SwCursorShell
& rCursorShell
) = 0;
328 virtual void ClearFieldActivation() = 0;
331 virtual const_iterator_t
getAnnotationMarksBegin() const = 0;
332 virtual const_iterator_t
getAnnotationMarksEnd() const = 0;
333 virtual sal_Int32
getAnnotationMarksCount() const = 0;
334 virtual const_iterator_t
findAnnotationMark( const OUString
& rName
) const = 0;
335 virtual sw::mark::IMark
* getAnnotationMarkFor(const SwPosition
& rPosition
) const = 0;
336 /** Finds the first mark that is starting after.
339 an iterator pointing to the mark, or pointing to getAnnotationMarksEnd() if nothing was found.
341 virtual const_iterator_t
findFirstAnnotationStartsAfter(const SwPosition
& rPos
) const =0;
343 /** Returns the MarkType used to create the mark
345 static SW_DLLPUBLIC MarkType
GetType(const ::sw::mark::IMark
& rMark
);
347 static SW_DLLPUBLIC OUString
GetCrossRefHeadingBookmarkNamePrefix();
348 static SW_DLLPUBLIC
bool IsLegalPaMForCrossRefHeadingBookmark( const SwPaM
& rPaM
);
349 static void DeleteFieldmarkCommand(::sw::mark::IFieldmark
const& rMark
);
352 virtual ~IDocumentMarkAccess() {};
355 #endif // IDOCUMENTBOOKMARKACCESS_HXX_INCLUDED
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */