(:file "gobject.generating")
(:file "gobject.object-defs")
(:file "gobject.foreign-gobject-subclassing"))
- :depends-on (:cffi :trivial-garbage :metabang-bind :iterate :anaphora :bordeaux-threads :iterate :closer-mop))
\ No newline at end of file
+ :depends-on (:cffi :trivial-garbage :iterate :bordeaux-threads :iterate :closer-mop))
\ No newline at end of file
name))
(defun slot->slot-parser (class-name pointer-var slot)
- (bind (((slot-name slot-type &key parser &allow-other-keys) slot))
+ (destructuring-bind (slot-name slot-type &key parser &allow-other-keys) slot
(cond
(parser
`(setf ,slot-name (funcall ,parser ',class-name ,pointer-var)))
,@(mapcar (lambda (slot) (slot->slot-parser name 'pointer slot)) slots)))))
(defun slot->slot-unparser (class-name pointer-var slot object)
- (bind (((slot-name slot-type &key unparser &allow-other-keys) slot))
+ (destructuring-bind (slot-name slot-type &key unparser &allow-other-keys) slot
(cond
(unparser
`(funcall ,unparser ',class-name ,pointer-var ,object))
(intern (format nil "MAKE-~A" (symbol-name name)) (symbol-package name)))
(defun get-g-boxed-direct-subclasses (name)
- (mapcar (lambda (spec) (bind (((name slot values) spec))
+ (mapcar (lambda (spec) (destructuring-bind (name slot values) spec
(declare (ignore slot values))
name))
(get name 'boxed-dispatch)))
(get-g-boxed-completed-c-definition (g-boxed-root name) (get name 'c-name))))
(defmacro define-g-boxed-class (g-name-and-c-name name (&optional superclass-and-dispatch (export t)) &body slots)
- (bind (((&optional g-name c-name) (ensure-list g-name-and-c-name))
- ((&optional superclass dispatch-slot dispatch-values) superclass-and-dispatch)
- (superclass-slots (get superclass 'boxed-combined-slots))
- (combined-slots (append superclass-slots slots)))
- (setf c-name (or c-name (gensym "C-UNION-")))
- `(progn ,(cstruct-definition name combined-slots)
- ,(struct-definition name superclass slots)
- ,(parse-method-definition name combined-slots)
- ,(unparse-method-definition name combined-slots)
- (eval-when (:load-toplevel :compile-toplevel :execute)
- (setf (get ',name 'boxed-slots) ',slots
- (get ',name 'boxed-combined-slots) ',combined-slots
- (get ',name 'superclass) ',superclass
- (get ',name 'c-name) (or (get ',name 'c-name) ',c-name))
- ,@(when superclass
- (list `(pushnew '(,name ,dispatch-slot ,(ensure-list dispatch-values)) (get ',superclass 'boxed-dispatch) :test 'equalp))))
- (update-g-boxed-root-c-class ,name)
- ,@(when g-name
- (list `(register-boxed-type ,g-name ',name)))
- ,@(when export
- (append (list `(export ',name (symbol-package ',name))
- `(export ',(struct-constructor-name name) (symbol-package ',(struct-constructor-name name))))
- (mapcar (lambda (slot) (slot->export-accessor name slot)) slots))))))
+ (destructuring-bind (&optional g-name c-name) (ensure-list g-name-and-c-name)
+ (destructuring-bind (&optional superclass dispatch-slot dispatch-values) superclass-and-dispatch
+ (let* ((superclass-slots (get superclass 'boxed-combined-slots))
+ (combined-slots (append superclass-slots slots)))
+
+ (setf c-name (or c-name (gensym "C-UNION-")))
+ `(progn ,(cstruct-definition name combined-slots)
+ ,(struct-definition name superclass slots)
+ ,(parse-method-definition name combined-slots)
+ ,(unparse-method-definition name combined-slots)
+ (eval-when (:load-toplevel :compile-toplevel :execute)
+ (setf (get ',name 'boxed-slots) ',slots
+ (get ',name 'boxed-combined-slots) ',combined-slots
+ (get ',name 'superclass) ',superclass
+ (get ',name 'c-name) (or (get ',name 'c-name) ',c-name))
+ ,@(when superclass
+ (list `(pushnew '(,name ,dispatch-slot ,(ensure-list dispatch-values)) (get ',superclass 'boxed-dispatch) :test 'equalp))))
+ (update-g-boxed-root-c-class ,name)
+ ,@(when g-name
+ (list `(register-boxed-type ,g-name ',name)))
+ ,@(when export
+ (append (list `(export ',name (symbol-package ',name))
+ `(export ',(struct-constructor-name name) (symbol-package ',(struct-constructor-name name))))
+ (mapcar (lambda (slot) (slot->export-accessor name slot)) slots))))))))
(defun boxed-c-structure-name (name)
(get (g-boxed-root name) 'c-name))
(unless (gethash (pointer-address pointer) *boxed-ref-count*)
(error "g-boxed-ref ~A is already disposed from lisp-side" pointer))
(with-recursive-lock-held (*g-boxed-gc-lock*)
- (awhen (gethash (pointer-address pointer) *known-boxed-refs*)
- (debugf "Removing finalization from ~A for pointer ~A~%" it pointer)
- (tg:cancel-finalization it))
+ (let ((object (gethash (pointer-address pointer) *known-boxed-refs*)))
+ (when object
+ (debugf "Removing finalization from ~A for pointer ~A~%" object pointer)
+ (tg:cancel-finalization object)))
(when (eq :lisp (gethash (pointer-address pointer) *boxed-ref-owner*))
(funcall (boxed-ref-free-function type) pointer))
(remhash (pointer-address pointer) *known-boxed-refs*)
(defmethod initialize-instance :after ((object g-boxed-ref) &key)
(with-recursive-lock-held (*g-boxed-gc-lock*)
(let ((address (pointer-address (pointer object))))
- (awhen (gethash address *known-boxed-refs*)
- (tg:cancel-finalization it))
+ (let ((object (gethash address *known-boxed-refs*)))
+ (when object
+ (tg:cancel-finalization object)))
(setf (gethash address *known-boxed-refs*) object)
(setf (gethash address *boxed-ref-count*) 1)
(setf (gethash address *boxed-ref-owner*)
(defun convert-g-boxed-ref-from-pointer (pointer name type)
(unless (null-pointer-p pointer)
(with-recursive-lock-held (*g-boxed-gc-lock*)
- (or (aprog1 (gethash (pointer-address pointer) *known-boxed-refs*)
- (when it (debugf "Boxed-ref for ~A is found (~A)~%" pointer it))
- (when it (incf (gethash (pointer-address pointer) *boxed-ref-count*)))
- it)
- (aprog1 (make-instance name :pointer pointer)
- (setf (gethash (pointer-address pointer) *boxed-ref-owner*) (g-boxed-ref-owner type))
- (debugf "Boxed-ref for ~A is created (~A) with owner ~A~%" pointer it
- (gethash (pointer-address pointer) *boxed-ref-owner*))
- it)))))
+ (or (let ((object (gethash (pointer-address pointer) *known-boxed-refs*)))
+ (when object (debugf "Boxed-ref for ~A is found (~A)~%" pointer object))
+ (when object (incf (gethash (pointer-address pointer) *boxed-ref-count*)))
+ object)
+ (let ((object (make-instance name :pointer pointer)))
+ (setf (gethash (pointer-address pointer) *boxed-ref-owner*) (g-boxed-ref-owner type))
+ (debugf "Boxed-ref for ~A is created (~A) with owner ~A~%" pointer object
+ (gethash (pointer-address pointer) *boxed-ref-owner*))
+ object)))))
(defmethod translate-from-foreign (value (type g-boxed-ref-type))
(let ((owner (or (gethash (pointer-address value) *boxed-ref-owner*) (g-boxed-ref-owner type)))) ;;This is needed to prevent changing ownership of already created
(setf (gethash (pointer-address value) *boxed-ref-owner*) owner))))
(defun g-boxed-ref-slot->methods (class slot)
- (bind (((slot-name &key reader writer type (accessor slot-name)) slot))
+ (destructuring-bind (slot-name &key reader writer type (accessor slot-name)) slot
`(progn ,@(when reader
(list `(defmethod ,accessor ((object ,class))
,(if (stringp reader)
(return-from-interface-method-implementation (v) :interactive (lambda () (list (eval (read)))) v)))))))
(defun interface-init (iface data)
- (bind (((class-name interface-name) (prog1 (get-stable-pointer-value data) (free-stable-pointer data)))
- (vtable (gethash interface-name *vtables*))
- (vtable-cstruct (vtable-description-cstruct-name vtable)))
- (debugf "interface-init for class ~A and interface ~A~%" class-name interface-name)
- (iter (for method in (vtable-description-methods vtable))
- (setf (foreign-slot-value iface vtable-cstruct (vtable-method-info-name method)) (get-callback (vtable-method-info-callback-name method))))))
+ (destructuring-bind (class-name interface-name) (prog1 (get-stable-pointer-value data) (free-stable-pointer data))
+ (let* ((vtable (gethash interface-name *vtables*))
+ (vtable-cstruct (vtable-description-cstruct-name vtable)))
+ (debugf "interface-init for class ~A and interface ~A~%" class-name interface-name)
+ (iter (for method in (vtable-description-methods vtable))
+ (setf (foreign-slot-value iface vtable-cstruct (vtable-method-info-name method)) (get-callback (vtable-method-info-callback-name method)))))))
(defcallback c-interface-init :void ((iface :pointer) (data :pointer))
(interface-init iface data))
(gethash (pointer-address pointer) *foreign-gobjects*)
(gethash (pointer-address pointer) *foreign-gobjects-ref-count*)
(ref-count pointer))
- (awhen (gethash (pointer-address pointer) *foreign-gobjects*)
- (setf (pointer it) nil)
- (cancel-finalization it))
+ (let ((object (gethash (pointer-address pointer) *foreign-gobjects*)))
+ (when object
+ (setf (pointer object) nil)
+ (cancel-finalization object)))
(remhash (pointer-address pointer) *foreign-gobjects*)
(remhash (pointer-address pointer) *foreign-gobjects-ref-count*)
(g-object-unref pointer))
(defun get-g-object-for-pointer (pointer)
(unless (null-pointer-p pointer)
- (aif (gethash (pointer-address pointer) *foreign-gobjects*)
- (prog1 it
- (incf (gethash (pointer-address pointer) *foreign-gobjects-ref-count*))
- (debugf "increfering object ~A~%" pointer))
- (make-g-object-from-pointer pointer))))
+ (let ((object (gethash (pointer-address pointer) *foreign-gobjects*)))
+ (if object
+ (prog1 object
+ (incf (gethash (pointer-address pointer) *foreign-gobjects-ref-count*))
+ (debugf "increfering object ~A~%" pointer))
+ (make-g-object-from-pointer pointer)))))
(defmethod translate-from-foreign (pointer (type foreign-g-object-type))
(get-g-object-for-pointer pointer))
(defpackage :gobject
- (:use :cl :glib :cffi :tg :bind :anaphora :bordeaux-threads :iter :closer-mop)
+ (:use :cl :glib :cffi :tg :bordeaux-threads :iter :closer-mop)
(:export #:g-object
#:register-object-type
#:g-object-call-constructor
(:file "gtk.dialog.example")
(:file "gtk.demo"))
- :depends-on (:glib :cffi :gdk :anaphora :bordeaux-threads))
\ No newline at end of file
+ :depends-on (:glib :cffi :gdk :bordeaux-threads))
\ No newline at end of file
(defun builder-connect-signals-simple (builder handlers-list)
(flet ((connect-func (builder object signal-name handler-name connect-object flags)
(declare (ignore builder connect-object))
- (awhen (find handler-name handlers-list :key 'first :test 'string=)
- (g-signal-connect object signal-name (second it) :after (member :after flags)))))
+ (let ((handler (find handler-name handlers-list :key 'first :test 'string=)))
+ (when handler
+ (g-signal-connect object signal-name (second handler) :after (member :after flags))))))
(builder-connect-signals-full builder #'connect-func)))
(export 'builder-connect-signals-simple)
(defpackage :gtk-demo
- (:use :cl :gtk :gdk :gobject :anaphora :iter)
+ (:use :cl :gtk :gdk :gobject :iter)
(:export #:test
#:test-entry
#:table-packing
#:demo-code-editor
#:test-treeview-list
#:test-combo-box
- #:test-toolbar
#:test-ui-manager
#:test-color-button
#:test-color-selection
(for action = (make-instance 'action :name name :stock-id stock-id))
(g-signal-connect action "activate" fn)
(action-group-add-action action-group action))
- (awhen (ui-manager-widget ui-manager "/toolbar1")
- (container-add window it))
+ (let ((widget (ui-manager-widget ui-manager "/toolbar1")))
+ (when widget
+ (container-add window widget)))
(widget-show window))))
(defun test-color-button ()
(defun demo-text-editor ()
(within-main-loop
- (let* ((builder (aprog1 (make-instance 'builder)
- (builder-add-from-file it (namestring (merge-pathnames "demo/text-editor.ui" *src-location*)))))
+ (let* ((builder (let ((builder (make-instance 'builder)))
+ (builder-add-from-file builder (namestring (merge-pathnames "demo/text-editor.ui" *src-location*)))
+ builder))
(window (builder-get-object builder "window1"))
(text-view (builder-get-object builder "textview1"))
(status-bar (builder-get-object builder "statusbar1"))
(defpackage :gtk
- (:use :cl :cffi :gobject :gdk :glib :metabang-bind :anaphora)
+ (:use :cl :cffi :gobject :gdk :glib)
(:export #:register-object-type
#:gtk-main
#:gtk-main-quit
(char-offset :int))
(defun text-buffer-get-iter-at-line-offset (buffer line-number char-offset)
- (aprog1 (make-instance 'text-iter)
- (gtk-text-buffer-get-iter-at-line-offset buffer it line-number char-offset)))
+ (let ((iter (make-instance 'text-iter)))
+ (gtk-text-buffer-get-iter-at-line-offset buffer iter line-number char-offset)
+ iter))
(export 'text-buffer-get-iter-at-line-offset)
(char-offset :int))
(defun text-buffer-get-iter-at-offset (buffer offset)
- (aprog1 (make-instance 'text-iter)
- (gtk-text-buffer-get-iter-at-offset buffer it offset)))
+ (let ((iter (make-instance 'text-iter)))
+ (gtk-text-buffer-get-iter-at-offset buffer iter offset)
+ iter))
(export 'text-buffer-get-iter-at-offset)
(line-number :int))
(defun text-buffer-get-iter-at-line (buffer line-number)
- (aprog1 (make-instance 'text-iter)
- (gtk-text-buffer-get-iter-at-line buffer it line-number)))
+ (let ((iter (make-instance 'text-iter)))
+ (gtk-text-buffer-get-iter-at-line buffer iter line-number)
+ iter))
(export 'text-buffet-get-iter-at-line)
(defun text-buffer-get-iter-at-mark (buffer mark)
(when (stringp mark)
(setf mark (text-buffer-get-mark buffer mark)))
- (aprog1 (make-instance 'text-iter)
- (gtk-text-buffer-get-iter-at-mark buffer it mark)))
+ (let ((iter (make-instance 'text-iter)))
+ (gtk-text-buffer-get-iter-at-mark buffer iter mark)
+ iter))
(export 'text-buffer-get-iter-at-mark)
(anchor (g-object text-child-anchor)))
(defun text-buffer-get-iter-at-child-anchor (buffer anchor)
- (aprog1 (make-instance 'text-iter)
- (gtk-text-buffer-get-iter-at-child-anchor buffer it anchor)))
+ (let ((iter (make-instance 'text-iter)))
+ (gtk-text-buffer-get-iter-at-child-anchor buffer iter anchor)
+ iter))
(export 'text-buffer-get-iter-at-child-anchor)
(iter (g-boxed-ref text-iter)))
(defun text-buffer-get-start-iter (buffer)
- (aprog1 (make-instance 'text-iter)
- (gtk-text-buffer-get-start-iter buffer it)))
+ (let ((iter (make-instance 'text-iter)))
+ (gtk-text-buffer-get-start-iter buffer iter)
+ iter))
(export 'text-buffer-get-start-iter)
(iter (g-boxed-ref text-iter)))
(defun text-buffer-get-end-iter (buffer)
- (aprog1 (make-instance 'text-iter)
- (gtk-text-buffer-get-end-iter buffer it)))
+ (let ((iter (make-instance 'text-iter)))
+ (gtk-text-buffer-get-end-iter buffer iter)
+ iter))
(export 'text-buffer-get-end-iter)
(visible-rect (g-boxed-ptr rectangle :in-out)))
(defun text-view-visible-rect (text-view)
- (aprog1 (make-rectangle :x 0 :y 0 :width 0 :height 0)
- (gtk-text-view-get-visible-rect text-view it)))
+ (let ((rect (make-rectangle :x 0 :y 0 :width 0 :height 0)))
+ (gtk-text-view-get-visible-rect text-view rect)
+ rect))
(export 'text-view-visible-rect)
(location (g-boxed-ptr rectangle :in-out)))
(defun text-view-iter-location (text-view iter)
- (aprog1 (make-rectangle :x 0 :y 0 :width 0 :height 0)
- (gtk-text-view-get-iter-location text-view iter it)))
+ (let ((rect (make-rectangle :x 0 :y 0 :width 0 :height 0)))
+ (gtk-text-view-get-iter-location text-view iter rect)
+ rect))
(export 'text-view-iter-location)
(defmethod tree-model-get-path-impl ((model array-list-store) iter)
(using* (iter)
- (anaphora:aprog1 (make-instance 'tree-path)
- (setf (tree-path-indices anaphora:it) (list (tree-iter-user-data iter)))
- (disown-boxed-ref anaphora:it))))
+ (let ((path (make-instance 'tree-path)))
+ (setf (tree-path-indices path) (list (tree-iter-user-data iter)))
+ (disown-boxed-ref path)
+ path)))
(defmethod tree-model-iter-has-child-impl ((model array-list-store) iter)
(release iter)
(rectangle (g-boxed-ptr rectangle)))
(defun tree-view-get-cell-area (tree-view path column)
- (aprog1 (make-rectangle :x 0 :y 0 :width 0 :height 0)
- (gtk-tree-view-get-cell-area tree-view path column it)))
+ (let ((rect (make-rectangle :x 0 :y 0 :width 0 :height 0)))
+ (gtk-tree-view-get-cell-area tree-view path column rect)
+ rect))
(export 'tree-view-get-cell-area)
(rectangle (g-boxed-ptr rectangle)))
(defun tree-view-get-background-area (tree-view path column)
- (aprog1 (make-rectangle :x 0 :y 0 :width 0 :height 0)
- (gtk-tree-view-get-background-area tree-view path column it)))
+ (let ((rect (make-rectangle :x 0 :y 0 :width 0 :height 0)))
+ (gtk-tree-view-get-background-area tree-view path column rect)
+ rect))
(export 'tree-view-get-background-area)
(rectangle (g-boxed-ptr rectangle)))
(defun tree-view-get-visible-rect (tree-view)
- (aprog1 (make-rectangle :x 0 :y 0 :width 0 :height 0)
- (gtk-tree-view-get-visible-rect tree-view it)))
+ (let ((rect (make-rectangle :x 0 :y 0 :width 0 :height 0)))
+ (gtk-tree-view-get-visible-rect tree-view rect)
+ rect))
(export 'tree-view-get-visible-rect)
(defmethod tree-model-get-path-impl ((model array-list-store) iter)
(gobject:using* (iter)
- (anaphora:aprog1 (make-instance 'tree-path)
- (setf (tree-path-indices anaphora:it) (list (tree-iter-user-data iter)))
- (gobject:disown-boxed-ref anaphora:it))))
+ (let ((path (make-instance 'tree-path)))
+ (setf (tree-path-indices path) (list (tree-iter-user-data iter)))
+ (gobject:disown-boxed-ref path)
+ path)))
(defmethod tree-model-iter-has-child-impl ((model array-list-store) iter)
(gobject:release iter)