chiark / gitweb /
Fixed gvalue leakage
[clg] / gdk / gdk.lisp
CommitLineData
8bb8ead0 1;; Common Lisp bindings for GTK+ v2.0
2;; Copyright (C) 1999-2001 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
bc9997e8 18;; $Id: gdk.lisp,v 1.8 2004-10-28 09:28:25 espen Exp $
560af5c5 19
20
21(in-package "GDK")
22
23
24;;; Events
25
7d56481e 26(defbinding connection-number () int)
560af5c5 27
8bb8ead0 28(defbinding (events-pending-p "gdk_events_pending") () boolean)
560af5c5 29
8bb8ead0 30(defbinding event-get () event)
560af5c5 31
8bb8ead0 32(defbinding event-peek () event)
560af5c5 33
8bb8ead0 34(defbinding event-get-graphics-expose () event
560af5c5 35 (window window))
36
8bb8ead0 37(defbinding event-put () event
560af5c5 38 (event event))
39
8bb8ead0 40;(defbinding event-handler-set () ...)
560af5c5 41
8bb8ead0 42(defbinding set-show-events () nil
560af5c5 43 (show-events boolean))
44
45;;; Misc
46
8bb8ead0 47(defbinding set-use-xshm () nil
560af5c5 48 (use-xshm boolean))
49
8bb8ead0 50(defbinding get-show-events () boolean)
560af5c5 51
8bb8ead0 52(defbinding get-use-xshm () boolean)
560af5c5 53
8bb8ead0 54(defbinding get-display () string)
560af5c5 55
8bb8ead0 56; (defbinding time-get () (unsigned 32))
560af5c5 57
8bb8ead0 58; (defbinding timer-get () (unsigned 32))
560af5c5 59
8bb8ead0 60; (defbinding timer-set () nil
560af5c5 61; (milliseconds (unsigned 32)))
62
8bb8ead0 63; (defbinding timer-enable () nil)
560af5c5 64
8bb8ead0 65; (defbinding timer-disable () nil)
560af5c5 66
67; input ...
68
8bb8ead0 69(defbinding pointer-grab () int
560af5c5 70 (window window)
71 (owner-events boolean)
72 (event-mask event-mask)
73 (confine-to (or null window))
74 (cursor (or null cursor))
75 (time (unsigned 32)))
76
8bb8ead0 77(defbinding pointer-ungrab () nil
560af5c5 78 (time (unsigned 32)))
79
8bb8ead0 80(defbinding keyboard-grab () int
560af5c5 81 (window window)
82 (owner-events boolean)
83 (time (unsigned 32)))
84
8bb8ead0 85(defbinding keyboard-ungrab () nil
560af5c5 86 (time (unsigned 32)))
87
8bb8ead0 88(defbinding (pointer-is-grabbed-p "gdk_pointer_is_grabbed") () boolean)
560af5c5 89
8bb8ead0 90(defbinding screen-width () int)
91(defbinding screen-height () int)
560af5c5 92
8bb8ead0 93(defbinding screen-width-mm () int)
94(defbinding screen-height-mm () int)
560af5c5 95
8bb8ead0 96(defbinding flush () nil)
97(defbinding beep () nil)
560af5c5 98
99
100
101;;; Visuals
102
8bb8ead0 103(defbinding visual-get-best-depth () int)
560af5c5 104
8bb8ead0 105(defbinding visual-get-best-type () visual-type)
560af5c5 106
8bb8ead0 107(defbinding visual-get-system () visual)
560af5c5 108
109
8bb8ead0 110(defbinding (%visual-get-best-with-nothing "gdk_visual_get_best") () visual)
560af5c5 111
8bb8ead0 112(defbinding %visual-get-best-with-depth () visual
560af5c5 113 (depth int))
114
8bb8ead0 115(defbinding %visual-get-best-with-type () visual
560af5c5 116 (type visual-type))
117
8bb8ead0 118(defbinding %visual-get-best-with-both () visual
560af5c5 119 (depth int)
120 (type visual-type))
121
122(defun visual-get-best (&key depth type)
123 (cond
124 ((and depth type) (%visual-get-best-with-both depth type))
125 (depth (%visual-get-best-with-depth depth))
126 (type (%visual-get-best-with-type type))
127 (t (%visual-get-best-with-nothing))))
128
8bb8ead0 129;(defbinding query-depths ..)
560af5c5 130
8bb8ead0 131;(defbinding query-visual-types ..)
560af5c5 132
8bb8ead0 133(defbinding list-visuals () (glist visual))
560af5c5 134
135
136;;; Windows
137
8bb8ead0 138; (defbinding window-new ... )
560af5c5 139
8bb8ead0 140(defbinding window-destroy () nil
560af5c5 141 (window window))
142
143
8bb8ead0 144; (defbinding window-at-pointer () window
560af5c5 145; (window window)
146; (x int :in-out)
147; (y int :in-out))
148
8bb8ead0 149(defbinding window-show () nil
560af5c5 150 (window window))
151
8bb8ead0 152(defbinding window-hide () nil
560af5c5 153 (window window))
154
8bb8ead0 155(defbinding window-withdraw () nil
560af5c5 156 (window window))
157
8bb8ead0 158(defbinding window-move () nil
560af5c5 159 (window window)
160 (x int)
161 (y int))
162
8bb8ead0 163(defbinding window-resize () nil
560af5c5 164 (window window)
165 (width int)
166 (height int))
167
8bb8ead0 168(defbinding window-move-resize () nil
560af5c5 169 (window window)
170 (x int)
171 (y int)
172 (width int)
173 (height int))
174
8bb8ead0 175(defbinding window-reparent () nil
560af5c5 176 (window window)
177 (new-parent window)
178 (x int)
179 (y int))
180
8bb8ead0 181(defbinding window-clear () nil
560af5c5 182 (window window))
183
184(unexport
185 '(window-clear-area-no-e window-clear-area-e))
186
8bb8ead0 187(defbinding (window-clear-area-no-e "gdk_window_clear_area") () nil
560af5c5 188 (window window)
189 (x int) (y int) (width int) (height int))
190
8bb8ead0 191(defbinding window-clear-area-e () nil
560af5c5 192 (window window)
193 (x int) (y int) (width int) (height int))
194
195(defun window-clear-area (window x y width height &optional expose)
196 (if expose
197 (window-clear-area-e window x y width height)
198 (window-clear-area-no-e window x y width height)))
199
8bb8ead0 200; (defbinding window-copy-area () nil
560af5c5 201; (window window)
202; (gc gc)
203; (x int)
204; (y int)
205; (source-window window)
206; (source-x int)
207; (source-y int)
208; (width int)
209; (height int))
210
8bb8ead0 211(defbinding window-raise () nil
560af5c5 212 (window window))
213
8bb8ead0 214(defbinding window-lower () nil
560af5c5 215 (window window))
216
8bb8ead0 217; (defbinding window-set-user-data () nil
560af5c5 218
8bb8ead0 219(defbinding window-set-override-redirect () nil
560af5c5 220 (window window)
221 (override-redirect boolean))
222
8bb8ead0 223; (defbinding window-add-filter () nil
560af5c5 224
8bb8ead0 225; (defbinding window-remove-filter () nil
560af5c5 226
8bb8ead0 227(defbinding window-shape-combine-mask () nil
560af5c5 228 (window window)
229 (shape-mask bitmap)
230 (offset-x int)
231 (offset-y int))
232
8bb8ead0 233(defbinding window-set-child-shapes () nil
560af5c5 234 (window window))
235
8bb8ead0 236(defbinding window-merge-child-shapes () nil
560af5c5 237 (window window))
238
8bb8ead0 239(defbinding (window-is-visible-p "gdk_window_is_visible") () boolean
560af5c5 240 (window window))
241
8bb8ead0 242(defbinding (window-is-viewable-p "gdk_window_is_viewable") () boolean
560af5c5 243 (window window))
244
8bb8ead0 245(defbinding window-set-static-gravities () boolean
560af5c5 246 (window window)
247 (use-static boolean))
248
8bb8ead0 249; (defbinding add-client-message-filter ...
560af5c5 250
251
252;;; Drag and Drop
253
560af5c5 254;; Destination side
255
8bb8ead0 256(defbinding drag-status () nil
560af5c5 257 (context drag-context)
258 (action drag-action)
259 (time (unsigned 32)))
260
261
262
263
8bb8ead0 264(defbinding window-set-cursor () nil
560af5c5 265 (window window)
266 (cursor cursor))
267
8bb8ead0 268(defbinding window-get-pointer () window
560af5c5 269 (window window)
270 (x int :out)
271 (y int :out)
272 (mask modifier-type :out))
273
bc9997e8 274(defbinding %get-default-root-window () window)
560af5c5 275
bc9997e8 276(defun get-root-window (%optional display)
277 (if display
278 (error "Not implemented")
279 (%get-default-root-window)))
560af5c5 280
281
282;;
283
8bb8ead0 284(defbinding rgb-init () nil)
560af5c5 285
286
287
288
289;;; Cursor
290
291(deftype-method alien-ref cursor (type-spec)
292 (declare (ignore type-spec))
293 '%cursor-ref)
294
295(deftype-method alien-unref cursor (type-spec)
296 (declare (ignore type-spec))
297 '%cursor-unref)
298
299
8bb8ead0 300(defbinding cursor-new () cursor
560af5c5 301 (cursor-type cursor-type))
302
8bb8ead0 303(defbinding cursor-new-from-pixmap () cursor
560af5c5 304 (source pixmap)
305 (mask bitmap)
306 (foreground color)
307 (background color)
308 (x int) (y int))
309
8bb8ead0 310(defbinding %cursor-ref () pointer
560af5c5 311 (cursor (or cursor pointer)))
312
8bb8ead0 313(defbinding %cursor-unref () nil
560af5c5 314 (cursor (or cursor pointer)))
315
316
317
318;;; Pixmaps
bc9997e8 319
8bb8ead0 320(defbinding pixmap-new (width height depth &key window) pixmap
560af5c5 321 (width int)
322 (height int)
323 (depth int)
324 (window (or null window)))
325
8bb8ead0 326(defbinding %pixmap-colormap-create-from-xpm () pixmap
560af5c5 327 (window (or null window))
328 (colormap (or null colormap))
329 (mask bitmap :out)
330 (color (or null color))
331 (filename string))
332
8bb8ead0 333(defbinding %pixmap-colormap-create-from-xpm-d () pixmap
560af5c5 334 (window (or null window))
335 (colormap (or null colormap))
336 (mask bitmap :out)
337 (color (or null color))
2a189a9e 338 (data (vector string)))
560af5c5 339
bb110f5f 340(defun pixmap-create (source &key color window colormap)
341 (let ((window
342 (if (not (or window colormap))
343 (get-root-window)
344 window)))
345 (multiple-value-bind (pixmap mask)
2a189a9e 346 (etypecase source
bb110f5f 347 ((or string pathname)
348 (%pixmap-colormap-create-from-xpm
349 window colormap color (namestring (truename source))))
2a189a9e 350 ((vector string)
351 (%pixmap-colormap-create-from-xpm-d window colormap color source)))
bc9997e8 352;; (unreference-instance pixmap)
353;; (unreference-instance mask)
bb110f5f 354 (values pixmap mask))))
bc9997e8 355
560af5c5 356
357
358;;; Color
359
360(defun %scale-value (value)
361 (etypecase value
362 (integer value)
363 (float (truncate (* value 65535)))))
364
365(defmethod initialize-instance ((color color) &rest initargs
1ebfd3a6 366 &key red green blue)
560af5c5 367 (declare (ignore initargs))
368 (call-next-method)
369 (with-slots ((%red red) (%green green) (%blue blue)) color
370 (setf
1ebfd3a6 371 %red (%scale-value red)
372 %green (%scale-value green)
373 %blue (%scale-value blue))))
560af5c5 374
560af5c5 375(defun ensure-color (color)
376 (etypecase color
377 (null nil)
378 (color color)
1ebfd3a6 379 (vector
380 (make-instance
381 'color :red (svref color 0) :green (svref color 1)
382 :blue (svref color 2)))))
560af5c5 383
384
385
560af5c5 386;;; Drawing functions
387
8bb8ead0 388(defbinding draw-rectangle () nil
560af5c5 389 (drawable (or window pixmap bitmap))
390 (gc gc) (filled boolean)
391 (x int) (y int) (width int) (height int))
392
393
394;;; Key values
395
8bb8ead0 396(defbinding keyval-name () string
560af5c5 397 (keyval unsigned-int))
398
8bb8ead0 399(defbinding keyval-from-name () unsigned-int
560af5c5 400 (name string))
401
8bb8ead0 402(defbinding keyval-to-upper () unsigned-int
560af5c5 403 (keyval unsigned-int))
404
8bb8ead0 405(defbinding keyval-to-lower ()unsigned-int
560af5c5 406 (keyval unsigned-int))
407
8bb8ead0 408(defbinding (keyval-is-upper-p "gdk_keyval_is_upper") () boolean
560af5c5 409 (keyval unsigned-int))
410
8bb8ead0 411(defbinding (keyval-is-lower-p "gdk_keyval_is_lower") () boolean
560af5c5 412 (keyval unsigned-int))
413