1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef SD_OUTLINER_ITERATOR_HXX
29 #define SD_OUTLINER_ITERATOR_HXX
31 #include <svx/svdobj.hxx>
34 #include "sal/types.h"
36 #include <boost/shared_ptr.hpp>
48 class IteratorImplBase
;
49 class IteratorPosition
;
51 /** Use this enum to specify the initial location of the object pointed to by
52 a newly created iterator. The values are
53 <ul><li><const>BEGIN</const> for the first object with reference to
54 iteration direction.</li>
55 <li>END for one past the last valid object or, if the iterator is a
56 backward iterator, the object in front of the first valid one.</li>
57 <li>CURRENT for the current object. Because there is only a current
58 page this usually is taken to be the first/last object on the current
61 enum IteratorLocation
{BEGIN
,END
,CURRENT
};
63 /** Use this enum to specify the type of iterator when creating a new
65 <ul><li>SELECTION for iteration over all objects that belong to the
66 current mark list.</li>
67 <li>SINGLE_VIEW for iteration over all objects in the current view.</li>
68 <li>DOCUMENT for iteratioin over all object in all relevant
71 enum IteratorType
{SELECTION
,SINGLE_VIEW
,DOCUMENT
};
74 /** This iterator can be used to iterate over all <type>SdrObject</type>
75 objects of one of three set denoted by the <type>IteratorType</type>:
76 <ul><li>All objects of the current mark list (selection)
77 (type==SELECTION).</li>
78 <li>All objects in the current view (type==SINGLE_VIEW).</li>
79 <li>All objects in all views (type=DOCUMENT).</li></ul>
81 <p>Note that the iterator does not change pages or views. It is the
82 task of the user of the iterator to take the information provided by the
83 <type>IteratorPosition</type> as returned by the
84 <member>operator*()</member> method and set view, visible page, and
85 selection/edit mode markers to reflect this position.</p>
87 <p>A simple forward iteration from the first to the last object would
88 instantiate the iterator with
89 <code>Iterator(pDocument,pViewShell,true,BEGIN)</code> for some document
90 and view shell. This iterator can then be compared against
91 <code>Iterator(pDocument,pViewShell,true,END)</code>. On equality the
92 iteration should be stoped without evaluating the iterator: The position
93 of an end iterator is not valid.</p>
100 /** The copy constructor creates a new iterator by copying the
101 implementation object.
103 Iterator (const Iterator
& rIterator
);
105 /** Create a new iterator with the implementation object being the
108 A copy of this object will become the implementation object.
110 explicit Iterator (IteratorImplBase
* pObject
);
114 /** Assign the iterator from the given one. The implementation object
115 of this iterator will be a copy of the given iterator.
117 The iterator which to assign from.
119 Iterator
& operator= (const Iterator
& rIterator
);
120 /** Return the current position of the iterator.
122 Returns a reference to the current position. Therefore this
123 method is not thread safe. The reason for this behaviour is, of
124 course, to ommit the copying of the returned position.
126 const IteratorPosition
& operator* () const;
127 /** The prefix increment operator returns the iterator pointing to the
128 next object. When in doubt prefer this operator over the postfix
131 Returns a reference to this iterator pointing to the next object.
133 Iterator
& operator++ ();
134 /** The postfix increment operator returns the iterator still pointing
135 to the current object. Only the next call to
136 <member>operator*()</member> will return the next object. When in
137 doubt rather use the prefix increment operator.
139 A dummy operator used by the compiler.
141 Returns a copy of the iterator as it where before the operator
144 Iterator
operator++ (int);
145 /** Test equality of two iterators. Two iterators are taken to be equal
146 when they point are of the same type (their implementation objects
147 are instances of the same class) and point to the same object.
149 The iterator to test equality with.
151 Returns <TRUE/> when both iterators point to the same object.
153 bool operator== (const Iterator
& rIterator
);
154 /** Test whether two iterators point to different objects. This is just
155 the negation of the result of the equality operator.
157 The iterator to test inequality with.
159 Returns <TRUE/> when both iterators point to the different objects.
161 bool operator!= (const Iterator
& rIterator
);
162 /** Reverse the direction of iteration. The position of the iterator is
163 not changed. Thus caling this method twice returns to the old state.
168 /// The implementation object to which most of the methods are forwarded.
169 IteratorImplBase
* mpIterator
;
175 /** This class wraps the <type>Outliner</type> class and represents it as
176 a container of <type>SdrObject</type> objects. Its main purpose is to
177 provide iterators for certain sub-sets of those objects. These sub-sets
178 are a) the set of the currently selected objects, b) all objects in the
179 current view, and c) all objects in all views.
181 <p>The direction of the returned iterators depends on the underlying
182 <type>Outliner</type> object and is usually set in the search
185 class OutlinerContainer
188 /** Create a new wraper object for the given outliner.
190 The outliner that is represented by the new object as
191 <type>SdrObject</type> container.
193 OutlinerContainer (::sd::Outliner
* pOutliner
);
195 /** Return an iterator that points to the first object of one of the
196 sets described above. This takes also into account the direction of
199 The returned iterator points either to the first (forward
200 search) or to the last object (backward search) of the set.
202 Iterator
begin (void);
204 /** Return an iterator that marks the end of the iteration. This takes
205 also into account the direction of iteration. The object pointed to
208 The returned iterator points either to that object past the last
209 one (forward search) or to the one in front of the first
214 /** Return an iterator that points to the current object of one of the
215 sets described above. This takes also into account the direction of
218 The returned iterator points either to the first (forward
219 search) or to the last object (backward search) of the set of
220 selected objects or of the current page if the search set spans
223 Iterator
current (void);
226 /// The wrapped outliner that is represented as object container.
227 ::sd::Outliner
* mpOutliner
;
229 /** Create an iterator. The object pointed to depends on the search
230 direction retrieved from the outliner object
231 <member>mpOutliner</member> and the given location.
233 This specifies whether the returned iterator points to the
234 first, (one past the) last, or current object.
236 Returns an iterator as constructed by
237 <member>CreateSelectionIterator()</member>,
239 Iterator
CreateIterator (IteratorLocation aLocation
);
241 /** Create an iterator that iterates over all currently selected
242 <type>SdrObjects</type> objects of the <member>mpOutliner</member>
245 List of currently selected objects. This list is necessary
246 so that the selection can be changed without affecting the
249 The document to which the objects belong.
251 The view shell which displays the objects.
252 @param bDirectionIsForward
253 The direction of iteration. It defaults to forward.
255 This specifies at which object the iterator points initially.
257 Iterator
CreateSelectionIterator (
258 const ::std::vector
<SdrObjectWeakRef
>& rObjectList
,
259 SdDrawDocument
* pDocument
,
260 const ::boost::shared_ptr
<ViewShell
>& rpViewShell
,
261 bool bDirectionIsForward
=true,
262 IteratorLocation aLocation
=BEGIN
);
264 /** Create an iterator that iterates over all <type>SdrObjects</type>
265 objects of the <member>mpOutliner</member> outliner.
267 The document to which the objects belong.
269 The view shell which displays the objects.
270 @param bDirectionIsForward
271 The direction of iteration. It defaults to forward.
273 This specifies at which object the iterator points initially.
275 Iterator
CreateDocumentIterator (
276 SdDrawDocument
* pDocument
,
277 const ::boost::shared_ptr
<ViewShell
>& rpViewShell
,
278 bool bDirectionIsForward
=true,
279 IteratorLocation aLocation
=BEGIN
);
281 /** Return the index of a page that contains an object that a new
282 iterator shall point to. This page index depends primarily on the
283 location, iteration direction, as well as on edit mode and page
286 The document to which the page belongs.
288 The view shell which displays the page.
290 Specifies the view the page belongs to.
292 Specifies whether the page is a master page.
293 @param bDirectionIsForward
294 The direction of iteration.
296 This specifies at which object the iterator points initially.
298 sal_Int32
GetPageIndex (
299 SdDrawDocument
* pDocument
,
300 const ::boost::shared_ptr
<ViewShell
>& rpViewShell
,
303 bool bDirectionIsForward
,
304 IteratorLocation aLocation
);
306 // Do not allow default constructor and copying of outliner containers.
307 OutlinerContainer (const OutlinerContainer
&) {};
308 OutlinerContainer (void) {};
309 OutlinerContainer
& operator= (const OutlinerContainer
&) {return *this;};
315 /** Data collection specifying a <type>SdrObject</type> and its position in
318 class IteratorPosition
321 /** Create a new object with all data members set to default values.
322 These values should not be accessed. The only use of the object as
323 it is is as a marker in comparisons.
325 IteratorPosition (void);
326 /** Create a new object with all data members set from the given
329 The position object from which to take the values that are
330 assigned to the data members of this object.
332 IteratorPosition (const IteratorPosition
& aPosition
);
334 /// The destructor is a no-op at the moment.
335 ~IteratorPosition (void);
336 /** Assign the content of the given position to this one.
338 This is the position object from which to take the values of all
341 Returns a reference to this object.
343 IteratorPosition
& operator= (const IteratorPosition
& aPosition
);
344 /** Compare two positions for equality.
346 <TRUE/> is returned only when all data members have the same
347 values in both position objects.
349 bool operator== (const IteratorPosition
& aPosition
) const;
351 /// Pointer to the actual <type>SdrObject</type> object.
352 SdrObjectWeakRef mxObject
;
354 /// Number of the actual SdrText from the current <type>SdrObject</type>
357 /// The index of a page where the object is located on.
358 sal_Int32 mnPageIndex
;
359 /// Page kind of the view.
361 /// Edit mode of the view.
366 } } // end of namespace ::sd::outliner
369 #endif // _SD_OUTLINER_ITERATOR_HXX