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 | |
1a1949c7 |
18 | ;; $Id: gtkcontainer.lisp,v 1.12 2004-11-07 17:55:29 espen Exp $ |
560af5c5 |
19 | |
20 | (in-package "GTK") |
0f2634d2 |
21 | |
1047e159 |
22 | (defmethod shared-initialize ((container container) names &rest initargs |
23 | &key child children child-args) |
24 | (declare (ignore child)) |
560af5c5 |
25 | (call-next-method) |
1047e159 |
26 | (dolist (child (append children (get-all initargs :child))) |
27 | (apply #'container-add container (append (mklist child) child-args)))) |
560af5c5 |
28 | |
560af5c5 |
29 | |
e5b416f0 |
30 | (defbinding %container-add () nil |
560af5c5 |
31 | (container container) |
32 | (widget widget)) |
33 | |
f9e76ebe |
34 | (defmethod container-add ((container container) (widget widget) &rest args) |
e5b416f0 |
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 |
560af5c5 |
46 | (container container) |
47 | (widget widget)) |
48 | |
f9e76ebe |
49 | (defmethod container-remove ((container container) (widget widget)) |
e5b416f0 |
50 | (%container-remove container widget) |
51 | (slot-makunbound widget 'child-slots)) |
52 | |
53 | |
1f518a51 |
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 | |
0d270bd9 |
67 | (defbinding container-check-resize () nil |
560af5c5 |
68 | (container container)) |
69 | |
8755b1a5 |
70 | (def-callback-marshal %foreach-callback (nil widget)) |
1de3a418 |
71 | |
72 | (defbinding %container-foreach (container callback-id) nil |
560af5c5 |
73 | (container container) |
34f9e1d4 |
74 | ((callback %foreach-callback) pointer) |
1de3a418 |
75 | (callback-id unsigned-int)) |
76 | |
77 | (defun container-foreach (container function) |
1a1949c7 |
78 | (with-callback-function (id function) |
79 | (%container-foreach container id))) |
560af5c5 |
80 | |
81 | (defun map-container (seqtype func container) |
82 | (case seqtype |
83 | ((nil) |
1047e159 |
84 | (container-foreach container func) |
560af5c5 |
85 | nil) |
86 | (list |
87 | (let ((list nil)) |
1de3a418 |
88 | (container-foreach |
560af5c5 |
89 | container |
90 | #'(lambda (child) |
91 | (push (funcall func child) list))) |
92 | (nreverse list))) |
93 | (t |
1de3a418 |
94 | (let ((seq (make-sequence seqtype (container-length container))) |
560af5c5 |
95 | (index 0)) |
1de3a418 |
96 | (container-foreach |
560af5c5 |
97 | container |
98 | #'(lambda (child) |
99 | (setf (elt seq index) (funcall func child)) |
100 | (incf index))) |
101 | seq)))) |
102 | |
103 | (defmacro do-container ((var container &optional (result nil)) &body body) |
104 | (let ((continue (make-symbol "CONTINUE"))) |
105 | `(let ((,continue t)) |
1de3a418 |
106 | (container-foreach |
560af5c5 |
107 | ,container |
108 | #'(lambda (,var) |
109 | (when ,continue |
110 | (setq ,continue nil) |
111 | (block nil |
112 | ,@body |
113 | (setq ,continue t))))) |
114 | ,result))) |
115 | |
1de3a418 |
116 | ;; (defbinding %container-get-children () (glist widget) |
117 | ;; (container container)) |
560af5c5 |
118 | |
e5b416f0 |
119 | (defmethod container-children ((container container)) |
1de3a418 |
120 | ;; (%container-get-children container) |
121 | (map-container 'list #'identity container)) |
e5b416f0 |
122 | |
123 | (defmethod (setf container-children) (children (container container)) |
560af5c5 |
124 | (dolist (child (container-children container)) |
125 | (container-remove container child)) |
126 | (dolist (child children) |
127 | (container-add container child)) |
128 | children) |
129 | |
1de3a418 |
130 | (defun container-length (container) |
131 | (let ((n 0)) |
132 | (container-foreach container |
133 | #'(lambda (child) |
134 | (declare (ignore child)) |
135 | (incf n))) |
136 | n)) |
560af5c5 |
137 | |
0d270bd9 |
138 | (defbinding container-resize-children () nil |
560af5c5 |
139 | (container container)) |
1de3a418 |
140 | |
141 | (defbinding container-propagate-expose () nil |
142 | (container container) |
143 | (child widget) |
144 | (event gdk:expose-event)) |
145 | |
146 | |
147 | (defbinding %container-get-focus-chain () boolean |
148 | (container container) |
149 | (focusable-widgets (glist widget) :out)) |
150 | |
151 | (defun container-focus-chain (container) |
152 | (multiple-value-bind (chain-set-p focusable-widgets) |
153 | (%container-get-focus-chain container) |
154 | (and chain-set-p focusable-widgets))) |
155 | |
156 | (defbinding %container-set-focus-chain () nil |
157 | (container container) |
158 | (focusable-widgets (glist widget))) |
159 | |
160 | (defbinding %container-unset-focus-chain () nil |
161 | (container container)) |
162 | |
163 | (defun (setf container-focus-chain) (focusable-widgets container) |
164 | (if (null focusable-widgets) |
165 | (%container-unset-focus-chain container) |
166 | (%container-set-focus-chain container focusable-widgets))) |