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 | |
0d270bd9 |
18 | ;; $Id: gtkcontainer.lisp,v 1.3 2001-05-29 16:03:04 espen Exp $ |
560af5c5 |
19 | |
20 | (in-package "GTK") |
21 | |
560af5c5 |
22 | |
23 | (defmethod initialize-instance ((container container) &rest initargs |
24 | &key children) |
25 | (declare (ignore initargs)) |
26 | (call-next-method) |
27 | (dolist (child children) |
28 | (cond |
29 | ((consp child) |
30 | (container-add container (first child)) |
31 | (setf |
32 | (slot-value (first child) 'child-slots) |
33 | (apply |
34 | #'make-instance |
35 | (slot-value (class-of container) 'child-class) |
36 | :parent container :child (first child) (cdr child)))) |
37 | (t |
38 | (container-add container child))))) |
39 | |
0d270bd9 |
40 | (defbinding %container-child-getv () nil |
560af5c5 |
41 | (container container) |
42 | (child widget) |
43 | (1 unsigned-int) |
44 | (arg arg)) |
45 | |
0d270bd9 |
46 | (defbinding %container-child-setv () nil |
560af5c5 |
47 | (container container) |
48 | (child widget) |
49 | (1 unsigned-int) |
50 | (arg arg)) |
0d270bd9 |
51 | |
560af5c5 |
52 | |
0d270bd9 |
53 | (defbinding container-add () nil |
560af5c5 |
54 | (container container) |
55 | (widget widget)) |
56 | |
0d270bd9 |
57 | (defbinding container-remove () nil |
560af5c5 |
58 | (container container) |
59 | (widget widget)) |
60 | |
0d270bd9 |
61 | (defbinding container-check-resize () nil |
560af5c5 |
62 | (container container)) |
63 | |
0d270bd9 |
64 | (defbinding (%container-foreach "gtk_container_foreach_full") |
560af5c5 |
65 | (container function) nil |
66 | (container container) |
67 | (0 unsigned-long) |
68 | (*callback-marshal* pointer) |
69 | ((register-callback-function function) unsigned-long) |
70 | (*destroy-marshal* pointer)) |
71 | |
72 | (defun map-container (seqtype func container) |
73 | (case seqtype |
74 | ((nil) |
75 | (%container-foreach container func) |
76 | nil) |
77 | (list |
78 | (let ((list nil)) |
79 | (%container-foreach |
80 | container |
81 | #'(lambda (child) |
82 | (push (funcall func child) list))) |
83 | (nreverse list))) |
84 | (t |
85 | (let ((seq (make-sequence seqtype (container-num-children container))) |
86 | (index 0)) |
87 | (%container-foreach |
88 | container |
89 | #'(lambda (child) |
90 | (setf (elt seq index) (funcall func child)) |
91 | (incf index))) |
92 | seq)))) |
93 | |
94 | (defmacro do-container ((var container &optional (result nil)) &body body) |
95 | (let ((continue (make-symbol "CONTINUE"))) |
96 | `(let ((,continue t)) |
97 | (%container-foreach |
98 | ,container |
99 | #'(lambda (,var) |
100 | (when ,continue |
101 | (setq ,continue nil) |
102 | (block nil |
103 | ,@body |
104 | (setq ,continue t))))) |
105 | ,result))) |
106 | |
0d270bd9 |
107 | (defbinding container-children () (glist widget) |
560af5c5 |
108 | (container container)) |
109 | |
110 | (defun (setf container-children) (children container) |
111 | (dolist (child (container-children container)) |
112 | (container-remove container child)) |
113 | (dolist (child children) |
114 | (container-add container child)) |
115 | children) |
116 | |
117 | ;; Should be implemented as a foreign function |
118 | (defun container-num-children (container) |
119 | (length (container-children container))) |
120 | |
0d270bd9 |
121 | (defbinding container-resize-children () nil |
560af5c5 |
122 | (container container)) |