chiark / gitweb /
Fixed a few bugs
[clg] / glib / gobject.lisp
index 015f29b09753b00ce5808080459402c07f56f078..9f560d2b97de17d85b78c8ae9f87f9b5fd1ed3d7 100644 (file)
@@ -1,5 +1,5 @@
 ;; Common Lisp bindings for GTK+ v2.0
-;; Copyright (C) 2000 Espen S. Johnsen <espejohn@online.no>
+;; Copyright (C) 2000-2001 Espen S. Johnsen <esj@stud.cs.uit.no>
 ;;
 ;; This library is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU Lesser General Public
 ;; License along with this library; if not, write to the Free Software
 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-;; $Id: gobject.lisp,v 1.1 2000-08-14 16:44:30 espen Exp $
+;; $Id: gobject.lisp,v 1.6 2001-04-29 20:34:18 espen Exp $
 
 (in-package "GLIB")
 
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
-  (defclass gobject (gtype)
+  (defclass gobject (ginstance)
     ()
-    (:metaclass gtype-class)
-    (:alien-name "GObject"))
+    (:metaclass ginstance-class)
+    (:alien-name "GObject")
+    (:ref "g_object_ref")
+    (:unref "g_object_unref")))
+
+(defmethod initialize-instance ((object gobject) &rest initargs)
+  (declare (ignore initargs))
+  (setf 
+   (slot-value object 'location)
+   (%gobject-new (type-number-of object)))
+  (call-next-method))
 
-  (defclass gobject-class (gtype-class)))
+(defbinding ("g_object_new" %gobject-new) () gobject
+  (type type-number)
+  (nil null))
 
 
-;;;; Methods for gobject
+;;;; Parameter stuff
 
-;; Specializing reference-instance and unreference-instance on gobject
-;; is not really necessary but done for efficiency
+(defbinding %object-set-property () nil
+  (object gobject)
+  (name string)
+  (value gvalue))
 
-(defmethod reference-instance ((object gobject))
-  (%object-ref object)
-  object)
+(defbinding %object-get-property () nil
+  (object gobject)
+  (name string)
+  (value gvalue))
 
-(defmethod unreference-instance ((object gobject))
-  (%object-unref object))
+(defbinding %object-notify () nil
+  (object gobject)
+  (name string))
 
-(deftype-method alien-ref gobject (type-spec)
-  (declare (ignore type-spec))
-  '%object-ref)
+(defbinding object-freeze-notify () nil
+  (object gobject))
 
-(deftype-method alien-unref gobject (type-spec)
-  (declare (ignore type-spec))
-  '%object-unref)
+(defbinding object-thaw-notify () nil
+  (object gobject))
 
-(define-foreign %object-ref () pointer
-  (object (or gobject pointer)))
+(defbinding %object-set-qdata-full () nil
+  (object gobject)
+  (id quark)
+  (data unsigned-long)
+  (destroy-marshal pointer))
 
-(define-foreign %object-unref () nil
-  (object (or gobject pointer)))
 
+;;;; User data
 
-;; Parameter stuff not yet implemented
+(defun (setf object-data) (data object key &key (test #'eq))
+  (%object-set-qdata-full
+   object (quark-from-object key :test test)
+   (register-user-data data) *destroy-notify*)
+  data)
 
-; (define-foreign object-set-param () nil
-;   (object gobject)
-;   (name string)
-;   (value gvalue))
+(defbinding %object-get-qdata () unsigned-long
+  (object gobject)              
+  (id quark))
+
+(defun object-data (object key &key (test #'eq))
+  (find-user-data
+   (%object-get-qdata object (quark-from-object key :test test))))
 
-; (define-foreign object-get-param () nil
-;   (object gobject)
-;   (name string)
-;   (value gvalue :out))
 
-; (define-foreign object-queue-param-changed () nil
-;   (object gobject)
-;   (name string))
 
+;;;; Metaclass used for subclasses of gobject
 
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (defclass gobject-class (ginstance-class))
 
-;;;; Methods for gobject-class
+  (defclass direct-gobject-slot-definition (direct-virtual-slot-definition))
 
-(defmethod shared-initialize ((class gobject-class) names &rest initargs
-                             &key type-init name)
-  (declare (ignore initargs names))
-  (let ((alien
-        (alien::%heap-alien
-         (alien::make-heap-alien-info
-          :type (alien::parse-alien-type '(function (unsigned 32)))
-          :sap-form (system:foreign-symbol-address
-                     (or
-                      (first type-init)
-                      (default-alien-func-name
-                        (format
-                         nil "~A_get_type" (or name (class-name class))))))))))
-    (alien:alien-funcall alien))
-  (call-next-method))
+  (defclass effective-gobject-slot-definition
+    (effective-virtual-slot-definition)))
 
 
-; (define-foreign object-class-install-param () nil
+; (defbinding object-class-install-param () nil
 ;   (class pointer)
 ;   (id unsigned-int)
 ;   (parameter parameter))
 
-; (define-foreign object-class-find-param-spec () parameter
+; (defbinding object-class-find-param-spec () parameter
 ;   (class pointer)
 ;   (name string))
 
+
+(defmethod initialize-instance :after ((slotd direct-gobject-slot-definition)
+                                      &rest initargs &key)
+  (declare (ignore initargs))
+  (unless (slot-boundp slotd 'location)
+    ;; Find parameter name from slot name
+    (with-slots (pcl::name location) slotd
+      (setf location (signal-name-to-string pcl::name)))))
+
+(defmethod direct-slot-definition-class ((class gobject-class) initargs)
+  (case (getf initargs :allocation)
+    (:param (find-class 'direct-gobject-slot-definition))
+    (t (call-next-method))))
+
+(defmethod effective-slot-definition-class ((class gobject-class) initargs)
+  (case (getf initargs :allocation)
+    (:param (find-class 'effective-gobject-slot-definition))
+    (t (call-next-method))))
+
+(defmethod compute-virtual-slot-location
+    ((class gobject-class) (slotd effective-gobject-slot-definition)
+     direct-slotds)
+  (with-slots (type) slotd
+    (let ((param-name (slot-definition-location (first direct-slotds)))
+         (type-number (find-type-number type))
+         (reader (intern-reader-function type))
+         (writer (intern-writer-function type))
+         (destroy (intern-destroy-function type)))
+      (list
+       #'(lambda (object)
+          (with-gc-disabled
+            (let ((gvalue (gvalue-new type-number)))
+              (%object-get-property object param-name gvalue)
+              (prog1
+                  (funcall reader gvalue +gvalue-value-offset+)
+                (gvalue-free gvalue t)))))
+       #'(lambda (value object)
+          (with-gc-disabled
+            (let ((gvalue (gvalue-new type-number)))
+              (funcall writer value gvalue +gvalue-value-offset+)
+              (%object-set-property object param-name gvalue)
+              (funcall destroy gvalue +gvalue-value-offset+)
+              (gvalue-free gvalue nil)
+              value)))))))
+
+
+(defmethod validate-superclass ((class gobject-class)
+                               (super pcl::standard-class))
+  (subtypep (class-name super) 'gobject))
+    
\ No newline at end of file