build: depends on cairo-gobject if introspection is enabled
[adg.git] / src / adg / adg-style.c
blob14bb72db85783ef1679a27bc43d7be9eca7b588f
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 Nicola Fontana <ntd at entidi.it>
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 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
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:adg-style
23 * @short_description: The base class of all styling objects
25 * This is the fundamental abstract class for styles.
27 * Since: 1.0
28 **/
30 /**
31 * AdgStyle:
33 * All fields are private and should not be used directly.
34 * Use its public methods instead.
36 * Since: 1.0
37 **/
39 /**
40 * AdgStyleClass:
41 * @invalidate: virtual method to reset the style.
42 * @apply: abstract virtual to apply a style to a cairo context.
44 * The default @invalidate handler does not do anything.
46 * The virtual method @apply *must* be implemented by any derived class.
47 * The default implementation will trigger an error if called.
49 * Since: 1.0
50 **/
53 #include "adg-internal.h"
55 #include "adg-style.h"
58 #define _ADG_OLD_OBJECT_CLASS ((GObjectClass *) adg_style_parent_class)
61 G_DEFINE_ABSTRACT_TYPE(AdgStyle, adg_style, G_TYPE_OBJECT)
63 enum {
64 INVALIDATE,
65 APPLY,
66 LAST_SIGNAL
69 static void _adg_dispose (GObject *object);
70 static void _adg_apply (AdgStyle *style,
71 AdgEntity *entity,
72 cairo_t *cr);
73 static guint _adg_signals[LAST_SIGNAL] = { 0 };
76 static void
77 adg_style_class_init(AdgStyleClass *klass)
79 GObjectClass *gobject_class;
81 gobject_class = (GObjectClass *) klass;
83 gobject_class->dispose = _adg_dispose;
85 klass->invalidate = NULL;
86 klass->apply = _adg_apply;
88 /**
89 * AdgStyle::invalidate:
90 * @style: an #AdgStyle
92 * Invalidates the @style, that is resets all the cache, if any,
93 * retained by the internal implementation.
95 * This signal is emitted while disposing @style, so be sure it
96 * can be called more than once without harms. Furthermore it
97 * will be emitted from property setter code of new implementations
98 * to force the recomputation of the cache.
100 * Since: 1.0
102 _adg_signals[INVALIDATE] =
103 g_signal_new("invalidate",
104 G_OBJECT_CLASS_TYPE(klass),
105 G_SIGNAL_RUN_LAST,
106 G_STRUCT_OFFSET(AdgStyleClass, invalidate),
107 NULL, NULL,
108 adg_marshal_VOID__VOID,
109 G_TYPE_NONE, 0);
112 * AdgStyle::apply:
113 * @style: an #AdgStyle
114 * @entity: the caller #AdgEntity
115 * @cr: the #cairo_t context
117 * Applies @style to @cr so the next rendering operations will be
118 * done accordling to this style directives. The @entity parameter
119 * is used to resolve the internal dresses of @style, if any.
121 * Since: 1.0
123 _adg_signals[APPLY] =
124 g_signal_new("apply",
125 G_OBJECT_CLASS_TYPE(klass),
126 G_SIGNAL_RUN_LAST,
127 G_STRUCT_OFFSET(AdgStyleClass, apply),
128 NULL, NULL,
129 adg_marshal_VOID__OBJECT_POINTER,
130 G_TYPE_NONE, 2, ADG_TYPE_ENTITY, G_TYPE_POINTER);
133 static void
134 adg_style_init(AdgStyle *style)
138 static void
139 _adg_dispose(GObject *object)
141 g_signal_emit(object, _adg_signals[INVALIDATE], 0);
143 if (_ADG_OLD_OBJECT_CLASS->dispose != NULL)
144 _ADG_OLD_OBJECT_CLASS->dispose(object);
149 * adg_style_invalidate:
150 * @style: an #AdgStyle derived style
152 * Emits the #AdgStyle::invalidate signal on @style. This signal
153 * is always emitted while disposing @style, so be sure it
154 * can be called more than once without harms.
156 * <note><para>
157 * This function is only useful in new style implementations.
158 * </para></note>
160 * Since: 1.0
162 void
163 adg_style_invalidate(AdgStyle *style)
165 g_return_if_fail(ADG_IS_STYLE(style));
167 g_signal_emit(style, _adg_signals[INVALIDATE], 0);
171 * adg_style_apply:
172 * @style: an #AdgStyle derived style
173 * @entity: the caller #AdgEntity
174 * @cr: the subject cairo context
176 * Emits the #AdgStyle::apply signal on @style, passing @entity and
177 * @cr as parameters to the signal.
179 * Since: 1.0
181 void
182 adg_style_apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr)
184 g_return_if_fail(ADG_IS_STYLE(style));
185 g_return_if_fail(ADG_IS_ENTITY(entity));
186 g_return_if_fail(cr != NULL);
188 g_signal_emit(style, _adg_signals[APPLY], 0, entity, cr);
192 static void
193 _adg_apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr)
195 /* The apply method must be defined */
196 g_warning(_("%s: `apply' method not implemented for type `%s'"),
197 G_STRLOC, g_type_name(G_OBJECT_TYPE(style)));