• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

SymbolClassTag.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 
00018 #ifndef GNASH_SWF_SYMBOLCLASSTAG_H
00019 #define GNASH_SWF_SYMBOLCLASSTAG_H
00020 
00021 #include <string>
00022 #include "ControlTag.h" // for inheritance
00023 #include "SWF.h" // for tag_type definition
00024 #include "MovieClip.h" // for inlines
00025 #include "SWFStream.h" // for inlines
00026 #include "Machine.h"
00027 #include "VM.h"
00028 #include "sprite_definition.h"
00029 #include "Global_as.h"
00030 
00031 // Forward declarations
00032 namespace gnash {
00033         class movie_definition;
00034 }
00035 
00036 namespace gnash {
00037 namespace SWF {
00038 
00040 //
00041 class SymbolClassTag : public ControlTag
00042 {
00043 public:
00044 
00045         virtual void executeActions(MovieClip* m, DisplayList& /* dlist */) const
00046         {
00047                 VM& vm = getVM(*getObject(m));
00048         abc::Machine* mach = vm.getMachine();
00049                 log_debug("SymbolClassTag: Creating class %s.", _rootClass);
00050                 mach->instantiateClass(_rootClass, vm.getGlobal());
00051         }
00052 
00053         static void loader(SWFStream& in, TagType tag, movie_definition& m,
00054             const RunResources& /*r*/)
00055         {
00056                 assert(tag == SYMBOLCLASS); 
00057         
00058         if (!m.isAS3()) {
00059             IF_VERBOSE_MALFORMED_SWF(
00060                 log_swferror("SWF contains SymbolClass tag, but is not an "
00061                     "AS3 SWF!");
00062             );
00063             throw ParserException("SymbolClass tag found in non-AS3 SWF!");
00064         }
00065                 
00066         in.ensureBytes(2);
00067                 boost::uint16_t num_symbols = in.read_u16();
00068                 log_debug("There are %u symbols.", num_symbols);
00069                 for (unsigned int i = 0; i < num_symbols; ++i) {
00070                         in.ensureBytes(2);
00071                         boost::uint16_t id = in.read_u16();
00072                         std::string name;
00073                         in.read_string(name);
00074                         IF_VERBOSE_PARSE(
00075                         log_parse("Symbol %u name %s, character %u", i, name, id);
00076                         );
00077             
00078             SymbolClassTag* st = new SymbolClassTag(name);
00079                         
00080             if (id == 0) m.addControlTag(st);
00081             else {
00082                 sprite_definition* s =
00083                     dynamic_cast<sprite_definition*>(m.getDefinitionTag(id));
00084                 
00085                 // TODO: it seems that the pp will add the control tag to
00086                 // the main timeline also if the id is not 0 but the
00087                 // sprite_definition does not exist.
00088                 //
00089                 // Manual tests show that:
00090                 // 1. Only the first SymbolClass tag is executed for the
00091                 //    root Sprite. TODO: check also for other Sprites. This
00092                 //    applies to multiple symbols in the same tag or to
00093                 //    subsequent SymbolClass tags.
00094                 // 2. If the id is not a definition, the tag is added to
00095                 //    the root Sprite (main timeline). TODO: check what
00096                 //    happens if the sprite is defined later.
00097                 if (s) s->addControlTag(st);
00098 
00099             }
00100                 }
00101         }
00102 
00103 private:
00104         
00105     SymbolClassTag(std::string name) 
00106         :
00107         _rootClass(name)
00108         {}
00109 
00110     const std::string _rootClass;
00111 };
00112 
00113 } // namespace gnash::SWF
00114 } // namespace gnash
00115 
00116 
00117 #endif // GNASH_SWF_SYMBOLCLASSTAG_H
00118 
00119 
00120 // Local Variables:
00121 // mode: C++
00122 // indent-tabs-mode: t
00123 // End:

Generated on Thu Sep 30 2010 14:35:03 for Gnash by  doxygen 1.7.1