chiark / gitweb /
Changed to use of settable FOREIGN-LOCATION
[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.4 2006-02-08 22:21:07 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 initialize-instance ((target-list target-list) &key targets)
50   (setf (foreign-location target-list) (%target-list-new targets))
51   (call-next-method))
52
53 (defbinding target-list-add (target-list target &optional flags info) nil
54   (target-list target-list)
55   (target gdk:atom)
56   (flags unsigned-int)
57   (info unsigned-int))
58
59 (defbinding target-list-add-table (target-list targets) nil
60   (target-list target-list)
61   ((etypecase targets 
62      ((or vector list) targets)
63      (target-entry (vector targets)))
64    (vector (inlined target-entry)))
65   ((etypecase targets 
66      ((or vector list) (length targets))
67      (target-entry 1))
68    int))
69
70 #+gtk2.6
71 (progn
72   (defbinding target-list-add-text-targets (target-list info &optional writable-p) nil
73     (target-list target-list)
74     (info unsigned-int)
75     (writable-p boolean))
76   
77   (defbinding target-list-add-image-targets (target-list info &optional writable-p) nil
78     (target-list target-list)
79     (info unsigned-int)
80     (writable-p boolean))
81
82   (defbinding target-list-add-uri-targets (target-list info &optional writable-p) nil
83     (target-list target-list)
84     (info unsigned-int)
85     (writable-p boolean)))
86
87 (defbinding target-list-remove () nil
88   (target-list target-list)
89   (target gdk:atom))
90
91 ;; (defbinding target-list-find () nil
92 ;;   (target-list target-list)
93 ;;   (target gdk:atom)
94 ;;   ...)
95
96 (defbinding (selection-set-owner "gtk_selection_owner_set_for_display")
97     (widget selection time &optional (display (gdk:display-get-default))) 
98     boolean
99   (display gdk:display)
100   (widget widget)
101   ((gdk:atom-intern selection) gdk:atom))
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 (defcallback %clipboard-get-func (nil (clipboard pointer)
188                                       (selection-data selection-data)
189                                       (info int)
190                                       (user-data unsigned-int))
191   (funcall (car (find-user-data user-data)) selection-data info))
192
193 (defcallback %clipboard-clear-func (nil (clipboard pointer)
194                                         (user-data unsigned-int))
195   (funcall (cdr (find-user-data user-data))))
196
197 (defbinding clipboard-set-with-data (clipboard targets get-func clear-func) gobject
198   (clipboard clipboard)
199   (targets (vector (inlined target-entry)))
200   ((length targets) unsigned-int)
201   (%clipboard-get-func callback)
202   (%clipboard-clear-func callback)
203   ((register-user-data (cons get-func clear-func)) unsigned-int))
204
205 (defbinding clipboard-clear () nil
206   (clipboard clipboard))
207
208 (defbinding clipboard-set-text (clipboard text) nil
209   (clipboard clipboard)
210   (text string)
211   ((length text) int))
212
213 #+gtk2.6
214 (defbinding clipboard-set-image () nil
215   (clipboard clipboard)
216   (pixbuf gdk:pixbuf))
217
218 (defun clipboard-set (clipboard object)
219   (etypecase object
220     (string (clipboard-set-text clipboard object))
221     #+gtk2.6
222     (gdk:pixbuf (clipboard-set-image clipboard object))))
223
224 (defcallback %clipboard-receive-func (nil (clipboard pointer)
225                                           (selection-data selection-data)
226                                           (user-data unsigned-int))
227   (funcall (find-user-data user-data) selection-data))
228
229 (defbinding clipboard-request-contents (clipboard target callback) nil
230   (clipboard clipboard)
231   ((gdk:atom-intern target) gdk:atom)
232   (%clipboard-receive-func callback)
233   ((register-callback-function callback) unsigned-int))
234
235 (defcallback %clipboard-text-receive-func (nil (clipboard pointer)
236                                                (text (copy-of string))
237                                                (user-data unsigned-int))
238   (funcall (find-user-data user-data) text))
239
240 (defbinding clipboard-request-text (clipboard callback) nil
241   (clipboard clipboard)
242   (%clipboard-text-receive-func callback)
243   ((register-callback-function callback) unsigned-int))
244
245 #+gtk2.6
246 (progn
247   (defcallback %clipboard-image-receive-func (nil (clipboard pointer)
248                                                   (image gdk:pixbuf)
249                                                   (user-data unsigned-int))
250     (funcall (find-user-data user-data) image))
251
252   (defbinding clipboard-request-image (clipboard callback) nil
253     (clipboard clipboard)
254     (%clipboard-image-receive-func callback)
255     ((register-callback-function callback) unsigned-int)))
256
257
258 (defcallback %clipboard-targets-receive-func 
259     (nil (clipboard pointer)
260          (atoms (vector gdk:atom n-atoms))
261          (n-atoms unsigned-int)
262          (user-data unsigned-int))
263   (funcall (find-user-data user-data) atoms))
264
265 (defbinding clipboard-request-targets (clipboard callback) nil
266   (clipboard clipboard)
267   (%clipboard-targets-receive-func callback)
268   ((register-callback-function callback) unsigned-int))
269
270 (defbinding clipboard-wait-for-contents () selection-data
271   (clipboard clipboard))
272
273 (defbinding clipboard-wait-for-text () string
274   (clipboard clipboard))
275
276 #+gtk2.6
277 (defbinding clipboard-wait-for-image () (referenced gdk:pixbuf)
278   (clipboard clipboard))
279
280 (defbinding clipboard-wait-is-text-available-p () boolean
281   (clipboard clipboard))
282
283 #+gtk2.6
284 (defbinding clipboard-wait-is-image-available-p () boolean
285   (clipboard clipboard))
286
287 (defbinding clipboard-wait-for-targets () boolean
288   (clipboard clipboard)
289   (targets (vector gdk:atom n-targets) :out)
290   (n-targets unsigned-int :out))
291
292 #+gtk2.6
293 (defbinding clipboard-wait-is-target-available-p () boolean
294   (clipboard clipboard)
295   (target gdk:atom))
296
297 #+gtk2.6
298 (defbinding clipboard-set-can-store () nil
299   (clipboard clipboard)
300   (targets (vector gdk:atom))
301   ((length targets) int))
302
303 #+gtk2.6
304 (defbinding clipboard-store () nil
305   (clipboard clipboard))
306
307
308 ;;;; Drag and Drop
309
310 (defbinding drag-dest-set (widget flags targets actions) nil
311   (widget widget)
312   (flags dest-defaults)
313   ((etypecase targets 
314      ((or vector list) targets)
315      (target-entry (vector targets)))
316    (vector (inlined target-entry)))
317   ((etypecase targets 
318      ((or vector list) (length targets))
319      (target-entry 1))
320    int)
321   (actions gdk:drag-action))
322
323 (defbinding drag-dest-set-proxy () nil
324   (widget widget)
325   (window gdk:window)
326   (protocol gdk:drag-protocol)
327   (use-coordinates-p boolean))
328
329 (defbinding drag-dest-unset () nil
330   (widget widget))
331
332 (defbinding drag-dest-find-target () gdk:atom
333   (widget widget)
334   (context gdk:drag-context)
335   (targets target-list))
336
337 (defbinding drag-dest-get-target-list () target-list
338   (widget widget))
339
340 (defbinding drag-dest-set-target-list () nil
341   (widget widget)
342   (targets target-list))
343
344 #+gtk2.6
345 (progn
346   (defbinding drag-dest-add-text-targets () nil
347     (widget widget))
348
349   (defbinding drag-dest-add-image-targets () nil
350     (widget widget))
351
352   (defbinding drag-dest-add-uri-targets () nil
353     (widget widget)))
354
355 (defbinding drag-finish () nil
356   (context gdk:drag-context)
357   (success boolean)
358   (delete boolean)
359   (time unsigned-int))
360
361 (defbinding drag-get-data () nil
362   (widget widget)
363   (context gdk:drag-context)
364   (target gdk:atom)
365   (time unsigned-int))
366
367 (defbinding drag-get-source-widget () widget
368   (context gdk:drag-context))
369
370 (defbinding drag-highlight () nil
371   (widget widget))
372
373 (defbinding drag-unhighlight () nil
374   (widget widget))
375
376 (defbinding drag-begin () gdk:drag-context
377   (widget widget)
378   (targets target-list)
379   (actions gdk:drag-action)
380   (button int)
381   (event gdk:event))
382
383 (defbinding %drag-set-icon-widget () nil
384   (context gdk:drag-context)
385   (widget widget)
386   (hot-x int)
387   (hot-y int))
388
389 (defbinding %drag-set-icon-pixmap () nil
390   (context gdk:drag-context)
391   (pixmap gdk:pixmap)
392   (mask gdk:bitmap)
393   (hot-x int)
394   (hot-y int))
395
396 (defbinding %drag-set-icon-pixbuf () nil
397   (context gdk:drag-context)
398   (pixbuf gdk:pixbuf)
399   (hot-x int)
400   (hot-y int))
401
402 (defbinding %drag-set-icon-stock () nil
403   (context gdk:drag-context)
404   (stock-id string)
405   (hot-x int)
406   (hot-y int))
407
408 (defbinding %drag-set-icon-default () nil
409   (context gdk:drag-context))
410
411 (defun drag-set-icon (context icon &optional (hot-x 0) (hot-y 0))
412   (etypecase icon
413     (widget (%drag-set-icon-widget context icon hot-x hot-y))
414     (gdk:pixbuf (%drag-set-icon-pixbuf context icon hot-x hot-y))
415     (string (%drag-set-icon-stock context icon hot-x hot-y))
416     (vector (multiple-value-bind (pixmap mask) (gdk:pixmap-create icon)
417               (%drag-set-icon-pixmap context pixmap mask hot-x hot-y)))
418     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
419                 (%drag-set-icon-pixbuf context pixbuf hot-x hot-y)))
420     (null (%drag-set-icon-default context))))
421
422 (defbinding drag-check-threshold-p () boolean
423   (widget widget)
424   (start-x int)
425   (start-y int)
426   (current-x int)
427   (current-y int))
428
429 (defbinding drag-source-set (widget start-button-mask targets actions) nil
430   (widget widget)
431   (start-button-mask gdk:modifier-type)
432   ((etypecase targets 
433      ((or vector list) targets)
434      (target-entry (vector targets)))
435    (vector (inlined target-entry)))
436   ((etypecase targets 
437      ((or vector list) (length targets))
438      (target-entry 1)) 
439    int)
440   (actions gdk:drag-action))
441
442 (defbinding %drag-source-set-icon-pixbuf () nil
443   (widget widget)
444   (pixbuf gdk:pixbuf))
445   
446 (defbinding %drag-source-set-icon-stock () nil
447   (widget widget)
448   (pixbuf gdk:pixbuf))
449
450 (defun drag-source-set-icon (widget icon)
451   (etypecase icon
452     (gdk:pixbuf (%drag-source-set-icon-pixbuf widget icon))
453     (string (%drag-source-set-icon-stock widget icon))
454 ;    (vector )
455     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
456                 (%drag-source-set-icon-pixbuf widget pixbuf)))))
457
458 (defbinding drag-source-unset () nil
459   (widget widget))
460
461 (defbinding drag-source-set-target-list () nil
462   (widget widget)
463   (targets (or null target-list)))
464
465 (defbinding drag-source-get-target-list () target-list
466   (widget widget))
467
468 #+gtk2.6
469 (progn
470   (defbinding drag-source-add-text-targets () nil
471     (widget widget))
472
473   (defbinding drag-source-add-image-targets () nil
474     (widget widget))
475
476   (defbinding drag-source-add-uri-targets () nil
477     (widget widget)))