94f15c3c |
1 | ;; Common Lisp bindings for GTK+ v2.0 |
2 | ;; Copyright (C) 2001 Espen S. Johnsen <esj@stud.cs.uit.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 | |
735a29da |
18 | ;; $Id: gboxed.lisp,v 1.18 2005-03-11 10:56:58 espen Exp $ |
94f15c3c |
19 | |
20 | (in-package "GLIB") |
21 | |
22 | |
2b481386 |
23 | (defclass boxed (struct) |
9adccb27 |
24 | () |
25 | (:metaclass struct-class)) |
94f15c3c |
26 | |
1dbf4216 |
27 | (defmethod instance-finalizer ((instance boxed)) |
28 | (let ((location (proxy-location instance)) |
29 | (type-number (type-number-of instance))) |
30 | #'(lambda () |
31 | (remove-cached-instance location) |
32 | (%boxed-free type-number location)))) |
33 | |
94f15c3c |
34 | |
35 | ;;;; Metaclass for boxed classes |
36 | |
37 | (eval-when (:compile-toplevel :load-toplevel :execute) |
9adccb27 |
38 | (defclass boxed-class (struct-class) |
4d83a8a6 |
39 | ()) |
94f15c3c |
40 | |
9adccb27 |
41 | (defmethod validate-superclass ((class boxed-class) (super standard-class)) |
42 | (subtypep (class-name super) 'boxed))) |
94f15c3c |
43 | |
94f15c3c |
44 | |
dfa4f314 |
45 | (defmethod shared-initialize ((class boxed-class) names &key name gtype) |
46 | (declare (ignore names)) |
9adccb27 |
47 | (call-next-method) |
dfa4f314 |
48 | (let ((class-name (or name (class-name class)))) |
49 | (unless (find-type-number class-name) |
50 | (register-type class-name |
51 | (or (first gtype) (default-type-init-name class-name)))))) |
9adccb27 |
52 | |
1dbf4216 |
53 | (defbinding %boxed-copy () pointer |
54 | (type-number type-number) |
9adccb27 |
55 | (location pointer)) |
56 | |
1dbf4216 |
57 | (defbinding %boxed-free () nil |
58 | (type-number type-number) |
9adccb27 |
59 | (location pointer)) |
60 | |
61 | (defmethod reference-foreign ((class boxed-class) location) |
1dbf4216 |
62 | (%boxed-copy (find-type-number class) location)) |
9adccb27 |
63 | |
64 | (defmethod unreference-foreign ((class boxed-class) location) |
1dbf4216 |
65 | (%boxed-free (find-type-number class) location)) |
94f15c3c |
66 | |
67 | |
d4b21b08 |
68 | ;;;; |
69 | |
62f12808 |
70 | (defun expand-boxed-type (type-number forward-p slots) |
d4b21b08 |
71 | `(defclass ,(type-from-number type-number) (boxed) |
62f12808 |
72 | ,(unless forward-p |
73 | slots) |
d4b21b08 |
74 | (:metaclass boxed-class) |
735a29da |
75 | (:gtype ,(register-type-as type-number)))) |
94f15c3c |
76 | |
b0bb0027 |
77 | (register-derivable-type 'boxed "GBoxed" 'expand-boxed-type) |
bddc0ce5 |
78 | |
79 | ;;;; Special boxed types |
80 | |
9adccb27 |
81 | ;; (defclass gstring (boxed) |
82 | ;; () |
83 | ;; (:metaclass boxed-class) |
84 | ;; (:alien-name "GString")) |
85 | |
86 | ;; (deftype-method translate-from-alien |
87 | ;; gstring (type-spec location &optional weak-ref) |
88 | ;; `(let ((location ,location)) |
89 | ;; (unless (null-pointer-p location) |
90 | ;; (prog1 |
91 | ;; (c-call::%naturalize-c-string location) |
92 | ;; ,(unless weak-ref |
93 | ;; (unreference-alien type-spec location)))))) |
94 | |
95 | ;; (deftype-method translate-to-alien |
96 | ;; gstring (type-spec string &optional weak-ref) |
97 | ;; (declare (ignore weak-ref)) |
98 | ;; `(let ((string ,string)) |
99 | ;; ;; Always copy strings to prevent seg fault due to GC |
100 | ;; (funcall |
101 | ;; ',(proxy-class-copy (find-class type-spec)) |
102 | ;; ',type-spec |
103 | ;; (make-pointer (1+ (kernel:get-lisp-obj-address string)))))) |
104 | |
105 | ;; (deftype-method cleanup-alien gstring (type-spec c-string &optional weak-ref) |
106 | ;; (when weak-ref |
107 | ;; (unreference-alien type-spec c-string))) |
bddc0ce5 |
108 | |
1dd3a887 |
109 | |
110 | |
545712f4 |
111 | ;;;; NULL terminated vector of strings |
1dd3a887 |
112 | |
545712f4 |
113 | (deftype strings () '(null-terminated-vector string)) |
dfa4f314 |
114 | (register-type 'strings '|g_strv_get_type|) |