1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2000 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.4 2001-01-28 14:17:12 espen Exp $
23 (eval-when (:compile-toplevel :load-toplevel :execute)
24 (defclass gobject (ginstance)
26 (:metaclass ginstance-class)
27 (:alien-name "GObject")))
30 ;;;; Object construction
32 (define-foreign ("g_object_new" %gobject-new) () gobject
37 ;;;; Reference counting for gobject
39 ;; Specializing reference-instance and unreference-instance on gobject
40 ;; is not really necessary but done for efficiency
42 (defmethod reference-instance ((object gobject))
46 (defmethod unreference-instance ((object gobject))
47 (%object-unref object))
49 (deftype-method alien-ref gobject (type-spec)
50 (declare (ignore type-spec))
53 (deftype-method alien-unref gobject (type-spec)
54 (declare (ignore type-spec))
57 (define-foreign %object-ref () pointer
58 (object (or gobject pointer)))
60 (define-foreign %object-unref () nil
61 (object (or gobject pointer)))
66 (define-foreign %object-set-property () nil
71 (define-foreign %object-get-property () nil
76 (define-foreign %object-notify () nil
80 (define-foreign object-freeze-notify () nil
83 (define-foreign object-thaw-notify () nil
86 (define-foreign %object-set-qdata-full () nil
90 (destroy-marshal pointer))
95 (defun (setf object-data) (data object key &key (test #'eq))
96 (%object-set-qdata-full
97 object (quark-from-object key :test test)
98 (register-user-data data) *destroy-notify*)
101 (define-foreign %object-get-qdata () unsigned-long
105 (defun object-data (object key &key (test #'eq))
107 (%object-get-qdata object (quark-from-object key :test test))))
111 ;;;; Metaclass used for subclasses of gobject
113 (eval-when (:compile-toplevel :load-toplevel :execute)
114 (defclass gobject-class (ginstance-class))
116 (defclass direct-gobject-slot-definition (direct-virtual-slot-definition))
118 (defclass effective-gobject-slot-definition
119 (effective-virtual-slot-definition)))
121 (defmethod allocate-alien-storage ((class gobject-class))
122 (alien-instance-location (%gobject-new (find-type-number class))))
124 (defmethod shared-initialize ((class gobject-class) names &rest initargs
126 (declare (ignore initargs names))
129 (alien::make-heap-alien-info
130 :type (alien::parse-alien-type '(function (unsigned 32)))
131 :sap-form (system:foreign-symbol-address
134 (default-alien-func-name
136 nil "~A_get_type" (or name (class-name class))))))))))
137 (alien:alien-funcall alien))
141 ; (define-foreign object-class-install-param () nil
144 ; (parameter parameter))
146 ; (define-foreign object-class-find-param-spec () parameter
151 (defmethod initialize-instance :after ((slotd direct-gobject-slot-definition)
153 (declare (ignore initargs))
154 (unless (slot-boundp slotd 'location)
155 ;; Find parameter name from slot name
156 (with-slots (pcl::name location) slotd
157 (setf location (signal-name-to-string pcl::name)))))
159 (defmethod direct-slot-definition-class ((class gobject-class) initargs)
160 (case (getf initargs :allocation)
161 (:param (find-class 'direct-gobject-slot-definition))
162 (t (call-next-method))))
164 (defmethod effective-slot-definition-class ((class gobject-class) initargs)
165 (case (getf initargs :allocation)
166 (:param (find-class 'effective-gobject-slot-definition))
167 (t (call-next-method))))
169 (defmethod compute-virtual-slot-location
170 ((class gobject-class) (slotd effective-gobject-slot-definition)
172 (with-slots (type) slotd
173 (let ((param-name (slot-definition-location (first direct-slotds)))
174 (type-number (find-type-number type))
175 (reader (get-reader-function type))
176 (writer (get-writer-function type))
177 (destroy (get-destroy-function type)))
181 (let ((gvalue (gvalue-new type-number)))
182 (%object-get-property object param-name gvalue)
184 (funcall reader gvalue +gvalue-value-offset+)
185 (gvalue-free gvalue t)))))
186 #'(lambda (value object)
188 (let ((gvalue (gvalue-new type-number)))
189 (funcall writer value gvalue +gvalue-value-offset+)
190 (%object-set-property object param-name gvalue)
191 (funcall destroy gvalue +gvalue-value-offset+)
192 (gvalue-free gvalue nil)
196 (defmethod validate-superclass ((class gobject-class)
197 (super pcl::standard-class))
198 (subtypep (class-name super) 'gobject))