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.10 2004-11-06 21:39:58 espen Exp $
23 (defmethod shared-initialize ((widget widget) names &rest initargs &key parent)
24 (remf initargs :parent)
26 (apply #'call-next-method widget names initargs)
28 (let ((old-parent (widget-parent widget))
29 (parent (first (mklist parent)))
30 (args (rest (mklist parent))))
32 (container-remove old-parent widget))
33 (apply #'container-add parent widget args)))))
35 (defmethod shared-initialize :after ((widget widget) names &rest initargs
37 (declare (ignore initargs names))
39 (widget-show-all widget)))
42 (defmethod slot-unbound ((class gobject-class) (object widget) slot)
44 ((and (eq slot 'child-slots) (slot-value object 'parent))
45 (with-slots (parent child-slots) object
49 (gethash (class-of parent) *container-to-child-class-mappings*)
50 :parent parent :child object))))
51 (t (call-next-method))))
54 (defun child-slot-value (widget slot)
55 (slot-value (widget-child-slots widget) slot))
57 (defun (setf child-slot-value) (value widget slot)
58 (setf (slot-value (widget-child-slots widget) slot) value))
60 (defmacro with-child-slots (slots widget &body body)
61 `(with-slots ,slots (widget-child-slots ,widget)
65 (defmacro widget-destroyed (place)
71 (defbinding widget-destroy () nil
74 (defbinding widget-unparent () nil
77 (defbinding widget-show () nil
80 (defbinding widget-show-now () nil
83 (defbinding widget-hide () nil
86 (defbinding widget-show-all () nil
89 (defbinding widget-hide-all () nil
92 (defbinding widget-map () nil
95 (defbinding widget-unmap () nil
98 (defbinding widget-realize () nil
101 (defbinding widget-unrealize () nil
104 (defbinding widget-queue-draw () nil
107 (defbinding widget-queue-resize () nil
110 (defbinding widget-size-request () nil
112 (requisition requisition))
114 (defbinding widget-get-child-requisition () nil
116 (requisition requisition))
118 (defbinding widget-size-allocate () nil
120 (allocation allocation))
123 (defbinding widget-add-accelerator
124 (widget signal accel-group key modifiers flags) nil
126 ((name-to-string signal) string)
127 (accel-group accel-group)
128 ((gdk:keyval-from-name key) unsigned-int)
129 (modifiers gdk:modifier-type)
132 (defbinding widget-remove-accelerator
133 (widget accel-group key modifiers) nil
135 (accel-group accel-group)
136 ((gdk:keyval-from-name key) unsigned-int)
137 (modifiers gdk:modifier-type))
139 (defbinding (widget-set-accelerator-path "gtk_widget_set_accel_path") () nil
142 (accel-group accel-group))
145 (defbinding widget-event () int
149 (defbinding widget-activate () boolean
152 (defbinding widget-reparent () nil
156 (defbinding %widget-intersect () boolean
159 (intersection pointer))
162 (defun widget-intersection (widget area)
163 (let ((intersection (make-instance 'gdk:rectangle)))
164 (when (%widget-intersect widget area intersection)
167 (defun widget-intersect-p (widget area)
168 (%widget-intersect widget area (make-pointer 0)))
170 (defbinding (widget-is-focus-p "gtk_widget_is_focus") () boolean
173 (defbinding widget-grab-focus () nil
176 (defbinding widget-grab-default () nil
179 (defbinding widget-add-events () nil
181 (events gdk:event-mask))
183 (defbinding widget-get-toplevel () widget
186 (defbinding widget-get-ancestor (widget type) widget
188 ((find-type-number type) type-number))
190 (defbinding widget-get-pointer () nil
195 (defbinding (widget-is-ancestor-p "gtk_widget_is_ancestor") () boolean
199 (defbinding widget-translate-coordinates () boolean
202 (src-x int) (src-y int)
203 (set-x int :out) (dest-y int :out))
205 (defun widget-hide-on-delete (widget)
206 "Utility function; intended to be connected to the DELETE-EVENT
207 signal on a GtkWindow. The function calls WIDGET-HIDE on its
208 argument, then returns T. If connected to DELETE-EVENT, the
209 result is that clicking the close button for a window (on the window
210 frame, top right corner usually) will hide but not destroy the
211 window. By default, GTK+ destroys windows when DELETE-EVENT is
216 (defbinding widget-ensure-style () nil
219 (defbinding widget-reset-rc-styles () nil
222 (defbinding widget-push-colormap () nil
223 (colormap gdk:colormap))
225 (defbinding widget-pop-colormap () nil)
227 (defbinding widget-set-default-colormap () nil
228 (colormap gdk:colormap))
230 (defbinding widget-get-default-style () style)
232 (defbinding widget-get-default-colormap () gdk:colormap)
234 (defbinding widget-get-default-visual () gdk:visual)
236 (defbinding widget-get-default-direction () text-direction)
238 (defbinding widget-set-default-direction () nil
239 (direction text-direction))
241 (defbinding widget-shape-combine-mask () nil
243 (shape-mask gdk:bitmap)
247 (defbinding widget-path () nil
249 (path-length int :out)
251 (reverse-path string :out))
253 (defbinding widget-class-path () nil
255 (path-length int :out)
257 (reverse-path string :out))
259 (defbinding widget-modify-style () nil
263 (defbinding widget-modify-style () rc-style
266 (defbinding (widget-modify-foreground "gtk_widget_modify_fg") () nil
271 (defbinding (widget-modify-background "gtk_widget_modify_bg") () nil
276 (defbinding widget-modify-text () nil
281 (defbinding widget-modify-base () nil
286 (defbinding widget-modify-font () nil
289 (font-desc pango:font-description))
291 (defbinding widget-create-pango-context () pango:context
294 (defbinding widget-get-pango-context () pango:context
297 (defbinding widget-create-pango-layout (widget &optional text) pango:layout
299 (text (or string null)))
301 (defbinding widget-render-icon () gdk:pixbuf
307 (defbinding widget-push-composite-child () nil)
309 (defbinding widget-pop-composite-child () nil)
311 (defbinding widget-queue-draw-area () nil
313 (x int) (y int) (width int) (height int))
315 (defbinding widget-reset-shapes () nil
318 (defbinding widget-set-double-buffered () nil
320 (double-buffered boolean))
322 (defbinding widget-set-redraw-on-allocate () nil
324 (redraw-on-allocate boolean))
326 (defbinding widget-set-scroll-adjustments () boolean
328 (hadjustment adjustment)
329 (vadjustment adjustment))
331 (defbinding widget-mnemonic-activate () boolean
333 (group-cycling boolean))
335 (defbinding widget-region-intersect () pointer ;gdk:region
337 (region pointer)) ;gdk:region))
339 (defbinding widget-send-expose () int
343 (defbinding widget-get-accessible () atk:object
346 (defbinding widget-child-focus () boolean
348 (direction direction-type))
350 (defbinding widget-child-notify () nil
352 (child-property string))
354 (defbinding widget-freeze-child-notify () nil
357 (defbinding %widget-get-size-request () nil
362 (defun widget-get-size-request (widget)
363 (multiple-value-bind (width height) (%widget-get-size-request widget)
364 (values (unless (= width -1) width) (unless (= height -1) height))))
366 (defbinding widget-set-size-request (widget width height) nil
369 ((or height -1) int))
371 (defbinding widget-thaw-child-notify () nil
375 ;;; Additional bindings and functions
377 (defbinding widget-mapped-p () boolean
380 (defbinding widget-get-size-allocation () nil
385 (defbinding get-event-widget () widget
388 (defun (setf widget-cursor) (cursor-type widget)
389 (let ((cursor (make-instance 'cursor :type cursor-type)))
390 (gdk:window-set-cursor (widget-window widget) cursor)))