X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/26b133ede0e73b51f5151f1e2318b2567bdbcc5e..85482331660eb6044d70881636b8d0b444e47f41:/glib/gobject.lisp diff --git a/glib/gobject.lisp b/glib/gobject.lisp index 9f560d2..be77962 100644 --- a/glib/gobject.lisp +++ b/glib/gobject.lisp @@ -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.6 2001-04-29 20:34:18 espen Exp $ +;; $Id: gobject.lisp,v 1.7 2001-05-11 16:08:08 espen Exp $ (in-package "GLIB") @@ -35,11 +35,12 @@ (%gobject-new (type-number-of object))) (call-next-method)) -(defbinding ("g_object_new" %gobject-new) () gobject +(defbinding (%gobject-new "g_object_new") () pointer (type type-number) (nil null)) + ;;;; Parameter stuff (defbinding %object-set-property () nil @@ -92,7 +93,8 @@ (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))) @@ -109,12 +111,12 @@ (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) @@ -126,14 +128,14 @@ (: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))) + (let ((param-name (slot-definition-param (first direct-slotds))) (type-number (find-type-number type)) - (reader (intern-reader-function type)) - (writer (intern-writer-function type)) + (getter (intern-reader-function type)) + (setter (intern-writer-function type)) (destroy (intern-destroy-function type))) (list #'(lambda (object) @@ -141,19 +143,91 @@ (let ((gvalue (gvalue-new type-number))) (%object-get-property object param-name gvalue) (prog1 - (funcall reader gvalue +gvalue-value-offset+) + (funcall getter 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 setter 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 + + + +;;;; + +(defbinding %object-class-properties () pointer + (class pointer) + (n-properties unsigned-int :out)) + +(defun query-object-class-properties (type) + (let ((class (type-class-ref type))) + (multiple-value-bind (array length) + (%object-class-properties class) + (map-c-array 'list #'identity array 'param length)))) + +(defun query-object-class-dependencies (class) + (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 class type)) + (type-hierarchy (param-type param)))) + (query-object-class-properties class))))) + + +(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) + (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)) + (accessor + (default-slot-accessor class slot-name slot-type))) + `(,slot-name + :allocation :param + :param ,name + ,@(when (member :writable flags) + (list :writer `(setf ,accessor))) + ,@(when (member :readable flags) + (list :reader accessor)) + ,@(when (member :construct 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 gobject-class) + (:alien-name ,(find-type-name type-number))))) + +(register-derivable-type + 'gobject "GObject" + :query 'query-object-class-dependencies + :expand 'expand-gobject-type) +