1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2000-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: gobject.lisp,v 1.11 2002-03-24 12:50:30 espen Exp $
23 (eval-when (:compile-toplevel :load-toplevel :execute)
24 (defclass gobject (ginstance)
26 (:metaclass ginstance-class)
27 (:alien-name "GObject")
29 (:free %object-unref)))
31 (defmethod initialize-instance ((object gobject) &rest initargs)
32 (declare (ignore initargs))
33 (setf (slot-value object 'location) (%gobject-new (type-number-of object)))
36 (defbinding (%gobject-new "g_object_new") () pointer
41 (defbinding %object-ref (type location) pointer
44 (defbinding %object-unref (type location) nil
48 (defun object-ref (object)
49 (%object-ref nil (proxy-location object)))
51 (defun object-unref (object)
52 (%object-unref nil (proxy-location object)))
58 (defbinding %object-set-property () nil
63 (defbinding %object-get-property () nil
68 (defbinding %object-notify () nil
72 (defbinding object-freeze-notify () nil
75 (defbinding object-thaw-notify () nil
78 (defbinding %object-set-qdata-full () nil
82 (destroy-marshal pointer))
87 (defun (setf object-data) (data object key &key (test #'eq))
88 (%object-set-qdata-full
89 object (quark-from-object key :test test)
90 (register-user-data data) *destroy-notify*)
93 (defbinding %object-get-qdata () unsigned-long
97 (defun object-data (object key &key (test #'eq))
99 (%object-get-qdata object (quark-from-object key :test test))))
103 ;;;; Metaclass used for subclasses of gobject
105 (eval-when (:compile-toplevel :load-toplevel :execute)
106 (defclass gobject-class (ginstance-class))
108 (defclass direct-gobject-slot-definition (direct-virtual-slot-definition)
109 ((pname :reader slot-definition-pname)))
111 (defclass effective-gobject-slot-definition
112 (effective-virtual-slot-definition)))
116 ; (defbinding object-class-install-param () nil
119 ; (parameter parameter))
121 ; (defbinding object-class-find-param-spec () parameter
125 (defun signal-name-to-string (name)
126 (substitute #\_ #\- (string-downcase (string name))))
128 (defmethod initialize-instance :after ((slotd direct-gobject-slot-definition)
129 &rest initargs &key pname)
130 (declare (ignore initargs))
133 (slot-value slotd 'pname)
134 (signal-name-to-string (slot-definition-name slotd)))))
136 (defmethod direct-slot-definition-class ((class gobject-class) initargs)
137 (case (getf initargs :allocation)
138 (:property (find-class 'direct-gobject-slot-definition))
139 (t (call-next-method))))
141 (defmethod effective-slot-definition-class ((class gobject-class) initargs)
142 (case (getf initargs :allocation)
143 (:property (find-class 'effective-gobject-slot-definition))
144 (t (call-next-method))))
146 (defmethod compute-virtual-slot-accessors
147 ((class gobject-class) (slotd effective-gobject-slot-definition)
149 (with-slots (type) slotd
150 (let ((pname (slot-definition-pname (first direct-slotds)))
151 (type-number (find-type-number type)))
155 (let ((gvalue (gvalue-new type-number)))
156 (%object-get-property object pname gvalue)
159 (intern-reader-function type) gvalue +gvalue-value-offset+)
160 (gvalue-free gvalue t)))))
161 #'(lambda (value object)
163 (let ((gvalue (gvalue-new type-number)))
165 (intern-writer-function type)
166 value gvalue +gvalue-value-offset+)
167 (%object-set-property object pname gvalue)
169 (intern-destroy-function type)
170 gvalue +gvalue-value-offset+)
171 (gvalue-free gvalue nil)
174 (defmethod validate-superclass ((class gobject-class)
175 (super pcl::standard-class))
176 ; (subtypep (class-name super) 'gobject)
183 (defbinding %object-class-list-properties () pointer
185 (n-properties unsigned-int :out))
187 (defun query-object-class-properties (type-number &optional
188 inherited-properties)
189 (let ((class (type-class-ref type-number)))
190 (multiple-value-bind (array length)
191 (%object-class-list-properties class)
193 (let ((all-properties
194 (map-c-array 'list #'identity array 'param length)))
195 (if (not inherited-properties)
198 (not (eql type-number (param-owner-type param))))
201 (deallocate-memory array)))))
204 (defun default-slot-name (name)
205 (intern (substitute #\- #\_ (string-upcase (string-upcase name)))))
207 (defun default-slot-accessor (class-name slot-name type)
210 nil "~A-~A~A" class-name slot-name
211 (if (eq 'boolean type) "-P" ""))))
213 (defun expand-gobject-type (type-number &optional options
214 (metaclass 'gobject-class))
215 (let* ((supers (cons (supertype type-number) (implements type-number)))
216 (class (type-from-number type-number))
217 (override-slots (getf options :slots))
221 (with-slots (name flags value-type documentation) param
222 (let* ((slot-name (default-slot-name name))
223 (slot-type (type-from-number value-type #|t|#))
225 (default-slot-accessor class slot-name slot-type)))
227 :allocation :property
231 (member :writable flags)
232 (member :readable flags))
233 (list :accessor accessor))
234 ((member :writable flags)
235 (list :writer `(setf ,accessor)))
236 ((member :readable flags)
237 (list :reader accessor)))
239 (member :construct flags)
240 (member :writable flags))
241 (list :initarg (intern (string slot-name) "KEYWORD")))
243 ,@(when documentation
244 (list :documentation documentation))))))
245 (query-object-class-properties type-number))))
247 (dolist (slot-def override-slots)
248 (let ((name (car slot-def))
249 (pname (getf (cdr slot-def) :pname)))
253 #'(lambda (expanded-slot-def)
255 (eq name (car expanded-slot-def))
258 (string= pname (getf (cdr expanded-slot-def) :pname)))))
261 (unless (getf (cdr slot-def) :ignore)
262 (push slot-def expanded-slots))))
265 (defclass ,class ,supers
267 (:metaclass ,metaclass)
268 (:alien-name ,(find-type-name type-number))))))
271 (register-derivable-type 'gobject "GObject" 'expand-gobject-type)