chiark / gitweb /
C callbacks cleaned up and ported to new API
[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.6 2006-02-19 19:31:15 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
102 (defbinding selection-add-target () nil
103   (widget widget)
104   (selection gdk:atom)
105   (target gdk:atom)
106   (info unsigned-int))
107
108 (defbinding selection-add-targets (widget selection targets) nil
109   (widget widget)
110   (selection gdk:atom)
111   ((etypecase targets 
112      ((or vector list) targets)
113      (target-entry (vector targets)))
114    (vector (inlined target-entry)))
115   ((etypecase targets 
116      ((or vector list) (length targets))
117      (target-entry 1))
118    int))
119
120 (defbinding selection-clear-targets () nil
121   (widget widget)
122   (selection gdk:atom))
123
124 (defbinding selection-convert () boolean
125   (widget widget)
126   (selection gdk:atom)
127   (target gdk:atom)
128   (time unsigned-int))
129
130 (defbinding selection-data-set () boolean
131   (selection-data selection-data)
132   (type gdk:atom)
133   (format int)
134   (data pointer)
135   (length int))
136
137 (defbinding selection-data-set-text () boolean
138   (selection-data selection-data)
139   (text string)
140   (-1 integer))
141
142 (defbinding selection-data-get-text () string
143   (selection-data selection-data))
144
145 #+gtk2.6
146 (progn
147   (defbinding selection-data-set-pixbuf () boolean
148     (selection-data selection-data)
149     (puxbuf gdk:pixbuf))
150
151   (defbinding selection-data-get-pixbuf () gdk:pixbuf
152     (selection-data selection-data))
153
154   (defbinding selection-data-set-uris () boolean
155     (selection-data selection-data)
156     (uris (null-terminated-vector string)))
157
158   (defbinding selection-data-get-uris () (null-terminated-vector string)
159     (selection-data selection-data)))
160
161 (defbinding selection-data-get-targets () boolean
162   (selection-data selection-data)
163   (targets (vector gdk:atom n-atoms))
164   (n-atoms int))
165
166 #+gtk2.6
167 (defbinding selection-data-targets-include-image-p (selection-data &optional writable-p) boolean
168   (selection-data selection-data)
169   (writable-p boolean))
170
171 (defbinding selection-data-targets-include-text-p (selection-data) boolean
172   (selection-data selection-data))
173
174 (defbinding selection-remove-all () boolean
175   (widget widget))
176
177
178 ;;; Clipboard -- untestet
179
180 (defbinding (clipboard-get "gtk_clipboard_get_for_display") 
181     (selection &optional (display (gdk:display-get-default))) clipboard
182   (display gdk:display)
183   ((gdk:atom-intern selection) gdk:atom))
184
185
186 (define-callback %clipboard-get-callback nil
187     ((clipboard pointer) (selection-data selection-data)
188      (info int) (callback-ids unsigned-int))
189   (funcall (car (find-user-data callback-ids)) selection-data info))
190
191 (define-callback %clipboard-clear-callback nil
192     ((clipboard pointer) (callback-ids unsigned-int))
193   (funcall (cdr (find-user-data callback-ids))))
194
195 (defbinding clipboard-set-with-data (clipboard targets get-func clear-func) gobject
196   (clipboard clipboard)
197   (targets (vector (inlined target-entry)))
198   ((length targets) unsigned-int)
199   (%clipboard-get-callback callback)
200   (%clipboard-clear-callback callback)
201   ((register-user-data (cons get-func clear-func)) unsigned-int))
202
203 (defbinding clipboard-clear () nil
204   (clipboard clipboard))
205
206 (defbinding clipboard-set-text (clipboard text) nil
207   (clipboard clipboard)
208   (text string)
209   ((length text) int))
210
211 #+gtk2.6
212 (defbinding clipboard-set-image () nil
213   (clipboard clipboard)
214   (pixbuf gdk:pixbuf))
215
216 (defun clipboard-set (clipboard object)
217   (etypecase object
218     (string (clipboard-set-text clipboard object))
219     #+gtk2.6
220     (gdk:pixbuf (clipboard-set-image clipboard object))))
221
222 (define-callback-marshal %clipboard-receive-callback nil 
223  ((:ignore clipboard) selection-data))
224
225 (defbinding clipboard-request-contents (clipboard target callback) nil
226   (clipboard clipboard)
227   ((gdk:atom-intern target) gdk:atom)
228   (%clipboard-receive-callback callback)
229   ((register-callback-function callback) unsigned-int))
230
231 (define-callback-marshal %clipboard-text-receive-callback nil
232   ((:ignore clipboard) (text string)))
233
234
235 (defbinding clipboard-request-text (clipboard callback) nil
236   (clipboard clipboard)
237   (%clipboard-text-receive-callback callback)
238   ((register-callback-function callback) unsigned-int))
239
240 #+gtk2.6
241 (progn
242   (define-callback-marshal %clipboard-image-receive-callback nil 
243     ((:ignore clipboard) (image gdk:pixbuf)))
244
245   (defbinding clipboard-request-image (clipboard callback) nil
246     (clipboard clipboard)
247     (%clipboard-image-receive-callback callback)
248     ((register-callback-function callback) unsigned-int)))
249
250
251 (define-callback %clipboard-targets-receive-callback nil
252     ((clipboard pointer) (atoms (vector gdk:atom n-atoms))
253      (n-atoms unsigned-int) (callback-id unsigned-int))
254   (funcall (find-user-data callback-id) atoms))
255
256 (defbinding clipboard-request-targets (clipboard callback) nil
257   (clipboard clipboard)
258   (%clipboard-targets-receive-callback callback)
259   ((register-callback-function callback) unsigned-int))
260
261 (defbinding clipboard-wait-for-contents () selection-data
262   (clipboard clipboard))
263
264 (defbinding clipboard-wait-for-text () string
265   (clipboard clipboard))
266
267 #+gtk2.6
268 (defbinding clipboard-wait-for-image () (referenced gdk:pixbuf)
269   (clipboard clipboard))
270
271 (defbinding clipboard-wait-is-text-available-p () boolean
272   (clipboard clipboard))
273
274 #+gtk2.6
275 (defbinding clipboard-wait-is-image-available-p () boolean
276   (clipboard clipboard))
277
278 (defbinding clipboard-wait-for-targets () boolean
279   (clipboard clipboard)
280   (targets (vector gdk:atom n-targets) :out)
281   (n-targets unsigned-int :out))
282
283 #+gtk2.6
284 (defbinding clipboard-wait-is-target-available-p () boolean
285   (clipboard clipboard)
286   (target gdk:atom))
287
288 #+gtk2.6
289 (defbinding clipboard-set-can-store () nil
290   (clipboard clipboard)
291   (targets (vector gdk:atom))
292   ((length targets) int))
293
294 #+gtk2.6
295 (defbinding clipboard-store () nil
296   (clipboard clipboard))
297
298
299 ;;;; Drag and Drop
300
301 (defbinding drag-dest-set (widget flags targets actions) nil
302   (widget widget)
303   (flags dest-defaults)
304   ((etypecase targets 
305      ((or vector list) targets)
306      (target-entry (vector targets)))
307    (vector (inlined target-entry)))
308   ((etypecase targets 
309      ((or vector list) (length targets))
310      (target-entry 1))
311    int)
312   (actions gdk:drag-action))
313
314 (defbinding drag-dest-set-proxy () nil
315   (widget widget)
316   (window gdk:window)
317   (protocol gdk:drag-protocol)
318   (use-coordinates-p boolean))
319
320 (defbinding drag-dest-unset () nil
321   (widget widget))
322
323 (defbinding drag-dest-find-target () gdk:atom
324   (widget widget)
325   (context gdk:drag-context)
326   (targets target-list))
327
328 (defbinding drag-dest-get-target-list () target-list
329   (widget widget))
330
331 (defbinding drag-dest-set-target-list () nil
332   (widget widget)
333   (targets target-list))
334
335 #+gtk2.6
336 (progn
337   (defbinding drag-dest-add-text-targets () nil
338     (widget widget))
339
340   (defbinding drag-dest-add-image-targets () nil
341     (widget widget))
342
343   (defbinding drag-dest-add-uri-targets () nil
344     (widget widget)))
345
346 (defbinding drag-finish () nil
347   (context gdk:drag-context)
348   (success boolean)
349   (delete boolean)
350   (time unsigned-int))
351
352 (defbinding drag-get-data () nil
353   (widget widget)
354   (context gdk:drag-context)
355   (target gdk:atom)
356   (time unsigned-int))
357
358 (defbinding drag-get-source-widget () widget
359   (context gdk:drag-context))
360
361 (defbinding drag-highlight () nil
362   (widget widget))
363
364 (defbinding drag-unhighlight () nil
365   (widget widget))
366
367 (defbinding drag-begin () gdk:drag-context
368   (widget widget)
369   (targets target-list)
370   (actions gdk:drag-action)
371   (button int)
372   (event gdk:event))
373
374 (defbinding %drag-set-icon-widget () nil
375   (context gdk:drag-context)
376   (widget widget)
377   (hot-x int)
378   (hot-y int))
379
380 (defbinding %drag-set-icon-pixmap () nil
381   (context gdk:drag-context)
382   (pixmap gdk:pixmap)
383   (mask gdk:bitmap)
384   (hot-x int)
385   (hot-y int))
386
387 (defbinding %drag-set-icon-pixbuf () nil
388   (context gdk:drag-context)
389   (pixbuf gdk:pixbuf)
390   (hot-x int)
391   (hot-y int))
392
393 (defbinding %drag-set-icon-stock () nil
394   (context gdk:drag-context)
395   (stock-id string)
396   (hot-x int)
397   (hot-y int))
398
399 (defbinding %drag-set-icon-default () nil
400   (context gdk:drag-context))
401
402 (defun drag-set-icon (context icon &optional (hot-x 0) (hot-y 0))
403   (etypecase icon
404     (widget (%drag-set-icon-widget context icon hot-x hot-y))
405     (gdk:pixbuf (%drag-set-icon-pixbuf context icon hot-x hot-y))
406     (string (%drag-set-icon-stock context icon hot-x hot-y))
407     (vector (multiple-value-bind (pixmap mask) (gdk:pixmap-create icon)
408               (%drag-set-icon-pixmap context pixmap mask hot-x hot-y)))
409     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
410                 (%drag-set-icon-pixbuf context pixbuf hot-x hot-y)))
411     (null (%drag-set-icon-default context))))
412
413 (defbinding drag-check-threshold-p () boolean
414   (widget widget)
415   (start-x int)
416   (start-y int)
417   (current-x int)
418   (current-y int))
419
420 (defbinding drag-source-set (widget start-button-mask targets actions) nil
421   (widget widget)
422   (start-button-mask gdk:modifier-type)
423   ((etypecase targets 
424      ((or vector list) targets)
425      (target-entry (vector targets)))
426    (vector (inlined target-entry)))
427   ((etypecase targets 
428      ((or vector list) (length targets))
429      (target-entry 1)) 
430    int)
431   (actions gdk:drag-action))
432
433 (defbinding %drag-source-set-icon-pixbuf () nil
434   (widget widget)
435   (pixbuf gdk:pixbuf))
436   
437 (defbinding %drag-source-set-icon-stock () nil
438   (widget widget)
439   (pixbuf gdk:pixbuf))
440
441 (defun drag-source-set-icon (widget icon)
442   (etypecase icon
443     (gdk:pixbuf (%drag-source-set-icon-pixbuf widget icon))
444     (string (%drag-source-set-icon-stock widget icon))
445 ;    (vector )
446     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
447                 (%drag-source-set-icon-pixbuf widget pixbuf)))))
448
449 (defbinding drag-source-unset () nil
450   (widget widget))
451
452 (defbinding drag-source-set-target-list () nil
453   (widget widget)
454   (targets (or null target-list)))
455
456 (defbinding drag-source-get-target-list () target-list
457   (widget widget))
458
459 #+gtk2.6
460 (progn
461   (defbinding drag-source-add-text-targets () nil
462     (widget widget))
463
464   (defbinding drag-source-add-image-targets () nil
465     (widget widget))
466
467   (defbinding drag-source-add-uri-targets () nil
468     (widget widget)))