2007-11-14 Emmanuele Bassi <ebassi@openedhand.com>

* clutter/clutter-scriptable.[ch]: Rename ::set_name and ::get_name
	to ::set_id and ::get_id, to avoid potential confusion with the
	ClutterActor:name property.

	* clutter/clutter-script.h:
	* clutter/clutter-script.c (clutter_script_construct_object): Use
	clutter_scriptable_set_id().

	(clutter_get_script_id): Add a public function to retrieve the ID
	used in the UI definition files from an object.

	* clutter/clutter-actor.c: Do not set the name of the actor with
	the ID set in the UI definition files.

	* tests/test-script.c: Test clutter_get_script_id().

	* clutter.symbols: Update with the new symbols.
This commit is contained in:
Emmanuele Bassi 2007-11-14 11:32:24 +00:00
parent bbf57ee461
commit b0e169d73c
10 changed files with 93 additions and 58 deletions

View File

@ -1,3 +1,23 @@
2007-11-14 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-scriptable.[ch]: Rename ::set_name and ::get_name
to ::set_id and ::get_id, to avoid potential confusion with the
ClutterActor:name property.
* clutter/clutter-script.h:
* clutter/clutter-script.c (clutter_script_construct_object): Use
clutter_scriptable_set_id().
(clutter_get_script_id): Add a public function to retrieve the ID
used in the UI definition files from an object.
* clutter/clutter-actor.c: Do not set the name of the actor with
the ID set in the UI definition files.
* tests/test-script.c: Test clutter_get_script_id().
* clutter.symbols: Update with the new symbols.
2007-11-14 Emmanuele Bassi <ebassi@openedhand.com> 2007-11-14 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/cutter-deprecated.h: Don't let everyone know from where * clutter/cutter-deprecated.h: Don't let everyone know from where

View File

@ -513,8 +513,9 @@ clutter_script_get_objects
clutter_script_unmerge_objects clutter_script_unmerge_objects
clutter_script_ensure_objects clutter_script_ensure_objects
clutter_script_get_type_from_name clutter_script_get_type_from_name
clutter_get_script_id
clutter_scriptable_get_type clutter_scriptable_get_type
clutter_scriptable_set_name clutter_scriptable_set_id
clutter_scriptable_get_name clutter_scriptable_get_id
clutter_scriptable_parse_custom_node clutter_scriptable_parse_custom_node
clutter_scriptable_set_custom_property clutter_scriptable_set_custom_property

View File

@ -75,13 +75,9 @@
#include "clutter-units.h" #include "clutter-units.h"
#include "cogl.h" #include "cogl.h"
static void clutter_scriptable_iface_init (ClutterScriptableIface *iface); G_DEFINE_ABSTRACT_TYPE (ClutterActor,
clutter_actor,
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (ClutterActor, G_TYPE_INITIALLY_UNOWNED);
clutter_actor,
G_TYPE_INITIALLY_UNOWNED,
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
clutter_scriptable_iface_init));
static guint32 __id = 0; static guint32 __id = 0;
@ -148,26 +144,6 @@ enum
static guint actor_signals[LAST_SIGNAL] = { 0, }; static guint actor_signals[LAST_SIGNAL] = { 0, };
static void
clutter_actor_scriptable_set_name (ClutterScriptable *scriptable,
const gchar *name)
{
clutter_actor_set_name (CLUTTER_ACTOR (scriptable), name);
}
static const gchar *
clutter_actor_scriptable_get_name (ClutterScriptable *scriptable)
{
return clutter_actor_get_name (CLUTTER_ACTOR (scriptable));
}
static void
clutter_scriptable_iface_init (ClutterScriptableIface *iface)
{
iface->set_name = clutter_actor_scriptable_set_name;
iface->get_name = clutter_actor_scriptable_get_name;
}
static void static void
_clutter_actor_apply_modelview_transform (ClutterActor * self); _clutter_actor_apply_modelview_transform (ClutterActor * self);

View File

