55212af1 |
1 | ;; Common Lisp bindings for GTK+ v2.x |
aa032564 |
2 | ;; Copyright 2000-2006 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 | |
44cba00e |
23 | ;; $Id: gtkwidget.lisp,v 1.27 2007/02/19 14:29:33 espen Exp $ |
0d07716f |
24 | |
25 | (in-package "GTK") |
26 | |
27 | |
7af3f90b |
28 | #-debug-ref-counting |
29 | (defmethod print-object ((widget widget) stream) |
30 | (if (and |
31 | (proxy-valid-p widget) |
32 | (slot-boundp widget 'name) (not (zerop (length (widget-name widget))))) |
33 | (print-unreadable-object (widget stream :type t :identity nil) |
34 | (format stream "~S at 0x~X" |
aa032564 |
35 | (widget-name widget) (pointer-address (foreign-location widget)))) |
7af3f90b |
36 | (call-next-method))) |
37 | |
d0cc9e86 |
38 | (defmethod shared-initialize ((widget widget) names &key (visible nil visible-p)) |
aa032564 |
39 | (declare (ignore names)) |
d0cc9e86 |
40 | (when (and visible-p (not visible)) ; widget explicit set as not visible |
41 | (setf (user-data widget 'hidden-p) t) |
42 | (signal-connect widget 'show |
43 | #'(lambda () |
44 | (unset-user-data widget 'hidden-p)) |
45 | :remove t)) |
46 | (call-next-method)) |
dd392521 |
47 | |
9d5e4733 |
48 | (defmethod shared-initialize :after ((widget widget) names &key parent visible) |
d0cc9e86 |
49 | (declare (ignore names)) |
9d5e4733 |
50 | (when visible |
51 | (widget-show widget)) |
d0cc9e86 |
52 | (when parent |
53 | (when (slot-boundp widget 'parent) |
54 | (container-remove (widget-parent widget) widget)) |
55 | (destructuring-bind (parent &rest args) (mklist parent) |
56 | (apply #'container-add parent widget args)))) |
0d07716f |
57 | |
03272be4 |
58 | (defmethod slot-unbound ((class gobject-class) (object widget) |
59 | (slot (eql 'child-properties))) |
0d07716f |
60 | (cond |
03272be4 |
61 | ((slot-boundp object 'parent) |
c66e7b94 |
62 | (with-slots (parent child-properties) object |
03272be4 |
63 | (setf child-properties |
64 | (make-instance |
65 | (gethash (class-of parent) *container-to-child-class-mappings*) |
0d07716f |
66 | :parent parent :child object)))) |
03272be4 |
67 | ((call-next-method)))) |
68 | |
0d07716f |
69 | |
a68868d1 |
70 | (defmethod compute-signal-function ((widget widget) signal function object args) |
aa032564 |
71 | (declare (ignore signal)) |
d0cc9e86 |
72 | (if (eq object :parent) |
a68868d1 |
73 | #'(lambda (&rest emission-args) |
74 | (let ((all-args (nconc (rest emission-args) args))) |
75 | (if (slot-boundp widget 'parent) |
76 | (apply function (widget-parent widget) all-args) |
03272be4 |
77 | ;; Delay until parent is set |
2519d4ca |
78 | (signal-connect widget 'parent-set |
79 | #'(lambda (old-parent) |
80 | (declare (ignore old-parent)) |
81 | (let ((*signal-stop-emission* |
82 | #'(lambda () |
83 | (warn "Ignoring emission stop in delayed signal handler")))) |
a68868d1 |
84 | (apply function (widget-parent widget) all-args))) |
2519d4ca |
85 | :remove t) |
86 | ; (warn "Widget has no parent -- ignoring signal") |
a68868d1 |
87 | ))) |
2519d4ca |
88 | (call-next-method))) |
89 | |
c66e7b94 |
90 | (defun child-property-value (widget slot) |
91 | (slot-value (widget-child-properties widget) slot)) |
0d07716f |
92 | |
c66e7b94 |
93 | (defun (setf child-property-value) (value widget slot) |
94 | (setf (slot-value (widget-child-properties widget) slot) value)) |
0d07716f |
95 | |
c66e7b94 |
96 | (defmacro with-child-properties (slots widget &body body) |
97 | `(with-slots ,slots (widget-child-properties ,widget) |
0d07716f |
98 | ,@body)) |
99 | |
860e6a2e |
100 | |
860e6a2e |
101 | ;;; Bindings |
102 | |
08aad4db |
103 | (defbinding widget-destroy () nil |
0d07716f |
104 | (widget widget)) |
105 | |
08aad4db |
106 | (defbinding widget-unparent () nil |
0d07716f |
107 | (widget widget)) |
108 | |
08aad4db |
109 | (defbinding widget-show () nil |
0d07716f |
110 | (widget widget)) |
111 | |
08aad4db |
112 | (defbinding widget-show-now () nil |
0d07716f |
113 | (widget widget)) |
114 | |
08aad4db |
115 | (defbinding widget-hide () nil |
0d07716f |
116 | (widget widget)) |
117 | |
d0cc9e86 |
118 | (defun widget-hidden-p (widget) |
119 | "Return T if WIDGET has been explicit hidden during construction." |
120 | (user-data widget 'hidden-p)) |
121 | |
08aad4db |
122 | (defbinding widget-show-all () nil |
0d07716f |
123 | (widget widget)) |
124 | |
08aad4db |
125 | (defbinding widget-hide-all () nil |
0d07716f |
126 | (widget widget)) |
127 | |
08aad4db |
128 | (defbinding widget-map () nil |
0d07716f |
129 | (widget widget)) |
130 | |
08aad4db |
131 | (defbinding widget-unmap () nil |
0d07716f |
132 | (widget widget)) |
133 | |
08aad4db |
134 | (defbinding widget-realize () nil |
0d07716f |
135 | (widget widget)) |
136 | |
08aad4db |
137 | (defbinding widget-unrealize () nil |
0d07716f |
138 | (widget widget)) |
139 | |
860e6a2e |
140 | (defbinding widget-queue-draw () nil |
141 | (widget widget)) |
142 | |
143 | (defbinding widget-queue-resize () nil |
144 | (widget widget)) |
145 | |
03272be4 |
146 | (defbinding widget-queue-resize-no-redraw () nil |
147 | (widget widget)) |
148 | |
149 | (defbinding widget-size-request |
150 | (widget &optional (requisition (make-instance 'requisition))) nil |
860e6a2e |
151 | (widget widget) |
aa032564 |
152 | (requisition requisition :in/return)) |
860e6a2e |
153 | |
03272be4 |
154 | (defbinding widget-get-child-requisition |
155 | (widget &optional (requisition (make-instance 'requisition))) nil |
860e6a2e |
156 | (widget widget) |
aa032564 |
157 | (requisition requisition :in/return)) |
860e6a2e |
158 | |
159 | (defbinding widget-size-allocate () nil |
160 | (widget widget) |
161 | (allocation allocation)) |
162 | |
08aad4db |
163 | (defbinding widget-add-accelerator |
0d07716f |
164 | (widget signal accel-group key modifiers flags) nil |
165 | (widget widget) |
7af3f90b |
166 | ((signal-name-to-string signal) string) |
0d07716f |
167 | (accel-group accel-group) |
168 | ((gdk:keyval-from-name key) unsigned-int) |
169 | (modifiers gdk:modifier-type) |
170 | (flags accel-flags)) |
171 | |
08aad4db |
172 | (defbinding widget-remove-accelerator |
0d07716f |
173 | (widget accel-group key modifiers) nil |
174 | (widget widget) |
175 | (accel-group accel-group) |
176 | ((gdk:keyval-from-name key) unsigned-int) |
177 | (modifiers gdk:modifier-type)) |
178 | |
03272be4 |
179 | (defbinding widget-set-accel-path () nil |
0d07716f |
180 | (widget widget) |
860e6a2e |
181 | (accel-path string) |
182 | (accel-group accel-group)) |
0d07716f |
183 | |
03272be4 |
184 | (defbinding widget-list-accel-closures () (glist pointer) |
185 | (widget widget)) |
186 | |
187 | (defbinding widget-can-activate-accel-p () boolean |
188 | (widget widget) |
189 | (signal-id unsigned-int)) |
190 | |
191 | (defbinding widget-event () boolean |
0d07716f |
192 | (widget widget) |
193 | (event gdk:event)) |
194 | |
08aad4db |
195 | (defbinding widget-activate () boolean |
0d07716f |
196 | (widget widget)) |
197 | |
08aad4db |
198 | (defbinding widget-reparent () nil |
0d07716f |
199 | (widget widget) |
200 | (new-parent widget)) |
201 | |
860e6a2e |
202 | (defbinding %widget-intersect () boolean |
203 | (widget widget) |
204 | (area gdk:rectangle) |
ecdb2ae2 |
205 | (intersection (or null gdk:rectangle))) |
0d07716f |
206 | |
860e6a2e |
207 | (defun widget-intersection (widget area) |
208 | (let ((intersection (make-instance 'gdk:rectangle))) |
209 | (when (%widget-intersect widget area intersection) |
210 | intersection))) |
0d07716f |
211 | |
860e6a2e |
212 | (defun widget-intersect-p (widget area) |
ecdb2ae2 |
213 | (%widget-intersect widget area nil)) |
13148f19 |
214 | |
860e6a2e |
215 | (defbinding widget-grab-focus () nil |
13148f19 |
216 | (widget widget)) |
217 | |
860e6a2e |
218 | (defbinding widget-grab-default () nil |
219 | (widget widget)) |
0d07716f |
220 | |
08aad4db |
221 | (defbinding widget-add-events () nil |
0d07716f |
222 | (widget widget) |
223 | (events gdk:event-mask)) |
224 | |
860e6a2e |
225 | (defbinding widget-get-toplevel () widget |
0d07716f |
226 | (widget widget)) |
227 | |
860e6a2e |
228 | (defbinding widget-get-ancestor (widget type) widget |
0d07716f |
229 | (widget widget) |
230 | ((find-type-number type) type-number)) |
231 | |
860e6a2e |
232 | (defbinding widget-get-pointer () nil |
0d07716f |
233 | (widget widget) |
234 | (x int :out) |
235 | (y int :out)) |
236 | |
03272be4 |
237 | (defbinding widget-is-ancestor-p () boolean |
0d07716f |
238 | (widget widget) |
239 | (ancestor widget)) |
240 | |
860e6a2e |
241 | (defbinding widget-translate-coordinates () boolean |
242 | (src-widget widget) |
243 | (dest-widget widget) |
244 | (src-x int) (src-y int) |
245 | (set-x int :out) (dest-y int :out)) |
246 | |
247 | (defun widget-hide-on-delete (widget) |
248 | "Utility function; intended to be connected to the DELETE-EVENT |
03272be4 |
249 | signal on a WINDOW. The function calls WIDGET-HIDE on its |
860e6a2e |
250 | argument, then returns T. If connected to DELETE-EVENT, the |
251 | result is that clicking the close button for a window (on the window |
252 | frame, top right corner usually) will hide but not destroy the |
253 | window. By default, GTK+ destroys windows when DELETE-EVENT is |
254 | received." |
255 | (widget-hide widget) |
256 | t) |
257 | |
08aad4db |
258 | (defbinding widget-ensure-style () nil |
0d07716f |
259 | (widget widget)) |
260 | |
08aad4db |
261 | (defbinding widget-reset-rc-styles () nil |
0d07716f |
262 | (widget widget)) |
263 | |
08aad4db |
264 | (defbinding widget-push-colormap () nil |
0d07716f |
265 | (colormap gdk:colormap)) |
266 | |
08aad4db |
267 | (defbinding widget-pop-colormap () nil) |
0d07716f |
268 | |
03272be4 |
269 | (defbinding %widget-set-default-colormap () nil |
0d07716f |
270 | (colormap gdk:colormap)) |
271 | |
03272be4 |
272 | (defun (setf widget-default-colormap) (colormap) |
273 | (%widget-set-default-colormap colormap) |
274 | colormap) |
275 | |
276 | (defbinding (widget-default-style "gtk_widget_get_default_style") () style) |
0d07716f |
277 | |
03272be4 |
278 | (defbinding (widget-default-colromap "gtk_widget_get_default_colormap") |
279 | () gdk:colormap) |
0d07716f |
280 | |
03272be4 |
281 | (defbinding (widget-default-visual "gtk_widget_get_default_visual") |
282 | () gdk:visual) |
860e6a2e |
283 | |
03272be4 |
284 | (defbinding (widget-default-direction "gtk_widget_get_default_direction") |
285 | () text-direction) |
860e6a2e |
286 | |
03272be4 |
287 | (defbinding %widget-set-default-direction () nil |
288 | (direction text-direction)) |
289 | |
290 | (defun (setf widget-default-direction) (direction) |
291 | (%widget-set-default-direction direction) |
292 | direction) |
860e6a2e |
293 | |
08aad4db |
294 | (defbinding widget-shape-combine-mask () nil |
0d07716f |
295 | (widget widget) |
03272be4 |
296 | (shape-mask (or null gdk:bitmap)) |
0d07716f |
297 | (x-offset int) |
298 | (y-offset int)) |
299 | |
46158111 |
300 | (defun widget-path (widget) |
301 | (let ((subpath (list (if (and |
302 | (slot-boundp widget 'name) |
303 | (not (zerop (length (widget-name widget))))) |
304 | (widget-name widget) |
305 | (type-of widget))))) |
306 | (if (slot-boundp widget 'parent) |
307 | (nconc (widget-path (widget-parent widget)) subpath) |
308 | subpath))) |
309 | |
310 | (defun widget-class-path (widget) |
311 | (let ((subpath (list (type-of widget)))) |
312 | (if (slot-boundp widget 'parent) |
313 | (nconc (widget-class-path (widget-parent widget)) subpath) |
314 | subpath))) |
315 | |
316 | |
317 | (defun widget-path-lookup (path &optional (root (nreverse (window-list-toplevels))) (error-p t)) |
318 | (let ((component (first path))) |
319 | (loop |
320 | for widget in (mklist root) |
321 | do (when (or |
322 | (and |
323 | (stringp component) (slot-boundp widget 'name) |
324 | (string= component (widget-name widget))) |
325 | (and |
326 | (symbolp component) (typep widget component))) |
327 | (cond |
328 | ((endp (rest path)) (return widget)) |
329 | ((typep widget 'container) |
330 | (let ((descendant (widget-path-lookup (rest path) (container-children widget) nil))) |
331 | (when descendant |
332 | (return descendant)))))))) |
333 | (when error-p |
334 | (error "Widget not found: ~A" path))) |
335 | |
336 | |
337 | (defun widget-find (name &optional (root (nreverse (window-list-toplevels))) (error-p t)) |
338 | "Search for a widget with the given name. ROOT should be a container |
339 | widget or a list of containers." |
340 | (loop |
341 | for widget in (mklist root) |
342 | do (cond |
343 | ((and (slot-boundp widget 'name) (string= name (widget-name widget))) |
9afb775d |
344 | (return-from widget-find widget)) |
46158111 |
345 | ((typep widget 'container) |
346 | (let ((descendant (widget-find name (container-children widget) nil))) |
347 | (when descendant |
9afb775d |
348 | (return-from widget-find descendant)))))) |
46158111 |
349 | (when error-p |
350 | (error "Widget not found: ~A" name))) |
860e6a2e |
351 | |
860e6a2e |
352 | |
353 | (defbinding widget-modify-style () nil |
354 | (widget widget) |
355 | (style rc-style)) |
356 | |
03272be4 |
357 | (defbinding widget-get-modifier-style () rc-style |
860e6a2e |
358 | (widget widget)) |
359 | |
03272be4 |
360 | (defbinding widget-modify-fg () nil |
860e6a2e |
361 | (widget widget) |
362 | (state state-type) |
363 | (color gdk:color)) |
364 | |
03272be4 |
365 | (defbinding widget-modify-bg () nil |
860e6a2e |
366 | (widget widget) |
367 | (state state-type) |
368 | (color gdk:color)) |
369 | |
370 | (defbinding widget-modify-text () nil |
371 | (widget widget) |
372 | (state state-type) |
373 | (color gdk:color)) |
374 | |
375 | (defbinding widget-modify-base () nil |
376 | (widget widget) |
377 | (state state-type) |
378 | (color gdk:color)) |
379 | |
b22f5374 |
380 | (defbinding widget-modify-font (widget font-desc) nil |
860e6a2e |
381 | (widget widget) |
b22f5374 |
382 | ((etypecase font-desc |
383 | (pango:font-description font-desc) |
384 | (string (pango:font-description-from-string font-desc))) |
385 | pango:font-description)) |
860e6a2e |
386 | |
387 | (defbinding widget-create-pango-context () pango:context |
388 | (widget widget)) |
389 | |
390 | (defbinding widget-get-pango-context () pango:context |
391 | (widget widget)) |
392 | |
393 | (defbinding widget-create-pango-layout (widget &optional text) pango:layout |
394 | (widget widget) |
395 | (text (or string null))) |
396 | |
03272be4 |
397 | (defbinding widget-render-icon (widget stock-id &optional size detail) |
398 | gdk:pixbuf |
860e6a2e |
399 | (widget widget) |
400 | (stock-id string) |
03272be4 |
401 | ((or size -1) (or icon-size int)) |
402 | (detail (or null string))) |
860e6a2e |
403 | |
404 | (defbinding widget-push-composite-child () nil) |
405 | |
406 | (defbinding widget-pop-composite-child () nil) |
407 | |
408 | (defbinding widget-queue-draw-area () nil |
409 | (widget widget) |
410 | (x int) (y int) (width int) (height int)) |
411 | |
412 | (defbinding widget-reset-shapes () nil |
413 | (widget widget)) |
414 | |
44cba00e |
415 | (defbinding widget-set-double-buffered () nil |
416 | (widget widget) |
417 | (double-buffered boolean)) |
860e6a2e |
418 | |
03272be4 |
419 | ;; (defbinding widget-set-redraw-on-allocate () nil |
420 | ;; (widget widget) |
421 | ;; (redraw-on-allocate boolean)) |
860e6a2e |
422 | |
423 | (defbinding widget-set-scroll-adjustments () boolean |
424 | (widget widget) |
03272be4 |
425 | (hadjustment (or null adjustment)) |
426 | (vadjustment (or null adjustment))) |
860e6a2e |
427 | |
428 | (defbinding widget-mnemonic-activate () boolean |
429 | (widget widget) |
430 | (group-cycling boolean)) |
431 | |
03272be4 |
432 | (defbinding widget-class-find-style-property (class name) param |
433 | ((type-class-peek class) pointer) |
434 | (name string)) |
435 | |
436 | (defbinding widget-class-list-style-properties (class) |
437 | (vector (copy-of param) n-properties) |
438 | ((type-class-peek class) pointer) |
439 | (n-properties unsigned-int :out)) |
440 | |
860e6a2e |
441 | (defbinding widget-region-intersect () pointer ;gdk:region |
442 | (widget widget) |
443 | (region pointer)) ;gdk:region)) |
444 | |
03272be4 |
445 | (defbinding widget-send-expose () boolean |
860e6a2e |
446 | (widget widget) |
447 | (event gdk:event)) |
448 | |
03272be4 |
449 | (defbinding %widget-style-get-property () nil |
450 | (widget widget) |
451 | (name string) |
452 | (value gvalue)) |
453 | |
454 | (defun style-property-value (widget style) |
455 | (let* ((name (string-downcase style)) |
456 | (param (widget-class-find-style-property (class-of widget) name))) |
457 | (if (not param) |
458 | (error "~A has no such style property: ~A" widget style) |
459 | (with-gvalue (gvalue (param-value-type param)) |
460 | (%widget-style-get-property widget (string-downcase style) gvalue))))) |
461 | |
860e6a2e |
462 | (defbinding widget-get-accessible () atk:object |
463 | (widget widget)) |
464 | |
465 | (defbinding widget-child-focus () boolean |
466 | (widget widget) |
467 | (direction direction-type)) |
468 | |
469 | (defbinding widget-child-notify () nil |
470 | (widget widget) |
471 | (child-property string)) |
472 | |
473 | (defbinding widget-freeze-child-notify () nil |
474 | (widget widget)) |
475 | |
03272be4 |
476 | (defbinding widget-get-clipboard () clipboard |
477 | (widget widget) |
478 | (selection int #|gdk:atom|#)) |
479 | |
480 | (defbinding widget-get-display () gdk:display |
481 | (widget widget)) |
482 | |
483 | (defbinding widget-get-root-window () gdk:window |
484 | (widget widget)) |
485 | |
486 | (defbinding widget-get-screen () gdk:screen |
487 | (widget widget)) |
488 | |
489 | (defbinding widget-has-screen-p () boolean |
490 | (widget widget)) |
491 | |
860e6a2e |
492 | (defbinding %widget-get-size-request () nil |
493 | (widget widget) |
494 | (width int :out) |
495 | (height int :out)) |
496 | |
497 | (defun widget-get-size-request (widget) |
498 | (multiple-value-bind (width height) (%widget-get-size-request widget) |
6baf860c |
499 | (values (unless (= width -1) width) (unless (= height -1) height)))) |
860e6a2e |
500 | |
501 | (defbinding widget-set-size-request (widget width height) nil |
502 | (widget widget) |
503 | ((or width -1) int) |
504 | ((or height -1) int)) |
505 | |
506 | (defbinding widget-thaw-child-notify () nil |
507 | (widget widget)) |
508 | |
03272be4 |
509 | (defbinding widget-list-mnemonic-labels () (glist widget) |
510 | (widget widget)) |
511 | |
512 | (defbinding widget-add-mnemonic-label () nil |
513 | (widget widget) |
514 | (label widget)) |
515 | |
516 | (defbinding widget-remove-mnemonic-label () nil |
517 | (widget widget) |
518 | (label widget)) |
519 | |
860e6a2e |
520 | |
521 | ;;; Additional bindings and functions |
522 | |
ecdb2ae2 |
523 | (defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean |
0d07716f |
524 | (widget widget)) |
525 | |
860e6a2e |
526 | (defbinding widget-get-size-allocation () nil |
527 | (widget widget) |
528 | (width int :out) |
529 | (height int :out)) |
530 | |
531 | (defbinding get-event-widget () widget |
532 | (event gdk:event)) |
533 | |
534 | (defun (setf widget-cursor) (cursor-type widget) |
6091b3e8 |
535 | (warn "(SETF WIDGET-CURSOR) is deprecated, use WIDGET-SET-CURSOR instead") |
536 | (widget-set-cursor widget cursor-type)) |
537 | |
538 | (defun widget-set-cursor (widget cursor &rest args) |
539 | (gdk:window-set-cursor (widget-window widget) |
540 | (apply #'gdk:ensure-cursor cursor args))) |
03272be4 |
541 | |
542 | (defbinding %widget-get-parent-window () gdk:window |
543 | (widget widget)) |
544 | |
545 | (defun %widget-parent-window (widget) |
546 | (when (slot-boundp widget 'parent) |
547 | (%widget-get-parent-window widget))) |