chiark / gitweb /
Stock item bindings updated to Gtk+ 2.8
[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.7 2006/02/26 15:22: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
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   (declare (ignore clipboard))
190   (funcall (car (find-user-data callback-ids)) selection-data info))
191
192 (define-callback %clipboard-clear-callback nil
193     ((clipboard pointer) (callback-ids unsigned-int))
194   (declare (ignore clipboard))
195   (funcall (cdr (find-user-data callback-ids))))
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-callback callback)
202   (%clipboard-clear-callback 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 (define-callback-marshal %clipboard-receive-callback nil 
225  ((:ignore clipboard) selection-data))
226
227 (defbinding clipboard-request-contents (clipboard target callback) nil
228   (clipboard clipboard)
229   ((gdk:atom-intern target) gdk:atom)
230   (%clipboard-receive-callback callback)
231   ((register-callback-function callback) unsigned-int))
232
233 (define-callback-marshal %clipboard-text-receive-callback nil
234   ((:ignore clipboard) (text string)))
235
236
237 (defbinding clipboard-request-text (clipboard callback) nil
238   (clipboard clipboard)
239   (%clipboard-text-receive-callback callback)
240   ((register-callback-function callback) unsigned-int))
241
242 #+gtk2.6
243 (progn
244   (define-callback-marshal %clipboard-image-receive-callback nil 
245     ((:ignore clipboard) (image gdk:pixbuf)))
246
247   (defbinding clipboard-request-image (clipboard callback) nil
248     (clipboard clipboard)
249     (%clipboard-image-receive-callback callback)
250     ((register-callback-function callback) unsigned-int)))
251
252
253 (define-callback %clipboard-targets-receive-callback nil
254     ((clipboard pointer) (atoms (vector gdk:atom n-atoms))
255      (n-atoms unsigned-int) (callback-id unsigned-int))
256   (declare (ignore clipboard n-atoms))
257   (funcall (find-user-data callback-id) atoms))
258
259 (defbinding clipboard-request-targets (clipboard callback) nil
260   (clipboard clipboard)
261   (%clipboard-targets-receive-callback callback)
262   ((register-callback-function callback) unsigned-int))
263
264 (defbinding clipboard-wait-for-contents () selection-data
265   (clipboard clipboard))
266
267 (defbinding clipboard-wait-for-text () string
268   (clipboard clipboard))
269
270 #+gtk2.6
271 (defbinding clipboard-wait-for-image () (referenced gdk:pixbuf)
272   (clipboard clipboard))
273
274 (defbinding clipboard-wait-is-text-available-p () boolean
275   (clipboard clipboard))
276
277 #+gtk2.6
278 (defbinding clipboard-wait-is-image-available-p () boolean
279   (clipboard clipboard))
280
281 (defbinding clipboard-wait-for-targets () boolean
282   (clipboard clipboard)
283   (targets (vector gdk:atom n-targets) :out)
284   (n-targets unsigned-int :out))
285
286 #+gtk2.6
287 (defbinding clipboard-wait-is-target-available-p () boolean
288   (clipboard clipboard)
289   (target gdk:atom))
290
291 #+gtk2.6
292 (defbinding clipboard-set-can-store () nil
293   (clipboard clipboard)
294   (targets (vector gdk:atom))
295   ((length targets) int))
296
297 #+gtk2.6
298 (defbinding clipboard-store () nil
299   (clipboard clipboard))
300
301
302 ;;;; Drag and Drop
303
304 (defbinding drag-dest-set (widget flags targets actions) nil
305   (widget widget)
306   (flags dest-defaults)
307   ((etypecase targets 
308      ((or vector list) targets)
309      (target-entry (vector targets)))
310    (vector (inlined target-entry)))
311   ((etypecase targets 
312      ((or vector list) (length targets))
313      (target-entry 1))
314    int)
315   (actions gdk:drag-action))
316
317 (defbinding drag-dest-set-proxy () nil
318   (widget widget)
319   (window gdk:window)
320   (protocol gdk:drag-protocol)
321   (use-coordinates-p boolean))
322
323 (defbinding drag-dest-unset () nil
324   (widget widget))
325
326 (defbinding drag-dest-find-target () gdk:atom
327   (widget widget)
328   (context gdk:drag-context)
329   (targets target-list))
330
331 (defbinding drag-dest-get-target-list () target-list
332   (widget widget))
333
334 (defbinding drag-dest-set-target-list () nil
335   (widget widget)
336   (targets target-list))
337
338 #+gtk2.6
339 (progn
340   (defbinding drag-dest-add-text-targets () nil
341     (widget widget))
342
343   (defbinding drag-dest-add-image-targets () nil
344     (widget widget))
345
346   (defbinding drag-dest-add-uri-targets () nil
347     (widget widget)))
348
349 (defbinding drag-finish () nil
350   (context gdk:drag-context)
351   (success boolean)
352   (delete boolean)
353   (time unsigned-int))
354
355 (defbinding drag-get-data () nil
356   (widget widget)
357   (context gdk:drag-context)
358   (target gdk:atom)
359   (time unsigned-int))
360
361 (defbinding drag-get-source-widget () widget
362   (context gdk:drag-context))
363
364 (defbinding drag-highlight () nil
365   (widget widget))
366
367 (defbinding drag-unhighlight () nil
368   (widget widget))
369
370 (defbinding drag-begin () gdk:drag-context
371   (widget widget)
372   (targets target-list)
373   (actions gdk:drag-action)
374   (button int)
375   (event gdk:event))
376
377 (defbinding %drag-set-icon-widget () nil
378   (context gdk:drag-context)
379   (widget widget)
380   (hot-x int)
381   (hot-y int))
382
383 (defbinding %drag-set-icon-pixmap () nil
384   (context gdk:drag-context)
385   (pixmap gdk:pixmap)
386   (mask gdk:bitmap)
387   (hot-x int)
388   (hot-y int))
389
390 (defbinding %drag-set-icon-pixbuf () nil
391   (context gdk:drag-context)
392   (pixbuf gdk:pixbuf)
393   (hot-x int)
394   (hot-y int))
395
396 (defbinding %drag-set-icon-stock () nil
397   (context gdk:drag-context)
398   (stock-id string)
399   (hot-x int)
400   (hot-y int))
401
402 (defbinding %drag-set-icon-default () nil
403   (context gdk:drag-context))
404
405 (defun drag-set-icon (context icon &optional (hot-x 0) (hot-y 0))
406   (etypecase icon
407     (widget (%drag-set-icon-widget context icon hot-x hot-y))
408     (gdk:pixbuf (%drag-set-icon-pixbuf context icon hot-x hot-y))
409     (string (%drag-set-icon-stock context icon hot-x hot-y))
410     (vector (multiple-value-bind (pixmap mask) (gdk:pixmap-create icon)
411               (%drag-set-icon-pixmap context pixmap mask hot-x hot-y)))
412     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
413                 (%drag-set-icon-pixbuf context pixbuf hot-x hot-y)))
414     (null (%drag-set-icon-default context))))
415
416 (defbinding drag-check-threshold-p () boolean
417   (widget widget)
418   (start-x int)
419   (start-y int)
420   (current-x int)
421   (current-y int))
422
423 (defbinding drag-source-set (widget start-button-mask targets actions) nil
424   (widget widget)
425   (start-button-mask gdk:modifier-type)
426   ((etypecase targets 
427      ((or vector list) targets)
428      (target-entry (vector targets)))
429    (vector (inlined target-entry)))
430   ((etypecase targets 
431      ((or vector list) (length targets))
432      (target-entry 1)) 
433    int)
434   (actions gdk:drag-action))
435
436 (defbinding %drag-source-set-icon-pixbuf () nil
437   (widget widget)
438   (pixbuf gdk:pixbuf))
439   
440 (defbinding %drag-source-set-icon-stock () nil
441   (widget widget)
442   (pixbuf gdk:pixbuf))
443
444 (defun drag-source-set-icon (widget icon)
445   (etypecase icon
446     (gdk:pixbuf (%drag-source-set-icon-pixbuf widget icon))
447     (string (%drag-source-set-icon-stock widget icon))
448 ;    (vector )
449     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
450                 (%drag-source-set-icon-pixbuf widget pixbuf)))))
451
452 (defbinding drag-source-unset () nil
453   (widget widget))
454
455 (defbinding drag-source-set-target-list () nil
456   (widget widget)
457   (targets (or null target-list)))
458
459 (defbinding drag-source-get-target-list () target-list
460   (widget widget))
461
462 #+gtk2.6
463 (progn
464   (defbinding drag-source-add-text-targets () nil
465     (widget widget))
466
467   (defbinding drag-source-add-image-targets () nil
468     (widget widget))
469
470   (defbinding drag-source-add-uri-targets () nil
471     (widget widget)))