1 // DisplayObjectContainer.h: Container of DisplayObjects.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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
22 # include "gnashconfig.h" // GNASH_USE_GC, USE_SWFTREE
25 #include "DisplayList.h" // DisplayList
26 #include "DisplayObjectContainer.h"
27 #include "InteractiveObject.h"
29 #include "dsodefs.h" // for DSOEXPORT
33 DisplayObjectContainer::~DisplayObjectContainer()
38 DisplayObjectContainer::removeChild(DisplayObject
* obj
)
40 _displayList
.removeDisplayObject(obj
);
46 DisplayObjectContainer::removeChildAt(int index
)
48 DisplayObject
* obj
= _displayList
.removeDisplayObjectAt(index
);
49 if (obj
) obj
->set_parent(0);
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);
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);
86 class MovieInfoVisitor
90 MovieInfoVisitor(DisplayObject::InfoTree
& tr
,
91 DisplayObject::InfoTree::iterator it
)
97 void operator()(DisplayObject
* ch
) {
98 ch
->getMovieInfo(_tr
, _it
);
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
);
128 #endif // USE_SWFTREE