0d07716f |
1 | ;; Common Lisp bindings for GTK+ v2.0 |
ca0a8e30 |
2 | ;; Copyright (C) 2000-2001 Espen S. Johnsen <esj@stud.cs.uit.no> |
0d07716f |
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 | |
b011356b |
18 | ;; $Id: gobject.lisp,v 1.8 2001/05/29 15:50:31 espen Exp $ |
0d07716f |
19 | |
20 | (in-package "GLIB") |
21 | |
22 | |
23 | (eval-when (:compile-toplevel :load-toplevel :execute) |
c9819f3e |
24 | (defclass gobject (ginstance) |
0d07716f |
25 | () |
c9819f3e |
26 | (:metaclass ginstance-class) |
ca0a8e30 |
27 | (:alien-name "GObject") |
28 | (:ref "g_object_ref") |
29 | (:unref "g_object_unref"))) |
0d07716f |
30 | |
ca0a8e30 |
31 | (defmethod initialize-instance ((object gobject) &rest initargs) |
32 | (declare (ignore initargs)) |
33 | (setf |
34 | (slot-value object 'location) |
35 | (%gobject-new (type-number-of object))) |
36 | (call-next-method)) |
b75a7b77 |
37 | |
3a935dfa |
38 | (defbinding (%gobject-new "g_object_new") () pointer |
b75a7b77 |
39 | (type type-number) |
40 | (nil null)) |
0d07716f |
41 | |
42 | |
3a935dfa |
43 | |
c9819f3e |
44 | ;;;; Parameter stuff |
0d07716f |
45 | |
c2cd6b3a |
46 | (defbinding %object-set-property () nil |
c9819f3e |
47 | (object gobject) |
48 | (name string) |
49 | (value gvalue)) |
a905f5d9 |
50 | |
c2cd6b3a |
51 | (defbinding %object-get-property () nil |
c9819f3e |
52 | (object gobject) |
53 | (name string) |
b75a7b77 |
54 | (value gvalue)) |
a905f5d9 |
55 | |
c2cd6b3a |
56 | (defbinding %object-notify () nil |
c9819f3e |
57 | (object gobject) |
58 | (name string)) |
a905f5d9 |
59 | |
c2cd6b3a |
60 | (defbinding object-freeze-notify () nil |
b75a7b77 |
61 | (object gobject)) |
a905f5d9 |
62 | |
c2cd6b3a |
63 | (defbinding object-thaw-notify () nil |
b75a7b77 |
64 | (object gobject)) |
a905f5d9 |
65 | |
c2cd6b3a |
66 | (defbinding %object-set-qdata-full () nil |
a905f5d9 |
67 | (object gobject) |
68 | (id quark) |
69 | (data unsigned-long) |
70 | (destroy-marshal pointer)) |
71 | |
b75a7b77 |
72 | |
73 | ;;;; User data |
74 | |
a905f5d9 |
75 | (defun (setf object-data) (data object key &key (test #'eq)) |
76 | (%object-set-qdata-full |
77 | object (quark-from-object key :test test) |
c9819f3e |
78 | (register-user-data data) *destroy-notify*) |
a905f5d9 |
79 | data) |
80 | |
c2cd6b3a |
81 | (defbinding %object-get-qdata () unsigned-long |
a905f5d9 |
82 | (object gobject) |
83 | (id quark)) |
84 | |
85 | (defun object-data (object key &key (test #'eq)) |
86 | (find-user-data |
87 | (%object-get-qdata object (quark-from-object key :test test)))) |
88 | |
89 | |
0d07716f |
90 | |
b75a7b77 |
91 | ;;;; Metaclass used for subclasses of gobject |
92 | |
93 | (eval-when (:compile-toplevel :load-toplevel :execute) |
94 | (defclass gobject-class (ginstance-class)) |
c9819f3e |
95 | |
3a935dfa |
96 | (defclass direct-gobject-slot-definition (direct-virtual-slot-definition) |
97 | ((param :reader slot-definition-param))) |
c9819f3e |
98 | |
b75a7b77 |
99 | (defclass effective-gobject-slot-definition |
100 | (effective-virtual-slot-definition))) |
c9819f3e |
101 | |
b011356b |
102 | |
0d07716f |
103 | |
c2cd6b3a |
104 | ; (defbinding object-class-install-param () nil |
0d07716f |
105 | ; (class pointer) |
106 | ; (id unsigned-int) |
107 | ; (parameter parameter)) |
108 | |
c2cd6b3a |
109 | ; (defbinding object-class-find-param-spec () parameter |
0d07716f |
110 | ; (class pointer) |
111 | ; (name string)) |
112 | |
b75a7b77 |
113 | |
114 | (defmethod initialize-instance :after ((slotd direct-gobject-slot-definition) |
3a935dfa |
115 | &rest initargs &key param) |
b75a7b77 |
116 | (declare (ignore initargs)) |
3a935dfa |
117 | (when param |
118 | (setf |
119 | (slot-value slotd 'param) |
120 | (signal-name-to-string (slot-definition-name slotd))))) |
b75a7b77 |
121 | |
122 | (defmethod direct-slot-definition-class ((class gobject-class) initargs) |
123 | (case (getf initargs :allocation) |
124 | (:param (find-class 'direct-gobject-slot-definition)) |
125 | (t (call-next-method)))) |
126 | |
127 | (defmethod effective-slot-definition-class ((class gobject-class) initargs) |
128 | (case (getf initargs :allocation) |
129 | (:param (find-class 'effective-gobject-slot-definition)) |
130 | (t (call-next-method)))) |
131 | |
3a935dfa |
132 | (defmethod compute-virtual-slot-accessors |
b75a7b77 |
133 | ((class gobject-class) (slotd effective-gobject-slot-definition) |
134 | direct-slotds) |
135 | (with-slots (type) slotd |
3a935dfa |
136 | (let ((param-name (slot-definition-param (first direct-slotds))) |
b011356b |
137 | (type-number (find-type-number type))) |
b75a7b77 |
138 | (list |
139 | #'(lambda (object) |
140 | (with-gc-disabled |
141 | (let ((gvalue (gvalue-new type-number))) |
142 | (%object-get-property object param-name gvalue) |
143 | (prog1 |
b011356b |
144 | (funcall |
145 | (intern-reader-function type) gvalue +gvalue-value-offset+) |
b75a7b77 |
146 | (gvalue-free gvalue t))))) |
147 | #'(lambda (value object) |
148 | (with-gc-disabled |
149 | (let ((gvalue (gvalue-new type-number))) |
b011356b |
150 | (funcall |
151 | (intern-writer-function type) |
152 | value gvalue +gvalue-value-offset+) |
b75a7b77 |
153 | (%object-set-property object param-name gvalue) |
b011356b |
154 | (funcall |
155 | (intern-destroy-function type) |
156 | gvalue +gvalue-value-offset+) |
b75a7b77 |
157 | (gvalue-free gvalue nil) |
158 | value))))))) |
159 | |
b75a7b77 |
160 | (defmethod validate-superclass ((class gobject-class) |
161 | (super pcl::standard-class)) |
b011356b |
162 | ; (subtypep (class-name super) 'gobject) |
163 | t) |
3a935dfa |
164 | |
165 | |
166 | |
167 | ;;;; |
168 | |
169 | (defbinding %object-class-properties () pointer |
170 | (class pointer) |
171 | (n-properties unsigned-int :out)) |
172 | |
b011356b |
173 | (defun query-object-class-properties (type-number) |
174 | (let ((class (type-class-ref type-number))) |
3a935dfa |
175 | (multiple-value-bind (array length) |
176 | (%object-class-properties class) |
177 | (map-c-array 'list #'identity array 'param length)))) |
178 | |
b011356b |
179 | (defun query-object-type-dependencies (type-number) |
3a935dfa |
180 | (delete-duplicates |
181 | (reduce |
182 | #'nconc |
183 | (mapcar |
184 | #'(lambda (param) |
185 | ;; A gobject does not depend on it's supertypes due to forward |
186 | ;; referenced superclasses |
b011356b |
187 | (delete-if |
188 | #'(lambda (type) |
189 | (type-is-p type-number type)) |
3a935dfa |
190 | (type-hierarchy (param-type param)))) |
b011356b |
191 | (query-object-class-properties type-number))))) |
3a935dfa |
192 | |
193 | |
194 | (defun default-slot-name (name) |
195 | (intern (substitute #\- #\_ (string-upcase (string-upcase name))))) |
196 | |
197 | (defun default-slot-accessor (class-name slot-name type) |
198 | (intern |
199 | (format |
200 | nil "~A-~A~A" class-name slot-name |
b011356b |
201 | (if (eq 'boolean type) "-P" "")))) |
3a935dfa |
202 | |
b011356b |
203 | (defun expand-gobject-type (type-number &optional slots |
204 | (metaclass 'gobject-class)) |
3a935dfa |
205 | (let* ((super (supertype type-number)) |
206 | (class (type-from-number type-number)) |
207 | (expanded-slots |
208 | (mapcar |
209 | #'(lambda (param) |
210 | (with-slots (name flags type documentation) param |
211 | (let* ((slot-name (default-slot-name name)) |
b011356b |
212 | (slot-type (type-from-number type #|t|#)) |
3a935dfa |
213 | (accessor |
214 | (default-slot-accessor class slot-name slot-type))) |
215 | `(,slot-name |
216 | :allocation :param |
217 | :param ,name |
b011356b |
218 | ,@(cond |
219 | ((and |
220 | (member :writable flags) |
221 | (member :readable flags)) |
222 | (list :accessor accessor)) |
223 | ((member :writable flags) |
3a935dfa |
224 | (list :writer `(setf ,accessor))) |
b011356b |
225 | ((member :readable flags) |
226 | (list :reader accessor))) |
227 | ,@(when (or |
228 | (member :construct flags) |
229 | (member :writable flags)) |
3a935dfa |
230 | (list :initarg (intern (string slot-name) "KEYWORD"))) |
231 | :type ,slot-type |
232 | ,@(when documentation |
233 | (list :documentation documentation)))))) |
234 | (query-object-class-properties type-number)))) |
235 | |
236 | `(defclass ,class (,super) |
237 | ,expanded-slots |
b011356b |
238 | (:metaclass ,metaclass) |
3a935dfa |
239 | (:alien-name ,(find-type-name type-number))))) |
240 | |
241 | (register-derivable-type |
242 | 'gobject "GObject" |
b011356b |
243 | :query 'query-object-type-dependencies |
3a935dfa |
244 | :expand 'expand-gobject-type) |
245 | |