(:file "gobject.foreign")
(:file "gobject.stable-pointer")
(:file "gobject.closure")
+ (:file "gobject.object.low")
(:file "gobject.foreign-gobject")
(:file "gobject.foreign-gboxed")
(in-package :gobject)
-(defun g-type-from-object (object)
- "Returns the GType of an @code{object}
-
-@arg[object]{C pointer to an object}
-@return{GType designator (see @class{g-type-designator})}"
- (g-type-from-instance object))
-
-(defun g-type-from-class (g-class)
- (g-type-name (foreign-slot-value g-class 'g-type-class :type)))
-
-(defun g-type-from-instance (type-instance)
- (g-type-from-class (foreign-slot-value type-instance 'g-type-instance :class)))
-
-(defun g-type-from-interface (type-interface)
- (g-type-name (foreign-slot-value type-interface 'g-type-interface :type)))
-
(defclass g-object ()
((pointer
:type cffi:foreign-pointer
(etypecase object
(g-object (pointer object)))))
-(define-condition property-access-error (error)
- ((property-name :initarg :property-name :reader property-access-error-property-name)
- (class-name :initarg :class-name :reader property-access-error-class-name)
- (message :initarg :message :reader property-access-error-message))
- (:report (lambda (condition stream)
- (format stream "Error accessing property '~A' on class '~A': ~A"
- (property-access-error-property-name condition)
- (property-access-error-class-name condition)
- (property-access-error-message condition)))))
-
-(define-condition property-unreadable-error (property-access-error)
- ()
- (:default-initargs :message "property is not readable"))
-
-(define-condition property-unwritable-error (property-access-error)
- ()
- (:default-initargs :message "property is not writable"))
-
-(defun g-param-spec-property-type (param-spec property-name object-type assert-readable assert-writable)
- (when (null-pointer-p param-spec)
- (error "Property ~A on type ~A is not found"
- property-name
- (g-type-name object-type)))
- (when (and assert-readable
- (not (member :readable
- (foreign-slot-value param-spec
- 'g-param-spec
- :flags))))
- (error 'property-unreadable-error
- :property-name property-name
- :class-name (g-type-name object-type)))
- (when (and assert-writable
- (not (member :writable
- (foreign-slot-value param-spec
- 'g-param-spec
- :flags))))
- (error 'property-unwritable-error
- :property-name property-name
- :class-name (g-type-name object-type)))
- (foreign-slot-value param-spec 'g-param-spec :value-type))
-
-(defun g-object-type-property-type (object-type property-name
- &key assert-readable assert-writable)
- (let* ((object-class (g-type-class-ref object-type))
- (param-spec (g-object-class-find-property object-class property-name)))
- (unwind-protect
- (g-param-spec-property-type param-spec property-name object-type assert-readable assert-writable)
- (g-type-class-unref object-class))))
-
-(defun g-object-property-type (object property-name
- &key assert-readable assert-writable)
- (g-object-type-property-type (g-type-from-object (ensure-object-pointer object))
- property-name
- :assert-readable assert-readable
- :assert-writable assert-writable))
-
-(defun g-object-call-constructor (object-type args-names args-values
- &optional args-types)
- (unless args-types
- (setf args-types
- (mapcar (lambda (name)
- (g-object-type-property-type object-type name))
- args-names)))
- (let ((args-count (length args-names)))
- (with-foreign-object (parameters 'g-parameter args-count)
- (loop
- for i from 0 below args-count
- for arg-name in args-names
- for arg-value in args-values
- for arg-type in args-types
- for arg-g-type = (if arg-type (ensure-g-type arg-type) (g-object-type-property-type object-type arg-name))
- for parameter = (mem-aref parameters 'g-parameter i)
- do (setf (foreign-slot-value parameter 'g-parameter :name) arg-name)
- do (set-g-value (foreign-slot-value parameter 'g-parameter :value)
- arg-value arg-g-type
- :zero-g-value t))
- (unwind-protect
- (g-object-newv object-type args-count parameters)
- (loop
- for i from 0 below args-count
- for parameter = (mem-aref parameters 'g-parameter i)
- do (foreign-free (mem-ref (foreign-slot-pointer parameter 'g-parameter :name) :pointer))
- do (g-value-unset (foreign-slot-pointer parameter 'g-parameter :value)))))))
-
-(defun g-object-call-get-property (object property-name &optional property-type)
- (restart-case
- (unless property-type
- (setf property-type
- (g-object-property-type object property-name :assert-readable t)))
- (return-nil () (return-from g-object-call-get-property nil)))
- (setf property-type (ensure-g-type property-type))
- (with-foreign-object (value 'g-value)
- (g-value-zero value)
- (g-value-init value property-type)
- (g-object-get-property (ensure-object-pointer object)
- property-name value)
- (unwind-protect
- (parse-gvalue value)
- (g-value-unset value))))
-
-(defun g-object-call-set-property (object property-name new-value
- &optional property-type)
- (unless property-type
- (setf property-type
- (g-object-property-type object property-name :assert-writable t)))
- (setf property-type (ensure-g-type property-type))
- (with-foreign-object (value 'g-value)
- (set-g-value value new-value property-type :zero-g-value t)
- (unwind-protect
- (g-object-set-property (ensure-object-pointer object)
- property-name value)
- (g-value-unset value))))
-
(defmethod parse-gvalue-for-type (gvalue-ptr (type-numeric (eql +g-type-object+)))
(parse-gvalue-object gvalue-ptr))
(property-unreadable-error () nil)))
(defmethod slot-value-using-class ((class gobject-class) object (slot gobject-property-effective-slot-definition))
- (g-object-call-get-property object
+ (g-object-call-get-property (pointer object)
(gobject-property-effective-slot-definition-g-property-name slot)
(gobject-effective-slot-definition-g-property-type slot)))
(defmethod (setf slot-value-using-class) (new-value (class gobject-class) object (slot gobject-property-effective-slot-definition))
- (g-object-call-set-property object
+ (g-object-call-set-property (pointer object)
(gobject-property-effective-slot-definition-g-property-name slot)
new-value
(gobject-effective-slot-definition-g-property-type slot)))
--- /dev/null
+(in-package :gobject)
+
+(defun g-type-from-object (object-ptr)
+ "Returns the GType of an @code{object-ptr}
+
+@arg[object-ptr]{C pointer to an object}
+@return{GType designator (see @class{g-type-designator})}"
+ (g-type-from-instance object-ptr))
+
+(defun g-type-from-class (g-class)
+ (g-type-name (foreign-slot-value g-class 'g-type-class :type)))
+
+(defun g-type-from-instance (type-instance)
+ (g-type-from-class (foreign-slot-value type-instance 'g-type-instance :class)))
+
+(defun g-type-from-interface (type-interface)
+ (g-type-name (foreign-slot-value type-interface 'g-type-interface :type)))
+
+(define-condition property-access-error (error)
+ ((property-name :initarg :property-name :reader property-access-error-property-name)
+ (class-name :initarg :class-name :reader property-access-error-class-name)
+ (message :initarg :message :reader property-access-error-message))
+ (:report (lambda (condition stream)
+ (format stream "Error accessing property '~A' on class '~A': ~A"
+ (property-access-error-property-name condition)
+ (property-access-error-class-name condition)
+ (property-access-error-message condition)))))
+
+(define-condition property-unreadable-error (property-access-error)
+ ()
+ (:default-initargs :message "property is not readable"))
+
+(define-condition property-unwritable-error (property-access-error)
+ ()
+ (:default-initargs :message "property is not writable"))
+
+(defun g-object-type-property-type (object-type property-name
+ &key assert-readable assert-writable)
+ (let* ((property (class-property-info object-type property-name)))
+ (when (and assert-readable (not (g-class-property-definition-readable property)))
+ (error 'property-unreadable-error
+ :property-name property-name
+ :class-name (g-type-string object-type)))
+ (when (and assert-writable (not (g-class-property-definition-writable property)))
+ (error 'property-unwritable-error
+ :property-name property-name
+ :class-name (g-type-string object-type)))
+ (g-class-property-definition-type property)))
+
+(defun g-object-property-type (object-ptr property-name &key assert-readable assert-writable)
+ (g-object-type-property-type (g-type-from-object object-ptr) property-name :assert-readable assert-readable :assert-writable assert-writable))
+
+(defun g-object-call-get-property (object-ptr property-name &optional property-type)
+ (restart-case
+ (unless property-type
+ (setf property-type
+ (g-object-type-property-type (g-type-from-object object-ptr) property-name :assert-readable t)))
+ (return-nil () (return-from g-object-call-get-property nil)))
+ (with-foreign-object (value 'g-value)
+ (g-value-zero value)
+ (g-value-init value property-type)
+ (g-object-get-property object-ptr property-name value)
+ (unwind-protect
+ (parse-gvalue value)
+ (g-value-unset value))))
+
+(defun g-object-call-set-property (object-ptr property-name new-value
+ &optional property-type)
+ (unless property-type
+ (setf property-type
+ (g-object-type-property-type (g-type-from-object object-ptr) property-name :assert-writable t)))
+ (with-foreign-object (value 'g-value)
+ (set-g-value value new-value property-type :zero-g-value t)
+ (unwind-protect
+ (g-object-set-property object-ptr property-name value)
+ (g-value-unset value))))
+
+(defun g-object-call-constructor (object-type args-names args-values
+ &optional args-types)
+ (unless args-types
+ (setf args-types
+ (mapcar (lambda (name)
+ (g-object-type-property-type object-type name))
+ args-names)))
+ (let ((args-count (length args-names)))
+ (with-foreign-object (parameters 'g-parameter args-count)
+ (loop
+ for i from 0 below args-count
+ for arg-name in args-names
+ for arg-value in args-values
+ for arg-type in args-types
+ for arg-g-type = (if arg-type arg-type (g-object-type-property-type object-type arg-name))
+ for parameter = (mem-aref parameters 'g-parameter i)
+ do (setf (foreign-slot-value parameter 'g-parameter :name) arg-name)
+ do (set-g-value (foreign-slot-value parameter 'g-parameter :value) arg-value arg-g-type :zero-g-value t))
+ (unwind-protect
+ (g-object-newv object-type args-count parameters)
+ (loop
+ for i from 0 below args-count
+ for parameter = (mem-aref parameters 'g-parameter i)
+ do (foreign-string-free (mem-ref (foreign-slot-pointer parameter 'g-parameter :name) :pointer))
+ do (g-value-unset (foreign-slot-pointer parameter 'g-parameter :value)))))))
+
#:signal-info-detail
#:query-signal-info
#:type-signals
- #:parse-signal-name)
+ #:parse-signal-name
+ #:class-property-info)
(:documentation
"This package contains functions for querying the basic type information from GObject type system. For an overview of GObject type system, see @a[http://library.gnome.org/devel/gobject/stable/index.html]{GObject documentation}