xref: /AOO41X/main/sd/inc/OutlinerIterator.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef SD_OUTLINER_ITERATOR_HXX
29*cdf0e10cSrcweir #define SD_OUTLINER_ITERATOR_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <svx/svdobj.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "pres.hxx"
34*cdf0e10cSrcweir #include "sal/types.h"
35*cdf0e10cSrcweir #include <vector>
36*cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir class SdDrawDocument;
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace sd {
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir class ViewShell;
43*cdf0e10cSrcweir class Outliner;
44*cdf0e10cSrcweir class View;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir namespace outliner {
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir class IteratorImplBase;
49*cdf0e10cSrcweir class IteratorPosition;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir /** Use this enum to specify the initial location of the object pointed to by
52*cdf0e10cSrcweir     a newly created iterator.  The values are
53*cdf0e10cSrcweir     <ul><li><const>BEGIN</const> for the first object with reference to
54*cdf0e10cSrcweir     iteration direction.</li>
55*cdf0e10cSrcweir     <li>END for one past the last valid object or, if the iterator is a
56*cdf0e10cSrcweir     backward iterator, the object in front of the first valid one.</li>
57*cdf0e10cSrcweir     <li>CURRENT for the current object.  Because there is only a current
58*cdf0e10cSrcweir     page this usually is taken to be the first/last object on the current
59*cdf0e10cSrcweir     page.</li></ul>
60*cdf0e10cSrcweir */
61*cdf0e10cSrcweir enum IteratorLocation {BEGIN,END,CURRENT};
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir /** Use this enum to specify the type of iterator when creating a new
64*cdf0e10cSrcweir     iterator:
65*cdf0e10cSrcweir     <ul><li>SELECTION for iteration over all objects that belong to the
66*cdf0e10cSrcweir     current mark list.</li>
67*cdf0e10cSrcweir     <li>SINGLE_VIEW for iteration over all objects in the current view.</li>
68*cdf0e10cSrcweir     <li>DOCUMENT for iteratioin over all object in all relevant
69*cdf0e10cSrcweir     views.</li></ul>
70*cdf0e10cSrcweir */
71*cdf0e10cSrcweir enum IteratorType {SELECTION,SINGLE_VIEW,DOCUMENT};
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir /** This iterator can be used to iterate over all <type>SdrObject</type>
75*cdf0e10cSrcweir     objects of one of three set denoted by the <type>IteratorType</type>:
76*cdf0e10cSrcweir     <ul><li>All objects of the current mark list (selection)
77*cdf0e10cSrcweir     (type==SELECTION).</li>
78*cdf0e10cSrcweir     <li>All objects in the current view (type==SINGLE_VIEW).</li>
79*cdf0e10cSrcweir     <li>All objects in all views (type=DOCUMENT).</li></ul>
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     <p>Note that the iterator does not change pages or views.  It is the
82*cdf0e10cSrcweir     task of the user of the iterator to take the information provided by the
83*cdf0e10cSrcweir     <type>IteratorPosition</type> as returned by the
84*cdf0e10cSrcweir     <member>operator*()</member> method and set view, visible page, and
85*cdf0e10cSrcweir     selection/edit mode markers to reflect this position.</p>
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     <p>A simple forward iteration from the first to the last object would
88*cdf0e10cSrcweir     instantiate the iterator with
89*cdf0e10cSrcweir     <code>Iterator(pDocument,pViewShell,true,BEGIN)</code> for some document
90*cdf0e10cSrcweir     and view shell.  This iterator can then be compared against
91*cdf0e10cSrcweir     <code>Iterator(pDocument,pViewShell,true,END)</code>.  On equality the
92*cdf0e10cSrcweir     iteration should be stoped without evaluating the iterator: The position
93*cdf0e10cSrcweir     of an end iterator is not valid.</p>
94*cdf0e10cSrcweir */
95*cdf0e10cSrcweir class Iterator
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir public:
98*cdf0e10cSrcweir     Iterator (void);
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     /** The copy constructor creates a new iterator by copying the
101*cdf0e10cSrcweir         implementation object.
102*cdf0e10cSrcweir     */
103*cdf0e10cSrcweir     Iterator (const Iterator& rIterator);
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     /** Create a new iterator with the implementation object being the
106*cdf0e10cSrcweir         provided one.
107*cdf0e10cSrcweir         @param pObject
108*cdf0e10cSrcweir             A copy of this object will become the implementation object.
109*cdf0e10cSrcweir     */
110*cdf0e10cSrcweir     explicit Iterator (IteratorImplBase* pObject);
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     ~Iterator (void);
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     /** Assign the iterator from the given one.  The implementation object
115*cdf0e10cSrcweir         of this iterator will be a copy of the given iterator.
116*cdf0e10cSrcweir         @param rIterator
117*cdf0e10cSrcweir             The iterator which to assign from.
118*cdf0e10cSrcweir     */
119*cdf0e10cSrcweir     Iterator& operator= (const Iterator& rIterator);
120*cdf0e10cSrcweir     /** Return the current position of the iterator.
121*cdf0e10cSrcweir         @return
122*cdf0e10cSrcweir             Returns a reference to the current position.  Therefore this
123*cdf0e10cSrcweir             method is not thread safe.  The reason for this behaviour is, of
124*cdf0e10cSrcweir             course, to ommit the copying of the returned position.
125*cdf0e10cSrcweir     */
126*cdf0e10cSrcweir     const IteratorPosition& operator* () const;
127*cdf0e10cSrcweir     /** The prefix increment operator returns the iterator pointing to the
128*cdf0e10cSrcweir         next object.  When in doubt prefer this operator over the postfix
129*cdf0e10cSrcweir         increment operator.
130*cdf0e10cSrcweir         @return
131*cdf0e10cSrcweir             Returns a reference to this iterator pointing to the next object.
132*cdf0e10cSrcweir     */
133*cdf0e10cSrcweir     Iterator& operator++ ();
134*cdf0e10cSrcweir     /** The postfix increment operator returns the iterator still pointing
135*cdf0e10cSrcweir         to the current object.  Only the next call to
136*cdf0e10cSrcweir         <member>operator*()</member> will return the next object.  When in
137*cdf0e10cSrcweir         doubt rather use the prefix increment operator.
138*cdf0e10cSrcweir         @param dummy
139*cdf0e10cSrcweir             A dummy operator used by the compiler.
140*cdf0e10cSrcweir         @return
141*cdf0e10cSrcweir             Returns a copy of the iterator as it where before the operator
142*cdf0e10cSrcweir             was called.
143*cdf0e10cSrcweir     */
144*cdf0e10cSrcweir     Iterator operator++ (int);
145*cdf0e10cSrcweir     /** Test equality of two iterators.  Two iterators are taken to be equal
146*cdf0e10cSrcweir         when they point are of the same type (their implementation objects
147*cdf0e10cSrcweir         are instances of the same class) and point to the same object.
148*cdf0e10cSrcweir         @param rIterator
149*cdf0e10cSrcweir             The iterator to test equality with.
150*cdf0e10cSrcweir         @return
151*cdf0e10cSrcweir             Returns <TRUE/> when both iterators point to the same object.
152*cdf0e10cSrcweir     */
153*cdf0e10cSrcweir     bool operator== (const Iterator& rIterator);
154*cdf0e10cSrcweir     /** Test whether two iterators point to different objects.  This is just
155*cdf0e10cSrcweir         the negation of the result of the equality operator.
156*cdf0e10cSrcweir         @param rIterator
157*cdf0e10cSrcweir             The iterator to test inequality with.
158*cdf0e10cSrcweir         @return
159*cdf0e10cSrcweir             Returns <TRUE/> when both iterators point to the different objects.
160*cdf0e10cSrcweir     */
161*cdf0e10cSrcweir     bool operator!= (const Iterator& rIterator);
162*cdf0e10cSrcweir     /** Reverse the direction of iteration.  The position of the iterator is
163*cdf0e10cSrcweir         not changed.  Thus caling this method twice returns to the old state.
164*cdf0e10cSrcweir     */
165*cdf0e10cSrcweir     void Reverse (void);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir private:
168*cdf0e10cSrcweir     /// The implementation object to which most of the methods are forwarded.
169*cdf0e10cSrcweir     IteratorImplBase* mpIterator;
170*cdf0e10cSrcweir };
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir /** This class wraps the <type>Outliner</type> class and represents it as
176*cdf0e10cSrcweir     a container of <type>SdrObject</type> objects.  Its main purpose is to
177*cdf0e10cSrcweir     provide iterators for certain sub-sets of those objects.  These sub-sets
178*cdf0e10cSrcweir     are a) the set of the currently selected objects, b) all objects in the
179*cdf0e10cSrcweir     current view, and c) all objects in all views.
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     <p>The direction of the returned iterators depends on the underlying
182*cdf0e10cSrcweir     <type>Outliner</type> object and is usually set in the search
183*cdf0e10cSrcweir     dialog.</p>
184*cdf0e10cSrcweir */
185*cdf0e10cSrcweir class OutlinerContainer
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir public:
188*cdf0e10cSrcweir     /** Create a new wraper object for the given outliner.
189*cdf0e10cSrcweir         @param pOutliner
190*cdf0e10cSrcweir             The outliner that is represented by the new object as
191*cdf0e10cSrcweir             <type>SdrObject</type> container.
192*cdf0e10cSrcweir     */
193*cdf0e10cSrcweir     OutlinerContainer (::sd::Outliner* pOutliner);
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir     /** Return an iterator that points to the first object of one of the
196*cdf0e10cSrcweir         sets described above.  This takes also into account the direction of
197*cdf0e10cSrcweir         iteration.
198*cdf0e10cSrcweir         @return
199*cdf0e10cSrcweir             The returned iterator points either to the first (forward
200*cdf0e10cSrcweir             search) or to the last object (backward search) of the set.
201*cdf0e10cSrcweir     */
202*cdf0e10cSrcweir     Iterator begin (void);
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     /** Return an iterator that marks the end of the iteration.  This takes
205*cdf0e10cSrcweir         also into account the direction of iteration. The object pointed to
206*cdf0e10cSrcweir         is not valid.
207*cdf0e10cSrcweir         @return
208*cdf0e10cSrcweir             The returned iterator points either to that object past the last
209*cdf0e10cSrcweir             one (forward search) or to the one in front of the first
210*cdf0e10cSrcweir             (backward search).
211*cdf0e10cSrcweir     */
212*cdf0e10cSrcweir     Iterator end (void);
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir     /** Return an iterator that points to the current object of one of the
215*cdf0e10cSrcweir         sets described above.  This takes also into account the direction of
216*cdf0e10cSrcweir         iteration.
217*cdf0e10cSrcweir         @return
218*cdf0e10cSrcweir             The returned iterator points either to the first (forward
219*cdf0e10cSrcweir             search) or to the last object (backward search) of the set of
220*cdf0e10cSrcweir             selected objects or of the current page if the search set spans
221*cdf0e10cSrcweir             more than one page.
222*cdf0e10cSrcweir     */
223*cdf0e10cSrcweir     Iterator current (void);
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir private:
226*cdf0e10cSrcweir     /// The wrapped outliner that is represented as object container.
227*cdf0e10cSrcweir     ::sd::Outliner* mpOutliner;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     /** Create an iterator.  The object pointed to depends on the search
230*cdf0e10cSrcweir         direction retrieved from the outliner object
231*cdf0e10cSrcweir         <member>mpOutliner</member> and the given location.
232*cdf0e10cSrcweir         @param aLocation
233*cdf0e10cSrcweir             This specifies whether the returned iterator points to the
234*cdf0e10cSrcweir             first, (one past the) last, or current object.
235*cdf0e10cSrcweir         @return
236*cdf0e10cSrcweir             Returns an iterator as constructed by
237*cdf0e10cSrcweir             <member>CreateSelectionIterator()</member>,
238*cdf0e10cSrcweir      */
239*cdf0e10cSrcweir     Iterator CreateIterator (IteratorLocation aLocation);
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     /** Create an iterator that iterates over all currently selected
242*cdf0e10cSrcweir         <type>SdrObjects</type> objects of the <member>mpOutliner</member>
243*cdf0e10cSrcweir         outliner.
244*cdf0e10cSrcweir         @param rObjectList
245*cdf0e10cSrcweir             List of currently selected objects.  This list is necessary
246*cdf0e10cSrcweir             so that the selection can be changed without affecting the
247*cdf0e10cSrcweir             iterator.
248*cdf0e10cSrcweir         @param pDocument
249*cdf0e10cSrcweir             The document to which the objects belong.
250*cdf0e10cSrcweir         @param pViewShell
251*cdf0e10cSrcweir             The view shell which displays the objects.
252*cdf0e10cSrcweir         @param bDirectionIsForward
253*cdf0e10cSrcweir             The direction of iteration.  It defaults to forward.
254*cdf0e10cSrcweir         @param aLocation
255*cdf0e10cSrcweir             This specifies at which object the iterator points initially.
256*cdf0e10cSrcweir     */
257*cdf0e10cSrcweir     Iterator CreateSelectionIterator (
258*cdf0e10cSrcweir         const ::std::vector<SdrObjectWeakRef>& rObjectList,
259*cdf0e10cSrcweir         SdDrawDocument* pDocument,
260*cdf0e10cSrcweir         const ::boost::shared_ptr<ViewShell>& rpViewShell,
261*cdf0e10cSrcweir         bool bDirectionIsForward=true,
262*cdf0e10cSrcweir         IteratorLocation aLocation=BEGIN);
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     /** Create an iterator that iterates over all <type>SdrObjects</type>
265*cdf0e10cSrcweir         objects of the <member>mpOutliner</member> outliner.
266*cdf0e10cSrcweir         @param pDocument
267*cdf0e10cSrcweir             The document to which the objects belong.
268*cdf0e10cSrcweir         @param pViewShell
269*cdf0e10cSrcweir             The view shell which displays the objects.
270*cdf0e10cSrcweir         @param bDirectionIsForward
271*cdf0e10cSrcweir             The direction of iteration.  It defaults to forward.
272*cdf0e10cSrcweir         @param aLocation
273*cdf0e10cSrcweir             This specifies at which object the iterator points initially.
274*cdf0e10cSrcweir     */
275*cdf0e10cSrcweir     Iterator CreateDocumentIterator (
276*cdf0e10cSrcweir         SdDrawDocument* pDocument,
277*cdf0e10cSrcweir         const ::boost::shared_ptr<ViewShell>& rpViewShell,
278*cdf0e10cSrcweir         bool bDirectionIsForward=true,
279*cdf0e10cSrcweir         IteratorLocation aLocation=BEGIN);
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     /** Return the index of a page that contains an object that a new
282*cdf0e10cSrcweir         iterator shall point to.  This page index depends primarily on the
283*cdf0e10cSrcweir         location, iteration direction, as well as on edit mode and page
284*cdf0e10cSrcweir         kind.
285*cdf0e10cSrcweir         @param pDocument
286*cdf0e10cSrcweir             The document to which the page belongs.
287*cdf0e10cSrcweir         @param pViewShell
288*cdf0e10cSrcweir             The view shell which displays the page.
289*cdf0e10cSrcweir         @param ePageKind
290*cdf0e10cSrcweir             Specifies the view the page belongs to.
291*cdf0e10cSrcweir         @param eEditMode
292*cdf0e10cSrcweir             Specifies whether the page is a master page.
293*cdf0e10cSrcweir         @param bDirectionIsForward
294*cdf0e10cSrcweir             The direction of iteration.
295*cdf0e10cSrcweir         @param aLocation
296*cdf0e10cSrcweir             This specifies at which object the iterator points initially.
297*cdf0e10cSrcweir     */
298*cdf0e10cSrcweir     sal_Int32 GetPageIndex (
299*cdf0e10cSrcweir         SdDrawDocument* pDocument,
300*cdf0e10cSrcweir         const ::boost::shared_ptr<ViewShell>& rpViewShell,
301*cdf0e10cSrcweir         PageKind ePageKind,
302*cdf0e10cSrcweir         EditMode eEditMode,
303*cdf0e10cSrcweir         bool bDirectionIsForward,
304*cdf0e10cSrcweir         IteratorLocation aLocation);
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     // Do not allow default constructor and copying of outliner containers.
307*cdf0e10cSrcweir     OutlinerContainer (const OutlinerContainer&) {};
308*cdf0e10cSrcweir     OutlinerContainer (void) {};
309*cdf0e10cSrcweir     OutlinerContainer& operator= (const OutlinerContainer&) {return *this;};
310*cdf0e10cSrcweir };
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir /** Data collection specifying a <type>SdrObject</type> and its position in
316*cdf0e10cSrcweir     a document and view.
317*cdf0e10cSrcweir */
318*cdf0e10cSrcweir class IteratorPosition
319*cdf0e10cSrcweir {
320*cdf0e10cSrcweir public:
321*cdf0e10cSrcweir     /** Create a new object with all data members set to default values.
322*cdf0e10cSrcweir         These values should not be accessed.  The only use of the object as
323*cdf0e10cSrcweir         it is is as a marker in comparisons.
324*cdf0e10cSrcweir     */
325*cdf0e10cSrcweir     IteratorPosition (void);
326*cdf0e10cSrcweir     /** Create a new object with all data members set from the given
327*cdf0e10cSrcweir         position.
328*cdf0e10cSrcweir         @param aPosition
329*cdf0e10cSrcweir             The position object from which to take the values that are
330*cdf0e10cSrcweir             assigned to the data members of this object.
331*cdf0e10cSrcweir     */
332*cdf0e10cSrcweir     IteratorPosition (const IteratorPosition& aPosition);
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 	/// The destructor is a no-op at the moment.
335*cdf0e10cSrcweir     ~IteratorPosition (void);
336*cdf0e10cSrcweir     /** Assign the content of the given position to this one.
337*cdf0e10cSrcweir         @param aPosition
338*cdf0e10cSrcweir             This is the position object from which to take the values of all
339*cdf0e10cSrcweir             data members.
340*cdf0e10cSrcweir         @return
341*cdf0e10cSrcweir             Returns a reference to this object.
342*cdf0e10cSrcweir     */
343*cdf0e10cSrcweir     IteratorPosition& operator= (const IteratorPosition& aPosition);
344*cdf0e10cSrcweir     /** Compare two positions for equality.
345*cdf0e10cSrcweir         @return
346*cdf0e10cSrcweir             <TRUE/> is returned only when all data members have the same
347*cdf0e10cSrcweir             values in both position objects.
348*cdf0e10cSrcweir     */
349*cdf0e10cSrcweir     bool operator== (const IteratorPosition& aPosition) const;
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir     /// Pointer to the actual <type>SdrObject</type> object.
352*cdf0e10cSrcweir     SdrObjectWeakRef mxObject;
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 	/// Number of the actual SdrText from the current <type>SdrObject</type>
355*cdf0e10cSrcweir 	sal_Int32 mnText;
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir     /// The index of a page where the object is located on.
358*cdf0e10cSrcweir     sal_Int32 mnPageIndex;
359*cdf0e10cSrcweir     /// Page kind of the view.
360*cdf0e10cSrcweir 	PageKind mePageKind;
361*cdf0e10cSrcweir     /// Edit mode of the view.
362*cdf0e10cSrcweir 	EditMode meEditMode;
363*cdf0e10cSrcweir };
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir } } // end of namespace ::sd::outliner
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir #endif // _SD_OUTLINER_ITERATOR_HXX
370*cdf0e10cSrcweir 
371