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.6 2001/04/29 20:34:18 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 ("g_object_new" %gobject-new) () gobject
45 (defbinding %object-set-property () nil
50 (defbinding %object-get-property () nil
55 (defbinding %object-notify () nil
59 (defbinding object-freeze-notify () nil
62 (defbinding object-thaw-notify () nil
65 (defbinding %object-set-qdata-full () nil
69 (destroy-marshal pointer))
74 (defun (setf object-data) (data object key &key (test #'eq))
75 (%object-set-qdata-full
76 object (quark-from-object key :test test)
77 (register-user-data data) *destroy-notify*)
80 (defbinding %object-get-qdata () unsigned-long
84 (defun object-data (object key &key (test #'eq))
86 (%object-get-qdata object (quark-from-object key :test test))))
90 ;;;; Metaclass used for subclasses of gobject
92 (eval-when (:compile-toplevel :load-toplevel :execute)
93 (defclass gobject-class (ginstance-class))
95 (defclass direct-gobject-slot-definition (direct-virtual-slot-definition))
97 (defclass effective-gobject-slot-definition
98 (effective-virtual-slot-definition)))
101 ; (defbinding object-class-install-param () nil
104 ; (parameter parameter))
106 ; (defbinding object-class-find-param-spec () parameter
111 (defmethod initialize-instance :after ((slotd direct-gobject-slot-definition)
113 (declare (ignore initargs))
114 (unless (slot-boundp slotd 'location)
115 ;; Find parameter name from slot name
116 (with-slots (pcl::name location) slotd
117 (setf location (signal-name-to-string pcl::name)))))
119 (defmethod direct-slot-definition-class ((class gobject-class) initargs)
120 (case (getf initargs :allocation)
121 (:param (find-class 'direct-gobject-slot-definition))
122 (t (call-next-method))))
124 (defmethod effective-slot-definition-class ((class gobject-class) initargs)
125 (case (getf initargs :allocation)
126 (:param (find-class 'effective-gobject-slot-definition))
127 (t (call-next-method))))
129 (defmethod compute-virtual-slot-location
130 ((class gobject-class) (slotd effective-gobject-slot-definition)
132 (with-slots (type) slotd
133 (let ((param-name (slot-definition-location (first direct-slotds)))
134 (type-number (find-type-number type))
135 (reader (intern-reader-function type))
136 (writer (intern-writer-function type))
137 (destroy (intern-destroy-function type)))
141 (let ((gvalue (gvalue-new type-number)))
142 (%object-get-property object param-name gvalue)
144 (funcall reader gvalue +gvalue-value-offset+)
145 (gvalue-free gvalue t)))))
146 #'(lambda (value object)
148 (let ((gvalue (gvalue-new type-number)))
149 (funcall writer value gvalue +gvalue-value-offset+)
150 (%object-set-property object param-name gvalue)
151 (funcall destroy gvalue +gvalue-value-offset+)
152 (gvalue-free gvalue nil)
156 (defmethod validate-superclass ((class gobject-class)
157 (super pcl::standard-class))
158 (subtypep (class-name super) 'gobject))