/
flashevents.h
322 lines (287 loc) · 6.75 KB
/
flashevents.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/**************************************************************************
Lightspark, a free flash player implementation
Copyright (C) 2009,2010 Alessandro Pignotti (a.pignotti@sssup.it)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#ifndef _FLASH_EVENTS_H
#define _FLASH_EVENTS_H
#include "asobjects.h"
#include <string>
#include <semaphore.h>
#include "compat.h"
#undef MOUSE_EVENT
namespace lightspark
{
enum EVENT_TYPE { EVENT=0,BIND_CLASS, SHUTDOWN, SYNC, MOUSE_EVENT, FUNCTION, CONTEXT_INIT, CONSTRUCT_OBJECT, CHANGE_FRAME };
class ASObject;
class ABCContext;
class Event: public ASObject
{
public:
Event():type("Event"),target(NULL){}
Event(const tiny_string& t, ASObject* _t=NULL);
virtual ~Event();
static void sinit(Class_base*);
static void buildTraits(ASObject* o);
ASFUNCTION(_constructor);
ASFUNCTION(_getType);
ASFUNCTION(_getTarget);
virtual EVENT_TYPE getEventType() {return EVENT;}
tiny_string type;
ASObject* target;
};
class KeyboardEvent: public Event
{
public:
KeyboardEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
ASFUNCTION(_constructor);
};
class FocusEvent: public Event
{
public:
FocusEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
ASFUNCTION(_constructor);
};
class FullScreenEvent: public Event
{
public:
FullScreenEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
ASFUNCTION(_constructor);
};
class NetStatusEvent: public Event
{
private:
tiny_string level;
tiny_string code;
public:
NetStatusEvent():Event("netStatus"){}
NetStatusEvent(const tiny_string& l, const tiny_string& c);
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
ASFUNCTION(_constructor);
};
class TextEvent: public Event
{
public:
TextEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
ASFUNCTION(_constructor);
};
class ErrorEvent: public TextEvent
{
public:
ErrorEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
ASFUNCTION(_constructor);
};
class IOErrorEvent: public ErrorEvent
{
public:
IOErrorEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
};
class SecurityErrorEvent: public ErrorEvent
{
public:
SecurityErrorEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
ASFUNCTION(_constructor);
};
class AsyncErrorEvent: public ErrorEvent
{
public:
AsyncErrorEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
ASFUNCTION(_constructor);
};
class ProgressEvent: public Event
{
private:
uint32_t bytesLoaded;
uint32_t bytesTotal;
public:
ProgressEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o);
ASFUNCTION(_constructor);
ASFUNCTION(_getBytesLoaded);
ASFUNCTION(_getBytesTotal);
};
class TimerEvent: public Event
{
public:
TimerEvent():Event("DEPRECATED"){}
TimerEvent(const tiny_string& t):Event(t){};
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
};
class MouseEvent: public Event
{
public:
MouseEvent();
static void sinit(Class_base*);
static void buildTraits(ASObject* o)
{
}
EVENT_TYPE getEventType(){ return MOUSE_EVENT;}
};
class listener
{
friend class EventDispatcher;
private:
IFunction* f;
public:
explicit listener(IFunction* _f):f(_f){};
bool operator==(IFunction* r)
{
return f->isEqual(r);
}
};
class IEventDispatcher: public InterfaceClass
{
public:
static void linkTraits(ASObject* o);
};
class EventDispatcher: public ASObject
{
private:
std::map<tiny_string,std::list<listener> > handlers;
void dumpHandlers();
public:
EventDispatcher();
static void sinit(Class_base*);
static void buildTraits(ASObject* o);
virtual ~EventDispatcher(){}
void handleEvent(Event* e);
bool hasEventListener(const tiny_string& eventName);
ASFUNCTION(_constructor);
ASFUNCTION(addEventListener);
ASFUNCTION(removeEventListener);
ASFUNCTION(dispatchEvent);
ASFUNCTION(_hasEventListener);
};
//Internal events from now on, used to pass data to the execution thread
class BindClassEvent: public Event
{
friend class ABCVm;
private:
ASObject* base;
tiny_string class_name;
public:
BindClassEvent(ASObject* b, const tiny_string& c):
Event("bindClass"),base(b),class_name(c){}
static void sinit(Class_base*);
EVENT_TYPE getEventType(){ return BIND_CLASS;}
};
class ShutdownEvent: public Event
{
public:
ShutdownEvent():Event("shutdownEvent"){}
static void sinit(Class_base*);
EVENT_TYPE getEventType() { return SHUTDOWN; }
};
class FunctionEvent: public Event
{
friend class ABCVm;
private:
IFunction* f;
public:
FunctionEvent(IFunction* _f):Event("functionEvent"),f(_f){}
static void sinit(Class_base*);
EVENT_TYPE getEventType() { return FUNCTION; }
};
class SynchronizationEvent: public Event
{
private:
sem_t s;
public:
SynchronizationEvent():Event("SynchronizationEvent"){sem_init(&s,0,0);}
SynchronizationEvent(const tiny_string& _s):Event(_s){sem_init(&s,0,0);}
static void sinit(Class_base*);
~SynchronizationEvent(){sem_destroy(&s);}
EVENT_TYPE getEventType() { return SYNC; }
void sync()
{
sem_post(&s);
}
void wait()
{
sem_wait(&s);
}
};
class ABCContextInitEvent: public Event
{
friend class ABCVm;
private:
ABCContext* context;
public:
ABCContextInitEvent(ABCContext* c):Event("ABCContextInitEvent"),context(c){}
static void sinit(Class_base*);
EVENT_TYPE getEventType() { return CONTEXT_INIT; }
};
//This event is also synchronous
class ConstructObjectEvent: public SynchronizationEvent
{
friend class ABCVm;
private:
Class_base* _class;
ASObject* _obj;
static void sinit(Class_base*);
public:
ConstructObjectEvent(ASObject* o, Class_base* c):SynchronizationEvent("ConstructObjectEvent"),_class(c),_obj(o){}
EVENT_TYPE getEventType() { return CONSTRUCT_OBJECT; }
};
//Event to change the current frame
class FrameChangeEvent: public Event
{
friend class ABCVm;
private:
int frame;
MovieClip* movieClip;
static void sinit(Class_base*);
public:
FrameChangeEvent(int f, MovieClip* m):Event("FrameChangeEvent"),frame(f),movieClip(m){}
EVENT_TYPE getEventType() { return CHANGE_FRAME; }
};
};
#endif