xref: /trunk/main/sw/inc/IDocumentMarkAccess.hxx (revision 57e74413)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef IDOCUMENTMARKACCESS_HXX_INCLUDED
25 #define IDOCUMENTMARKACCESS_HXX_INCLUDED
26 
27 #include <sal/types.h>
28 #include <IMark.hxx>
29 #include <boost/shared_ptr.hpp>
30 
31 class SwPaM;
32 class KeyCode;
33 class String;
34 struct SwPosition;
35 class SwTxtNode;
36 
37 namespace sw { namespace mark {
38     class SaveBookmark; // FIXME: Ugly: SaveBookmark is a core-internal class, and should not be used in the interface
39 }}
40 
41 /** Provides access to the marks of a document.
42 */
43 class IDocumentMarkAccess
44 {
45     public:
46         enum MarkType
47         {
48             UNO_BOOKMARK,
49             DDE_BOOKMARK,
50             BOOKMARK,
51             CROSSREF_HEADING_BOOKMARK,
52             CROSSREF_NUMITEM_BOOKMARK,
53             ANNOTATIONMARK,
54             TEXT_FIELDMARK,
55             CHECKBOX_FIELDMARK,
56             NAVIGATOR_REMINDER
57         };
58 
59         typedef ::boost::shared_ptr< ::sw::mark::IMark> pMark_t;
60         typedef ::std::vector< pMark_t > container_t;
61         typedef container_t::iterator iterator_t;
62         typedef container_t::const_iterator const_iterator_t;
63         typedef container_t::const_reverse_iterator const_reverse_iterator_t;
64 
65         /** Generates a new mark in the document for a certain selection.
66 
67            @param rPaM
68            [in] the selection being marked.
69 
70            @param rProposedName
71            [in] the proposed name of the new mark.
72 
73            @param eMark
74            [in] the type of the new mark.
75 
76            @returns
77            a pointer to the new mark (name might have changed).
78         */
79         virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM,
80             const ::rtl::OUString& rProposedName,
81             MarkType eMark) =0;
82 
83         virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM,
84             const rtl::OUString& rName,
85             const rtl::OUString& rType) = 0;
86         virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM,
87             const rtl::OUString& rName,
88             const rtl::OUString& rType) = 0;
89 
90         virtual sw::mark::IMark* makeAnnotationMark(
91             const SwPaM& rPaM,
92             const ::rtl::OUString& rName ) = 0;
93 
94         /** Returns a mark in the document for a paragraph.
95             If there is none, a mark will be created.
96 
97            @param rTxtNode
98            [in] the paragraph being marked (a selection over the paragraph is marked)
99 
100            @param eMark
101            [in] the type of the new mark.
102 
103            @returns
104            a pointer to the new mark (name might have changed).
105         */
106         virtual ::sw::mark::IMark* getMarkForTxtNode(const SwTxtNode& rTxtNode,
107             MarkType eMark) =0;
108 
109         /** Moves an existing mark to a new selection and performs needed updates.
110             @param io_pMark
111             [in/out] the mark to be moved
112 
113             @param rPaM
114             [in] new selection to be marked
115         */
116 
117         virtual void repositionMark(::sw::mark::IMark* io_pMark,
118             const SwPaM& rPaM) =0;
119 
120         /** Renames an existing Mark, if possible.
121             @param io_pMark
122             [in/out] the mark to be renamed
123 
124             @param rNewName
125             [in] new name for the mark
126 
127             @returns false, if renaming failed (because the name is already in use)
128         */
129             virtual bool renameMark(::sw::mark::IMark* io_pMark,
130                 const ::rtl::OUString& rNewName) =0;
131 
132         /** Corrects marks (absolute)
133             This method ignores the previous position of the mark in the paragraph
134 
135             @param rOldNode
136             [in] the node from which nodes should be moved
137 
138             @param rNewPos
139             [in] new position to which marks will be moved, if nOffset == 0
140 
141             @param nOffset
142             [in] the offset by which the mark gets positioned of rNewPos
143         */
144         virtual void correctMarksAbsolute(const SwNodeIndex& rOldNode,
145             const SwPosition& rNewPos,
146             const xub_StrLen nOffset) =0;
147 
148         /** Corrects marks (relative)
149             This method uses the previous position of the mark in the paragraph as offset
150 
151             @param rOldNode
152             [in] the node from which nodes should be moved
153 
154             @param rNewPos
155             [in] new position to which marks from the start of the paragraph will be
156                  moved, if nOffset == 0
157 
158             @param nOffset
159             [in] the offset by which the mark gets positioned of rNewPos in addition to
160                  its old position in the paragraph
161         */
162         virtual void correctMarksRelative(const SwNodeIndex& rOldNode,
163             const SwPosition& rNewPos,
164             const xub_StrLen nOffset) =0;
165 
166         /** Deletes marks in a range
167 
168             Note: navigator reminders are excluded
169 
170         */
171         virtual void deleteMarks(
172             const SwNodeIndex& rStt,
173             const SwNodeIndex& rEnd,
174             ::std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk, // Ugly: SaveBookmark is core-internal
175             const SwIndex* pSttIdx,
176             const SwIndex* pEndIdx) =0;
177 
178         /** Deletes a mark.
179 
180             @param ppMark
181             [in] an iterator pointing to the Mark to be deleted.
182         */
183         virtual void deleteMark(const IDocumentMarkAccess::const_iterator_t ppMark) =0;
184 
185         /** Deletes a mark.
186 
187             @param ppMark
188             [in] the name of the mark to be deleted.
189         */
190         virtual void deleteMark(const ::sw::mark::IMark* const pMark) =0;
191 
192         /** Clear (deletes) all marks.
193         */
194         virtual void clearAllMarks() =0;
195 
196         virtual void assureSortedMarkContainers() const = 0;
197 
198         /** returns a STL-like random access iterator to the begin of the sequence of marks.
199         */
200         virtual const_iterator_t getAllMarksBegin() const =0;
201 
202         /** returns a STL-like random access iterator to the end of the sequence of marks.
203         */
204         virtual const_iterator_t getAllMarksEnd() const =0;
205 
206         /** returns the number of marks.
207 
208             Note: annotation marks are excluded
209         */
210         virtual sal_Int32 getAllMarksCount() const =0;
211 
212         /** Finds a mark by name.
213 
214             @param rName
215             [in] the name of the mark to find.
216 
217             @returns
218             an iterator pointing to the mark, or pointing to getAllMarksEnd() if nothing was found.
219         */
220         virtual const_iterator_t findMark(const ::rtl::OUString& rMark) const =0;
221 
222 
223         // interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK )
224 
225         /** returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
226         */
227         virtual const_iterator_t getBookmarksBegin() const =0;
228 
229         /** returns a STL-like random access iterator to the end of the sequence of IBookmarks.
230         */
231         virtual const_iterator_t getBookmarksEnd() const =0;
232 
233         /** returns the number of IBookmarks.
234         */
235         virtual sal_Int32 getBookmarksCount() const =0;
236 
237         /** Finds a bookmark by name.
238 
239             @param rName
240             [in] the name of the bookmark to find.
241 
242             @returns
243             an iterator pointing to the bookmark, or getBookmarksEnd() if nothing was found.
244         */
245         virtual const_iterator_t findBookmark(const ::rtl::OUString& rMark) const =0;
246 
247 
248         // Fieldmarks
249         virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& pos) const =0;
250         virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& pos) const =0;
251         virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& pos) const =0;
252 
253         // Annotation Marks
254         virtual const_iterator_t getAnnotationMarksBegin() const = 0;
255         virtual const_iterator_t getAnnotationMarksEnd() const = 0;
256         virtual sal_Int32 getAnnotationMarksCount() const = 0;
257         virtual const_iterator_t findAnnotationMark( const ::rtl::OUString& rName ) const = 0;
258 
259         // Returns the MarkType used to create the mark
260         static SAL_DLLPUBLIC_EXPORT MarkType GetType(const ::sw::mark::IMark& rMark);
261 
262         static SAL_DLLPUBLIC_EXPORT const ::rtl::OUString& GetCrossRefHeadingBookmarkNamePrefix();
263         static SAL_DLLPUBLIC_EXPORT bool IsLegalPaMForCrossRefHeadingBookmark( const SwPaM& );
264     protected:
~IDocumentMarkAccess()265         virtual ~IDocumentMarkAccess() {};
266 };
267 
268 #endif // IDOCUMENTBOOKMARKACCESS_HXX_INCLUDED
269