1 ;; Common Lisp bindings for GTK+ v2.x
2 ;; Copyright 2000-2006 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.23 2006-04-26 12:11:21 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) (pointer-address (foreign-location widget))))
38 (defmethod shared-initialize ((widget widget) names &key (visible nil visible-p))
39 (declare (ignore names))
40 (when (and visible-p (not visible)) ; widget explicit set as not visible
41 (setf (user-data widget 'hidden-p) t)
42 (signal-connect widget 'show
44 (unset-user-data widget 'hidden-p))
48 (defmethod shared-initialize :after ((widget widget) names &key parent visible)
49 (declare (ignore names))
53 (when (slot-boundp widget 'parent)
54 (container-remove (widget-parent widget) widget))
55 (destructuring-bind (parent &rest args) (mklist parent)
56 (apply #'container-add parent widget args))))
58 (defmethod slot-unbound ((class gobject-class) (object widget)
59 (slot (eql 'child-properties)))
61 ((slot-boundp object 'parent)
62 (with-slots (parent child-properties) object
63 (setf child-properties
65 (gethash (class-of parent) *container-to-child-class-mappings*)
66 :parent parent :child object))))
67 ((call-next-method))))
70 (defmethod compute-signal-function ((widget widget) signal function object)
71 (declare (ignore signal))
72 (if (eq object :parent)
73 #'(lambda (&rest args)
74 (if (slot-boundp widget 'parent)
75 (apply function (widget-parent widget) (rest args))
76 ;; Delay until parent is set
77 (signal-connect widget 'parent-set
78 #'(lambda (old-parent)
79 (declare (ignore old-parent))
80 (let ((*signal-stop-emission*
82 (warn "Ignoring emission stop in delayed signal handler"))))
83 (apply function (widget-parent widget) (rest args))))
85 ; (warn "Widget has no parent -- ignoring signal")
89 (defun child-property-value (widget slot)
90 (slot-value (widget-child-properties widget) slot))
92 (defun (setf child-property-value) (value widget slot)
93 (setf (slot-value (widget-child-properties widget) slot) value))
95 (defmacro with-child-properties (slots widget &body body)
96 `(with-slots ,slots (widget-child-properties ,widget)
102 (defbinding widget-destroy () nil
105 (defbinding widget-unparent () nil
108 (defbinding widget-show () nil
111 (defbinding widget-show-now () nil
114 (defbinding widget-hide () nil
117 (defun widget-hidden-p (widget)
118 "Return T if WIDGET has been explicit hidden during construction."
119 (user-data widget 'hidden-p))
121 (defbinding widget-show-all () nil
124 (defbinding widget-hide-all () nil
127 (defbinding widget-map () nil
130 (defbinding widget-unmap () nil
133 (defbinding widget-realize () nil
136 (defbinding widget-unrealize () nil
139 (defbinding widget-queue-draw () nil
142 (defbinding widget-queue-resize () nil
145 (defbinding widget-queue-resize-no-redraw () nil
148 (defbinding widget-size-request
149 (widget &optional (requisition (make-instance 'requisition))) nil
151 (requisition requisition :in/return))
153 (defbinding widget-get-child-requisition
154 (widget &optional (requisition (make-instance 'requisition))) nil
156 (requisition requisition :in/return))
158 (defbinding widget-size-allocate () nil
160 (allocation allocation))
162 (defbinding widget-add-accelerator
163 (widget signal accel-group key modifiers flags) nil
165 ((signal-name-to-string signal) string)
166 (accel-group accel-group)
167 ((gdk:keyval-from-name key) unsigned-int)
168 (modifiers gdk:modifier-type)
171 (defbinding widget-remove-accelerator
172 (widget accel-group key modifiers) nil
174 (accel-group accel-group)
175 ((gdk:keyval-from-name key) unsigned-int)
176 (modifiers gdk:modifier-type))
178 (defbinding widget-set-accel-path () nil
181 (accel-group accel-group))
183 (defbinding widget-list-accel-closures () (glist pointer)
186 (defbinding widget-can-activate-accel-p () boolean
188 (signal-id unsigned-int))
190 (defbinding widget-event () boolean
194 (defbinding widget-activate () boolean
197 (defbinding widget-reparent () nil
201 (defbinding %widget-intersect () boolean
204 (intersection (or null gdk:rectangle)))
206 (defun widget-intersection (widget area)
207 (let ((intersection (make-instance 'gdk:rectangle)))
208 (when (%widget-intersect widget area intersection)
211 (defun widget-intersect-p (widget area)
212 (%widget-intersect widget area nil))
214 (defbinding widget-grab-focus () nil
217 (defbinding widget-grab-default () nil
220 (defbinding widget-add-events () nil
222 (events gdk:event-mask))
224 (defbinding widget-get-toplevel () widget
227 (defbinding widget-get-ancestor (widget type) widget
229 ((find-type-number type) type-number))
231 (defbinding widget-get-pointer () nil
236 (defbinding widget-is-ancestor-p () boolean
240 (defbinding widget-translate-coordinates () boolean
243 (src-x int) (src-y int)
244 (set-x int :out) (dest-y int :out))
246 (defun widget-hide-on-delete (widget)
247 "Utility function; intended to be connected to the DELETE-EVENT
248 signal on a WINDOW. The function calls WIDGET-HIDE on its
249 argument, then returns T. If connected to DELETE-EVENT, the
250 result is that clicking the close button for a window (on the window
251 frame, top right corner usually) will hide but not destroy the
252 window. By default, GTK+ destroys windows when DELETE-EVENT is
257 (defbinding widget-ensure-style () nil
260 (defbinding widget-reset-rc-styles () nil
263 (defbinding widget-push-colormap () nil
264 (colormap gdk:colormap))
266 (defbinding widget-pop-colormap () nil)
268 (defbinding %widget-set-default-colormap () nil
269 (colormap gdk:colormap))
271 (defun (setf widget-default-colormap) (colormap)
272 (%widget-set-default-colormap colormap)
275 (defbinding (widget-default-style "gtk_widget_get_default_style") () style)
277 (defbinding (widget-default-colromap "gtk_widget_get_default_colormap")
280 (defbinding (widget-default-visual "gtk_widget_get_default_visual")
283 (defbinding (widget-default-direction "gtk_widget_get_default_direction")
286 (defbinding %widget-set-default-direction () nil
287 (direction text-direction))
289 (defun (setf widget-default-direction) (direction)
290 (%widget-set-default-direction direction)
293 (defbinding widget-shape-combine-mask () nil
295 (shape-mask (or null gdk:bitmap))
299 (defbinding widget-path () nil
301 (path-length int :out)
303 (reverse-path string :out))
305 (defbinding widget-class-path () nil
307 (path-length int :out)
309 (reverse-path string :out))
311 (defbinding widget-modify-style () nil
315 (defbinding widget-get-modifier-style () rc-style
318 (defbinding widget-modify-fg () nil
323 (defbinding widget-modify-bg () nil
328 (defbinding widget-modify-text () nil
333 (defbinding widget-modify-base () nil
338 (defbinding widget-modify-font (widget font-desc) nil
340 ((etypecase font-desc
341 (pango:font-description font-desc)
342 (string (pango:font-description-from-string font-desc)))
343 pango:font-description))
345 (defbinding widget-create-pango-context () pango:context
348 (defbinding widget-get-pango-context () pango:context
351 (defbinding widget-create-pango-layout (widget &optional text) pango:layout
353 (text (or string null)))
355 (defbinding widget-render-icon (widget stock-id &optional size detail)
359 ((or size -1) (or icon-size int))
360 (detail (or null string)))
362 (defbinding widget-push-composite-child () nil)
364 (defbinding widget-pop-composite-child () nil)
366 (defbinding widget-queue-draw-area () nil
368 (x int) (y int) (width int) (height int))
370 (defbinding widget-reset-shapes () nil
373 ;; (defbinding widget-set-double-buffered () nil
375 ;; (double-buffered boolean))
377 ;; (defbinding widget-set-redraw-on-allocate () nil
379 ;; (redraw-on-allocate boolean))
381 (defbinding widget-set-scroll-adjustments () boolean
383 (hadjustment (or null adjustment))
384 (vadjustment (or null adjustment)))
386 (defbinding widget-mnemonic-activate () boolean
388 (group-cycling boolean))
390 (defbinding widget-class-find-style-property (class name) param
391 ((type-class-peek class) pointer)
394 (defbinding widget-class-list-style-properties (class)
395 (vector (copy-of param) n-properties)
396 ((type-class-peek class) pointer)
397 (n-properties unsigned-int :out))
399 (defbinding widget-region-intersect () pointer ;gdk:region
401 (region pointer)) ;gdk:region))
403 (defbinding widget-send-expose () boolean
407 (defbinding %widget-style-get-property () nil
412 (defun style-property-value (widget style)
413 (let* ((name (string-downcase style))
414 (param (widget-class-find-style-property (class-of widget) name)))
416 (error "~A has no such style property: ~A" widget style)
417 (with-gvalue (gvalue (param-value-type param))
418 (%widget-style-get-property widget (string-downcase style) gvalue)))))
420 (defbinding widget-get-accessible () atk:object
423 (defbinding widget-child-focus () boolean
425 (direction direction-type))
427 (defbinding widget-child-notify () nil
429 (child-property string))
431 (defbinding widget-freeze-child-notify () nil
434 (defbinding widget-get-clipboard () clipboard
436 (selection int #|gdk:atom|#))
438 (defbinding widget-get-display () gdk:display
441 (defbinding widget-get-root-window () gdk:window
444 (defbinding widget-get-screen () gdk:screen
447 (defbinding widget-has-screen-p () boolean
450 (defbinding %widget-get-size-request () nil
455 (defun widget-get-size-request (widget)
456 (multiple-value-bind (width height) (%widget-get-size-request widget)
457 (values (unless (= width -1) width) (unless (= height -1) height))))
459 (defbinding widget-set-size-request (widget width height) nil
462 ((or height -1) int))
464 (defbinding widget-thaw-child-notify () nil
467 (defbinding widget-list-mnemonic-labels () (glist widget)
470 (defbinding widget-add-mnemonic-label () nil
474 (defbinding widget-remove-mnemonic-label () nil
479 ;;; Additional bindings and functions
481 (defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean
484 (defbinding widget-get-size-allocation () nil
489 (defbinding get-event-widget () widget
492 (defun (setf widget-cursor) (cursor-type widget)
493 (warn "(SETF WIDGET-CURSOR) is deprecated, use WIDGET-SET-CURSOR instead")
494 (widget-set-cursor widget cursor-type))
496 (defun widget-set-cursor (widget cursor &rest args)
497 (gdk:window-set-cursor (widget-window widget)
498 (apply #'gdk:ensure-cursor cursor args)))
500 (defbinding %widget-get-parent-window () gdk:window
503 (defun %widget-parent-window (widget)
504 (when (slot-boundp widget 'parent)
505 (%widget-get-parent-window widget)))