1 ;; Common Lisp bindings for GTK+ v2.x
2 ;; Copyright 2000-2005 Espen S. Johnsen <espen@users.sf.net>
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:
12 ;; The above copyright notice and this permission notice shall be
13 ;; included in all copies or substantial portions of the Software.
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.
23 ;; $Id: gtkwidget.lisp,v 1.18 2005-04-23 16:48:52 espen Exp $
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
33 (unset-user-data widget 'hidden-p))
37 (defmethod shared-initialize :after ((widget widget) names &key parent visible)
38 (declare (ignore names))
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))))
47 (defmethod slot-unbound ((class gobject-class) (object widget)
48 (slot (eql 'child-properties)))
50 ((slot-boundp object 'parent)
51 (with-slots (parent child-properties) object
52 (setf child-properties
54 (gethash (class-of parent) *container-to-child-class-mappings*)
55 :parent parent :child object))))
56 ((call-next-method))))
58 (defmethod slot-boundp-using-class ((class gobject-class) (object widget) slot)
61 (eq (slot-definition-name slot) 'child-properties)
62 (slot-boundp object 'parent))
65 (defmethod compute-signal-function ((widget widget) signal function object)
66 (if (eq object :parent)
67 #'(lambda (&rest args)
68 (if (slot-boundp widget 'parent)
69 (apply function (widget-parent widget) (rest args))
70 ;; Delay until parent is set
71 (signal-connect widget 'parent-set
72 #'(lambda (old-parent)
73 (declare (ignore old-parent))
74 (let ((*signal-stop-emission*
76 (warn "Ignoring emission stop in delayed signal handler"))))
77 (apply function (widget-parent widget) (rest args))))
79 ; (warn "Widget has no parent -- ignoring signal")
83 (defun child-property-value (widget slot)
84 (slot-value (widget-child-properties widget) slot))
86 (defun (setf child-property-value) (value widget slot)
87 (setf (slot-value (widget-child-properties widget) slot) value))
89 (defmacro with-child-properties (slots widget &body body)
90 `(with-slots ,slots (widget-child-properties ,widget)
96 (defbinding widget-destroy () nil
99 (defbinding widget-unparent () nil
102 (defbinding widget-show () nil
105 (defbinding widget-show-now () nil
108 (defbinding widget-hide () nil
111 (defun widget-hidden-p (widget)
112 "Return T if WIDGET has been explicit hidden during construction."
113 (user-data widget 'hidden-p))
115 (defbinding widget-show-all () nil
118 (defbinding widget-hide-all () nil
121 (defbinding widget-map () nil
124 (defbinding widget-unmap () nil
127 (defbinding widget-realize () nil
130 (defbinding widget-unrealize () nil
133 (defbinding widget-queue-draw () nil
136 (defbinding widget-queue-resize () nil
139 (defbinding widget-queue-resize-no-redraw () nil
142 (defbinding widget-size-request
143 (widget &optional (requisition (make-instance 'requisition))) nil
145 (requisition requisition :return))
147 (defbinding widget-get-child-requisition
148 (widget &optional (requisition (make-instance 'requisition))) nil
150 (requisition requisition :return))
152 (defbinding widget-size-allocate () nil
154 (allocation allocation))
156 (defbinding widget-add-accelerator
157 (widget signal accel-group key modifiers flags) nil
159 ((name-to-string signal) string)
160 (accel-group accel-group)
161 ((gdk:keyval-from-name key) unsigned-int)
162 (modifiers gdk:modifier-type)
165 (defbinding widget-remove-accelerator
166 (widget accel-group key modifiers) nil
168 (accel-group accel-group)
169 ((gdk:keyval-from-name key) unsigned-int)
170 (modifiers gdk:modifier-type))
172 (defbinding widget-set-accel-path () nil
175 (accel-group accel-group))
177 (defbinding widget-list-accel-closures () (glist pointer)
180 (defbinding widget-can-activate-accel-p () boolean
182 (signal-id unsigned-int))
184 (defbinding widget-event () boolean
188 (defbinding widget-activate () boolean
191 (defbinding widget-reparent () nil
195 (defbinding %widget-intersect () boolean
198 (intersection (or null gdk:rectangle)))
200 (defun widget-intersection (widget area)
201 (let ((intersection (make-instance 'gdk:rectangle)))
202 (when (%widget-intersect widget area intersection)
205 (defun widget-intersect-p (widget area)
206 (%widget-intersect widget area nil))
208 (defbinding widget-grab-focus () nil
211 (defbinding widget-grab-default () nil
214 (defbinding widget-add-events () nil
216 (events gdk:event-mask))
218 (defbinding widget-get-toplevel () widget
221 (defbinding widget-get-ancestor (widget type) widget
223 ((find-type-number type) type-number))
225 (defbinding widget-get-pointer () nil
230 (defbinding widget-is-ancestor-p () boolean
234 (defbinding widget-translate-coordinates () boolean
237 (src-x int) (src-y int)
238 (set-x int :out) (dest-y int :out))
240 (defun widget-hide-on-delete (widget)
241 "Utility function; intended to be connected to the DELETE-EVENT
242 signal on a WINDOW. The function calls WIDGET-HIDE on its
243 argument, then returns T. If connected to DELETE-EVENT, the
244 result is that clicking the close button for a window (on the window
245 frame, top right corner usually) will hide but not destroy the
246 window. By default, GTK+ destroys windows when DELETE-EVENT is
251 (defbinding widget-ensure-style () nil
254 (defbinding widget-reset-rc-styles () nil
257 (defbinding widget-push-colormap () nil
258 (colormap gdk:colormap))
260 (defbinding widget-pop-colormap () nil)
262 (defbinding %widget-set-default-colormap () nil
263 (colormap gdk:colormap))
265 (defun (setf widget-default-colormap) (colormap)
266 (%widget-set-default-colormap colormap)
269 (defbinding (widget-default-style "gtk_widget_get_default_style") () style)
271 (defbinding (widget-default-colromap "gtk_widget_get_default_colormap")
274 (defbinding (widget-default-visual "gtk_widget_get_default_visual")
277 (defbinding (widget-default-direction "gtk_widget_get_default_direction")
280 (defbinding %widget-set-default-direction () nil
281 (direction text-direction))
283 (defun (setf widget-default-direction) (direction)
284 (%widget-set-default-direction direction)
287 (defbinding widget-shape-combine-mask () nil
289 (shape-mask (or null gdk:bitmap))
293 (defbinding widget-path () nil
295 (path-length int :out)
297 (reverse-path string :out))
299 (defbinding widget-class-path () nil
301 (path-length int :out)
303 (reverse-path string :out))
305 (defbinding widget-modify-style () nil
309 (defbinding widget-get-modifier-style () rc-style
312 (defbinding widget-modify-fg () nil
317 (defbinding widget-modify-bg () nil
322 (defbinding widget-modify-text () nil
327 (defbinding widget-modify-base () nil
332 (defbinding widget-modify-font () nil
335 (font-desc pango:font-description))
337 (defbinding widget-create-pango-context () pango:context
340 (defbinding widget-get-pango-context () pango:context
343 (defbinding widget-create-pango-layout (widget &optional text) pango:layout
345 (text (or string null)))
347 (defbinding widget-render-icon (widget stock-id &optional size detail)
351 ((or size -1) (or icon-size int))
352 (detail (or null string)))
354 (defbinding widget-push-composite-child () nil)
356 (defbinding widget-pop-composite-child () nil)
358 (defbinding widget-queue-draw-area () nil
360 (x int) (y int) (width int) (height int))
362 (defbinding widget-reset-shapes () nil
365 ;; (defbinding widget-set-double-buffered () nil
367 ;; (double-buffered boolean))
369 ;; (defbinding widget-set-redraw-on-allocate () nil
371 ;; (redraw-on-allocate boolean))
373 (defbinding widget-set-scroll-adjustments () boolean
375 (hadjustment (or null adjustment))
376 (vadjustment (or null adjustment)))
378 (defbinding widget-mnemonic-activate () boolean
380 (group-cycling boolean))
382 (defbinding widget-class-find-style-property (class name) param
383 ((type-class-peek class) pointer)
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))
391 (defbinding widget-region-intersect () pointer ;gdk:region
393 (region pointer)) ;gdk:region))
395 (defbinding widget-send-expose () boolean
399 (defbinding %widget-style-get-property () nil
404 (defun style-property-value (widget style)
405 (let* ((name (string-downcase style))
406 (param (widget-class-find-style-property (class-of widget) name)))
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)))))
412 (defbinding widget-get-accessible () atk:object
415 (defbinding widget-child-focus () boolean
417 (direction direction-type))
419 (defbinding widget-child-notify () nil
421 (child-property string))
423 (defbinding widget-freeze-child-notify () nil
426 (defbinding widget-get-clipboard () clipboard
428 (selection int #|gdk:atom|#))
430 (defbinding widget-get-display () gdk:display
433 (defbinding widget-get-root-window () gdk:window
436 (defbinding widget-get-screen () gdk:screen
439 (defbinding widget-has-screen-p () boolean
442 (defbinding %widget-get-size-request () nil
447 (defun widget-get-size-request (widget)
448 (multiple-value-bind (width height) (%widget-get-size-request widget)
449 (values (unless (= width -1) width) (unless (= height -1) height))))
451 (defbinding widget-set-size-request (widget width height) nil
454 ((or height -1) int))
456 (defbinding widget-thaw-child-notify () nil
459 (defbinding widget-list-mnemonic-labels () (glist widget)
462 (defbinding widget-add-mnemonic-label () nil
466 (defbinding widget-remove-mnemonic-label () nil
471 ;;; Additional bindings and functions
473 (defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean
476 (defbinding widget-get-size-allocation () nil
481 (defbinding get-event-widget () widget
484 (defun (setf widget-cursor) (cursor-type widget)
485 (let ((cursor (make-instance 'gdk:cursor :type cursor-type)))
486 (gdk:window-set-cursor (widget-window widget) cursor)))
488 (defbinding %widget-get-parent-window () gdk:window
491 (defun %widget-parent-window (widget)
492 (when (slot-boundp widget 'parent)
493 (%widget-get-parent-window widget)))