@ -1168,9 +1168,9 @@ clutter_script_construct_object (ClutterScript *script,
oinfo->has_unresolved = FALSE; oinfo->has_unresolved = FALSE;
if (scriptable) if (scriptable)
clutter_scriptable_set_name (scriptable, oinfo->id); clutter_scriptable_set_id (scriptable, oinfo->id);
else else
g_object_set_data_full (object, "clutter-script-name", g_object_set_data_full (object, "clutter-script-id",
g_strdup (oinfo->id), g_strdup (oinfo->id),
g_free); g_free);
@ -1688,6 +1688,29 @@ clutter_script_get_type_from_name (ClutterScript *script,
return CLUTTER_SCRIPT_GET_CLASS (script)->get_type_from_name (script, type_name); return CLUTTER_SCRIPT_GET_CLASS (script)->get_type_from_name (script, type_name);
} }
/**
* clutter_get_script_id:
* @gobject: a #GObject
*
* Retrieves the Clutter script id, if any.
*
* Return value: the script id, or %NULL if @object was not defined inside
* a UI definition file. The returned string is owned by the object and
* should never be modified or freed.
*
* Since: 0.6
*/
G_CONST_RETURN gchar *
clutter_get_script_id (GObject *gobject)
{
g_return_val_if_fail (G_IS_OBJECT (gobject), NULL);
if (CLUTTER_IS_SCRIPTABLE (gobject))
return clutter_scriptable_get_id (CLUTTER_SCRIPTABLE (gobject));
else
return g_object_get_data (gobject, "clutter-script-id");
}
GQuark GQuark
clutter_script_error_quark (void) clutter_script_error_quark (void)
{ {

View File

@ -109,6 +109,8 @@ void clutter_script_ensure_objects (ClutterScript *script);
GType clutter_script_get_type_from_name (ClutterScript *script, GType clutter_script_get_type_from_name (ClutterScript *script,
const gchar *type_name); const gchar *type_name);
G_CONST_RETURN gchar *clutter_get_script_id (GObject *object);
G_END_DECLS G_END_DECLS
#endif /* __CLUTTER_SCRIPT_H__ */ #endif /* __CLUTTER_SCRIPT_H__ */

View File

@ -66,57 +66,61 @@ clutter_scriptable_get_type (void)
} }
/** /**
* clutter_scriptable_set_name: * clutter_scriptable_set_id:
* @scriptable: a #ClutterScriptable * @scriptable: a #ClutterScriptable
* @name: the name of the object * @id: the #ClutterScript id of the object
* *
* Sets @name as the name for this instance of #ClutterScriptableIface. * Sets @id as the unique Clutter script it for this instance of
* This name can be used by user interface designer applications. * #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 * Since: 0.6
*/ */
void void
clutter_scriptable_set_name (ClutterScriptable *scriptable, clutter_scriptable_set_id (ClutterScriptable *scriptable,
const gchar *name) const gchar *id)
{ {
ClutterScriptableIface *iface; ClutterScriptableIface *iface;
g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable)); g_return_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable));
g_return_if_fail (name != NULL); g_return_if_fail (id != NULL);
iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable); iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
if (iface->set_name) if (iface->set_id)
iface->set_name (scriptable, name); iface->set_id (scriptable, id);
else else
g_object_set_data_full (G_OBJECT (scriptable), g_object_set_data_full (G_OBJECT (scriptable),
"clutter-script-name", "clutter-script-id",
g_strdup (name), g_strdup (id),
g_free); g_free);
} }
/** /**
* clutter_scriptable_get_name: * clutter_scriptable_get_id:
* @scriptable: a #ClutterScriptable * @scriptable: a #ClutterScriptable
* *
* Retrieves the name of @scriptable set using clutter_scriptable_set_name(). * Retrieves the id of @scriptable set using clutter_scriptable_set_id().
* *
* Return value: the name of the object. The returned string is owned by * Return value: the id of the object. The returned string is owned by
* the scriptable object and should never be modified of freed * the scriptable object and should never be modified of freed
* *
* Since: 0.6 * Since: 0.6
*/ */
G_CONST_RETURN gchar * G_CONST_RETURN gchar *
clutter_scriptable_get_name (ClutterScriptable *scriptable) clutter_scriptable_get_id (ClutterScriptable *scriptable)
{ {
ClutterScriptableIface *iface; ClutterScriptableIface *iface;
g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), NULL); g_return_val_if_fail (CLUTTER_IS_SCRIPTABLE (scriptable), NULL);
iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable); iface = CLUTTER_SCRIPTABLE_GET_IFACE (scriptable);
if (iface->get_name) if (iface->get_id)
return iface->get_name (scriptable); return iface->get_id (scriptable);
else else
return g_object_get_data (G_OBJECT (scriptable), "clutter-script-name"); return g_object_get_data (G_OBJECT (scriptable), "clutter-script-id");
} }
/** /**

View File

@ -43,8 +43,8 @@ typedef struct _ClutterScriptableIface ClutterScriptableIface;
/** /**
* ClutterScriptableIface: * ClutterScriptableIface:
* @set_name: virtual function for setting the name of a scriptable object * @set_id: virtual function for setting the id of a scriptable object
* @get_name: virtual function for getting the name of a scriptable object * @get_id: virtual function for getting the id of a scriptable object
* @parse_custom_node: virtual function for parsing complex data containers * @parse_custom_node: virtual function for parsing complex data containers
* into GObject properties * into GObject properties
* @set_custom_property: virtual function for setting a custom property * @set_custom_property: virtual function for setting a custom property
@ -59,9 +59,9 @@ struct _ClutterScriptableIface
{ {
GTypeInterface g_iface; GTypeInterface g_iface;
void (* set_name) (ClutterScriptable *scriptable, void (* set_id) (ClutterScriptable *scriptable,
const gchar *name); const gchar *name);
const gchar *(* get_name) (ClutterScriptable *scriptable); const gchar *(* get_id) (ClutterScriptable *scriptable);
gboolean (* parse_custom_node) (ClutterScriptable *scriptable, gboolean (* parse_custom_node) (ClutterScriptable *scriptable,
ClutterScript *script, ClutterScript *script,
@ -76,9 +76,9 @@ struct _ClutterScriptableIface
GType clutter_scriptable_get_type (void) G_GNUC_CONST; GType clutter_scriptable_get_type (void) G_GNUC_CONST;
void clutter_scriptable_set_name (ClutterScriptable *scriptable, void clutter_scriptable_set_id (ClutterScriptable *scriptable,
const gchar *name); const gchar *id);
G_CONST_RETURN gchar *clutter_scriptable_get_name (ClutterScriptable *scriptable); G_CONST_RETURN gchar *clutter_scriptable_get_id (ClutterScriptable *scriptable);
gboolean clutter_scriptable_parse_custom_node (ClutterScriptable *scriptable, gboolean clutter_scriptable_parse_custom_node (ClutterScriptable *scriptable,
ClutterScript *script, ClutterScript *script,
GValue *value, GValue *value,

View File

@ -1,3 +1,8 @@
2007-11-14 Emmanuele Bassi <ebassi@openedhand.com>
* clutter-sections.txt: Update with the ClutterScriptable changes
and add clutter_get_script_id().
2007-10-28 Matthew Allum <mallum@openedhand.com> 2007-10-28 Matthew Allum <mallum@openedhand.com>
* clutter-animation.sgml: * clutter-animation.sgml:

View File

@ -1101,6 +1101,7 @@ clutter_script_get_objects
clutter_script_unmerge_objects clutter_script_unmerge_objects
clutter_script_ensure_objects clutter_script_ensure_objects
clutter_script_get_type_from_name clutter_script_get_type_from_name
clutter_get_script_id
<SUBSECTION Standard> <SUBSECTION Standard>
CLUTTER_TYPE_SCRIPT CLUTTER_TYPE_SCRIPT
CLUTTER_SCRIPT CLUTTER_SCRIPT
@ -1119,8 +1120,8 @@ clutter_script_error_quark
<FILE>clutter-scriptable</FILE> <FILE>clutter-scriptable</FILE>
<TITLE>ClutterScriptable</TITLE> <TITLE>ClutterScriptable</TITLE>
ClutterScriptableIface ClutterScriptableIface
clutter_scriptable_set_name clutter_scriptable_set_id
clutter_scriptable_get_name clutter_scriptable_get_id
clutter_scriptable_parse_custom_node clutter_scriptable_parse_custom_node
clutter_scriptable_set_custom_property clutter_scriptable_set_custom_property
<SUBSECTION Standard> <SUBSECTION Standard>

View File

@ -66,6 +66,7 @@ blue_button_press (ClutterActor *actor,
ClutterButtonEvent *event, ClutterButtonEvent *event,
gpointer data) gpointer data)
{ {
g_print ("[*] Pressed `%s'\n", clutter_get_script_id (G_OBJECT (actor)));
g_print ("[*] Unmerging objects with merge id: %d\n", merge_id); g_print ("[*] Unmerging objects with merge id: %d\n", merge_id);
clutter_script_unmerge_objects (script, merge_id); clutter_script_unmerge_objects (script, merge_id);
@ -80,6 +81,8 @@ red_button_press (ClutterActor *actor,
{ {
GObject *timeline; GObject *timeline;
g_print ("[*] Pressed `%s'\n", clutter_get_script_id (G_OBJECT (actor)));
timeline = clutter_script_get_object (script, "main-timeline"); timeline = clutter_script_get_object (script, "main-timeline");
g_assert (CLUTTER_IS_TIMELINE (timeline)); g_assert (CLUTTER_IS_TIMELINE (timeline));