560af5c5 |
1 | ;; Common Lisp bindings for GTK+ v2.0 |
1de3a418 |
2 | ;; Copyright (C) 2000-2002 Espen S. Johnsen <espen@users.sourceforge.net> |
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 | |
03802c3c |
18 | ;; $Id: gtkwidget.lisp,v 1.14 2005-01-06 21:00:51 espen Exp $ |
560af5c5 |
19 | |
20 | (in-package "GTK") |
21 | |
22 | |
0f2634d2 |
23 | (defmethod shared-initialize ((widget widget) names &rest initargs &key parent) |
1047e159 |
24 | (remf initargs :parent) |
1de3a418 |
25 | (prog1 |
1047e159 |
26 | (apply #'call-next-method widget names initargs) |
1de3a418 |
27 | (when parent |
853ec10e |
28 | (when (slot-boundp widget 'parent) |
29 | (container-remove (widget-parent widget) widget)) |
30 | (let ((parent-widget (first (mklist parent))) |
1de3a418 |
31 | (args (rest (mklist parent)))) |
853ec10e |
32 | (apply #'container-add parent-widget widget args))))) |
e5b416f0 |
33 | |
0f2634d2 |
34 | (defmethod shared-initialize :after ((widget widget) names &rest initargs |
853ec10e |
35 | &key show-all all-visible) |
0f2634d2 |
36 | (declare (ignore initargs names)) |
853ec10e |
37 | (when (or all-visible show-all) |
e5b416f0 |
38 | (widget-show-all widget))) |
560af5c5 |
39 | |
40 | |
e5b416f0 |
41 | (defmethod slot-unbound ((class gobject-class) (object widget) slot) |
560af5c5 |
42 | (cond |
c289d084 |
43 | ((and (eq slot 'child-properties) (slot-value object 'parent)) |
44 | (with-slots (parent child-properties) object |
560af5c5 |
45 | (setf |
c289d084 |
46 | child-properties |
560af5c5 |
47 | (make-instance |
0d270bd9 |
48 | (gethash (class-of parent) *container-to-child-class-mappings*) |
560af5c5 |
49 | :parent parent :child object)))) |
50 | (t (call-next-method)))) |
51 | |
03802c3c |
52 | (defmethod create-callback-function ((widget widget) function arg1) |
53 | (if (eq arg1 :parent) |
54 | #'(lambda (&rest args) |
55 | (if (slot-boundp widget 'parent) |
56 | (apply function (widget-parent widget) (rest args)) |
57 | (signal-connect widget 'parent-set |
58 | #'(lambda (old-parent) |
59 | (declare (ignore old-parent)) |
60 | (let ((*signal-stop-emission* |
61 | #'(lambda () |
62 | (warn "Ignoring emission stop in delayed signal handler")))) |
63 | (apply function (widget-parent widget) (rest args)))) |
64 | :remove t) |
65 | ; (warn "Widget has no parent -- ignoring signal") |
66 | )) |
67 | (call-next-method))) |
68 | |
c289d084 |
69 | (defun child-property-value (widget slot) |
70 | (slot-value (widget-child-properties widget) slot)) |
560af5c5 |
71 | |
c289d084 |
72 | (defun (setf child-property-value) (value widget slot) |
73 | (setf (slot-value (widget-child-properties widget) slot) value)) |
560af5c5 |
74 | |
c289d084 |
75 | (defmacro with-child-properties (slots widget &body body) |
76 | `(with-slots ,slots (widget-child-properties ,widget) |
560af5c5 |
77 | ,@body)) |
78 | |
1de3a418 |
79 | |
560af5c5 |
80 | (defmacro widget-destroyed (place) |
81 | `(setf ,place nil)) |
82 | |
1de3a418 |
83 | |
84 | ;;; Bindings |
85 | |
0d270bd9 |
86 | (defbinding widget-destroy () nil |
560af5c5 |
87 | (widget widget)) |
88 | |
0d270bd9 |
89 | (defbinding widget-unparent () nil |
560af5c5 |
90 | (widget widget)) |
91 | |
0d270bd9 |
92 | (defbinding widget-show () nil |
560af5c5 |
93 | (widget widget)) |
94 | |
0d270bd9 |
95 | (defbinding widget-show-now () nil |
560af5c5 |
96 | (widget widget)) |
97 | |
0d270bd9 |
98 | (defbinding widget-hide () nil |
560af5c5 |
99 | (widget widget)) |
100 | |
0d270bd9 |
101 | (defbinding widget-show-all () nil |
560af5c5 |
102 | (widget widget)) |
103 | |
0d270bd9 |
104 | (defbinding widget-hide-all () nil |
560af5c5 |
105 | (widget widget)) |
106 | |
0d270bd9 |
107 | (defbinding widget-map () nil |
560af5c5 |
108 | (widget widget)) |
109 | |
0d270bd9 |
110 | (defbinding widget-unmap () nil |
560af5c5 |
111 | (widget widget)) |
112 | |
0d270bd9 |
113 | (defbinding widget-realize () nil |
560af5c5 |
114 | (widget widget)) |
115 | |
0d270bd9 |
116 | (defbinding widget-unrealize () nil |
560af5c5 |
117 | (widget widget)) |
118 | |
1de3a418 |
119 | (defbinding widget-queue-draw () nil |
120 | (widget widget)) |
121 | |
122 | (defbinding widget-queue-resize () nil |
123 | (widget widget)) |
124 | |
125 | (defbinding widget-size-request () nil |
126 | (widget widget) |
127 | (requisition requisition)) |
128 | |
129 | (defbinding widget-get-child-requisition () nil |
130 | (widget widget) |
131 | (requisition requisition)) |
132 | |
133 | (defbinding widget-size-allocate () nil |
134 | (widget widget) |
135 | (allocation allocation)) |
136 | |
137 | |
0d270bd9 |
138 | (defbinding widget-add-accelerator |
560af5c5 |
139 | (widget signal accel-group key modifiers flags) nil |
140 | (widget widget) |
141 | ((name-to-string signal) string) |
142 | (accel-group accel-group) |
143 | ((gdk:keyval-from-name key) unsigned-int) |
144 | (modifiers gdk:modifier-type) |
145 | (flags accel-flags)) |
146 | |
0d270bd9 |
147 | (defbinding widget-remove-accelerator |
560af5c5 |
148 | (widget accel-group key modifiers) nil |
149 | (widget widget) |
150 | (accel-group accel-group) |
151 | ((gdk:keyval-from-name key) unsigned-int) |
152 | (modifiers gdk:modifier-type)) |
153 | |
1de3a418 |
154 | (defbinding (widget-set-accelerator-path "gtk_widget_set_accel_path") () nil |
560af5c5 |
155 | (widget widget) |
1de3a418 |
156 | (accel-path string) |
157 | (accel-group accel-group)) |
158 | |
560af5c5 |
159 | |
0d270bd9 |
160 | (defbinding widget-event () int |
560af5c5 |
161 | (widget widget) |
162 | (event gdk:event)) |
163 | |
0d270bd9 |
164 | (defbinding widget-activate () boolean |
560af5c5 |
165 | (widget widget)) |
166 | |
0d270bd9 |
167 | (defbinding widget-reparent () nil |
560af5c5 |
168 | (widget widget) |
169 | (new-parent widget)) |
170 | |
1de3a418 |
171 | (defbinding %widget-intersect () boolean |
172 | (widget widget) |
173 | (area gdk:rectangle) |
853ec10e |
174 | (intersection (or null gdk:rectangle))) |
560af5c5 |
175 | |
1de3a418 |
176 | (defun widget-intersection (widget area) |
177 | (let ((intersection (make-instance 'gdk:rectangle))) |
178 | (when (%widget-intersect widget area intersection) |
179 | intersection))) |
560af5c5 |
180 | |
1de3a418 |
181 | (defun widget-intersect-p (widget area) |
853ec10e |
182 | (%widget-intersect widget area nil)) |
aace61f5 |
183 | |
853ec10e |
184 | ;; (defbinding (widget-is-focus-p "gtk_widget_is_focus") () boolean |
185 | ;; (widget widget)) |
aace61f5 |
186 | |
1de3a418 |
187 | (defbinding widget-grab-focus () nil |
aace61f5 |
188 | (widget widget)) |
189 | |
1de3a418 |
190 | (defbinding widget-grab-default () nil |
191 | (widget widget)) |
560af5c5 |
192 | |
0d270bd9 |
193 | (defbinding widget-add-events () nil |
560af5c5 |
194 | (widget widget) |
195 | (events gdk:event-mask)) |
196 | |
1de3a418 |
197 | (defbinding widget-get-toplevel () widget |
560af5c5 |
198 | (widget widget)) |
199 | |
1de3a418 |
200 | (defbinding widget-get-ancestor (widget type) widget |
560af5c5 |
201 | (widget widget) |
202 | ((find-type-number type) type-number)) |
203 | |
1de3a418 |
204 | (defbinding widget-get-pointer () nil |
560af5c5 |
205 | (widget widget) |
206 | (x int :out) |
207 | (y int :out)) |
208 | |
0d270bd9 |
209 | (defbinding (widget-is-ancestor-p "gtk_widget_is_ancestor") () boolean |
560af5c5 |
210 | (widget widget) |
211 | (ancestor widget)) |
212 | |
1de3a418 |
213 | (defbinding widget-translate-coordinates () boolean |
214 | (src-widget widget) |
215 | (dest-widget widget) |
216 | (src-x int) (src-y int) |
217 | (set-x int :out) (dest-y int :out)) |
218 | |
219 | (defun widget-hide-on-delete (widget) |
220 | "Utility function; intended to be connected to the DELETE-EVENT |
221 | signal on a GtkWindow. The function calls WIDGET-HIDE on its |
222 | argument, then returns T. If connected to DELETE-EVENT, the |
223 | result is that clicking the close button for a window (on the window |
224 | frame, top right corner usually) will hide but not destroy the |
225 | window. By default, GTK+ destroys windows when DELETE-EVENT is |
226 | received." |
227 | (widget-hide widget) |
228 | t) |
229 | |
0d270bd9 |
230 | (defbinding widget-ensure-style () nil |
560af5c5 |
231 | (widget widget)) |
232 | |
0d270bd9 |
233 | (defbinding widget-reset-rc-styles () nil |
560af5c5 |
234 | (widget widget)) |
235 | |
0d270bd9 |
236 | (defbinding widget-push-colormap () nil |
560af5c5 |
237 | (colormap gdk:colormap)) |
238 | |
0d270bd9 |
239 | (defbinding widget-pop-colormap () nil) |
560af5c5 |
240 | |
0d270bd9 |
241 | (defbinding widget-set-default-colormap () nil |
560af5c5 |
242 | (colormap gdk:colormap)) |
243 | |
0d270bd9 |
244 | (defbinding widget-get-default-style () style) |
560af5c5 |
245 | |
0d270bd9 |
246 | (defbinding widget-get-default-colormap () gdk:colormap) |
560af5c5 |
247 | |
1de3a418 |
248 | (defbinding widget-get-default-visual () gdk:visual) |
249 | |
250 | (defbinding widget-get-default-direction () text-direction) |
251 | |
252 | (defbinding widget-set-default-direction () nil |
253 | (direction text-direction)) |
254 | |
0d270bd9 |
255 | (defbinding widget-shape-combine-mask () nil |
560af5c5 |
256 | (widget widget) |
257 | (shape-mask gdk:bitmap) |
258 | (x-offset int) |
259 | (y-offset int)) |
260 | |
1de3a418 |
261 | (defbinding widget-path () nil |
262 | (widget widget) |
263 | (path-length int :out) |
264 | (path string :out) |
265 | (reverse-path string :out)) |
266 | |
267 | (defbinding widget-class-path () nil |
268 | (widget widget) |
269 | (path-length int :out) |
270 | (path string :out) |
271 | (reverse-path string :out)) |
272 | |
273 | (defbinding widget-modify-style () nil |
274 | (widget widget) |
275 | (style rc-style)) |
276 | |
277 | (defbinding widget-modify-style () rc-style |
278 | (widget widget)) |
279 | |
280 | (defbinding (widget-modify-foreground "gtk_widget_modify_fg") () nil |
281 | (widget widget) |
282 | (state state-type) |
283 | (color gdk:color)) |
284 | |
285 | (defbinding (widget-modify-background "gtk_widget_modify_bg") () nil |
286 | (widget widget) |
287 | (state state-type) |
288 | (color gdk:color)) |
289 | |
290 | (defbinding widget-modify-text () nil |
291 | (widget widget) |
292 | (state state-type) |
293 | (color gdk:color)) |
294 | |
295 | (defbinding widget-modify-base () nil |
296 | (widget widget) |
297 | (state state-type) |
298 | (color gdk:color)) |
299 | |
300 | (defbinding widget-modify-font () nil |
301 | (widget widget) |
302 | (state state-type) |
303 | (font-desc pango:font-description)) |
304 | |
305 | (defbinding widget-create-pango-context () pango:context |
306 | (widget widget)) |
307 | |
308 | (defbinding widget-get-pango-context () pango:context |
309 | (widget widget)) |
310 | |
311 | (defbinding widget-create-pango-layout (widget &optional text) pango:layout |
312 | (widget widget) |
313 | (text (or string null))) |
314 | |
315 | (defbinding widget-render-icon () gdk:pixbuf |
316 | (widget widget) |
317 | (stock-id string) |
318 | (size icon-size) |
319 | (detail string)) |
320 | |
321 | (defbinding widget-push-composite-child () nil) |
322 | |
323 | (defbinding widget-pop-composite-child () nil) |
324 | |
325 | (defbinding widget-queue-draw-area () nil |
326 | (widget widget) |
327 | (x int) (y int) (width int) (height int)) |
328 | |
329 | (defbinding widget-reset-shapes () nil |
330 | (widget widget)) |
331 | |
332 | (defbinding widget-set-double-buffered () nil |
333 | (widget widget) |
334 | (double-buffered boolean)) |
335 | |
336 | (defbinding widget-set-redraw-on-allocate () nil |
337 | (widget widget) |
338 | (redraw-on-allocate boolean)) |
339 | |
340 | (defbinding widget-set-scroll-adjustments () boolean |
341 | (widget widget) |
342 | (hadjustment adjustment) |
343 | (vadjustment adjustment)) |
344 | |
345 | (defbinding widget-mnemonic-activate () boolean |
346 | (widget widget) |
347 | (group-cycling boolean)) |
348 | |
349 | (defbinding widget-region-intersect () pointer ;gdk:region |
350 | (widget widget) |
351 | (region pointer)) ;gdk:region)) |
352 | |
353 | (defbinding widget-send-expose () int |
354 | (widget widget) |
355 | (event gdk:event)) |
356 | |
357 | (defbinding widget-get-accessible () atk:object |
358 | (widget widget)) |
359 | |
360 | (defbinding widget-child-focus () boolean |
361 | (widget widget) |
362 | (direction direction-type)) |
363 | |
364 | (defbinding widget-child-notify () nil |
365 | (widget widget) |
366 | (child-property string)) |
367 | |
368 | (defbinding widget-freeze-child-notify () nil |
369 | (widget widget)) |
370 | |
371 | (defbinding %widget-get-size-request () nil |
372 | (widget widget) |
373 | (width int :out) |
374 | (height int :out)) |
375 | |
376 | (defun widget-get-size-request (widget) |
377 | (multiple-value-bind (width height) (%widget-get-size-request widget) |
9adccb27 |
378 | (values (unless (= width -1) width) (unless (= height -1) height)))) |
1de3a418 |
379 | |
380 | (defbinding widget-set-size-request (widget width height) nil |
381 | (widget widget) |
382 | ((or width -1) int) |
383 | ((or height -1) int)) |
384 | |
385 | (defbinding widget-thaw-child-notify () nil |
386 | (widget widget)) |
387 | |
388 | |
389 | ;;; Additional bindings and functions |
390 | |
853ec10e |
391 | (defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean |
560af5c5 |
392 | (widget widget)) |
393 | |
1de3a418 |
394 | (defbinding widget-get-size-allocation () nil |
395 | (widget widget) |
396 | (width int :out) |
397 | (height int :out)) |
398 | |
399 | (defbinding get-event-widget () widget |
400 | (event gdk:event)) |
401 | |
402 | (defun (setf widget-cursor) (cursor-type widget) |
56329445 |
403 | (let ((cursor (make-instance 'gdk:cursor :type cursor-type))) |
1de3a418 |
404 | (gdk:window-set-cursor (widget-window widget) cursor))) |