xref: /aoo42x/main/sw/inc/IDocumentMarkAccess.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef IDOCUMENTMARKACCESS_HXX_INCLUDED
29 #define IDOCUMENTMARKACCESS_HXX_INCLUDED
30 
31 #include <sal/types.h>
32 #include <IMark.hxx>
33 #include <boost/shared_ptr.hpp>
34 
35 class SwPaM;
36 class KeyCode;
37 class String;
38 struct SwPosition;
39 class SwTxtNode;
40 
41 namespace sw { namespace mark {
42     class SaveBookmark; // FIXME: Ugly: SaveBookmark is a core-internal class, and should not be used in the interface
43 }}
44 
45 /** Provides access to the marks of a document.
46 */
47 class IDocumentMarkAccess
48 {
49     public:
50         enum MarkType
51         {
52             UNO_BOOKMARK,
53             DDE_BOOKMARK,
54             BOOKMARK,
55             CROSSREF_HEADING_BOOKMARK,
56             CROSSREF_NUMITEM_BOOKMARK,
57             TEXT_FIELDMARK,
58             CHECKBOX_FIELDMARK,
59             NAVIGATOR_REMINDER
60         };
61 
62         typedef ::boost::shared_ptr< ::sw::mark::IMark> pMark_t;
63         typedef ::std::vector< pMark_t > container_t;
64         typedef container_t::iterator iterator_t;
65         typedef container_t::const_iterator const_iterator_t;
66         typedef container_t::const_reverse_iterator const_reverse_iterator_t;
67 
68         /** Generates a new mark in the document for a certain selection.
69 
70            @param rPaM
71            [in] the selection being marked.
72 
73            @param rProposedName
74            [in] the proposed name of the new mark.
75 
76            @param eMark
77            [in] the type of the new mark.
78 
79            @returns
80            a pointer to the new mark (name might have changed).
81         */
82         virtual ::sw::mark::IMark* makeMark(const SwPaM& rPaM,
83             const ::rtl::OUString& rProposedName,
84             MarkType eMark) =0;
85 
86         virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM,
87             const rtl::OUString& rName,
88             const rtl::OUString& rType) = 0;
89         virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM,
90             const rtl::OUString& rName,
91             const rtl::OUString& rType) = 0;
92 
93         /** Returns a mark in the document for a paragraph.
94             If there is none, a mark will be created.
95 
96            @param rTxtNode
97            [in] the paragraph being marked (a selection over the paragraph is marked)
98 
99            @param eMark
100            [in] the type of the new mark.
101 
102            @returns
103            a pointer to the new mark (name might have changed).
104         */
105         virtual ::sw::mark::IMark* getMarkForTxtNode(const SwTxtNode& rTxtNode,
106             MarkType eMark) =0;
107 
108         /** Moves an existing mark to a new selection and performs needed updates.
109             @param io_pMark
110             [in/out] the mark to be moved
111 
112             @param rPaM
113             [in] new selection to be marked
114         */
115 
116         virtual void repositionMark(::sw::mark::IMark* io_pMark,
117             const SwPaM& rPaM) =0;
118 
119         /** Renames an existing Mark, if possible.
120             @param io_pMark
121             [in/out] the mark to be renamed
122 
123             @param rNewName
124             [in] new name for the mark
125 
126             @returns false, if renaming failed (because the name is already in use)
127         */
128             virtual bool renameMark(::sw::mark::IMark* io_pMark,
129                 const ::rtl::OUString& rNewName) =0;
130 
131         /** Corrects marks (absolute)
132             This method ignores the previous position of the mark in the paragraph
133 
134             @param rOldNode
135             [in] the node from which nodes should be moved
136 
137             @param rNewPos
138             [in] new position to which marks will be moved, if nOffset == 0
139 
140             @param nOffset
141             [in] the offset by which the mark gets positioned of rNewPos
142         */
143         virtual void correctMarksAbsolute(const SwNodeIndex& rOldNode,
144             const SwPosition& rNewPos,
145             const xub_StrLen nOffset) =0;
146 
147         /** Corrects marks (relative)
148             This method uses the previous position of the mark in the paragraph as offset
149 
150             @param rOldNode
151             [in] the node from which nodes should be moved
152 
153             @param rNewPos
154             [in] new position to which marks from the start of the paragraph will be
155                  moved, if nOffset == 0
156 
157             @param nOffset
158             [in] the offset by which the mark gets positioned of rNewPos in addition to
159                  its old position in the paragraph
160         */
161         virtual void correctMarksRelative(const SwNodeIndex& rOldNode,
162             const SwPosition& rNewPos,
163             const xub_StrLen nOffset) =0;
164 
165         /** Deletes marks in a range
166         */
167         virtual void deleteMarks(
168             const SwNodeIndex& rStt,
169             const SwNodeIndex& rEnd,
170             ::std::vector< ::sw::mark::SaveBookmark>* pSaveBkmk, // Ugly: SaveBookmark is core-internal
171             const SwIndex* pSttIdx,
172             const SwIndex* pEndIdx) =0;
173 
174         /** Deletes a mark.
175 
176             @param ppMark
177             [in] an iterator pointing to the Mark to be deleted.
178         */
179         virtual void deleteMark(const IDocumentMarkAccess::const_iterator_t ppMark) =0;
180 
181         /** Deletes a mark.
182 
183             @param ppMark
184             [in] the name of the mark to be deleted.
185         */
186         virtual void deleteMark(const ::sw::mark::IMark* const pMark) =0;
187 
188         /** Clear (deletes) all marks.
189         */
190         virtual void clearAllMarks() =0;
191 
192         /** returns a STL-like random access iterator to the begin of the sequence of marks.
193         */
194         virtual const_iterator_t getMarksBegin() const =0;
195 
196         /** returns a STL-like random access iterator to the end of the sequence of marks.
197         */
198         virtual const_iterator_t getMarksEnd() const =0;
199 
200         /** returns the number of marks.
201         */
202         virtual sal_Int32 getMarksCount() const =0;
203 
204         /** Finds a mark by name.
205 
206             @param rName
207             [in] the name of the mark to find.
208 
209             @returns
210             an iterator pointing to the mark, or pointing to getMarksEnd() if nothing was found.
211         */
212         virtual const_iterator_t findMark(const ::rtl::OUString& rMark) const =0;
213 
214 
215         // interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK)
216 
217         /** returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
218         */
219         virtual const_iterator_t getBookmarksBegin() const =0;
220 
221         /** returns a STL-like random access iterator to the end of the sequence of IBookmarks.
222         */
223         virtual const_iterator_t getBookmarksEnd() const =0;
224 
225         /** returns the number of IBookmarks.
226         */
227         virtual sal_Int32 getBookmarksCount() const =0;
228 
229         /** Finds a bookmark by name.
230 
231             @param rName
232             [in] the name of the bookmark to find.
233 
234             @returns
235             an iterator pointing to the bookmark, or getBookmarksEnd() if nothing was found.
236         */
237         virtual const_iterator_t findBookmark(const ::rtl::OUString& rMark) const =0;
238 
239 
240         // Fieldmarks
241         virtual ::sw::mark::IFieldmark* getFieldmarkFor(const SwPosition& pos) const =0;
242         virtual ::sw::mark::IFieldmark* getFieldmarkBefore(const SwPosition& pos) const =0;
243         virtual ::sw::mark::IFieldmark* getFieldmarkAfter(const SwPosition& pos) const =0;
244 
245         // Returns the MarkType used to create the mark
246         static MarkType SAL_DLLPUBLIC_EXPORT GetType(const ::sw::mark::IMark& rMark);
247     protected:
248         virtual ~IDocumentMarkAccess() {};
249 };
250 
251 #endif // IDOCUMENTBOOKMARKACCESS_HXX_INCLUDED
252