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