chiark / gitweb /
Updated for CMUCL 19a and glib-2.4. Lots of improvements
[clg] / gtk / gtkcontainer.lisp
1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2000 Espen S. Johnsen <esj@stud.cs.uit.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
18 ;; $Id: gtkcontainer.lisp,v 1.9 2004-10-31 12:05:52 espen Exp $
19
20 (in-package "GTK")
21             
22 (defmethod shared-initialize ((container container) names &rest initargs 
23                               &key child children child-args)
24   (declare (ignore child))
25   (call-next-method)
26   (dolist (child (append children (get-all initargs :child)))
27     (apply #'container-add container (append (mklist child) child-args))))
28
29
30 (defbinding %container-add () nil
31   (container container)
32   (widget widget))
33
34 (defmethod container-add ((container container) (widget widget) &rest args)
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
46   (container container)
47   (widget widget))
48
49 (defmethod container-remove ((container container) (widget widget))
50   (%container-remove container widget)
51   (slot-makunbound widget 'child-slots))
52
53
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
67 (defbinding container-check-resize () nil
68   (container container))
69
70 (defvar *callback-marshal*
71   (system:foreign-symbol-address "gtk_callback_marshal"))
72
73 (defbinding %container-foreach (container callback-id) nil
74   (container container)
75   (*callback-marshal* pointer)
76   (callback-id unsigned-int))
77
78 (defun container-foreach (container function)
79   (let ((callback-id (register-callback-function function)))
80     (unwind-protect
81         (%container-foreach container callback-id)
82       (destroy-user-data callback-id))))
83
84 (defun map-container (seqtype func container)
85   (case seqtype
86     ((nil)
87      (container-foreach container func)
88      nil)
89     (list
90      (let ((list nil))
91        (container-foreach
92         container
93         #'(lambda (child)
94             (push (funcall func child) list)))
95        (nreverse list)))
96     (t
97      (let ((seq (make-sequence seqtype (container-length container)))
98            (index 0))
99        (container-foreach
100         container
101         #'(lambda (child)
102             (setf (elt seq index) (funcall func child))
103             (incf index)))
104        seq))))
105
106 (defmacro do-container ((var container &optional (result nil)) &body body)
107   (let ((continue (make-symbol "CONTINUE")))
108     `(let ((,continue t))
109        (container-foreach
110         ,container
111         #'(lambda (,var)
112             (when ,continue
113               (setq ,continue nil)
114               (block nil
115                 ,@body
116                 (setq ,continue t)))))
117        ,result)))
118
119 ;; (defbinding %container-get-children () (glist widget)
120 ;;   (container container))
121
122 (defmethod container-children ((container container))
123 ;;   (%container-get-children container)
124   (map-container 'list #'identity container))
125
126 (defmethod (setf container-children) (children (container container))
127   (dolist (child (container-children container))
128     (container-remove container child))
129   (dolist (child children)
130     (container-add container child))
131   children)
132
133 (defun container-length (container)
134   (let ((n 0))
135     (container-foreach container
136      #'(lambda (child)
137          (declare (ignore child))
138          (incf n)))
139     n))
140
141 (defbinding container-resize-children () nil
142   (container container))
143
144 (defbinding container-propagate-expose () nil
145   (container container)
146   (child widget)
147   (event gdk:expose-event))
148
149
150 (defbinding %container-get-focus-chain () boolean
151   (container container)
152   (focusable-widgets (glist widget) :out))
153
154 (defun container-focus-chain (container)
155   (multiple-value-bind (chain-set-p focusable-widgets)
156       (%container-get-focus-chain container)
157     (and chain-set-p focusable-widgets)))
158
159 (defbinding %container-set-focus-chain () nil
160   (container container)
161   (focusable-widgets (glist widget)))
162
163 (defbinding %container-unset-focus-chain () nil
164   (container container))
165
166 (defun (setf container-focus-chain) (focusable-widgets container)
167   (if (null focusable-widgets)
168       (%container-unset-focus-chain container)
169     (%container-set-focus-chain container focusable-widgets)))