1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2000-2002 Espen S. Johnsen <espen@users.sourceforge.net>
4 ;; This library is free software; you can redistribute it and/or
5 ;; modify it under the terms of the GNU Lesser General Public
6 ;; License as published by the Free Software Foundation; either
7 ;; version 2 of the License, or (at your option) any later version.
9 ;; This library is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;; Lesser General Public License for more details.
14 ;; You should have received a copy of the GNU Lesser General Public
15 ;; License along with this library; if not, write to the Free Software
16 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ;; $Id: gtkwidget.lisp,v 1.16 2005-02-22 23:12:06 espen Exp $
23 (defmethod shared-initialize ((widget widget) names &key (visible nil visible-p))
24 (when (and visible-p (not visible)) ; widget explicit set as not visible
25 (setf (user-data widget 'hidden-p) t)
26 (signal-connect widget 'show
28 (unset-user-data widget 'hidden-p))
32 (defmethod shared-initialize :after ((widget widget) names &key parent)
33 (declare (ignore names))
35 (when (slot-boundp widget 'parent)
36 (container-remove (widget-parent widget) widget))
37 (destructuring-bind (parent &rest args) (mklist parent)
38 (apply #'container-add parent widget args))))
40 (defmethod slot-unbound ((class gobject-class) (object widget)
41 (slot (eql 'child-properties)))
43 ((slot-boundp object 'parent)
44 (with-slots (parent child-properties) object
45 (setf child-properties
47 (gethash (class-of parent) *container-to-child-class-mappings*)
48 :parent parent :child object))))
49 ((call-next-method))))
51 (defmethod slot-boundp-using-class ((class gobject-class) (object widget) slot)
54 (eq (slot-definition-name slot) 'child-properties)
55 (slot-boundp object 'parent))
58 (defmethod compute-signal-function ((widget widget) signal function object)
59 (if (eq object :parent)
60 #'(lambda (&rest args)
61 (if (slot-boundp widget 'parent)
62 (apply function (widget-parent widget) (rest args))
63 ;; Delay until parent is set
64 (signal-connect widget 'parent-set
65 #'(lambda (old-parent)
66 (declare (ignore old-parent))
67 (let ((*signal-stop-emission*
69 (warn "Ignoring emission stop in delayed signal handler"))))
70 (apply function (widget-parent widget) (rest args))))
72 ; (warn "Widget has no parent -- ignoring signal")
76 (defun child-property-value (widget slot)
77 (slot-value (widget-child-properties widget) slot))
79 (defun (setf child-property-value) (value widget slot)
80 (setf (slot-value (widget-child-properties widget) slot) value))
82 (defmacro with-child-properties (slots widget &body body)
83 `(with-slots ,slots (widget-child-properties ,widget)
89 (defbinding widget-destroy () nil
92 (defbinding widget-unparent () nil
95 (defbinding widget-show () nil
98 (defbinding widget-show-now () nil
101 (defbinding widget-hide () nil
104 (defun widget-hidden-p (widget)
105 "Return T if WIDGET has been explicit hidden during construction."
106 (user-data widget 'hidden-p))
108 (defbinding widget-show-all () nil
111 (defbinding widget-hide-all () nil
114 (defbinding widget-map () nil
117 (defbinding widget-unmap () nil
120 (defbinding widget-realize () nil
123 (defbinding widget-unrealize () nil
126 (defbinding widget-queue-draw () nil
129 (defbinding widget-queue-resize () nil
132 (defbinding widget-queue-resize-no-redraw () nil
135 (defbinding widget-size-request
136 (widget &optional (requisition (make-instance 'requisition))) nil
138 (requisition requisition :return))
140 (defbinding widget-get-child-requisition
141 (widget &optional (requisition (make-instance 'requisition))) nil
143 (requisition requisition :return))
145 (defbinding widget-size-allocate () nil
147 (allocation allocation))
149 (defbinding widget-add-accelerator
150 (widget signal accel-group key modifiers flags) nil
152 ((name-to-string signal) string)
153 (accel-group accel-group)
154 ((gdk:keyval-from-name key) unsigned-int)
155 (modifiers gdk:modifier-type)
158 (defbinding widget-remove-accelerator
159 (widget accel-group key modifiers) nil
161 (accel-group accel-group)
162 ((gdk:keyval-from-name key) unsigned-int)
163 (modifiers gdk:modifier-type))
165 (defbinding widget-set-accel-path () nil
168 (accel-group accel-group))
170 (defbinding widget-list-accel-closures () (glist pointer)
173 (defbinding widget-can-activate-accel-p () boolean
175 (signal-id unsigned-int))
177 (defbinding widget-event () boolean
181 (defbinding widget-activate () boolean
184 (defbinding widget-reparent () nil
188 (defbinding %widget-intersect () boolean
191 (intersection (or null gdk:rectangle)))
193 (defun widget-intersection (widget area)
194 (let ((intersection (make-instance 'gdk:rectangle)))
195 (when (%widget-intersect widget area intersection)
198 (defun widget-intersect-p (widget area)
199 (%widget-intersect widget area nil))
201 (defbinding widget-grab-focus () nil
204 (defbinding widget-grab-default () nil
207 (defbinding widget-add-events () nil
209 (events gdk:event-mask))
211 (defbinding widget-get-toplevel () widget
214 (defbinding widget-get-ancestor (widget type) widget
216 ((find-type-number type) type-number))
218 (defbinding widget-get-pointer () nil
223 (defbinding widget-is-ancestor-p () boolean
227 (defbinding widget-translate-coordinates () boolean
230 (src-x int) (src-y int)
231 (set-x int :out) (dest-y int :out))
233 (defun widget-hide-on-delete (widget)
234 "Utility function; intended to be connected to the DELETE-EVENT
235 signal on a WINDOW. The function calls WIDGET-HIDE on its
236 argument, then returns T. If connected to DELETE-EVENT, the
237 result is that clicking the close button for a window (on the window
238 frame, top right corner usually) will hide but not destroy the
239 window. By default, GTK+ destroys windows when DELETE-EVENT is
244 (defbinding widget-ensure-style () nil
247 (defbinding widget-reset-rc-styles () nil
250 (defbinding widget-push-colormap () nil
251 (colormap gdk:colormap))
253 (defbinding widget-pop-colormap () nil)
255 (defbinding %widget-set-default-colormap () nil
256 (colormap gdk:colormap))
258 (defun (setf widget-default-colormap) (colormap)
259 (%widget-set-default-colormap colormap)
262 (defbinding (widget-default-style "gtk_widget_get_default_style") () style)
264 (defbinding (widget-default-colromap "gtk_widget_get_default_colormap")
267 (defbinding (widget-default-visual "gtk_widget_get_default_visual")
270 (defbinding (widget-default-direction "gtk_widget_get_default_direction")
273 (defbinding %widget-set-default-direction () nil
274 (direction text-direction))
276 (defun (setf widget-default-direction) (direction)
277 (%widget-set-default-direction direction)
280 (defbinding widget-shape-combine-mask () nil
282 (shape-mask (or null gdk:bitmap))
286 (defbinding widget-path () nil
288 (path-length int :out)
290 (reverse-path string :out))
292 (defbinding widget-class-path () nil
294 (path-length int :out)
296 (reverse-path string :out))
298 (defbinding widget-modify-style () nil
302 (defbinding widget-get-modifier-style () rc-style
305 (defbinding widget-modify-fg () nil
310 (defbinding widget-modify-bg () nil
315 (defbinding widget-modify-text () nil
320 (defbinding widget-modify-base () nil
325 (defbinding widget-modify-font () nil
328 (font-desc pango:font-description))
330 (defbinding widget-create-pango-context () pango:context
333 (defbinding widget-get-pango-context () pango:context
336 (defbinding widget-create-pango-layout (widget &optional text) pango:layout
338 (text (or string null)))
340 (defbinding widget-render-icon (widget stock-id &optional size detail)
344 ((or size -1) (or icon-size int))
345 (detail (or null string)))
347 (defbinding widget-push-composite-child () nil)
349 (defbinding widget-pop-composite-child () nil)
351 (defbinding widget-queue-draw-area () nil
353 (x int) (y int) (width int) (height int))
355 (defbinding widget-reset-shapes () nil
358 ;; (defbinding widget-set-double-buffered () nil
360 ;; (double-buffered boolean))
362 ;; (defbinding widget-set-redraw-on-allocate () nil
364 ;; (redraw-on-allocate boolean))
366 (defbinding widget-set-scroll-adjustments () boolean
368 (hadjustment (or null adjustment))
369 (vadjustment (or null adjustment)))
371 (defbinding widget-mnemonic-activate () boolean
373 (group-cycling boolean))
375 (defbinding widget-class-find-style-property (class name) param
376 ((type-class-peek class) pointer)
379 (defbinding widget-class-list-style-properties (class)
380 (vector (copy-of param) n-properties)
381 ((type-class-peek class) pointer)
382 (n-properties unsigned-int :out))
384 (defbinding widget-region-intersect () pointer ;gdk:region
386 (region pointer)) ;gdk:region))
388 (defbinding widget-send-expose () boolean
392 (defbinding %widget-style-get-property () nil
397 (defun style-property-value (widget style)
398 (let* ((name (string-downcase style))
399 (param (widget-class-find-style-property (class-of widget) name)))
401 (error "~A has no such style property: ~A" widget style)
402 (with-gvalue (gvalue (param-value-type param))
403 (%widget-style-get-property widget (string-downcase style) gvalue)))))
405 (defbinding widget-get-accessible () atk:object
408 (defbinding widget-child-focus () boolean
410 (direction direction-type))
412 (defbinding widget-child-notify () nil
414 (child-property string))
416 (defbinding widget-freeze-child-notify () nil
419 (defbinding widget-get-clipboard () clipboard
421 (selection int #|gdk:atom|#))
423 (defbinding widget-get-display () gdk:display
426 (defbinding widget-get-root-window () gdk:window
429 (defbinding widget-get-screen () gdk:screen
432 (defbinding widget-has-screen-p () boolean
435 (defbinding %widget-get-size-request () nil
440 (defun widget-get-size-request (widget)
441 (multiple-value-bind (width height) (%widget-get-size-request widget)
442 (values (unless (= width -1) width) (unless (= height -1) height))))
444 (defbinding widget-set-size-request (widget width height) nil
447 ((or height -1) int))
449 (defbinding widget-thaw-child-notify () nil
452 (defbinding widget-list-mnemonic-labels () (glist widget)
455 (defbinding widget-add-mnemonic-label () nil
459 (defbinding widget-remove-mnemonic-label () nil
464 ;;; Additional bindings and functions
466 (defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean
469 (defbinding widget-get-size-allocation () nil
474 (defbinding get-event-widget () widget
477 (defun (setf widget-cursor) (cursor-type widget)
478 (let ((cursor (make-instance 'gdk:cursor :type cursor-type)))
479 (gdk:window-set-cursor (widget-window widget) cursor)))
481 (defbinding %widget-get-parent-window () gdk:window
484 (defun %widget-parent-window (widget)
485 (when (slot-boundp widget 'parent)
486 (%widget-get-parent-window widget)))