Gnash  0.8.11dev
SymbolClassTag.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_SWF_SYMBOLCLASSTAG_H
20 #define GNASH_SWF_SYMBOLCLASSTAG_H
21 
22 #include <string>
23 #include "ControlTag.h" // for inheritance
24 #include "SWF.h" // for tag_type definition
25 #include "MovieClip.h" // for inlines
26 #include "SWFStream.h" // for inlines
27 #include "Machine.h"
28 #include "VM.h"
29 #include "sprite_definition.h"
30 #include "Global_as.h"
31 
32 // Forward declarations
33 namespace gnash {
34  class movie_definition;
35 }
36 
37 namespace gnash {
38 namespace SWF {
39 
41 //
42 class SymbolClassTag : public ControlTag
43 {
44 public:
45 
46  virtual void executeActions(MovieClip* m, DisplayList& /* dlist */) const
47  {
48  VM& vm = getVM(*getObject(m));
49  abc::Machine* mach = vm.getMachine();
50  log_debug("SymbolClassTag: Creating class %s.", _rootClass);
51  mach->instantiateClass(_rootClass, vm.getGlobal());
52  }
53 
54  static void loader(SWFStream& in, TagType tag, movie_definition& m,
55  const RunResources& /*r*/)
56  {
57  assert(tag == SYMBOLCLASS);
58 
59  if (!m.isAS3()) {
61  log_swferror("SWF contains SymbolClass tag, but is not an "
62  "AS3 SWF!");
63  );
64  throw ParserException("SymbolClass tag found in non-AS3 SWF!");
65  }
66 
67  in.ensureBytes(2);
68  std::uint16_t num_symbols = in.read_u16();
69  log_debug("There are %u symbols.", num_symbols);
70  for (unsigned int i = 0; i < num_symbols; ++i) {
71  in.ensureBytes(2);
72  std::uint16_t id = in.read_u16();
73  std::string name;
74  in.read_string(name);
76  log_parse("Symbol %u name %s, character %u", i, name, id);
77  );
78 
79  boost::intrusive_ptr<SymbolClassTag> st(new SymbolClassTag(name));
80 
81  if (id == 0) m.addControlTag(st);
82  else {
84  dynamic_cast<sprite_definition*>(m.getDefinitionTag(id));
85 
86  // TODO: it seems that the pp will add the control tag to
87  // the main timeline also if the id is not 0 but the
88  // sprite_definition does not exist.
89  //
90  // Manual tests show that:
91  // 1. Only the first SymbolClass tag is executed for the
92  // root Sprite. TODO: check also for other Sprites. This
93  // applies to multiple symbols in the same tag or to
94  // subsequent SymbolClass tags.
95  // 2. If the id is not a definition, the tag is added to
96  // the root Sprite (main timeline). TODO: check what
97  // happens if the sprite is defined later.
98  if (s) s->addControlTag(st);
99 
100  }
101  }
102  }
103 
104 private:
105 
106  SymbolClassTag(std::string name)
107  :
108  _rootClass(name)
109  {}
110 
111  const std::string _rootClass;
112 };
113 
114 } // namespace gnash::SWF
115 } // namespace gnash
116 
117 
118 #endif // GNASH_SWF_SYMBOLCLASSTAG_H
119 
120 
121 // Local Variables:
122 // mode: C++
123 // indent-tabs-mode: t
124 // End:
std::uint16_t read_u16()
Read a aligned unsigned 16-bit value from the stream.
Definition: SWFStream.cpp:332
Global_as * getGlobal() const
Get a pointer to this VM&#39;s _global Object.
Definition: VM.cpp:149
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
A MovieClip is a container for DisplayObjects.
Definition: MovieClip.h:83
void read_string(std::string &to)
Reads a null-terminated string from the given file and assigns it to the given std::string, overriding any previous value of it.
Definition: SWFStream.cpp:395
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:30
Holds the immutable data for a sprite, as read from as SWF stream. @ should not derive from movie_def...
Definition: sprite_definition.h:49
An SWF parsing exception.
Definition: GnashException.h:89
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
#define IF_VERBOSE_MALFORMED_SWF(x)
Definition: log.h:404
virtual void executeActions(MovieClip *m, DisplayList &) const
Execute Action tags.
Definition: SymbolClassTag.h:46
virtual void addControlTag(boost::intrusive_ptr< SWF::ControlTag > c)
Add an ControlTag to this movie_definition&#39;s playlist.
Definition: sprite_definition.h:211
#define IF_VERBOSE_PARSE(x)
Definition: log.h:378
Control tags are swf tags that control the operation of the movie.
Definition: ControlTag.h:43
void log_parse(StringType msg, Args... args)
Definition: log.h:313
static void loader(SWFStream &in, TagType tag, movie_definition &m, const RunResources &)
Definition: SymbolClassTag.h:54
virtual DefinitionTag * getDefinitionTag(std::uint16_t) const
Get a DisplayObject from the dictionary.
Definition: movie_definition.h:196
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
SWF Tag SymbolClass (76)
Definition: SymbolClassTag.h:42
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:53
Definition: SWF.h:106
void log_swferror(StringType msg, Args... args)
Definition: log.h:325
virtual bool isAS3() const
True if the SWFMovie should use AVM2.
Definition: movie_definition.h:410
The virtual machine for executing ABC (ActionScript Bytecode).
Definition: Machine.h:73
The AVM1 virtual machine.
Definition: VM.h:71
Definition: GnashKey.h:155
Definition: GnashKey.h:159
Definition: GnashKey.h:165
void log_debug(StringType msg, Args... args)
Definition: log.h:301
virtual void addControlTag(boost::intrusive_ptr< SWF::ControlTag >)
Add an ControlTag to this movie_definition&#39;s playlist.
Definition: movie_definition.h:273
A list of on-stage DisplayObjects, ordered by depth.
Definition: DisplayList.h:64
std::string name
Definition: LocalConnection_as.cpp:149
Definition: GnashKey.h:331
as_object * getObject(const DisplayObject *d)
Return the as_object associated with a DisplayObject if it exists.
Definition: DisplayObject.h:1160
SWF stream wrapper class.
Definition: SWFStream.h:58
void instantiateClass(std::string className, as_object *global)
Definition: Machine.cpp:3224
void ensureBytes(unsigned long needed)
Ensure the requested number of bytes are available for an aligned read in the currently opened tag...
Definition: SWFStream.cpp:50