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