+; (subtypep (class-name super) 'gobject)
+ t)
+
+
+
+;;;;
+
+(defbinding %object-class-list-properties () pointer
+ (class pointer)
+ (n-properties unsigned-int :out))
+
+(defun query-object-class-properties (type-number &optional
+ inherited-properties)
+ (let ((class (type-class-ref type-number)))
+ (multiple-value-bind (array length)
+ (%object-class-list-properties class)
+ (unwind-protect
+ (let ((all-properties
+ (map-c-array 'list #'identity array 'param length)))
+ (if (not inherited-properties)
+ (delete-if
+ #'(lambda (param)
+ (not (eql type-number (param-owner-type param))))
+ all-properties)
+ all-properties))
+ (deallocate-memory array)))))
+
+
+(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 options
+ (metaclass 'gobject-class))
+ (let* ((supers (cons (supertype type-number) (implements type-number)))
+ (class (type-from-number type-number))
+ (override-slots (getf options :slots))
+ (expanded-slots
+ (mapcar
+ #'(lambda (param)
+ (with-slots (name flags value-type documentation) param
+ (let* ((slot-name (default-slot-name name))
+ (slot-type value-type) ;(type-from-number value-type t))
+ (accessor
+ (default-slot-accessor class slot-name (type-from-number slot-type)))) ; temporary workaround for wrong topological sorting of types
+ `(,slot-name
+ :allocation :property
+ :pname ,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))))
+
+ (dolist (slot-def override-slots)
+ (let ((name (car slot-def))
+ (pname (getf (cdr slot-def) :pname)))
+ (setq
+ expanded-slots
+ (delete-if
+ #'(lambda (expanded-slot-def)
+ (or
+ (eq name (car expanded-slot-def))
+ (and
+ pname
+ (string= pname (getf (cdr expanded-slot-def) :pname)))))
+ expanded-slots))
+
+ (unless (getf (cdr slot-def) :ignore)
+ (push slot-def expanded-slots))))
+
+ `(progn
+ (defclass ,class ,supers
+ ,expanded-slots
+ (:metaclass ,metaclass)
+ (:alien-name ,(find-type-name type-number))))))
+
+
+(register-derivable-type 'gobject "GObject" 'expand-gobject-type)
+