Initial checkin
[clg] / gtk / gtkwidget.lisp
CommitLineData
0d07716f 1;; Common Lisp bindings for GTK+ v2.0
860e6a2e 2;; Copyright (C) 2000-2002 Espen S. Johnsen <espen@users.sourceforge.net>
0d07716f 3;;
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.
8;;
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.
13;;
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
17
ecdb2ae2 18;; $Id: gtkwidget.lisp,v 1.11 2004/12/17 00:27:01 espen Exp $
0d07716f 19
20(in-package "GTK")
21
22
56a0b955 23(defmethod shared-initialize ((widget widget) names &rest initargs &key parent)
eb4f580c 24 (remf initargs :parent)
860e6a2e 25 (prog1
eb4f580c 26 (apply #'call-next-method widget names initargs)
860e6a2e 27 (when parent
ecdb2ae2 28 (when (slot-boundp widget 'parent)
29 (container-remove (widget-parent widget) widget))
30 (let ((parent-widget (first (mklist parent)))
860e6a2e 31 (args (rest (mklist parent))))
ecdb2ae2 32 (apply #'container-add parent-widget widget args)))))
dd392521 33
56a0b955 34(defmethod shared-initialize :after ((widget widget) names &rest initargs
ecdb2ae2 35 &key show-all all-visible)
56a0b955 36 (declare (ignore initargs names))
ecdb2ae2 37 (when (or all-visible show-all)
dd392521 38 (widget-show-all widget)))
0d07716f 39
40
dd392521 41(defmethod slot-unbound ((class gobject-class) (object widget) slot)
0d07716f 42 (cond
43 ((and (eq slot 'child-slots) (slot-value object 'parent))
44 (with-slots (parent child-slots) object
45 (setf
46 child-slots
47 (make-instance
08aad4db 48 (gethash (class-of parent) *container-to-child-class-mappings*)
0d07716f 49 :parent parent :child object))))
50 (t (call-next-method))))
51
52
53(defun child-slot-value (widget slot)
54 (slot-value (widget-child-slots widget) slot))
55
56(defun (setf child-slot-value) (value widget slot)
57 (setf (slot-value (widget-child-slots widget) slot) value))
58
59(defmacro with-child-slots (slots widget &body body)
60 `(with-slots ,slots (widget-child-slots ,widget)
61 ,@body))
62
860e6a2e 63
0d07716f 64(defmacro widget-destroyed (place)
65 `(setf ,place nil))
66
860e6a2e 67
68;;; Bindings
69
08aad4db 70(defbinding widget-destroy () nil
0d07716f 71 (widget widget))
72
08aad4db 73(defbinding widget-unparent () nil
0d07716f 74 (widget widget))
75
08aad4db 76(defbinding widget-show () nil
0d07716f 77 (widget widget))
78
08aad4db 79(defbinding widget-show-now () nil
0d07716f 80 (widget widget))
81
08aad4db 82(defbinding widget-hide () nil
0d07716f 83 (widget widget))
84
08aad4db 85(defbinding widget-show-all () nil
0d07716f 86 (widget widget))
87
08aad4db 88(defbinding widget-hide-all () nil
0d07716f 89 (widget widget))
90
08aad4db 91(defbinding widget-map () nil
0d07716f 92 (widget widget))
93
08aad4db 94(defbinding widget-unmap () nil
0d07716f 95 (widget widget))
96
08aad4db 97(defbinding widget-realize () nil
0d07716f 98 (widget widget))
99
08aad4db 100(defbinding widget-unrealize () nil
0d07716f 101 (widget widget))
102
860e6a2e 103(defbinding widget-queue-draw () nil
104 (widget widget))
105
106(defbinding widget-queue-resize () nil
107 (widget widget))
108
109(defbinding widget-size-request () nil
110 (widget widget)
111 (requisition requisition))
112
113(defbinding widget-get-child-requisition () nil
114 (widget widget)
115 (requisition requisition))
116
117(defbinding widget-size-allocate () nil
118 (widget widget)
119 (allocation allocation))
120
121
08aad4db 122(defbinding widget-add-accelerator
0d07716f 123 (widget signal accel-group key modifiers flags) nil
124 (widget widget)
125 ((name-to-string signal) string)
126 (accel-group accel-group)
127 ((gdk:keyval-from-name key) unsigned-int)
128 (modifiers gdk:modifier-type)
129 (flags accel-flags))
130
08aad4db 131(defbinding widget-remove-accelerator
0d07716f 132 (widget accel-group key modifiers) nil
133 (widget widget)
134 (accel-group accel-group)
135 ((gdk:keyval-from-name key) unsigned-int)
136 (modifiers gdk:modifier-type))
137
860e6a2e 138(defbinding (widget-set-accelerator-path "gtk_widget_set_accel_path") () nil
0d07716f 139 (widget widget)
860e6a2e 140 (accel-path string)
141 (accel-group accel-group))
142
0d07716f 143
08aad4db 144(defbinding widget-event () int
0d07716f 145 (widget widget)
146 (event gdk:event))
147
08aad4db 148(defbinding widget-activate () boolean
0d07716f 149 (widget widget))
150
08aad4db 151(defbinding widget-reparent () nil
0d07716f 152 (widget widget)
153 (new-parent widget))
154
860e6a2e 155(defbinding %widget-intersect () boolean
156 (widget widget)
157 (area gdk:rectangle)
ecdb2ae2 158 (intersection (or null gdk:rectangle)))
0d07716f 159
860e6a2e 160(defun widget-intersection (widget area)
161 (let ((intersection (make-instance 'gdk:rectangle)))
162 (when (%widget-intersect widget area intersection)
163 intersection)))
0d07716f 164
860e6a2e 165(defun widget-intersect-p (widget area)
ecdb2ae2 166 (%widget-intersect widget area nil))
13148f19 167
ecdb2ae2 168;; (defbinding (widget-is-focus-p "gtk_widget_is_focus") () boolean
169;; (widget widget))
13148f19 170
860e6a2e 171(defbinding widget-grab-focus () nil
13148f19 172 (widget widget))
173
860e6a2e 174(defbinding widget-grab-default () nil
175 (widget widget))
0d07716f 176
08aad4db 177(defbinding widget-add-events () nil
0d07716f 178 (widget widget)
179 (events gdk:event-mask))
180
860e6a2e 181(defbinding widget-get-toplevel () widget
0d07716f 182 (widget widget))
183
860e6a2e 184(defbinding widget-get-ancestor (widget type) widget
0d07716f 185 (widget widget)
186 ((find-type-number type) type-number))
187
860e6a2e 188(defbinding widget-get-pointer () nil
0d07716f 189 (widget widget)
190 (x int :out)
191 (y int :out))
192
08aad4db 193(defbinding (widget-is-ancestor-p "gtk_widget_is_ancestor") () boolean
0d07716f 194 (widget widget)
195 (ancestor widget))
196
860e6a2e 197(defbinding widget-translate-coordinates () boolean
198 (src-widget widget)
199 (dest-widget widget)
200 (src-x int) (src-y int)
201 (set-x int :out) (dest-y int :out))
202
203(defun widget-hide-on-delete (widget)
204 "Utility function; intended to be connected to the DELETE-EVENT
205signal on a GtkWindow. The function calls WIDGET-HIDE on its
206argument, then returns T. If connected to DELETE-EVENT, the
207result is that clicking the close button for a window (on the window
208frame, top right corner usually) will hide but not destroy the
209window. By default, GTK+ destroys windows when DELETE-EVENT is
210received."
211 (widget-hide widget)
212 t)
213
08aad4db 214(defbinding widget-ensure-style () nil
0d07716f 215 (widget widget))
216
08aad4db 217(defbinding widget-reset-rc-styles () nil
0d07716f 218 (widget widget))
219
08aad4db 220(defbinding widget-push-colormap () nil
0d07716f 221 (colormap gdk:colormap))
222
08aad4db 223(defbinding widget-pop-colormap () nil)
0d07716f 224
08aad4db 225(defbinding widget-set-default-colormap () nil
0d07716f 226 (colormap gdk:colormap))
227
08aad4db 228(defbinding widget-get-default-style () style)
0d07716f 229
08aad4db 230(defbinding widget-get-default-colormap () gdk:colormap)
0d07716f 231
860e6a2e 232(defbinding widget-get-default-visual () gdk:visual)
233
234(defbinding widget-get-default-direction () text-direction)
235
236(defbinding widget-set-default-direction () nil
237 (direction text-direction))
238
08aad4db 239(defbinding widget-shape-combine-mask () nil
0d07716f 240 (widget widget)
241 (shape-mask gdk:bitmap)
242 (x-offset int)
243 (y-offset int))
244
860e6a2e 245(defbinding widget-path () nil
246 (widget widget)
247 (path-length int :out)
248 (path string :out)
249 (reverse-path string :out))
250
251(defbinding widget-class-path () nil
252 (widget widget)
253 (path-length int :out)
254 (path string :out)
255 (reverse-path string :out))
256
257(defbinding widget-modify-style () nil
258 (widget widget)
259 (style rc-style))
260
261(defbinding widget-modify-style () rc-style
262 (widget widget))
263
264(defbinding (widget-modify-foreground "gtk_widget_modify_fg") () nil
265 (widget widget)
266 (state state-type)
267 (color gdk:color))
268
269(defbinding (widget-modify-background "gtk_widget_modify_bg") () nil
270 (widget widget)
271 (state state-type)
272 (color gdk:color))
273
274(defbinding widget-modify-text () nil
275 (widget widget)
276 (state state-type)
277 (color gdk:color))
278
279(defbinding widget-modify-base () nil
280 (widget widget)
281 (state state-type)
282 (color gdk:color))
283
284(defbinding widget-modify-font () nil
285 (widget widget)
286 (state state-type)
287 (font-desc pango:font-description))
288
289(defbinding widget-create-pango-context () pango:context
290 (widget widget))
291
292(defbinding widget-get-pango-context () pango:context
293 (widget widget))
294
295(defbinding widget-create-pango-layout (widget &optional text) pango:layout
296 (widget widget)
297 (text (or string null)))
298
299(defbinding widget-render-icon () gdk:pixbuf
300 (widget widget)
301 (stock-id string)
302 (size icon-size)
303 (detail string))
304
305(defbinding widget-push-composite-child () nil)
306
307(defbinding widget-pop-composite-child () nil)
308
309(defbinding widget-queue-draw-area () nil
310 (widget widget)
311 (x int) (y int) (width int) (height int))
312
313(defbinding widget-reset-shapes () nil
314 (widget widget))
315
316(defbinding widget-set-double-buffered () nil
317 (widget widget)
318 (double-buffered boolean))
319
320(defbinding widget-set-redraw-on-allocate () nil
321 (widget widget)
322 (redraw-on-allocate boolean))
323
324(defbinding widget-set-scroll-adjustments () boolean
325 (widget widget)
326 (hadjustment adjustment)
327 (vadjustment adjustment))
328
329(defbinding widget-mnemonic-activate () boolean
330 (widget widget)
331 (group-cycling boolean))
332
333(defbinding widget-region-intersect () pointer ;gdk:region
334 (widget widget)
335 (region pointer)) ;gdk:region))
336
337(defbinding widget-send-expose () int
338 (widget widget)
339 (event gdk:event))
340
341(defbinding widget-get-accessible () atk:object
342 (widget widget))
343
344(defbinding widget-child-focus () boolean
345 (widget widget)
346 (direction direction-type))
347
348(defbinding widget-child-notify () nil
349 (widget widget)
350 (child-property string))
351
352(defbinding widget-freeze-child-notify () nil
353 (widget widget))
354
355(defbinding %widget-get-size-request () nil
356 (widget widget)
357 (width int :out)
358 (height int :out))
359
360(defun widget-get-size-request (widget)
361 (multiple-value-bind (width height) (%widget-get-size-request widget)
6baf860c 362 (values (unless (= width -1) width) (unless (= height -1) height))))
860e6a2e 363
364(defbinding widget-set-size-request (widget width height) nil
365 (widget widget)
366 ((or width -1) int)
367 ((or height -1) int))
368
369(defbinding widget-thaw-child-notify () nil
370 (widget widget))
371
372
373;;; Additional bindings and functions
374
ecdb2ae2 375(defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean
0d07716f 376 (widget widget))
377
860e6a2e 378(defbinding widget-get-size-allocation () nil
379 (widget widget)
380 (width int :out)
381 (height int :out))
382
383(defbinding get-event-widget () widget
384 (event gdk:event))
385
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)))