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 | |
56ccd5b7 |
23 | ;; $Id: gtkcontainer.lisp,v 1.19 2006-02-19 19:31:14 espen Exp $ |
560af5c5 |
24 | |
25 | (in-package "GTK") |
4a383aae |
26 | |
1047e159 |
27 | (defmethod shared-initialize ((container container) names &rest initargs |
67b44e86 |
28 | &key child children child-args |
29 | (show-children nil show-children-p)) |
4a383aae |
30 | (declare (ignore child children)) |
67b44e86 |
31 | (when show-children-p |
32 | (if (not show-children) |
33 | (setf (user-data container 'show-recursive-p) nil) |
34 | (signal-connect container 'show #'container-show-recursive |
35 | :object t :remove t))) |
36 | |
560af5c5 |
37 | (call-next-method) |
4a383aae |
38 | (initial-add container |
39 | #'(lambda (container args) |
40 | (apply #'container-add container (append (mklist args) child-args))) |
41 | initargs :child :children)) |
560af5c5 |
42 | |
560af5c5 |
43 | |
67b44e86 |
44 | (defmethod compute-signal-function ((container container) signal function object) |
45 | (if (eq object :children) |
03802c3c |
46 | #'(lambda (&rest args) |
47 | (mapc #'(lambda (child) |
48 | (apply function child (rest args))) |
49 | (container-children container))) |
50 | (call-next-method))) |
51 | |
52 | |
e5b416f0 |
53 | (defbinding %container-add () nil |
560af5c5 |
54 | (container container) |
55 | (widget widget)) |
56 | |
f9e76ebe |
57 | (defmethod container-add ((container container) (widget widget) &rest args) |
e5b416f0 |
58 | (%container-add container widget) |
59 | (when args |
60 | (setf |
c289d084 |
61 | (slot-value widget 'child-properties) |
e5b416f0 |
62 | (apply |
63 | #'make-instance |
64 | (gethash (class-of container) *container-to-child-class-mappings*) |
65 | :parent container :child widget args)))) |
66 | |
e5b416f0 |
67 | (defbinding %container-remove () nil |
560af5c5 |
68 | (container container) |
69 | (widget widget)) |
70 | |
f9e76ebe |
71 | (defmethod container-remove ((container container) (widget widget)) |
e5b416f0 |
72 | (%container-remove container widget) |
c289d084 |
73 | (slot-makunbound widget 'child-properties)) |
e5b416f0 |
74 | |
75 | |
1f518a51 |
76 | (defbinding %container-child-get-property () nil |
77 | (container container) |
78 | (child widget) |
79 | (property-name string) |
80 | (value gvalue)) |
81 | |
82 | (defbinding %container-child-set-property () nil |
83 | (container container) |
84 | (child widget) |
85 | (property-name string) |
86 | (value gvalue)) |
87 | |
88 | |
0d270bd9 |
89 | (defbinding container-check-resize () nil |
560af5c5 |
90 | (container container)) |
91 | |
56ccd5b7 |
92 | (define-callback-marshal %foreach-callback nil (widget)) |
1de3a418 |
93 | |
94 | (defbinding %container-foreach (container callback-id) nil |
560af5c5 |
95 | (container container) |
56ccd5b7 |
96 | (%foreach-callback callback) |
1de3a418 |
97 | (callback-id unsigned-int)) |
98 | |
99 | (defun container-foreach (container function) |
1a1949c7 |
100 | (with-callback-function (id function) |
101 | (%container-foreach container id))) |
560af5c5 |
102 | |
d2ba9d86 |
103 | (defbinding %container-forall (container callback-id) nil |
104 | (container container) |
56ccd5b7 |
105 | (%foreach-callback callback) |
d2ba9d86 |
106 | (callback-id unsigned-int)) |
107 | |
108 | (defun container-forall (container function) |
109 | (with-callback-function (id function) |
110 | (%container-forall container id))) |
111 | |
560af5c5 |
112 | (defun map-container (seqtype func container) |
113 | (case seqtype |
114 | ((nil) |
1047e159 |
115 | (container-foreach container func) |
560af5c5 |
116 | nil) |
117 | (list |
118 | (let ((list nil)) |
1de3a418 |
119 | (container-foreach |
560af5c5 |
120 | container |
121 | #'(lambda (child) |
122 | (push (funcall func child) list))) |
123 | (nreverse list))) |
124 | (t |
1de3a418 |
125 | (let ((seq (make-sequence seqtype (container-length container))) |
560af5c5 |
126 | (index 0)) |
1de3a418 |
127 | (container-foreach |
560af5c5 |
128 | container |
129 | #'(lambda (child) |
130 | (setf (elt seq index) (funcall func child)) |
131 | (incf index))) |
132 | seq)))) |
133 | |
e5b416f0 |
134 | (defmethod container-children ((container container)) |
1de3a418 |
135 | (map-container 'list #'identity container)) |
e5b416f0 |
136 | |
137 | (defmethod (setf container-children) (children (container container)) |
560af5c5 |
138 | (dolist (child (container-children container)) |
139 | (container-remove container child)) |
140 | (dolist (child children) |
d2ba9d86 |
141 | (apply #'container-add container (mklist child))) |
560af5c5 |
142 | children) |
143 | |
1de3a418 |
144 | (defun container-length (container) |
145 | (let ((n 0)) |
146 | (container-foreach container |
147 | #'(lambda (child) |
148 | (declare (ignore child)) |
149 | (incf n))) |
150 | n)) |
560af5c5 |
151 | |
0d270bd9 |
152 | (defbinding container-resize-children () nil |
560af5c5 |
153 | (container container)) |
1de3a418 |
154 | |
155 | (defbinding container-propagate-expose () nil |
156 | (container container) |
157 | (child widget) |
158 | (event gdk:expose-event)) |
159 | |
160 | |
161 | (defbinding %container-get-focus-chain () boolean |
162 | (container container) |
163 | (focusable-widgets (glist widget) :out)) |
164 | |
165 | (defun container-focus-chain (container) |
166 | (multiple-value-bind (chain-set-p focusable-widgets) |
167 | (%container-get-focus-chain container) |
168 | (and chain-set-p focusable-widgets))) |
169 | |
170 | (defbinding %container-set-focus-chain () nil |
171 | (container container) |
172 | (focusable-widgets (glist widget))) |
173 | |
174 | (defbinding %container-unset-focus-chain () nil |
175 | (container container)) |
176 | |
177 | (defun (setf container-focus-chain) (focusable-widgets container) |
178 | (if (null focusable-widgets) |
179 | (%container-unset-focus-chain container) |
180 | (%container-set-focus-chain container focusable-widgets))) |
67b44e86 |
181 | |
182 | (defgeneric container-show-recursive (container)) |
183 | |
184 | (defmethod container-show-recursive ((container container)) |
185 | "Recursively shows any child widgets except widgets explicit hidden during construction." |
186 | (labels ((recursive-show (widget) |
187 | (when (typep widget 'container) |
188 | (if (not (user-data-p widget 'show-recursive-p)) |
189 | (container-foreach widget #'recursive-show) |
190 | (unset-user-data widget 'show-recursive-p))) |
191 | (unless (widget-hidden-p widget) |
192 | (widget-show widget)))) |
193 | (container-foreach container #'recursive-show))) |