Benjamin Otte
2008-Jan-04 10:06 UTC
[Swfdec] libswfdec/swfdec_style_sheet.c libswfdec/swfdec_style_sheet.h libswfdec/swfdec_text_field_movie_as.c libswfdec/swfdec_text_field_movie.c
libswfdec/swfdec_style_sheet.c | 71 ++++----------------------------- libswfdec/swfdec_style_sheet.h | 8 --- libswfdec/swfdec_text_field_movie.c | 4 - libswfdec/swfdec_text_field_movie_as.c | 19 ++++++-- 4 files changed, 25 insertions(+), 77 deletions(-) New commits: commit 55ed6db5ac3cc401dc6eab764521e1f9ab7efc8d Author: Benjamin Otte <otte at gnome.org> Date: Fri Jan 4 11:03:16 2008 +0100 switch StyleSheet listener handling to use GObject signals diff --git a/libswfdec/swfdec_style_sheet.c b/libswfdec/swfdec_style_sheet.c index 6084b9e..f146c8a 100644 --- a/libswfdec/swfdec_style_sheet.c +++ b/libswfdec/swfdec_style_sheet.c @@ -36,40 +36,20 @@ #include "swfdec_as_internal.h" #include "swfdec_player_internal.h" -G_DEFINE_TYPE (SwfdecStyleSheet, swfdec_style_sheet, SWFDEC_TYPE_AS_OBJECT) - -static void -swfdec_style_sheet_dispose (GObject *object) -{ - SwfdecStyleSheet *style = SWFDEC_STYLESHEET (object); - - if (style->listeners != NULL) { - g_slist_free (style->listeners); - style->listeners = NULL; - } -} +enum { + UPDATE, + LAST_SIGNAL +}; -static void -swfdec_style_sheet_mark (SwfdecAsObject *object) -{ - SwfdecStyleSheet *style = SWFDEC_STYLESHEET (object); - GSList *iter; - - for (iter = style->listeners; iter != NULL; iter = iter->next) { - swfdec_as_object_mark (iter->data); - } - - SWFDEC_AS_OBJECT_CLASS (swfdec_style_sheet_parent_class)->mark (object); -} +G_DEFINE_TYPE (SwfdecStyleSheet, swfdec_style_sheet, SWFDEC_TYPE_AS_OBJECT) +static guint signals[LAST_SIGNAL] = { 0, }; static void swfdec_style_sheet_class_init (SwfdecStyleSheetClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - SwfdecAsObjectClass *asobject_class = SWFDEC_AS_OBJECT_CLASS (klass); - - object_class->dispose = swfdec_style_sheet_dispose; - asobject_class->mark = swfdec_style_sheet_mark; + signals[UPDATE] = g_signal_new ("update", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } static void @@ -251,17 +231,10 @@ swfdec_style_sheet_update (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval) { SwfdecStyleSheet *style; - SwfdecTextFieldMovie *text; - GSList *iter; SWFDEC_AS_CHECK (SWFDEC_TYPE_STYLESHEET, &style, ""); - for (iter = style->listeners; iter != NULL; iter = iter->next) { - g_assert (SWFDEC_IS_TEXT_FIELD_MOVIE (iter->data)); - text = iter->data; - if (text->style_sheet_input != NULL) - swfdec_text_field_movie_set_text (text, text->style_sheet_input, TRUE); - } + g_signal_emit (style, signals[UPDATE], 0); } SWFDEC_AS_NATIVE (113, 101, swfdec_style_sheet_parseCSSInternal) @@ -345,30 +318,6 @@ swfdec_style_sheet_construct (SwfdecAsContext *cx, SwfdecAsObject *object, g_assert (SWFDEC_IS_STYLESHEET (object)); } -void -swfdec_style_sheet_add_listener (SwfdecStyleSheet *style, - SwfdecAsObject *listener) -{ - g_return_if_fail (SWFDEC_IS_STYLESHEET (style)); - g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (listener)); - - g_return_if_fail (g_slist_find (style->listeners, listener) == NULL); - - style->listeners = g_slist_prepend (style->listeners, listener); -} - -void -swfdec_style_sheet_remove_listener (SwfdecStyleSheet *style, - SwfdecAsObject *listener) -{ - g_return_if_fail (SWFDEC_IS_STYLESHEET (style)); - g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (listener)); - - g_return_if_fail (g_slist_find (style->listeners, listener) != NULL); - - style->listeners = g_slist_remove (style->listeners, listener); -} - static SwfdecTextFormat * swfdec_style_sheet_get_format (SwfdecStyleSheet *style, const char *name) { diff --git a/libswfdec/swfdec_style_sheet.h b/libswfdec/swfdec_style_sheet.h index 14fe280..847d7f7 100644 --- a/libswfdec/swfdec_style_sheet.h +++ b/libswfdec/swfdec_style_sheet.h @@ -40,8 +40,6 @@ typedef struct _SwfdecStyleSheetClass SwfdecStyleSheetClass; struct _SwfdecStyleSheet { SwfdecAsObject object; - - GSList *listeners; /* text fields to update */ }; struct _SwfdecStyleSheetClass { @@ -50,12 +48,6 @@ struct _SwfdecStyleSheetClass { GType swfdec_style_sheet_get_type (void); -// FIXME: Take SwfdecTextFieldMovie -void swfdec_style_sheet_add_listener (SwfdecStyleSheet * style, - SwfdecAsObject * listener); -void swfdec_style_sheet_remove_listener (SwfdecStyleSheet * style, - SwfdecAsObject * listener); - SwfdecTextFormat *swfdec_style_sheet_get_tag_format (SwfdecStyleSheet * style, const char * name); SwfdecTextFormat *swfdec_style_sheet_get_class_format (SwfdecStyleSheet * style, diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c index ab33f55..040c336 100644 --- a/libswfdec/swfdec_text_field_movie.c +++ b/libswfdec/swfdec_text_field_movie.c @@ -1062,8 +1062,8 @@ swfdec_text_field_movie_dispose (GObject *object) if (text->style_sheet) { if (SWFDEC_IS_STYLESHEET (text->style_sheet)) { - swfdec_style_sheet_remove_listener ( - SWFDEC_STYLESHEET (text->style_sheet), SWFDEC_AS_OBJECT (text)); + g_signal_handlers_disconnect_matched (text->style_sheet, + G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, text); } text->style_sheet = NULL; } diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c index 33578b3..5d76ed4 100644 --- a/libswfdec/swfdec_text_field_movie_as.c +++ b/libswfdec/swfdec_text_field_movie_as.c @@ -897,6 +897,13 @@ swfdec_text_field_movie_get_styleSheet (SwfdecAsContext *cx, } static void +swfdec_text_field_movie_style_sheet_update (SwfdecTextFieldMovie *text) +{ + if (text->style_sheet_input) + swfdec_text_field_movie_set_text (text, text->style_sheet_input, TRUE); +} + +static void swfdec_text_field_movie_set_styleSheet (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret) @@ -923,17 +930,17 @@ swfdec_text_field_movie_set_styleSheet (SwfdecAsContext *cx, return; if (text->style_sheet != NULL && SWFDEC_IS_STYLESHEET (text->style_sheet)) { - swfdec_style_sheet_remove_listener (SWFDEC_STYLESHEET (text->style_sheet), - object); + g_signal_handlers_disconnect_by_func (text->style_sheet, + swfdec_text_field_movie_style_sheet_update, text); } text->style_sheet = value; - if (value != NULL && SWFDEC_IS_STYLESHEET (value)) { - if (text->style_sheet_input) - swfdec_text_field_movie_set_text (text, text->style_sheet_input, TRUE); + if (SWFDEC_IS_STYLESHEET (value)) { + g_signal_connect_swapped (value, "update", + G_CALLBACK (swfdec_text_field_movie_style_sheet_update), text); - swfdec_style_sheet_add_listener (SWFDEC_STYLESHEET (value), object); + swfdec_text_field_movie_style_sheet_update (text); } }