chiark / gitweb /
Changed PROXY-CLASS to work with forward referneced superclasses.
[clg] / glib / gobject.lisp
CommitLineData
560af5c5 1;; Common Lisp bindings for GTK+ v2.0
82747bbd 2;; Copyright (C) 2000-2001 Espen S. Johnsen <esj@stud.cs.uit.no>
560af5c5 3;;
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.
8;;
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.
13;;
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
17
26b133ed 18;; $Id: gobject.lisp,v 1.6 2001-04-29 20:34:18 espen Exp $
560af5c5 19
20(in-package "GLIB")
21
22
23(eval-when (:compile-toplevel :load-toplevel :execute)
c8c48a4c 24 (defclass gobject (ginstance)
560af5c5 25 ()
c8c48a4c 26 (:metaclass ginstance-class)
82747bbd 27 (:alien-name "GObject")
28 (:ref "g_object_ref")
29 (:unref "g_object_unref")))
560af5c5 30
82747bbd 31(defmethod initialize-instance ((object gobject) &rest initargs)
32 (declare (ignore initargs))
33 (setf
34 (slot-value object 'location)
35 (%gobject-new (type-number-of object)))
36 (call-next-method))
a9044181 37
26b133ed 38(defbinding ("g_object_new" %gobject-new) () gobject
a9044181 39 (type type-number)
40 (nil null))
560af5c5 41
42
c8c48a4c 43;;;; Parameter stuff
560af5c5 44
26b133ed 45(defbinding %object-set-property () nil
c8c48a4c 46 (object gobject)
47 (name string)
48 (value gvalue))
86d9d6ab 49
26b133ed 50(defbinding %object-get-property () nil
c8c48a4c 51 (object gobject)
52 (name string)
a9044181 53 (value gvalue))
86d9d6ab 54
26b133ed 55(defbinding %object-notify () nil
c8c48a4c 56 (object gobject)
57 (name string))
86d9d6ab 58
26b133ed 59(defbinding object-freeze-notify () nil
a9044181 60 (object gobject))
86d9d6ab 61
26b133ed 62(defbinding object-thaw-notify () nil
a9044181 63 (object gobject))
86d9d6ab 64
26b133ed 65(defbinding %object-set-qdata-full () nil
86d9d6ab 66 (object gobject)
67 (id quark)
68 (data unsigned-long)
69 (destroy-marshal pointer))
70
a9044181 71
72;;;; User data
73
86d9d6ab 74(defun (setf object-data) (data object key &key (test #'eq))
75 (%object-set-qdata-full
76 object (quark-from-object key :test test)
c8c48a4c 77 (register-user-data data) *destroy-notify*)
86d9d6ab 78 data)
79
26b133ed 80(defbinding %object-get-qdata () unsigned-long
86d9d6ab 81 (object gobject)
82 (id quark))
83
84(defun object-data (object key &key (test #'eq))
85 (find-user-data
86 (%object-get-qdata object (quark-from-object key :test test))))
87
88
560af5c5 89
a9044181 90;;;; Metaclass used for subclasses of gobject
91
92(eval-when (:compile-toplevel :load-toplevel :execute)
93 (defclass gobject-class (ginstance-class))
c8c48a4c 94
a9044181 95 (defclass direct-gobject-slot-definition (direct-virtual-slot-definition))
c8c48a4c 96
a9044181 97 (defclass effective-gobject-slot-definition
98 (effective-virtual-slot-definition)))
c8c48a4c 99
560af5c5 100
26b133ed 101; (defbinding object-class-install-param () nil
560af5c5 102; (class pointer)
103; (id unsigned-int)
104; (parameter parameter))
105
26b133ed 106; (defbinding object-class-find-param-spec () parameter
560af5c5 107; (class pointer)
108; (name string))
109
a9044181 110
111(defmethod initialize-instance :after ((slotd direct-gobject-slot-definition)
112 &rest initargs &key)
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)))))
118
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))))
123
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))))
128
129(defmethod compute-virtual-slot-location
130 ((class gobject-class) (slotd effective-gobject-slot-definition)
131 direct-slotds)
132 (with-slots (type) slotd
133 (let ((param-name (slot-definition-location (first direct-slotds)))
134 (type-number (find-type-number type))
82747bbd 135 (reader (intern-reader-function type))
136 (writer (intern-writer-function type))
137 (destroy (intern-destroy-function type)))
a9044181 138 (list
139 #'(lambda (object)
140 (with-gc-disabled
141 (let ((gvalue (gvalue-new type-number)))
142 (%object-get-property object param-name gvalue)
143 (prog1
144 (funcall reader gvalue +gvalue-value-offset+)
145 (gvalue-free gvalue t)))))
146 #'(lambda (value object)
147 (with-gc-disabled
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)
153 value)))))))
154
155
156(defmethod validate-superclass ((class gobject-class)
157 (super pcl::standard-class))
158 (subtypep (class-name super) 'gobject))
82747bbd 159