fix typo, add instructions about lowercase named strings
[gnash.git] / libcore / DisplayObjectContainer.cpp
blob6b58bbe107f41c6a59c5ba308295d232344e574c
1 // DisplayObjectContainer.h: Container of DisplayObjects.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
4 // 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" // GNASH_USE_GC, USE_SWFTREE
23 #endif
25 #include "DisplayList.h" // DisplayList
26 #include "DisplayObjectContainer.h"
27 #include "InteractiveObject.h"
28 #include "log.h"
29 #include "dsodefs.h" // for DSOEXPORT
31 namespace gnash {
33 DisplayObjectContainer::~DisplayObjectContainer()
37 DisplayObject*
38 DisplayObjectContainer::removeChild(DisplayObject* obj)
40 _displayList.removeDisplayObject(obj);
41 obj->set_parent(0);
42 return obj;
45 DisplayObject*
46 DisplayObjectContainer::removeChildAt(int index)
48 DisplayObject* obj = _displayList.removeDisplayObjectAt(index);
49 if (obj) obj->set_parent(0);
51 return obj;
54 DisplayObject*
55 DisplayObjectContainer::addChild(DisplayObject* obj)
57 // TODO: parent should be a DisplayObjectContainer; remove dynamic_cast.
58 DisplayObjectContainer* parent =
59 dynamic_cast<DisplayObjectContainer*>(obj->parent());
60 if (parent) parent->removeChild(obj);
62 _displayList.addDisplayObject(obj);
63 obj->set_parent(this);
64 return obj;
68 DisplayObject*
69 DisplayObjectContainer::addChildAt(DisplayObject* obj, int index)
71 // TODO: parent should be a DisplayObjectContainer; remove dynamic_cast.
72 DisplayObjectContainer* parent =
73 dynamic_cast<DisplayObjectContainer*>(obj->parent());
74 if (parent) parent->removeChild(obj);
76 _displayList.insertDisplayObject(obj, index);
77 obj->set_parent(this);
78 return obj;
82 #ifdef USE_SWFTREE
84 namespace {
86 class MovieInfoVisitor
89 public:
90 MovieInfoVisitor(DisplayObject::InfoTree& tr,
91 DisplayObject::InfoTree::iterator it)
93 _tr(tr),
94 _it(it)
97 void operator()(DisplayObject* ch) {
98 ch->getMovieInfo(_tr, _it);
101 private:
103 DisplayObject::InfoTree& _tr;
104 DisplayObject::InfoTree::iterator _it;
108 } // anonymous namespace
110 DisplayObject::InfoTree::iterator
111 DisplayObjectContainer::getMovieInfo(InfoTree& tr, InfoTree::iterator it)
113 InfoTree::iterator selfIt = DisplayObject::getMovieInfo(tr, it);
114 std::ostringstream os;
115 os << _displayList.size();
116 InfoTree::iterator localIter = tr.append_child(selfIt,
117 StringPair(_("Children"), os.str()));
118 //localIter = tr.append_child(localIter, StringPair("child1", "fake"));
119 //localIter = tr.append_child(localIter, StringPair("child2", "fake"));
121 MovieInfoVisitor v(tr, localIter);
122 _displayList.visitAll(v);
124 return selfIt;
128 #endif // USE_SWFTREE
130 } // namespace gnash