chiark / gitweb /
Added more bindings to GtkWindow
[clg] / glib / gcallback.lisp
index 0598e445824ae61fbf9a7cfad07ff3ce67be40d4..b2cd568fdd6629059f81a9a0a634dd6c0fba3cbc 100644 (file)
@@ -20,7 +20,7 @@
 ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-;; $Id: gcallback.lisp,v 1.30 2006-02-19 19:31:14 espen Exp $
+;; $Id: gcallback.lisp,v 1.35 2006-06-07 13:16:11 espen Exp $
 
 (in-package "GLIB")
 
@@ -29,6 +29,9 @@ (use-prefix "g")
 
 ;;;; Callback invokation
 
+(deftype gclosure () 'pointer)
+(register-type 'gclosure '|g_closure_get_type|)
+
 (defun register-callback-function (function)
   (check-type function (or null symbol function))
   (register-user-data function))
@@ -45,6 +48,7 @@ (define-callback closure-marshal nil
 (define-callback signal-emission-hook nil
     ((invocation-hint pointer) (n-params unsigned-int) (param-values pointer)
      (callback-id unsigned-int))
+  (declare (ignore invocation-hint))
   (callback-trampoline callback-id n-params param-values))
 
 (defun callback-trampoline (callback-id n-params param-values &optional
@@ -54,14 +58,16 @@ (defun callback-trampoline (callback-id n-params param-values &optional
         (args (loop
                for n from 0 below n-params
                for offset from 0 by +gvalue-size+
-               collect (gvalue-get (sap+ param-values offset) t))))
+               collect (gvalue-peek (pointer+ param-values offset)))))
     (unwind-protect
        (let ((result (apply #'invoke-callback callback-id return-type args)))
          (when return-type
            (gvalue-set return-value result)))
+      ;; TODO: this should be made more general, by adding a type
+      ;; method to return invalidate functions.
       (loop 
        for arg in args
-       when (typep arg 'proxy)
+       when (typep arg 'struct)
        do (invalidate-instance arg)))))
 
 
@@ -161,7 +167,7 @@   (defclass signal-query (struct)
 (defbinding signal-query 
     (signal-id &optional (signal-query (make-instance 'signal-query))) nil
   (signal-id unsigned-int)
-  (signal-query signal-query :return))
+  (signal-query signal-query :in/return))
 
 (defun signal-param-types (info)
   (with-slots (n-params param-types) info
@@ -221,7 +227,7 @@ (defun %call-next-handler (n-params types args return-type)
      for arg in args
      for type in types
      for offset from 0 by +gvalue-size+
-     do (gvalue-init (sap+ params offset) type arg))
+     do (gvalue-init (pointer+ params offset) type arg))
 
     (unwind-protect
        (if return-type
@@ -232,7 +238,7 @@ (defun %call-next-handler (n-params types args return-type)
        (loop
         repeat n-params
         for offset from 0 by +gvalue-size+
-        do (gvalue-unset (sap+ params offset)))
+        do (gvalue-unset (pointer+ params offset)))
        (deallocate-memory params)))))
 
 
@@ -255,8 +261,8 @@      (default (make-symbol "DEFAULT")))
            (let ((,default (list* ,object ,@vars ,rest)))
              (flet ((call-next-handler (&rest ,next)
                       (%call-next-handler 
-                       ,n-params ',types (or ,next ,default) ',return-type))))
-             ,@body)))
+                       ,n-params ',types (or ,next ,default) ',return-type)))
+             ,@body))))
        ',name)))
 
 
@@ -317,9 +323,6 @@ (defbinding signal-handler-is-connected-p () boolean
   (instance ginstance)
   (handler-id unsigned-int))
 
-(deftype gclosure () 'pointer)
-(register-type 'gclosure '|g_closure_get_type|)
-
 (defbinding (callback-closure-new "clg_callback_closure_new") () gclosure
   (callback-id unsigned-int) 
   (callback callback)
@@ -413,7 +416,7 @@ (defun create-signal-emit-function (signal-id)
              (loop
               for arg in (cons object args)
               for type in param-types
-              as tmp = params then (sap+ tmp +gvalue-size+)
+              as tmp = params then (pointer+ tmp +gvalue-size+)
               do (gvalue-init tmp type arg)          
               finally 
               (if return-type
@@ -423,7 +426,7 @@ (defun create-signal-emit-function (signal-id)
                 (%signal-emitv params signal-id detail (make-pointer 0))))
            (loop
             repeat n-params
-            as tmp = params then (sap+ tmp +gvalue-size+)
+            as tmp = params then (pointer+ tmp +gvalue-size+)
             while (gvalue-p tmp)
             do (gvalue-unset tmp)))))))
 
@@ -469,14 +472,10 @@ (defmacro define-callback-marshal (name return-type args &key (callback-id :last
          (:first `((callback-id unsigned-int) ,@(mapcar #'list names types)))
          (:last `(,@(mapcar #'list names types) (callback-id unsigned-int))))
        (declare (ignore ,@ignore))
-       (invoke-callback callback-id ',return-type ,@params))))
+       (invoke-callback callback-id ',return-type ,@(nreverse params)))))
 
 (defmacro with-callback-function ((id function) &body body)
   `(let ((,id (register-callback-function ,function)))
     (unwind-protect
         (progn ,@body)
       (destroy-user-data ,id))))
-
-;; For backward compatibility
-(defmacro def-callback-marshal (name (return-type &rest args))
-  `(define-callback-marshal ,name ,return-type ,args))