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.
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
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
)
33 swfdec_edit_text_movie_update_extents (SwfdecMovie
*movie
,
36 swfdec_rect_union (extents
, extents
,
37 &SWFDEC_GRAPHIC (SWFDEC_EDIT_TEXT_MOVIE (movie
)->text
)->extents
);
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
)
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
);
53 swfdec_edit_text_render (text
->text
, cr
, text
->paragraph
, trans
, inval
);
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
;
68 G_OBJECT_CLASS (swfdec_edit_text_movie_parent_class
)->dispose (object
);
72 swfdec_edit_text_movie_iterate (SwfdecMovie
*movie
)
74 SwfdecEditTextMovie
*text
= SWFDEC_EDIT_TEXT_MOVIE (movie
);
75 SwfdecAsObject
*parent
;
77 SwfdecAsValue val
= { 0, };
79 if (text
->text
->variable
== NULL
)
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
))
87 s
= swfdec_as_value_to_string (parent
->context
, &val
);
89 if (text
->str
&& g_str_equal (s
, text
->str
))
92 swfdec_edit_text_movie_set_text (text
, s
);
96 swfdec_edit_text_movie_init_movie (SwfdecMovie
*movie
)
98 SwfdecEditTextMovie
*text
= SWFDEC_EDIT_TEXT_MOVIE (movie
);
99 SwfdecAsObject
*parent
;
100 SwfdecAsValue val
= { 0, };
103 if (text
->text
->variable
== NULL
)
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
);
111 if (text
->str
&& g_str_equal (s
, text
->str
))
114 swfdec_edit_text_movie_set_text (text
, s
);
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
);
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
;
140 swfdec_edit_text_movie_init (SwfdecEditTextMovie
*movie
)
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
);
153 movie
->str
= g_strdup (str
);
155 if (movie
->text
->html
)
156 movie
->paragraph
= swfdec_paragraph_html_parse (movie
->text
, movie
->str
);
158 movie
->paragraph
= swfdec_paragraph_text_parse (movie
->text
, movie
->str
);
160 movie
->paragraph
= NULL
;
162 swfdec_movie_invalidate (SWFDEC_MOVIE (movie
));