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