chiark / gitweb /
Added statusbar example
[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
e295d6df 18;; $Id: gdk.lisp,v 1.10 2004/10/31 11:51:08 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
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
0d07716f 57
5515cd18 58(defbinding (events-pending-p "gdk_events_pending") () boolean)
0d07716f 59
5515cd18 60(defbinding event-get () event)
0d07716f 61
5515cd18 62(defbinding event-peek () event)
0d07716f 63
5515cd18 64(defbinding event-get-graphics-expose () event
0d07716f 65 (window window))
66
5515cd18 67(defbinding event-put () event
0d07716f 68 (event event))
69
5515cd18 70;(defbinding event-handler-set () ...)
0d07716f 71
5515cd18 72(defbinding set-show-events () nil
0d07716f 73 (show-events boolean))
74
75;;; Misc
76
5515cd18 77(defbinding set-use-xshm () nil
0d07716f 78 (use-xshm boolean))
79
5515cd18 80(defbinding get-show-events () boolean)
0d07716f 81
5515cd18 82(defbinding get-use-xshm () boolean)
0d07716f 83
5515cd18 84(defbinding get-display () string)
0d07716f 85
5515cd18 86; (defbinding time-get () (unsigned 32))
0d07716f 87
5515cd18 88; (defbinding timer-get () (unsigned 32))
0d07716f 89
5515cd18 90; (defbinding timer-set () nil
0d07716f 91; (milliseconds (unsigned 32)))
92
5515cd18 93; (defbinding timer-enable () nil)
0d07716f 94
5515cd18 95; (defbinding timer-disable () nil)
0d07716f 96
97; input ...
98
5515cd18 99(defbinding pointer-grab () int
0d07716f 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
5515cd18 107(defbinding pointer-ungrab () nil
0d07716f 108 (time (unsigned 32)))
109
5515cd18 110(defbinding keyboard-grab () int
0d07716f 111 (window window)
112 (owner-events boolean)
113 (time (unsigned 32)))
114
5515cd18 115(defbinding keyboard-ungrab () nil
0d07716f 116 (time (unsigned 32)))
117
5515cd18 118(defbinding (pointer-is-grabbed-p "gdk_pointer_is_grabbed") () boolean)
0d07716f 119
5515cd18 120(defbinding screen-width () int)
121(defbinding screen-height () int)
0d07716f 122
5515cd18 123(defbinding screen-width-mm () int)
124(defbinding screen-height-mm () int)
0d07716f 125
5515cd18 126(defbinding flush () nil)
127(defbinding beep () nil)
0d07716f 128
129
130
131;;; Visuals
132
5515cd18 133(defbinding visual-get-best-depth () int)
0d07716f 134
5515cd18 135(defbinding visual-get-best-type () visual-type)
0d07716f 136
5515cd18 137(defbinding visual-get-system () visual)
0d07716f 138
139
5515cd18 140(defbinding (%visual-get-best-with-nothing "gdk_visual_get_best") () visual)
0d07716f 141
5515cd18 142(defbinding %visual-get-best-with-depth () visual
0d07716f 143 (depth int))
144
5515cd18 145(defbinding %visual-get-best-with-type () visual
0d07716f 146 (type visual-type))
147
5515cd18 148(defbinding %visual-get-best-with-both () visual
0d07716f 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
5515cd18 159;(defbinding query-depths ..)
0d07716f 160
5515cd18 161;(defbinding query-visual-types ..)
0d07716f 162
5515cd18 163(defbinding list-visuals () (glist visual))
0d07716f 164
165
166;;; Windows
167
5515cd18 168; (defbinding window-new ... )
0d07716f 169
5515cd18 170(defbinding window-destroy () nil
0d07716f 171 (window window))
172
173
5515cd18 174; (defbinding window-at-pointer () window
0d07716f 175; (window window)
176; (x int :in-out)
177; (y int :in-out))
178
5515cd18 179(defbinding window-show () nil
0d07716f 180 (window window))
181
5515cd18 182(defbinding window-hide () nil
0d07716f 183 (window window))
184
5515cd18 185(defbinding window-withdraw () nil
0d07716f 186 (window window))
187
5515cd18 188(defbinding window-move () nil
0d07716f 189 (window window)
190 (x int)
191 (y int))
192
5515cd18 193(defbinding window-resize () nil
0d07716f 194 (window window)
195 (width int)
196 (height int))
197
5515cd18 198(defbinding window-move-resize () nil
0d07716f 199 (window window)
200 (x int)
201 (y int)
202 (width int)
203 (height int))
204
5515cd18 205(defbinding window-reparent () nil
0d07716f 206 (window window)
207 (new-parent window)
208 (x int)
209 (y int))
210
5515cd18 211(defbinding window-clear () nil
0d07716f 212 (window window))
213
214(unexport
215 '(window-clear-area-no-e window-clear-area-e))
216
5515cd18 217(defbinding (window-clear-area-no-e "gdk_window_clear_area") () nil
0d07716f 218 (window window)
219 (x int) (y int) (width int) (height int))
220
5515cd18 221(defbinding window-clear-area-e () nil
0d07716f 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
5515cd18 230; (defbinding window-copy-area () nil
0d07716f 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
5515cd18 241(defbinding window-raise () nil
0d07716f 242 (window window))
243
5515cd18 244(defbinding window-lower () nil
0d07716f 245 (window window))
246
5515cd18 247; (defbinding window-set-user-data () nil
0d07716f 248
5515cd18 249(defbinding window-set-override-redirect () nil
0d07716f 250 (window window)
251 (override-redirect boolean))
252
5515cd18 253; (defbinding window-add-filter () nil
0d07716f 254
5515cd18 255; (defbinding window-remove-filter () nil
0d07716f 256
5515cd18 257(defbinding window-shape-combine-mask () nil
0d07716f 258 (window window)
259 (shape-mask bitmap)
260 (offset-x int)
261 (offset-y int))
262
5515cd18 263(defbinding window-set-child-shapes () nil
0d07716f 264 (window window))
265
5515cd18 266(defbinding window-merge-child-shapes () nil
0d07716f 267 (window window))
268
5515cd18 269(defbinding (window-is-visible-p "gdk_window_is_visible") () boolean
0d07716f 270 (window window))
271
5515cd18 272(defbinding (window-is-viewable-p "gdk_window_is_viewable") () boolean
0d07716f 273 (window window))
274
5515cd18 275(defbinding window-set-static-gravities () boolean
0d07716f 276 (window window)
277 (use-static boolean))
278
5515cd18 279; (defbinding add-client-message-filter ...
0d07716f 280
281
282;;; Drag and Drop
283
0d07716f 284;; Destination side
285
5515cd18 286(defbinding drag-status () nil
0d07716f 287 (context drag-context)
288 (action drag-action)
289 (time (unsigned 32)))
290
291
292
293
5515cd18 294(defbinding window-set-cursor () nil
0d07716f 295 (window window)
296 (cursor cursor))
297
5515cd18 298(defbinding window-get-pointer () window
0d07716f 299 (window window)
300 (x int :out)
301 (y int :out)
302 (mask modifier-type :out))
303
402183fc 304(defbinding %get-default-root-window () window)
0d07716f 305
67824820 306(defun get-root-window (&optional display)
402183fc 307 (if display
308 (error "Not implemented")
309 (%get-default-root-window)))
0d07716f 310
311
312;;
313
5515cd18 314(defbinding rgb-init () nil)
0d07716f 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
5515cd18 330(defbinding cursor-new () cursor
0d07716f 331 (cursor-type cursor-type))
332
5515cd18 333(defbinding cursor-new-from-pixmap () cursor
0d07716f 334 (source pixmap)
335 (mask bitmap)
336 (foreground color)
337 (background color)
338 (x int) (y int))
339
5515cd18 340(defbinding %cursor-ref () pointer
0d07716f 341 (cursor (or cursor pointer)))
342
5515cd18 343(defbinding %cursor-unref () nil
0d07716f 344 (cursor (or cursor pointer)))
345
346
347
348;;; Pixmaps
402183fc 349
5515cd18 350(defbinding pixmap-new (width height depth &key window) pixmap
0d07716f 351 (width int)
352 (height int)
353 (depth int)
354 (window (or null window)))
355
5515cd18 356(defbinding %pixmap-colormap-create-from-xpm () pixmap
0d07716f 357 (window (or null window))
358 (colormap (or null colormap))
359 (mask bitmap :out)
360 (color (or null color))
361 (filename string))
362
5515cd18 363(defbinding %pixmap-colormap-create-from-xpm-d () pixmap
0d07716f 364 (window (or null window))
365 (colormap (or null colormap))
366 (mask bitmap :out)
367 (color (or null color))
b53669e6 368 (data (vector string)))
0d07716f 369
5a66b42b 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)
b53669e6 376 (etypecase source
5a66b42b 377 ((or string pathname)
378 (%pixmap-colormap-create-from-xpm
379 window colormap color (namestring (truename source))))
b53669e6 380 ((vector string)
381 (%pixmap-colormap-create-from-xpm-d window colormap color source)))
402183fc 382;; (unreference-instance pixmap)
383;; (unreference-instance mask)
5a66b42b 384 (values pixmap mask))))
402183fc 385
0d07716f 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
216bc8c3 396 &key red green blue)
0d07716f 397 (declare (ignore initargs))
398 (call-next-method)
399 (with-slots ((%red red) (%green green) (%blue blue)) color
400 (setf
216bc8c3 401 %red (%scale-value red)
402 %green (%scale-value green)
403 %blue (%scale-value blue))))
0d07716f 404
0d07716f 405(defun ensure-color (color)
406 (etypecase color
407 (null nil)
408 (color color)
216bc8c3 409 (vector
410 (make-instance
411 'color :red (svref color 0) :green (svref color 1)
412 :blue (svref color 2)))))
0d07716f 413
414
415
0d07716f 416;;; Drawing functions
417
5515cd18 418(defbinding draw-rectangle () nil
0d07716f 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
5515cd18 426(defbinding keyval-name () string
0d07716f 427 (keyval unsigned-int))
428
5515cd18 429(defbinding keyval-from-name () unsigned-int
0d07716f 430 (name string))
431
5515cd18 432(defbinding keyval-to-upper () unsigned-int
0d07716f 433 (keyval unsigned-int))
434
5515cd18 435(defbinding keyval-to-lower ()unsigned-int
0d07716f 436 (keyval unsigned-int))
437
5515cd18 438(defbinding (keyval-is-upper-p "gdk_keyval_is_upper") () boolean
0d07716f 439 (keyval unsigned-int))
440
5515cd18 441(defbinding (keyval-is-lower-p "gdk_keyval_is_lower") () boolean
0d07716f 442 (keyval unsigned-int))
443