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