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