1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2000 Espen S. Johnsen <esj@stud.cs.uit.no>
4 ;; This library is free software; you can redistribute it and/or
5 ;; modify it under the terms of the GNU Lesser General Public
6 ;; License as published by the Free Software Foundation; either
7 ;; version 2 of the License, or (at your option) any later version.
9 ;; This library is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;; Lesser General Public License for more details.
14 ;; You should have received a copy of the GNU Lesser General Public
15 ;; License along with this library; if not, write to the Free Software
16 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ;; $Id: gcallback.lisp,v 1.5 2002/01/20 14:52:04 espen Exp $
27 (deftype gclosure () 'pointer)
29 (defbinding lisp-callback-closure-new () gclosure
30 (callback-id unsigned-int))
34 ;;;; Callback mechanism
36 (defun register-callback-function (function)
37 (check-type function (or null symbol function))
38 (lisp-callback-closure-new (register-user-data function)))
40 (defun callback-trampoline (callback-id params return-value)
41 (let* ((return-type (unless (null-pointer-p return-value)
42 (type-from-number (gvalue-type return-value))))
44 (callback-function (find-user-data callback-id)))
46 (destructuring-bind (nparams . param-values) params
48 (push (gvalue-get (sap+ param-values (* n +gvalue-size+))) args)))
50 (labels ((invoke-callback ()
53 (let ((result (apply callback-function (reverse args))))
55 (gvalue-set return-value result))))
57 (continue nil :report "Return from callback function"
61 "Enter return value of type ~S: "
63 (force-output *query-io*)
64 (gvalue-set return-value (eval (read *query-io*)))))
65 (re-invoke nil :report "Re-invoke callback function"
69 (defun after-gc-hook ()
71 (extern-alien "callback_trampoline" system-area-pointer)
72 (make-pointer (kernel:get-lisp-obj-address #'callback-trampoline))
73 (extern-alien "destroy_user_data" system-area-pointer)
74 (make-pointer (kernel:get-lisp-obj-address #'destroy-user-data))))
76 (pushnew 'after-gc-hook ext:*after-gc-hooks*)
83 (defun signal-name-to-string (name)
84 (substitute #\_ #\- (string-downcase (string name))))
86 (defbinding signal-lookup (name itype) unsigned-int
87 ((signal-name-to-string name) string)
90 (defbinding signal-name () string
91 (signal-id unsigned-int))
93 (defun ensure-signal-id (signal-id instance)
96 (string (signal-lookup signal-id (type-number-of instance)))
97 (symbol (signal-lookup signal-id (type-number-of instance)))))
99 (defbinding signal-stop-emission (instance signal-id) nil
101 ((ensure-signal-id signal-id instance) unsigned-int))
103 ; (defbinding (signal-add-emisson-hook "g_signal_add_emission_hook_full")
105 ; (signal-id unsigned-int)
106 ; (closure gclosure))
108 ; (defbinding signal-remove-emisson-hook () nil
109 ; (signal-id unsigned-int)
110 ; (hook-id unsigned-int))
112 (defbinding (signal-has-handler-pending-p "g_signal_has_handler_pending")
113 (instance signal-id &key detail blocked) boolean
115 ((ensure-signal-id signal-id instance) unsigned-int)
116 ((or detail 0) quark)
119 (defbinding (signal-connect-closure "g_signal_connect_closure_by_id")
120 (instance signal-id closure &key detail after) unsigned-int
122 ((ensure-signal-id signal-id instance) unsigned-int)
123 ((or detail 0) quark)
127 (defbinding signal-handler-block () nil
129 (handler unsigned-int))
131 (defbinding signal-handler-unblock () nil
133 (handler unsigned-int))
135 (defbinding signal-handler-disconnect () nil
137 (handler unsigned-int))
140 (defmethod signal-connect ((gobject gobject) signal function &rest args &key after object)
141 (declare (ignore signal args after))
143 ((or (eq object t) (eq object gobject)) function)
145 #'(lambda (&rest args) (apply function (cdr args))))
147 #'(lambda (&rest args) (apply function object (rest args))))))
150 (defmethod signal-connect :around ((gobject gobject) signal function
152 (declare (ignore object))
153 (let ((callback-id (register-callback-function (call-next-method))))
154 (signal-connect-closure gobject signal callback-id :after after)))