chiark / gitweb /
Minor required changes
[clg] / gtk / gtkselection.lisp
1 ;; Common Lisp bindings for GTK+ v2.x
2 ;; Copyright 2005 Espen S. Johnsen <espen@users.sf.net>
3 ;;
4 ;; Permission is hereby granted, free of charge, to any person obtaining
5 ;; a copy of this software and associated documentation files (the
6 ;; "Software"), to deal in the Software without restriction, including
7 ;; without limitation the rights to use, copy, modify, merge, publish,
8 ;; distribute, sublicense, and/or sell copies of the Software, and to
9 ;; permit persons to whom the Software is furnished to do so, subject to
10 ;; the following conditions:
11 ;;
12 ;; The above copyright notice and this permission notice shall be
13 ;; included in all copies or substantial portions of the Software.
14 ;;
15 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23 ;; $Id: gtkselection.lisp,v 1.8 2006-04-10 18:54:47 espen Exp $
24
25
26 (in-package "GTK")
27
28
29 ;;;; Selection
30
31 (defbinding %target-list-ref () pointer
32   (location pointer))
33   
34 (defbinding %target-list-unref () nil
35   (location pointer))
36
37 (defmethod reference-foreign ((class (eql (find-class 'target-list))) location)
38   (declare (ignore class))
39   (%target-list-ref location))
40
41 (defmethod unreference-foreign ((class (eql (find-class 'target-list))) location)
42   (declare (ignore class))
43   (%target-list-unref location))
44
45 (defbinding %target-list-new () pointer
46   (targets (vector (inlined target-entry)))
47   ((length targets) int))
48   
49 (defmethod allocate-foreign ((target-list target-list) &key targets)
50   (%target-list-new targets))
51
52 (defbinding target-list-add (target-list target &optional flags info) nil
53   (target-list target-list)
54   (target gdk:atom)
55   (flags unsigned-int)
56   (info unsigned-int))
57
58 (defbinding target-list-add-table (target-list targets) nil
59   (target-list target-list)
60   ((etypecase targets 
61      ((or vector list) targets)
62      (target-entry (vector targets)))
63    (vector (inlined target-entry)))
64   ((etypecase targets 
65      ((or vector list) (length targets))
66      (target-entry 1))
67    int))
68
69 #+gtk2.6
70 (progn
71   (defbinding target-list-add-text-targets (target-list info &optional writable-p) nil
72     (target-list target-list)
73     (info unsigned-int)
74     (writable-p boolean))
75   
76   (defbinding target-list-add-image-targets (target-list info &optional writable-p) nil
77     (target-list target-list)
78     (info unsigned-int)
79     (writable-p boolean))
80
81   (defbinding target-list-add-uri-targets (target-list info &optional writable-p) nil
82     (target-list target-list)
83     (info unsigned-int)
84     (writable-p boolean)))
85
86 (defbinding target-list-remove () nil
87   (target-list target-list)
88   (target gdk:atom))
89
90 ;; (defbinding target-list-find () nil
91 ;;   (target-list target-list)
92 ;;   (target gdk:atom)
93 ;;   ...)
94
95 (defbinding (selection-set-owner "gtk_selection_owner_set_for_display")
96     (widget selection time &optional (display (gdk:display-get-default))) 
97     boolean
98   (display gdk:display)
99   (widget widget)
100   ((gdk:atom-intern selection) gdk:atom)
101   (time (unsigned 32)))
102
103 (defbinding selection-add-target () nil
104   (widget widget)
105   (selection gdk:atom)
106   (target gdk:atom)
107   (info unsigned-int))
108
109 (defbinding selection-add-targets (widget selection targets) nil
110   (widget widget)
111   (selection gdk:atom)
112   ((etypecase targets 
113      ((or vector list) targets)
114      (target-entry (vector targets)))
115    (vector (inlined target-entry)))
116   ((etypecase targets 
117      ((or vector list) (length targets))
118      (target-entry 1))
119    int))
120
121 (defbinding selection-clear-targets () nil
122   (widget widget)
123   (selection gdk:atom))
124
125 (defbinding selection-convert () boolean
126   (widget widget)
127   (selection gdk:atom)
128   (target gdk:atom)
129   (time unsigned-int))
130
131 (defbinding selection-data-set () boolean
132   (selection-data selection-data)
133   (type gdk:atom)
134   (format int)
135   (data pointer)
136   (length int))
137
138 (defbinding selection-data-set-text () boolean
139   (selection-data selection-data)
140   (text string)
141   (-1 integer))
142
143 (defbinding selection-data-get-text () string
144   (selection-data selection-data))
145
146 #+gtk2.6
147 (progn
148   (defbinding selection-data-set-pixbuf () boolean
149     (selection-data selection-data)
150     (puxbuf gdk:pixbuf))
151
152   (defbinding selection-data-get-pixbuf () gdk:pixbuf
153     (selection-data selection-data))
154
155   (defbinding selection-data-set-uris () boolean
156     (selection-data selection-data)
157     (uris (null-terminated-vector string)))
158
159   (defbinding selection-data-get-uris () (null-terminated-vector string)
160     (selection-data selection-data)))
161
162 (defbinding selection-data-get-targets () boolean
163   (selection-data selection-data)
164   (targets (vector gdk:atom n-atoms))
165   (n-atoms int))
166
167 #+gtk2.6
168 (defbinding selection-data-targets-include-image-p (selection-data &optional writable-p) boolean
169   (selection-data selection-data)
170   (writable-p boolean))
171
172 (defbinding selection-data-targets-include-text-p (selection-data) boolean
173   (selection-data selection-data))
174
175 (defbinding selection-remove-all () boolean
176   (widget widget))
177
178
179 ;;; Clipboard -- untestet
180
181 (defbinding (clipboard-get "gtk_clipboard_get_for_display") 
182     (selection &optional (display (gdk:display-get-default))) clipboard
183   (display gdk:display)
184   ((gdk:atom-intern selection) gdk:atom))
185
186
187 (define-callback %clipboard-get-callback nil
188     ((clipboard pointer) (selection-data selection-data)
189      (info int) (callback-ids unsigned-int))
190   (declare (ignore clipboard))
191   (funcall (car (find-user-data callback-ids)) selection-data info))
192
193 (define-callback %clipboard-clear-callback nil
194     ((clipboard pointer) (callback-ids unsigned-int))
195   (declare (ignore clipboard))
196   (funcall (cdr (find-user-data callback-ids))))
197
198 (defbinding clipboard-set-with-data (clipboard targets get-func clear-func) gobject
199   (clipboard clipboard)
200   (targets (vector (inlined target-entry)))
201   ((length targets) unsigned-int)
202   (%clipboard-get-callback callback)
203   (%clipboard-clear-callback callback)
204   ((register-user-data (cons get-func clear-func)) unsigned-int))
205
206 (defbinding clipboard-clear () nil
207   (clipboard clipboard))
208
209 (defbinding clipboard-set-text (clipboard text) nil
210   (clipboard clipboard)
211   (text string)
212   ((length text) int))
213
214 #+gtk2.6
215 (defbinding clipboard-set-image () nil
216   (clipboard clipboard)
217   (pixbuf gdk:pixbuf))
218
219 (defun clipboard-set (clipboard object)
220   (etypecase object
221     (string (clipboard-set-text clipboard object))
222     #+gtk2.6
223     (gdk:pixbuf (clipboard-set-image clipboard object))))
224
225 (define-callback-marshal %clipboard-receive-callback nil 
226  ((:ignore clipboard) selection-data))
227
228 (defbinding clipboard-request-contents (clipboard target callback) nil
229   (clipboard clipboard)
230   ((gdk:atom-intern target) gdk:atom)
231   (%clipboard-receive-callback callback)
232   ((register-callback-function callback) unsigned-int))
233
234 (define-callback-marshal %clipboard-text-receive-callback nil
235   ((:ignore clipboard) (text string)))
236
237
238 (defbinding clipboard-request-text (clipboard callback) nil
239   (clipboard clipboard)
240   (%clipboard-text-receive-callback callback)
241   ((register-callback-function callback) unsigned-int))
242
243 #+gtk2.6
244 (progn
245   (define-callback-marshal %clipboard-image-receive-callback nil 
246     ((:ignore clipboard) (image gdk:pixbuf)))
247
248   (defbinding clipboard-request-image (clipboard callback) nil
249     (clipboard clipboard)
250     (%clipboard-image-receive-callback callback)
251     ((register-callback-function callback) unsigned-int)))
252
253
254 (define-callback %clipboard-targets-receive-callback nil
255     ((clipboard pointer) (atoms (vector gdk:atom n-atoms))
256      (n-atoms unsigned-int) (callback-id unsigned-int))
257   (declare (ignore clipboard n-atoms))
258   (funcall (find-user-data callback-id) atoms))
259
260 (defbinding clipboard-request-targets (clipboard callback) nil
261   (clipboard clipboard)
262   (%clipboard-targets-receive-callback callback)
263   ((register-callback-function callback) unsigned-int))
264
265 (defbinding clipboard-wait-for-contents () selection-data
266   (clipboard clipboard))
267
268 (defbinding clipboard-wait-for-text () string
269   (clipboard clipboard))
270
271 #+gtk2.6
272 (defbinding clipboard-wait-for-image () (referenced gdk:pixbuf)
273   (clipboard clipboard))
274
275 (defbinding clipboard-wait-is-text-available-p () boolean
276   (clipboard clipboard))
277
278 #+gtk2.6
279 (defbinding clipboard-wait-is-image-available-p () boolean
280   (clipboard clipboard))
281
282 (defbinding clipboard-wait-for-targets () boolean
283   (clipboard clipboard)
284   (targets (vector gdk:atom n-targets) :out)
285   (n-targets unsigned-int :out))
286
287 #+gtk2.6
288 (defbinding clipboard-wait-is-target-available-p () boolean
289   (clipboard clipboard)
290   (target gdk:atom))
291
292 #+gtk2.6
293 (defbinding clipboard-set-can-store () nil
294   (clipboard clipboard)
295   (targets (vector gdk:atom))
296   ((length targets) int))
297
298 #+gtk2.6
299 (defbinding clipboard-store () nil
300   (clipboard clipboard))
301
302
303 ;;;; Drag and Drop
304
305 (defbinding drag-dest-set (widget flags targets actions) nil
306   (widget widget)
307   (flags dest-defaults)
308   ((etypecase targets 
309      ((or vector list) targets)
310      (target-entry (vector targets)))
311    (vector (inlined target-entry)))
312   ((etypecase targets 
313      ((or vector list) (length targets))
314      (target-entry 1))
315    int)
316   (actions gdk:drag-action))
317
318 (defbinding drag-dest-set-proxy () nil
319   (widget widget)
320   (window gdk:window)
321   (protocol gdk:drag-protocol)
322   (use-coordinates-p boolean))
323
324 (defbinding drag-dest-unset () nil
325   (widget widget))
326
327 (defbinding drag-dest-find-target () gdk:atom
328   (widget widget)
329   (context gdk:drag-context)
330   (targets target-list))
331
332 (defbinding drag-dest-get-target-list () target-list
333   (widget widget))
334
335 (defbinding drag-dest-set-target-list () nil
336   (widget widget)
337   (targets target-list))
338
339 #+gtk2.6
340 (progn
341   (defbinding drag-dest-add-text-targets () nil
342     (widget widget))
343
344   (defbinding drag-dest-add-image-targets () nil
345     (widget widget))
346
347   (defbinding drag-dest-add-uri-targets () nil
348     (widget widget)))
349
350 (defbinding drag-finish () nil
351   (context gdk:drag-context)
352   (success boolean)
353   (delete boolean)
354   (time unsigned-int))
355
356 (defbinding drag-get-data () nil
357   (widget widget)
358   (context gdk:drag-context)
359   (target gdk:atom)
360   (time unsigned-int))
361
362 (defbinding drag-get-source-widget () widget
363   (context gdk:drag-context))
364
365 (defbinding drag-highlight () nil
366   (widget widget))
367
368 (defbinding drag-unhighlight () nil
369   (widget widget))
370
371 (defbinding drag-begin () gdk:drag-context
372   (widget widget)
373   (targets target-list)
374   (actions gdk:drag-action)
375   (button int)
376   (event gdk:event))
377
378 (defbinding %drag-set-icon-widget () nil
379   (context gdk:drag-context)
380   (widget widget)
381   (hot-x int)
382   (hot-y int))
383
384 (defbinding %drag-set-icon-pixmap () nil
385   (context gdk:drag-context)
386   (pixmap gdk:pixmap)
387   (mask gdk:bitmap)
388   (hot-x int)
389   (hot-y int))
390
391 (defbinding %drag-set-icon-pixbuf () nil
392   (context gdk:drag-context)
393   (pixbuf gdk:pixbuf)
394   (hot-x int)
395   (hot-y int))
396
397 (defbinding %drag-set-icon-stock () nil
398   (context gdk:drag-context)
399   (stock-id string)
400   (hot-x int)
401   (hot-y int))
402
403 (defbinding %drag-set-icon-default () nil
404   (context gdk:drag-context))
405
406 (defun drag-set-icon (context icon &optional (hot-x 0) (hot-y 0))
407   (etypecase icon
408     (widget (%drag-set-icon-widget context icon hot-x hot-y))
409     (gdk:pixbuf (%drag-set-icon-pixbuf context icon hot-x hot-y))
410     (string (%drag-set-icon-stock context icon hot-x hot-y))
411     (vector (multiple-value-bind (pixmap mask) (gdk:pixmap-create icon)
412               (%drag-set-icon-pixmap context pixmap mask hot-x hot-y)))
413     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
414                 (%drag-set-icon-pixbuf context pixbuf hot-x hot-y)))
415     (null (%drag-set-icon-default context))))
416
417 (defbinding drag-check-threshold-p () boolean
418   (widget widget)
419   (start-x int)
420   (start-y int)
421   (current-x int)
422   (current-y int))
423
424 (defbinding drag-source-set (widget start-button-mask targets actions) nil
425   (widget widget)
426   (start-button-mask gdk:modifier-type)
427   ((etypecase targets 
428      ((or vector list) targets)
429      (target-entry (vector targets)))
430    (vector (inlined target-entry)))
431   ((etypecase targets 
432      ((or vector list) (length targets))
433      (target-entry 1)) 
434    int)
435   (actions gdk:drag-action))
436
437 (defbinding %drag-source-set-icon-pixbuf () nil
438   (widget widget)
439   (pixbuf gdk:pixbuf))
440   
441 (defbinding %drag-source-set-icon-stock () nil
442   (widget widget)
443   (pixbuf gdk:pixbuf))
444
445 (defun drag-source-set-icon (widget icon)
446   (etypecase icon
447     (gdk:pixbuf (%drag-source-set-icon-pixbuf widget icon))
448     (string (%drag-source-set-icon-stock widget icon))
449 ;    (vector )
450     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
451                 (%drag-source-set-icon-pixbuf widget pixbuf)))))
452
453 (defbinding drag-source-unset () nil
454   (widget widget))
455
456 (defbinding drag-source-set-target-list () nil
457   (widget widget)
458   (targets (or null target-list)))
459
460 (defbinding drag-source-get-target-list () target-list
461   (widget widget))
462
463 #+gtk2.6
464 (progn
465   (defbinding drag-source-add-text-targets () nil
466     (widget widget))
467
468   (defbinding drag-source-add-image-targets () nil
469     (widget widget))
470
471   (defbinding drag-source-add-uri-targets () nil
472     (widget widget)))