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.8 2001-05-29 15:50:31 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)))
38 (defbinding (%gobject-new "g_object_new") () pointer
46 (defbinding %object-set-property () nil
51 (defbinding %object-get-property () nil
56 (defbinding %object-notify () nil
60 (defbinding object-freeze-notify () nil
63 (defbinding object-thaw-notify () nil
66 (defbinding %object-set-qdata-full () nil
70 (destroy-marshal pointer))
75 (defun (setf object-data) (data object key &key (test #'eq))
76 (%object-set-qdata-full
77 object (quark-from-object key :test test)
78 (register-user-data data) *destroy-notify*)
81 (defbinding %object-get-qdata () unsigned-long
85 (defun object-data (object key &key (test #'eq))
87 (%object-get-qdata object (quark-from-object key :test test))))
91 ;;;; Metaclass used for subclasses of gobject
93 (eval-when (:compile-toplevel :load-toplevel :execute)
94 (defclass gobject-class (ginstance-class))
96 (defclass direct-gobject-slot-definition (direct-virtual-slot-definition)
97 ((param :reader slot-definition-param)))
99 (defclass effective-gobject-slot-definition
100 (effective-virtual-slot-definition)))
104 ; (defbinding object-class-install-param () nil
107 ; (parameter parameter))
109 ; (defbinding object-class-find-param-spec () parameter
114 (defmethod initialize-instance :after ((slotd direct-gobject-slot-definition)
115 &rest initargs &key param)
116 (declare (ignore initargs))
119 (slot-value slotd 'param)
120 (signal-name-to-string (slot-definition-name slotd)))))
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))))
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))))
132 (defmethod compute-virtual-slot-accessors
133 ((class gobject-class) (slotd effective-gobject-slot-definition)
135 (with-slots (type) slotd
136 (let ((param-name (slot-definition-param (first direct-slotds)))
137 (type-number (find-type-number type)))
141 (let ((gvalue (gvalue-new type-number)))
142 (%object-get-property object param-name gvalue)
145 (intern-reader-function type) gvalue +gvalue-value-offset+)
146 (gvalue-free gvalue t)))))
147 #'(lambda (value object)
149 (let ((gvalue (gvalue-new type-number)))
151 (intern-writer-function type)
152 value gvalue +gvalue-value-offset+)
153 (%object-set-property object param-name gvalue)
155 (intern-destroy-function type)
156 gvalue +gvalue-value-offset+)
157 (gvalue-free gvalue nil)
160 (defmethod validate-superclass ((class gobject-class)
161 (super pcl::standard-class))
162 ; (subtypep (class-name super) 'gobject)
169 (defbinding %object-class-properties () pointer
171 (n-properties unsigned-int :out))
173 (defun query-object-class-properties (type-number)
174 (let ((class (type-class-ref type-number)))
175 (multiple-value-bind (array length)
176 (%object-class-properties class)
177 (map-c-array 'list #'identity array 'param length))))
179 (defun query-object-type-dependencies (type-number)
185 ;; A gobject does not depend on it's supertypes due to forward
186 ;; referenced superclasses
189 (type-is-p type-number type))
190 (type-hierarchy (param-type param))))
191 (query-object-class-properties type-number)))))
194 (defun default-slot-name (name)
195 (intern (substitute #\- #\_ (string-upcase (string-upcase name)))))
197 (defun default-slot-accessor (class-name slot-name type)
200 nil "~A-~A~A" class-name slot-name
201 (if (eq 'boolean type) "-P" ""))))
203 (defun expand-gobject-type (type-number &optional slots
204 (metaclass 'gobject-class))
205 (let* ((super (supertype type-number))
206 (class (type-from-number type-number))
210 (with-slots (name flags type documentation) param
211 (let* ((slot-name (default-slot-name name))
212 (slot-type (type-from-number type #|t|#))
214 (default-slot-accessor class slot-name slot-type)))
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 `(defclass ,class (,super)
238 (:metaclass ,metaclass)
239 (:alien-name ,(find-type-name type-number)))))
241 (register-derivable-type
243 :query 'query-object-type-dependencies
244 :expand 'expand-gobject-type)