chiark / gitweb /
Signaling error in clg-init if running SBCL in Slime with communication style :spawn
[clg] / gtk / gtkobject.lisp
CommitLineData
112ac1d3 1;; Common Lisp bindings for GTK+ v2.x
2;; Copyright 1999-2005 Espen S. Johnsen <espen@users.sf.net>
560af5c5 3;;
112ac1d3 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:
560af5c5 11;;
112ac1d3 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
560af5c5 14;;
112ac1d3 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.
560af5c5 22
b19bbc94 23;; $Id: gtkobject.lisp,v 1.31 2006-02-15 09:47:42 espen Exp $
560af5c5 24
25
26(in-package "GTK")
27
8bf63d9f 28
560af5c5 29;;;; Misc utils
30
f86d391e 31; (defun name-to-string (name)
32; (substitute #\_ #\- (string-downcase (string name))))
560af5c5 33
f86d391e 34; (defun string-to-name (name &optional (package "KEYWORD"))
35; (intern (substitute #\- #\_ (string-upcase name)) package))
560af5c5 36
37
560af5c5 38
39;;;; Superclass for the gtk class hierarchy
40
41(eval-when (:compile-toplevel :load-toplevel :execute)
9adccb27 42 (init-types-in-library
43 #.(concatenate 'string (pkg-config:pkg-variable "gtk+-2.0" "libdir")
c046c2f6 44 "/libgtk-x11-2.0.so"))
f86d391e 45
46 (defclass %object (gobject)
560af5c5 47 ()
560af5c5 48 (:metaclass gobject-class)
dfa4f314 49 (:gtype |gtk_object_get_type|)))
560af5c5 50
51
9adccb27 52(defmethod initialize-instance ((object %object) &rest initargs &key signal)
53 (declare (ignore signal))
560af5c5 54 (call-next-method)
18eed2a0 55 (dolist (signal-definition (get-all initargs :signal))
56 (apply #'signal-connect object signal-definition)))
560af5c5 57
9adccb27 58(defmethod initialize-instance :around ((object %object) &rest initargs)
560af5c5 59 (declare (ignore initargs))
60 (call-next-method)
88d2b3c2 61 ;; Add a temorary reference which will be removed when the object is
62 ;; sinked
1eae767d 63 (reference-foreign (class-of object) (foreign-location object))
18eed2a0 64 (%object-sink object))
560af5c5 65
f86d391e 66(defbinding %object-sink () nil
67 (object %object))
560af5c5 68
73572c12 69;;;; Main loop and event handling
560af5c5 70
71(declaim (inline events-pending-p main-iteration))
72
73572c12 73(defbinding events-pending-p () boolean)
560af5c5 74
f86d391e 75(defbinding get-current-event () gdk:event)
aace61f5 76
f86d391e 77(defbinding main-do-event () nil
560af5c5 78 (event gdk:event))
79
f86d391e 80(defbinding main () nil)
560af5c5 81
f86d391e 82(defbinding main-level () int)
560af5c5 83
f86d391e 84(defbinding main-quit () nil)
560af5c5 85
f86d391e 86(defbinding main-iteration-do (&optional (blocking t)) boolean
560af5c5 87 (blocking boolean))
88
89(defun main-iterate-all (&rest args)
90 (declare (ignore args))
73572c12 91 (loop
92 while (events-pending-p)
93 do (main-iteration-do nil)))
560af5c5 94
560af5c5 95
560af5c5 96;;;; Metaclass for child classes
f86d391e 97
98(defvar *container-to-child-class-mappings* (make-hash-table))
560af5c5 99
100(eval-when (:compile-toplevel :load-toplevel :execute)
9adccb27 101 (defclass child-class (virtual-slots-class)
1047e159 102 ())
560af5c5 103
f86d391e 104 (defclass direct-child-slot-definition (direct-virtual-slot-definition)
1047e159 105 ((pname :reader slot-definition-pname :initarg :pname)))
560af5c5 106
1047e159 107 (defclass effective-child-slot-definition (effective-virtual-slot-definition)
108 ((pname :reader slot-definition-pname :initarg :pname)))
560af5c5 109
110
1047e159 111(defmethod shared-initialize ((class child-class) names &key container)
560af5c5 112 (call-next-method)
f86d391e 113 (setf
114 (gethash (find-class (first container)) *container-to-child-class-mappings*)
115 class))
560af5c5 116
1047e159 117(defmethod direct-slot-definition-class ((class child-class) &rest initargs)
560af5c5 118 (case (getf initargs :allocation)
18eed2a0 119 (:property (find-class 'direct-child-slot-definition))
560af5c5 120 (t (call-next-method))))
121
1047e159 122(defmethod effective-slot-definition-class ((class child-class) &rest initargs)
560af5c5 123 (case (getf initargs :allocation)
18eed2a0 124 (:property (find-class 'effective-child-slot-definition))
560af5c5 125 (t (call-next-method))))
560af5c5 126
1047e159 127(defmethod compute-effective-slot-definition-initargs ((class child-class) direct-slotds)
b19bbc94 128 (if (eq (slot-definition-allocation (first direct-slotds)) :property)
1047e159 129 (nconc
130 (list :pname (most-specific-slot-value direct-slotds 'pname))
b19bbc94 131 ;; Need this to prevent type expansion in SBCL (>= 0.9.8)
1eaa1bd6 132 (list :type (most-specific-slot-value direct-slotds 'type))
1047e159 133 (call-next-method))
134 (call-next-method)))
135
b030f2d9 136(progn
73572c12 137 #+cmu(declaim (optimize (inhibit-warnings 3)))
138 #+sbcl(declaim (muffle-conditions compiler-note))
b030f2d9 139 (defun %container-child-get-property (parent child pname gvalue))
140 (defun %container-child-set-property (parent child pname gvalue)))
141
142
1047e159 143(defmethod initialize-internal-slot-functions ((slotd effective-child-slot-definition))
dfa4f314 144 (let ((type (slot-definition-type slotd))
145 (pname (slot-definition-pname slotd)))
d24bc5ad 146 (setf
147 (slot-value slotd 'getter)
148 #'(lambda (object)
149 (with-slots (parent child) object
dfa4f314 150 (let ((gvalue (gvalue-new type)))
d24bc5ad 151 (%container-child-get-property parent child pname gvalue)
152 (unwind-protect
153 (funcall (reader-function type) gvalue +gvalue-value-offset+)
154 (gvalue-free gvalue t))))))
1047e159 155
d24bc5ad 156 (setf
157 (slot-value slotd 'setter)
158 #'(lambda (value object)
159 (with-slots (parent child) object
dfa4f314 160 (let ((gvalue (gvalue-new type)))
d24bc5ad 161 (funcall (writer-function type) value gvalue +gvalue-value-offset+)
162 (%container-child-set-property parent child pname gvalue)
163 (gvalue-free gvalue t)
164 value)))))
165
1047e159 166 (call-next-method)))
560af5c5 167
168
73572c12 169(defmethod add-reader-method ((class child-class) generic-function slot-name)
560af5c5 170 (add-method
171 generic-function
172 (make-instance 'standard-method
c289d084 173 :specializers (list (find-class 'widget))
174 :lambda-list '(widget)
175 :function #'(lambda (args next-methods)
176 (declare (ignore next-methods))
177 (child-property-value (first args) slot-name)))))
560af5c5 178
73572c12 179(defmethod add-writer-method
560af5c5 180 ((class child-class) generic-function slot-name)
181 (add-method
182 generic-function
183 (make-instance 'standard-method
c289d084 184 :specializers (list (find-class t) (find-class 'widget))
185 :lambda-list '(value widget)
186 :function #'(lambda (args next-methods)
187 (declare (ignore next-methods))
188 (destructuring-bind (value widget) args
189 (setf (child-property-value widget slot-name) value))))))
560af5c5 190
191
73572c12 192(defmethod validate-superclass ((class child-class) (super standard-class))
18eed2a0 193 ;(subtypep (class-name super) 'container-child)
194 t)
560af5c5 195
196
f86d391e 197(defclass container-child ()
198 ((parent :initarg :parent :type container)
199 (child :initarg :child :type widget)))
200
201
202;;;;
203
18eed2a0 204(defbinding %container-class-list-child-properties () pointer
205 (class pointer)
206 (n-properties unsigned-int :out))
f86d391e 207
18eed2a0 208(defun query-container-class-child-properties (type-number)
209 (let ((class (type-class-ref type-number)))
210 (multiple-value-bind (array length)
211 (%container-class-list-child-properties class)
212 (unwind-protect
9adccb27 213 (map-c-vector 'list #'identity array 'param length)
18eed2a0 214 (deallocate-memory array)))))
f86d391e 215
216(defun default-container-child-name (container-class)
217 (intern (format nil "~A-CHILD" container-class)))
218
62f12808 219(defun expand-container-type (type forward-p options)
1047e159 220 (let* ((class (type-from-number type))
221 (super (supertype type))
222 (child-class (default-container-child-name class)))
62f12808 223 (if forward-p
224 (expand-gobject-type type t options)
225 `(progn
226 ,(expand-gobject-type type nil options)
227 (defclass ,child-class (,(default-container-child-name super))
228 ,(slot-definitions child-class
229 (query-container-class-child-properties type) nil)
230 (:metaclass child-class)
231 (:container ,class))))))
232
233
234(register-derivable-type 'container "GtkContainer" 'expand-container-type 'gobject-dependencies)