Gnash  0.8.10
DoInitActionTag.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc.
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_SWF_DOINITACTIONTAG_H
00020 #define GNASH_SWF_DOINITACTIONTAG_H
00021 
00022 #include "ControlTag.h" // for inheritance
00023 #include "SWF.h" // for TagType definition
00024 #include "action_buffer.h" // for composition
00025 #include "MovieClip.h" // for inlines
00026 #include "SWFStream.h" // for inlines
00027 
00028 // Forward declarations
00029 namespace gnash {
00030     class movie_definition;
00031 }
00032 
00033 namespace gnash {
00034 namespace SWF {
00035 
00037 //
00040 class DoInitActionTag : public ControlTag
00041 {
00042 public:
00043 
00044     DoInitActionTag(SWFStream& in, movie_definition& md, int cid)
00045         :
00046         _buf(md),
00047         _cid(cid)
00048     {
00049         read(in);
00050     }
00051 
00053     //
00056     //
00059     virtual void executeState(MovieClip* m, DisplayList& /*dlist*/) const {
00060         m->execute_init_action_buffer(_buf, _cid);
00061     }
00062 
00063     static void loader(SWFStream& in, TagType tag, movie_definition& m,
00064             const RunResources& /*r*/)
00065     {
00066         if (m.isAS3()) {
00067             IF_VERBOSE_MALFORMED_SWF(
00068                 log_swferror("SWF contains DoInitAction tag, but is an "
00069                 "AS3 SWF!");
00070             );
00071             throw ParserException("DoInitAction tag found in AS3 SWF!");
00072         }
00073         
00074         in.ensureBytes(2);
00075         const boost::uint16_t cid = in.read_u16();
00076 
00077         IF_VERBOSE_PARSE(
00078             log_parse(_("  tag %d: do_init_action_loader"), tag);
00079             log_parse(_("  -- init actions for sprite %d"), cid);
00080         );
00081 
00082         // TODO: Currently, tags are only be executed for already parsed
00083         // character ids. This is known to be wrong: a more accurate
00084         // description is:
00085         //
00086         // The DoInitAction tag is executed only for characters on the stage
00087         // or exported characters. It is only executed once.
00088         //
00089         // It's not known whether characters that were placed on the stage
00090         // but then removed before the InitAction tag is encountered cause
00091         // the actions to be executed.
00092         //
00093         // Gnash currently doesn't know which characters are on the stage, or
00094         // which IDs have been exported.
00095         boost::intrusive_ptr<ControlTag> da(new DoInitActionTag(in, m, cid));
00096         m.addControlTag(da); // ownership transferred
00097     }
00098 
00099 private:
00100 
00102     //
00103     void read(SWFStream& in)
00104     {
00105         _buf.read(in, in.get_tag_end_position());
00106     }
00107 
00108 
00109     action_buffer _buf;
00110 
00111     // id of referenced DisplayObject definition
00112     int _cid;
00113 };
00114 
00115 } // namespace gnash::SWF
00116 } // namespace gnash
00117 
00118 
00119 #endif // GNASH_SWF_DOINITACTIONTAG_H
00120 
00121 
00122 // Local Variables:
00123 // mode: C++
00124 // indent-tabs-mode: t
00125 // End:
00126