1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011 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.
23 * @short_description: The base class of all styling objects
25 * This is the fundamental abstract class for styles.
31 * All fields are private and should not be used directly.
32 * Use its public methods instead.
36 #include "adg-internal.h"
38 #include "adg-style.h"
41 #define _ADG_OLD_OBJECT_CLASS ((GObjectClass *) adg_style_parent_class)
44 G_DEFINE_ABSTRACT_TYPE(AdgStyle
, adg_style
, G_TYPE_OBJECT
)
53 static void _adg_dispose (GObject
*object
);
54 static void _adg_apply (AdgStyle
*style
,
57 static guint _adg_signals
[LAST_SIGNAL
] = { 0 };
61 adg_style_class_init(AdgStyleClass
*klass
)
63 GObjectClass
*gobject_class
;
65 gobject_class
= (GObjectClass
*) klass
;
67 gobject_class
->dispose
= _adg_dispose
;
69 klass
->invalidate
= NULL
;
70 klass
->apply
= _adg_apply
;
73 * AdgStyle::invalidate:
74 * @style: an #AdgStyle
76 * Invalidates the @style, that is resets all the cache, if any,
77 * retained by the internal implementation.
79 * This signal is emitted while disposing @style, so be sure it
80 * can be called more than once without harms. Furthermore it
81 * will be emitted from property setter code of new implementations
82 * to force the recomputation of the cache.
84 _adg_signals
[INVALIDATE
] =
85 g_signal_new("invalidate",
86 G_OBJECT_CLASS_TYPE(klass
),
88 G_STRUCT_OFFSET(AdgStyleClass
, invalidate
),
90 adg_marshal_VOID__VOID
,
95 * @style: an #AdgStyle
96 * @entity: the caller #AdgEntity
97 * @cr: the #cairo_t context
99 * Applies @style to @cr so the next rendering operations will be
100 * done accordling to this style directives. The @entity parameter
101 * is used to resolve the internal dresses of @style, if any.
103 _adg_signals
[APPLY
] =
104 g_signal_new("apply",
105 G_OBJECT_CLASS_TYPE(klass
),
107 G_STRUCT_OFFSET(AdgStyleClass
, apply
),
109 adg_marshal_VOID__OBJECT_POINTER
,
110 G_TYPE_NONE
, 2, ADG_TYPE_ENTITY
, G_TYPE_POINTER
);
114 adg_style_init(AdgStyle
*style
)
119 _adg_dispose(GObject
*object
)
121 g_signal_emit(object
, _adg_signals
[INVALIDATE
], 0);
123 if (_ADG_OLD_OBJECT_CLASS
->dispose
!= NULL
)
124 _ADG_OLD_OBJECT_CLASS
->dispose(object
);
129 * adg_style_invalidate:
130 * @style: an #AdgStyle derived style
132 * Emits the #AdgStyle::invalidate signal on @style. This signal
133 * is always emitted while disposing @style, so be sure it
134 * can be called more than once without harms.
137 * This function is only useful in new style implementations.
141 adg_style_invalidate(AdgStyle
*style
)
143 g_return_if_fail(ADG_IS_STYLE(style
));
145 g_signal_emit(style
, _adg_signals
[INVALIDATE
], 0);
150 * @style: an #AdgStyle derived style
151 * @entity: the caller #AdgEntity
152 * @cr: the subject cairo context
154 * Emits the #AdgStyle::apply signal on @style, passing @entity and
155 * @cr as parameters to the signal.
158 adg_style_apply(AdgStyle
*style
, AdgEntity
*entity
, cairo_t
*cr
)
160 g_return_if_fail(ADG_IS_STYLE(style
));
161 g_return_if_fail(ADG_IS_ENTITY(entity
));
162 g_return_if_fail(cr
!= NULL
);
164 g_signal_emit(style
, _adg_signals
[APPLY
], 0, entity
, cr
);
169 _adg_apply(AdgStyle
*style
, AdgEntity
*entity
, cairo_t
*cr
)
171 /* The apply method must be defined */
172 g_warning(_("%s: `apply' method not implemented for type `%s'"),
173 G_STRLOC
, g_type_name(G_OBJECT_TYPE(style
)));