update credits
[LibreOffice.git] / sd / source / core / shapelist.cxx
blobaa223ed940f42b25b870116125f72cc4eed1a819
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/svdobj.hxx>
21 #include "shapelist.hxx"
23 #include <algorithm>
25 using namespace sd;
27 ShapeList::ShapeList()
29 maIter = maShapeList.end();
32 ShapeList::~ShapeList()
34 clear();
37 /** adds the given shape to this list */
38 void ShapeList::addShape( SdrObject& rObject )
40 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
41 if( aIter == maShapeList.end() )
43 maShapeList.push_back(&rObject);
44 rObject.AddObjectUser( *this );
46 else
48 OSL_FAIL("sd::ShapeList::addShape(), given shape already part of list!");
52 /** removes the given shape from this list */
53 SdrObject* ShapeList::removeShape( SdrObject& rObject )
55 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
56 if( aIter != maShapeList.end() )
58 bool bIterErased = aIter == maIter;
60 (*aIter)->RemoveObjectUser(*this);
61 aIter = maShapeList.erase( aIter );
63 if( bIterErased )
64 maIter = aIter;
66 if( aIter != maShapeList.end() )
67 return (*aIter);
69 else
71 OSL_FAIL("sd::ShapeList::removeShape(), given shape not part of list!");
73 return 0;
76 /** removes all shapes from this list
77 NOTE: iterators will become invalid */
78 void ShapeList::clear()
80 ListImpl aShapeList;
81 aShapeList.swap( maShapeList );
83 ListImpl::iterator aIter( aShapeList.begin() );
84 while( aIter != aShapeList.end() )
85 (*aIter++)->RemoveObjectUser(*this);
87 maIter = aShapeList.end();
90 /** returns true if this list is empty */
91 bool ShapeList::isEmpty() const
93 return maShapeList.empty();
96 /** returns true if given shape is part of this list */
97 bool ShapeList::hasShape( SdrObject& rObject ) const
99 return std::find( maShapeList.begin(), maShapeList.end(), &rObject ) != maShapeList.end();
102 SdrObject* ShapeList::getNextShape(SdrObject* pObj) const
104 if( pObj )
106 ListImpl::const_iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), pObj ) );
107 if( aIter != maShapeList.end() )
109 ++aIter;
110 if( aIter != maShapeList.end() )
112 return (*aIter);
116 else if( !maShapeList.empty() )
118 return (*maShapeList.begin());
121 return 0;
124 void ShapeList::ObjectInDestruction(const SdrObject& rObject)
126 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
127 if( aIter != maShapeList.end() )
129 bool bIterErased = aIter == maIter;
131 aIter = maShapeList.erase( aIter );
133 if( bIterErased )
134 maIter = aIter;
136 else
138 OSL_FAIL("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
142 SdrObject* ShapeList::getNextShape()
144 if( maIter != maShapeList.end() )
146 return (*maIter++);
148 else
150 return 0;
154 void ShapeList::seekShape( sal_uInt32 nIndex )
156 maIter = maShapeList.begin();
157 while( nIndex-- && (maIter != maShapeList.end()) )
158 maIter++;
161 bool ShapeList::hasMore() const
163 return maIter != maShapeList.end();
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */