summaryrefslogtreecommitdiff
path: root/clutter/clutter/clutter-scriptable.c
blob: 25b983c167a61373ff82250da827fc9a0f0b90bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * Clutter.
 *
 * An OpenGL based 'interactive canvas' library.
 *
 * Authored By Matthew Allum  <mallum@openedhand.com>
 *             Emmanuele Bassi  <ebassi@openedhand.com>
 *
 * Copyright (C) 2006 OpenedHand
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 *
 */

/**
 * SECTION:clutter-scriptable
 * @short_description: Override the UI definition parsing
 *
 * The #ClutterScriptableIface interface exposes the UI definition parsing
 * process to external classes. By implementing this interface, a class can
 * override the UI definition parsing and transform complex data types into
 * GObject properties, or allow custom properties.
 *
 * #ClutterScriptable is available since Clutter 0.6
 */

#include "clutter-build-config.h"

#include <string.h>
#include <stdlib.h>

#include <glib.h>

#include "clutter-scriptable.h"
#include "clutter-script-private.h"

#include "clutter-private.h"
#include "clutter-debug.h"

typedef ClutterScriptableIface  ClutterScriptableInterface;

G_DEFINE_INTERFACE (ClutterScriptable, clutter_scriptable, G_TYPE_OBJECT);

static void
clutter_scriptable_default_init (ClutterScriptableInterface *iface)
{
}

/**
 * clutter_scriptable_set_id:
 * @scriptable: a #ClutterScriptable
 * @id_: the #ClutterScript id of the object
 *
 * Sets @id_ as the unique Clutter script it for this instance of
 * #ClutterScriptableIface.
 *
 * This name can be used by user interface designer applications to
 * define a unique name for an object constructable using the UI
 * definition language parsed by #ClutterScript.
 *
 * Since: 0.6
 */
void
clutter_scriptable_set_id (ClutterScriptable *scriptable,
                           const gchar       *id_)
{
  ClutterScriptableIface *iface;

  g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable));
  g_return_if_fail (id_ != NULL);

  iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
  if (iface->set_id)
    iface->set_id (scriptable, id_);
  else
    g_object_set_data_full (G_OBJECT (scriptable),
                            "clutter-script-id",
                            g_strdup (id_),
                            g_free);
}

/**
 * clutter_scriptable_get_id:
 * @scriptable: a #ClutterScriptable
 *
 * Retrieves the id of @scriptable set using clutter_scriptable_set_id().
 *
 * Return value: the id of the object. The returned string is owned by
 *   the scriptable object and should never be modified of freed
 *
 * Since: 0.6
 */
const gchar *
clutter_scriptable_get_id (ClutterScriptable *scriptable)
{
  ClutterScriptableIface *iface;

  g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), NULL);

  iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
  if (iface->get_id)
    return iface->get_id (scriptable);
  else
    return g_object_get_data (G_OBJECT (scriptable), "clutter-script-id");
}

/**
 * clutter_scriptable_parse_custom_node:
 * @scriptable: a #ClutterScriptable
 * @script: the #ClutterScript creating the scriptable instance
 * @value: the generic value to be set
 * @name: the name of the node
 * @node: the JSON node to be parsed
 *
 * Parses the passed JSON node. The implementation must set the type
 * of the passed #GValue pointer using g_value_init().
 *
 * Return value: %TRUE if the node was successfully parsed, %FALSE otherwise.
 *
 * Since: 0.6
 */
gboolean
clutter_scriptable_parse_custom_node (ClutterScriptable *scriptable,
                                      ClutterScript     *script,
                                      GValue            *value,
                                      const gchar       *name,
                                      JsonNode          *node)
{
  ClutterScriptableIface *iface;

  g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), FALSE);
  g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE);
  g_return_val_if_fail (name != NULL, FALSE);
  g_return_val_if_fail (node != NULL, FALSE);

  iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
  if (iface->parse_custom_node)
    return iface->parse_custom_node (scriptable, script, value, name, node);

  return FALSE;
}

/**
 * clutter_scriptable_set_custom_property:
 * @scriptable: a #ClutterScriptable
 * @script: the #ClutterScript creating the scriptable instance
 * @name: the name of the property
 * @value: the value of the property
 *
 * Overrides the common properties setting. The underlying virtual
 * function should be used when implementing custom properties.
 *
 * Since: 0.6
 */
void
clutter_scriptable_set_custom_property (ClutterScriptable *scriptable,
                                        ClutterScript     *script,
                                        const gchar       *name,
                                        const GValue      *value)
{
  ClutterScriptableIface *iface;

  g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable));
  g_return_if_fail (CLUTTER_IS_SCRIPT (script));
  g_return_if_fail (name != NULL);
  g_return_if_fail (value != NULL);

  iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
  if (iface->set_custom_property)
    iface->set_custom_property (scriptable, script, name, value);
}