chiark / gitweb /
Updates for SBCL 0.9.14 and 0.9.15
[clg] / gtk / gtkobject.lisp
CommitLineData
55212af1 1;; Common Lisp bindings for GTK+ v2.x
2;; Copyright 1999-2005 Espen S. Johnsen <espen@users.sf.net>
0d07716f 3;;
55212af1 4;; Permission is hereby granted, free of charge, to any person obtaining
5;; a copy of this software and associated documentation files (the
6;; "Software"), to deal in the Software without restriction, including
7;; without limitation the rights to use, copy, modify, merge, publish,
8;; distribute, sublicense, and/or sell copies of the Software, and to
9;; permit persons to whom the Software is furnished to do so, subject to
10;; the following conditions:
0d07716f 11;;
55212af1 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
0d07716f 14;;
55212af1 15;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0d07716f 22
6b716036 23;; $Id: gtkobject.lisp,v 1.36 2006/08/16 11:02:46 espen Exp $
0d07716f 24
25
26(in-package "GTK")
27
aa1ae3a5 28
0d07716f 29;;;; Superclass for the gtk class hierarchy
30
31(eval-when (:compile-toplevel :load-toplevel :execute)
6baf860c 32 (init-types-in-library
33 #.(concatenate 'string (pkg-config:pkg-variable "gtk+-2.0" "libdir")
33766b28 34 "/libgtk-x11-2.0.so"))
6d27e76c 35
36 (defclass %object (gobject)
0d07716f 37 ()
0d07716f 38 (:metaclass gobject-class)
dcb31db6 39 (:gtype |gtk_object_get_type|)))
0d07716f 40
41
6baf860c 42(defmethod initialize-instance ((object %object) &rest initargs &key signal)
43 (declare (ignore signal))
0d07716f 44 (call-next-method)
fb449127 45 (dolist (signal-definition (get-all initargs :signal))
46 (apply #'signal-connect object signal-definition)))
0d07716f 47
6baf860c 48(defmethod initialize-instance :around ((object %object) &rest initargs)
0d07716f 49 (declare (ignore initargs))
50 (call-next-method)
bba7e2d9 51 ;; Add a temorary reference which will be removed when the object is
52 ;; sinked
616e1430 53 (funcall (reference-function '%object) (foreign-location object))
fb449127 54 (%object-sink object))
0d07716f 55
6d27e76c 56(defbinding %object-sink () nil
57 (object %object))
0d07716f 58
3d36c5d6 59;;;; Main loop and event handling
0d07716f 60
3d36c5d6 61(defbinding events-pending-p () boolean)
0d07716f 62
6d27e76c 63(defbinding get-current-event () gdk:event)
13148f19 64
6d27e76c 65(defbinding main-do-event () nil
0d07716f 66 (event gdk:event))
67
6d27e76c 68(defbinding main () nil)
0d07716f 69
6d27e76c 70(defbinding main-level () int)
0d07716f 71
6d27e76c 72(defbinding main-quit () nil)
0d07716f 73
6d27e76c 74(defbinding main-iteration-do (&optional (blocking t)) boolean
0d07716f 75 (blocking boolean))
76
77(defun main-iterate-all (&rest args)
78 (declare (ignore args))
3d36c5d6 79 (loop
80 while (events-pending-p)
616e1430 81 do (main-iteration-do nil))
82 #+clisp 0)
0d07716f 83
0d07716f 84
0d07716f 85;;;; Metaclass for child classes
6d27e76c 86
87(defvar *container-to-child-class-mappings* (make-hash-table))
0d07716f 88
89(eval-when (:compile-toplevel :load-toplevel :execute)
616e1430 90 (defclass container-child-class (virtual-slots-class)
eb4f580c 91 ())
0d07716f 92
6d27e76c 93 (defclass direct-child-slot-definition (direct-virtual-slot-definition)
eb4f580c 94 ((pname :reader slot-definition-pname :initarg :pname)))
0d07716f 95
eb4f580c 96 (defclass effective-child-slot-definition (effective-virtual-slot-definition)
616e1430 97 ((pname :reader slot-definition-pname :initarg :pname))))
0d07716f 98
99
616e1430 100(defmethod shared-initialize ((class container-child-class) names &key container)
101 (declare (ignore names))
0d07716f 102 (call-next-method)
6d27e76c 103 (setf
104 (gethash (find-class (first container)) *container-to-child-class-mappings*)
616e1430 105 class)
106 #+clisp
107 (loop
108 for slotd in (class-direct-slots class)
109 when (typep slotd 'direct-child-slot-definition)
110 do (loop
111 for reader in (slot-definition-readers slotd)
112 do (add-reader-method class
113 (ensure-generic-function reader :lambda-list '(object))
114 (slot-definition-name slotd)))
115 (loop
116 for writer in (slot-definition-writers slotd)
117 do (add-writer-method class
118 (ensure-generic-function writer :lambda-list '(value object))
119 (slot-definition-name slotd)))))
120
121(defmethod direct-slot-definition-class ((class container-child-class) &rest initargs)
0d07716f 122 (case (getf initargs :allocation)
fb449127 123 (:property (find-class 'direct-child-slot-definition))
0d07716f 124 (t (call-next-method))))
125
616e1430 126(defmethod effective-slot-definition-class ((class container-child-class) &rest initargs)
0d07716f 127 (case (getf initargs :allocation)
fb449127 128 (:property (find-class 'effective-child-slot-definition))
0d07716f 129 (t (call-next-method))))
0d07716f 130
616e1430 131(defmethod compute-effective-slot-definition-initargs ((class container-child-class) direct-slotds)
c23cc486 132 (if (eq (slot-definition-allocation (first direct-slotds)) :property)
eb4f580c 133 (nconc
134 (list :pname (most-specific-slot-value direct-slotds 'pname))
135 (call-next-method))
136 (call-next-method)))
137
6b716036 138(defmethod compute-slot-reader-function ((slotd effective-child-slot-definition) &optional signal-unbound-p)
139 (declare (ignore signal-unbound-p))
616e1430 140 (let* ((type (slot-definition-type slotd))
141 (pname (slot-definition-pname slotd))
142 (reader (reader-function type :ref :get)))
143 #'(lambda (object)
144 (with-slots (parent child) object
145 (with-memory (gvalue +gvalue-size+)
146 (glib::%gvalue-init gvalue (find-type-number type))
147 (%container-child-get-property parent child pname gvalue)
148 (funcall reader gvalue +gvalue-value-offset+))))))
149
150(defmethod compute-slot-writer-function ((slotd effective-child-slot-definition))
151 (let* ((type (slot-definition-type slotd))
152 (pname (slot-definition-pname slotd))
153 (writer (writer-function type :temp t))
154 (destroy (destroy-function type :temp t)))
155 #'(lambda (value object)
156 (with-slots (parent child) object
157 (with-memory (gvalue +gvalue-size+)
158 (glib::%gvalue-init gvalue (find-type-number type))
159 (funcall writer value gvalue +gvalue-value-offset+)
160 (%container-child-set-property parent child pname gvalue)
161 (funcall destroy gvalue +gvalue-value-offset+))
162 value))))
163
164
165(defmethod add-reader-method ((class container-child-class) generic-function slot-name)
0d07716f 166 (add-method
167 generic-function
168 (make-instance 'standard-method
c66e7b94 169 :specializers (list (find-class 'widget))
170 :lambda-list '(widget)
171 :function #'(lambda (args next-methods)
172 (declare (ignore next-methods))
173 (child-property-value (first args) slot-name)))))
0d07716f 174
616e1430 175(defmethod add-writer-method ((class container-child-class) generic-function slot-name)
0d07716f 176 (add-method
177 generic-function
178 (make-instance 'standard-method
c66e7b94 179 :specializers (list (find-class t) (find-class 'widget))
180 :lambda-list '(value widget)
181 :function #'(lambda (args next-methods)
182 (declare (ignore next-methods))
183 (destructuring-bind (value widget) args
184 (setf (child-property-value widget slot-name) value))))))
0d07716f 185
186
616e1430 187(defmethod validate-superclass ((class container-child-class) (super standard-class))
fb449127 188 ;(subtypep (class-name super) 'container-child)
189 t)
0d07716f 190
191
27927751 192(defclass container-child (virtual-slots-object)
6d27e76c 193 ((parent :initarg :parent :type container)
194 (child :initarg :child :type widget)))
195
196
197;;;;
198
fb449127 199(defbinding %container-class-list-child-properties () pointer
200 (class pointer)
201 (n-properties unsigned-int :out))
6d27e76c 202
fb449127 203(defun query-container-class-child-properties (type-number)
204 (let ((class (type-class-ref type-number)))
205 (multiple-value-bind (array length)
206 (%container-class-list-child-properties class)
207 (unwind-protect
6baf860c 208 (map-c-vector 'list #'identity array 'param length)
fb449127 209 (deallocate-memory array)))))
6d27e76c 210
211(defun default-container-child-name (container-class)
212 (intern (format nil "~A-CHILD" container-class)))
213
e9934f39 214(defun expand-container-type (type forward-p options)
eb4f580c 215 (let* ((class (type-from-number type))
216 (super (supertype type))
217 (child-class (default-container-child-name class)))
e9934f39 218 (if forward-p
219 (expand-gobject-type type t options)
220 `(progn
221 ,(expand-gobject-type type nil options)
222 (defclass ,child-class (,(default-container-child-name super))
223 ,(slot-definitions child-class
224 (query-container-class-child-properties type) nil)
616e1430 225 (:metaclass container-child-class)
e9934f39 226 (:container ,class))))))
227
228
229(register-derivable-type 'container "GtkContainer" 'expand-container-type 'gobject-dependencies)