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 .
22 #include <svx/svdobj.hxx>
23 #include <unotools/weakref.hxx>
26 #include <sal/types.h>
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 /** This iterator can be used to iterate over all <type>SdrObject</type>
55 objects of one of three set denoted by the <type>IteratorType</type>:
56 <ul><li>All objects of the current mark list (selection)
57 (type==SELECTION).</li>
58 <li>All objects in the current view (type==SINGLE_VIEW).</li>
59 <li>All objects in all views (type=DOCUMENT).</li></ul>
61 <p>Note that the iterator does not change pages or views. It is the
62 task of the user of the iterator to take the information provided by the
63 <type>IteratorPosition</type> as returned by the
64 <member>operator*()</member> method and set view, visible page, and
65 selection/edit mode markers to reflect this position.</p>
67 <p>A simple forward iteration from the first to the last object would
68 instantiate the iterator with
69 <code>Iterator(pDocument,pViewShell,true,BEGIN)</code> for some document
70 and view shell. This iterator can then be compared against
71 <code>Iterator(pDocument,pViewShell,true,END)</code>. On equality the
72 iteration should be stopped without evaluating the iterator: The position
73 of an end iterator is not valid.</p>
80 /** The copy constructor creates a new iterator by copying the
81 implementation object.
83 Iterator (const Iterator
& rIterator
);
84 Iterator(Iterator
&& rIterator
) noexcept
;
86 /** Create a new iterator with the implementation object being the
89 A copy of this object will become the implementation object.
91 explicit Iterator (std::unique_ptr
<IteratorImplBase
> pObject
);
95 /** Assign the iterator from the given one. The implementation object
96 of this iterator will be a copy of the given iterator.
98 The iterator which to assign from.
100 Iterator
& operator= (const Iterator
& rIterator
);
101 Iterator
& operator=(Iterator
&& rIterator
) noexcept
;
103 /** Return the current position of the iterator.
105 Returns a reference to the current position. Therefore this
106 method is not thread safe. The reason for this behaviour is, of
107 course, to omit the copying of the returned position.
109 const IteratorPosition
& operator* () const;
110 /** The prefix increment operator returns the iterator pointing to the
111 next object. When in doubt prefer this operator over the postfix
114 Returns a reference to this iterator pointing to the next object.
116 Iterator
& operator++ ();
117 /** Test equality of two iterators. Two iterators are taken to be equal
118 when they point are of the same type (their implementation objects
119 are instances of the same class) and point to the same object.
121 The iterator to test equality with.
123 Returns <TRUE/> when both iterators point to the same object.
125 bool operator== (const Iterator
& rIterator
) const;
126 /** Test whether two iterators point to different objects. This is just
127 the negation of the result of the equality operator.
129 The iterator to test inequality with.
131 Returns <TRUE/> when both iterators point to the different objects.
133 bool operator!= (const Iterator
& rIterator
) const;
134 /** Reverse the direction of iteration. The position of the iterator is
135 not changed. Thus calling this method twice returns to the old state.
140 /// The implementation object to which most of the methods are forwarded.
141 std::unique_ptr
<IteratorImplBase
> mxIterator
;
144 /** This class wraps the <type>SdOutliner</type> class and represents it as
145 a container of <type>SdrObject</type> objects. Its main purpose is to
146 provide iterators for certain sub-sets of those objects. These sub-sets
147 are a) the set of the currently selected objects, b) all objects in the
148 current view, and c) all objects in all views.
150 <p>The direction of the returned iterators depends on the underlying
151 <type>SdOutliner</type> object and is usually set in the search
154 class OutlinerContainer
157 /** Create a new wrapper object for the given outliner.
159 The outliner that is represented by the new object as
160 <type>SdrObject</type> container.
162 OutlinerContainer (SdOutliner
* pOutliner
);
164 /** Return an iterator that points to the first object of one of the
165 sets described above. This takes also into account the direction of
168 The returned iterator points either to the first (forward
169 search) or to the last object (backward search) of the set.
173 /** Return an iterator that marks the end of the iteration. This takes
174 also into account the direction of iteration. The object pointed to
177 The returned iterator points either to that object past the last
178 one (forward search) or to the one in front of the first
183 /** Return an iterator that points to the current object of one of the
184 sets described above. This takes also into account the direction of
187 The returned iterator points either to the first (forward
188 search) or to the last object (backward search) of the set of
189 selected objects or of the current page if the search set spans
195 /// The wrapped outliner that is represented as object container.
196 SdOutliner
* mpOutliner
;
198 /** Create an iterator. The object pointed to depends on the search
199 direction retrieved from the outliner object
200 <member>mpOutliner</member> and the given location.
202 This specifies whether the returned iterator points to the
203 first, (one past the) last, or current object.
205 Returns an iterator as constructed by
206 <member>CreateSelectionIterator()</member>,
208 Iterator
CreateIterator (IteratorLocation aLocation
);
210 /** Create an iterator that iterates over all currently selected
211 <type>SdrObjects</type> objects of the <member>mpOutliner</member>
214 List of currently selected objects. This list is necessary
215 so that the selection can be changed without affecting the
218 The document to which the objects belong.
220 The view shell which displays the objects.
221 @param bDirectionIsForward
222 The direction of iteration. It defaults to forward.
224 This specifies at which object the iterator points initially.
226 static Iterator
CreateSelectionIterator (
227 const ::std::vector
<::unotools::WeakReference
<SdrObject
>>& rObjectList
,
228 SdDrawDocument
* pDocument
,
229 const std::shared_ptr
<ViewShell
>& rpViewShell
,
230 bool bDirectionIsForward
,
231 IteratorLocation aLocation
);
233 /** Create an iterator that iterates over all <type>SdrObjects</type>
234 objects of the <member>mpOutliner</member> outliner.
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
CreateDocumentIterator (
245 SdDrawDocument
* pDocument
,
246 const std::shared_ptr
<ViewShell
>& rpViewShell
,
247 bool bDirectionIsForward
,
248 IteratorLocation aLocation
);
250 /** Return the index of a page that contains an object that a new
251 iterator shall point to. This page index depends primarily on the
252 location, iteration direction, as well as on edit mode and page
255 The document to which the page belongs.
257 The view shell which displays the page.
259 Specifies the view the page belongs to.
261 Specifies whether the page is a master page.
262 @param bDirectionIsForward
263 The direction of iteration.
265 This specifies at which object the iterator points initially.
267 static sal_Int32
GetPageIndex (
268 SdDrawDocument
const * pDocument
,
269 const std::shared_ptr
<ViewShell
>& rpViewShell
,
272 bool bDirectionIsForward
,
273 IteratorLocation aLocation
);
275 // Do not allow default constructor and copying of outliner containers.
276 OutlinerContainer (const OutlinerContainer
&) = delete;
277 OutlinerContainer
& operator= (const OutlinerContainer
&) = delete;
280 /** Data collection specifying a <type>SdrObject</type> and its position in
283 class IteratorPosition
286 /** Create a new object with all data members set to default values.
287 These values should not be accessed. The only use of the object as
288 it is as a marker in comparisons.
292 /** Compare two positions for equality.
294 <TRUE/> is returned only when all data members have the same
295 values in both position objects.
297 bool operator== (const IteratorPosition
& aPosition
) const;
299 /// Pointer to the actual <type>SdrObject</type> object.
300 ::unotools::WeakReference
<SdrObject
> mxObject
;
302 /// Number of the actual SdrText from the current <type>SdrObject</type>
305 /// The index of a page where the object is located on.
306 sal_Int32 mnPageIndex
;
307 /// Page kind of the view.
309 /// Edit mode of the view.
313 } } // end of namespace ::sd::outliner
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */