Gnash  0.8.10
SymbolClassTag.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_SYMBOLCLASSTAG_H
00020 #define GNASH_SWF_SYMBOLCLASSTAG_H
00021 
00022 #include <string>
00023 #include "ControlTag.h" // for inheritance
00024 #include "SWF.h" // for tag_type definition
00025 #include "MovieClip.h" // for inlines
00026 #include "SWFStream.h" // for inlines
00027 #include "Machine.h"
00028 #include "VM.h"
00029 #include "sprite_definition.h"
00030 #include "Global_as.h"
00031 
00032 // Forward declarations
00033 namespace gnash {
00034         class movie_definition;
00035 }
00036 
00037 namespace gnash {
00038 namespace SWF {
00039 
00041 //
00042 class SymbolClassTag : public ControlTag
00043 {
00044 public:
00045 
00046         virtual void executeActions(MovieClip* m, DisplayList& /* dlist */) const
00047         {
00048                 VM& vm = getVM(*getObject(m));
00049         abc::Machine* mach = vm.getMachine();
00050                 log_debug("SymbolClassTag: Creating class %s.", _rootClass);
00051                 mach->instantiateClass(_rootClass, vm.getGlobal());
00052         }
00053 
00054         static void loader(SWFStream& in, TagType tag, movie_definition& m,
00055             const RunResources& /*r*/)
00056         {
00057                 assert(tag == SYMBOLCLASS); 
00058         
00059         if (!m.isAS3()) {
00060             IF_VERBOSE_MALFORMED_SWF(
00061                 log_swferror("SWF contains SymbolClass tag, but is not an "
00062                     "AS3 SWF!");
00063             );
00064             throw ParserException("SymbolClass tag found in non-AS3 SWF!");
00065         }
00066                 
00067         in.ensureBytes(2);
00068                 boost::uint16_t num_symbols = in.read_u16();
00069                 log_debug("There are %u symbols.", num_symbols);
00070                 for (unsigned int i = 0; i < num_symbols; ++i) {
00071                         in.ensureBytes(2);
00072                         boost::uint16_t id = in.read_u16();
00073                         std::string name;
00074                         in.read_string(name);
00075                         IF_VERBOSE_PARSE(
00076                         log_parse("Symbol %u name %s, character %u", i, name, id);
00077                         );
00078             
00079             boost::intrusive_ptr<SymbolClassTag> st(new SymbolClassTag(name));
00080                         
00081             if (id == 0) m.addControlTag(st);
00082             else {
00083                 sprite_definition* s =
00084                     dynamic_cast<sprite_definition*>(m.getDefinitionTag(id));
00085                 
00086                 // TODO: it seems that the pp will add the control tag to
00087                 // the main timeline also if the id is not 0 but the
00088                 // sprite_definition does not exist.
00089                 //
00090                 // Manual tests show that:
00091                 // 1. Only the first SymbolClass tag is executed for the
00092                 //    root Sprite. TODO: check also for other Sprites. This
00093                 //    applies to multiple symbols in the same tag or to
00094                 //    subsequent SymbolClass tags.
00095                 // 2. If the id is not a definition, the tag is added to
00096                 //    the root Sprite (main timeline). TODO: check what
00097                 //    happens if the sprite is defined later.
00098                 if (s) s->addControlTag(st);
00099 
00100             }
00101                 }
00102         }
00103 
00104 private:
00105         
00106     SymbolClassTag(std::string name) 
00107         :
00108         _rootClass(name)
00109         {}
00110 
00111     const std::string _rootClass;
00112 };
00113 
00114 } // namespace gnash::SWF
00115 } // namespace gnash
00116 
00117 
00118 #endif // GNASH_SWF_SYMBOLCLASSTAG_H
00119 
00120 
00121 // Local Variables:
00122 // mode: C++
00123 // indent-tabs-mode: t
00124 // End: