chiark / gitweb /
Added new file gtkutils.lisp
[clg] / gtk / gtkcontainer.lisp
CommitLineData
560af5c5 1;; Common Lisp bindings for GTK+ v2.0
2;; Copyright (C) 2000 Espen S. Johnsen <espejohn@online.no>
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
0aaa4dc1 18;; $Id: gtkcontainer.lisp,v 1.2 2000-10-05 17:21: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
40
41
42(define-foreign ("gtk_container_child_getv" container-child-get-arg) () nil
43 (container container)
44 (child widget)
45 (1 unsigned-int)
46 (arg arg))
47
48(define-foreign ("gtk_container_child_setv" container-child-set-arg) () nil
49 (container container)
50 (child widget)
51 (1 unsigned-int)
52 (arg arg))
53
54(defun container-child-arg (container child name)
55 (with-gc-disabled
56 (let ((arg (arg-new 0)))
57 (setf (arg-name arg) name)
58 (container-child-get-arg container child arg) ; probably memory leak
59 (let ((type (type-from-number (arg-type arg))))
60 (prog1
61 (arg-value arg type)
62 (arg-free arg nil))))))
63
64(defun (setf container-child-arg) (value container child name)
65 (with-gc-disabled
66 (let ((arg (arg-new 0)))
67 (setf (arg-name arg) name)
68 (container-child-get-arg container child arg) ; probably memory leak
69 (let ((type (type-from-number (arg-type arg))))
70 (setf (arg-value arg type) value)
71 (container-child-set-arg container child arg)
72 (arg-free arg nil))))
73 value)
74
75
76(define-foreign container-add () nil
77 (container container)
78 (widget widget))
79
80(define-foreign container-remove () nil
81 (container container)
82 (widget widget))
83
84(define-foreign container-check-resize () nil
85 (container container))
86
87(define-foreign ("gtk_container_foreach_full" %container-foreach)
88 (container function) nil
89 (container container)
90 (0 unsigned-long)
91 (*callback-marshal* pointer)
92 ((register-callback-function function) unsigned-long)
93 (*destroy-marshal* pointer))
94
95(defun map-container (seqtype func container)
96 (case seqtype
97 ((nil)
98 (%container-foreach container func)
99 nil)
100 (list
101 (let ((list nil))
102 (%container-foreach
103 container
104 #'(lambda (child)
105 (push (funcall func child) list)))
106 (nreverse list)))
107 (t
108 (let ((seq (make-sequence seqtype (container-num-children container)))
109 (index 0))
110 (%container-foreach
111 container
112 #'(lambda (child)
113 (setf (elt seq index) (funcall func child))
114 (incf index)))
115 seq))))
116
117(defmacro do-container ((var container &optional (result nil)) &body body)
118 (let ((continue (make-symbol "CONTINUE")))
119 `(let ((,continue t))
120 (%container-foreach
121 ,container
122 #'(lambda (,var)
123 (when ,continue
124 (setq ,continue nil)
125 (block nil
126 ,@body
127 (setq ,continue t)))))
128 ,result)))
129
0aaa4dc1 130(define-foreign container-children () (glist widget)
560af5c5 131 (container container))
132
133(defun (setf container-children) (children container)
134 (dolist (child (container-children container))
135 (container-remove container child))
136 (dolist (child children)
137 (container-add container child))
138 children)
139
140;; Should be implemented as a foreign function
141(defun container-num-children (container)
142 (length (container-children container)))
143
144(define-foreign container-resize-children () nil
145 (container container))