LibreOffice Module sw (master) 1
MarkManager.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_SW_SOURCE_CORE_INC_MARKMANAGER_HXX
21#define INCLUDED_SW_SOURCE_CORE_INC_MARKMANAGER_HXX
22
23#include <IMark.hxx>
25#include <unordered_map>
26#include <memory>
27
28class SwCursorShell;
29class SfxViewShell;
30
31namespace sw::mark {
32 typedef std::unordered_map<OUString, sal_Int32> MarkBasenameMapUniqueOffset_t;
33
35
36 class MarkManager final
37 : virtual public IDocumentMarkAccess
38 {
39 public:
40 MarkManager(/*[in/out]*/ SwDoc& rDoc);
41 // IDocumentMarkAccess
42 virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM,
43 const OUString& rName, IDocumentMarkAccess::MarkType eMark,
45 SwPosition const* pSepPos = nullptr) override;
46
47 virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM,
48 const OUString& rName,
49 const OUString& rType,
50 SwPosition const* pSepPos = nullptr) override;
51 virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM,
52 const OUString& rName,
53 const OUString& rType) override;
54
55 virtual ::sw::mark::IMark* getMarkForTextNode(const SwTextNode& rTextNode, IDocumentMarkAccess::MarkType eMark) override;
56
58 const SwPaM& rPaM,
59 const OUString& rName ) override;
60
61 virtual void repositionMark(::sw::mark::IMark* io_pMark, const SwPaM& rPaM) override;
62 virtual bool renameMark(::sw::mark::IMark* io_pMark, const OUString& rNewName) override;
63 virtual void correctMarksAbsolute(const SwNode& rOldNode, const SwPosition& rNewPos, const sal_Int32 nOffset) override;
64 virtual void correctMarksRelative(const SwNode& rOldNode, const SwPosition& rNewPos, const sal_Int32 nOffset) override;
65
66 virtual void deleteMarks(const SwNode& rStt,
67 const SwNode& rEnd,
68 std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk,
69 std::optional<sal_Int32> oStartContentIdx,
70 std::optional<sal_Int32> oEndContentIdx) override;
71
72 // deleters
73 virtual std::unique_ptr<ILazyDeleter>
74 deleteMark(const const_iterator_t& ppMark, bool isMoveNodes) override;
75 virtual void deleteMark(const ::sw::mark::IMark* const pMark) override;
76 virtual void clearAllMarks() override;
77
78 // marks
79 virtual const_iterator_t getAllMarksBegin() const override;
80 virtual const_iterator_t getAllMarksEnd() const override;
81 virtual sal_Int32 getAllMarksCount() const override;
82 virtual const_iterator_t findMark(const OUString& rName) const override;
83
84 // bookmarks
85 virtual bool isBookmarkDeleted(SwPaM const& rPaM, bool isReplace) const override;
86 virtual const_iterator_t getBookmarksBegin() const override;
87 virtual const_iterator_t getBookmarksEnd() const override;
88 virtual sal_Int32 getBookmarksCount() const override;
89 virtual const_iterator_t findBookmark(const OUString& rName) const override;
90 virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const override;
91 virtual ::sw::mark::IMark* getOneInnermostBookmarkFor(const SwPosition& rPos) const override;
92
93 // Fieldmarks
94 virtual const_iterator_t getFieldmarksBegin() const override;
95 virtual const_iterator_t getFieldmarksEnd() const override;
96 virtual sal_Int32 getFieldmarksCount() const override;
97 virtual ::sw::mark::IFieldmark* getFieldmarkAt(const SwPosition& rPos) const override;
98 virtual sw::mark::IFieldmark* getInnerFieldmarkFor(const SwPosition& rPos) const override;
99 virtual sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& rPos, bool bLoop) const override;
100 virtual sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& rPos, bool bLoop) const override;
101
102 virtual ::sw::mark::IFieldmark* getDropDownFor(const SwPosition &rPos) const override;
103 virtual std::vector<::sw::mark::IFieldmark*> getNoTextFieldmarksIn(const SwPaM &rPaM) const override;
104
105 virtual void deleteFieldmarkAt(const SwPosition& rPos) override;
106 virtual ::sw::mark::IFieldmark* changeFormFieldmarkType(::sw::mark::IFieldmark* pFieldmark, const OUString& rNewType) override;
107
108 virtual void NotifyCursorUpdate(const SwCursorShell& rCursorShell) override;
109 virtual void ClearFieldActivation() override;
110 void LOKUpdateActiveField(const SfxViewShell* pViewShell);
111
112 void dumpAsXml(xmlTextWriterPtr pWriter) const;
113
114 // Annotation Marks
115 virtual const_iterator_t getAnnotationMarksBegin() const override;
116 virtual const_iterator_t getAnnotationMarksEnd() const override;
117 virtual sal_Int32 getAnnotationMarksCount() const override;
118 virtual const_iterator_t findAnnotationMark( const OUString& rName ) const override;
119 virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPos) const override;
120 virtual const_iterator_t findFirstAnnotationStartsAfter(const SwPosition& rPos) const override;
121
122 virtual void assureSortedMarkContainers() const override;
123
124 typedef std::vector<sw::mark::MarkBase*> container_t;
125
126 // helper bookmark to store annotation range of redlines
127 virtual ::sw::mark::IMark* makeAnnotationBookmark(const SwPaM& rPaM,
128 const OUString& rName, IDocumentMarkAccess::MarkType eMark,
130 SwPosition const* pSepPos = nullptr) override;
131 virtual const_iterator_t findAnnotationBookmark( const OUString& rName ) const override;
132 virtual void restoreAnnotationMarks(bool bDelete = true) override;
133
134 private:
135
136 MarkManager(MarkManager const&) = delete;
138
139 // make names
140 OUString getUniqueMarkName(const OUString& rName) const;
141
142 void sortSubsetMarks();
143 void sortMarks();
144
145 // container for all marks, this container owns the objects it points to
147
148 // additional container for bookmarks
150 // additional container for fieldmarks
152
154
155 // container for annotation marks
157
159
161 };
162
163}
164
165#endif
166
167/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
Provides access to the marks of a document.
Definition: doc.hxx:197
Base class of the Writer document model elements.
Definition: node.hxx:98
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field)
virtual void deleteMark(const ::sw::mark::IMark *const pMark) override
Deletes a mark.
virtual sw::mark::IMark * getAnnotationMarkFor(const SwPosition &rPos) const override
Definition: docbm.cxx:1719
virtual ::sw::mark::IMark * getOneInnermostBookmarkFor(const SwPosition &rPos) const override
Get the innermost bookmark that contains rPos.
Definition: docbm.cxx:1489
virtual sal_Int32 getAllMarksCount() const override
returns the number of marks.
Definition: docbm.cxx:1417
virtual const_iterator_t getFieldmarksBegin() const override
returns a STL-like random access iterator to the begin of the sequence of fieldmarks.
Definition: docbm.cxx:1429
virtual bool renameMark(::sw::mark::IMark *io_pMark, const OUString &rNewName) override
Renames an existing Mark, if possible.
Definition: docbm.cxx:876
virtual void restoreAnnotationMarks(bool bDelete=true) override
Definition: docbm.cxx:1760
virtual const_iterator_t findAnnotationBookmark(const OUString &rName) const override
Definition: docbm.cxx:1752
std::vector< sw::mark::MarkBase * > container_t
virtual void ClearFieldActivation() override
Definition: docbm.cxx:1618
virtual ::sw::mark::IFieldmark * getFieldmarkAt(const SwPosition &rPos) const override
get Fieldmark for CH_TXT_ATR_FIELDSTART/CH_TXT_ATR_FIELDEND at rPos
Definition: docbm.cxx:1448
virtual ::sw::mark::IMark * makeAnnotationBookmark(const SwPaM &rPaM, const OUString &rName, IDocumentMarkAccess::MarkType eMark, sw::mark::InsertMode eMode, SwPosition const *pSepPos=nullptr) override
Definition: docbm.cxx:1741
virtual void correctMarksAbsolute(const SwNode &rOldNode, const SwPosition &rNewPos, const sal_Int32 nOffset) override
Corrects marks (absolute) This method ignores the previous position of the mark in the paragraph.
Definition: docbm.cxx:905
virtual void NotifyCursorUpdate(const SwCursorShell &rCursorShell) override
Definition: docbm.cxx:1576
virtual void clearAllMarks() override
Clear (deletes) all marks.
Definition: docbm.cxx:1388
virtual const_iterator_t getAllMarksBegin() const override
returns a STL-like random access iterator to the begin of the sequence of marks.
Definition: docbm.cxx:1411
OUString getUniqueMarkName(const OUString &rName) const
Definition: docbm.cxx:1791
virtual const_iterator_t getAnnotationMarksBegin() const override
Definition: docbm.cxx:1698
virtual void assureSortedMarkContainers() const override
Definition: docbm.cxx:1831
virtual sw::mark::IFieldmark * makeNoTextFieldBookmark(const SwPaM &rPaM, const OUString &rName, const OUString &rType) override
Definition: docbm.cxx:780
void LOKUpdateActiveField(const SfxViewShell *pViewShell)
Definition: docbm.cxx:1626
sw::mark::FieldmarkWithDropDownButton * m_pLastActiveFieldmark
virtual std::vector<::sw::mark::IFieldmark * > getNoTextFieldmarksIn(const SwPaM &rPaM) const override
Definition: docbm.cxx:1667
virtual const_iterator_t getFieldmarksEnd() const override
returns a STL-like random access iterator to the end of the sequence of fieldmarks.
Definition: docbm.cxx:1432
MarkManager & operator=(MarkManager const &)=delete
virtual const_iterator_t findFirstAnnotationStartsAfter(const SwPosition &rPos) const override
Finds the first mark that is starting after.
Definition: docbm.cxx:1731
virtual sw::mark::IFieldmark * getFieldmarkAfter(const SwPosition &rPos, bool bLoop) const override
Definition: docbm.cxx:1692
container_t m_vFieldmarks
virtual const_iterator_t getAnnotationMarksEnd() const override
Definition: docbm.cxx:1703
MarkBasenameMapUniqueOffset_t m_aMarkBasenameMapUniqueOffset
container_t m_vBookmarks
virtual ::sw::mark::IFieldmark * changeFormFieldmarkType(::sw::mark::IFieldmark *pFieldmark, const OUString &rNewType) override
Definition: docbm.cxx:1524
virtual void correctMarksRelative(const SwNode &rOldNode, const SwPosition &rNewPos, const sal_Int32 nOffset) override
Corrects marks (relative) This method uses the previous position of the mark in the paragraph as offs...
Definition: docbm.cxx:951
virtual void repositionMark(::sw::mark::IMark *io_pMark, const SwPaM &rPaM) override
Moves an existing mark to a new selection and performs needed updates.
Definition: docbm.cxx:849
virtual sw::mark::IFieldmark * getInnerFieldmarkFor(const SwPosition &rPos) const override
Definition: docbm.cxx:1464
virtual void deleteMarks(const SwNode &rStt, const SwNode &rEnd, std::vector< ::sw::mark::SaveBookmark > *pSaveBkmk, std::optional< sal_Int32 > oStartContentIdx, std::optional< sal_Int32 > oEndContentIdx) override
Deletes marks in a range.
Definition: docbm.cxx:1095
virtual sw::mark::IFieldmark * makeFieldBookmark(const SwPaM &rPaM, const OUString &rName, const OUString &rType, SwPosition const *pSepPos=nullptr) override
Definition: docbm.cxx:740
virtual ::sw::mark::IMark * getMarkForTextNode(const SwTextNode &rTextNode, IDocumentMarkAccess::MarkType eMark) override
Returns a mark in the document for a paragraph.
Definition: docbm.cxx:829
virtual sal_Int32 getFieldmarksCount() const override
returns the number of IFieldmarks.
Definition: docbm.cxx:1435
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docbm.cxx:1849
virtual sw::mark::IMark * makeAnnotationMark(const SwPaM &rPaM, const OUString &rName) override
Definition: docbm.cxx:841
virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition &rPos) const override
Finds the first mark that is starting after.
Definition: docbm.cxx:1439
virtual ::sw::mark::IMark * makeMark(const SwPaM &rPaM, const OUString &rName, IDocumentMarkAccess::MarkType eMark, sw::mark::InsertMode eMode, SwPosition const *pSepPos=nullptr) override
Definition: docbm.cxx:568
virtual const_iterator_t findAnnotationMark(const OUString &rName) const override
Definition: docbm.cxx:1713
virtual ::sw::mark::IFieldmark * getDropDownFor(const SwPosition &rPos) const override
Definition: docbm.cxx:1659
virtual sw::mark::IFieldmark * getFieldmarkBefore(const SwPosition &rPos, bool bLoop) const override
Definition: docbm.cxx:1695
MarkManager(MarkManager const &)=delete
virtual void deleteFieldmarkAt(const SwPosition &rPos) override
Definition: docbm.cxx:1516
virtual const_iterator_t findBookmark(const OUString &rName) const override
Finds a bookmark by name.
Definition: docbm.cxx:1405
virtual sal_Int32 getAnnotationMarksCount() const override
Definition: docbm.cxx:1708
virtual bool isBookmarkDeleted(SwPaM const &rPaM, bool isReplace) const override
check if the selection would delete a BOOKMARK
Definition: docbm.cxx:1073
virtual const_iterator_t getBookmarksEnd() const override
returns a STL-like random access iterator to the end of the sequence of IBookmarks.
Definition: docbm.cxx:1423
virtual std::unique_ptr< ILazyDeleter > deleteMark(const const_iterator_t &ppMark, bool isMoveNodes) override
Deletes a mark.
Definition: docbm.cxx:1268
virtual const_iterator_t getAllMarksEnd() const override
returns a STL-like random access iterator to the end of the sequence of marks.
Definition: docbm.cxx:1414
MarkManager(SwDoc &rDoc)
Definition: docbm.cxx:563
virtual sal_Int32 getBookmarksCount() const override
returns the number of IBookmarks.
Definition: docbm.cxx:1426
container_t m_vAnnotationMarks
virtual const_iterator_t getBookmarksBegin() const override
returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
Definition: docbm.cxx:1420
virtual const_iterator_t findMark(const OUString &rName) const override
Finds a mark by name.
Definition: docbm.cxx:1399
struct _xmlTextWriter * xmlTextWriterPtr
Mode eMode
InsertMode
Definition: IMark.hxx:32
std::unordered_map< OUString, sal_Int32 > MarkBasenameMapUniqueOffset_t
Definition: MarkManager.hxx:32
Marks a position in the document model.
Definition: pam.hxx:38