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