1 ;; a short example how to use the new Drag'n'Drop API in
2 ;; combination with extents.
5 (defun dnd-drop-message (event object text)
6 (message "Dropped %s with :%s" text object)
7 ;; signal that we have done something with the data
10 (defun do-nothing (event object)
11 ;; signal that the data is still unprocessed
14 (defun start-drag (event what &optional typ)
15 ;; short drag interface, until the real one is implemented
16 (cond ((featurep 'offix)
18 (offix-start-drag event what typ)
19 (offix-start-drag event what)))
22 (funcall (intern "cde-start-drag-internal") event nil (list what))
23 (funcall (intern "cde-start-drag-internal") event t what)))
24 (t display-message 'error "no valid drag protocols implemented")))
26 (defun start-region-drag (event)
28 (if (click-inside-extent-p event zmacs-region-extent)
29 ;; okay, this is a drag
30 (cond ((featurep 'offix)
31 (offix-start-drag-region event
32 (extent-start-position zmacs-region-extent)
33 (extent-end-position zmacs-region-extent)))
35 ;; should also work with CDE
36 (cde-start-drag-region event
37 (extent-start-position zmacs-region-extent)
38 (extent-end-position zmacs-region-extent)))
39 (t (error "No offix or CDE support compiled in")))))
41 (defun make-drop-targets ()
42 (let ((buf (get-buffer-create "*DND misc-user extent test buffer*"))
48 (insert "[ DROP TARGET 1]")
50 (setq ext (make-extent s e))
51 (set-extent-property ext
52 'experimental-dragdrop-drop-functions
54 (dnd-drop-message t t "on target 1")))
55 (set-extent-property ext 'mouse-face 'highlight)
58 (insert "[ DROP TARGET 2]")
60 (setq ext (make-extent s e))
61 (set-extent-property ext
62 'experimental-dragdrop-drop-functions
63 '((dnd-drop-message t t "on target 2")))
64 (set-extent-property ext 'mouse-face 'highlight)
67 (insert "[ DROP TARGET 3]")
69 (setq ext (make-extent s e))
70 (set-extent-property ext
71 'experimental-dragdrop-drop-functions
72 '((dnd-drop-message t t "on target 3")))
73 (set-extent-property ext 'mouse-face 'highlight)
76 (defun make-drag-starters ()
77 (let ((buf (get-buffer-create "*DND misc-user extent test buffer*"))
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 ")
89 (insert " this demo, press 'q'.")
90 (setq ext (make-extent s e))
91 (setq kmap (make-keymap))
92 (define-key kmap [button1] 'end-dnd-demo)
93 (set-extent-property ext 'keymap kmap)
94 (set-extent-property ext 'mouse-face 'highlight)
97 (insert "[ TEXT DRAG TEST ]")
99 (setq ext (make-extent s e))
100 (set-extent-property ext 'mouse-face 'isearch)
101 (setq kmap (make-keymap))
102 (define-key kmap [button1] 'text-drag)
103 (set-extent-property ext 'keymap kmap)
106 (insert "[ FILE DRAG TEST ]")
108 (setq ext (make-extent s e))
109 (set-extent-property ext 'mouse-face 'isearch)
110 (setq kmap (make-keymap))
112 (define-key kmap [button1] 'cde-file-drag)
113 (define-key kmap [button1] 'file-drag))
114 (set-extent-property ext 'keymap kmap)
117 (insert "[ FILES DRAG TEST ]")
119 (setq ext (make-extent s e))
120 (set-extent-property ext 'mouse-face 'isearch)
121 (setq kmap (make-keymap))
122 (define-key kmap [button1] 'files-drag)
123 (set-extent-property ext 'keymap kmap)
126 (insert "[ URL DRAG TEST ]")
128 (setq ext (make-extent s e))
129 (set-extent-property ext 'mouse-face 'isearch)
130 (setq kmap (make-keymap))
132 (define-key kmap [button1] 'cde-file-drag)
133 (define-key kmap [button1] 'url-drag))
134 (set-extent-property ext 'keymap kmap)
137 (defun text-drag (event)
139 (start-drag event "That's a test"))
141 (defun file-drag (event)
143 (start-drag event "/tmp/DropTest.xpm" 2))
145 (defun cde-file-drag (event)
147 (start-drag event '("/tmp/DropTest.xpm") t))
149 (defun url-drag (event)
151 (start-drag event "http://www.xemacs.org/" 8))
153 (defun files-drag (event)
155 (start-drag event '("/tmp/DropTest.html" "/tmp/DropTest.xpm" "/tmp/DropTest.tex") 3))
157 (setq experimental-dragdrop-drop-functions '((do-nothing t t)
158 ;; CDE does not have any button info...
159 (dnd-drop-message 0 t "cde-drop somewhere else")
160 (dnd-drop-message 2 t "region somewhere else")
161 (dnd-drop-message 1 t "drag-source somewhere else")
167 (defun end-dnd-demo ()
169 (global-set-key [button2] button2-func)
172 (setq lmap (make-keymap))
174 (local-set-key [q] 'end-dnd-demo)
175 (setq button2-func (lookup-key global-map [button2]))
176 (global-set-key [button2] 'start-region-drag)