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 | |
d2ba9d86 |
18 | ;; $Id: gtkcontainer.lisp,v 1.15 2004-12-29 21:14:23 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 | |
e5b416f0 |
33 | (defbinding %container-add () nil |
560af5c5 |
34 | (container container) |
35 | (widget widget)) |
36 | |
f9e76ebe |
37 | (defmethod container-add ((container container) (widget widget) &rest args) |
e5b416f0 |
38 | (%container-add container widget) |
39 | (when args |
40 | (setf |
c289d084 |
41 | (slot-value widget 'child-properties) |
e5b416f0 |
42 | (apply |
43 | #'make-instance |
44 | (gethash (class-of container) *container-to-child-class-mappings*) |
45 | :parent container :child widget args)))) |
46 | |
47 | |
48 | (defbinding %container-remove () nil |
560af5c5 |
49 | (container container) |
50 | (widget widget)) |
51 | |
f9e76ebe |
52 | (defmethod container-remove ((container container) (widget widget)) |
e5b416f0 |
53 | (%container-remove container widget) |
c289d084 |
54 | (slot-makunbound widget 'child-properties)) |
e5b416f0 |
55 | |
56 | |
1f518a51 |
57 | (defbinding %container-child-get-property () nil |
58 | (container container) |
59 | (child widget) |
60 | (property-name string) |
61 | (value gvalue)) |
62 | |
63 | (defbinding %container-child-set-property () nil |
64 | (container container) |
65 | (child widget) |
66 | (property-name string) |
67 | (value gvalue)) |
68 | |
69 | |
0d270bd9 |
70 | (defbinding container-check-resize () nil |
560af5c5 |
71 | (container container)) |
72 | |
8755b1a5 |
73 | (def-callback-marshal %foreach-callback (nil widget)) |
1de3a418 |
74 | |
75 | (defbinding %container-foreach (container callback-id) nil |
560af5c5 |
76 | (container container) |
34f9e1d4 |
77 | ((callback %foreach-callback) pointer) |
1de3a418 |
78 | (callback-id unsigned-int)) |
79 | |
80 | (defun container-foreach (container function) |
1a1949c7 |
81 | (with-callback-function (id function) |
82 | (%container-foreach container id))) |
560af5c5 |
83 | |
d2ba9d86 |
84 | (defbinding %container-forall (container callback-id) nil |
85 | (container container) |
86 | ((callback %foreach-callback) pointer) |
87 | (callback-id unsigned-int)) |
88 | |
89 | (defun container-forall (container function) |
90 | (with-callback-function (id function) |
91 | (%container-forall container id))) |
92 | |
560af5c5 |
93 | (defun map-container (seqtype func container) |
94 | (case seqtype |
95 | ((nil) |
1047e159 |
96 | (container-foreach container func) |
560af5c5 |
97 | nil) |
98 | (list |
99 | (let ((list nil)) |
1de3a418 |
100 | (container-foreach |
560af5c5 |
101 | container |
102 | #'(lambda (child) |
103 | (push (funcall func child) list))) |
104 | (nreverse list))) |
105 | (t |
1de3a418 |
106 | (let ((seq (make-sequence seqtype (container-length container))) |
560af5c5 |
107 | (index 0)) |
1de3a418 |
108 | (container-foreach |
560af5c5 |
109 | container |
110 | #'(lambda (child) |
111 | (setf (elt seq index) (funcall func child)) |
112 | (incf index))) |
113 | seq)))) |
114 | |
e5b416f0 |
115 | (defmethod container-children ((container container)) |
1de3a418 |
116 | (map-container 'list #'identity container)) |
e5b416f0 |
117 | |
118 | (defmethod (setf container-children) (children (container container)) |
560af5c5 |
119 | (dolist (child (container-children container)) |
120 | (container-remove container child)) |
121 | (dolist (child children) |
d2ba9d86 |
122 | (apply #'container-add container (mklist child))) |
560af5c5 |
123 | children) |
124 | |
1de3a418 |
125 | (defun container-length (container) |
126 | (let ((n 0)) |
127 | (container-foreach container |
128 | #'(lambda (child) |
129 | (declare (ignore child)) |
130 | (incf n))) |
131 | n)) |
560af5c5 |
132 | |
0d270bd9 |
133 | (defbinding container-resize-children () nil |
560af5c5 |
134 | (container container)) |
1de3a418 |
135 | |
136 | (defbinding container-propagate-expose () nil |
137 | (container container) |
138 | (child widget) |
139 | (event gdk:expose-event)) |
140 | |
141 | |
142 | (defbinding %container-get-focus-chain () boolean |
143 | (container container) |
144 | (focusable-widgets (glist widget) :out)) |
145 | |
146 | (defun container-focus-chain (container) |
147 | (multiple-value-bind (chain-set-p focusable-widgets) |
148 | (%container-get-focus-chain container) |
149 | (and chain-set-p focusable-widgets))) |
150 | |
151 | (defbinding %container-set-focus-chain () nil |
152 | (container container) |
153 | (focusable-widgets (glist widget))) |
154 | |
155 | (defbinding %container-unset-focus-chain () nil |
156 | (container container)) |
157 | |
158 | (defun (setf container-focus-chain) (focusable-widgets container) |
159 | (if (null focusable-widgets) |
160 | (%container-unset-focus-chain container) |
161 | (%container-set-focus-chain container focusable-widgets))) |