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