chiark / gitweb /
Added binding to create font descriptions from strings
[clg] / gtk / gtkwidget.lisp
CommitLineData
112ac1d3 1;; Common Lisp bindings for GTK+ v2.x
2;; Copyright 2000-2005 Espen S. Johnsen <espen@users.sf.net>
560af5c5 3;;
112ac1d3 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:
560af5c5 11;;
112ac1d3 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
560af5c5 14;;
112ac1d3 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.
560af5c5 22
71267721 23;; $Id: gtkwidget.lisp,v 1.20 2006-02-26 15:24:46 espen Exp $
560af5c5 24
25(in-package "GTK")
26
27
71267721 28#-debug-ref-counting
29(defmethod print-object ((widget widget) stream)
30 (if (and
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) (sap-int (foreign-location widget))))
36 (call-next-method)))
37
fa60e0a2 38(defmethod shared-initialize ((widget widget) names &key (visible nil visible-p))
39 (when (and visible-p (not visible)) ; widget explicit set as not visible
40 (setf (user-data widget 'hidden-p) t)
41 (signal-connect widget 'show
42 #'(lambda ()
43 (unset-user-data widget 'hidden-p))
44 :remove t))
45 (call-next-method))
e5b416f0 46
a457d472 47(defmethod shared-initialize :after ((widget widget) names &key parent visible)
fa60e0a2 48 (declare (ignore names))
a457d472 49 (when visible
50 (widget-show widget))
fa60e0a2 51 (when parent
52 (when (slot-boundp widget 'parent)
53 (container-remove (widget-parent widget) widget))
54 (destructuring-bind (parent &rest args) (mklist parent)
55 (apply #'container-add parent widget args))))
560af5c5 56
8e947895 57(defmethod slot-unbound ((class gobject-class) (object widget)
58 (slot (eql 'child-properties)))
560af5c5 59 (cond
8e947895 60 ((slot-boundp object 'parent)
c289d084 61 (with-slots (parent child-properties) object
8e947895 62 (setf child-properties
63 (make-instance
64 (gethash (class-of parent) *container-to-child-class-mappings*)
560af5c5 65 :parent parent :child object))))
8e947895 66 ((call-next-method))))
67
560af5c5 68
fa60e0a2 69(defmethod compute-signal-function ((widget widget) signal function object)
70 (if (eq object :parent)
03802c3c 71 #'(lambda (&rest args)
72 (if (slot-boundp widget 'parent)
73 (apply function (widget-parent widget) (rest args))
8e947895 74 ;; Delay until parent is set
03802c3c 75 (signal-connect widget 'parent-set
76 #'(lambda (old-parent)
77 (declare (ignore old-parent))
78 (let ((*signal-stop-emission*
79 #'(lambda ()
80 (warn "Ignoring emission stop in delayed signal handler"))))
81 (apply function (widget-parent widget) (rest args))))
82 :remove t)
83; (warn "Widget has no parent -- ignoring signal")
84 ))
85 (call-next-method)))
86
c289d084 87(defun child-property-value (widget slot)
88 (slot-value (widget-child-properties widget) slot))
560af5c5 89
c289d084 90(defun (setf child-property-value) (value widget slot)
91 (setf (slot-value (widget-child-properties widget) slot) value))
560af5c5 92
c289d084 93(defmacro with-child-properties (slots widget &body body)
94 `(with-slots ,slots (widget-child-properties ,widget)
560af5c5 95 ,@body))
96
1de3a418 97
1de3a418 98;;; Bindings
99
0d270bd9 100(defbinding widget-destroy () nil
560af5c5 101 (widget widget))
102
0d270bd9 103(defbinding widget-unparent () nil
560af5c5 104 (widget widget))
105
0d270bd9 106(defbinding widget-show () nil
560af5c5 107 (widget widget))
108
0d270bd9 109(defbinding widget-show-now () nil
560af5c5 110 (widget widget))
111
0d270bd9 112(defbinding widget-hide () nil
560af5c5 113 (widget widget))
114
fa60e0a2 115(defun widget-hidden-p (widget)
116 "Return T if WIDGET has been explicit hidden during construction."
117 (user-data widget 'hidden-p))
118
0d270bd9 119(defbinding widget-show-all () nil
560af5c5 120 (widget widget))
121
0d270bd9 122(defbinding widget-hide-all () nil
560af5c5 123 (widget widget))
124
0d270bd9 125(defbinding widget-map () nil
560af5c5 126 (widget widget))
127
0d270bd9 128(defbinding widget-unmap () nil
560af5c5 129 (widget widget))
130
0d270bd9 131(defbinding widget-realize () nil
560af5c5 132 (widget widget))
133
0d270bd9 134(defbinding widget-unrealize () nil
560af5c5 135 (widget widget))
136
1de3a418 137(defbinding widget-queue-draw () nil
138 (widget widget))
139
140(defbinding widget-queue-resize () nil
141 (widget widget))
142
8e947895 143(defbinding widget-queue-resize-no-redraw () nil
144 (widget widget))
145
146(defbinding widget-size-request
147 (widget &optional (requisition (make-instance 'requisition))) nil
1de3a418 148 (widget widget)
8e947895 149 (requisition requisition :return))
1de3a418 150
8e947895 151(defbinding widget-get-child-requisition
152 (widget &optional (requisition (make-instance 'requisition))) nil
1de3a418 153 (widget widget)
8e947895 154 (requisition requisition :return))
1de3a418 155
156(defbinding widget-size-allocate () nil
157 (widget widget)
158 (allocation allocation))
159
0d270bd9 160(defbinding widget-add-accelerator
560af5c5 161 (widget signal accel-group key modifiers flags) nil
162 (widget widget)
71267721 163 ((signal-name-to-string signal) string)
560af5c5 164 (accel-group accel-group)
165 ((gdk:keyval-from-name key) unsigned-int)
166 (modifiers gdk:modifier-type)
167 (flags accel-flags))
168
0d270bd9 169(defbinding widget-remove-accelerator
560af5c5 170 (widget accel-group key modifiers) nil
171 (widget widget)
172 (accel-group accel-group)
173 ((gdk:keyval-from-name key) unsigned-int)
174 (modifiers gdk:modifier-type))
175
8e947895 176(defbinding widget-set-accel-path () nil
560af5c5 177 (widget widget)
1de3a418 178 (accel-path string)
179 (accel-group accel-group))
560af5c5 180
8e947895 181(defbinding widget-list-accel-closures () (glist pointer)
182 (widget widget))
183
184(defbinding widget-can-activate-accel-p () boolean
185 (widget widget)
186 (signal-id unsigned-int))
187
188(defbinding widget-event () boolean
560af5c5 189 (widget widget)
190 (event gdk:event))
191
0d270bd9 192(defbinding widget-activate () boolean
560af5c5 193 (widget widget))
194
0d270bd9 195(defbinding widget-reparent () nil
560af5c5 196 (widget widget)
197 (new-parent widget))
198
1de3a418 199(defbinding %widget-intersect () boolean
200 (widget widget)
201 (area gdk:rectangle)
853ec10e 202 (intersection (or null gdk:rectangle)))
560af5c5 203
1de3a418 204(defun widget-intersection (widget area)
205 (let ((intersection (make-instance 'gdk:rectangle)))
206 (when (%widget-intersect widget area intersection)
207 intersection)))
560af5c5 208
1de3a418 209(defun widget-intersect-p (widget area)
853ec10e 210 (%widget-intersect widget area nil))
aace61f5 211
1de3a418 212(defbinding widget-grab-focus () nil
aace61f5 213 (widget widget))
214
1de3a418 215(defbinding widget-grab-default () nil
216 (widget widget))
560af5c5 217
0d270bd9 218(defbinding widget-add-events () nil
560af5c5 219 (widget widget)
220 (events gdk:event-mask))
221
1de3a418 222(defbinding widget-get-toplevel () widget
560af5c5 223 (widget widget))
224
1de3a418 225(defbinding widget-get-ancestor (widget type) widget
560af5c5 226 (widget widget)
227 ((find-type-number type) type-number))
228
1de3a418 229(defbinding widget-get-pointer () nil
560af5c5 230 (widget widget)
231 (x int :out)
232 (y int :out))
233
8e947895 234(defbinding widget-is-ancestor-p () boolean
560af5c5 235 (widget widget)
236 (ancestor widget))
237
1de3a418 238(defbinding widget-translate-coordinates () boolean
239 (src-widget widget)
240 (dest-widget widget)
241 (src-x int) (src-y int)
242 (set-x int :out) (dest-y int :out))
243
244(defun widget-hide-on-delete (widget)
245 "Utility function; intended to be connected to the DELETE-EVENT
8e947895 246signal on a WINDOW. The function calls WIDGET-HIDE on its
1de3a418 247argument, then returns T. If connected to DELETE-EVENT, the
248result is that clicking the close button for a window (on the window
249frame, top right corner usually) will hide but not destroy the
250window. By default, GTK+ destroys windows when DELETE-EVENT is
251received."
252 (widget-hide widget)
253 t)
254
0d270bd9 255(defbinding widget-ensure-style () nil
560af5c5 256 (widget widget))
257
0d270bd9 258(defbinding widget-reset-rc-styles () nil
560af5c5 259 (widget widget))
260
0d270bd9 261(defbinding widget-push-colormap () nil
560af5c5 262 (colormap gdk:colormap))
263
0d270bd9 264(defbinding widget-pop-colormap () nil)
560af5c5 265
8e947895 266(defbinding %widget-set-default-colormap () nil
560af5c5 267 (colormap gdk:colormap))
268
8e947895 269(defun (setf widget-default-colormap) (colormap)
270 (%widget-set-default-colormap colormap)
271 colormap)
272
273(defbinding (widget-default-style "gtk_widget_get_default_style") () style)
560af5c5 274
8e947895 275(defbinding (widget-default-colromap "gtk_widget_get_default_colormap")
276 () gdk:colormap)
560af5c5 277
8e947895 278(defbinding (widget-default-visual "gtk_widget_get_default_visual")
279 () gdk:visual)
1de3a418 280
8e947895 281(defbinding (widget-default-direction "gtk_widget_get_default_direction")
282 () text-direction)
1de3a418 283
8e947895 284(defbinding %widget-set-default-direction () nil
285 (direction text-direction))
286
287(defun (setf widget-default-direction) (direction)
288 (%widget-set-default-direction direction)
289 direction)
1de3a418 290
0d270bd9 291(defbinding widget-shape-combine-mask () nil
560af5c5 292 (widget widget)
8e947895 293 (shape-mask (or null gdk:bitmap))
560af5c5 294 (x-offset int)
295 (y-offset int))
296
1de3a418 297(defbinding widget-path () nil
298 (widget widget)
299 (path-length int :out)
300 (path string :out)
301 (reverse-path string :out))
302
303(defbinding widget-class-path () nil
304 (widget widget)
305 (path-length int :out)
306 (path string :out)
307 (reverse-path string :out))
308
309(defbinding widget-modify-style () nil
310 (widget widget)
311 (style rc-style))
312
8e947895 313(defbinding widget-get-modifier-style () rc-style
1de3a418 314 (widget widget))
315
8e947895 316(defbinding widget-modify-fg () nil
1de3a418 317 (widget widget)
318 (state state-type)
319 (color gdk:color))
320
8e947895 321(defbinding widget-modify-bg () nil
1de3a418 322 (widget widget)
323 (state state-type)
324 (color gdk:color))
325
326(defbinding widget-modify-text () nil
327 (widget widget)
328 (state state-type)
329 (color gdk:color))
330
331(defbinding widget-modify-base () nil
332 (widget widget)
333 (state state-type)
334 (color gdk:color))
335
336(defbinding widget-modify-font () nil
337 (widget widget)
338 (state state-type)
339 (font-desc pango:font-description))
340
341(defbinding widget-create-pango-context () pango:context
342 (widget widget))
343
344(defbinding widget-get-pango-context () pango:context
345 (widget widget))
346
347(defbinding widget-create-pango-layout (widget &optional text) pango:layout
348 (widget widget)
349 (text (or string null)))
350
8e947895 351(defbinding widget-render-icon (widget stock-id &optional size detail)
352 gdk:pixbuf
1de3a418 353 (widget widget)
354 (stock-id string)
8e947895 355 ((or size -1) (or icon-size int))
356 (detail (or null string)))
1de3a418 357
358(defbinding widget-push-composite-child () nil)
359
360(defbinding widget-pop-composite-child () nil)
361
362(defbinding widget-queue-draw-area () nil
363 (widget widget)
364 (x int) (y int) (width int) (height int))
365
366(defbinding widget-reset-shapes () nil
367 (widget widget))
368
8e947895 369;; (defbinding widget-set-double-buffered () nil
370;; (widget widget)
371;; (double-buffered boolean))
1de3a418 372
8e947895 373;; (defbinding widget-set-redraw-on-allocate () nil
374;; (widget widget)
375;; (redraw-on-allocate boolean))
1de3a418 376
377(defbinding widget-set-scroll-adjustments () boolean
378 (widget widget)
8e947895 379 (hadjustment (or null adjustment))
380 (vadjustment (or null adjustment)))
1de3a418 381
382(defbinding widget-mnemonic-activate () boolean
383 (widget widget)
384 (group-cycling boolean))
385
8e947895 386(defbinding widget-class-find-style-property (class name) param
387 ((type-class-peek class) pointer)
388 (name string))
389
390(defbinding widget-class-list-style-properties (class)
391 (vector (copy-of param) n-properties)
392 ((type-class-peek class) pointer)
393 (n-properties unsigned-int :out))
394
1de3a418 395(defbinding widget-region-intersect () pointer ;gdk:region
396 (widget widget)
397 (region pointer)) ;gdk:region))
398
8e947895 399(defbinding widget-send-expose () boolean
1de3a418 400 (widget widget)
401 (event gdk:event))
402
8e947895 403(defbinding %widget-style-get-property () nil
404 (widget widget)
405 (name string)
406 (value gvalue))
407
408(defun style-property-value (widget style)
409 (let* ((name (string-downcase style))
410 (param (widget-class-find-style-property (class-of widget) name)))
411 (if (not param)
412 (error "~A has no such style property: ~A" widget style)
413 (with-gvalue (gvalue (param-value-type param))
414 (%widget-style-get-property widget (string-downcase style) gvalue)))))
415
1de3a418 416(defbinding widget-get-accessible () atk:object
417 (widget widget))
418
419(defbinding widget-child-focus () boolean
420 (widget widget)
421 (direction direction-type))
422
423(defbinding widget-child-notify () nil
424 (widget widget)
425 (child-property string))
426
427(defbinding widget-freeze-child-notify () nil
428 (widget widget))
429
8e947895 430(defbinding widget-get-clipboard () clipboard
431 (widget widget)
432 (selection int #|gdk:atom|#))
433
434(defbinding widget-get-display () gdk:display
435 (widget widget))
436
437(defbinding widget-get-root-window () gdk:window
438 (widget widget))
439
440(defbinding widget-get-screen () gdk:screen
441 (widget widget))
442
443(defbinding widget-has-screen-p () boolean
444 (widget widget))
445
1de3a418 446(defbinding %widget-get-size-request () nil
447 (widget widget)
448 (width int :out)
449 (height int :out))
450
451(defun widget-get-size-request (widget)
452 (multiple-value-bind (width height) (%widget-get-size-request widget)
9adccb27 453 (values (unless (= width -1) width) (unless (= height -1) height))))
1de3a418 454
455(defbinding widget-set-size-request (widget width height) nil
456 (widget widget)
457 ((or width -1) int)
458 ((or height -1) int))
459
460(defbinding widget-thaw-child-notify () nil
461 (widget widget))
462
8e947895 463(defbinding widget-list-mnemonic-labels () (glist widget)
464 (widget widget))
465
466(defbinding widget-add-mnemonic-label () nil
467 (widget widget)
468 (label widget))
469
470(defbinding widget-remove-mnemonic-label () nil
471 (widget widget)
472 (label widget))
473
1de3a418 474
475;;; Additional bindings and functions
476
853ec10e 477(defbinding (widget-mapped-p "gtk_widget_mapped_p") () boolean
560af5c5 478 (widget widget))
479
1de3a418 480(defbinding widget-get-size-allocation () nil
481 (widget widget)
482 (width int :out)
483 (height int :out))
484
485(defbinding get-event-widget () widget
486 (event gdk:event))
487
488(defun (setf widget-cursor) (cursor-type widget)
56329445 489 (let ((cursor (make-instance 'gdk:cursor :type cursor-type)))
1de3a418 490 (gdk:window-set-cursor (widget-window widget) cursor)))
8e947895 491
492(defbinding %widget-get-parent-window () gdk:window
493 (widget widget))
494
495(defun %widget-parent-window (widget)
496 (when (slot-boundp widget 'parent)
497 (%widget-get-parent-window widget)))