seed r643 - in trunk: libseed tests



Author: racarr
Date: Sun Jan  4 15:47:33 2009
New Revision: 643
URL: http://svn.gnome.org/viewvc/seed?rev=643&view=rev

Log:
Add GObject propery installation support.

Added:
   trunk/tests/gtype-property.js   (contents, props changed)
Modified:
   trunk/libseed/seed-gtype.c
   trunk/tests/Makefile.am

Modified: trunk/libseed/seed-gtype.c
==============================================================================
--- trunk/libseed/seed-gtype.c	(original)
+++ trunk/libseed/seed-gtype.c	Sun Jan  4 15:47:33 2009
@@ -351,6 +351,45 @@
 	return (JSValueRef) seed_value_from_uint(ctx, signal_id, exception);
 }
 
+static void seed_gtype_set_property(GObject * object,
+									guint property_id,
+									const GValue *value,
+									GParamSpec *spec)
+{
+	JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+	gchar * name = g_strjoin(NULL, "_", spec->name, NULL);
+	JSObjectRef jsobj = (JSObjectRef)seed_value_from_object(ctx, object, 0);
+	
+	seed_object_set_property(ctx, 
+							 jsobj, 
+							 name, 
+							 seed_value_from_gvalue(ctx, 
+													(GValue *)value, 
+													0));
+	
+	g_free(name);
+	JSGlobalContextRelease((JSGlobalContextRef) ctx);
+}
+
+static void seed_gtype_get_property(GObject * object,
+									guint property_id,
+									GValue *value,
+									GParamSpec *spec)
+{
+	// TODO: Exceptions
+	JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+	gchar * name = g_strjoin(NULL, "_", spec->name, NULL);
+	JSObjectRef jsobj = (JSObjectRef) seed_value_from_object(ctx, object, 0);
+	JSValueRef jsval = seed_object_get_property(ctx, jsobj,
+												name);
+	
+	seed_gvalue_from_seed_value(ctx, jsval, spec->owner_type,
+								value, 0);
+	
+	g_free(name);
+	JSGlobalContextRelease((JSGlobalContextRef) ctx);
+}
+
 static void
 seed_handle_class_init_closure(ffi_cif * cif,
 							   void *result, void **args, void *userdata)
@@ -361,6 +400,10 @@
 	JSValueRef exception = 0;
 	JSContextRef ctx = JSGlobalContextCreateInGroup(context_group,
 													0);
+	GObjectClass * klass = *(GObjectClass **) args[0];
+	
+	klass->get_property = seed_gtype_get_property;
+	klass->set_property = seed_gtype_set_property;
 
 	type = (GType) JSObjectGetPrivate(*(JSObjectRef *) args[1]);
 	jsargs[0] = seed_make_pointer(ctx, *(gpointer *) args[0]);

Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am	(original)
+++ trunk/tests/Makefile.am	Sun Jan  4 15:47:33 2009
@@ -5,6 +5,7 @@
     native-closure-exception.js \
     struct-enumerate.js \
     gtype-class-init-exception.js \
+    gtype-property.js        \
     struct-union-enumerate.js \
     compare.js \
     include-syntax.js \

Added: trunk/tests/gtype-property.js
==============================================================================
--- (empty file)
+++ trunk/tests/gtype-property.js	Sun Jan  4 15:47:33 2009
@@ -0,0 +1,36 @@
+#!/usr/bin/env seed
+// Returns: 0
+// STDIN:
+// STDOUT:1\.000000\n0\.000000
+// STDERR:
+   // Returns: 0
+   // STDIN:
+   // STDOUT:In klass init\nIn constructor for \[object HelloWindow\]\nPrototypes!\nIn map, verifying widget\.title : Hello!
+   // STDERR:
+
+Seed.import_namespace("Gtk");
+Seed.import_namespace("GObject");
+Gtk.init(null, null);
+
+HelloWindowType = {
+parent: Gtk.Window.type,
+name: "HelloWindow",
+class_init: function(klass, prototype)
+{
+	klass.install_property(GObject.param_spec_boolean("test",
+													  "test property",
+													  "A test property!",
+													  false,
+													  GObject.ParamFlags.Readable | GObject.ParamFlags.Writable));
+},
+instance_init: function(klass)
+{
+	
+}};
+
+HelloWindow = new GType(HelloWindowType);
+w = new HelloWindow({test: true});
+Seed.print(w.test);
+w = new HelloWindow();
+Seed.print(w.test);
+	  



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]