chiark / gitweb /
Hopefully allow (require :glib) again.
[clg] / glib / gboxed.lisp
CommitLineData
112ac1d3 1;; Common Lisp bindings for GTK+ v2.x
b8955a28 2;; Copyright 2001-2006 Espen S. Johnsen <espen@users.sf.net>
94f15c3c 3;;
112ac1d3 4;; Permission is hereby granted, free of charge, to any person obtaining
5;; a copy of this software and associated documentation files (the
6;; "Software"), to deal in the Software without restriction, including
7;; without limitation the rights to use, copy, modify, merge, publish,
8;; distribute, sublicense, and/or sell copies of the Software, and to
9;; permit persons to whom the Software is furnished to do so, subject to
10;; the following conditions:
94f15c3c 11;;
112ac1d3 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
94f15c3c 14;;
112ac1d3 15;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
b8955a28 23;; $Id: gboxed.lisp,v 1.21 2006-04-25 21:55:42 espen Exp $
94f15c3c 24
25(in-package "GLIB")
26
27
2b481386 28(defclass boxed (struct)
9adccb27 29 ()
30 (:metaclass struct-class))
94f15c3c 31
1dbf4216 32(defmethod instance-finalizer ((instance boxed))
09f6e237 33 (let ((location (foreign-location instance))
1dbf4216 34 (type-number (type-number-of instance)))
35 #'(lambda ()
1dbf4216 36 (%boxed-free type-number location))))
37
94f15c3c 38
39;;;; Metaclass for boxed classes
40
41(eval-when (:compile-toplevel :load-toplevel :execute)
9adccb27 42 (defclass boxed-class (struct-class)
4d83a8a6 43 ())
94f15c3c 44
9adccb27 45 (defmethod validate-superclass ((class boxed-class) (super standard-class))
46 (subtypep (class-name super) 'boxed)))
94f15c3c 47
94f15c3c 48
1dbf4216 49(defbinding %boxed-copy () pointer
50 (type-number type-number)
9adccb27 51 (location pointer))
52
1dbf4216 53(defbinding %boxed-free () nil
54 (type-number type-number)
9adccb27 55 (location pointer))
56
b8955a28 57(defmethod shared-initialize ((class boxed-class) names
58 &key name gtype ref unref)
59 (declare (ignore names))
60 (let* ((class-name (or name (class-name class)))
61 (type-number
62 (register-type class-name
63 (or
64 (first gtype)
65 (default-type-init-name class-name)))))
66 (unless (or ref (slot-boundp class 'ref))
67 (setf
68 (slot-value class 'ref)
69 #'(lambda (location)
70 (%boxed-copy type-number location))))
71 (unless (or unref (slot-boundp class 'unref))
72 (setf
73 (slot-value class 'unref)
74 #'(lambda (location)
75 (%boxed-free type-number location)))))
76 (call-next-method))
94f15c3c 77
d4b21b08 78
62f12808 79(defun expand-boxed-type (type-number forward-p slots)
d4b21b08 80 `(defclass ,(type-from-number type-number) (boxed)
62f12808 81 ,(unless forward-p
82 slots)
d4b21b08 83 (:metaclass boxed-class)
735a29da 84 (:gtype ,(register-type-as type-number))))
94f15c3c 85
b0bb0027 86(register-derivable-type 'boxed "GBoxed" 'expand-boxed-type)
bddc0ce5 87
1dd3a887 88
545712f4 89;;;; NULL terminated vector of strings
1dd3a887 90
545712f4 91(deftype strings () '(null-terminated-vector string))
dfa4f314 92(register-type 'strings '|g_strv_get_type|)