xref: /aoo42x/main/sw/inc/IDocumentMarkAccess.hxx (revision 1d2dbeb0)
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             TEXT_FIELDMARK,
54             CHECKBOX_FIELDMARK,
55             NAVIGATOR_REMINDER
56         };
57 
58         typedef ::boost::shared_ptr< ::sw::mark::IMark> pMark_t;
59         typedef ::std::vector< pMark_t > container_t;
60         typedef container_t::iterator iterator_t;
61         typedef container_t::const_iterator const_iterator_t;
62         typedef container_t::const_reverse_iterator const_reverse_iterator_t;
63 
64         /** Generates a new mark in the document for a certain selection.
65 
66            @param rPaM
67            [in] the selection being marked.
68 
69            @param rProposedName
70            [in] the proposed name of the new mark.
71 
72            @param eMark
73            [in] the type of the new mark.
74 
75            @returns
76            a pointer to the new mark (name might have changed).
77         */
78         virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM,
79             const ::rtl::OUString& rProposedName,
80             MarkType eMark) =0;
81 
82         virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM,
83             const rtl::OUString& rName,
84             const rtl::OUString& rType) = 0;
85         virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM,
86             const rtl::OUString& rName,
87             const rtl::OUString& rType) = 0;
88 
89         /** Returns a mark in the document for a paragraph.
90             If there is none, a mark will be created.
91 
92            @param rTxtNode
93            [in] the paragraph being marked (a selection over the paragraph is marked)
94 
95            @param eMark
96            [in] the type of the new mark.
97 
98            @returns
99            a pointer to the new mark (name might have changed).
100         */
101         virtual ::sw::mark::IMark* getMarkForTxtNode(const SwTxtNode& rTxtNode,
102             MarkType eMark) =0;
103 
104         /** Moves an existing mark to a new selection and performs needed updates.
105             @param io_pMark
106             [in/out] the mark to be moved
107 
108             @param rPaM
109             [in] new selection to be marked
110         */
111 
112         virtual void repositionMark(::sw::mark::IMark* io_pMark,
113             const SwPaM& rPaM) =0;
114 
115         /** Renames an existing Mark, if possible.
116             @param io_pMark
117             [in/out] the mark to be renamed
118 
119             @param rNewName
120             [in] new name for the mark
121 
122             @returns false, if renaming failed (because the name is already in use)
123         */
124             virtual bool renameMark(::sw::mark::IMark* io_pMark,
125                 const ::rtl::OUString& rNewName) =0;
126 
127         /** Corrects marks (absolute)
128             This method ignores the previous position of the mark in the paragraph
129 
130             @param rOldNode
131             [in] the node from which nodes should be moved
132 
133             @param rNewPos
134             [in] new position to which marks will be moved, if nOffset == 0
135 
136             @param nOffset
137             [in] the offset by which the mark gets positioned of rNewPos
138         */
139         virtual void correctMarksAbsolute(const SwNodeIndex& rOldNode,
140             const SwPosition& rNewPos,
141             const xub_StrLen nOffset) =0;
142 
143         /** Corrects marks (relative)
144             This method uses the previous position of the mark in the paragraph as offset
145 
146             @param rOldNode
147             [in] the node from which nodes should be moved
148 
149             @param rNewPos
150             [in] new position to which marks from the start of the paragraph will be
151                  moved, if nOffset == 0
152 
153             @param nOffset
154             [in] the offset by which the mark gets positioned of rNewPos in addition to
155                  its old position in the paragraph
156         */
157         virtual void correctMarksRelative(const SwNodeIndex& rOldNode,
158             const SwPosition& rNewPos,
159             const xub_StrLen nOffset) =0;
160 
161         /** Deletes marks in a range
162         */
163         virtual void deleteMarks(
164             const SwNodeIndex& rStt,
165             const SwNodeIndex& rEnd,
166             ::std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk, // Ugly: SaveBookmark is core-internal
167             const SwIndex* pSttIdx,
168             const SwIndex* pEndIdx) =0;
169 
170         /** Deletes a mark.
171 
172             @param ppMark
173             [in] an iterator pointing to the Mark to be deleted.
174         */
175         virtual void deleteMark(const IDocumentMarkAccess::const_iterator_t ppMark) =0;
176 
177         /** Deletes a mark.
178 
179             @param ppMark
180             [in] the name of the mark to be deleted.
181         */
182         virtual void deleteMark(const ::sw::mark::IMark* const pMark) =0;
183 
184         /** Clear (deletes) all marks.
185         */
186         virtual void clearAllMarks() =0;
187 
188         /** returns a STL-like random access iterator to the begin of the sequence of marks.
189         */
190         virtual const_iterator_t getMarksBegin() const =0;
191 
192         /** returns a STL-like random access iterator to the end of the sequence of marks.
193         */
194         virtual const_iterator_t getMarksEnd() const =0;
195 
196         /** returns the number of marks.
197         */
198         virtual sal_Int32 getMarksCount() const =0;
199 
200         /** Finds a mark by name.
201 
202             @param rName
203             [in] the name of the mark to find.
204 
205             @returns
206             an iterator pointing to the mark, or pointing to getMarksEnd() if nothing was found.
207         */
208         virtual const_iterator_t findMark(const ::rtl::OUString& rMark) const =0;
209 
210 
211         // interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK)
212 
213         /** returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
214         */
215         virtual const_iterator_t getBookmarksBegin() const =0;
216 
217         /** returns a STL-like random access iterator to the end of the sequence of IBookmarks.
218         */
219         virtual const_iterator_t getBookmarksEnd() const =0;
220 
221         /** returns the number of IBookmarks.
222         */
223         virtual sal_Int32 getBookmarksCount() const =0;
224 
225         /** Finds a bookmark by name.
226 
227             @param rName
228             [in] the name of the bookmark to find.
229 
230             @returns
231             an iterator pointing to the bookmark, or getBookmarksEnd() if nothing was found.
232         */
233         virtual const_iterator_t findBookmark(const ::rtl::OUString& rMark) const =0;
234 
235 
236         // Fieldmarks
237         virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& pos) const =0;
238         virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& pos) const =0;
239         virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& pos) const =0;
240 
241         // Returns the MarkType used to create the mark
242         static MarkType SAL_DLLPUBLIC_EXPORT GetType(const ::sw::mark::IMark& rMark);
243     protected:
244         virtual ~IDocumentMarkAccess() {};
245 };
246 
247 #endif // IDOCUMENTBOOKMARKACCESS_HXX_INCLUDED
248