-(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
+;; depecated
+(defun object-data (object key &key (test #'eq))
+ (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)))))
+
+
+;;;;
+
+(defbinding %object-class-list-properties () pointer
+ (class pointer)
+ (n-properties unsigned-int :out))
+
+
+(defun %map-params (params length type inherited-p)
+ (if inherited-p
+ (map-c-vector 'list #'identity params 'param length)
+ (let ((properties ()))
+ (map-c-vector 'list
+ #'(lambda (param)
+ (when (eql (param-owner-type param) type)
+ (push param properties)))
+ params 'param length)
+ (nreverse properties))))
+
+(defun query-object-class-properties (type &optional inherited-p)
+ (let* ((type-number (find-type-number type))
+ (class (type-class-ref type-number)))
+ (unwind-protect
+ (multiple-value-bind (array length)
+ (%object-class-list-properties class)
+ (unwind-protect
+ (%map-params array length type-number inherited-p)
+ (deallocate-memory array)))
+; (type-class-unref 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 type 'boolean) "-P" ""))))
+
+
+(defun slot-definition-from-property (class property &optional slot-name args)
+ (with-slots (name flags value-type documentation) property
+ (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)))
+
+ `(,slot-name
+ :allocation :property :pname ,name
+
+ ,@(cond
+ ((find :unbound args) (list :unbound (getf args :unbound))))
+
+ ;; accessors
+ ,@(cond
+ ((and
+ (member :writable flags) (member :readable flags)
+ (not (member :construct-only flags)))
+ (list :accessor accessor))
+ ((and (member :writable flags) (not (member :construct-only flags)))
+ (list :writer `(setf ,accessor)))
+ ((member :readable flags)
+ (list :reader accessor)))
+
+ ;; readable/writable/construct
+ ,@(when (or (not (member :writable flags))
+ (member :construct-only flags))
+ '(:writable nil))
+ ,@(when (not (member :readable flags))
+ '(:readable nil))
+ ,@(when (or (member :construct flags)
+ (member :construct-only flags))
+ '(:construct t))
+
+ ;; initargs
+ ,@(when (or (member :construct flags)
+ (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))))
+
+
+(defun slot-definitions (class properties slots)
+ (loop
+ for property in properties
+ as slot = (or
+ (find (param-name property) slots
+ :key #'(lambda (slot) (getf (rest slot) :pname))
+ :test #'string=)
+ (find (param-name property) slots
+ :key #'first :test #'string-equal))
+ do (cond
+ ((not slot)
+ (push (slot-definition-from-property class property) slots))
+ ((getf (rest slot) :merge)
+ (setf
+ (rest slot)
+ (rest (slot-definition-from-property class property (first slot) (rest slot)))))))
+ (delete-if #'(lambda (slot) (getf (rest slot) :ignore)) slots))
+
+
+(defun expand-gobject-type (type &optional options (metaclass 'gobject-class))
+ (let ((supers (cons (supertype type) (implements type)))
+ (class (type-from-number type))
+ (slots (getf options :slots)))
+ `(defclass ,class ,supers
+ ,(slot-definitions class (query-object-class-properties type) slots)
+ (:metaclass ,metaclass)
+ (:alien-name ,(find-type-name type)))))
+
+
+(register-derivable-type 'gobject "GObject" 'expand-gobject-type)
+
+
+;;; Pseudo type for gobject instances which have their reference count
+;;; increased by the returning function
+
+(defmethod alien-type ((type (eql 'referenced)) &rest args)
+ (declare (ignore type args))
+ (alien-type 'gobject))
+
+(defmethod from-alien-form (form (type (eql 'referenced)) &rest args)
+ (declare (ignore type))
+ (destructuring-bind (type) args
+ (if (subtypep type 'gobject)
+ (let ((instance (make-symbol "INSTANCE")))
+ `(let ((,instance ,(from-alien-form form type)))
+ (when ,instance
+ (%object-unref (proxy-location ,instance)))
+ ,instance))
+ (error "~A is not a subclass of GOBJECT" type))))
+
+(export 'referenced)