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