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.11 2004/12/17 00:27:01 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 (when (slot-boundp widget 'parent)
29 (container-remove (widget-parent widget) widget))
30 (let ((parent-widget (first (mklist parent)))
31 (args (rest (mklist parent))))
32 (apply #'container-add parent-widget widget args)))))
34 (defmethod shared-initialize :after ((widget widget) names &rest initargs
35 &key show-all all-visible)
36 (declare (ignore initargs names))
37 (when (or all-visible show-all)
38 (widget-show-all widget)))
41 (defmethod slot-unbound ((class gobject-class) (object widget) slot)
43 ((and (eq slot 'child-slots) (slot-value object 'parent))
44 (with-slots (parent child-slots) object
48 (gethash (class-of parent) *container-to-child-class-mappings*)
49 :parent parent :child object))))
50 (t (call-next-method))))
53 (defun child-slot-value (widget slot)
54 (slot-value (widget-child-slots widget) slot))
56 (defun (setf child-slot-value) (value widget slot)
57 (setf (slot-value (widget-child-slots widget) slot) value))
59 (defmacro with-child-slots (slots widget &body body)
60 `(with-slots ,slots (widget-child-slots ,widget)
64 (defmacro widget-destroyed (place)
70 (defbinding widget-destroy () nil
73 (defbinding widget-unparent () nil
76 (defbinding widget-show () nil
79 (defbinding widget-show-now () nil
82 (defbinding widget-hide () nil
85 (defbinding widget-show-all () nil
88 (defbinding widget-hide-all () nil
91 (defbinding widget-map () nil
94 (defbinding widget-unmap () nil
97 (defbinding widget-realize () nil
100 (defbinding widget-unrealize () nil
103 (defbinding widget-queue-draw () nil
106 (defbinding widget-queue-resize () nil
109 (defbinding widget-size-request () nil
111 (requisition requisition))
113 (defbinding widget-get-child-requisition () nil
115 (requisition requisition))
117 (defbinding widget-size-allocate () nil
119 (allocation allocation))
122 (defbinding widget-add-accelerator
123 (widget signal accel-group key modifiers flags) nil
125 ((name-to-string signal) string)
126 (accel-group accel-group)
127 ((gdk:keyval-from-name key) unsigned-int)
128 (modifiers gdk:modifier-type)
131 (defbinding widget-remove-accelerator
132 (widget accel-group key modifiers) nil
134 (accel-group accel-group)
135 ((gdk:keyval-from-name key) unsigned-int)
136 (modifiers gdk:modifier-type))
138 (defbinding (widget-set-accelerator-path "gtk_widget_set_accel_path") () nil
141 (accel-group accel-group))
144 (defbinding widget-event () int
148 (defbinding widget-activate () boolean
151 (defbinding widget-reparent () nil
155 (defbinding %widget-intersect () boolean
158 (intersection (or null gdk:rectangle)))
160 (defun widget-intersection (widget area)
161 (let ((intersection (make-instance 'gdk:rectangle)))
162 (when (%widget-intersect widget area intersection)
165 (defun widget-intersect-p (widget area)
166 (%widget-intersect widget area nil))
168 ;; (defbinding (widget-is-focus-p "gtk_widget_is_focus") () boolean
171 (defbinding widget-grab-focus () nil
174 (defbinding widget-grab-default () nil
177 (defbinding widget-add-events () nil
179 (events gdk:event-mask))
181 (defbinding widget-get-toplevel () widget
184 (defbinding widget-get-ancestor (widget type) widget
186 ((find-type-number type) type-number))
188 (defbinding widget-get-pointer () nil
193 (defbinding (widget-is-ancestor-p "gtk_widget_is_ancestor") () boolean
197 (defbinding widget-translate-coordinates () boolean
200 (src-x int) (src-y int)
201 (set-x int :out) (dest-y int :out))
203 (defun widget-hide-on-delete (widget)
204 "Utility function; intended to be connected to the DELETE-EVENT
205 signal on a GtkWindow. The function calls WIDGET-HIDE on its
206 argument, then returns T. If connected to DELETE-EVENT, the
207 result is that clicking the close button for a window (on the window
208 frame, top right corner usually) will hide but not destroy the
209 window. By default, GTK+ destroys windows when DELETE-EVENT is
214 (defbinding widget-ensure-style () nil
217 (defbinding widget-reset-rc-styles () nil
220 (defbinding widget-push-colormap () nil
221 (colormap gdk:colormap))
223 (defbinding widget-pop-colormap () nil)
225 (defbinding widget-set-default-colormap () nil
226 (colormap gdk:colormap))
228 (defbinding widget-get-default-style () style)
230 (defbinding widget-get-default-colormap () gdk:colormap)
232 (defbinding widget-get-default-visual () gdk:visual)
234 (defbinding widget-get-default-direction () text-direction)
236 (defbinding widget-set-default-direction () nil
237 (direction text-direction))
239 (defbinding widget-shape-combine-mask () nil
241 (shape-mask gdk:bitmap)
245 (defbinding widget-path () nil
247 (path-length int :out)
249 (reverse-path string :out))
251 (defbinding widget-class-path () nil
253 (path-length int :out)
255 (reverse-path string :out))
257 (defbinding widget-modify-style () nil
261 (defbinding widget-modify-style () rc-style
264 (defbinding (widget-modify-foreground "gtk_widget_modify_fg") () nil
269 (defbinding (widget-modify-background "gtk_widget_modify_bg") () nil
274 (defbinding widget-modify-text () nil
279 (defbinding widget-modify-base () nil
284 (defbinding widget-modify-font () nil
287 (font-desc pango:font-description))
289 (defbinding widget-create-pango-context () pango:context
292 (defbinding widget-get-pango-context () pango:context
295 (defbinding widget-create-pango-layout (widget &optional text) pango:layout
297 (text (or string null)))
299 (defbinding widget-render-icon () gdk:pixbuf
305 (defbinding widget-push-composite-child () nil)
307 (defbinding widget-pop-composite-child () nil)
309 (defbinding widget-queue-draw-area () nil
311 (x int) (y int) (width int) (height int))
313 (defbinding widget-reset-shapes () nil
316 (defbinding widget-set-double-buffered () nil
318 (double-buffered boolean))
320 (defbinding widget-set-redraw-on-allocate () nil
322 (redraw-on-allocate boolean))
324 (defbinding widget-set-scroll-adjustments () boolean
326 (hadjustment adjustment)
327 (vadjustment adjustment))
329 (defbinding widget-mnemonic-activate () boolean
331 (group-cycling boolean))
333 (defbinding widget-region-intersect () pointer ;gdk:region
335 (region pointer)) ;gdk:region))
337 (defbinding widget-send-expose () int
341 (defbinding widget-get-accessible () atk:object
344 (defbinding widget-child-focus () boolean
346 (direction direction-type))
348 (defbinding widget-child-notify () nil
350 (child-property string))
352 (defbinding widget-freeze-child-notify () nil
355 (defbinding %widget-get-size-request () nil
360 (defun widget-get-size-request (widget)
361 (multiple-value-bind (width height) (%widget-get-size-request widget)
362 (values (unless (= width -1) width) (unless (= height -1) height))))
364 (defbinding widget-set-size-request (widget width height) nil
367 ((or height -1) int))
369 (defbinding widget-thaw-child-notify () nil
373 ;;; Additional bindings and functions
375 (defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean
378 (defbinding widget-get-size-allocation () nil
383 (defbinding get-event-widget () widget
386 (defun (setf widget-cursor) (cursor-type widget)
387 (let ((cursor (make-instance 'cursor :type cursor-type)))
388 (gdk:window-set-cursor (widget-window widget) cursor)))