chiark / gitweb /
Initial checkin
[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.1 2006/02/06 11:57:27 espen Exp $
24
25
26 (in-package "GTK")
27
28
29 ;;;; Selection
30
31 (defbinding %selection-data-copy () pointer
32   (location pointer))
33   
34 (defbinding %selection-data-free () nil
35   (location pointer))
36
37 (defmethod reference-foreign ((class (eql (find-class 'selection-data))) location)
38   (declare (ignore class))
39   (%selection-data-copy location))
40
41 (defmethod unreference-foreign ((class (eql (find-class 'selection-data))) location)
42   (declare (ignore class))
43   (%selection-data-free location))
44
45 (defbinding %target-list-ref () pointer
46   (location pointer))
47   
48 (defbinding %target-list-unref () nil
49   (location pointer))
50
51 (defmethod reference-foreign ((class (eql (find-class 'target-list))) location)
52   (declare (ignore class))
53   (%target-list-ref location))
54
55 (defmethod unreference-foreign ((class (eql (find-class 'target-list))) location)
56   (declare (ignore class))
57   (%target-list-unref location))
58
59 (defbinding %target-list-new () pointer
60   (targets (vector (inlined target-entry)))
61   ((length targets) int))
62   
63 (defmethod initialize-instance ((target-list target-list) &key targets)
64   (setf  
65    (slot-value target-list 'location) 
66    (%target-list-new targets))
67   (call-next-method))
68
69 (defbinding target-list-add (target-list targets &optional flags info) nil
70   (target-list target-list)
71   (target gdk:atom)
72   (flags unsigned-int)
73   (info unsigned-int))
74
75 (defbinding target-list-add-table (target-list targets) nil
76   (target-list target-list)
77   ((etypecase targets 
78      ((or vector list) targets)
79      (target-entry (vector targets)))
80    (vector (inlined target-entry)))
81   ((etypecase targets 
82      ((or vector list) (length targets))
83      (target-entry 1))
84    int))
85
86 #+gtk2.6
87 (progn
88   (defbinding target-list-add-text-targets (target-list info &optional writable-p) nil
89     (target-list target-list)
90     (info unsigned-int)
91     (writable-p boolean))
92   
93   (defbinding target-list-add-image-targets (target-list info &optional writable-p) nil
94     (target-list target-list)
95     (info unsigned-int)
96     (writable-p boolean))
97
98   (defbinding target-list-add-uri-targets (target-list info &optional writable-p) nil
99     (target-list target-list)
100     (info unsigned-int)
101     (writable-p boolean)))
102
103 (defbinding target-list-remove () nil
104   (target-list target-list)
105   (target gdk:atom))
106
107 ;; (defbinding target-list-find () nil
108 ;;   (target-list target-list)
109 ;;   (target gdk:atom)
110 ;;   ...)
111
112 (defbinding (selection-set-owner "gtk_selection_owner_set_for_display")
113     (widget selection time &optional (display (gdk:display-get-default))) 
114     boolean
115   (display gdk:display)
116   (widget widget)
117   ((gdk:atom-intern selection) gdk:atom))
118
119 (defbinding selection-add-target () nil
120   (widget widget)
121   (selection gdk:atom)
122   (target gdk:atom)
123   (info unsigned-int))
124
125 (defbinding selection-add-targets (widget selection targets) nil
126   (widget widget)
127   (selection gdk:atom)
128   ((etypecase targets 
129      ((or vector list) targets)
130      (target-entry (vector targets)))
131    (vector (inlined target-entry)))
132   ((etypecase targets 
133      ((or vector list) (length targets))
134      (target-entry 1))
135    int))
136
137 (defbinding selection-clear-targets () nil
138   (widget widget)
139   (selection gdk:atom))
140
141 (defbinding selection-convert () boolean
142   (widget widget)
143   (selection gdk:atom)
144   (target gdk:atom)
145   (time unsigned-int))
146
147 (defbinding selection-data-set () boolean
148   (selection-data selection-data)
149   (type gdk:atom)
150   (format int)
151   (data pointer)
152   (length int))
153
154 (defbinding selection-data-set-text () boolean
155   (selection-data selection-data)
156   (text string)
157   (-1 integer))
158
159 (defbinding selection-data-get-text () string
160   (selection-data selection-data))
161
162 #+gtk2.6
163 (progn
164   (defbinding selection-data-set-pixbuf () boolean
165     (selection-data selection-data)
166     (puxbuf gdk:pixbuf))
167
168   (defbinding selection-data-get-pixbuf () gdk:pixbuf
169     (selection-data selection-data))
170
171   (defbinding selection-data-set-uris () boolean
172     (selection-data selection-data)
173     (uris (null-terminated-vector string)))
174
175   (defbinding selection-data-get-uris () (null-terminated-vector string)
176     (selection-data selection-data)))
177
178 (defbinding selection-data-get-targets () boolean
179   (selection-data selection-data)
180   (targets (vector gdk:atom n-atoms))
181   (n-atoms int))
182
183 #+gtk2.6
184 (defbinding selection-data-targets-include-image-p (selection-data &optional writable-p) boolean
185   (selection-data selection-data)
186   (writable-p boolean))
187
188 (defbinding selection-data-targets-include-text-p (selection-data) boolean
189   (selection-data selection-data))
190
191 (defbinding selection-remove-all (selection-data) boolean
192   (widget widget))
193
194
195 ;;; Clipboard -- untestet
196
197 (defbinding (clipboard-get "gtk_clipboard_get_for_display") 
198     (selection &optional (display (gdk:display-get-default))) clipboard
199   (display gdk:display)
200   ((gdk:atom-intern selection) gdk:atom))
201
202
203 (defcallback %clipboard-get-func (nil (clipboard pointer)
204                                       (selection-data selection-data)
205                                       (info int)
206                                       (user-data unsigned-int))
207   (funcall (car (find-user-data user-data)) selection-data info))
208
209 (defcallback %clipboard-clear-func (nil (clipboard pointer)
210                                         (user-data unsigned-int))
211   (funcall (cdr (find-user-data user-data))))
212
213 (defbinding clipboard-set-with-data (clipboard targets get-func clear-func) gobject
214   (clipboard clipboard)
215   (targets (vector target-entry))
216   ((length targets) unsigned-int)
217   (%clipboard-get-func callback)
218   (%clipboard-clear-func callback)
219   ((register-user-data (cons get-func clear-func)) unsigned-int))
220
221 (defbinding clipboard-clear () nil
222   (clipboard clipboard))
223
224 (defbinding clipboard-set-text (clipboard text) nil
225   (clipboard clipboard)
226   (text string)
227   ((length text) int))
228
229 #+gtk2.6
230 (defbinding clipboard-set-image () nil
231   (clipboard clipboard)
232   (pixbuf gdk:pixbuf))
233
234 (defun clipboard-set (clipboard object)
235   (etypecase object
236     (string (clipboard-set-text clipboard object))
237     #+gtk2.6
238     (gdk:pixbuf (clipboard-set-image clipboard object))))
239
240 (defcallback %clipboard-receive-func (nil (clipboard pointer)
241                                           (selection-data selection-data)
242                                           (user-data unsigned-int))
243   (funcall (find-user-data user-data) selection-data))
244
245 (defbinding clipboard-request-contents (clipboard target callback) nil
246   (clipboard clipboard)
247   ((gdk:atom-intern target) gdk:atom)
248   (%clipboard-receive-func callback)
249   ((register-callback-function callback) unsigned-int))
250
251 (defcallback %clipboard-text-receive-func (nil (clipboard pointer)
252                                                (text (copy-of string))
253                                                (user-data unsigned-int))
254   (funcall (find-user-data user-data) text))
255
256 (defbinding clipboard-request-text (clipboard callback) nil
257   (clipboard clipboard)
258   (%clipboard-text-receive-func callback)
259   ((register-callback-function callback) unsigned-int))
260
261 #+gtk2.6
262 (progn
263   (defcallback %clipboard-image-receive-func (nil (clipboard pointer)
264                                                   (image gdk:pixbuf)
265                                                   (user-data unsigned-int))
266     (funcall (find-user-data user-data) image))
267
268   (defbinding clipboard-request-image (clipboard callback) nil
269     (clipboard clipboard)
270     (%clipboard-image-receive-func callback)
271     ((register-callback-function callback) unsigned-int)))
272
273
274 (defcallback %clipboard-targets-receive-func 
275     (nil (clipboard pointer)
276          (atoms (vector gdk:atom n-atoms))
277          (n-atoms unsigned-int)
278          (user-data unsigned-int))
279   (funcall (find-user-data user-data) atoms))
280
281 (defbinding clipboard-request-targets (clipboard callback) nil
282   (clipboard clipboard)
283   (%clipboard-targets-receive-func callback)
284   ((register-callback-function callback) unsigned-int))
285
286 (defbinding clipboard-wait-for-contents () selection-data
287   (clipboard clipboard))
288
289 (defbinding clipboard-wait-for-text () string
290   (clipboard clipboard))
291
292 #+gtk2.6
293 (defbinding clipboard-wait-for-image () (referenced gdk:pixbuf)
294   (clipboard clipboard))
295
296 (defbinding clipboard-wait-is-text-available-p () boolean
297   (clipboard clipboard))
298
299 #+gtk2.6
300 (defbinding clipboard-wait-is-image-available-p () boolean
301   (clipboard clipboard))
302
303 (defbinding clipboard-wait-for-targets () boolean
304   (clipboard clipboard)
305   (targets (vector gdk:atom n-targets) :out)
306   (n-targets unsigned-int :out))
307
308 #+gtk2.6
309 (defbinding clipboard-wait-is-target-available-p () boolean
310   (clipboard clipboard)
311   (target gdk:atom))
312
313 #+gtk2.6
314 (defbinding clipboard-set-can-store () nil
315   (clipboard clipboard)
316   (targets (vector gdk:atom))
317   ((length targets) int))
318
319 #+gtk2.6
320 (defbinding clipboard-store () nil
321   (clipboard clipboard))
322
323 ;;;; Drag and Drop
324
325 (defbinding drag-dest-set (widget flags targets actions) nil
326   (widget widget)
327   (flags dest-defaults)
328   ((etypecase targets 
329      ((or vector list) targets)
330      (target-entry (vector targets)))
331    (vector (inlined target-entry)))
332   ((etypecase targets 
333      ((or vector list) (length targets))
334      (target-entry 1))
335    int)
336   (actions gdk:drag-action))
337
338 (defbinding drag-dest-set-proxy () nil
339   (widget widget)
340   (window gdk:window)
341   (protocol gdk:drag-protocol)
342   (use-coordinates-p boolean))
343
344 (defbinding drag-dest-unset () nil
345   (widget widget))
346
347 (defbinding drag-dest-find-target () gdk:atom
348   (widget widget)
349   (context gdk:drag-context)
350   (targets target-list))
351
352 (defbinding drag-dest-get-target-list () target-list
353   (widget widget))
354
355 (defbinding drag-dest-set-target-list () nil
356   (widget widget)
357   (targets target-list))
358
359 #+gtk2.6
360 (progn
361   (defbinding drag-dest-add-text-targets () nil
362     (widget widget))
363
364   (defbinding drag-dest-add-image-targets () nil
365     (widget widget))
366
367   (defbinding drag-dest-add-uri-targets () nil
368     (widget widget)))
369
370 (defbinding drag-finish () nil
371   (context gdk:drag-context)
372   (success boolean)
373   (delete boolean)
374   (time unsigned-int))
375
376 (defbinding drag-get-data () nil
377   (widget widget)
378   (context gdk:drag-context)
379   (target gdk:atom)
380   (time unsigned-int))
381
382 (defbinding drag-get-source-widget () widget
383   (context gdk:drag-context))
384
385 (defbinding drag-highlight () nil
386   (widget widget))
387
388 (defbinding drag-unhighlight () nil
389   (widget widget))
390
391 (defbinding drag-begin () gdk:drag-context
392   (widget widget)
393   (targets target-list)
394   (actions gdk:drag-action)
395   (button int)
396   (event gdk:event))
397
398 (defbinding %drag-set-icon-widget () nil
399   (context gdk:drag-context)
400   (widget widget)
401   (hot-x int)
402   (hot-y int))
403
404 (defbinding %drag-set-icon-pixmap () nil
405   (context gdk:drag-context)
406   (pixmap gdk:pixmap)
407   (mask gdk:bitmap)
408   (hot-x int)
409   (hot-y int))
410
411 (defbinding %drag-set-icon-pixbuf () nil
412   (context gdk:drag-context)
413   (pixbuf gdk:pixbuf)
414   (hot-x int)
415   (hot-y int))
416
417 (defbinding %drag-set-icon-stock () nil
418   (context gdk:drag-context)
419   (stock-id string)
420   (hot-x int)
421   (hot-y int))
422
423 (defbinding %drag-set-icon-default () nil
424   (context gdk:drag-context))
425
426 (defun drag-set-icon (context icon &optional (hot-x 0) (hot-y 0))
427   (etypecase icon
428     (widget (%drag-set-icon-widget context icon hot-x hot-y))
429     (gdk:pixbuf (%drag-set-icon-pixbuf context icon hot-x hot-y))
430     (string (%drag-set-icon-stock context icon hot-x hot-y))
431     (vector (multiple-value-bind (pixmap mask) (gdk:pixmap-create icon)
432               (%drag-set-icon-pixmap context pixmap mask hot-x hot-y)))
433     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
434                 (%drag-set-icon-pixbuf context pixbuf hot-x hot-y)))
435     (null (%drag-set-icon-default context))))
436
437 (defbinding drag-check-threshold-p () boolean
438   (widget widget)
439   (start-x int)
440   (start-y int)
441   (current-x int)
442   (current-y int))
443
444 (defbinding drag-source-set (widget start-button-mask targets actions) nil
445   (widget widget)
446   (start-button-mask gdk:modifier-type)
447   ((etypecase targets 
448      ((or vector list) targets)
449      (target-entry (vector targets)))
450    (vector (inlined target-entry)))
451   ((etypecase targets 
452      ((or vector list) (length targets))
453      (target-entry 1)) 
454    int)
455   (actions gdk:drag-action))
456
457 (defbinding %drag-source-set-icon-pixbuf () nil
458   (widget widget)
459   (pixbuf gdk:pixbuf))
460   
461 (defbinding %drag-source-set-icon-stock () nil
462   (widget widget)
463   (pixbuf gdk:pixbuf))
464
465 (defun drag-source-set-icon (widget icon)
466   (etypecase icon
467     (gdk:pixbuf (%drag-source-set-icon-pixbuf widget icon))
468     (string (%drag-source-set-icon-stock widget icon))
469 ;    (vector )
470     (pathname (let ((pixbuf (gdk:pixbuf-load icon)))
471                 (%drag-source-set-icon-pixbuf widget pixbuf)))))
472
473 (defbinding drag-source-unset () nil
474   (widget widget))
475
476 (defbinding drag-source-set-target-list () nil
477   (widget widget)
478   (targets (or null target-list)))
479
480 (defbinding drag-source-get-target-list () target-list
481   (widget widget))
482
483 #+gtk2.6
484 (progn
485   (defbinding drag-source-add-text-targets () nil
486     (widget widget))
487
488   (defbinding drag-source-add-image-targets () nil
489     (widget widget))
490
491   (defbinding drag-source-add-uri-targets () nil
492     (widget widget)))