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"
25 #include "DisplayObjectContainer.h"
29 #include "DisplayList.h"
30 #include "InteractiveObject.h"
32 #include "dsodefs.h" // for DSOEXPORT
36 DisplayObjectContainer::~DisplayObjectContainer()
41 DisplayObjectContainer::removeChild(DisplayObject
* obj
)
43 _displayList
.removeDisplayObject(obj
);
49 DisplayObjectContainer::removeChildAt(int index
)
51 DisplayObject
* obj
= _displayList
.removeDisplayObjectAt(index
);
52 if (obj
) obj
->set_parent(0);
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);
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);
89 class MovieInfoVisitor
93 MovieInfoVisitor(DisplayObject::InfoTree
& tr
,
94 DisplayObject::InfoTree::iterator it
)
100 void operator()(DisplayObject
* ch
) {
101 ch
->getMovieInfo(_tr
, _it
);
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
);
129 #endif // USE_SWFTREE