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.19 2006-02-08 22:00:09 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))))
59 (defmethod compute-signal-function ((widget widget) signal function object)
60 (if (eq object :parent)
61 #'(lambda (&rest args)
62 (if (slot-boundp widget 'parent)
63 (apply function (widget-parent widget) (rest args))
64 ;; Delay until parent is set
65 (signal-connect widget 'parent-set
66 #'(lambda (old-parent)
67 (declare (ignore old-parent))
68 (let ((*signal-stop-emission*
70 (warn "Ignoring emission stop in delayed signal handler"))))
71 (apply function (widget-parent widget) (rest args))))
73 ; (warn "Widget has no parent -- ignoring signal")
77 (defun child-property-value (widget slot)
78 (slot-value (widget-child-properties widget) slot))
80 (defun (setf child-property-value) (value widget slot)
81 (setf (slot-value (widget-child-properties widget) slot) value))
83 (defmacro with-child-properties (slots widget &body body)
84 `(with-slots ,slots (widget-child-properties ,widget)
90 (defbinding widget-destroy () nil
93 (defbinding widget-unparent () nil
96 (defbinding widget-show () nil
99 (defbinding widget-show-now () nil
102 (defbinding widget-hide () nil
105 (defun widget-hidden-p (widget)
106 "Return T if WIDGET has been explicit hidden during construction."
107 (user-data widget 'hidden-p))
109 (defbinding widget-show-all () nil
112 (defbinding widget-hide-all () nil
115 (defbinding widget-map () nil
118 (defbinding widget-unmap () nil
121 (defbinding widget-realize () nil
124 (defbinding widget-unrealize () nil
127 (defbinding widget-queue-draw () nil
130 (defbinding widget-queue-resize () nil
133 (defbinding widget-queue-resize-no-redraw () nil
136 (defbinding widget-size-request
137 (widget &optional (requisition (make-instance 'requisition))) nil
139 (requisition requisition :return))
141 (defbinding widget-get-child-requisition
142 (widget &optional (requisition (make-instance 'requisition))) nil
144 (requisition requisition :return))
146 (defbinding widget-size-allocate () nil
148 (allocation allocation))
150 (defbinding widget-add-accelerator
151 (widget signal accel-group key modifiers flags) nil
153 ((name-to-string signal) string)
154 (accel-group accel-group)
155 ((gdk:keyval-from-name key) unsigned-int)
156 (modifiers gdk:modifier-type)
159 (defbinding widget-remove-accelerator
160 (widget accel-group key modifiers) nil
162 (accel-group accel-group)
163 ((gdk:keyval-from-name key) unsigned-int)
164 (modifiers gdk:modifier-type))
166 (defbinding widget-set-accel-path () nil
169 (accel-group accel-group))
171 (defbinding widget-list-accel-closures () (glist pointer)
174 (defbinding widget-can-activate-accel-p () boolean
176 (signal-id unsigned-int))
178 (defbinding widget-event () boolean
182 (defbinding widget-activate () boolean
185 (defbinding widget-reparent () nil
189 (defbinding %widget-intersect () boolean
192 (intersection (or null gdk:rectangle)))
194 (defun widget-intersection (widget area)
195 (let ((intersection (make-instance 'gdk:rectangle)))
196 (when (%widget-intersect widget area intersection)
199 (defun widget-intersect-p (widget area)
200 (%widget-intersect widget area nil))
202 (defbinding widget-grab-focus () nil
205 (defbinding widget-grab-default () nil
208 (defbinding widget-add-events () nil
210 (events gdk:event-mask))
212 (defbinding widget-get-toplevel () widget
215 (defbinding widget-get-ancestor (widget type) widget
217 ((find-type-number type) type-number))
219 (defbinding widget-get-pointer () nil
224 (defbinding widget-is-ancestor-p () boolean
228 (defbinding widget-translate-coordinates () boolean
231 (src-x int) (src-y int)
232 (set-x int :out) (dest-y int :out))
234 (defun widget-hide-on-delete (widget)
235 "Utility function; intended to be connected to the DELETE-EVENT
236 signal on a WINDOW. The function calls WIDGET-HIDE on its
237 argument, then returns T. If connected to DELETE-EVENT, the
238 result is that clicking the close button for a window (on the window
239 frame, top right corner usually) will hide but not destroy the
240 window. By default, GTK+ destroys windows when DELETE-EVENT is
245 (defbinding widget-ensure-style () nil
248 (defbinding widget-reset-rc-styles () nil
251 (defbinding widget-push-colormap () nil
252 (colormap gdk:colormap))
254 (defbinding widget-pop-colormap () nil)
256 (defbinding %widget-set-default-colormap () nil
257 (colormap gdk:colormap))
259 (defun (setf widget-default-colormap) (colormap)
260 (%widget-set-default-colormap colormap)
263 (defbinding (widget-default-style "gtk_widget_get_default_style") () style)
265 (defbinding (widget-default-colromap "gtk_widget_get_default_colormap")
268 (defbinding (widget-default-visual "gtk_widget_get_default_visual")
271 (defbinding (widget-default-direction "gtk_widget_get_default_direction")
274 (defbinding %widget-set-default-direction () nil
275 (direction text-direction))
277 (defun (setf widget-default-direction) (direction)
278 (%widget-set-default-direction direction)
281 (defbinding widget-shape-combine-mask () nil
283 (shape-mask (or null gdk:bitmap))
287 (defbinding widget-path () nil
289 (path-length int :out)
291 (reverse-path string :out))
293 (defbinding widget-class-path () nil
295 (path-length int :out)
297 (reverse-path string :out))
299 (defbinding widget-modify-style () nil
303 (defbinding widget-get-modifier-style () rc-style
306 (defbinding widget-modify-fg () nil
311 (defbinding widget-modify-bg () nil
316 (defbinding widget-modify-text () nil
321 (defbinding widget-modify-base () nil
326 (defbinding widget-modify-font () nil
329 (font-desc pango:font-description))
331 (defbinding widget-create-pango-context () pango:context
334 (defbinding widget-get-pango-context () pango:context
337 (defbinding widget-create-pango-layout (widget &optional text) pango:layout
339 (text (or string null)))
341 (defbinding widget-render-icon (widget stock-id &optional size detail)
345 ((or size -1) (or icon-size int))
346 (detail (or null string)))
348 (defbinding widget-push-composite-child () nil)
350 (defbinding widget-pop-composite-child () nil)
352 (defbinding widget-queue-draw-area () nil
354 (x int) (y int) (width int) (height int))
356 (defbinding widget-reset-shapes () nil
359 ;; (defbinding widget-set-double-buffered () nil
361 ;; (double-buffered boolean))
363 ;; (defbinding widget-set-redraw-on-allocate () nil
365 ;; (redraw-on-allocate boolean))
367 (defbinding widget-set-scroll-adjustments () boolean
369 (hadjustment (or null adjustment))
370 (vadjustment (or null adjustment)))
372 (defbinding widget-mnemonic-activate () boolean
374 (group-cycling boolean))
376 (defbinding widget-class-find-style-property (class name) param
377 ((type-class-peek class) pointer)
380 (defbinding widget-class-list-style-properties (class)
381 (vector (copy-of param) n-properties)
382 ((type-class-peek class) pointer)
383 (n-properties unsigned-int :out))
385 (defbinding widget-region-intersect () pointer ;gdk:region
387 (region pointer)) ;gdk:region))
389 (defbinding widget-send-expose () boolean
393 (defbinding %widget-style-get-property () nil
398 (defun style-property-value (widget style)
399 (let* ((name (string-downcase style))
400 (param (widget-class-find-style-property (class-of widget) name)))
402 (error "~A has no such style property: ~A" widget style)
403 (with-gvalue (gvalue (param-value-type param))
404 (%widget-style-get-property widget (string-downcase style) gvalue)))))
406 (defbinding widget-get-accessible () atk:object
409 (defbinding widget-child-focus () boolean
411 (direction direction-type))
413 (defbinding widget-child-notify () nil
415 (child-property string))
417 (defbinding widget-freeze-child-notify () nil
420 (defbinding widget-get-clipboard () clipboard
422 (selection int #|gdk:atom|#))
424 (defbinding widget-get-display () gdk:display
427 (defbinding widget-get-root-window () gdk:window
430 (defbinding widget-get-screen () gdk:screen
433 (defbinding widget-has-screen-p () boolean
436 (defbinding %widget-get-size-request () nil
441 (defun widget-get-size-request (widget)
442 (multiple-value-bind (width height) (%widget-get-size-request widget)
443 (values (unless (= width -1) width) (unless (= height -1) height))))
445 (defbinding widget-set-size-request (widget width height) nil
448 ((or height -1) int))
450 (defbinding widget-thaw-child-notify () nil
453 (defbinding widget-list-mnemonic-labels () (glist widget)
456 (defbinding widget-add-mnemonic-label () nil
460 (defbinding widget-remove-mnemonic-label () nil
465 ;;; Additional bindings and functions
467 (defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean
470 (defbinding widget-get-size-allocation () nil
475 (defbinding get-event-widget () widget
478 (defun (setf widget-cursor) (cursor-type widget)
479 (let ((cursor (make-instance 'gdk:cursor :type cursor-type)))
480 (gdk:window-set-cursor (widget-window widget) cursor)))
482 (defbinding %widget-get-parent-window () gdk:window
485 (defun %widget-parent-window (widget)
486 (when (slot-boundp widget 'parent)
487 (%widget-get-parent-window widget)))