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.9 2001/10/21 21:52:53 espen Exp $
23 (eval-when (:compile-toplevel :load-toplevel :execute)
24 (defclass gobject (ginstance)
26 (:metaclass ginstance-class)
27 (:alien-name "GObject")
29 (:unref "g_object_unref")))
31 (defmethod initialize-instance ((object gobject) &rest initargs)
32 (declare (ignore initargs))
34 (slot-value object 'location)
35 (%gobject-new (type-number-of object)))
36 ; (funcall (proxy-class-copy (class-of object)) nil (proxy-location object))
38 ; (funcall (proxy-class-free (class-of object)) nil (proxy-location object))
41 (defbinding (%gobject-new "g_object_new") () pointer
49 (defbinding %object-set-property () nil
54 (defbinding %object-get-property () nil
59 (defbinding %object-notify () nil
63 (defbinding object-freeze-notify () nil
66 (defbinding object-thaw-notify () nil
69 (defbinding %object-set-qdata-full () nil
73 (destroy-marshal pointer))
78 (defun (setf object-data) (data object key &key (test #'eq))
79 (%object-set-qdata-full
80 object (quark-from-object key :test test)
81 (register-user-data data) *destroy-notify*)
84 (defbinding %object-get-qdata () unsigned-long
88 (defun object-data (object key &key (test #'eq))
90 (%object-get-qdata object (quark-from-object key :test test))))
94 ;;;; Metaclass used for subclasses of gobject
96 (eval-when (:compile-toplevel :load-toplevel :execute)
97 (defclass gobject-class (ginstance-class))
99 (defclass direct-gobject-slot-definition (direct-virtual-slot-definition)
100 ((pname :reader slot-definition-pname)))
102 (defclass effective-gobject-slot-definition
103 (effective-virtual-slot-definition)))
107 ; (defbinding object-class-install-param () nil
110 ; (parameter parameter))
112 ; (defbinding object-class-find-param-spec () parameter
117 (defmethod initialize-instance :after ((slotd direct-gobject-slot-definition)
118 &rest initargs &key pname)
119 (declare (ignore initargs))
122 (slot-value slotd 'pname)
123 (signal-name-to-string (slot-definition-name slotd)))))
125 (defmethod direct-slot-definition-class ((class gobject-class) initargs)
126 (case (getf initargs :allocation)
127 (:property (find-class 'direct-gobject-slot-definition))
128 (t (call-next-method))))
130 (defmethod effective-slot-definition-class ((class gobject-class) initargs)
131 (case (getf initargs :allocation)
132 (:property (find-class 'effective-gobject-slot-definition))
133 (t (call-next-method))))
135 (defmethod compute-virtual-slot-accessors
136 ((class gobject-class) (slotd effective-gobject-slot-definition)
138 (with-slots (type) slotd
139 (let ((pname (slot-definition-pname (first direct-slotds)))
140 (type-number (find-type-number type)))
144 (let ((gvalue (gvalue-new type-number)))
145 (%object-get-property object pname gvalue)
148 (intern-reader-function type) gvalue +gvalue-value-offset+)
149 (gvalue-free gvalue t)))))
150 #'(lambda (value object)
152 (let ((gvalue (gvalue-new type-number)))
154 (intern-writer-function type)
155 value gvalue +gvalue-value-offset+)
156 (%object-set-property object pname gvalue)
158 (intern-destroy-function type)
159 gvalue +gvalue-value-offset+)
160 (gvalue-free gvalue nil)
163 (defmethod validate-superclass ((class gobject-class)
164 (super pcl::standard-class))
165 ; (subtypep (class-name super) 'gobject)
172 (defbinding %object-class-list-properties () pointer
174 (n-properties unsigned-int :out))
176 (defun query-object-class-properties (type-number &optional
177 inherited-properties)
178 (let ((class (type-class-ref type-number)))
179 (multiple-value-bind (array length)
180 (%object-class-list-properties class)
182 (let ((all-properties
183 (map-c-array 'list #'identity array 'param length)))
184 (if (not inherited-properties)
187 (not (eql type-number (param-owner-type param))))
190 (deallocate-memory array)))))
193 (defun default-slot-name (name)
194 (intern (substitute #\- #\_ (string-upcase (string-upcase name)))))
196 (defun default-slot-accessor (class-name slot-name type)
199 nil "~A-~A~A" class-name slot-name
200 (if (eq 'boolean type) "-P" ""))))
202 (defun expand-gobject-type (type-number &optional options
203 (metaclass 'gobject-class))
204 (let* ((super (supertype type-number))
205 (class (type-from-number type-number))
206 (override-slots (getf options :slots))
210 (with-slots (name flags value-type documentation) param
211 (let* ((slot-name (default-slot-name name))
212 (slot-type (type-from-number value-type #|t|#))
214 (default-slot-accessor class slot-name slot-type)))
216 :allocation :property
220 (member :writable flags)
221 (member :readable flags))
222 (list :accessor accessor))
223 ((member :writable flags)
224 (list :writer `(setf ,accessor)))
225 ((member :readable flags)
226 (list :reader accessor)))
228 (member :construct flags)
229 (member :writable flags))
230 (list :initarg (intern (string slot-name) "KEYWORD")))
232 ,@(when documentation
233 (list :documentation documentation))))))
234 (query-object-class-properties type-number))))
236 (dolist (slot-def override-slots)
237 (let ((name (car slot-def))
238 (pname (getf (cdr slot-def) :pname)))
242 #'(lambda (expanded-slot-def)
244 (eq name (car expanded-slot-def))
247 (string= pname (getf (cdr expanded-slot-def) :pname)))))
250 (unless (getf (cdr slot-def) :ignore)
251 (push slot-def expanded-slots))))
254 (defclass ,class (,super)
256 (:metaclass ,metaclass)
257 (:alien-name ,(find-type-name type-number))))))
260 (register-derivable-type 'gobject "GObject" 'expand-gobject-type)