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.1 2001-04-29 20:19:25 espen Exp $
23 (eval-when (:compile-toplevel :load-toplevel :execute)
24 (defclass boxed (alien-structure)
26 (:metaclass proxy-class)))
28 (defmethod initialize-proxy ((boxed boxed) &rest initargs
29 &key location weak-ref)
30 (declare (ignore initargs))
32 (slot-value boxed 'location)
34 (%boxed-copy (find-type-number (class-of boxed)) location)
38 (defmethod instance-finalizer ((boxed boxed))
39 (let ((location (proxy-location boxed))
40 (type-number (find-type-number (class-of boxed))))
41 (declare (type system-area-pointer location))
43 (%boxed-free type-number location)
44 (remove-cached-instance location))))
47 (deftype-method translate-to-alien boxed (type-spec boxed &optional weak-ref)
49 `(proxy-location ,boxed)
50 `(let ((boxed ,boxed))
52 (find-type-number type-spec)
53 (proxy-location boxed)))))
55 (deftype-method unreference-alien boxed (type-spec c-struct)
56 `(%boxed-free ,(find-type-number type-spec) ,c-struct))
59 (defbinding %boxed-copy () pointer
63 (defbinding %boxed-free () nil
68 ;;;; Metaclass for boxed classes
70 (eval-when (:compile-toplevel :load-toplevel :execute)
71 (defclass boxed-class (proxy-class)))
74 (defmethod shared-initialize ((class boxed-class) names
76 &key name alien-name type-init)
77 (declare (ignore initargs names))
80 (let* ((class-name (or name (class-name class)))
83 ((and alien-name type-init)
85 "Specify either :type-init or :alien-name for class ~A"
87 (alien-name (type-number-from-alien-name (first alien-name)))
89 (funcall (alien-function (first type-init) '(unsigned 32))))
92 (type-number-from-alien-name
93 (default-alien-type-name class-name) nil)
96 (default-alien-fname (format nil "~A_get_type" class-name))
98 (setf (find-type-number class) type-number)))
101 (defmethod validate-superclass
102 ((class boxed-class) (super pcl::standard-class))
103 (subtypep (class-name super) 'boxed))
106 ;;;; Initializing type numbers
108 (setf (alien-type-name 'boxed) "GBoxed")