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