chiark / gitweb /
Changes to gvalue, renaming of some accessor functions
[clg] / glib / ginterface.lisp
CommitLineData
55212af1 1;; Common Lisp bindings for GTK+ v2.x
2;; Copyright 2001-2005 Espen S. Johnsen <espen@users.sf.net>
24af32f5 3;;
55212af1 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:
24af32f5 11;;
55212af1 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
24af32f5 14;;
55212af1 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
4b2f29e4 23;; $Id: ginterface.lisp,v 1.17 2006/04/25 22:02:34 espen Exp $
24af32f5 24
25(in-package "GLIB")
26
27(use-prefix "g")
28
29;;;;
30
935a783c 31(defclass ginterface ()
32 ())
24af32f5 33
24af32f5 34;;;; Metaclass for interfaces
35
36(eval-when (:compile-toplevel :load-toplevel :execute)
6baf860c 37 (defclass ginterface-class (virtual-slots-class)
935a783c 38 ()))
24af32f5 39
b7833c4c 40(defmethod direct-slot-definition-class ((class ginterface-class) &rest initargs)
41 (case (getf initargs :allocation)
42 (:property (find-class 'direct-property-slot-definition))
43 (t (call-next-method))))
44
45(defmethod effective-slot-definition-class ((class ginterface-class) &rest initargs)
46 (case (getf initargs :allocation)
47 (:property (find-class 'effective-property-slot-definition))
48 (t (call-next-method))))
49
50(defmethod compute-effective-slot-definition-initargs ((class ginterface-class) direct-slotds)
c23cc486 51 (if (eq (slot-definition-allocation (first direct-slotds)) :property)
b7833c4c 52 (nconc
53 (list :pname (signal-name-to-string
54 (most-specific-slot-value direct-slotds 'pname))
55 :readable (most-specific-slot-value direct-slotds 'readable)
56 :writable (most-specific-slot-value direct-slotds 'writable)
f9364484 57 :construct-only (most-specific-slot-value direct-slotds 'construct))
b7833c4c 58 (call-next-method))
59 (call-next-method)))
60
24af32f5 61
dcb31db6 62(defmethod shared-initialize ((class ginterface-class) names &key name gtype)
63 (declare (ignore names))
b8211bee 64 (let* ((class-name (or name (class-name class)))
65 (type-number
66 (or
67 (find-type-number class-name)
68 (register-type class-name
69 (or (first gtype) (default-type-init-name class-name))))))
70 (type-default-interface-ref type-number))
24af32f5 71 (call-next-method))
72
73
3d36c5d6 74(defmethod validate-superclass ((class ginterface-class) (super standard-class))
24af32f5 75 (subtypep (class-name super) 'ginterface))
76
77
4d1fea77 78(define-type-method alien-type ((type ginterface))
79 (declare (ignore type))
6baf860c 80 (alien-type 'gobject))
81
4b2f29e4 82(define-type-method size-of ((type ginterface) &key inlined)
83 (assert-not-inlined type inlined)
6baf860c 84 (size-of 'gobject))
85
4b2f29e4 86(define-type-method from-alien-form ((type ginterface) location &key (ref :copy))
4d1fea77 87 (declare (ignore type))
4b2f29e4 88 (from-alien-form 'gobject location :ref ref))
6baf860c 89
4b2f29e4 90(define-type-method from-alien-function ((type ginterface) &key (ref :copy))
4d1fea77 91 (declare (ignore type))
4b2f29e4 92 (from-alien-function 'gobject :ref ref))
6baf860c 93
4b2f29e4 94(define-type-method to-alien-form ((type ginterface) instance &optional copy-p)
4d1fea77 95 (declare (ignore type))
4b2f29e4 96 (to-alien-form 'gobject instance copy-p))
6baf860c 97
4b2f29e4 98(define-type-method to-alien-function ((type ginterface) &optional copy-p)
4d1fea77 99 (declare (ignore type))
4b2f29e4 100 (to-alien-function 'gobject copy-p))
6baf860c 101
4b2f29e4 102(define-type-method reader-function ((type ginterface) &key ref inlined)
103 (assert-not-inlined type inlined)
104 (reader-function 'gobject :ref ref))
17731c75 105
4b2f29e4 106(define-type-method writer-function ((type ginterface) &key temp inlined)
107 (assert-not-inlined type inlined)
108 (writer-function 'gobject :temp temp))
17731c75 109
4b2f29e4 110(define-type-method destroy-function ((type ginterface) &key temp inlined)
111 (assert-not-inlined type inlined)
112 (destroy-function 'gobject :temp temp))
17731c75 113
6baf860c 114
24af32f5 115;;;;
116
b7833c4c 117
118(defbinding type-default-interface-ref (type) pointer
119 ((find-type-number type t) type-number))
120
b8211bee 121(defbinding type-default-interface-unref () nil
122 (iface pointer))
b7833c4c 123
124(defbinding type-default-interface-peek (type) pointer
125 ((find-type-number type t) type-number))
126
127(defbinding %object-interface-list-properties () pointer
128 (iface pointer)
129 (n-properties unsigned-int :out))
130
131(defun query-object-interface-properties (type &optional inherited-p)
132 (let* ((type-number (find-type-number type))
133 (iface (type-default-interface-ref type-number)))
134 (unwind-protect
135 (multiple-value-bind (array length)
136 (%object-interface-list-properties iface)
6556dccd 137 (unless (null-pointer-p array)
138 (unwind-protect
139 (%map-params array length type-number inherited-p)
140 (deallocate-memory array))))
b8211bee 141 (type-default-interface-unref iface))))
b7833c4c 142
143
e9934f39 144(defun expand-ginterface-type (type forward-p options &rest args)
24af32f5 145 (declare (ignore args))
b7833c4c 146 (let ((class (type-from-number type))
e9934f39 147 (slots (getf options :slots)))
b7833c4c 148 `(defclass ,class (,(supertype type))
e9934f39 149 ,(unless forward-p
150 (slot-definitions class (query-object-interface-properties type) slots))
b7833c4c 151 (:metaclass ginterface-class)
80031aba 152 (:gtype ,(register-type-as type)))))
24af32f5 153
4b2f29e4 154(defun ginterface-dependencies (type options)
6556dccd 155 (delete-duplicates
156 (cons
157 (supertype type)
4b2f29e4 158 (append
159 (mapcar #'param-value-type (query-object-interface-properties type))
160 (loop
161 for slot in (getf options :slots)
162 as type = (getf (rest slot) :type)
163 when (and type (symbolp type) (find-type-number type))
164 collect (find-type-number type))))))
165
24af32f5 166
e9934f39 167(register-derivable-type 'ginterface "GInterface" 'expand-ginterface-type 'ginterface-dependencies)