0d07716f |
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 | |
7bde5a67 |
18 | ;; $Id: glib.lisp,v 1.17 2004/11/07 01:23:38 espen Exp $ |
0d07716f |
19 | |
20 | |
21 | (in-package "GLIB") |
b467f3d0 |
22 | |
0d07716f |
23 | (use-prefix "g") |
24 | |
25 | |
26 | ;;;; Memory management |
27 | |
1c99696e |
28 | (defbinding (allocate-memory "g_malloc0") () pointer |
0d07716f |
29 | (size unsigned-long)) |
30 | |
1c99696e |
31 | (defbinding (reallocate-memory "g_realloc") () pointer |
0d07716f |
32 | (address pointer) |
33 | (size unsigned-long)) |
34 | |
3fa4f6bd |
35 | (defbinding (deallocate-memory "g_free") () nil |
36 | (address pointer)) |
6baf860c |
37 | ;; (defun deallocate-memory (address) |
38 | ;; (declare (ignore address))) |
0d07716f |
39 | |
40 | (defun copy-memory (from length &optional (to (allocate-memory length))) |
41 | (kernel:system-area-copy from 0 to 0 (* 8 length)) |
42 | to) |
43 | |
44 | |
b467f3d0 |
45 | ;;;; User data mechanism |
46 | |
47 | (internal *user-data* *user-data-count*) |
48 | |
49 | (declaim (fixnum *user-data-count*)) |
50 | |
b467f3d0 |
51 | (defvar *user-data* (make-hash-table)) |
52 | (defvar *user-data-count* 0) |
53 | |
54 | (defun register-user-data (object &optional destroy-function) |
55 | (check-type destroy-function (or null symbol function)) |
56 | (incf *user-data-count*) |
57 | (setf |
58 | (gethash *user-data-count* *user-data*) |
59 | (cons object destroy-function)) |
60 | *user-data-count*) |
61 | |
62 | (defun find-user-data (id) |
63 | (check-type id fixnum) |
64 | (multiple-value-bind (user-data p) (gethash id *user-data*) |
65 | (values (car user-data) p))) |
66 | |
67 | (defun destroy-user-data (id) |
68 | (check-type id fixnum) |
69 | (let ((user-data (gethash id *user-data*))) |
70 | (when (cdr user-data) |
71 | (funcall (cdr user-data) (car user-data)))) |
72 | (remhash id *user-data*)) |
73 | |
7bde5a67 |
74 | (defmacro def-callback-marshal (name (return-type &rest args)) |
75 | (let ((names (loop |
76 | for arg in args |
77 | collect (if (atom arg) (gensym) (first arg)))) |
78 | (types (loop |
79 | for arg in args |
80 | collect (if (atom arg) arg (second arg))))) |
81 | `(defcallback ,name (,return-type ,@(mapcar #'list names types) |
82 | (callback-id unsigned-int)) |
83 | (invoke-callback callback-id ',return-type ,@names)))) |
b467f3d0 |
84 | |
0d07716f |
85 | |
6755fdad |
86 | ;;;; Quarks |
87 | |
b467f3d0 |
88 | (internal *quark-counter* *quark-from-object* *quark-to-object*) |
89 | |
6755fdad |
90 | (deftype quark () 'unsigned) |
91 | |
cb816364 |
92 | ;(defbinding %quark-get-reserved () quark) |
e5b6173a |
93 | |
cb816364 |
94 | (defbinding %quark-from-string () quark |
e5b6173a |
95 | (string string)) |
96 | |
b467f3d0 |
97 | (defvar *quark-counter* 0) |
e5b6173a |
98 | |
99 | (defun %quark-get-reserved () |
b467f3d0 |
100 | ;; The string is just a dummy |
101 |