update copyright date
[gnash.git] / libcore / DisplayObjectContainer.cpp
blob47393f468cce140385fb7f9135d169338d24468b
1 // DisplayObjectContainer.h: Container of DisplayObjects.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifdef HAVE_CONFIG_H
22 # include "gnashconfig.h"
23 #endif
25 #include "DisplayObjectContainer.h"
27 #include <utility>
29 #include "DisplayList.h"
30 #include "InteractiveObject.h"
31 #include "log.h"
32 #include "dsodefs.h" // for DSOEXPORT
34 namespace gnash {
36 DisplayObjectContainer::~DisplayObjectContainer()
40 DisplayObject*
41 DisplayObjectContainer::removeChild(DisplayObject* obj)
43 _displayList.removeDisplayObject(obj);
44 obj->set_parent(0);
45 return obj;
48 DisplayObject*
49 DisplayObjectContainer::removeChildAt(int index)
51 DisplayObject* obj = _displayList.removeDisplayObjectAt(index);
52 if (obj) obj->set_parent(0);
54 return obj;
57 DisplayObject*
58 DisplayObjectContainer::addChild(DisplayObject* obj)
60 // TODO: parent should be a DisplayObjectContainer; remove dynamic_cast.
61 DisplayObjectContainer* parent =
62 dynamic_cast<DisplayObjectContainer*>(obj->parent());
63 if (parent) parent->removeChild(obj);
65 _displayList.addDisplayObject(obj);
66 obj->set_parent(this);
67 return obj;
71 DisplayObject*
72 DisplayObjectContainer::addChildAt(DisplayObject* obj, int index)
74 // TODO: parent should be a DisplayObjectContainer; remove dynamic_cast.
75 DisplayObjectContainer* parent =
76 dynamic_cast<DisplayObjectContainer*>(obj->parent());
77 if (parent) parent->removeChild(obj);
79 _displayList.insertDisplayObject(obj, index);
80 obj->set_parent(this);
81 return obj;
85 #ifdef USE_SWFTREE
87 namespace {
89 class MovieInfoVisitor
92 public:
93 MovieInfoVisitor(DisplayObject::InfoTree& tr,
94 DisplayObject::InfoTree::iterator it)
96 _tr(tr),
97 _it(it)
100 void operator()(DisplayObject* ch) {
101 ch->getMovieInfo(_tr, _it);
104 private:
106 DisplayObject::InfoTree& _tr;
107 DisplayObject::InfoTree::iterator _it;
111 } // anonymous namespace
113 DisplayObject::InfoTree::iterator
114 DisplayObjectContainer::getMovieInfo(InfoTree& tr, InfoTree::iterator it)
116 InfoTree::iterator selfIt = DisplayObject::getMovieInfo(tr, it);
117 std::ostringstream os;
118 os << _displayList.size();
119 InfoTree::iterator localIter = tr.append_child(selfIt,
120 std::make_pair(_("Children"), os.str()));
122 MovieInfoVisitor v(tr, localIter);
123 _displayList.visitAll(v);
125 return selfIt;
129 #endif // USE_SWFTREE
131 } // namespace gnash