2 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "ming_utils.h"
26 #define OUTPUT_VERSION 7
27 #define OUTPUT_FILENAME "KeyEventOrder.swf"
29 /// This test checks the event order of key events.
31 /// Known listeners are:
32 /// 1. MovieClips with a defined key event
33 /// 2. Button with a defined key event
34 /// 3. Anything added to Key listeners in ActionScript.
36 /// The test adds objects in this order:
40 /// 3. button1 (responds to 'a')
41 /// 3. o1 (actionscript key listener object)
45 /// 5. button2 (responds to 'a')
46 /// 6. button3 (responds to 'b')
47 /// 3. o2 (actionscript key listener object)
49 /// The test shows that, irrespective of construction order:
50 /// 1. MovieClips are notified first
51 /// 2. ActionScript listeners are notified second.
52 /// 3. Buttons are notified last.
56 /// 1. Only one button action can respond to any key.
58 main(int argc
, char** argv
)
61 SWFMovieClip mc
, dejagnuclip
;
64 SWFDisplayItem it1
, it
, it2
;
67 const char *srcdir
=".";
72 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
77 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
78 SWFMovie_setDimension(mo
, 800, 600);
80 SWFMovie_setRate (mo
, 12.0);
82 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
),
84 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
86 SWFMovie_nextFrame(mo
);
90 "_root.note('Press \"a\" then \"b\"');"
91 "_root.note('Do not press any other keys!');"
94 mc
= newSWFMovieClip();
95 it
= SWFMovie_add(mo
, (SWFBlock
)mc
);
96 SWFDisplayItem_setName(it
, "mc1");
97 SWFDisplayItem_addAction(it
,
98 newSWFAction("trace('mc1'); _root.order += 'mc1,';"),
103 sh1
= make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 0, 0);
104 sh2
= make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 255, 0);
106 br
= SWFButton_addCharacter(bu
, (SWFCharacter
)sh1
, SWFBUTTON_HIT
);
107 SWFButtonRecord_setDepth(br
, 3);
109 br
= SWFButton_addCharacter(bu
, (SWFCharacter
)sh1
, SWFBUTTON_UP
);
110 SWFButtonRecord_setDepth(br
, 4);
112 br
= SWFButton_addCharacter(bu
, (SWFCharacter
)sh2
, SWFBUTTON_OVER
);
113 SWFButtonRecord_setDepth(br
, 5);
115 SWFButton_addAction(bu
,
116 newSWFAction("trace('button1'); _root.order += 'button1,';"),
117 SWFBUTTON_KEYPRESS('a'));
119 it1
= SWFMovie_add(mo
, (SWFBlock
)bu
);
120 SWFDisplayItem_setName(it
, "button1");
122 SWFMovie_add(mo
, newSWFAction(
124 "o1.onKeyDown = function() {"
126 " _root.order += 'o1,';"
128 "Key.addListener(o1);"
131 mc
= newSWFMovieClip();
132 it
= SWFMovie_add(mo
, (SWFBlock
)mc
);
133 SWFDisplayItem_setName(it
, "mc2");
134 SWFDisplayItem_addAction(it
,
135 newSWFAction("trace('mc2'); _root.order += 'mc2,';"),
138 SWFMovie_nextFrame(mo
); // Frame 2
142 sh1
= make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 0, 0);
143 sh2
= make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 255, 0);
145 br
= SWFButton_addCharacter(bu
, (SWFCharacter
)sh1
, SWFBUTTON_HIT
);
146 SWFButtonRecord_setDepth(br
, 3);
148 br
= SWFButton_addCharacter(bu
, (SWFCharacter
)sh1
, SWFBUTTON_UP
);
149 SWFButtonRecord_setDepth(br
, 4);
151 br
= SWFButton_addCharacter(bu
, (SWFCharacter
)sh2
, SWFBUTTON_OVER
);
152 SWFButtonRecord_setDepth(br
, 5);
154 SWFButton_addAction(bu
,
155 newSWFAction("trace('button2'); _root.order += 'button2,';"),
156 SWFBUTTON_KEYPRESS('a'));
158 it2
= SWFMovie_add(mo
, (SWFBlock
)bu
);
159 SWFDisplayItem_setName(it
, "button2");
163 sh1
= make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 0, 0);
164 sh2
= make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 255, 0);
166 br
= SWFButton_addCharacter(bu
, (SWFCharacter
)sh1
, SWFBUTTON_HIT
);
167 SWFButtonRecord_setDepth(br
, 3);
169 br
= SWFButton_addCharacter(bu
, (SWFCharacter
)sh1
, SWFBUTTON_UP
);
170 SWFButtonRecord_setDepth(br
, 4);
172 br
= SWFButton_addCharacter(bu
, (SWFCharacter
)sh2
, SWFBUTTON_OVER
);
173 SWFButtonRecord_setDepth(br
, 5);
175 SWFButton_addAction(bu
,
178 "_root.order += 'button3,';"
181 SWFBUTTON_KEYPRESS('b'));
183 it
= SWFMovie_add(mo
, (SWFBlock
)bu
);
184 SWFDisplayItem_setName(it
, "button3");
186 SWFMovie_add(mo
, newSWFAction(
188 "o2.onKeyDown = function() {"
190 " _root.order += 'o2,';"
192 "Key.addListener(o2);"
196 SWFMovie_nextFrame(mo
);
198 xcheck_equals(mo
, "_root.order",
199 "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'");
201 SWFMovie_nextFrame(mo
);
203 SWFDisplayItem_remove(it2
);
207 "_root.note('Press \"a\" then \"b\" again');"
208 "_root.note('Do not press any other keys!');"
211 SWFMovie_nextFrame(mo
);
213 // Check that removing the second button associated with 'a' does not
214 // remove the key trigger for button2. There's no reason to think it should,
215 // but it could happen if it's implemented badly!
216 check_equals(mo
, "_root.order",
217 "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'");
219 SWFMovie_add(mo
, newSWFAction("stop();"));
222 puts("Saving " OUTPUT_FILENAME
);
223 SWFMovie_save(mo
, OUTPUT_FILENAME
);