Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <svx/svdobj.hxx>
21 : #include "shapelist.hxx"
22 :
23 : #include <algorithm>
24 :
25 : using namespace sd;
26 :
27 0 : ShapeList::ShapeList()
28 : {
29 0 : maIter = maShapeList.end();
30 0 : }
31 :
32 0 : ShapeList::~ShapeList()
33 : {
34 0 : clear();
35 0 : }
36 :
37 : /** adds the given shape to this list */
38 0 : void ShapeList::addShape( SdrObject& rObject )
39 : {
40 0 : ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
41 0 : if( aIter == maShapeList.end() )
42 : {
43 0 : maShapeList.push_back(&rObject);
44 0 : rObject.AddObjectUser( *this );
45 : }
46 : else
47 : {
48 : OSL_FAIL("sd::ShapeList::addShape(), given shape already part of list!");
49 : }
50 0 : }
51 :
52 : /** removes the given shape from this list */
53 0 : SdrObject* ShapeList::removeShape( SdrObject& rObject )
54 : {
55 0 : ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
56 0 : if( aIter != maShapeList.end() )
57 : {
58 0 : bool bIterErased = aIter == maIter;
59 :
60 0 : (*aIter)->RemoveObjectUser(*this);
61 0 : aIter = maShapeList.erase( aIter );
62 :
63 0 : if( bIterErased )
64 0 : maIter = aIter;
65 :
66 0 : if( aIter != maShapeList.end() )
67 0 : return (*aIter);
68 : }
69 : else
70 : {
71 : OSL_FAIL("sd::ShapeList::removeShape(), given shape not part of list!");
72 : }
73 0 : return 0;
74 : }
75 :
76 : /** removes all shapes from this list
77 : NOTE: iterators will become invalid */
78 0 : void ShapeList::clear()
79 : {
80 0 : ListImpl aShapeList;
81 0 : aShapeList.swap( maShapeList );
82 :
83 0 : ListImpl::iterator aIter( aShapeList.begin() );
84 0 : while( aIter != aShapeList.end() )
85 0 : (*aIter++)->RemoveObjectUser(*this);
86 :
87 0 : maIter = aShapeList.end();
88 0 : }
89 :
90 : /** returns true if this list is empty */
91 0 : bool ShapeList::isEmpty() const
92 : {
93 0 : return maShapeList.empty();
94 : }
95 :
96 : /** returns true if given shape is part of this list */
97 0 : bool ShapeList::hasShape( SdrObject& rObject ) const
98 : {
99 0 : return std::find( maShapeList.begin(), maShapeList.end(), &rObject ) != maShapeList.end();
100 : }
101 :
102 0 : void ShapeList::ObjectInDestruction(const SdrObject& rObject)
103 : {
104 0 : ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
105 0 : if( aIter != maShapeList.end() )
106 : {
107 0 : bool bIterErased = aIter == maIter;
108 :
109 0 : aIter = maShapeList.erase( aIter );
110 :
111 0 : if( bIterErased )
112 0 : maIter = aIter;
113 : }
114 : else
115 : {
116 : OSL_FAIL("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
117 : }
118 0 : }
119 :
120 0 : SdrObject* ShapeList::getNextShape()
121 : {
122 0 : if( maIter != maShapeList.end() )
123 : {
124 0 : return (*maIter++);
125 : }
126 : else
127 : {
128 0 : return 0;
129 : }
130 : }
131 :
132 0 : void ShapeList::seekShape( sal_uInt32 nIndex )
133 : {
134 0 : maIter = maShapeList.begin();
135 0 : while( nIndex-- && (maIter != maShapeList.end()) )
136 0 : maIter++;
137 0 : }
138 :
139 0 : bool ShapeList::hasMore() const
140 : {
141 0 : return maIter != maShapeList.end();
142 : }
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|