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