merge the formfield patch from ooo-build
[ooovba.git] / sd / source / core / shapelist.cxx
blob58408818cd3a9e0e0cbe34b4524c1d7be298c8ef
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shapelist.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <tools/debug.hxx>
34 #include <svx/svdobj.hxx>
35 #include "shapelist.hxx"
37 #include <algorithm>
39 using namespace sd;
41 ShapeList::ShapeList()
43 maIter = maShapeList.end();
46 ShapeList::~ShapeList()
48 clear();
51 /** adds the given shape to this list */
52 void ShapeList::addShape( SdrObject& rObject )
54 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
55 if( aIter == maShapeList.end() )
57 maShapeList.push_back(&rObject);
58 rObject.AddObjectUser( *this );
60 else
62 DBG_ERROR("sd::ShapeList::addShape(), given shape already part of list!");
66 /** removes the given shape from this list */
67 SdrObject* ShapeList::removeShape( SdrObject& rObject )
69 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
70 if( aIter != maShapeList.end() )
72 bool bIterErased = aIter == maIter;
74 (*aIter)->RemoveObjectUser(*this);
75 aIter = maShapeList.erase( aIter );
77 if( bIterErased )
78 maIter = aIter;
80 if( aIter != maShapeList.end() )
81 return (*aIter);
83 else
85 DBG_ERROR("sd::ShapeList::removeShape(), given shape not part of list!");
87 return 0;
90 /** removes all shapes from this list
91 NOTE: iterators will become invalid */
92 void ShapeList::clear()
94 ListImpl aShapeList;
95 aShapeList.swap( maShapeList );
97 ListImpl::iterator aIter( aShapeList.begin() );
98 while( aIter != aShapeList.end() )
99 (*aIter++)->RemoveObjectUser(*this);
101 maIter = aShapeList.end();
104 /** returns true if this list is empty */
105 bool ShapeList::isEmpty() const
107 return maShapeList.empty();
110 /** returns true if given shape is part of this list */
111 bool ShapeList::hasShape( SdrObject& rObject ) const
113 return std::find( maShapeList.begin(), maShapeList.end(), &rObject ) != maShapeList.end();
116 SdrObject* ShapeList::getNextShape(SdrObject* pObj) const
118 if( pObj )
120 ListImpl::const_iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), pObj ) );
121 if( aIter != maShapeList.end() )
123 aIter++;
124 if( aIter != maShapeList.end() )
126 return (*aIter);
130 else if( !maShapeList.empty() )
132 return (*maShapeList.begin());
135 return 0;
138 SdrObject* ShapeList::getPreviousShape( SdrObject* pObj ) const
140 if( pObj )
142 ListImpl::const_iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), pObj ) );
143 if( (aIter != maShapeList.end()) && (aIter != maShapeList.begin()) )
145 aIter--;
146 return (*aIter);
149 else if( !maShapeList.empty() )
151 return (*--maShapeList.end());
154 return 0;
157 void ShapeList::ObjectInDestruction(const SdrObject& rObject)
159 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
160 if( aIter != maShapeList.end() )
162 bool bIterErased = aIter == maIter;
164 aIter = maShapeList.erase( aIter );
166 if( bIterErased )
167 maIter = aIter;
169 else
171 DBG_ERROR("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
175 SdrObject* ShapeList::getNextShape()
177 if( maIter != maShapeList.end() )
179 return (*maIter++);
181 else
183 return 0;
187 void ShapeList::seekShape( sal_uInt32 nIndex )
189 maIter = maShapeList.begin();
190 while( nIndex-- && (maIter != maShapeList.end()) )
191 maIter++;
194 bool ShapeList::hasMore() const
196 return maIter != maShapeList.end();