X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/a90441812ae6371c08c3e3cb6eac47168115b9c7..691d6718b76e5a6623b3277d5b37db4722569f29:/glib/gobject.lisp diff --git a/glib/gobject.lisp b/glib/gobject.lisp index f0d33b4..8b9a651 100644 --- a/glib/gobject.lisp +++ b/glib/gobject.lisp @@ -1,5 +1,5 @@ ;; Common Lisp bindings for GTK+ v2.0 -;; Copyright (C) 2000 Espen S. Johnsen +;; Copyright (C) 2000-2001 Espen S. Johnsen ;; ;; This library is free software; you can redistribute it and/or ;; modify it under the terms of the GNU Lesser General Public @@ -15,7 +15,7 @@ ;; 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.4 2001-01-28 14:17:12 espen Exp $ +;; $Id: gobject.lisp,v 1.8 2001-05-29 15:50:31 espen Exp $ (in-package "GLIB") @@ -24,66 +24,46 @@ (defclass gobject (ginstance) () (:metaclass ginstance-class) - (:alien-name "GObject"))) + (: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)) -;;;; Object construction - -(define-foreign ("g_object_new" %gobject-new) () gobject +(defbinding (%gobject-new "g_object_new") () pointer (type type-number) (nil null)) -;;;; Reference counting for gobject - -;; Specializing reference-instance and unreference-instance on gobject -;; is not really necessary but done for efficiency - -(defmethod reference-instance ((object gobject)) - (%object-ref object) - object) - -(defmethod unreference-instance ((object gobject)) - (%object-unref object)) - -(deftype-method alien-ref gobject (type-spec) - (declare (ignore type-spec)) - '%object-ref) - -(deftype-method alien-unref gobject (type-spec) - (declare (ignore type-spec)) - '%object-unref) - -(define-foreign %object-ref () pointer - (object (or gobject pointer))) - -(define-foreign %object-unref () nil - (object (or gobject pointer))) - ;;;; Parameter stuff -(define-foreign %object-set-property () nil +(defbinding %object-set-property () nil (object gobject) (name string) (value gvalue)) -(define-foreign %object-get-property () nil +(defbinding %object-get-property () nil (object gobject) (name string) (value gvalue)) -(define-foreign %object-notify () nil +(defbinding %object-notify () nil (object gobject) (name string)) -(define-foreign object-freeze-notify () nil +(defbinding object-freeze-notify () nil (object gobject)) -(define-foreign object-thaw-notify () nil +(defbinding object-thaw-notify () nil (object gobject)) -(define-foreign %object-set-qdata-full () nil +(defbinding %object-set-qdata-full () nil (object gobject) (id quark) (data unsigned-long) @@ -98,7 +78,7 @@ (register-user-data data) *destroy-notify*) data) -(define-foreign %object-get-qdata () unsigned-long +(defbinding %object-get-qdata () unsigned-long (object gobject) (id quark)) @@ -113,48 +93,31 @@ (eval-when (:compile-toplevel :load-toplevel :execute) (defclass gobject-class (ginstance-class)) - (defclass direct-gobject-slot-definition (direct-virtual-slot-definition)) + (defclass direct-gobject-slot-definition (direct-virtual-slot-definition) + ((param :reader slot-definition-param))) (defclass effective-gobject-slot-definition (effective-virtual-slot-definition))) -(defmethod allocate-alien-storage ((class gobject-class)) - (alien-instance-location (%gobject-new (find-type-number class)))) - -(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)) + - -; (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) + &rest initargs &key param) (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))))) + (when param + (setf + (slot-value slotd 'param) + (signal-name-to-string (slot-definition-name slotd))))) (defmethod direct-slot-definition-class ((class gobject-class) initargs) (case (getf initargs :allocation) @@ -166,33 +129,117 @@ (:param (find-class 'effective-gobject-slot-definition)) (t (call-next-method)))) -(defmethod compute-virtual-slot-location +(defmethod compute-virtual-slot-accessors ((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 (get-reader-function type)) - (writer (get-writer-function type)) - (destroy (get-destroy-function type))) + (let ((param-name (slot-definition-param (first direct-slotds))) + (type-number (find-type-number 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+) + (funcall + (intern-reader-function type) 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+) + (funcall + (intern-writer-function type) + value gvalue +gvalue-value-offset+) (%object-set-property object param-name gvalue) - (funcall destroy gvalue +gvalue-value-offset+) + (funcall + (intern-destroy-function type) + gvalue +gvalue-value-offset+) (gvalue-free gvalue nil) value))))))) - (defmethod validate-superclass ((class gobject-class) (super pcl::standard-class)) - (subtypep (class-name super) 'gobject)) +; (subtypep (class-name super) 'gobject) + t) + + + +;;;; + +(defbinding %object-class-properties () pointer + (class pointer) + (n-properties unsigned-int :out)) + +(defun query-object-class-properties (type-number) + (let ((class (type-class-ref type-number))) + (multiple-value-bind (array length) + (%object-class-properties class) + (map-c-array 'list #'identity array 'param length)))) + +(defun query-object-type-dependencies (type-number) + (delete-duplicates + (reduce + #'nconc + (mapcar + #'(lambda (param) + ;; A gobject does not depend on it's supertypes due to forward + ;; referenced superclasses + (delete-if + #'(lambda (type) + (type-is-p type-number type)) + (type-hierarchy (param-type param)))) + (query-object-class-properties type-number))))) + + +(defun default-slot-name (name) + (intern (substitute #\- #\_ (string-upcase (string-upcase name))))) + +(defun default-slot-accessor (class-name slot-name type) + (intern + (format + nil "~A-~A~A" class-name slot-name + (if (eq 'boolean type) "-P" "")))) + +(defun expand-gobject-type (type-number &optional slots + (metaclass 'gobject-class)) + (let* ((super (supertype type-number)) + (class (type-from-number type-number)) + (expanded-slots + (mapcar + #'(lambda (param) + (with-slots (name flags type documentation) param + (let* ((slot-name (default-slot-name name)) + (slot-type (type-from-number type #|t|#)) + (accessor + (default-slot-accessor class slot-name slot-type))) + `(,slot-name + :allocation :param + :param ,name + ,@(cond + ((and + (member :writable flags) + (member :readable flags)) + (list :accessor accessor)) + ((member :writable flags) + (list :writer `(setf ,accessor))) + ((member :readable flags) + (list :reader accessor))) + ,@(when (or + (member :construct flags) + (member :writable flags)) + (list :initarg (intern (string slot-name) "KEYWORD"))) + :type ,slot-type + ,@(when documentation + (list :documentation documentation)))))) + (query-object-class-properties type-number)))) + + `(defclass ,class (,super) + ,expanded-slots + (:metaclass ,metaclass) + (:alien-name ,(find-type-name type-number))))) + +(register-derivable-type + 'gobject "GObject" + :query 'query-object-type-dependencies + :expand 'expand-gobject-type) +