2 * Copyright (C) 2006-2007 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.
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
27 #include "swfdec_text_field.h"
28 #include "swfdec_debug.h"
29 #include "swfdec_text_field_movie.h"
30 #include "swfdec_font.h"
31 #include "swfdec_player_internal.h"
32 #include "swfdec_swf_decoder.h"
34 G_DEFINE_TYPE (SwfdecTextField
, swfdec_text_field
, SWFDEC_TYPE_GRAPHIC
)
37 swfdec_text_field_mouse_in (SwfdecGraphic
*graphic
, double x
, double y
)
39 return swfdec_rect_contains (&graphic
->extents
, x
, y
);
43 swfdec_text_field_dispose (GObject
*object
)
45 SwfdecTextField
*text
= SWFDEC_TEXT_FIELD (object
);
47 if (text
->input
!= NULL
) {
51 if (text
->variable
!= NULL
) {
52 g_free (text
->variable
);
53 text
->variable
= NULL
;
55 if (text
->font
!= NULL
) {
60 G_OBJECT_CLASS (swfdec_text_field_parent_class
)->dispose (object
);
64 swfdec_text_field_class_init (SwfdecTextFieldClass
* g_class
)
66 GObjectClass
*object_class
= G_OBJECT_CLASS (g_class
);
67 SwfdecGraphicClass
*graphic_class
= SWFDEC_GRAPHIC_CLASS (g_class
);
69 object_class
->dispose
= swfdec_text_field_dispose
;
71 graphic_class
->movie_type
= SWFDEC_TYPE_TEXT_FIELD_MOVIE
;
72 graphic_class
->mouse_in
= swfdec_text_field_mouse_in
;
76 swfdec_text_field_init (SwfdecTextField
* text
)
81 tag_func_define_edit_text (SwfdecSwfDecoder
* s
, guint tag
)
83 SwfdecTextField
*text
;
86 gboolean has_font
, has_color
, has_max_length
, has_layout
, has_text
;
87 gboolean has_font_class
;
88 SwfdecBits
*b
= &s
->b
;
90 id
= swfdec_bits_get_u16 (b
);
91 SWFDEC_LOG (" id = %u", id
);
92 text
= swfdec_swf_decoder_create_character (s
, id
, SWFDEC_TYPE_TEXT_FIELD
);
94 return SWFDEC_STATUS_OK
;
96 swfdec_bits_get_rect (b
, &SWFDEC_GRAPHIC (text
)->extents
);
97 SWFDEC_LOG (" extents: %g %g %g %g",
98 SWFDEC_GRAPHIC (text
)->extents
.x0
, SWFDEC_GRAPHIC (text
)->extents
.y0
,
99 SWFDEC_GRAPHIC (text
)->extents
.x1
, SWFDEC_GRAPHIC (text
)->extents
.y1
);
100 swfdec_bits_syncbits (b
);
102 has_text
= swfdec_bits_getbit (b
);
103 text
->word_wrap
= swfdec_bits_getbit (b
);
104 text
->multiline
= swfdec_bits_getbit (b
);
105 text
->password
= swfdec_bits_getbit (b
);
106 text
->editable
= !swfdec_bits_getbit (b
);
107 has_color
= swfdec_bits_getbit (b
);
108 has_max_length
= swfdec_bits_getbit (b
);
109 has_font
= swfdec_bits_getbit (b
);
110 has_font_class
= swfdec_bits_getbit (b
);
112 (swfdec_bits_getbit (b
) ? SWFDEC_AUTO_SIZE_LEFT
: SWFDEC_AUTO_SIZE_NONE
);
113 has_layout
= swfdec_bits_getbit (b
);
114 text
->selectable
= !swfdec_bits_getbit (b
);
115 text
->background
= text
->border
= swfdec_bits_getbit (b
);
116 reserved
= swfdec_bits_getbit (b
);
117 text
->html
= swfdec_bits_getbit (b
);
118 text
->embed_fonts
= swfdec_bits_getbit (b
);
119 if (text
->embed_fonts
)
120 SWFDEC_FIXME ("Using embed fonts in TextField is not supported");
122 SWFDEC_LOG (" word wrap: %u", text
->word_wrap
);
123 SWFDEC_LOG (" multiline: %u", text
->multiline
);
124 SWFDEC_LOG (" password: %u", text
->password
);
125 SWFDEC_LOG (" editable: %u", text
->editable
);
126 SWFDEC_LOG (" autosize: %u", text
->auto_size
);
127 SWFDEC_LOG (" selectable: %u", text
->selectable
);
128 SWFDEC_LOG (" background: %u", text
->background
);
129 SWFDEC_LOG (" html: %u", text
->html
);
130 SWFDEC_LOG (" embedFonts: %u", text
->embed_fonts
);
133 SwfdecCharacter
*font
;
135 id
= swfdec_bits_get_u16 (b
);
136 font
= swfdec_swf_decoder_get_character (s
, id
);
137 if (SWFDEC_IS_FONT (font
)) {
138 SWFDEC_LOG (" font = %u", id
);
139 text
->font
= g_strdup (SWFDEC_FONT (font
)->name
);
141 SWFDEC_ERROR ("id %u does not specify a font", id
);
143 text
->size
= swfdec_bits_get_u16 (b
);
144 SWFDEC_LOG (" size = %u", text
->size
);
147 if (has_font_class
) {
148 SWFDEC_FIXME ("Implement font_class for EditText");
150 SWFDEC_FIXME ("What to do if both font and font class are defined?");
151 swfdec_bits_get_string (b
, s
->version
);
155 text
->color
= swfdec_bits_get_rgba (b
);
156 SWFDEC_LOG (" color = %u", text
->color
);
158 SWFDEC_WARNING ("FIXME: figure out default color");
159 text
->color
= SWFDEC_COLOR_COMBINE (255, 255, 255, 0);
162 if (has_max_length
) {
163 text
->max_chars
= swfdec_bits_get_u16 (b
);
169 guint align
= swfdec_bits_get_u8 (b
);
172 text
->align
= SWFDEC_TEXT_ALIGN_LEFT
;
175 text
->align
= SWFDEC_TEXT_ALIGN_RIGHT
;
178 text
->align
= SWFDEC_TEXT_ALIGN_CENTER
;
181 text
->align
= SWFDEC_TEXT_ALIGN_JUSTIFY
;
184 SWFDEC_ERROR ("undefined align value %u", align
);
187 text
->left_margin
= swfdec_bits_get_u16 (b
);
188 text
->right_margin
= swfdec_bits_get_u16 (b
);
189 text
->indent
= swfdec_bits_get_u16 (b
);
190 text
->leading
= swfdec_bits_get_s16 (b
);
193 text
->variable
= swfdec_bits_get_string (b
, s
->version
);
194 if (text
->variable
&& *text
->variable
== 0) {
195 g_free (text
->variable
);
196 text
->variable
= NULL
;
200 text
->input
= swfdec_bits_get_string (b
, s
->version
);
201 SWFDEC_LOG (" text = %s", text
->input
);
204 return SWFDEC_STATUS_OK
;