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