X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/ae37d09673e10263db66dac3f2aecf376e7280a9..637525325db34a2c4e4de288711d97bb84adffee:/glib/gobject.lisp diff --git a/glib/gobject.lisp b/glib/gobject.lisp index 7eb4b41..c6bfe26 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.25 2004-12-28 20:29:05 espen Exp $ +;; $Id: gobject.lisp,v 1.28 2005-01-12 13:26:03 espen Exp $ (in-package "GLIB") @@ -41,7 +41,14 @@ ((pname :reader slot-definition-pname :initarg :pname) (readable :reader slot-readable-p :initarg :readable) (writable :reader slot-writable-p :initarg :writable) - (construct :initarg :construct)));) + (construct :initarg :construct))) + +(defclass direct-user-data-slot-definition (direct-virtual-slot-definition) + ()) + +(defclass effective-user-data-slot-definition (effective-virtual-slot-definition) + ()) + (defbinding %object-ref () pointer (location pointer)) @@ -74,11 +81,13 @@ (defmethod direct-slot-definition-class ((class gobject-class) &rest initargs) (case (getf initargs :allocation) (:property (find-class 'direct-property-slot-definition)) + (:user-data (find-class 'direct-user-data-slot-definition)) (t (call-next-method)))) (defmethod effective-slot-definition-class ((class gobject-class) &rest initargs) (case (getf initargs :allocation) (:property (find-class 'effective-property-slot-definition)) + (:user-data (find-class 'effective-user-data-slot-definition)) (t (call-next-method)))) (defmethod compute-effective-slot-definition-initargs ((class gobject-class) direct-slotds) @@ -125,6 +134,25 @@ (call-next-method)) +(defmethod initialize-internal-slot-functions ((slotd effective-user-data-slot-definition)) + (let ((slot-name (slot-definition-name slotd))) + (unless (slot-boundp slotd 'getter) + (setf + (slot-value slotd 'getter) + #'(lambda (object) + (prog1 (user-data object slot-name))))) + (unless (slot-boundp slotd 'setter) + (setf + (slot-value slotd 'setter) + #'(lambda (value object) + (setf (user-data object slot-name) value)))) + (unless (slot-boundp slotd 'boundp) + (setf + (slot-value slotd 'boundp) + #'(lambda (object) + (user-data-p object slot-name))))) + (call-next-method)) + ;;;; Super class for all classes in the GObject type hierarchy @@ -249,19 +277,31 @@ ;;;; User data -(defun (setf object-data) (data object key &key (test #'eq)) +(defun (setf user-data) (data object key) (%object-set-qdata-full - object (quark-from-object key :test test) + object (quark-from-object key) (register-user-data data) (callback %destroy-user-data)) data) +;; depecated +(defun (setf object-data) (data object key &key (test #'eq)) + (assert (eq test #'eq)) + (setf (user-data object key) data)) + (defbinding %object-get-qdata () unsigned-long (object gobject) (id quark)) +(defun user-data (object key) + (find-user-data (%object-get-qdata object (quark-from-object key)))) + +;; depecated (defun object-data (object key &key (test #'eq)) - (find-user-data - (%object-get-qdata object (quark-from-object key :test test)))) + (assert (eq test #'eq)) + (user-data object key)) + +(defun user-data-p (object key) + (nth-value 1 (find-user-data (%object-get-qdata object (quark-from-object key))))) ;;;; @@ -305,9 +345,9 @@ (if (eq type 'boolean) "-P" "")))) -(defun slot-definition-from-property (class property &optional args) +(defun slot-definition-from-property (class property &optional slot-name args) (with-slots (name flags value-type documentation) property - (let* ((slot-name (default-slot-name name)) + (let* ((slot-name (or slot-name (default-slot-name name))) (slot-type (or (getf args :type) (type-from-number value-type) value-type)) (accessor (default-slot-accessor class slot-name slot-type))) @@ -343,6 +383,8 @@ (member :construct-only flags) (member :writable flags)) (list :initarg (intern (string slot-name) "KEYWORD"))) + ,@(cond + ((find :initarg args) (list :initarg (getf args :initarg)))) :type ,slot-type :documentation ,documentation)))) @@ -363,7 +405,7 @@ ((getf (rest slot) :merge) (setf (rest slot) - (rest (slot-definition-from-property class property (rest slot))))))) + (rest (slot-definition-from-property class property (first slot) (rest slot))))))) (delete-if #'(lambda (slot) (getf (rest slot) :ignore)) slots))