| 1 | ;; Common Lisp bindings for GTK+ v1.2.x |
| 2 | ;; Copyright (C) 1999 Espen S. Johnsen <espejohn@online.no> |
| 3 | ;; |
| 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. |
| 8 | ;; |
| 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. |
| 13 | ;; |
| 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 |
| 17 | |
| 18 | ;; $Id: glib.lisp,v 1.13 2004-10-27 14:58:59 espen Exp $ |
| 19 | |
| 20 | |
| 21 | (in-package "GLIB") |
| 22 | |
| 23 | (use-prefix "g") |
| 24 | |
| 25 | ;(load-shared-library "libglib-2.0") |
| 26 | |
| 27 | ;;;; Memory management |
| 28 | |
| 29 | (defbinding (allocate-memory "g_malloc0") () pointer |
| 30 | (size unsigned-long)) |
| 31 | |
| 32 | (defbinding (reallocate-memory "g_realloc") () pointer |
| 33 | (address pointer) |
| 34 | (size unsigned-long)) |
| 35 | |
| 36 | (defbinding (deallocate-memory "g_free") () nil |
| 37 | (address pointer)) |
| 38 | ;(defun deallocate-memory (address) |
| 39 | ; (declare (ignore address))) |
| 40 | |
| 41 | (defun copy-memory (from length &optional (to (allocate-memory length))) |
| 42 | (kernel:system-area-copy from 0 to 0 (* 8 length)) |
| 43 | to) |
| 44 | |
| 45 | |
| 46 | ;;;; User data mechanism |
| 47 | |
| 48 | (internal *user-data* *user-data-count*) |
| 49 | |
| 50 | (declaim (fixnum *user-data-count*)) |
| 51 | |
| 52 | (defvar *destroy-notify* (system:foreign-symbol-address "destroy_notify")) |
| 53 | (defvar *user-data* (make-hash-table)) |
| 54 | (defvar *user-data-count* 0) |
| 55 | |
| 56 | (defun register-user-data (object &optional destroy-function) |
| 57 | (check-type destroy-function (or null symbol function)) |
| 58 | (incf *user-data-count*) |
| 59 | (setf |
| 60 | (gethash *user-data-count* *user-data*) |
| 61 | (cons object destroy-function)) |
| 62 | *user-data-count*) |
| 63 | |
| 64 | (defun find-user-data (id) |
| 65 | (check-type id fixnum) |
| 66 | (multiple-value-bind (user-data p) (gethash id *user-data*) |
| 67 | (values (car user-data) p))) |
| 68 | |
| 69 | (defun destroy-user-data (id) |
| 70 | (check-type id fixnum) |
| 71 | (let ((user-data (gethash id *user-data*))) |
| 72 | (when (cdr user-data) |
| 73 | (funcall (cdr user-data) (car user-data)))) |
| 74 | (remhash id *user-data*)) |
| 75 | |
| 76 | |
| 77 | |
| 78 | ;;;; Quarks |
| 79 | |
| 80 | (internal *quark-counter* *quark-from-object* *quark-to-object*) |
| 81 | |
| 82 | (deftype quark () 'unsigned) |
| 83 | |
| 84 | ;(defbinding %quark-get-reserved () quark) |
| 85 | |
| 86 | (defbinding %quark-from-string () quark |
| 87 | (string string)) |
| 88 | |
| 89 | (defvar *quark-counter* 0) |
| 90 | |
| 91 | (defun %quark-get-reserved () |
| 92 | ;; The string is just a dummy |
| 93 |