chiark / gitweb /
Changes in widget initialization
[clg] / gtk / gtkwidget.lisp
1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2000-2001 Espen S. Johnsen <espen@users.sourceforge.net>
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: gtkwidget.lisp,v 1.6 2001-11-20 18:25:53 espen Exp $
19
20 (in-package "GTK")
21
22
23 (defmethod shared-initialize ((widget widget) names &rest initargs &key parent)
24   (declare (ignore initargs names))
25   (call-next-method)
26   (when parent
27     (let ((old-parent (widget-parent widget))
28           (parent-widget (first (mklist parent)))
29           (args (rest (mklist parent))))
30       (when old-parent
31         (container-remove old-parent widget))
32       (apply #'container-add parent-widget widget args))))
33
34 (defmethod shared-initialize :after ((widget widget) names &rest initargs
35                                      &key show-all)
36   (declare (ignore initargs names))
37   (when show-all
38     (widget-show-all widget)))
39
40
41 (defmethod slot-unbound ((class gobject-class) (object widget) slot)
42   (cond
43    ((and (eq slot 'child-slots) (slot-value object 'parent))
44     (with-slots (parent child-slots) object
45       (setf
46        child-slots
47        (make-instance
48         (gethash (class-of parent) *container-to-child-class-mappings*)
49         :parent parent :child object))))
50    (t (call-next-method))))
51
52
53 (defun child-slot-value (widget slot)
54   (slot-value (widget-child-slots widget) slot))
55
56 (defun (setf child-slot-value) (value widget slot)
57   (setf (slot-value (widget-child-slots widget) slot) value))
58
59 (defmacro with-child-slots (slots widget &body body)
60   `(with-slots ,slots (widget-child-slots ,widget)
61      ,@body))
62
63 (defmacro widget-destroyed (place)
64   `(setf ,place nil))
65
66 (defbinding widget-destroy () nil
67   (widget widget))
68
69 (defbinding widget-unparent () nil
70   (widget widget))
71
72 (defbinding widget-show () nil
73   (widget widget))
74
75 (defbinding widget-show-now () nil
76   (widget widget))
77
78 (defbinding widget-hide () nil
79   (widget widget))
80
81 (defbinding widget-show-all () nil
82   (widget widget))
83
84 (defbinding widget-hide-all () nil
85   (widget widget))
86
87 (defbinding widget-map () nil
88   (widget widget))
89
90 (defbinding widget-unmap () nil
91   (widget widget))
92
93 (defbinding widget-realize () nil
94   (widget widget))
95
96 (defbinding widget-unrealize () nil
97   (widget widget))
98
99 (defbinding widget-add-accelerator
100     (widget signal accel-group key modifiers flags) nil
101   (widget widget)
102   ((name-to-string signal) string)
103   (accel-group accel-group)
104   ((gdk:keyval-from-name key) unsigned-int)
105   (modifiers gdk:modifier-type)
106   (flags accel-flags))
107
108 (defbinding widget-remove-accelerator
109     (widget accel-group key modifiers) nil
110   (widget widget)
111   (accel-group accel-group)
112   ((gdk:keyval-from-name key) unsigned-int)
113   (modifiers gdk:modifier-type))
114
115 (defbinding widget-accelerator-signal
116     (widget accel-group key modifiers) unsigned-int
117   (widget widget)
118   (accel-group accel-group)
119   ((gdk:keyval-from-name key) unsigned-int)
120   (modifiers gdk:modifier-type))
121
122 (defbinding widget-lock-accelerators () nil
123   (widget widget))
124
125 (defbinding widget-unlock-accelerators () nil
126   (widget widget))
127
128 (defbinding (widget-accelerators-locked-p "gtk_widget_accelerators_locked")
129     () boolean
130   (widget widget))
131
132 (defbinding widget-event () int
133   (widget widget)
134   (event gdk:event))
135
136 (defbinding get-event-widget () widget
137   (event gdk:event))
138
139 (defbinding widget-activate () boolean
140   (widget widget))
141
142 (defbinding widget-set-scroll-adjustments () boolean
143   (widget widget)
144   (hadjustment adjustment)
145   (vadjustment adjustment))
146
147 (defbinding widget-reparent () nil
148   (widget widget)
149   (new-parent widget))
150
151 ; (defbinding widget-popup () nil
152 ;   (widget widget)
153 ;   (x int)
154 ;   (y int))
155
156 (defbinding widget-grab-focus () nil
157   (widget widget))
158
159 (defbinding widget-grab-default () nil
160   (widget widget))
161
162 (defbinding grab-add () nil
163   (widget widget))
164
165 (defbinding grab-get-current () widget)
166
167 (defbinding grab-remove () nil
168   (widget widget))
169
170 (defbinding widget-allocation () nil
171   (widget widget)
172   (width int :out)
173   (height int :out))
174
175 (defbinding widget-add-events () nil
176   (widget widget)
177   (events gdk:event-mask))
178
179 (defbinding (widget-toplevel "gtk_widget_get_toplevel") () widget
180   (widget widget))
181
182 (defbinding (widget-ancestor "gtk_widget_get_ancestor") (widget type) widget
183   (widget widget)
184   ((find-type-number type) type-number))
185
186 (defbinding (widget-pointer "gtk_widget_get_pointer") () nil
187   (widget widget)
188   (x int :out)
189   (y int :out))
190
191 (defbinding (widget-is-ancestor-p "gtk_widget_is_ancestor") () boolean
192   (widget widget)
193   (ancestor widget))
194
195 (defbinding widget-ensure-style () nil
196   (widget widget))
197
198 (defbinding widget-reset-rc-styles () nil
199   (widget widget))
200
201 (defun (setf widget-cursor) (cursor-type widget)
202   (let ((cursor (gdk:cursor-new cursor-type))
203         (window (widget-window widget)))
204     (gdk:window-set-cursor window cursor)
205     ;(gdk:cursor-destroy cursor)
206     ))
207
208 ;; Push/pop pairs, to change default values upon a widget's creation.
209 ;; This will override the values that got set by the
210 ;; widget-set-default-* functions.
211
212 (defbinding widget-push-colormap () nil
213   (colormap gdk:colormap))
214
215 (defbinding widget-push-composite-child () nil)
216
217 (defbinding widget-pop-colormap () nil)
218
219 (defbinding widget-pop-composite-child () nil)
220
221
222 ;; Set certain default values to be used at widget creation time.
223
224 (defbinding widget-set-default-colormap () nil
225   (colormap gdk:colormap))
226
227 (defbinding widget-get-default-style () style)
228
229 (defbinding widget-get-default-colormap () gdk:colormap)
230
231 (defbinding widget-shape-combine-mask () nil
232   (widget widget)
233   (shape-mask gdk:bitmap)
234   (x-offset int)
235   (y-offset int))
236
237 ;; defined in gtkglue.c
238 (defbinding widget-mapped-p () boolean
239   (widget widget))
240