annotate tests/Dnd/droptest.el @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents c9fe270a4101
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
1 ;; a short example how to use the new Drag'n'Drop API in
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
2 ;; combination with extents.
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
3 ;;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
4
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
5 (defun dnd-drop-message (event object text)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
6 (message "Dropped %s with :%s" text object)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
7 ;; signal that we have done something with the data
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
8 t)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
9
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
10 (defun do-nothing (event object)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
11 ;; signal that the data is still unprocessed
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
12 nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
13
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
14 (defun start-drag (event what &optional typ)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
15 ;; short drag interface, until the real one is implemented
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
16 (cond ((featurep 'offix)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
17 (if (numberp typ)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
18 (offix-start-drag event what typ)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
19 (offix-start-drag event what)))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
20 ((featurep 'cde)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
21 (if (not typ)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
22 (funcall (intern "cde-start-drag-internal") event nil (list what))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
23 (funcall (intern "cde-start-drag-internal") event t what)))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
24 (t display-message 'error "no valid drag protocols implemented")))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
25
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
26 (defun start-region-drag (event)
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
27 (interactive "_e")
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
28 (if (click-inside-extent-p event zmacs-region-extent)
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
29 ;; okay, this is a drag
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
30 (cond ((featurep 'offix)
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
31 (offix-start-drag-region event
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
32 (extent-start-position zmacs-region-extent)
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
33 (extent-end-position zmacs-region-extent)))
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
34 ((featurep 'cde)
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
35 ;; should also work with CDE
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
36 (cde-start-drag-region event
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
37 (extent-start-position zmacs-region-extent)
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
38 (extent-end-position zmacs-region-extent)))
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
39 (t (error "No offix or CDE support compiled in")))))
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
40
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
41 (defun make-drop-targets ()
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
42 (let ((buf (get-buffer-create "*DND misc-user extent test buffer*"))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
43 (s nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
44 (e nil))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
45 (set-buffer buf)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
46 (pop-to-buffer buf)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
47 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
48 (insert "[ DROP TARGET 1]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
49 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
50 (setq ext (make-extent s e))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
51 (set-extent-property ext
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
52 'experimental-dragdrop-drop-functions
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
53 '((do-nothing t t)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
54 (dnd-drop-message t t "on target 1")))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
55 (set-extent-property ext 'mouse-face 'highlight)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
56 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
57 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
58 (insert "[ DROP TARGET 2]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
59 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
60 (setq ext (make-extent s e))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
61 (set-extent-property ext
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
62 'experimental-dragdrop-drop-functions
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
63 '((dnd-drop-message t t "on target 2")))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
64 (set-extent-property ext 'mouse-face 'highlight)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
65 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
66 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
67 (insert "[ DROP TARGET 3]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
68 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
69 (setq ext (make-extent s e))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
70 (set-extent-property ext
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
71 'experimental-dragdrop-drop-functions
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
72 '((dnd-drop-message t t "on target 3")))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
73 (set-extent-property ext 'mouse-face 'highlight)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
74 (newline 2)))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
75
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
76 (defun make-drag-starters ()
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
77 (let ((buf (get-buffer-create "*DND misc-user extent test buffer*"))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
78 (s nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
79 (e nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
80 (ext nil)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
81 (kmap nil))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
82 (set-buffer buf)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
83 (pop-to-buffer buf)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
84 (erase-buffer buf)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
85 (insert "Try to drag data from one of the upper extents to one\nof the lower extents. Make sure that your minibuffer is big\ncause it is used to display the data.\n\nYou may also try to select some of this text and drag it with button2.\n\nTo ")
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
86 (setq s (point))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
87 (insert "EXIT")
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
88 (setq e (point))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
89 (insert " this demo, press 'q'.")
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
90 (setq ext (make-extent s e))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
91 (setq kmap (make-keymap))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
92 (define-key kmap [button1] 'end-dnd-demo)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
93 (set-extent-property ext 'keymap kmap)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
94 (set-extent-property ext 'mouse-face 'highlight)
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
95 (newline 2)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
96 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
97 (insert "[ TEXT DRAG TEST ]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
98 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
99 (setq ext (make-extent s e))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
100 (set-extent-property ext 'mouse-face 'isearch)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
101 (setq kmap (make-keymap))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
102 (define-key kmap [button1] 'text-drag)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
103 (set-extent-property ext 'keymap kmap)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
104 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
105 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
106 (insert "[ FILE DRAG TEST ]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
107 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
108 (setq ext (make-extent s e))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
109 (set-extent-property ext 'mouse-face 'isearch)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
110 (setq kmap (make-keymap))
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
111 (if (featurep 'cde)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
112 (define-key kmap [button1] 'cde-file-drag)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
113 (define-key kmap [button1] 'file-drag))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
114 (set-extent-property ext 'keymap kmap)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
115 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
116 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
117 (insert "[ FILES DRAG TEST ]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
118 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
119 (setq ext (make-extent s e))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
120 (set-extent-property ext 'mouse-face 'isearch)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
121 (setq kmap (make-keymap))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
122 (define-key kmap [button1] 'files-drag)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
123 (set-extent-property ext 'keymap kmap)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
124 (insert " ")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
125 (setq s (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
126 (insert "[ URL DRAG TEST ]")
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
127 (setq e (point))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
128 (setq ext (make-extent s e))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
129 (set-extent-property ext 'mouse-face 'isearch)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
130 (setq kmap (make-keymap))
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
131 (if (featurep 'cde)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
132 (define-key kmap [button1] 'cde-file-drag)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
133 (define-key kmap [button1] 'url-drag))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
134 (set-extent-property ext 'keymap kmap)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
135 (newline 3)))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
136
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
137 (defun text-drag (event)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
138 (interactive "@e")
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
139 (start-drag event "That's a test"))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
140
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
141 (defun file-drag (event)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
142 (interactive "@e")
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
143 (start-drag event "/tmp/DropTest.xpm" 2))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
144
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
145 (defun cde-file-drag (event)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
146 (interactive "@e")
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
147 (start-drag event '("/tmp/DropTest.xpm") t))
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
148
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
149 (defun url-drag (event)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
150 (interactive "@e")
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
151 (start-drag event "http://www.xemacs.org/" 8))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
152
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
153 (defun files-drag (event)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
154 (interactive "@e")
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
155 (start-drag event '("/tmp/DropTest.html" "/tmp/DropTest.xpm" "/tmp/DropTest.tex") 3))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
156
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
157 (setq experimental-dragdrop-drop-functions '((do-nothing t t)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
158 ;; CDE does not have any button info...
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
159 (dnd-drop-message 0 t "cde-drop somewhere else")
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
160 (dnd-drop-message 2 t "region somewhere else")
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
161 (dnd-drop-message 1 t "drag-source somewhere else")
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
162 (do-nothing t t)))
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
163
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
164 (make-drag-starters)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 197
diff changeset
165 (make-drop-targets)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
166
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
167 (defun end-dnd-demo ()
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
168 (interactive)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
169 (global-set-key [button2] button2-func)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
170 (bury-buffer))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
171
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
172 (setq lmap (make-keymap))
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
173 (use-local-map lmap)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
174 (local-set-key [q] 'end-dnd-demo)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
175 (setq button2-func (lookup-key global-map [button2]))
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
176 (global-set-key [button2] 'start-region-drag)