annotate tests/Dnd/droptest.el @ 428:3ecd8885ac67 r21-2-22

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