bump libtool version
[swfdec.git] / libswfdec / swfdec_edittext_movie.c
blobe3b1ba5b7f0d15047577e725d7cd9a26708fc427
1 /* Swfdec
2 * Copyright (C) 2006 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "swfdec_edittext_movie.h"
25 #include "swfdec_as_context.h"
26 #include "swfdec_as_strings.h"
27 #include "swfdec_debug.h"
28 #include "swfdec_player_internal.h"
30 G_DEFINE_TYPE (SwfdecEditTextMovie, swfdec_edit_text_movie, SWFDEC_TYPE_MOVIE)
32 static void
33 swfdec_edit_text_movie_update_extents (SwfdecMovie *movie,
34 SwfdecRect *extents)
36 swfdec_rect_union (extents, extents,
37 &SWFDEC_GRAPHIC (SWFDEC_EDIT_TEXT_MOVIE (movie)->text)->extents);
40 static void
41 swfdec_edit_text_movie_render (SwfdecMovie *movie, cairo_t *cr,
42 const SwfdecColorTransform *trans, const SwfdecRect *inval)
44 SwfdecEditTextMovie *text = SWFDEC_EDIT_TEXT_MOVIE (movie);
46 if (text->paragraph == NULL)
47 return;
48 /* clip by extents to avoid artifacts */
49 cairo_rectangle (cr, movie->original_extents.x0, movie->original_extents.y0,
50 movie->original_extents.x1 - movie->original_extents.x0,
51 movie->original_extents.y1 - movie->original_extents.y0);
52 cairo_clip (cr);
53 swfdec_edit_text_render (text->text, cr, text->paragraph, trans, inval);
56 static void
57 swfdec_edit_text_movie_dispose (GObject *object)
59 SwfdecEditTextMovie *movie = SWFDEC_EDIT_TEXT_MOVIE (object);
61 if (movie->paragraph) {
62 swfdec_paragraph_free (movie->paragraph);
63 movie->paragraph = NULL;
65 g_free (movie->str);
66 movie->str = NULL;
68 G_OBJECT_CLASS (swfdec_edit_text_movie_parent_class)->dispose (object);
71 static void
72 swfdec_edit_text_movie_iterate (SwfdecMovie *movie)
74 SwfdecEditTextMovie *text = SWFDEC_EDIT_TEXT_MOVIE (movie);
75 SwfdecAsObject *parent;
76 const char *s;
77 SwfdecAsValue val = { 0, };
79 if (text->text->variable == NULL)
80 return;
82 parent = SWFDEC_AS_OBJECT (movie->parent);
83 swfdec_as_context_eval (parent->context, parent, text->text->variable, &val);
84 if (SWFDEC_AS_VALUE_IS_UNDEFINED (&val))
85 return;
87 s = swfdec_as_value_to_string (parent->context, &val);
88 g_assert (s);
89 if (text->str && g_str_equal (s, text->str))
90 return;
92 swfdec_edit_text_movie_set_text (text, s);
95 static void
96 swfdec_edit_text_movie_init_movie (SwfdecMovie *movie)
98 SwfdecEditTextMovie *text = SWFDEC_EDIT_TEXT_MOVIE (movie);
99 SwfdecAsObject *parent;
100 SwfdecAsValue val = { 0, };
101 const char *s;
103 if (text->text->variable == NULL)
104 return;
106 parent = SWFDEC_AS_OBJECT (movie->parent);
107 swfdec_as_context_eval (parent->context, parent, text->text->variable, &val);
108 if (!SWFDEC_AS_VALUE_IS_UNDEFINED (&val)) {
109 s = swfdec_as_value_to_string (parent->context, &val);
110 g_assert (s);
111 if (text->str && g_str_equal (s, text->str))
112 return;
114 swfdec_edit_text_movie_set_text (text, s);
115 return;
118 SWFDEC_LOG ("setting variable %s to \"%s\"", text->text->variable,
119 text->str ? text->str : "");
120 s = text->str ? swfdec_as_context_get_string (parent->context, text->str) : SWFDEC_AS_STR_EMPTY;
121 SWFDEC_AS_VALUE_SET_STRING (&val, s);
122 swfdec_as_context_eval_set (parent->context, parent, text->text->variable, &val);
125 static void
126 swfdec_edit_text_movie_class_init (SwfdecEditTextMovieClass * g_class)
128 GObjectClass *object_class = G_OBJECT_CLASS (g_class);
129 SwfdecMovieClass *movie_class = SWFDEC_MOVIE_CLASS (g_class);
131 object_class->dispose = swfdec_edit_text_movie_dispose;
133 movie_class->init_movie = swfdec_edit_text_movie_init_movie;
134 movie_class->update_extents = swfdec_edit_text_movie_update_extents;
135 movie_class->render = swfdec_edit_text_movie_render;
136 movie_class->iterate_start = swfdec_edit_text_movie_iterate;
139 static void
140 swfdec_edit_text_movie_init (SwfdecEditTextMovie *movie)
144 void
145 swfdec_edit_text_movie_set_text (SwfdecEditTextMovie *movie, const char *str)
147 g_return_if_fail (SWFDEC_IS_EDIT_TEXT_MOVIE (movie));
149 if (movie->paragraph) {
150 swfdec_paragraph_free (movie->paragraph);
152 g_free (movie->str);
153 movie->str = g_strdup (str);
154 if (movie->str) {
155 if (movie->text->html)
156 movie->paragraph = swfdec_paragraph_html_parse (movie->text, movie->str);
157 else
158 movie->paragraph = swfdec_paragraph_text_parse (movie->text, movie->str);
159 } else {
160 movie->paragraph = NULL;
162 swfdec_movie_invalidate (SWFDEC_MOVIE (movie));