chiark / gitweb /
Added single linked list type (gslist), changed name of double linked list type to...
[clg] / gtk / gtkobject.lisp
index d2583d87560404d287cef54963925c3700f60915..6b536e27e5968b28b6604fc52edbd08549e7cdab 100644 (file)
 ;; License along with this library; if not, write to the Free Software
 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-;; $Id: gtkobject.lisp,v 1.1 2000-08-14 16:44:54 espen Exp $
+;; $Id: gtkobject.lisp,v 1.6 2000-09-04 22:14:54 espen Exp $
 
 
 (in-package "GTK")
 
+
+;;;; Initializing
+
+(setf (alien-type-name 'pointer) "gpointer")
+
+
 ;;;; Misc utils
 
 (defun name-to-string (name)
@@ -78,7 +84,7 @@ (defun arg-value (arg &optional (type (type-from-number (arg-type arg))))
 ;; One should never call this function on an arg whose value is already set
 (defun (setf arg-value)
     (value arg &optional (type (type-from-number (arg-type arg))))
-  (funcall (get-writer-funcation type) value arg +arg-value-offset+)
+  (funcall (get-writer-function type) value arg +arg-value-offset+)
   value)
 
 (defun (setf return-arg-value)
@@ -155,43 +161,23 @@ (defun (setf object-arg) (value object name)
     (let ((arg (arg-new 0)))
       (setf (arg-name arg) name)
       (object-get-arg object arg)
-      (let ((type (type-from-number (arg-type arg))))
+      (let* ((type-number (arg-type arg))
+            (type (type-from-number type-number)))
        (%arg-reset arg)
+       (setf (arg-type arg) type-number)
        (setf (arg-value arg type) value)
        (object-set-arg object arg)
        (arg-free arg t))))
   value)
 
 
-;;;; Callback and user data mechanism
-
-(declaim (fixnum *user-data-count*))
-
-(defvar *user-data* (make-hash-table))
-(defvar *user-data-count* 0)
-
-(defun register-user-data (object &optional destroy-function)
-  (check-type destroy-function (or null symbol function))
-;  (incf *user-data-count*)
-  (setq *user-data-count* (the fixnum (1+ *user-data-count*)))
-  (setf
-   (gethash *user-data-count* *user-data*)
-   (cons object destroy-function))
-  *user-data-count*)
-
-
-(defun find-user-data (id)
-  (check-type id fixnum)
-  (multiple-value-bind (user-data p) (gethash id *user-data*)
-    (values (car user-data) p)))
-
+;;;; Callback mechanism
 
 (defun register-callback-function (function)
   (check-type function (or null symbol function))
   ; We treat callbacks just as ordinary user data
   (register-user-data function))
 
-
 (defun callback-trampoline (callback-id nargs arg-array)
   (declare (fixnum callback-id nargs))
   (let* ((return-arg (unless (null-pointer-p arg-array)
@@ -226,17 +212,8 @@ (defun callback-trampoline (callback-id nargs arg-array)
                  (invoke-callback)))))
       (invoke-callback))))
 
-
-(defun destroy-user-data (id)
-  (check-type id fixnum)
-  (let ((user-data (gethash id *user-data*)))
-    (when (cdr user-data)
-      (funcall (cdr user-data) (car user-data))))
-  (remhash id *user-data*))
-
-
 (defvar *callback-marshal* (system:foreign-symbol-address "callback_marshal"))
-(defvar *destroy-marshal* (system:foreign-symbol-address "destroy_marshal"))
+(setq *destroy-marshal* (system:foreign-symbol-address "destroy_marshal"))
 
 (defun after-gc-hook ()
   (setf
@@ -250,12 +227,14 @@ (after-gc-hook)
 
 
 
-;;;; Main loop
+;;;; Main loop, timeouts and idle functions
 
 (declaim (inline events-pending-p main-iteration))
 
 (define-foreign ("gtk_events_pending" events-pending-p) () boolean)
 
+(define-foreign get-current-event () gdk:event)
+
 (define-foreign main-do-event () nil
   (event gdk:event))
 
@@ -275,6 +254,29 @@ (defun main-iterate-all (&rest args)
     (main-iteration nil)
     (main-iterate-all)))
 
+(define-foreign ("gtk_timeout_add_full" timeout-add)
+    (interval function) unsigned-int
+  (interval (unsigned 32))
+  (0 unsigned-long)
+  (*callback-marshal* pointer)
+  ((register-callback-function function) unsigned-long)
+  (*destroy-marshal* pointer))
+
+(define-foreign timeout-remove () nil
+  (timeout-handler-id unsigned-int))
+  
+(define-foreign ("gtk_idle_add_full" idle-add)
+    (function &optional (priority 200)) unsigned-int
+  (priority int)
+  (0 unsigned-long)
+  (*callback-marshal* pointer)
+  ((register-callback-function function) unsigned-long)
+  (*destroy-marshal* pointer))
+
+(define-foreign idle-remove () nil
+  (idle-handler-id unsigned-int))
+
+
 (system:add-fd-handler (gdk:event-poll-fd) :input #'main-iterate-all)
 (setq lisp::*periodic-polling-function* #'main-iterate-all)
 (setq lisp::*max-event-to-sec* 0)