move dereferencing out of SwfdecAsValue macros
[swfdec.git] / swfdec / swfdec_text_field_movie_as.c
blob196d8c476320f71453ef2dd4e36dd90c20f69fe8
1 /* Swfdec
2 * Copyright (C) 2007-2008 Benjamin Otte <otte@gnome.org>
3 * 2007 Pekka Lampila <pekka.lampila@iki.fi>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 #include <math.h>
26 #include <string.h>
27 #include <pango/pangocairo.h>
29 #include "swfdec_text_field.h"
30 #include "swfdec_text_field_movie.h"
31 #include "swfdec_as_strings.h"
32 #include "swfdec_debug.h"
33 #include "swfdec_as_native_function.h"
34 #include "swfdec_as_internal.h"
35 #include "swfdec_as_context.h"
36 #include "swfdec_as_object.h"
37 #include "swfdec_as_frame_internal.h"
38 #include "swfdec_internal.h"
39 #include "swfdec_player_internal.h"
41 static SwfdecColor
42 swfdec_text_field_movie_int_to_color (SwfdecAsContext *cx, int value)
44 if (value < 0) {
45 value = (0xffffff + 1) + value % (0xffffff + 1);
46 } else {
47 value = value % (0xffffff + 1);
50 return SWFDEC_COLOR_COMBINE (value >> 16 & 0xff, value >> 8 & 0xff,
51 value & 0xff, 0);
54 // does nothing but calls valueOf
55 static void
56 swfdec_text_field_movie_set_readonly (SwfdecAsContext *cx,
57 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
58 SwfdecAsValue *ret)
60 SwfdecTextFieldMovie *text;
62 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
64 if (argc > 0)
65 swfdec_as_value_to_number (cx, &argv[0]);
69 * Native properties: Text
71 static void
72 swfdec_text_field_movie_do_get_text (SwfdecAsContext *cx,
73 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
74 SwfdecAsValue *ret)
76 SwfdecTextFieldMovie *text;
78 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
80 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_text_field_movie_get_text (text));
83 static void
84 swfdec_text_field_movie_do_set_text (SwfdecAsContext *cx,
85 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
86 SwfdecAsValue *ret)
88 SwfdecTextFieldMovie *text;
89 const char *value;
91 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "s", &value);
93 swfdec_text_field_movie_set_text (text, value, FALSE);
94 swfdec_text_field_movie_update_layout (text);
96 if (text->variable != NULL) {
97 if (text->html) {
98 swfdec_text_field_movie_set_listen_variable_text (text,
99 swfdec_text_field_movie_get_html_text (text));
100 } else {
101 swfdec_text_field_movie_set_listen_variable_text (text,
102 swfdec_text_field_movie_get_text (text));
107 static void
108 swfdec_text_field_movie_get_html (SwfdecAsContext *cx, SwfdecAsObject *object,
109 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
111 SwfdecTextFieldMovie *text;
113 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
115 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, text->html);
118 static void
119 swfdec_text_field_movie_set_html (SwfdecAsContext *cx, SwfdecAsObject *object,
120 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
122 SwfdecTextFieldMovie *text;
123 gboolean value;
125 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
127 swfdec_as_value_to_number (cx, &argv[0]);
129 text->html = value;
131 // FIXME: resize? invalidate?
134 static void
135 swfdec_text_field_movie_get_htmlText (SwfdecAsContext *cx,
136 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
137 SwfdecAsValue *ret)
139 SwfdecTextFieldMovie *text;
141 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
143 if (text->style_sheet_input) {
144 SWFDEC_AS_VALUE_SET_STRING (ret, text->style_sheet_input);
145 } else if (text->html) {
146 SWFDEC_AS_VALUE_SET_STRING (ret,
147 swfdec_text_field_movie_get_html_text (text));
148 } else {
149 SWFDEC_AS_VALUE_SET_STRING (ret,
150 swfdec_text_field_movie_get_text (text));
154 static void
155 swfdec_text_field_movie_set_htmlText (SwfdecAsContext *cx,
156 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
157 SwfdecAsValue *ret)
159 SwfdecTextFieldMovie *text;
160 const char *value;
162 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "s", &value);
164 swfdec_text_field_movie_set_text (text, value, text->html);
166 if (text->variable != NULL) {
167 if (text->html) {
168 swfdec_text_field_movie_set_listen_variable_text (text,
169 swfdec_text_field_movie_get_html_text (text));
170 } else {
171 swfdec_text_field_movie_set_listen_variable_text (text,
172 swfdec_text_field_movie_get_text (text));
177 static void
178 swfdec_text_field_movie_get_length (SwfdecAsContext *cx, SwfdecAsObject *object,
179 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
181 SwfdecTextFieldMovie *text;
183 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
185 swfdec_as_value_set_integer (cx, ret, g_utf8_strlen (swfdec_text_buffer_get_text (text->text), -1));
189 * Native properties: Input
191 static void
192 swfdec_text_field_movie_get_condenseWhite (SwfdecAsContext *cx,
193 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
194 SwfdecAsValue *ret)
196 SwfdecTextFieldMovie *text;
198 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
200 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, text->condense_white);
203 static void
204 swfdec_text_field_movie_set_condenseWhite (SwfdecAsContext *cx,
205 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
206 SwfdecAsValue *ret)
208 SwfdecTextFieldMovie *text;
209 gboolean value;
211 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
213 swfdec_as_value_to_number (cx, &argv[0]);
215 text->condense_white = value;
218 static void
219 swfdec_text_field_movie_get_maxChars (SwfdecAsContext *cx,
220 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
221 SwfdecAsValue *ret)
223 SwfdecTextFieldMovie *text;
225 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
227 if (text->max_chars != 0) {
228 swfdec_as_value_set_integer (cx, ret, text->max_chars);
229 } else {
230 SWFDEC_AS_VALUE_SET_NULL (ret);
234 static void
235 swfdec_text_field_movie_set_maxChars (SwfdecAsContext *cx,
236 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
237 SwfdecAsValue *ret)
239 SwfdecTextFieldMovie *text;
241 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
243 if (argc < 1)
244 return;
246 swfdec_as_value_to_number (cx, &argv[0]);
247 text->max_chars = swfdec_as_value_to_integer (cx, &argv[0]);
250 static void
251 swfdec_text_field_movie_get_multiline (SwfdecAsContext *cx,
252 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
253 SwfdecAsValue *ret)
255 SwfdecTextFieldMovie *text;
257 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
259 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, text->multiline);
262 static void
263 swfdec_text_field_movie_set_multiline (SwfdecAsContext *cx,
264 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
265 SwfdecAsValue *ret)
267 SwfdecTextFieldMovie *text;
268 gboolean value;
270 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
272 swfdec_as_value_to_number (cx, &argv[0]);
274 text->multiline = value;
277 static void
278 swfdec_text_field_movie_get_restrict (SwfdecAsContext *cx,
279 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
280 SwfdecAsValue *ret)
282 SwfdecTextFieldMovie *text;
284 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
286 if (text->restrict_ != NULL) {
287 SWFDEC_AS_VALUE_SET_STRING (ret, text->restrict_);
288 } else {
289 SWFDEC_AS_VALUE_SET_NULL (ret);
293 static void
294 swfdec_text_field_movie_set_restrict (SwfdecAsContext *cx,
295 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
296 SwfdecAsValue *ret)
298 SwfdecTextFieldMovie *text;
299 const char *value;
301 if (argc > 0)
302 swfdec_as_value_to_number (cx, &argv[0]);
304 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "s", &value);
306 if (text->restrict_ == NULL && value == SWFDEC_AS_STR_EMPTY)
307 return;
309 if (SWFDEC_AS_VALUE_IS_UNDEFINED (*&argv[0]) ||
310 SWFDEC_AS_VALUE_IS_NULL (*&argv[0])) {
311 text->restrict_ = NULL;
312 } else {
313 text->restrict_ = value;
317 static void
318 swfdec_text_field_movie_get_selectable (SwfdecAsContext *cx,
319 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
320 SwfdecAsValue *ret)
322 SwfdecTextFieldMovie *text;
324 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
326 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, text->selectable);
329 static void
330 swfdec_text_field_movie_set_selectable (SwfdecAsContext *cx,
331 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
332 SwfdecAsValue *ret)
334 SwfdecTextFieldMovie *text;
335 gboolean value;
337 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
339 swfdec_as_value_to_number (cx, &argv[0]);
341 text->selectable = value;
343 // FIXME: invalidate
346 static void
347 swfdec_text_field_movie_do_get_type (SwfdecAsContext *cx,
348 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
349 SwfdecAsValue *ret)
351 SwfdecTextFieldMovie *text;
353 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
355 if (text->editable) {
356 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_input);
357 } else {
358 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_dynamic);
362 static void
363 swfdec_text_field_movie_do_set_type (SwfdecAsContext *cx,
364 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
365 SwfdecAsValue *ret)
367 SwfdecTextFieldMovie *text;
368 const char *value;
370 if (argc > 0)
371 swfdec_as_value_to_number (cx, &argv[0]);
373 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "s", &value);
375 if (!g_strcasecmp (value, SWFDEC_AS_STR_input)) {
376 text->editable = TRUE;
377 } else if (!g_strcasecmp (value, SWFDEC_AS_STR_dynamic)) {
378 text->editable = FALSE;
380 /* else ignore */
382 // FIXME: invalidate
385 static void
386 swfdec_text_field_movie_do_get_variable (SwfdecAsContext *cx,
387 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
388 SwfdecAsValue *ret)
390 SwfdecTextFieldMovie *text;
392 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
394 if (text->variable) {
395 SWFDEC_AS_VALUE_SET_STRING (ret, text->variable);
396 } else {
397 SWFDEC_AS_VALUE_SET_NULL (ret);
401 static void
402 swfdec_text_field_movie_do_set_variable (SwfdecAsContext *cx,
403 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
404 SwfdecAsValue *ret)
406 SwfdecTextFieldMovie *text;
407 const char *value;
409 if (argc > 0)
410 swfdec_as_value_to_number (cx, &argv[0]);
412 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "s", &value);
414 if (SWFDEC_AS_VALUE_IS_UNDEFINED (*&argv[0]) ||
415 SWFDEC_AS_VALUE_IS_NULL (*&argv[0]) || value == SWFDEC_AS_STR_EMPTY) {
416 value = NULL;
419 swfdec_text_field_movie_set_listen_variable (text, value);
423 * Native properties: Info
425 static void
426 swfdec_text_field_movie_get_textHeight (SwfdecAsContext *cx,
427 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
428 SwfdecAsValue *ret)
430 SwfdecTextFieldMovie *text;
432 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
434 swfdec_movie_update (SWFDEC_MOVIE (text));
435 swfdec_text_field_movie_update_layout (text);
436 swfdec_as_value_set_integer (cx, ret, floor (text->layout_height *
437 text->from_layout.yy / SWFDEC_TWIPS_SCALE_FACTOR));
440 static void
441 swfdec_text_field_movie_get_textWidth (SwfdecAsContext *cx,
442 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
443 SwfdecAsValue *ret)
445 SwfdecTextFieldMovie *text;
447 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
449 swfdec_movie_update (SWFDEC_MOVIE (text));
450 swfdec_text_field_movie_update_layout (text);
451 swfdec_as_value_set_integer (cx, ret, floor (text->layout_width *
452 text->from_layout.xx / SWFDEC_TWIPS_SCALE_FACTOR));
456 * Native properties: Background & border
458 static void
459 swfdec_text_field_movie_get_background (SwfdecAsContext *cx,
460 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
461 SwfdecAsValue *ret)
463 SwfdecTextFieldMovie *text;
465 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
467 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, text->background);
470 static void
471 swfdec_text_field_movie_set_background (SwfdecAsContext *cx,
472 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
473 SwfdecAsValue *ret)
475 SwfdecTextFieldMovie *text;
476 gboolean value;
478 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
480 swfdec_as_value_to_number (cx, &argv[0]);
482 if (text->background != value) {
483 text->background = value;
484 swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
488 static void
489 swfdec_text_field_movie_get_backgroundColor (SwfdecAsContext *cx,
490 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
491 SwfdecAsValue *ret)
493 SwfdecTextFieldMovie *text;
495 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
497 swfdec_as_value_set_number (cx, ret,
498 SWFDEC_COLOR_RED (text->background_color) << 16 |
499 SWFDEC_COLOR_GREEN (text->background_color) << 8 |
500 SWFDEC_COLOR_BLUE (text->background_color));
503 static void
504 swfdec_text_field_movie_set_backgroundColor (SwfdecAsContext *cx,
505 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
506 SwfdecAsValue *ret)
508 SwfdecTextFieldMovie *text;
509 int value;
510 SwfdecColor color;
512 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
514 color = swfdec_text_field_movie_int_to_color (cx, value);
515 if (text->background_color != color) {
516 text->background_color = color;
517 swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
521 static void
522 swfdec_text_field_movie_get_border (SwfdecAsContext *cx,
523 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
524 SwfdecAsValue *ret)
526 SwfdecTextFieldMovie *text;
528 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
530 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, text->border);
533 static void
534 swfdec_text_field_movie_set_border (SwfdecAsContext *cx,
535 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
536 SwfdecAsValue *ret)
538 SwfdecTextFieldMovie *text;
539 gboolean value;
541 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
543 swfdec_as_value_to_number (cx, &argv[0]);
545 if (text->border != value) {
546 text->border = value;
547 swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
551 static void
552 swfdec_text_field_movie_get_borderColor (SwfdecAsContext *cx,
553 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
554 SwfdecAsValue *ret)
556 SwfdecTextFieldMovie *text;
558 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
561 swfdec_as_value_set_number (cx, ret,
562 SWFDEC_COLOR_RED (text->border_color) << 16 |
563 SWFDEC_COLOR_GREEN (text->border_color) << 8 |
564 SWFDEC_COLOR_BLUE (text->border_color));
567 static void
568 swfdec_text_field_movie_set_borderColor (SwfdecAsContext *cx,
569 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
570 SwfdecAsValue *ret)
572 SwfdecTextFieldMovie *text;
573 int value;
574 SwfdecColor color;
576 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
578 color = swfdec_text_field_movie_int_to_color (cx, value);
579 if (text->border_color != color) {
580 text->border_color = color;
581 swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
586 * Native properties: Scrolling
588 static void
589 swfdec_text_field_movie_get_bottomScroll (SwfdecAsContext *cx,
590 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
591 SwfdecAsValue *ret)
593 SwfdecTextFieldMovie *text;
595 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
597 swfdec_as_value_set_number (cx, ret, text->scroll + text->lines_visible);
600 static void
601 swfdec_text_field_movie_do_get_hscroll (SwfdecAsContext *cx,
602 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
603 SwfdecAsValue *ret)
605 SwfdecTextFieldMovie *text;
607 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
609 swfdec_as_value_set_number (cx, ret, text->hscroll);
612 static void
613 swfdec_text_field_movie_do_set_hscroll (SwfdecAsContext *cx,
614 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
615 SwfdecAsValue *ret)
617 SwfdecTextFieldMovie *text;
618 int value;
620 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
622 value = CLAMP (value, 0, (int) swfdec_text_field_movie_get_hscroll_max (text));
623 if ((guint) value != text->hscroll) {
624 swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
625 text->hscroll = value;
626 swfdec_text_field_movie_emit_onScroller (text);
630 static void
631 swfdec_text_field_movie_get_maxhscroll (SwfdecAsContext *cx,
632 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
633 SwfdecAsValue *ret)
635 SwfdecTextFieldMovie *text;
637 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
639 swfdec_as_value_set_integer (cx, ret, swfdec_text_field_movie_get_hscroll_max (text));
642 static void
643 swfdec_text_field_movie_get_maxscroll (SwfdecAsContext *cx,
644 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
645 SwfdecAsValue *ret)
647 SwfdecTextFieldMovie *text;
649 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
651 swfdec_as_value_set_number (cx, ret, text->scroll_max + 1);
654 static void
655 swfdec_text_field_movie_get_mouseWheelEnabled (SwfdecAsContext *cx,
656 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
657 SwfdecAsValue *ret)
659 SwfdecTextFieldMovie *text;
661 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
663 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, text->mouse_wheel_enabled);
666 static void
667 swfdec_text_field_movie_set_mouseWheelEnabled (SwfdecAsContext *cx,
668 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
669 SwfdecAsValue *ret)
671 SwfdecTextFieldMovie *text;
672 gboolean value;
674 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
676 swfdec_as_value_to_number (cx, &argv[0]);
678 text->mouse_wheel_enabled = value;
681 static void
682 swfdec_text_field_movie_do_get_scroll (SwfdecAsContext *cx,
683 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
684 SwfdecAsValue *ret)
686 SwfdecTextFieldMovie *text;
688 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
690 swfdec_as_value_set_number (cx, ret, text->scroll + 1);
693 static void
694 swfdec_text_field_movie_do_set_scroll (SwfdecAsContext *cx,
695 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
696 SwfdecAsValue *ret)
698 SwfdecTextFieldMovie *text;
699 int value;
701 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
703 if ((guint) value != text->scroll + 1) {
704 swfdec_text_field_movie_update_layout (text);
705 value = CLAMP (value - 1, 0, (int) text->scroll_max);
706 text->scroll = value;
707 swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
708 swfdec_text_field_movie_emit_onScroller (text);
713 * Native properties: Display
715 static void
716 swfdec_text_field_movie_get_autoSize (SwfdecAsContext *cx,
717 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
718 SwfdecAsValue *ret)
720 SwfdecTextFieldMovie *text;
722 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
724 switch (text->auto_size) {
725 case SWFDEC_AUTO_SIZE_NONE:
726 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_none);
727 break;
728 case SWFDEC_AUTO_SIZE_LEFT:
729 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_left);
730 break;
731 case SWFDEC_AUTO_SIZE_RIGHT:
732 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_right);
733 break;
734 case SWFDEC_AUTO_SIZE_CENTER:
735 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_center);
736 break;
737 default:
738 g_assert_not_reached ();
742 static void
743 swfdec_text_field_movie_set_autoSize (SwfdecAsContext *cx,
744 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
745 SwfdecAsValue *ret)
747 SwfdecTextFieldMovie *text;
748 const char *s;
750 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
752 if (argc < 1)
753 return;
755 if (SWFDEC_AS_VALUE_IS_BOOLEAN (*&argv[0])) {
756 if (SWFDEC_AS_VALUE_GET_BOOLEAN (*&argv[0])) {
757 text->auto_size = SWFDEC_AUTO_SIZE_LEFT;
758 } else {
759 text->auto_size = SWFDEC_AUTO_SIZE_NONE;
761 } else {
762 swfdec_as_value_to_number (cx, &argv[0]);
763 s = swfdec_as_value_to_string (cx, argv[0]);
765 if (!g_ascii_strcasecmp (s, "left")) {
766 text->auto_size = SWFDEC_AUTO_SIZE_LEFT;
767 } else if (!g_ascii_strcasecmp (s, "right")) {
768 text->auto_size = SWFDEC_AUTO_SIZE_RIGHT;
769 } else if (!g_ascii_strcasecmp (s, "center")) {
770 text->auto_size = SWFDEC_AUTO_SIZE_CENTER;
771 } else {
772 text->auto_size = SWFDEC_AUTO_SIZE_NONE;
777 static void
778 swfdec_text_field_movie_get_password (SwfdecAsContext *cx,
779 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
780 SwfdecAsValue *ret)
782 SwfdecTextFieldMovie *text;
784 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
786 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, swfdec_text_layout_get_password (text->layout));
789 static void
790 swfdec_text_field_movie_set_password (SwfdecAsContext *cx,
791 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
792 SwfdecAsValue *ret)
794 SwfdecTextFieldMovie *text;
795 gboolean value;
797 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
799 swfdec_as_value_to_number (cx, &argv[0]);
801 swfdec_text_layout_set_password (text->layout, value);
802 swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
805 static void
806 swfdec_text_field_movie_get_wordWrap (SwfdecAsContext *cx,
807 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
808 SwfdecAsValue *ret)
810 SwfdecTextFieldMovie *text;
812 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
814 SWFDEC_AS_VALUE_SET_BOOLEAN (ret,
815 swfdec_text_layout_get_word_wrap (text->layout));
818 static void
819 swfdec_text_field_movie_set_wordWrap (SwfdecAsContext *cx,
820 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
821 SwfdecAsValue *ret)
823 SwfdecTextFieldMovie *text;
824 gboolean value;
826 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
828 swfdec_as_value_to_number (cx, &argv[0]);
830 swfdec_text_layout_set_word_wrap (text->layout, value);
834 * Native properties: Format
836 static void
837 swfdec_text_field_movie_get_embedFonts (SwfdecAsContext *cx,
838 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
839 SwfdecAsValue *ret)
841 SwfdecTextFieldMovie *text;
843 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
845 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, text->embed_fonts);
848 static void
849 swfdec_text_field_movie_set_embedFonts (SwfdecAsContext *cx,
850 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
851 SwfdecAsValue *ret)
853 SwfdecTextFieldMovie *text;
854 gboolean value;
856 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "b", &value);
858 swfdec_as_value_to_number (cx, &argv[0]);
860 if (!text->embed_fonts && value)
861 SWFDEC_FIXME ("Using embed fonts in TextField not supported");
863 text->embed_fonts = value;
865 // FIXME: resize
868 static void
869 swfdec_text_field_movie_get_styleSheet (SwfdecAsContext *cx,
870 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
871 SwfdecAsValue *ret)
873 SwfdecTextFieldMovie *text;
875 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
877 if (text->style_sheet != NULL) {
878 SWFDEC_AS_VALUE_SET_OBJECT (ret, text->style_sheet);
879 } else {
880 SWFDEC_AS_VALUE_SET_UNDEFINED (ret);
884 static void
885 swfdec_text_field_movie_style_sheet_update (SwfdecTextFieldMovie *text)
887 if (text->style_sheet_input)
888 swfdec_text_field_movie_set_text (text, text->style_sheet_input, TRUE);
891 static void
892 swfdec_text_field_movie_set_styleSheet (SwfdecAsContext *cx,
893 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
894 SwfdecAsValue *ret)
896 SwfdecTextFieldMovie *text;
897 SwfdecAsObject *value;
899 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
901 if (argc < 1)
902 return;
904 swfdec_as_value_to_number (cx, &argv[0]);
906 if (SWFDEC_AS_VALUE_IS_OBJECT (*&argv[0])) {
907 value = SWFDEC_AS_VALUE_GET_OBJECT (*&argv[0]);
908 } else {
909 value = NULL;
912 if (text->style_sheet == value)
913 return;
915 if (text->style_sheet != NULL && SWFDEC_IS_STYLE_SHEET (text->style_sheet->relay)) {
916 g_signal_handlers_disconnect_by_func (text->style_sheet->relay,
917 swfdec_text_field_movie_style_sheet_update, text);
918 g_object_remove_weak_pointer (G_OBJECT (text->style_sheet->relay),
919 (gpointer) &text->style_sheet);
922 text->style_sheet = value;
924 if (value && SWFDEC_IS_STYLE_SHEET (value->relay)) {
925 g_signal_connect_swapped (value->relay, "update",
926 G_CALLBACK (swfdec_text_field_movie_style_sheet_update), text);
927 g_object_add_weak_pointer (G_OBJECT (text->style_sheet->relay),
928 (gpointer) &text->style_sheet);
930 swfdec_text_field_movie_style_sheet_update (text);
934 static void
935 swfdec_text_field_movie_get_textColor (SwfdecAsContext *cx,
936 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
937 SwfdecAsValue *ret)
939 SwfdecTextFieldMovie *text;
941 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
943 swfdec_as_value_set_number (cx, ret,
944 swfdec_text_buffer_get_default_attributes (text->text)->color);
947 // This doesn't work the same way as TextFormat's color setting
948 static void
949 swfdec_text_field_movie_set_textColor (SwfdecAsContext *cx,
950 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
951 SwfdecAsValue *ret)
953 SwfdecTextFieldMovie *text;
954 int value;
956 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
958 /* FIXME: don't access private variables, you lazy hacker! */
959 text->text->default_attributes.color = swfdec_text_field_movie_int_to_color (cx, value);
962 SWFDEC_AS_NATIVE (104, 300, swfdec_text_field_movie_get_gridFitType)
963 void
964 swfdec_text_field_movie_get_gridFitType (SwfdecAsContext *cx,
965 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
966 SwfdecAsValue *ret)
968 SWFDEC_STUB ("TextField.gridFitType (get)");
971 SWFDEC_AS_NATIVE (104, 301, swfdec_text_field_movie_set_gridFitType)
972 void
973 swfdec_text_field_movie_set_gridFitType (SwfdecAsContext *cx,
974 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
975 SwfdecAsValue *ret)
977 SWFDEC_STUB ("TextField.gridFitType (set)");
980 SWFDEC_AS_NATIVE (104, 302, swfdec_text_field_movie_get_antiAliasType)
981 void
982 swfdec_text_field_movie_get_antiAliasType (SwfdecAsContext *cx,
983 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
984 SwfdecAsValue *ret)
986 SWFDEC_STUB ("TextField.antiAliasType (get)");
989 SWFDEC_AS_NATIVE (104, 303, swfdec_text_field_movie_set_antiAliasType)
990 void
991 swfdec_text_field_movie_set_antiAliasType (SwfdecAsContext *cx,
992 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
993 SwfdecAsValue *ret)
995 SWFDEC_STUB ("TextField.antiAliasType (set)");
998 SWFDEC_AS_NATIVE (104, 304, swfdec_text_field_movie_get_thickness)
999 void
1000 swfdec_text_field_movie_get_thickness (SwfdecAsContext *cx,
1001 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1002 SwfdecAsValue *ret)
1004 SWFDEC_STUB ("TextField.thickness (get)");
1007 SWFDEC_AS_NATIVE (104, 305, swfdec_text_field_movie_set_thickness)
1008 void
1009 swfdec_text_field_movie_set_thickness (SwfdecAsContext *cx,
1010 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1011 SwfdecAsValue *ret)
1013 SWFDEC_STUB ("TextField.thickness (set)");
1016 SWFDEC_AS_NATIVE (104, 306, swfdec_text_field_movie_get_sharpness)
1017 void
1018 swfdec_text_field_movie_get_sharpness (SwfdecAsContext *cx,
1019 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1020 SwfdecAsValue *ret)
1022 SWFDEC_STUB ("TextField.sharpness (get)");
1025 SWFDEC_AS_NATIVE (104, 307, swfdec_text_field_movie_set_sharpness)
1026 void
1027 swfdec_text_field_movie_set_sharpness (SwfdecAsContext *cx,
1028 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1029 SwfdecAsValue *ret)
1031 SWFDEC_STUB ("TextField.sharpness (set)");
1034 SWFDEC_AS_NATIVE (104, 308, swfdec_text_field_movie_get_filters)
1035 void
1036 swfdec_text_field_movie_get_filters (SwfdecAsContext *cx,
1037 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1038 SwfdecAsValue *ret)
1040 SWFDEC_STUB ("TextField.filters (get)");
1043 SWFDEC_AS_NATIVE (104, 309, swfdec_text_field_movie_set_filters)
1044 void
1045 swfdec_text_field_movie_set_filters (SwfdecAsContext *cx,
1046 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1047 SwfdecAsValue *ret)
1049 SWFDEC_STUB ("TextField.filters (set)");
1053 * Native functions
1055 SWFDEC_AS_NATIVE (104, 104, swfdec_text_field_movie_getNewTextFormat)
1056 void
1057 swfdec_text_field_movie_getNewTextFormat (SwfdecAsContext *cx,
1058 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1059 SwfdecAsValue *ret)
1061 SwfdecTextFieldMovie *text;
1062 SwfdecTextFormat *format;
1064 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1066 format = swfdec_text_format_new (cx);
1068 swfdec_text_attributes_copy (&format->attr,
1069 swfdec_text_buffer_get_default_attributes (text->text),
1070 SWFDEC_TEXT_ATTRIBUTES_MASK);
1071 format->values_set = SWFDEC_TEXT_ATTRIBUTES_MASK;
1073 SWFDEC_AS_VALUE_SET_OBJECT (ret, swfdec_as_relay_get_as_object (SWFDEC_AS_RELAY (format)));
1076 SWFDEC_AS_NATIVE (104, 105, swfdec_text_field_movie_setNewTextFormat)
1077 void
1078 swfdec_text_field_movie_setNewTextFormat (SwfdecAsContext *cx,
1079 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1080 SwfdecAsValue *ret)
1082 SwfdecTextFieldMovie *text;
1083 SwfdecAsObject *format_object;
1084 SwfdecTextFormat *format;
1086 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "o", &format_object);
1088 if (!SWFDEC_IS_TEXT_FORMAT (format_object->relay))
1089 return;
1091 format = SWFDEC_TEXT_FORMAT (format_object->relay);
1092 swfdec_text_buffer_set_default_attributes (text->text,
1093 &format->attr, format->values_set);
1096 SWFDEC_AS_NATIVE (104, 102, swfdec_text_field_movie_setTextFormat)
1097 void
1098 swfdec_text_field_movie_setTextFormat (SwfdecAsContext *cx,
1099 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1100 SwfdecAsValue *ret)
1102 SwfdecTextFieldMovie *text;
1103 SwfdecTextFormat *format;
1104 int val;
1105 guint i;
1106 const char *string;
1107 gsize start, end, length;
1109 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1111 if (argc < 1)
1112 return;
1114 string = swfdec_text_buffer_get_text (text->text);
1115 length = g_utf8_strlen (string, -1);
1116 if (argc <= 1) {
1117 start = 0;
1118 end = length;
1119 i = 0;
1120 } else {
1121 val = swfdec_as_value_to_integer (cx, &argv[0]);
1122 start = MAX (val, 0);
1123 start = MIN (start, length);
1124 if (argc <= 2) {
1125 if (val < 0) { // fail
1126 return;
1127 } else {
1128 end = MIN (start + 1, length);
1130 i = 1;
1131 } else {
1132 val = swfdec_as_value_to_integer (cx, &argv[1]);
1133 end = MAX (val, 0);
1134 end = CLAMP (end, start, length);
1135 i = 2;
1138 if (start == end)
1139 return;
1141 if (!SWFDEC_AS_VALUE_IS_OBJECT (*&argv[i]))
1142 return;
1143 if (!SWFDEC_IS_TEXT_FORMAT (SWFDEC_AS_VALUE_GET_OBJECT (*&argv[i])->relay))
1144 return;
1146 format = SWFDEC_TEXT_FORMAT (SWFDEC_AS_VALUE_GET_OBJECT (*&argv[i])->relay);
1147 start = g_utf8_offset_to_pointer (string, start) - string;
1148 end = g_utf8_offset_to_pointer (string, end) - string;
1150 swfdec_text_buffer_set_attributes (text->text, start, end - start,
1151 &format->attr, format->values_set);
1153 swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
1154 /* special case: update the max values, not the current values */
1155 /* swfdec_text_field_movie_update_layout (text); */
1156 /* FIXME: emit onScroller? */
1157 text->layout_width = swfdec_text_layout_get_width (text->layout);
1158 text->layout_height = swfdec_text_layout_get_height (text->layout);
1159 text->scroll_max = swfdec_text_layout_get_n_rows (text->layout)
1160 - swfdec_text_layout_get_visible_rows_end (text->layout,
1161 text->layout_area.height);
1164 SWFDEC_AS_NATIVE (104, 101, swfdec_text_field_movie_getTextFormat)
1165 void
1166 swfdec_text_field_movie_getTextFormat (SwfdecAsContext *cx,
1167 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1168 SwfdecAsValue *ret)
1170 SwfdecTextFieldMovie *text;
1171 SwfdecTextFormat *format;
1172 int val;
1173 const char *string;
1174 guint mask;
1175 const SwfdecTextAttributes *attr;
1176 gsize start, end, length;
1178 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1180 string = swfdec_text_buffer_get_text (text->text);
1181 length = g_utf8_strlen (string, -1);
1183 format = swfdec_text_format_new (cx);
1184 SWFDEC_AS_VALUE_SET_OBJECT (ret, swfdec_as_relay_get_as_object (SWFDEC_AS_RELAY (format)));
1186 if (argc == 0) {
1187 start = 0;
1188 end = length;
1189 } else {
1190 val = swfdec_as_value_to_integer (cx, &argv[0]);
1191 start = MAX (val, 0);
1192 start = MIN (start, length);
1193 if (argc == 1) {
1194 if (val < 0) { // fail
1195 return;
1196 } else {
1197 end = MIN (start + 1, length);
1199 } else {
1200 val = swfdec_as_value_to_integer (cx, &argv[1]);
1201 end = MAX (val, 0);
1202 end = CLAMP (end, start, length);
1206 if (start == end)
1207 return;
1209 start = g_utf8_offset_to_pointer (string, start) - string;
1210 end = g_utf8_offset_to_pointer (string, end) - string;
1211 mask = swfdec_text_buffer_get_unique (text->text, start, end - start);
1212 attr = swfdec_text_buffer_get_attributes (text->text, start);
1213 swfdec_text_attributes_copy (&format->attr, attr, mask);
1214 format->values_set = mask;
1217 SWFDEC_AS_NATIVE (104, 100, swfdec_text_field_movie_replaceSel)
1218 void
1219 swfdec_text_field_movie_replaceSel (SwfdecAsContext *cx,
1220 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1221 SwfdecAsValue *ret)
1223 SWFDEC_STUB ("TextField.replaceSel");
1226 SWFDEC_AS_NATIVE (104, 107, swfdec_text_field_movie_replaceText)
1227 void
1228 swfdec_text_field_movie_replaceText (SwfdecAsContext *cx,
1229 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1230 SwfdecAsValue *ret)
1232 SwfdecTextFieldMovie *text;
1233 int start_index, end_index;
1234 const char *string, *str;
1235 gsize start, end;
1237 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "iis", &start_index,
1238 &end_index, &str);
1240 if (start_index < 0)
1241 return;
1242 if (end_index < start_index)
1243 return;
1244 /* if there was a style sheet set when setting the text, modifications are
1245 * not allowed */
1246 if (text->style_sheet_input)
1247 return;
1249 string = swfdec_text_buffer_get_text (text->text);
1250 start = end = g_utf8_strlen (string, -1);
1251 start = MIN ((gsize) start_index, start);
1252 end = MIN ((gsize) end_index, end);
1253 start = g_utf8_offset_to_pointer (string, start) - string;
1254 end = g_utf8_offset_to_pointer (string, end) - string;
1256 /* anyone explain to me why Flash 7 has this special case plz */
1257 if (end > start && (str != SWFDEC_AS_STR_EMPTY || cx->version != 7))
1258 swfdec_text_buffer_delete_text (text->text, start, end - start);
1260 swfdec_text_buffer_insert_text (text->text, start, str);
1261 /* yes, modifying text changes the default format */
1262 swfdec_text_buffer_set_default_attributes (text->text,
1263 swfdec_text_buffer_get_attributes (text->text, 0),
1264 SWFDEC_TEXT_ATTRIBUTES_MASK);
1267 // static
1268 SWFDEC_AS_NATIVE (104, 201, swfdec_text_field_movie_getFontList)
1269 void
1270 swfdec_text_field_movie_getFontList (SwfdecAsContext *cx,
1271 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1272 SwfdecAsValue *ret)
1274 SwfdecAsObject *array;
1275 SwfdecAsValue val;
1276 PangoFontFamily **families;
1277 int i, n_families;
1279 pango_font_map_list_families (pango_cairo_font_map_get_default (),
1280 &families, &n_families);
1282 array = swfdec_as_array_new (cx);
1283 for (i = 0; i < n_families; i++) {
1284 SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (cx,
1285 pango_font_family_get_name (families[i])));
1286 swfdec_as_array_push (array, &val);
1288 SWFDEC_AS_VALUE_SET_STRING (&val, SWFDEC_AS_STR_Sans);
1289 swfdec_as_array_push (array, &val);
1290 SWFDEC_AS_VALUE_SET_STRING (&val, SWFDEC_AS_STR_Serif);
1291 swfdec_as_array_push (array, &val);
1292 SWFDEC_AS_VALUE_SET_STRING (&val, SWFDEC_AS_STR_Monospace);
1293 swfdec_as_array_push (array, &val);
1295 g_free (families);
1297 SWFDEC_AS_VALUE_SET_OBJECT (ret, array);
1300 SWFDEC_AS_NATIVE (104, 106, swfdec_text_field_movie_getDepth)
1301 void
1302 swfdec_text_field_movie_getDepth (SwfdecAsContext *cx, SwfdecAsObject *object,
1303 guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
1305 SwfdecTextFieldMovie *text;
1307 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1309 swfdec_as_value_set_integer (cx, rval, SWFDEC_MOVIE (text)->depth);
1312 SWFDEC_AS_NATIVE (104, 103, swfdec_text_field_movie_removeTextField)
1313 void
1314 swfdec_text_field_movie_removeTextField (SwfdecAsContext *cx,
1315 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1316 SwfdecAsValue *rval)
1318 SwfdecTextFieldMovie *text;
1319 SwfdecMovie *movie;
1321 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1323 movie = SWFDEC_MOVIE (text);
1324 if (swfdec_depth_classify (movie->depth) == SWFDEC_DEPTH_CLASS_DYNAMIC)
1325 swfdec_movie_remove (movie);
1329 * Creating TextFields
1331 SWFDEC_AS_NATIVE (104, 200, swfdec_text_field_movie_createTextField)
1332 void
1333 swfdec_text_field_movie_createTextField (SwfdecAsContext *cx,
1334 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1335 SwfdecAsValue *rval)
1337 SwfdecMovie *movie, *parent;
1338 SwfdecTextField *edittext;
1339 int depth, x, y, width, height;
1340 const char *name;
1341 SwfdecAsFunction *fun;
1342 SwfdecAsObject *fun_object, *o;
1343 SwfdecAsValue val;
1345 SWFDEC_AS_CHECK (SWFDEC_TYPE_MOVIE, &parent, "siiiii", &name, &depth, &x, &y, &width, &height);
1346 width = ABS (width);
1347 height = ABS (height);
1349 edittext = g_object_new (SWFDEC_TYPE_TEXT_FIELD, NULL);
1350 edittext->html = FALSE;
1351 edittext->editable = FALSE;
1352 edittext->password = FALSE;
1353 edittext->selectable = TRUE;
1354 edittext->font = NULL; // FIXME
1355 edittext->word_wrap = FALSE;
1356 edittext->multiline = FALSE;
1357 edittext->auto_size = SWFDEC_AUTO_SIZE_NONE;
1358 edittext->border = FALSE;
1359 edittext->size = 240; // FIXME: Correct?
1361 edittext->input = NULL;
1362 edittext->variable = NULL;
1363 edittext->color = 0;
1364 edittext->align = SWFDEC_TEXT_ALIGN_LEFT;
1365 edittext->left_margin = 0;
1366 edittext->right_margin = 0;
1367 edittext->indent = 0;
1368 edittext->leading = 0;
1370 SWFDEC_GRAPHIC (edittext)->extents.x0 = 0;
1371 SWFDEC_GRAPHIC (edittext)->extents.x1 = SWFDEC_DOUBLE_TO_TWIPS (width);
1372 SWFDEC_GRAPHIC (edittext)->extents.y0 = 0;
1373 SWFDEC_GRAPHIC (edittext)->extents.y1 = SWFDEC_DOUBLE_TO_TWIPS (height);
1375 movie = swfdec_movie_find (parent, depth);
1376 if (movie)
1377 swfdec_movie_remove (movie);
1379 movie = swfdec_movie_new (SWFDEC_PLAYER (cx), depth, parent, parent->resource,
1380 SWFDEC_GRAPHIC (edittext), name);
1381 g_assert (SWFDEC_IS_TEXT_FIELD_MOVIE (movie));
1382 g_object_unref (edittext);
1384 swfdec_movie_begin_update_matrix (movie);
1385 movie->matrix.x0 = SWFDEC_DOUBLE_TO_TWIPS (x);
1386 movie->matrix.y0 = SWFDEC_DOUBLE_TO_TWIPS (y);
1387 movie->modified = TRUE;
1388 swfdec_movie_end_update_matrix (movie);
1390 swfdec_movie_initialize (movie);
1391 swfdec_movie_update (movie);
1393 swfdec_as_object_get_variable (cx->global, SWFDEC_AS_STR_TextField, &val);
1394 if (!SWFDEC_AS_VALUE_IS_OBJECT (*&val))
1395 return;
1396 fun_object = SWFDEC_AS_VALUE_GET_OBJECT (*&val);
1397 if (!SWFDEC_IS_AS_FUNCTION (fun_object->relay))
1398 return;
1399 fun = SWFDEC_AS_FUNCTION (fun_object->relay);
1401 /* set initial variables */
1402 o = swfdec_as_relay_get_as_object (SWFDEC_AS_RELAY (movie));
1403 if (swfdec_as_object_get_variable (fun_object,
1404 SWFDEC_AS_STR_prototype, &val)) {
1405 swfdec_as_object_set_variable_and_flags (o,
1406 SWFDEC_AS_STR___proto__, &val,
1407 SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT);
1409 SWFDEC_AS_VALUE_SET_OBJECT (&val, fun_object);
1410 if (cx->version < 7) {
1411 swfdec_as_object_set_variable_and_flags (o,
1412 SWFDEC_AS_STR_constructor, &val, SWFDEC_AS_VARIABLE_HIDDEN);
1414 swfdec_as_object_set_variable_and_flags (o,
1415 SWFDEC_AS_STR___constructor__, &val,
1416 SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_VERSION_6_UP);
1418 swfdec_as_function_call_full (fun, o, TRUE, NULL,
1419 0, NULL, cx->version > 7 ? rval : &val);
1422 void
1423 swfdec_text_field_movie_init_properties (SwfdecAsContext *cx)
1425 SwfdecAsValue val;
1426 SwfdecAsObject *object, *proto;
1428 // FIXME: We should only initialize if the prototype Object has not been
1429 // initialized by any object's constructor with native properties
1430 // (TextField, TextFormat, XML, XMLNode at least)
1432 g_return_if_fail (SWFDEC_IS_AS_CONTEXT (cx));
1434 swfdec_as_object_get_variable (cx->global, SWFDEC_AS_STR_TextField, &val);
1435 if (!SWFDEC_AS_VALUE_IS_OBJECT (*&val))
1436 return;
1437 object = SWFDEC_AS_VALUE_GET_OBJECT (*&val);
1438 swfdec_as_object_get_variable (object, SWFDEC_AS_STR_prototype, &val);
1439 if (!SWFDEC_AS_VALUE_IS_OBJECT (*&val))
1440 return;
1441 proto = SWFDEC_AS_VALUE_GET_OBJECT (*&val);
1443 // text
1444 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_text,
1445 swfdec_text_field_movie_do_get_text,
1446 swfdec_text_field_movie_do_set_text);
1447 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_html,
1448 swfdec_text_field_movie_get_html, swfdec_text_field_movie_set_html);
1449 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_htmlText,
1450 swfdec_text_field_movie_get_htmlText,
1451 swfdec_text_field_movie_set_htmlText);
1452 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_length,
1453 swfdec_text_field_movie_get_length,
1454 swfdec_text_field_movie_set_readonly);
1456 // input
1457 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_condenseWhite,
1458 swfdec_text_field_movie_get_condenseWhite,
1459 swfdec_text_field_movie_set_condenseWhite);
1460 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_maxChars,
1461 swfdec_text_field_movie_get_maxChars,
1462 swfdec_text_field_movie_set_maxChars);
1463 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_multiline,
1464 swfdec_text_field_movie_get_multiline,
1465 swfdec_text_field_movie_set_multiline);
1466 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_restrict,
1467 swfdec_text_field_movie_get_restrict,
1468 swfdec_text_field_movie_set_restrict);
1469 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_selectable,
1470 swfdec_text_field_movie_get_selectable,
1471 swfdec_text_field_movie_set_selectable);
1472 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_type,
1473 swfdec_text_field_movie_do_get_type,
1474 swfdec_text_field_movie_do_set_type);
1475 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_variable,
1476 swfdec_text_field_movie_do_get_variable,
1477 swfdec_text_field_movie_do_set_variable);
1479 // info
1480 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_textHeight,
1481 swfdec_text_field_movie_get_textHeight,
1482 swfdec_text_field_movie_set_readonly);
1483 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_textWidth,
1484 swfdec_text_field_movie_get_textWidth,
1485 swfdec_text_field_movie_set_readonly);
1487 // border & background
1488 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_background,
1489 swfdec_text_field_movie_get_background,
1490 swfdec_text_field_movie_set_background);
1491 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_backgroundColor,
1492 swfdec_text_field_movie_get_backgroundColor,
1493 swfdec_text_field_movie_set_backgroundColor);
1494 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_border,
1495 swfdec_text_field_movie_get_border, swfdec_text_field_movie_set_border);
1496 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_borderColor,
1497 swfdec_text_field_movie_get_borderColor,
1498 swfdec_text_field_movie_set_borderColor);
1500 // scrolling
1501 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_bottomScroll,
1502 swfdec_text_field_movie_get_bottomScroll,
1503 swfdec_text_field_movie_set_readonly);
1504 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_hscroll,
1505 swfdec_text_field_movie_do_get_hscroll,
1506 swfdec_text_field_movie_do_set_hscroll);
1507 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_maxhscroll,
1508 swfdec_text_field_movie_get_maxhscroll,
1509 swfdec_text_field_movie_set_readonly);
1510 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_maxscroll,
1511 swfdec_text_field_movie_get_maxscroll,
1512 swfdec_text_field_movie_set_readonly);
1513 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_mouseWheelEnabled,
1514 swfdec_text_field_movie_get_mouseWheelEnabled,
1515 swfdec_text_field_movie_set_mouseWheelEnabled);
1516 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_scroll,
1517 swfdec_text_field_movie_do_get_scroll,
1518 swfdec_text_field_movie_do_set_scroll);
1520 // display
1521 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_autoSize,
1522 swfdec_text_field_movie_get_autoSize,
1523 swfdec_text_field_movie_set_autoSize);
1524 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_password,
1525 swfdec_text_field_movie_get_password,
1526 swfdec_text_field_movie_set_password);
1527 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_wordWrap,
1528 swfdec_text_field_movie_get_wordWrap,
1529 swfdec_text_field_movie_set_wordWrap);
1531 // format
1532 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_embedFonts,
1533 swfdec_text_field_movie_get_embedFonts,
1534 swfdec_text_field_movie_set_embedFonts);
1535 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_styleSheet,
1536 swfdec_text_field_movie_get_styleSheet,
1537 swfdec_text_field_movie_set_styleSheet);
1538 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_textColor,
1539 swfdec_text_field_movie_get_textColor,
1540 swfdec_text_field_movie_set_textColor);
1542 // TODO: menu, tabEnabled, tabIndex
1544 // Version 8 properties have ASnative numbers:
1545 // gridFitType, antiAliasType, thickness, sharpness and filters
1548 SWFDEC_AS_NATIVE (104, 0, swfdec_text_field_movie_construct)
1549 void
1550 swfdec_text_field_movie_construct (SwfdecAsContext *cx, SwfdecAsObject *object,
1551 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
1553 if (!cx->frame->construct) {
1554 object = swfdec_as_object_new_empty (cx);
1555 swfdec_as_object_set_constructor_by_name (object, SWFDEC_AS_STR_TextField, NULL);
1558 swfdec_text_field_movie_init_properties (cx);
1560 // FIXME: do object.addListener (object);
1562 SWFDEC_AS_VALUE_SET_COMPOSITE (ret, object);