Bug 22803 - Make header conform to implementation
[swfdec.git] / swfdec / swfdec_text_field.c
blob34257b5785d4a6ecc343ec4281993ec52fe084b1
1 /* Swfdec
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.
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 <string.h>
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)
36 static gboolean
37 swfdec_text_field_mouse_in (SwfdecGraphic *graphic, double x, double y)
39 return swfdec_rect_contains (&graphic->extents, x, y);
42 static void
43 swfdec_text_field_dispose (GObject *object)
45 SwfdecTextField *text = SWFDEC_TEXT_FIELD (object);
47 if (text->input != NULL) {
48 g_free (text->input);
49 text->input = NULL;
51 if (text->variable != NULL) {
52 g_free (text->variable);
53 text->variable = NULL;
55 if (text->font != NULL) {
56 g_free (text->font);
57 text->font = NULL;
60 G_OBJECT_CLASS (swfdec_text_field_parent_class)->dispose (object);
63 static void
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;
75 static void
76 swfdec_text_field_init (SwfdecTextField * text)
80 int
81 tag_func_define_edit_text (SwfdecSwfDecoder * s, guint tag)
83 SwfdecTextField *text;
84 guint id;
85 int reserved;
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);
93 if (text == NULL)
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);
111 text->auto_size =
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);
132 if (has_font) {
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);
140 } else {
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");
149 if (has_font)
150 SWFDEC_FIXME ("What to do if both font and font class are defined?");
151 swfdec_bits_get_string (b, s->version);
154 if (has_color) {
155 text->color = swfdec_bits_get_rgba (b);
156 SWFDEC_LOG (" color = %u", text->color);
157 } else {
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);
164 } else {
165 text->max_chars = 0;
168 if (has_layout) {
169 guint align = swfdec_bits_get_u8 (b);
170 switch (align) {
171 case 0:
172 text->align = SWFDEC_TEXT_ALIGN_LEFT;
173 break;
174 case 1:
175 text->align = SWFDEC_TEXT_ALIGN_RIGHT;
176 break;
177 case 2:
178 text->align = SWFDEC_TEXT_ALIGN_CENTER;
179 break;
180 case 3:
181 text->align = SWFDEC_TEXT_ALIGN_JUSTIFY;
182 break;
183 default:
184 SWFDEC_ERROR ("undefined align value %u", align);
185 break;
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;
199 if (has_text) {
200 text->input = swfdec_bits_get_string (b, s->version);
201 SWFDEC_LOG (" text = %s", text->input);
204 return SWFDEC_STATUS_OK;