4 * An OpenGL based 'interactive canvas' library.
6 * Authored By Matthew Allum <mallum@openedhand.com>
7 * Emmanuele Bassi <ebassi@openedhand.com>
9 * Copyright (C) 2006 OpenedHand
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
28 * SECTION:clutter-scriptable
29 * @short_description: Override the UI definition parsing
31 * The #ClutterScriptableIface interface exposes the UI definition parsing
32 * process to external classes. By implementing this interface, a class can
33 * override the UI definition parsing and transform complex data types into
34 * GObject properties, or allow custom properties.
36 * #ClutterScriptable is available since Clutter 0.6
48 #include "clutter-scriptable.h"
49 #include "clutter-script-private.h"
51 #include "clutter-private.h"
52 #include "clutter-debug.h"
54 typedef ClutterScriptableIface ClutterScriptableInterface;
56 G_DEFINE_INTERFACE (ClutterScriptable, clutter_scriptable, G_TYPE_OBJECT);
59 clutter_scriptable_default_init (ClutterScriptableInterface *iface)
64 * clutter_scriptable_set_id:
65 * @scriptable: a #ClutterScriptable
66 * @id_: the #ClutterScript id of the object
68 * Sets @id_ as the unique Clutter script it for this instance of
69 * #ClutterScriptableIface.
71 * This name can be used by user interface designer applications to
72 * define a unique name for an object constructable using the UI
73 * definition language parsed by #ClutterScript.
78 clutter_scriptable_set_id (ClutterScriptable *scriptable,
81 ClutterScriptableIface *iface;
83 g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable));
84 g_return_if_fail (id_ != NULL);
86 iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
88 iface->set_id (scriptable, id_);
90 g_object_set_data_full (G_OBJECT (scriptable),
97 * clutter_scriptable_get_id:
98 * @scriptable: a #ClutterScriptable
100 * Retrieves the id of @scriptable set using clutter_scriptable_set_id().
102 * Return value: the id of the object. The returned string is owned by
103 * the scriptable object and should never be modified of freed
108 clutter_scriptable_get_id (ClutterScriptable *scriptable)
110 ClutterScriptableIface *iface;
112 g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), NULL);
114 iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
116 return iface->get_id (scriptable);
118 return g_object_get_data (G_OBJECT (scriptable), "clutter-script-id");
122 * clutter_scriptable_parse_custom_node:
123 * @scriptable: a #ClutterScriptable
124 * @script: the #ClutterScript creating the scriptable instance
125 * @value: the generic value to be set
126 * @name: the name of the node
127 * @node: the JSON node to be parsed
129 * Parses the passed JSON node. The implementation must set the type
130 * of the passed #GValue pointer using g_value_init().
132 * Return value: %TRUE if the node was successfully parsed, %FALSE otherwise.
137 clutter_scriptable_parse_custom_node (ClutterScriptable *scriptable,
138 ClutterScript *script,
143 ClutterScriptableIface *iface;
145 g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), FALSE);
146 g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE);
147 g_return_val_if_fail (name != NULL, FALSE);
148 g_return_val_if_fail (node != NULL, FALSE);
150 iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
151 if (iface->parse_custom_node)
152 return iface->parse_custom_node (scriptable, script, value, name, node);
158 * clutter_scriptable_set_custom_property:
159 * @scriptable: a #ClutterScriptable
160 * @script: the #ClutterScript creating the scriptable instance
161 * @name: the name of the property
162 * @value: the value of the property
164 * Overrides the common properties setting. The underlying virtual
165 * function should be used when implementing custom properties.
170 clutter_scriptable_set_custom_property (ClutterScriptable *scriptable,
171 ClutterScript *script,
175 ClutterScriptableIface *iface;
177 g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable));
178 g_return_if_fail (CLUTTER_IS_SCRIPT (script));
179 g_return_if_fail (name != NULL);
180 g_return_if_fail (value != NULL);
182 iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
183 if (iface->set_custom_property)
184 iface->set_custom_property (scriptable, script, name, value);