From e88bb84ca2485190c57e04e7c09ee4059fe7ac4a Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Tue, 15 Feb 2011 21:12:09 +0100 Subject: [PATCH] [AdgStyle] Implemented "apply" and "invalidate" signals Changed the virtual function "apply" to a signal handler and added the new "invalidate" signal. This will help in shaping the AdgPangoStyle implementation, which will be inherited from AdgFontStyle and requires the overriding of the invalidation infrastructure. --- src/adg/adg-marshal.genmarshal | 1 + src/adg/adg-style.c | 77 ++++++++++++++++++++++++++++++++++++------ src/adg/adg-style.h | 3 ++ 3 files changed, 71 insertions(+), 10 deletions(-) diff --git a/src/adg/adg-marshal.genmarshal b/src/adg/adg-marshal.genmarshal index 670e5e88..cf1710dd 100644 --- a/src/adg/adg-marshal.genmarshal +++ b/src/adg/adg-marshal.genmarshal @@ -2,3 +2,4 @@ VOID:VOID VOID:POINTER VOID:OBJECT VOID:STRING,POINTER +VOID:OBJECT,POINTER diff --git a/src/adg/adg-style.c b/src/adg/adg-style.c index 0246c90c..76362a33 100644 --- a/src/adg/adg-style.c +++ b/src/adg/adg-style.c @@ -40,16 +40,63 @@ G_DEFINE_ABSTRACT_TYPE(AdgStyle, adg_style, G_TYPE_OBJECT); +enum { + INVALIDATE, + APPLY, + LAST_SIGNAL +}; -static void _adg_apply (AdgStyle *style, - AdgEntity *entity, - cairo_t *cr); + +static void _adg_apply (AdgStyle *style, + AdgEntity *entity, + cairo_t *cr); +static guint _adg_signals[LAST_SIGNAL] = { 0 }; static void adg_style_class_init(AdgStyleClass *klass) { + klass->invalidate = NULL; klass->apply = _adg_apply; + + /** + * AdgStyle::invalidate: + * @style: an #AdgStyle + * + * Invalidates the @style, that is resets all the cache, if any, + * retained by the internal implementation. + * + * This is usually emitted from the property setter code of new + * style implementations when it changes something fundamental + * for the style itsself. + **/ + _adg_signals[INVALIDATE] = + g_signal_new("invalidate", + G_OBJECT_CLASS_TYPE(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(AdgStyleClass, invalidate), + NULL, NULL, + adg_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * AdgStyle::apply: + * @style: an #AdgStyle + * @entity: the caller #AdgEntity + * @cr: the #cairo_t context + * + * Applies @style to @cr so the next rendering operations will be + * done accordling to this style directives. The @entity parameter + * is used to resolve the internal dresses of @style, if any. + **/ + _adg_signals[APPLY] = + g_signal_new("apply", + G_OBJECT_CLASS_TYPE(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(AdgStyleClass, apply), + NULL, NULL, + adg_marshal_VOID__OBJECT_POINTER, + G_TYPE_NONE, 2, ADG_TYPE_ENTITY, G_TYPE_POINTER); } static void @@ -59,14 +106,27 @@ adg_style_init(AdgStyle *style) /** + * adg_style_invalidate: + * @style: an #AdgStyle derived style + * + * Emits the #AdgStyle::invalidate signal on @style. + **/ +void +adg_style_invalidate(AdgStyle *style) +{ + g_return_if_fail(ADG_IS_STYLE(style)); + + g_signal_emit(style, _adg_signals[INVALIDATE], 0); +} + +/** * adg_style_apply: * @style: an #AdgStyle derived style * @entity: the caller #AdgEntity * @cr: the subject cairo context * - * Applies @style to @cr so the next rendering operations will be - * done accordling to this style directives. The @entity parameter - * is used to resolve the internal dresses of @style, if any. + * Emits the #AdgStyle::apply signal on @style, passing @entity and + * @cr as parameters to the signal. **/ void adg_style_apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr) @@ -77,10 +137,7 @@ adg_style_apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr) g_return_if_fail(ADG_IS_ENTITY(entity)); g_return_if_fail(cr != NULL); - klass = ADG_STYLE_GET_CLASS(style); - - if (klass->apply) - klass->apply(style, entity, cr); + g_signal_emit(style, _adg_signals[APPLY], 0, entity, cr); } diff --git a/src/adg/adg-style.h b/src/adg/adg-style.h index 22d03d29..057de4b1 100644 --- a/src/adg/adg-style.h +++ b/src/adg/adg-style.h @@ -52,6 +52,8 @@ struct _AdgStyleClass { /*< private >*/ GObjectClass parent_class; /*< public >*/ + /* Signals */ + void (*invalidate) (AdgStyle *style); void (*apply) (AdgStyle *style, AdgEntity *entity, cairo_t *cr); @@ -60,6 +62,7 @@ struct _AdgStyleClass { GType adg_style_get_type (void) G_GNUC_CONST; +void adg_style_invalidate (AdgStyle *style); void adg_style_apply (AdgStyle *style, AdgEntity *entity, cairo_t *cr); -- 2.11.4.GIT