1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SD_INC_OUTLINERITERATOR_HXX
21 #define INCLUDED_SD_INC_OUTLINERITERATOR_HXX
23 #include <svx/svdobj.hxx>
26 #include "sal/types.h"
28 #include <boost/shared_ptr.hpp>
39 class IteratorImplBase
;
40 class IteratorPosition
;
42 /** Use this enum to specify the initial location of the object pointed to by
43 a newly created iterator. The values are
44 <ul><li><const>BEGIN</const> for the first object with reference to
45 iteration direction.</li>
46 <li>END for one past the last valid object or, if the iterator is a
47 backward iterator, the object in front of the first valid one.</li>
48 <li>CURRENT for the current object. Because there is only a current
49 page this usually is taken to be the first/last object on the current
52 enum IteratorLocation
{BEGIN
,END
,CURRENT
};
54 /** Use this enum to specify the type of iterator when creating a new
56 <ul><li>SELECTION for iteration over all objects that belong to the
57 current mark list.</li>
58 <li>SINGLE_VIEW for iteration over all objects in the current view.</li>
59 <li>DOCUMENT for iteration over all object in all relevant
62 enum IteratorType
{SELECTION
,SINGLE_VIEW
,DOCUMENT
};
64 /** This iterator can be used to iterate over all <type>SdrObject</type>
65 objects of one of three set denoted by the <type>IteratorType</type>:
66 <ul><li>All objects of the current mark list (selection)
67 (type==SELECTION).</li>
68 <li>All objects in the current view (type==SINGLE_VIEW).</li>
69 <li>All objects in all views (type=DOCUMENT).</li></ul>
71 <p>Note that the iterator does not change pages or views. It is the
72 task of the user of the iterator to take the information provided by the
73 <type>IteratorPosition</type> as returned by the
74 <member>operator*()</member> method and set view, visible page, and
75 selection/edit mode markers to reflect this position.</p>
77 <p>A simple forward iteration from the first to the last object would
78 instantiate the iterator with
79 <code>Iterator(pDocument,pViewShell,true,BEGIN)</code> for some document
80 and view shell. This iterator can then be compared against
81 <code>Iterator(pDocument,pViewShell,true,END)</code>. On equality the
82 iteration should be stopped without evaluating the iterator: The position
83 of an end iterator is not valid.</p>
90 /** The copy constructor creates a new iterator by copying the
91 implementation object.
93 Iterator (const Iterator
& rIterator
);
95 /** Create a new iterator with the implementation object being the
98 A copy of this object will become the implementation object.
100 explicit Iterator (IteratorImplBase
* pObject
);
104 /** Assign the iterator from the given one. The implementation object
105 of this iterator will be a copy of the given iterator.
107 The iterator which to assign from.
109 Iterator
& operator= (const Iterator
& rIterator
);
110 /** Return the current position of the iterator.
112 Returns a reference to the current position. Therefore this
113 method is not thread safe. The reason for this behaviour is, of
114 course, to omit the copying of the returned position.
116 const IteratorPosition
& operator* () const;
117 /** The prefix increment operator returns the iterator pointing to the
118 next object. When in doubt prefer this operator over the postfix
121 Returns a reference to this iterator pointing to the next object.
123 Iterator
& operator++ ();
124 /** The postfix increment operator returns the iterator still pointing
125 to the current object. Only the next call to
126 <member>operator*()</member> will return the next object. When in
127 doubt rather use the prefix increment operator.
129 A dummy operator used by the compiler.
131 Returns a copy of the iterator as it where before the operator
134 Iterator
operator++ (int);
135 /** Test equality of two iterators. Two iterators are taken to be equal
136 when they point are of the same type (their implementation objects
137 are instances of the same class) and point to the same object.
139 The iterator to test equality with.
141 Returns <TRUE/> when both iterators point to the same object.
143 bool operator== (const Iterator
& rIterator
);
144 /** Test whether two iterators point to different objects. This is just
145 the negation of the result of the equality operator.
147 The iterator to test inequality with.
149 Returns <TRUE/> when both iterators point to the different objects.
151 bool operator!= (const Iterator
& rIterator
);
152 /** Reverse the direction of iteration. The position of the iterator is
153 not changed. Thus calling this method twice returns to the old state.
158 /// The implementation object to which most of the methods are forwarded.
159 IteratorImplBase
* mpIterator
;
162 /** This class wraps the <type>Outliner</type> class and represents it as
163 a container of <type>SdrObject</type> objects. Its main purpose is to
164 provide iterators for certain sub-sets of those objects. These sub-sets
165 are a) the set of the currently selected objects, b) all objects in the
166 current view, and c) all objects in all views.
168 <p>The direction of the returned iterators depends on the underlying
169 <type>Outliner</type> object and is usually set in the search
172 class OutlinerContainer
175 /** Create a new wrapper object for the given outliner.
177 The outliner that is represented by the new object as
178 <type>SdrObject</type> container.
180 OutlinerContainer (::sd::Outliner
* pOutliner
);
182 /** Return an iterator that points to the first object of one of the
183 sets described above. This takes also into account the direction of
186 The returned iterator points either to the first (forward
187 search) or to the last object (backward search) of the set.
191 /** Return an iterator that marks the end of the iteration. This takes
192 also into account the direction of iteration. The object pointed to
195 The returned iterator points either to that object past the last
196 one (forward search) or to the one in front of the first
201 /** Return an iterator that points to the current object of one of the
202 sets described above. This takes also into account the direction of
205 The returned iterator points either to the first (forward
206 search) or to the last object (backward search) of the set of
207 selected objects or of the current page if the search set spans
213 /// The wrapped outliner that is represented as object container.
214 ::sd::Outliner
* mpOutliner
;
216 /** Create an iterator. The object pointed to depends on the search
217 direction retrieved from the outliner object
218 <member>mpOutliner</member> and the given location.
220 This specifies whether the returned iterator points to the
221 first, (one past the) last, or current object.
223 Returns an iterator as constructed by
224 <member>CreateSelectionIterator()</member>,
226 Iterator
CreateIterator (IteratorLocation aLocation
);
228 /** Create an iterator that iterates over all currently selected
229 <type>SdrObjects</type> objects of the <member>mpOutliner</member>
232 List of currently selected objects. This list is necessary
233 so that the selection can be changed without affecting the
236 The document to which the objects belong.
238 The view shell which displays the objects.
239 @param bDirectionIsForward
240 The direction of iteration. It defaults to forward.
242 This specifies at which object the iterator points initially.
244 static Iterator
CreateSelectionIterator (
245 const ::std::vector
<SdrObjectWeakRef
>& rObjectList
,
246 SdDrawDocument
* pDocument
,
247 const ::boost::shared_ptr
<ViewShell
>& rpViewShell
,
248 bool bDirectionIsForward
=true,
249 IteratorLocation aLocation
=BEGIN
);
251 /** Create an iterator that iterates over all <type>SdrObjects</type>
252 objects of the <member>mpOutliner</member> outliner.
254 The document to which the objects belong.
256 The view shell which displays the objects.
257 @param bDirectionIsForward
258 The direction of iteration. It defaults to forward.
260 This specifies at which object the iterator points initially.
262 static Iterator
CreateDocumentIterator (
263 SdDrawDocument
* pDocument
,
264 const ::boost::shared_ptr
<ViewShell
>& rpViewShell
,
265 bool bDirectionIsForward
=true,
266 IteratorLocation aLocation
=BEGIN
);
268 /** Return the index of a page that contains an object that a new
269 iterator shall point to. This page index depends primarily on the
270 location, iteration direction, as well as on edit mode and page
273 The document to which the page belongs.
275 The view shell which displays the page.
277 Specifies the view the page belongs to.
279 Specifies whether the page is a master page.
280 @param bDirectionIsForward
281 The direction of iteration.
283 This specifies at which object the iterator points initially.
285 static sal_Int32
GetPageIndex (
286 SdDrawDocument
* pDocument
,
287 const ::boost::shared_ptr
<ViewShell
>& rpViewShell
,
290 bool bDirectionIsForward
,
291 IteratorLocation aLocation
);
293 // Do not allow default constructor and copying of outliner containers.
294 OutlinerContainer (const OutlinerContainer
&) {};
295 OutlinerContainer() {};
296 OutlinerContainer
& operator= (const OutlinerContainer
&) {return *this;};
299 /** Data collection specifying a <type>SdrObject</type> and its position in
302 class IteratorPosition
305 /** Create a new object with all data members set to default values.
306 These values should not be accessed. The only use of the object as
307 it is as a marker in comparisons.
310 /** Create a new object with all data members set from the given
313 The position object from which to take the values that are
314 assigned to the data members of this object.
316 IteratorPosition (const IteratorPosition
& aPosition
);
318 /// The destructor is a no-op at the moment.
320 /** Assign the content of the given position to this one.
322 This is the position object from which to take the values of all
325 Returns a reference to this object.
327 IteratorPosition
& operator= (const IteratorPosition
& aPosition
);
328 /** Compare two positions for equality.
330 <TRUE/> is returned only when all data members have the same
331 values in both position objects.
333 bool operator== (const IteratorPosition
& aPosition
) const;
335 /// Pointer to the actual <type>SdrObject</type> object.
336 SdrObjectWeakRef mxObject
;
338 /// Number of the actual SdrText from the current <type>SdrObject</type>
341 /// The index of a page where the object is located on.
342 sal_Int32 mnPageIndex
;
343 /// Page kind of the view.
345 /// Edit mode of the view.
349 } } // end of namespace ::sd::outliner
351 #endif // _ INCLUDED_SD_INC_OUTLINERITERATOR_HXX
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */