8a24bd0b374323265c988ae252a0a728dbb6e5f7
[clg] / gtk / gtkcontainer.lisp
1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2000 Espen S. Johnsen <esj@stud.cs.uit.no>
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
18 ;; $Id: gtkcontainer.lisp,v 1.11 2004-11-07 01:23:38 espen Exp $
19
20 (in-package "GTK")
21
22 (defmethod shared-initialize ((container container) names &rest initargs
23 &key child children child-args)
24 (declare (ignore child))
25 (call-next-method)
26 (dolist (child (append children (get-all initargs :child)))
27 (apply #'container-add container (append (mklist child) child-args))))
28
29
30 (defbinding %container-add () nil
31 (container container)
32 (widget widget))
33
34 (defmethod container-add ((container container) (widget widget) &rest args)
35 (%container-add container widget)
36 (when args
37 (setf
38 (slot-value widget 'child-slots)
39 (apply
40 #'make-instance
41 (gethash (class-of container) *container-to-child-class-mappings*)
42 :parent container :child widget args))))
43
44
45 (defbinding %container-remove () nil
46 (container container)
47 (widget widget))
48
49 (defmethod container-remove ((container container) (widget widget))
50 (%container-remove container widget)
51 (slot-makunbound widget 'child-slots))
52
53
54 (defbinding %container-child-get-property () nil
55 (container container)
56 (child widget)
57 (property-name string)
58 (value gvalue))
59
60 (defbinding %container-child-set-property () nil
61 (container container)
62 (child widget)
63 (property-name string)
64 (value gvalue))
65
66
67 (defbinding container-check-resize () nil
68 (container container))
69
70 (def-callback-marshal %foreach-callback (nil widget))
71
72 (defbinding %container-foreach (container callback-id) nil
73 (container container)
74 ((callback %foreach-callback) pointer)
75 (callback-id unsigned-int))
76
77 (defun container-foreach (container function)
78 (let ((callback-id (register-callback-function function)))
79 (unwind-protect
80 (%container-foreach container callback-id)
81 (destroy-user-data callback-id))))
82
83 (defun map-container (seqtype func container)
84 (case seqtype
85 ((nil)
86 (container-foreach container func)
87 nil)
88 (list
89 (let ((list nil))
90 (container-foreach
91 container
92 #'(lambda (child)
93 (push (funcall func child) list)))
94 (nreverse list)))
95 (t
96 (let ((seq (make-sequence seqtype (container-length container)))
97 (index 0))
98 (container-foreach
99 container
100 #'(lambda (child)
101 (setf (elt seq index) (funcall func child))
102 (incf index)))
103 seq))))
104
105 (defmacro do-container ((var container &optional (result nil)) &body body)
106 (let ((continue (make-symbol "CONTINUE")))
107 `(let ((,continue t))
108 (container-foreach
109 ,container
110 #'(lambda (,var)
111 (when ,continue
112 (setq ,continue nil)
113 (block nil
114 ,@body
115 (setq ,continue t)))))
116 ,result)))
117
118 ;; (defbinding %container-get-children () (glist widget)
119 ;; (container container))
120
121 (defmethod container-children ((container container))
122 ;; (%container-get-children container)
123 (map-container 'list #'identity container))
124
125 (defmethod (setf container-children) (children (container container))
126 (dolist (child (container-children container))
127 (container-remove container child))
128 (dolist (child children)
129 (container-add container child))
130 children)
131
132 (defun container-length (container)
133 (let ((n 0))
134 (container-foreach container
135 #'(lambda (child)
136 (declare (ignore child))
137 (incf n)))
138 n))
139
140 (defbinding container-resize-children () nil
141 (container container))
142
143 (defbinding container-propagate-expose () nil
144 (container container)
145 (child widget)
146 (event gdk:expose-event))
147
148
149 (defbinding %container-get-focus-chain () boolean
150 (container container)
151 (focusable-widgets (glist widget) :out))
152
153 (defun container-focus-chain (container)
154 (multiple-value-bind (chain-set-p focusable-widgets)
155 (%container-get-focus-chain container)
156 (and chain-set-p focusable-widgets)))
157
158 (defbinding %container-set-focus-chain () nil
159 (container container)
160 (focusable-widgets (glist widget)))
161
162 (defbinding %container-unset-focus-chain () nil
163 (container container))
164
165 (defun (setf container-focus-chain) (focusable-widgets container)
166 (if (null focusable-widgets)
167 (%container-unset-focus-chain container)
168 (%container-set-focus-chain container focusable-widgets)))