1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shapelist.cxx,v $
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"
41 ShapeList::ShapeList()
43 maIter
= maShapeList
.end();
46 ShapeList::~ShapeList()
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 );
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
);
80 if( aIter
!= maShapeList
.end() )
85 DBG_ERROR("sd::ShapeList::removeShape(), given shape not part of list!");
90 /** removes all shapes from this list
91 NOTE: iterators will become invalid */
92 void ShapeList::clear()
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
120 ListImpl::const_iterator
aIter( std::find( maShapeList
.begin(), maShapeList
.end(), pObj
) );
121 if( aIter
!= maShapeList
.end() )
124 if( aIter
!= maShapeList
.end() )
130 else if( !maShapeList
.empty() )
132 return (*maShapeList
.begin());
138 SdrObject
* ShapeList::getPreviousShape( SdrObject
* pObj
) const
142 ListImpl::const_iterator
aIter( std::find( maShapeList
.begin(), maShapeList
.end(), pObj
) );
143 if( (aIter
!= maShapeList
.end()) && (aIter
!= maShapeList
.begin()) )
149 else if( !maShapeList
.empty() )
151 return (*--maShapeList
.end());
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
);
171 DBG_ERROR("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
175 SdrObject
* ShapeList::getNextShape()
177 if( maIter
!= maShapeList
.end() )
187 void ShapeList::seekShape( sal_uInt32 nIndex
)
189 maIter
= maShapeList
.begin();
190 while( nIndex
-- && (maIter
!= maShapeList
.end()) )
194 bool ShapeList::hasMore() const
196 return maIter
!= maShapeList
.end();