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.22 2006-04-25 20:19:32 espen Exp $
29 (defmethod print-object ((widget widget) stream)
31 (proxy-valid-p widget)
32 (slot-boundp widget 'name) (not (zerop (length (widget-name widget)))))
33 (print-unreadable-object (widget stream :type t :identity nil)
34 (format stream "~S at 0x~X"
35 (widget-name widget) (sap-int (foreign-location widget))))
38 (defmethod shared-initialize ((widget widget) names &key (visible nil visible-p))
39 (when (and visible-p (not visible)) ; widget explicit set as not visible
40 (setf (user-data widget 'hidden-p) t)
41 (signal-connect widget 'show
43 (unset-user-data widget 'hidden-p))
47 (defmethod shared-initialize :after ((widget widget) names &key parent visible)
48 (declare (ignore names))
52 (when (slot-boundp widget 'parent)
53 (container-remove (widget-parent widget) widget))
54 (destructuring-bind (parent &rest args) (mklist parent)
55 (apply #'container-add parent widget args))))
57 (defmethod slot-unbound ((class gobject-class) (object widget)
58 (slot (eql 'child-properties)))
60 ((slot-boundp object 'parent)
61 (with-slots (parent child-properties) object
62 (setf child-properties
64 (gethash (class-of parent) *container-to-child-class-mappings*)
65 :parent parent :child object))))
66 ((call-next-method))))
69 (defmethod compute-signal-function ((widget widget) signal function object)
70 (if (eq object :parent)
71 #'(lambda (&rest args)
72 (if (slot-boundp widget 'parent)
73 (apply function (widget-parent widget) (rest args))
74 ;; Delay until parent is set
75 (signal-connect widget 'parent-set
76 #'(lambda (old-parent)
77 (declare (ignore old-parent))
78 (let ((*signal-stop-emission*
80 (warn "Ignoring emission stop in delayed signal handler"))))
81 (apply function (widget-parent widget) (rest args))))
83 ; (warn "Widget has no parent -- ignoring signal")
87 (defun child-property-value (widget slot)
88 (slot-value (widget-child-properties widget) slot))
90 (defun (setf child-property-value) (value widget slot)
91 (setf (slot-value (widget-child-properties widget) slot) value))
93 (defmacro with-child-properties (slots widget &body body)
94 `(with-slots ,slots (widget-child-properties ,widget)
100 (defbinding widget-destroy () nil
103 (defbinding widget-unparent () nil
106 (defbinding widget-show () nil
109 (defbinding widget-show-now () nil
112 (defbinding widget-hide () nil
115 (defun widget-hidden-p (widget)
116 "Return T if WIDGET has been explicit hidden during construction."
117 (user-data widget 'hidden-p))
119 (defbinding widget-show-all () nil
122 (defbinding widget-hide-all () nil
125 (defbinding widget-map () nil
128 (defbinding widget-unmap () nil
131 (defbinding widget-realize () nil
134 (defbinding widget-unrealize () nil
137 (defbinding widget-queue-draw () nil
140 (defbinding widget-queue-resize () nil
143 (defbinding widget-queue-resize-no-redraw () nil
146 (defbinding widget-size-request
147 (widget &optional (requisition (make-instance 'requisition))) nil
149 (requisition requisition :return))
151 (defbinding widget-get-child-requisition
152 (widget &optional (requisition (make-instance 'requisition))) nil
154 (requisition requisition :return))
156 (defbinding widget-size-allocate () nil
158 (allocation allocation))
160 (defbinding widget-add-accelerator
161 (widget signal accel-group key modifiers flags) nil
163 ((signal-name-to-string signal) string)
164 (accel-group accel-group)
165 ((gdk:keyval-from-name key) unsigned-int)
166 (modifiers gdk:modifier-type)
169 (defbinding widget-remove-accelerator
170 (widget accel-group key modifiers) nil
172 (accel-group accel-group)
173 ((gdk:keyval-from-name key) unsigned-int)
174 (modifiers gdk:modifier-type))
176 (defbinding widget-set-accel-path () nil
179 (accel-group accel-group))
181 (defbinding widget-list-accel-closures () (glist pointer)
184 (defbinding widget-can-activate-accel-p () boolean
186 (signal-id unsigned-int))
188 (defbinding widget-event () boolean
192 (defbinding widget-activate () boolean
195 (defbinding widget-reparent () nil
199 (defbinding %widget-intersect () boolean
202 (intersection (or null gdk:rectangle)))
204 (defun widget-intersection (widget area)
205 (let ((intersection (make-instance 'gdk:rectangle)))
206 (when (%widget-intersect widget area intersection)
209 (defun widget-intersect-p (widget area)
210 (%widget-intersect widget area nil))
212 (defbinding widget-grab-focus () nil
215 (defbinding widget-grab-default () nil
218 (defbinding widget-add-events () nil
220 (events gdk:event-mask))
222 (defbinding widget-get-toplevel () widget
225 (defbinding widget-get-ancestor (widget type) widget
227 ((find-type-number type) type-number))
229 (defbinding widget-get-pointer () nil
234 (defbinding widget-is-ancestor-p () boolean
238 (defbinding widget-translate-coordinates () boolean
241 (src-x int) (src-y int)
242 (set-x int :out) (dest-y int :out))
244 (defun widget-hide-on-delete (widget)
245 "Utility function; intended to be connected to the DELETE-EVENT
246 signal on a WINDOW. The function calls WIDGET-HIDE on its
247 argument, then returns T. If connected to DELETE-EVENT, the
248 result is that clicking the close button for a window (on the window
249 frame, top right corner usually) will hide but not destroy the
250 window. By default, GTK+ destroys windows when DELETE-EVENT is
255 (defbinding widget-ensure-style () nil
258 (defbinding widget-reset-rc-styles () nil
261 (defbinding widget-push-colormap () nil
262 (colormap gdk:colormap))
264 (defbinding widget-pop-colormap () nil)
266 (defbinding %widget-set-default-colormap () nil
267 (colormap gdk:colormap))
269 (defun (setf widget-default-colormap) (colormap)
270 (%widget-set-default-colormap colormap)
273 (defbinding (widget-default-style "gtk_widget_get_default_style") () style)
275 (defbinding (widget-default-colromap "gtk_widget_get_default_colormap")
278 (defbinding (widget-default-visual "gtk_widget_get_default_visual")
281 (defbinding (widget-default-direction "gtk_widget_get_default_direction")
284 (defbinding %widget-set-default-direction () nil
285 (direction text-direction))
287 (defun (setf widget-default-direction) (direction)
288 (%widget-set-default-direction direction)
291 (defbinding widget-shape-combine-mask () nil
293 (shape-mask (or null gdk:bitmap))
297 (defbinding widget-path () nil
299 (path-length int :out)
301 (reverse-path string :out))
303 (defbinding widget-class-path () nil
305 (path-length int :out)
307 (reverse-path string :out))
309 (defbinding widget-modify-style () nil
313 (defbinding widget-get-modifier-style () rc-style
316 (defbinding widget-modify-fg () nil
321 (defbinding widget-modify-bg () nil
326 (defbinding widget-modify-text () nil
331 (defbinding widget-modify-base () nil
336 (defbinding widget-modify-font (widget font-desc) nil
338 ((etypecase font-desc
339 (pango:font-description font-desc)
340 (string (pango:font-description-from-string font-desc)))
341 pango:font-description))
343 (defbinding widget-create-pango-context () pango:context
346 (defbinding widget-get-pango-context () pango:context
349 (defbinding widget-create-pango-layout (widget &optional text) pango:layout
351 (text (or string null)))
353 (defbinding widget-render-icon (widget stock-id &optional size detail)
357 ((or size -1) (or icon-size int))
358 (detail (or null string)))
360 (defbinding widget-push-composite-child () nil)
362 (defbinding widget-pop-composite-child () nil)
364 (defbinding widget-queue-draw-area () nil
366 (x int) (y int) (width int) (height int))
368 (defbinding widget-reset-shapes () nil
371 ;; (defbinding widget-set-double-buffered () nil
373 ;; (double-buffered boolean))
375 ;; (defbinding widget-set-redraw-on-allocate () nil
377 ;; (redraw-on-allocate boolean))
379 (defbinding widget-set-scroll-adjustments () boolean
381 (hadjustment (or null adjustment))
382 (vadjustment (or null adjustment)))
384 (defbinding widget-mnemonic-activate () boolean
386 (group-cycling boolean))
388 (defbinding widget-class-find-style-property (class name) param
389 ((type-class-peek class) pointer)
392 (defbinding widget-class-list-style-properties (class)
393 (vector (copy-of param) n-properties)
394 ((type-class-peek class) pointer)
395 (n-properties unsigned-int :out))
397 (defbinding widget-region-intersect () pointer ;gdk:region
399 (region pointer)) ;gdk:region))
401 (defbinding widget-send-expose () boolean
405 (defbinding %widget-style-get-property () nil
410 (defun style-property-value (widget style)
411 (let* ((name (string-downcase style))
412 (param (widget-class-find-style-property (class-of widget) name)))
414 (error "~A has no such style property: ~A" widget style)
415 (with-gvalue (gvalue (param-value-type param))
416 (%widget-style-get-property widget (string-downcase style) gvalue)))))
418 (defbinding widget-get-accessible () atk:object
421 (defbinding widget-child-focus () boolean
423 (direction direction-type))
425 (defbinding widget-child-notify () nil
427 (child-property string))
429 (defbinding widget-freeze-child-notify () nil
432 (defbinding widget-get-clipboard () clipboard
434 (selection int #|gdk:atom|#))
436 (defbinding widget-get-display () gdk:display
439 (defbinding widget-get-root-window () gdk:window
442 (defbinding widget-get-screen () gdk:screen
445 (defbinding widget-has-screen-p () boolean
448 (defbinding %widget-get-size-request () nil
453 (defun widget-get-size-request (widget)
454 (multiple-value-bind (width height) (%widget-get-size-request widget)
455 (values (unless (= width -1) width) (unless (= height -1) height))))
457 (defbinding widget-set-size-request (widget width height) nil
460 ((or height -1) int))
462 (defbinding widget-thaw-child-notify () nil
465 (defbinding widget-list-mnemonic-labels () (glist widget)
468 (defbinding widget-add-mnemonic-label () nil
472 (defbinding widget-remove-mnemonic-label () nil
477 ;;; Additional bindings and functions
479 (defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean
482 (defbinding widget-get-size-allocation () nil
487 (defbinding get-event-widget () widget
490 (defun (setf widget-cursor) (cursor-type widget)
491 (warn "(SETF WIDGET-CURSOR) is deprecated, use WIDGET-SET-CURSOR instead")
492 (widget-set-cursor widget cursor-type))
494 (defun widget-set-cursor (widget cursor &rest args)
495 (gdk:window-set-cursor (widget-window widget)
496 (apply #'gdk:ensure-cursor cursor args)))
498 (defbinding %widget-get-parent-window () gdk:window
501 (defun %widget-parent-window (widget)
502 (when (slot-boundp widget 'parent)
503 (%widget-get-parent-window widget)))