1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SD_OUTLINER_ITERATOR_IMPL_HXX
29 #define SD_OUTLINER_ITERATOR_IMPL_HXX
31 #include <svx/svdobj.hxx>
32 #include "OutlinerIterator.hxx"
33 #include <boost/weak_ptr.hpp>
45 class IteratorImplBase
;
47 /** Base class for the polymorphic implementation class of the
48 <type>Iterator</type> class. The iterators based on this class are
49 basically uni directional iterators. Their direction can, however, be
50 reversed at any point of their life time.
52 class IteratorImplBase
55 /** The constructor stores the given arguments to be used by the derived
58 The document provides the information to be iterated on.
60 Some information has to be taken from the view shell.
61 @param bDirectionIsForward
62 This flag defines the iteration direction. When <TRUE/> then
63 the direction is forwards otherwise it is backwards.
65 IteratorImplBase (SdDrawDocument
* pDocument
,
66 const ::boost::weak_ptr
<ViewShell
>& rpViewShellWeak
,
67 bool bDirectionIsForward
);
68 IteratorImplBase (SdDrawDocument
* pDocument
,
69 const ::boost::weak_ptr
<ViewShell
>& rpViewShellWeak
,
70 bool bDirectionIsForward
, PageKind ePageKind
, EditMode eEditMode
);
71 virtual ~IteratorImplBase (void);
73 /** Advance to the next text of the current object or to the next object.
74 This takes the iteration direction into
75 account. The new object pointed to can be retrieved (among other
76 information) by calling the <member>GetPosition</member> method.
78 virtual void GotoNextText (void) = 0;
79 /** Return an object that describes the current object.
81 The returned object describes the current object pointed to by
82 the iterator. See the description of
83 <type>IteratorPosition</type> for details on the available
86 virtual const IteratorPosition
& GetPosition (void);
87 /** Create an exact copy of this object. No argument should be
88 specified when called from the outside. It then creates an object
89 first and passes that to the inherited <member>Clone()</member>
90 methods to fill in class specific information.
92 Returns a copy of this object. When this method is called with
93 an argument then this value will be returned.
95 virtual IteratorImplBase
* Clone (IteratorImplBase
* pObject
=NULL
) const;
96 /** Test the equality of the this object and the given iterator. Two
97 iterators are taken to be equal when they point to the same object.
98 Iteration direction is not taken into account.
100 The iterator to compare to.
102 When both iterators ar equal <TRUE/> is returned, <FALSE/> otherwise.
104 virtual bool operator== (const IteratorImplBase
& rIterator
) const;
105 /** This method is used by the equality operator. Additionaly to the
106 iterator it takes a type information which is taken into account on
107 comparison. It is part of a "multimethod" pattern.
109 The iterator to compare to.
111 The type of the iterator.
113 Returns <TRUE/> when both iterators point to the same object.
115 virtual bool IsEqual (const IteratorImplBase
& rIterator
, IteratorType aType
) const;
116 /** Reverse the direction of iteration. The current object stays the same.
118 virtual void Reverse (void);
121 /// The current position as returned by <member>GetPosition()</member>.
122 IteratorPosition maPosition
;
123 /// The document on whose data the iterator operates.
124 SdDrawDocument
* mpDocument
;
125 /// Necessary secondary source of information.
126 ::boost::weak_ptr
<ViewShell
> mpViewShellWeak
;
127 /// Specifies the search direction.
128 bool mbDirectionIsForward
;
134 /** Iterator all objects that belong to the current mark list
135 a.k.a. selection. It is assumed that all marked objects belong to the
136 same page. It is further assumed that the mark list does not change
137 while an iterator is alive. It is therefore the responsibility of an
138 iterator's owner to handle the case of a changed mark list.
140 <p>For documentation of the methods please refere to the base class
141 <type>IteratorImplBase</type>.</p>
143 class SelectionIteratorImpl
144 : public IteratorImplBase
147 SelectionIteratorImpl (
148 const ::std::vector
< SdrObjectWeakRef
>& rObjectList
,
149 sal_Int32 nObjectIndex
,
150 SdDrawDocument
* pDocument
,
151 const ::boost::weak_ptr
<ViewShell
>& rpViewShellWeak
,
152 bool bDirectionIsForward
);
153 SelectionIteratorImpl (const SelectionIteratorImpl
& rObject
);
154 virtual ~SelectionIteratorImpl (void);
156 virtual void GotoNextText (void);
157 virtual const IteratorPosition
& GetPosition (void);
158 virtual IteratorImplBase
* Clone (IteratorImplBase
* pObject
) const;
159 virtual bool operator== (const IteratorImplBase
& rIterator
) const;
162 const ::std::vector
<SdrObjectWeakRef
>& mrObjectList
;
163 sal_Int32 mnObjectIndex
;
165 /** Compare the given iterator with this object. This method handles
166 only the case that the given iterator is an instance of this class.
168 The iterator to compare to.
170 The type of the iterator.
172 Returns <TRUE/> when both iterators point to the same object.
174 virtual bool IsEqual (const IteratorImplBase
& rIterator
, IteratorType aType
) const;
176 IteratorImplBase
& operator= (const IteratorImplBase
& rIterator
);
180 /** Iterator for iteration over all objects in a single view. On reaching
181 the last object on the last page (or the first object on the first page)
182 the view is *not* switched. Further calls to the
183 <member>GotoNextObject()</member> method will be ignored.
185 <p>For documentation of the methods please refere to the base class
186 <type>IteratorImplBase</type>.</p>
188 class ViewIteratorImpl
: public IteratorImplBase
192 sal_Int32 nPageIndex
,
193 SdDrawDocument
* pDocument
,
194 const ::boost::weak_ptr
<ViewShell
>& rpViewShellWeak
,
195 bool bDirectionIsForward
);
197 sal_Int32 nPageIndex
,
198 SdDrawDocument
* pDocument
,
199 const ::boost::weak_ptr
<ViewShell
>& rpViewShellWeak
,
200 bool bDirectionIsForward
,
203 virtual ~ViewIteratorImpl (void);
205 virtual void GotoNextText (void);
206 virtual IteratorImplBase
* Clone (IteratorImplBase
* pObject
) const;
207 virtual void Reverse (void);
210 /// Number of pages in the view that is specified by <member>maPosition</member>.
211 sal_Int32 mnPageCount
;
213 /** Initialize this iterator with respect to the given location. After
214 this call the object looks like newly constructed.
216 void Init (IteratorLocation aLocation
);
218 /** Set up page pointer and object list iterator for the specified
221 Index of the new page. It may lie outside the valid range for
224 void SetPage (sal_Int32 nPageIndex
);
227 /// Indicates whether a page changed occured on switching to current page.
228 bool mbPageChangeOccured
;
229 /// Pointer to the page associated with the current page index. May be NULL.
231 /// Iterator of all objects on the current page.
232 SdrObjListIter
* mpObjectIterator
;
234 // Don't use this operator.
235 ViewIteratorImpl
& operator= (const ViewIteratorImpl
&){return *this;};
241 /** Iterator for iteration over all objects in all views. It automatically
242 switches views when reaching the end/beginning of a view.
244 <p>For documentation of the methods please refere to the base class
245 <type>IteratorImplBase</type>.</p>
247 class DocumentIteratorImpl
: public ViewIteratorImpl
250 DocumentIteratorImpl (
251 sal_Int32 nPageIndex
,
254 SdDrawDocument
* pDocument
,
255 const ::boost::weak_ptr
<ViewShell
>& rpViewShellWeak
,
256 bool bDirectionIsForward
);
257 virtual ~DocumentIteratorImpl (void);
259 virtual void GotoNextText (void);
260 virtual IteratorImplBase
* Clone (IteratorImplBase
* pObject
) const;
263 sal_Int32 mnPageCount
;
265 // Don't use this operator.
266 DocumentIteratorImpl
& operator= (const DocumentIteratorImpl
& ){return *this;};
270 } } // end of namespace ::sd::outliner