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