chiark / gitweb /
Removed libdir path in calls to INIT-TYPES-IN-LIBRARY
[clg] / gtk / gtkobject.lisp
CommitLineData
560af5c5 1;; Common Lisp bindings for GTK+ v2.0
56460319 2;; Copyright (C) 1999-2001 Espen S. Johnsen <espen@users.sourceforge.org>
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
56460319 18;; $Id: gtkobject.lisp,v 1.12 2001-11-12 22:33:08 espen Exp $
560af5c5 19
20
21(in-package "GTK")
22
8bf63d9f 23
560af5c5 24;;;; Misc utils
25
f86d391e 26; (defun name-to-string (name)
27; (substitute #\_ #\- (string-downcase (string name))))
560af5c5 28
f86d391e 29; (defun string-to-name (name &optional (package "KEYWORD"))
30; (intern (substitute #\- #\_ (string-upcase name)) package))
560af5c5 31
32
560af5c5 33
34;;;; Superclass for the gtk class hierarchy
35
36(eval-when (:compile-toplevel :load-toplevel :execute)
56460319 37 (init-types-in-library "libgtk-x11-1.3.so"
18eed2a0 38 :ignore ("gtk_window_get_type_hint"))
f86d391e 39
40 (defclass %object (gobject)
560af5c5 41 ()
560af5c5 42 (:metaclass gobject-class)
43 (:alien-name "GtkObject")))
44
45
f86d391e 46(defmethod shared-initialize ((object %object) names &rest initargs
18eed2a0 47 &allow-other-keys)
48 (declare (ignore names))
560af5c5 49 (call-next-method)
18eed2a0 50 (funcall (proxy-class-copy (class-of object)) nil (proxy-location object)) ; inc ref count before sinking
f86d391e 51 (%object-sink object)
18eed2a0 52 (dolist (signal-definition (get-all initargs :signal))
53 (apply #'signal-connect object signal-definition)))
560af5c5 54
18eed2a0 55(defmethod initialize-proxy ((object %object) &rest initargs)
560af5c5 56 (declare (ignore initargs))
57 (call-next-method)
18eed2a0 58 (%object-sink object))
560af5c5 59
f86d391e 60(defbinding %object-sink () nil
61 (object %object))
560af5c5 62
560af5c5 63
aace61f5 64;;;; Main loop, timeouts and idle functions
560af5c5 65
66(declaim (inline events-pending-p main-iteration))
67
f86d391e 68(defbinding (events-pending-p "gtk_events_pending") () boolean)
560af5c5 69
f86d391e 70(defbinding get-current-event () gdk:event)
aace61f5 71
f86d391e 72(defbinding main-do-event () nil
560af5c5 73 (event gdk:event))
74
f86d391e 75(defbinding main () nil)
560af5c5 76
f86d391e 77(defbinding main-level () int)
560af5c5 78
f86d391e 79(defbinding main-quit () nil)
560af5c5 80
f86d391e 81(defbinding main-iteration-do (&optional (blocking t)) boolean
560af5c5 82 (blocking boolean))
83
84(defun main-iterate-all (&rest args)
85 (declare (ignore args))
86 (when (events-pending-p)
f86d391e 87 (main-iteration-do nil)
560af5c5 88 (main-iterate-all)))
89
18eed2a0 90(system:add-fd-handler (gdk:connection-number) :input #'main-iterate-all)
560af5c5 91(setq lisp::*periodic-polling-function* #'main-iterate-all)
92(setq lisp::*max-event-to-sec* 0)
93(setq lisp::*max-event-to-usec* 1000)
94
95
96
560af5c5 97;;;; Metaclass for child classes
f86d391e 98
99(defvar *container-to-child-class-mappings* (make-hash-table))
560af5c5 100
101(eval-when (:compile-toplevel :load-toplevel :execute)
f86d391e 102 (defclass child-class (virtual-slot-class))
560af5c5 103
f86d391e 104 (defclass direct-child-slot-definition (direct-virtual-slot-definition)
18eed2a0 105 ((pname :reader slot-definition-pname)))
560af5c5 106
107 (defclass effective-child-slot-definition
108 (effective-virtual-slot-definition)))
109
110
f86d391e 111(defmethod shared-initialize ((class child-class) names &rest initargs
112 &key container)
560af5c5 113 (declare (ignore initargs))
114 (call-next-method)
f86d391e 115 (setf
116 (gethash (find-class (first container)) *container-to-child-class-mappings*)
117 class))
560af5c5 118
f86d391e 119(defmethod initialize-instance ((slotd direct-child-slot-definition)
18eed2a0 120 &rest initargs &key pname)
f86d391e 121 (declare (ignore initargs))
122 (call-next-method)
18eed2a0 123 (if pname
124 (setf (slot-value slotd 'pname) pname)
125 ; ???
126 (error "Need pname for slot with allocation :property")))
560af5c5 127
128(defmethod direct-slot-definition-class ((class child-class) initargs)
129 (case (getf initargs :allocation)
18eed2a0 130 (:property (find-class 'direct-child-slot-definition))
560af5c5 131 (t (call-next-method))))
132
560af5c5 133(defmethod effective-slot-definition-class ((class child-class) initargs)
134 (case (getf initargs :allocation)
18eed2a0 135 (:property (find-class 'effective-child-slot-definition))
560af5c5 136 (t (call-next-method))))
560af5c5 137
18eed2a0 138(defmethod compute-virtual-slot-accessors
560af5c5 139 ((class child-class) (slotd effective-child-slot-definition) direct-slotds)
140 (with-slots (type) slotd
18eed2a0 141 (let ((pname (slot-definition-pname (first direct-slotds)))
142 (type-number (find-type-number type)))
560af5c5 143 (list
144 #'(lambda (object)
145 (with-slots (parent child) object
146 (with-gc-disabled
18eed2a0 147 (let ((gvalue (gvalue-new type-number)))
148 (%container-child-get-property parent child pname gvalue)
149 (unwind-protect
f86d391e 150 (funcall
151 (intern-reader-function type)
18eed2a0 152 gvalue +gvalue-value-offset+)
153 (gvalue-free gvalue t))))))
560af5c5 154 #'(lambda (value object)
155 (with-slots (parent child) object
156 (with-gc-disabled
18eed2a0 157 (let ((gvalue (gvalue-new type-number)))
158 (funcall
159 (intern-writer-function type)
160 value gvalue +gvalue-value-offset+)
161 (%container-child-set-property parent child pname gvalue)
162 (funcall
163 (intern-destroy-function type)
164 gvalue +gvalue-value-offset+)
165 (gvalue-free gvalue nil)
166 value))))))))
560af5c5 167
168
169(defmethod pcl::add-reader-method ((class child-class) generic-function slot-name)
170 (add-method
171 generic-function
172 (make-instance 'standard-method
173 :specializers (list (find-class 'widget))
174 :lambda-list '(widget)
175 :function #'(lambda (args next-methods)
176 (declare (ignore next-methods))
177 (child-slot-value (first args) slot-name)))))
178
179(defmethod pcl::add-writer-method
180 ((class child-class) generic-function slot-name)
181 (add-method
182 generic-function
183 (make-instance 'standard-method
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
190 (child-slot-value widget slot-name)
191 value))))))
192
193
194(defmethod validate-superclass ((class child-class) (super pcl::standard-class))
18eed2a0 195 ;(subtypep (class-name super) 'container-child)
196 t)
560af5c5 197
198
f86d391e 199(defclass container-child ()
200 ((parent :initarg :parent :type container)
201 (child :initarg :child :type widget)))
202
203
204;;;;
205
18eed2a0 206(defbinding %container-class-list-child-properties () pointer
207 (class pointer)
208 (n-properties unsigned-int :out))
f86d391e 209
18eed2a0 210(defun query-container-class-child-properties (type-number)
211 (let ((class (type-class-ref type-number)))
212 (multiple-value-bind (array length)
213 (%container-class-list-child-properties class)
214 (unwind-protect
215 (map-c-array 'list #'identity array 'param length)
216 (deallocate-memory array)))))
f86d391e 217
218(defun default-container-child-name (container-class)
219 (intern (format nil "~A-CHILD" container-class)))
220
221(defun expand-container-type (type-number &optional slots)
222 (let* ((class (type-from-number type-number))
223 (super (supertype type-number))
224 (child-class (default-container-child-name class))
18eed2a0 225 (expanded-child-slots
226 (mapcar
227 #'(lambda (param)
228 (with-slots (name flags value-type documentation) param
229 (let* ((slot-name (default-slot-name name))
230 (slot-type (type-from-number value-type #|t|#))
231 (accessor
232 (default-slot-accessor class slot-name slot-type)))
233 `(,slot-name
234 :allocation :property
235 :pname ,name
236 ,@(cond
237 ((and
238 (member :writable flags)
239 (member :readable flags))
240 (list :accessor accessor))
241 ((member :writable flags)
242 (list :writer `(setf ,accessor)))
243 ((member :readable flags)
244 (list :reader accessor)))
245 ,@(when (or
246 (member :construct flags)
247 (member :writable flags))
248 (list :initarg (intern (string slot-name) "KEYWORD")))
249 :type ,slot-type
250 ,@(when documentation
251 (list :documentation documentation))))))
252 (query-container-class-child-properties type-number))))
253 `(progn
254 ,(expand-gobject-type type-number slots)
255 (defclass ,child-class
256 (,(default-container-child-name super))
257 ,expanded-child-slots
258 (:metaclass child-class)
259 (:container ,class)))))
260
261(register-derivable-type 'container "GtkContainer" 'expand-container-type)