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