1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2001 Espen S. Johnsen <esj@stud.cs.uit.no>
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.
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.
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
18 ;; $Id: gboxed.lisp,v 1.14 2005/02/01 15:24:52 espen Exp $
23 (eval-when (:compile-toplevel :load-toplevel :execute)
24 (init-types-in-library #.(concatenate 'string
25 (pkg-config:pkg-variable "glib-2.0" "libdir")
26 "/libgobject-2.0.so")))
28 (defclass boxed (struct)
30 (:metaclass struct-class))
32 (defmethod instance-finalizer ((instance boxed))
33 (let ((location (proxy-location instance))
34 (type-number (type-number-of instance)))
36 (remove-cached-instance location)
37 (%boxed-free type-number location))))
40 ;;;; Metaclass for boxed classes
42 (eval-when (:compile-toplevel :load-toplevel :execute)
43 (defclass boxed-class (struct-class)
46 (defmethod validate-superclass ((class boxed-class) (super standard-class))
47 (subtypep (class-name super) 'boxed)))
50 (defmethod shared-initialize ((class boxed-class) names
51 &rest initargs &key name alien-name)
52 (declare (ignore initargs names))
55 (let* ((class-name (or name (class-name class)))
58 (or (first alien-name) (default-alien-type-name class-name)))))
59 (register-type class-name type-number)))
62 (defbinding %boxed-copy () pointer
63 (type-number type-number)
66 (defbinding %boxed-free () nil
67 (type-number type-number)
70 (defmethod reference-foreign ((class boxed-class) location)
71 (%boxed-copy (find-type-number class) location))
73 (defmethod unreference-foreign ((class boxed-class) location)
74 (%boxed-free (find-type-number class) location))
79 (defun expand-boxed-type (type-number forward-p slots)
80 `(defclass ,(type-from-number type-number) (boxed)
83 (:metaclass boxed-class)
84 (:alien-name ,(find-type-name type-number))))
86 (register-derivable-type 'boxed "GBoxed" 'expand-boxed-type)
88 ;;;; Special boxed types
90 ;; (defclass gstring (boxed)
92 ;; (:metaclass boxed-class)
93 ;; (:alien-name "GString"))
95 ;; (deftype-method translate-from-alien
96 ;; gstring (type-spec location &optional weak-ref)
97 ;; `(let ((location ,location))
98 ;; (unless (null-pointer-p location)
100 ;; (c-call::%naturalize-c-string location)
102 ;; (unreference-alien type-spec location))))))
104 ;; (deftype-method translate-to-alien
105 ;; gstring (type-spec string &optional weak-ref)
106 ;; (declare (ignore weak-ref))
107 ;; `(let ((string ,string))
108 ;; ;; Always copy strings to prevent seg fault due to GC
110 ;; ',(proxy-class-copy (find-class type-spec))
112 ;; (make-pointer (1+ (kernel:get-lisp-obj-address string))))))
114 ;; (deftype-method cleanup-alien gstring (type-spec c-string &optional weak-ref)
116 ;; (unreference-alien type-spec c-string)))