1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_OUTLINER_ITERATOR_IMPL_HXX
25 #define SD_OUTLINER_ITERATOR_IMPL_HXX
26 
27 #include <svx/svdobj.hxx>
28 #include "OutlinerIterator.hxx"
29 #include <boost/weak_ptr.hpp>
30 
31 class SdDrawDocument;
32 class SdPage;
33 class SdrObjListIter;
34 
35 namespace sd {
36 
37 class ViewShell;
38 
39 namespace outliner {
40 
41 class IteratorImplBase;
42 
43 /** Base class for the polymorphic implementation class of the
44     <type>Iterator</type> class.  The iterators based on this class are
45     basically uni directional iterators.  Their direction can, however, be
46     reversed at any point of their life time.
47 */
48 class IteratorImplBase
49 {
50 public:
51     /** The constructor stores the given arguments to be used by the derived
52         classes.
53         @param pDocument
54             The document provides the information to be iterated on.
55         @param pViewShellWeak
56             Some information has to be taken from the view shell.
57         @param bDirectionIsForward
58             This flag defines the iteration direction.  When <TRUE/> then
59             the direction is forwards otherwise it is backwards.
60     */
61     IteratorImplBase (SdDrawDocument* pDocument,
62         const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
63         bool bDirectionIsForward);
64     IteratorImplBase (SdDrawDocument* pDocument,
65         const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
66         bool bDirectionIsForward, PageKind ePageKind, EditMode eEditMode);
67     virtual ~IteratorImplBase (void);
68 
69     /** Advance to the next text of the current object or to the next object.
70 	    This takes the iteration direction into
71         account.  The new object pointed to can be retrieved (among other
72         information) by calling the <member>GetPosition</member> method.
73     */
74     virtual void GotoNextText (void) = 0;
75     /** Return an object that describes the current object.
76         @return
77             The returned object describes the current object pointed to by
78             the iterator.  See the description of
79             <type>IteratorPosition</type> for details on the available
80             information.
81     */
82     virtual const IteratorPosition& GetPosition (void);
83     /** Create an exact copy of this object.  No argument should be
84         specified when called from the outside.  It then creates an object
85         first and passes that to the inherited <member>Clone()</member>
86         methods to fill in class specific information.
87         @return
88             Returns a copy of this object.  When this method is called with
89             an argument then this value will be returned.
90     */
91     virtual IteratorImplBase* Clone (IteratorImplBase* pObject=NULL) const;
92     /** Test the equality of the this object and the given iterator.  Two
93         iterators are taken to be equal when they point to the same object.
94         Iteration direction is not taken into account.
95         @param rIterator
96             The iterator to compare to.
97         @return
98             When both iterators ar equal <TRUE/> is returned, <FALSE/> otherwise.
99     */
100     virtual bool operator== (const IteratorImplBase& rIterator) const;
101     /** This method is used by the equality operator.  Additionaly to the
102         iterator it takes a type information which is taken into account on
103         comparison.  It is part of a "multimethod" pattern.
104         @param rIterator
105             The iterator to compare to.
106         @param aType
107             The type of the iterator.
108         @return
109             Returns <TRUE/> when both iterators point to the same object.
110     */
111     virtual bool IsEqual (const IteratorImplBase& rIterator, IteratorType aType) const;
112     /** Reverse the direction of iteration.  The current object stays the same.
113     */
114     virtual void Reverse (void);
115 
116 protected:
117     /// The current position as returned by <member>GetPosition()</member>.
118     IteratorPosition maPosition;
119     /// The document on whose data the iterator operates.
120     SdDrawDocument* mpDocument;
121     /// Necessary secondary source of information.
122     ::boost::weak_ptr<ViewShell> mpViewShellWeak;
123     /// Specifies the search direction.
124     bool mbDirectionIsForward;
125 };
126 
127 
128 
129 
130 /** Iterator all objects that belong to the current mark list
131     a.k.a. selection.  It is assumed that all marked objects belong to the
132     same page.  It is further assumed that the mark list does not change
133     while an iterator is alive.  It is therefore the responsibility of an
134     iterator's owner to handle the case of a changed mark list.
135 
136     <p>For documentation of the methods please refere to the base class
137     <type>IteratorImplBase</type>.</p>
138 */
139 class SelectionIteratorImpl
140     : public IteratorImplBase
141 {
142 public:
143     SelectionIteratorImpl (
144         const ::std::vector< SdrObjectWeakRef >& rObjectList,
145         sal_Int32 nObjectIndex,
146         SdDrawDocument* pDocument,
147         const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
148         bool bDirectionIsForward);
149     SelectionIteratorImpl (const SelectionIteratorImpl& rObject);
150     virtual ~SelectionIteratorImpl (void);
151 
152     virtual void GotoNextText (void);
153     virtual const IteratorPosition& GetPosition (void);
154     virtual IteratorImplBase* Clone (IteratorImplBase* pObject) const;
155     virtual bool operator== (const IteratorImplBase& rIterator) const;
156 
157 private:
158     const ::std::vector<SdrObjectWeakRef>& mrObjectList;
159     sal_Int32 mnObjectIndex;
160 
161     /** Compare the given iterator with this object.  This method handles
162         only the case that the given iterator is an instance of this class.
163         @param rIterator
164             The iterator to compare to.
165         @param aType
166             The type of the iterator.
167         @return
168             Returns <TRUE/> when both iterators point to the same object.
169     */
170     virtual bool IsEqual (const IteratorImplBase& rIterator, IteratorType aType) const;
171 
172     IteratorImplBase& operator= (const IteratorImplBase& rIterator);
173 };
174 
175 
176 /** Iterator for iteration over all objects in a single view.  On reaching
177     the last object on the last page (or the first object on the first page)
178     the view is *not* switched.  Further calls to the
179     <member>GotoNextObject()</member> method will be ignored.
180 
181     <p>For documentation of the methods please refere to the base class
182     <type>IteratorImplBase</type>.</p>
183 */
184 class ViewIteratorImpl : public IteratorImplBase
185 {
186 public:
187     ViewIteratorImpl (
188         sal_Int32 nPageIndex,
189         SdDrawDocument* pDocument,
190         const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
191         bool bDirectionIsForward);
192     ViewIteratorImpl (
193         sal_Int32 nPageIndex,
194         SdDrawDocument* pDocument,
195         const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
196         bool bDirectionIsForward,
197         PageKind ePageKind,
198         EditMode eEditMode);
199     virtual ~ViewIteratorImpl (void);
200 
201     virtual void GotoNextText (void);
202     virtual IteratorImplBase* Clone (IteratorImplBase* pObject) const;
203     virtual void Reverse (void);
204 
205 protected:
206     /// Number of pages in the view that is specified by <member>maPosition</member>.
207     sal_Int32 mnPageCount;
208 
209     /** Initialize this iterator with respect to the given location.  After
210         this call the object looks like newly constructed.
211     */
212     void Init (IteratorLocation aLocation);
213 
214     /** Set up page pointer and object list iterator for the specified
215         page.
216         @param nPageIndex
217             Index of the new page.  It may lie outside the valid range for
218             page indices.
219     */
220     void SetPage (sal_Int32 nPageIndex);
221 
222 private:
223     /// Indicates whether a page changed occured on switching to current page.
224     bool mbPageChangeOccured;
225     /// Pointer to the page associated with the current page index. May be NULL.
226     SdPage* mpPage;
227     /// Iterator of all objects on the current page.
228     SdrObjListIter* mpObjectIterator;
229 
230     // Don't use this operator.
231     ViewIteratorImpl& operator= (const ViewIteratorImpl&){return *this;};
232 };
233 
234 
235 
236 
237 /** Iterator for iteration over all objects in all views.  It automatically
238     switches views when reaching the end/beginning of a view.
239 
240     <p>For documentation of the methods please refere to the base class
241     <type>IteratorImplBase</type>.</p>
242 */
243 class DocumentIteratorImpl : public ViewIteratorImpl
244 {
245 public:
246     DocumentIteratorImpl (
247         sal_Int32 nPageIndex,
248         PageKind ePageKind,
249         EditMode eEditMode,
250         SdDrawDocument* pDocument,
251         const ::boost::weak_ptr<ViewShell>& rpViewShellWeak,
252         bool bDirectionIsForward);
253     virtual ~DocumentIteratorImpl (void);
254 
255     virtual void GotoNextText (void);
256     virtual IteratorImplBase* Clone (IteratorImplBase* pObject) const;
257 
258 private:
259     sal_Int32 mnPageCount;
260 
261     // Don't use this operator.
262     DocumentIteratorImpl& operator= (const DocumentIteratorImpl& ){return *this;};
263 };
264 
265 
266 } } // end of namespace ::sd::outliner
267 
268 #endif
269