+(defun widget-path (widget)
+ (let ((subpath (list (if (and
+ (slot-boundp widget 'name)
+ (not (zerop (length (widget-name widget)))))
+ (widget-name widget)
+ (type-of widget)))))
+ (if (slot-boundp widget 'parent)
+ (nconc (widget-path (widget-parent widget)) subpath)
+ subpath)))
+
+(defun widget-class-path (widget)
+ (let ((subpath (list (type-of widget))))
+ (if (slot-boundp widget 'parent)
+ (nconc (widget-class-path (widget-parent widget)) subpath)
+ subpath)))
+
+
+(defun widget-path-lookup (path &optional (root (nreverse (window-list-toplevels))) (error-p t))
+ (let ((component (first path)))
+ (loop
+ for widget in (mklist root)
+ do (when (or
+ (and
+ (stringp component) (slot-boundp widget 'name)
+ (string= component (widget-name widget)))
+ (and
+ (symbolp component) (typep widget component)))
+ (cond
+ ((endp (rest path)) (return widget))
+ ((typep widget 'container)
+ (let ((descendant (widget-path-lookup (rest path) (container-children widget) nil)))
+ (when descendant
+ (return descendant))))))))
+ (when error-p
+ (error "Widget not found: ~A" path)))
+
+
+(defun widget-find (name &optional (root (nreverse (window-list-toplevels))) (error-p t))
+ "Search for a widget with the given name. ROOT should be a container
+widget or a list of containers."
+ (loop
+ for widget in (mklist root)
+ do (cond
+ ((and (slot-boundp widget 'name) (string= name (widget-name widget)))
+ (return widget))
+ ((typep widget 'container)
+ (let ((descendant (widget-find name (container-children widget) nil)))
+ (when descendant
+ (return descendant))))))
+ (when error-p
+ (error "Widget not found: ~A" name)))
+
+
+(defbinding widget-modify-style () nil
+ (widget widget)
+ (style rc-style))
+
+(defbinding widget-get-modifier-style () rc-style
+ (widget widget))
+
+(defbinding widget-modify-fg () nil
+ (widget widget)
+ (state state-type)
+ (color gdk:color))
+
+(defbinding widget-modify-bg () nil
+ (widget widget)
+ (state state-type)
+ (color gdk:color))
+
+(defbinding widget-modify-text () nil
+ (widget widget)
+ (state state-type)
+ (color gdk:color))
+
+(defbinding widget-modify-base () nil
+ (widget widget)
+ (state state-type)
+ (color gdk:color))
+
+(defbinding widget-modify-font (widget font-desc) nil
+ (widget widget)
+ ((etypecase font-desc
+ (pango:font-description font-desc)
+ (string (pango:font-description-from-string font-desc)))
+ pango:font-description))
+
+(defbinding widget-create-pango-context () pango:context
+ (widget widget))
+
+(defbinding widget-get-pango-context () pango:context
+ (widget widget))
+
+(defbinding widget-create-pango-layout (widget &optional text) pango:layout
+ (widget widget)
+ (text (or string null)))
+
+(defbinding widget-render-icon (widget stock-id &optional size detail)
+ gdk:pixbuf
+ (widget widget)
+ (stock-id string)
+ ((or size -1) (or icon-size int))
+ (detail (or null string)))
+
+(defbinding widget-push-composite-child () nil)
+
+(defbinding widget-pop-composite-child () nil)
+
+(defbinding widget-queue-draw-area () nil
+ (widget widget)
+ (x int) (y int) (width int) (height int))
+
+(defbinding widget-reset-shapes () nil
+ (widget widget))
+
+;; (defbinding widget-set-double-buffered () nil
+;; (widget widget)
+;; (double-buffered boolean))
+
+;; (defbinding widget-set-redraw-on-allocate () nil
+;; (widget widget)
+;; (redraw-on-allocate boolean))
+
+(defbinding widget-set-scroll-adjustments () boolean
+ (widget widget)
+ (hadjustment (or null adjustment))
+ (vadjustment (or null adjustment)))
+
+(defbinding widget-mnemonic-activate () boolean
+ (widget widget)
+ (group-cycling boolean))
+
+(defbinding widget-class-find-style-property (class name) param
+ ((type-class-peek class) pointer)
+ (name string))
+
+(defbinding widget-class-list-style-properties (class)
+ (vector (copy-of param) n-properties)
+ ((type-class-peek class) pointer)
+ (n-properties unsigned-int :out))
+
+(defbinding widget-region-intersect () pointer ;gdk:region
+ (widget widget)
+ (region pointer)) ;gdk:region))
+
+(defbinding widget-send-expose () boolean
+ (widget widget)
+ (event gdk:event))
+
+(defbinding %widget-style-get-property () nil
+ (widget widget)
+ (name string)
+ (value gvalue))
+
+(defun style-property-value (widget style)
+ (let* ((name (string-downcase style))
+ (param (widget-class-find-style-property (class-of widget) name)))
+ (if (not param)
+ (error "~A has no such style property: ~A" widget style)
+ (with-gvalue (gvalue (param-value-type param))
+ (%widget-style-get-property widget (string-downcase style) gvalue)))))
+
+(defbinding widget-get-accessible () atk:object
+ (widget widget))
+
+(defbinding widget-child-focus () boolean
+ (widget widget)
+ (direction direction-type))
+
+(defbinding widget-child-notify () nil
+ (widget widget)
+ (child-property string))
+
+(defbinding widget-freeze-child-notify () nil
+ (widget widget))
+
+(defbinding widget-get-clipboard () clipboard
+ (widget widget)
+ (selection int #|gdk:atom|#))
+
+(defbinding widget-get-display () gdk:display
+ (widget widget))
+
+(defbinding widget-get-root-window () gdk:window
+ (widget widget))
+
+(defbinding widget-get-screen () gdk:screen
+ (widget widget))
+
+(defbinding widget-has-screen-p () boolean
+ (widget widget))
+
+(defbinding %widget-get-size-request () nil
+ (widget widget)
+ (width int :out)
+ (height int :out))
+
+(defun widget-get-size-request (widget)
+ (multiple-value-bind (width height) (%widget-get-size-request widget)
+ (values (unless (= width -1) width) (unless (= height -1) height))))
+
+(defbinding widget-set-size-request (widget width height) nil
+ (widget widget)
+ ((or width -1) int)
+ ((or height -1) int))
+
+(defbinding widget-thaw-child-notify () nil
+ (widget widget))
+
+(defbinding widget-list-mnemonic-labels () (glist widget)
+ (widget widget))
+
+(defbinding widget-add-mnemonic-label () nil
+ (widget widget)
+ (label widget))
+
+(defbinding widget-remove-mnemonic-label () nil
+ (widget widget)
+ (label widget))
+
+
+;;; Additional bindings and functions
+
+(defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean
+ (widget widget))
+
+(defbinding widget-get-size-allocation () nil
+ (widget widget)
+ (width int :out)
+ (height int :out))
+
+(defbinding get-event-widget () widget
+ (event gdk:event))
+
+(defun (setf widget-cursor) (cursor-type widget)
+ (warn "(SETF WIDGET-CURSOR) is deprecated, use WIDGET-SET-CURSOR instead")
+ (widget-set-cursor widget cursor-type))
+
+(defun widget-set-cursor (widget cursor &rest args)
+ (gdk:window-set-cursor (widget-window widget)
+ (apply #'gdk:ensure-cursor cursor args)))
+
+(defbinding %widget-get-parent-window () gdk:window