make numbers garbage-collected objects
[swfdec.git] / swfdec / swfdec_text_field_movie_as.c
blob9d04b72721655885572de16f9b65784d3a6a3265
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, SWFDEC_AS_OBJECT (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 if (SWFDEC_IS_MOVIE (value))
909 value = NULL;
910 } else {
911 value = NULL;
914 if (text->style_sheet == value)
915 return;
917 if (text->style_sheet != NULL && SWFDEC_IS_STYLESHEET (text->style_sheet)) {
918 g_signal_handlers_disconnect_by_func (text->style_sheet,
919 swfdec_text_field_movie_style_sheet_update, text);
920 g_object_remove_weak_pointer (G_OBJECT (text->style_sheet),
921 (gpointer) &text->style_sheet);
924 text->style_sheet = value;
926 if (SWFDEC_IS_STYLESHEET (value)) {
927 g_signal_connect_swapped (value, "update",
928 G_CALLBACK (swfdec_text_field_movie_style_sheet_update), text);
929 g_object_add_weak_pointer (G_OBJECT (text->style_sheet),
930 (gpointer) &text->style_sheet);
932 swfdec_text_field_movie_style_sheet_update (text);
936 static void
937 swfdec_text_field_movie_get_textColor (SwfdecAsContext *cx,
938 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
939 SwfdecAsValue *ret)
941 SwfdecTextFieldMovie *text;
943 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
945 swfdec_as_value_set_number (cx, ret,
946 swfdec_text_buffer_get_default_attributes (text->text)->color);
949 // This doesn't work the same way as TextFormat's color setting
950 static void
951 swfdec_text_field_movie_set_textColor (SwfdecAsContext *cx,
952 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
953 SwfdecAsValue *ret)
955 SwfdecTextFieldMovie *text;
956 int value;
958 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
960 /* FIXME: don't access private variables, you lazy hacker! */
961 text->text->default_attributes.color = swfdec_text_field_movie_int_to_color (cx, value);
964 SWFDEC_AS_NATIVE (104, 300, swfdec_text_field_movie_get_gridFitType)
965 void
966 swfdec_text_field_movie_get_gridFitType (SwfdecAsContext *cx,
967 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
968 SwfdecAsValue *ret)
970 SWFDEC_STUB ("TextField.gridFitType (get)");
973 SWFDEC_AS_NATIVE (104, 301, swfdec_text_field_movie_set_gridFitType)
974 void
975 swfdec_text_field_movie_set_gridFitType (SwfdecAsContext *cx,
976 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
977 SwfdecAsValue *ret)
979 SWFDEC_STUB ("TextField.gridFitType (set)");
982 SWFDEC_AS_NATIVE (104, 302, swfdec_text_field_movie_get_antiAliasType)
983 void
984 swfdec_text_field_movie_get_antiAliasType (SwfdecAsContext *cx,
985 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
986 SwfdecAsValue *ret)
988 SWFDEC_STUB ("TextField.antiAliasType (get)");
991 SWFDEC_AS_NATIVE (104, 303, swfdec_text_field_movie_set_antiAliasType)
992 void
993 swfdec_text_field_movie_set_antiAliasType (SwfdecAsContext *cx,
994 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
995 SwfdecAsValue *ret)
997 SWFDEC_STUB ("TextField.antiAliasType (set)");
1000 SWFDEC_AS_NATIVE (104, 304, swfdec_text_field_movie_get_thickness)
1001 void
1002 swfdec_text_field_movie_get_thickness (SwfdecAsContext *cx,
1003 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1004 SwfdecAsValue *ret)
1006 SWFDEC_STUB ("TextField.thickness (get)");
1009 SWFDEC_AS_NATIVE (104, 305, swfdec_text_field_movie_set_thickness)
1010 void
1011 swfdec_text_field_movie_set_thickness (SwfdecAsContext *cx,
1012 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1013 SwfdecAsValue *ret)
1015 SWFDEC_STUB ("TextField.thickness (set)");
1018 SWFDEC_AS_NATIVE (104, 306, swfdec_text_field_movie_get_sharpness)
1019 void
1020 swfdec_text_field_movie_get_sharpness (SwfdecAsContext *cx,
1021 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1022 SwfdecAsValue *ret)
1024 SWFDEC_STUB ("TextField.sharpness (get)");
1027 SWFDEC_AS_NATIVE (104, 307, swfdec_text_field_movie_set_sharpness)
1028 void
1029 swfdec_text_field_movie_set_sharpness (SwfdecAsContext *cx,
1030 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1031 SwfdecAsValue *ret)
1033 SWFDEC_STUB ("TextField.sharpness (set)");
1036 SWFDEC_AS_NATIVE (104, 308, swfdec_text_field_movie_get_filters)
1037 void
1038 swfdec_text_field_movie_get_filters (SwfdecAsContext *cx,
1039 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1040 SwfdecAsValue *ret)
1042 SWFDEC_STUB ("TextField.filters (get)");
1045 SWFDEC_AS_NATIVE (104, 309, swfdec_text_field_movie_set_filters)
1046 void
1047 swfdec_text_field_movie_set_filters (SwfdecAsContext *cx,
1048 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1049 SwfdecAsValue *ret)
1051 SWFDEC_STUB ("TextField.filters (set)");
1055 * Native functions
1057 SWFDEC_AS_NATIVE (104, 104, swfdec_text_field_movie_getNewTextFormat)
1058 void
1059 swfdec_text_field_movie_getNewTextFormat (SwfdecAsContext *cx,
1060 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1061 SwfdecAsValue *ret)
1063 SwfdecTextFieldMovie *text;
1064 SwfdecTextFormat *format;
1066 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1068 format = SWFDEC_TEXT_FORMAT (swfdec_text_format_new (cx));
1069 if (format == NULL)
1070 return;
1072 swfdec_text_attributes_copy (&format->attr,
1073 swfdec_text_buffer_get_default_attributes (text->text),
1074 SWFDEC_TEXT_ATTRIBUTES_MASK);
1075 format->values_set = SWFDEC_TEXT_ATTRIBUTES_MASK;
1077 SWFDEC_AS_VALUE_SET_OBJECT (ret, SWFDEC_AS_OBJECT (format));
1080 SWFDEC_AS_NATIVE (104, 105, swfdec_text_field_movie_setNewTextFormat)
1081 void
1082 swfdec_text_field_movie_setNewTextFormat (SwfdecAsContext *cx,
1083 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1084 SwfdecAsValue *ret)
1086 SwfdecTextFieldMovie *text;
1087 SwfdecTextFormat *format;
1089 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "o", &format);
1091 if (!SWFDEC_IS_TEXT_FORMAT (format))
1092 return;
1094 swfdec_text_buffer_set_default_attributes (text->text,
1095 &format->attr, format->values_set);
1098 SWFDEC_AS_NATIVE (104, 102, swfdec_text_field_movie_setTextFormat)
1099 void
1100 swfdec_text_field_movie_setTextFormat (SwfdecAsContext *cx,
1101 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1102 SwfdecAsValue *ret)
1104 SwfdecTextFieldMovie *text;
1105 SwfdecTextFormat *format;
1106 int val;
1107 guint i;
1108 const char *string;
1109 gsize start, end, length;
1111 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1113 if (argc < 1)
1114 return;
1116 string = swfdec_text_buffer_get_text (text->text);
1117 length = g_utf8_strlen (string, -1);
1118 if (argc <= 1) {
1119 start = 0;
1120 end = length;
1121 i = 0;
1122 } else {
1123 val = swfdec_as_value_to_integer (cx, &argv[0]);
1124 start = MAX (val, 0);
1125 start = MIN (start, length);
1126 if (argc <= 2) {
1127 if (val < 0) { // fail
1128 return;
1129 } else {
1130 end = MIN (start + 1, length);
1132 i = 1;
1133 } else {
1134 val = swfdec_as_value_to_integer (cx, &argv[1]);
1135 end = MAX (val, 0);
1136 end = CLAMP (end, start, length);
1137 i = 2;
1140 if (start == end)
1141 return;
1143 if (!SWFDEC_AS_VALUE_IS_OBJECT (&argv[i]))
1144 return;
1145 if (!SWFDEC_IS_TEXT_FORMAT (SWFDEC_AS_VALUE_GET_OBJECT (&argv[i])))
1146 return;
1148 format = SWFDEC_TEXT_FORMAT (SWFDEC_AS_VALUE_GET_OBJECT (&argv[i]));
1149 start = g_utf8_offset_to_pointer (string, start) - string;
1150 end = g_utf8_offset_to_pointer (string, end) - string;
1152 swfdec_text_buffer_set_attributes (text->text, start, end - start,
1153 &format->attr, format->values_set);
1155 swfdec_movie_invalidate_last (SWFDEC_MOVIE (text));
1156 /* special case: update the max values, not the current values */
1157 /* swfdec_text_field_movie_update_layout (text); */
1158 /* FIXME: emit onScroller? */
1159 text->layout_width = swfdec_text_layout_get_width (text->layout);
1160 text->layout_height = swfdec_text_layout_get_height (text->layout);
1161 text->scroll_max = swfdec_text_layout_get_n_rows (text->layout)
1162 - swfdec_text_layout_get_visible_rows_end (text->layout,
1163 text->layout_area.height);
1166 SWFDEC_AS_NATIVE (104, 101, swfdec_text_field_movie_getTextFormat)
1167 void
1168 swfdec_text_field_movie_getTextFormat (SwfdecAsContext *cx,
1169 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1170 SwfdecAsValue *ret)
1172 SwfdecTextFieldMovie *text;
1173 SwfdecTextFormat *format;
1174 int val;
1175 const char *string;
1176 guint mask;
1177 const SwfdecTextAttributes *attr;
1178 gsize start, end, length;
1180 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1182 string = swfdec_text_buffer_get_text (text->text);
1183 length = g_utf8_strlen (string, -1);
1185 format = SWFDEC_TEXT_FORMAT (swfdec_text_format_new (cx));
1186 SWFDEC_AS_VALUE_SET_OBJECT (ret, SWFDEC_AS_OBJECT (format));
1188 if (argc == 0) {
1189 start = 0;
1190 end = length;
1191 } else {
1192 val = swfdec_as_value_to_integer (cx, &argv[0]);
1193 start = MAX (val, 0);
1194 start = MIN (start, length);
1195 if (argc == 1) {
1196 if (val < 0) { // fail
1197 return;
1198 } else {
1199 end = MIN (start + 1, length);
1201 } else {
1202 val = swfdec_as_value_to_integer (cx, &argv[1]);
1203 end = MAX (val, 0);
1204 end = CLAMP (end, start, length);
1208 if (start == end)
1209 return;
1211 start = g_utf8_offset_to_pointer (string, start) - string;
1212 end = g_utf8_offset_to_pointer (string, end) - string;
1213 mask = swfdec_text_buffer_get_unique (text->text, start, end - start);
1214 attr = swfdec_text_buffer_get_attributes (text->text, start);
1215 swfdec_text_attributes_copy (&format->attr, attr, mask);
1216 format->values_set = mask;
1219 SWFDEC_AS_NATIVE (104, 100, swfdec_text_field_movie_replaceSel)
1220 void
1221 swfdec_text_field_movie_replaceSel (SwfdecAsContext *cx,
1222 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1223 SwfdecAsValue *ret)
1225 SWFDEC_STUB ("TextField.replaceSel");
1228 SWFDEC_AS_NATIVE (104, 107, swfdec_text_field_movie_replaceText)
1229 void
1230 swfdec_text_field_movie_replaceText (SwfdecAsContext *cx,
1231 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1232 SwfdecAsValue *ret)
1234 SwfdecTextFieldMovie *text;
1235 int start_index, end_index;
1236 const char *string, *str;
1237 gsize start, end;
1239 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "iis", &start_index,
1240 &end_index, &str);
1242 if (start_index < 0)
1243 return;
1244 if (end_index < start_index)
1245 return;
1246 /* if there was a style sheet set when setting the text, modifications are
1247 * not allowed */
1248 if (text->style_sheet_input)
1249 return;
1251 string = swfdec_text_buffer_get_text (text->text);
1252 start = end = g_utf8_strlen (string, -1);
1253 start = MIN ((gsize) start_index, start);
1254 end = MIN ((gsize) end_index, end);
1255 start = g_utf8_offset_to_pointer (string, start) - string;
1256 end = g_utf8_offset_to_pointer (string, end) - string;
1258 /* anyone explain to me why Flash 7 has this special case plz */
1259 if (end > start && (str != SWFDEC_AS_STR_EMPTY || cx->version != 7))
1260 swfdec_text_buffer_delete_text (text->text, start, end - start);
1262 swfdec_text_buffer_insert_text (text->text, start, str);
1263 /* yes, modifying text changes the default format */
1264 swfdec_text_buffer_set_default_attributes (text->text,
1265 swfdec_text_buffer_get_attributes (text->text, 0),
1266 SWFDEC_TEXT_ATTRIBUTES_MASK);
1269 // static
1270 SWFDEC_AS_NATIVE (104, 201, swfdec_text_field_movie_getFontList)
1271 void
1272 swfdec_text_field_movie_getFontList (SwfdecAsContext *cx,
1273 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1274 SwfdecAsValue *ret)
1276 SwfdecAsArray *array;
1277 SwfdecAsValue val;
1278 PangoFontFamily **families;
1279 int i, n_families;
1281 pango_font_map_list_families (pango_cairo_font_map_get_default (),
1282 &families, &n_families);
1284 array = SWFDEC_AS_ARRAY (swfdec_as_array_new (cx));
1285 for (i = 0; i < n_families; i++) {
1286 SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (cx,
1287 pango_font_family_get_name (families[i])));
1288 swfdec_as_array_push (array, &val);
1290 SWFDEC_AS_VALUE_SET_STRING (&val, SWFDEC_AS_STR_Sans);
1291 swfdec_as_array_push (array, &val);
1292 SWFDEC_AS_VALUE_SET_STRING (&val, SWFDEC_AS_STR_Serif);
1293 swfdec_as_array_push (array, &val);
1294 SWFDEC_AS_VALUE_SET_STRING (&val, SWFDEC_AS_STR_Monospace);
1295 swfdec_as_array_push (array, &val);
1297 g_free (families);
1299 SWFDEC_AS_VALUE_SET_OBJECT (ret, SWFDEC_AS_OBJECT (array));
1302 SWFDEC_AS_NATIVE (104, 106, swfdec_text_field_movie_getDepth)
1303 void
1304 swfdec_text_field_movie_getDepth (SwfdecAsContext *cx, SwfdecAsObject *object,
1305 guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
1307 SwfdecTextFieldMovie *text;
1309 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1311 swfdec_as_value_set_integer (cx, rval, SWFDEC_MOVIE (text)->depth);
1314 SWFDEC_AS_NATIVE (104, 103, swfdec_text_field_movie_removeTextField)
1315 void
1316 swfdec_text_field_movie_removeTextField (SwfdecAsContext *cx,
1317 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1318 SwfdecAsValue *rval)
1320 SwfdecTextFieldMovie *text;
1321 SwfdecMovie *movie;
1323 SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
1325 movie = SWFDEC_MOVIE (text);
1326 if (swfdec_depth_classify (movie->depth) == SWFDEC_DEPTH_CLASS_DYNAMIC)
1327 swfdec_movie_remove (movie);
1331 * Creating TextFields
1333 SWFDEC_AS_NATIVE (104, 200, swfdec_text_field_movie_createTextField)
1334 void
1335 swfdec_text_field_movie_createTextField (SwfdecAsContext *cx,
1336 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
1337 SwfdecAsValue *rval)
1339 SwfdecMovie *movie, *parent;
1340 SwfdecTextField *edittext;
1341 int depth, x, y, width, height;
1342 const char *name;
1343 SwfdecAsFunction *fun;
1344 SwfdecAsValue val;
1346 SWFDEC_AS_CHECK (SWFDEC_TYPE_MOVIE, &parent, "siiiii", &name, &depth, &x, &y, &width, &height);
1347 width = ABS (width);
1348 height = ABS (height);
1350 edittext = g_object_new (SWFDEC_TYPE_TEXT_FIELD, NULL);
1351 edittext->html = FALSE;
1352 edittext->editable = FALSE;
1353 edittext->password = FALSE;
1354 edittext->selectable = TRUE;
1355 edittext->font = NULL; // FIXME
1356 edittext->word_wrap = FALSE;
1357 edittext->multiline = FALSE;
1358 edittext->auto_size = SWFDEC_AUTO_SIZE_NONE;
1359 edittext->border = FALSE;
1360 edittext->size = 240; // FIXME: Correct?
1362 edittext->input = NULL;
1363 edittext->variable = NULL;
1364 edittext->color = 0;
1365 edittext->align = SWFDEC_TEXT_ALIGN_LEFT;
1366 edittext->left_margin = 0;
1367 edittext->right_margin = 0;
1368 edittext->indent = 0;
1369 edittext->leading = 0;
1371 SWFDEC_GRAPHIC (edittext)->extents.x0 = 0;
1372 SWFDEC_GRAPHIC (edittext)->extents.x1 = SWFDEC_DOUBLE_TO_TWIPS (width);
1373 SWFDEC_GRAPHIC (edittext)->extents.y0 = 0;
1374 SWFDEC_GRAPHIC (edittext)->extents.y1 = SWFDEC_DOUBLE_TO_TWIPS (height);
1376 movie = swfdec_movie_find (parent, depth);
1377 if (movie)
1378 swfdec_movie_remove (movie);
1380 movie = swfdec_movie_new (SWFDEC_PLAYER (cx), depth, parent, parent->resource,
1381 SWFDEC_GRAPHIC (edittext), name);
1382 g_assert (SWFDEC_IS_TEXT_FIELD_MOVIE (movie));
1383 g_object_unref (edittext);
1385 swfdec_movie_begin_update_matrix (movie);
1386 movie->matrix.x0 = SWFDEC_DOUBLE_TO_TWIPS (x);
1387 movie->matrix.y0 = SWFDEC_DOUBLE_TO_TWIPS (y);
1388 movie->modified = TRUE;
1389 swfdec_movie_end_update_matrix (movie);
1391 swfdec_movie_initialize (movie);
1392 swfdec_movie_update (movie);
1394 swfdec_as_object_get_variable (cx->global, SWFDEC_AS_STR_TextField, &val);
1395 if (!SWFDEC_AS_VALUE_IS_OBJECT (&val))
1396 return;
1397 fun = (SwfdecAsFunction *) SWFDEC_AS_VALUE_GET_OBJECT (&val);
1398 if (!SWFDEC_IS_AS_FUNCTION (fun))
1399 return;
1401 /* set initial variables */
1402 if (swfdec_as_object_get_variable (SWFDEC_AS_OBJECT (fun),
1403 SWFDEC_AS_STR_prototype, &val)) {
1404 swfdec_as_object_set_variable_and_flags (SWFDEC_AS_OBJECT (movie),
1405 SWFDEC_AS_STR___proto__, &val,
1406 SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT);
1408 SWFDEC_AS_VALUE_SET_OBJECT (&val, SWFDEC_AS_OBJECT (fun));
1409 if (cx->version < 7) {
1410 swfdec_as_object_set_variable_and_flags (SWFDEC_AS_OBJECT (movie),
1411 SWFDEC_AS_STR_constructor, &val, SWFDEC_AS_VARIABLE_HIDDEN);
1413 swfdec_as_object_set_variable_and_flags (SWFDEC_AS_OBJECT (movie),
1414 SWFDEC_AS_STR___constructor__, &val,
1415 SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_VERSION_6_UP);
1417 swfdec_as_function_call_full (fun, SWFDEC_AS_OBJECT (movie), TRUE, NULL,
1418 0, NULL, cx->version > 7 ? rval : &val);
1421 void
1422 swfdec_text_field_movie_init_properties (SwfdecAsContext *cx)
1424 SwfdecAsValue val;
1425 SwfdecAsObject *object, *proto;
1427 // FIXME: We should only initialize if the prototype Object has not been
1428 // initialized by any object's constructor with native properties
1429 // (TextField, TextFormat, XML, XMLNode at least)
1431 g_return_if_fail (SWFDEC_IS_AS_CONTEXT (cx));
1433 swfdec_as_object_get_variable (cx->global, SWFDEC_AS_STR_TextField, &val);
1434 if (!SWFDEC_AS_VALUE_IS_OBJECT (&val))
1435 return;
1436 object = SWFDEC_AS_VALUE_GET_OBJECT (&val);
1437 swfdec_as_object_get_variable (object, SWFDEC_AS_STR_prototype, &val);
1438 if (!SWFDEC_AS_VALUE_IS_OBJECT (&val))
1439 return;
1440 proto = SWFDEC_AS_VALUE_GET_OBJECT (&val);
1442 // text
1443 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_text,
1444 swfdec_text_field_movie_do_get_text,
1445 swfdec_text_field_movie_do_set_text);
1446 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_html,
1447 swfdec_text_field_movie_get_html, swfdec_text_field_movie_set_html);
1448 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_htmlText,
1449 swfdec_text_field_movie_get_htmlText,
1450 swfdec_text_field_movie_set_htmlText);
1451 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_length,
1452 swfdec_text_field_movie_get_length,
1453 swfdec_text_field_movie_set_readonly);
1455 // input
1456 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_condenseWhite,
1457 swfdec_text_field_movie_get_condenseWhite,
1458 swfdec_text_field_movie_set_condenseWhite);
1459 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_maxChars,
1460 swfdec_text_field_movie_get_maxChars,
1461 swfdec_text_field_movie_set_maxChars);
1462 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_multiline,
1463 swfdec_text_field_movie_get_multiline,
1464 swfdec_text_field_movie_set_multiline);
1465 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_restrict,
1466 swfdec_text_field_movie_get_restrict,
1467 swfdec_text_field_movie_set_restrict);
1468 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_selectable,
1469 swfdec_text_field_movie_get_selectable,
1470 swfdec_text_field_movie_set_selectable);
1471 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_type,
1472 swfdec_text_field_movie_do_get_type,
1473 swfdec_text_field_movie_do_set_type);
1474 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_variable,
1475 swfdec_text_field_movie_do_get_variable,
1476 swfdec_text_field_movie_do_set_variable);
1478 // info
1479 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_textHeight,
1480 swfdec_text_field_movie_get_textHeight,
1481 swfdec_text_field_movie_set_readonly);
1482 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_textWidth,
1483 swfdec_text_field_movie_get_textWidth,
1484 swfdec_text_field_movie_set_readonly);
1486 // border & background
1487 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_background,
1488 swfdec_text_field_movie_get_background,
1489 swfdec_text_field_movie_set_background);
1490 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_backgroundColor,
1491 swfdec_text_field_movie_get_backgroundColor,
1492 swfdec_text_field_movie_set_backgroundColor);
1493 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_border,
1494 swfdec_text_field_movie_get_border, swfdec_text_field_movie_set_border);
1495 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_borderColor,
1496 swfdec_text_field_movie_get_borderColor,
1497 swfdec_text_field_movie_set_borderColor);
1499 // scrolling
1500 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_bottomScroll,
1501 swfdec_text_field_movie_get_bottomScroll,
1502 swfdec_text_field_movie_set_readonly);
1503 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_hscroll,
1504 swfdec_text_field_movie_do_get_hscroll,
1505 swfdec_text_field_movie_do_set_hscroll);
1506 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_maxhscroll,
1507 swfdec_text_field_movie_get_maxhscroll,
1508 swfdec_text_field_movie_set_readonly);
1509 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_maxscroll,
1510 swfdec_text_field_movie_get_maxscroll,
1511 swfdec_text_field_movie_set_readonly);
1512 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_mouseWheelEnabled,
1513 swfdec_text_field_movie_get_mouseWheelEnabled,
1514 swfdec_text_field_movie_set_mouseWheelEnabled);
1515 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_scroll,
1516 swfdec_text_field_movie_do_get_scroll,
1517 swfdec_text_field_movie_do_set_scroll);
1519 // display
1520 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_autoSize,
1521 swfdec_text_field_movie_get_autoSize,
1522 swfdec_text_field_movie_set_autoSize);
1523 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_password,
1524 swfdec_text_field_movie_get_password,
1525 swfdec_text_field_movie_set_password);
1526 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_wordWrap,
1527 swfdec_text_field_movie_get_wordWrap,
1528 swfdec_text_field_movie_set_wordWrap);
1530 // format
1531 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_embedFonts,
1532 swfdec_text_field_movie_get_embedFonts,
1533 swfdec_text_field_movie_set_embedFonts);
1534 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_styleSheet,
1535 swfdec_text_field_movie_get_styleSheet,
1536 swfdec_text_field_movie_set_styleSheet);
1537 swfdec_as_object_add_native_variable (proto, SWFDEC_AS_STR_textColor,
1538 swfdec_text_field_movie_get_textColor,
1539 swfdec_text_field_movie_set_textColor);
1541 // TODO: menu, tabEnabled, tabIndex
1543 // Version 8 properties have ASnative numbers:
1544 // gridFitType, antiAliasType, thickness, sharpness and filters
1547 SWFDEC_AS_NATIVE (104, 0, swfdec_text_field_movie_construct)
1548 void
1549 swfdec_text_field_movie_construct (SwfdecAsContext *cx, SwfdecAsObject *object,
1550 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
1552 if (!cx->frame->construct) {
1553 object = swfdec_as_object_new_empty (cx);
1554 swfdec_as_object_set_constructor_by_name (object, SWFDEC_AS_STR_TextField, NULL);
1557 swfdec_text_field_movie_init_properties (cx);
1559 // FIXME: do object.addListener (object);
1561 SWFDEC_AS_VALUE_SET_OBJECT (ret, object);