GNU bug report logs -
#3468
Support drag and drop of text on MS Windows
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 3468 in the body.
You can then email your comments to 3468 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#3468
; Package
emacs
.
(Fri, 05 Jun 2009 00:00:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
"Erdkern Erdkern" <Erdkern2000 <at> gmx.de>
:
New bug report received and forwarded. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Fri, 05 Jun 2009 00:00:04 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):
I use windows as operating system. I want to drag text from text editor or browser (say Wordpad or Firefox) and drop it in emacs, but this is not possible, drop is not allowed. On the other side, if I drag an unknown filetype (say, an *.rdp-File) into emacs, it is dropped as text.
In GNU Emacs 22.3.1 (i386-mingw-nt5.1.2600)
of 2008-09-06 on SOFT-MJASON
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (3.4)'
Important settings:
value of $LC_ALL: nil
value of $LC_COLLATE: nil
value of $LC_CTYPE: nil
value of $LC_MESSAGES: nil
value of $LC_MONETARY: nil
value of $LC_NUMERIC: nil
value of $LC_TIME: nil
value of $LANG: DEU
locale-coding-system: cp1252
default-enable-multibyte-characters: t
Major mode: Lisp Interaction
Minor modes in effect:
cua-mode: t
encoded-kbd-mode: t
tooltip-mode: t
tool-bar-mode: t
mouse-wheel-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
unify-8859-on-encoding-mode: t
utf-translate-cjk-mode: t
auto-compression-mode: t
column-number-mode: t
line-number-mode: t
transient-mark-mode: t
Recent input:
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <down>
<down-mouse-1> <mouse-1> <down-mouse-1> <mouse-1> <down-mouse-1>
<mouse-1> <mouse-1> <mouse-1> <mouse-1> <mouse-1> <mouse-1>
<mouse-1> <mouse-1> <mouse-1> <mouse-1> <mouse-1> <mouse-1>
<mouse-1> <mouse-1> <mouse-1> <mouse-1> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <tool-bar>
<kill-buffer> <help-echo> <help-echo> <help-echo> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
<menu-bar> <help-menu> <send-emacs-bug-report>
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Loading emacsbug...
Loading regexp-opt...done
Loading emacsbug...done
Loading help-mode...done
Auto-saving...done
Undo! [29 times]
Auto-saving...done
*** E-Mail body has been placed on clipboard, please paste them here! ***
--
GMX FreeDSL mit DSL 6.000 Flatrate und Telefonanschluss nur 17,95 Euro/mtl.!
http://dslspecial.gmx.de/freedsl-aktionspreis/?ac=OM.AD.PD003K11308T4569a
Severity set to `wishlist' from `normal'
Request was from
Chong Yidong <cyd <at> stupidchicken.com>
to
control <at> emacsbugs.donarmstrong.com
.
(Fri, 05 Jun 2009 22:50:05 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Mon, 30 Sep 2019 15:30:02 GMT)
Full text and
rfc822 format available.
Message #10 received at 3468 <at> debbugs.gnu.org (full text, mbox):
"Erdkern Erdkern" <Erdkern2000 <at> gmx.de> writes:
> I use windows as operating system. I want to drag text from text
> editor or browser (say Wordpad or Firefox) and drop it in emacs, but
> this is not possible, drop is not allowed. On the other side, if I
> drag an unknown filetype (say, an *.rdp-File) into emacs, it is
> dropped as text.
(I'm going through old bug reports that unfortunately didn't get any
response at the time.)
I tried this in Emacs 27, but on GNU/Linux, and it worked fine for me
there. Are you still seeing this problem?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) moreinfo.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 30 Sep 2019 15:31:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Mon, 30 Sep 2019 15:51:02 GMT)
Full text and
rfc822 format available.
Message #15 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> From: Lars Ingebrigtsen <larsi <at> gnus.org>
> Date: Mon, 30 Sep 2019 17:29:54 +0200
> Cc: 3468 <at> debbugs.gnu.org
>
> I tried this in Emacs 27, but on GNU/Linux, and it worked fine for me
> there. Are you still seeing this problem?
Emacs on MS-Windows doesn't support drag-n-drop of arbitrary text, it
only supports drag-n-drop of file names. This is indicated by the
"you can't do that" icon shown as the mouse pointer when you attempt
to drop the text onto the Emacs frame.
The Emacs User manual says in "Drag and Drop":
The XDND and Motif drag and drop protocols, and the old KDE 1.x
protocol, are currently supported.
which doesn't include any MS-Windows protocols.
The reason for not supporting this on MS-Windows is that the relevant
system APIs are only available for C++ programs. If someone knows how
to work around this limitation, I'm sure we will welcome patches or at
least an explanation for how to do that in plain C.
Changed bug title to 'Support drag and drop of text on MS Windows' from 'drag and drop text'
Request was from
Stefan Kangas <stefan <at> marxist.se>
to
control <at> debbugs.gnu.org
.
(Thu, 13 Aug 2020 01:42:02 GMT)
Full text and
rfc822 format available.
Removed tag(s) moreinfo.
Request was from
Stefan Kangas <stefan <at> marxist.se>
to
control <at> debbugs.gnu.org
.
(Thu, 13 Aug 2020 01:42:02 GMT)
Full text and
rfc822 format available.
Added tag(s) help.
Request was from
Stefan Kangas <stefan <at> marxist.se>
to
control <at> debbugs.gnu.org
.
(Thu, 13 Aug 2020 01:42:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sat, 28 Sep 2024 21:54:02 GMT)
Full text and
rfc822 format available.
Message #24 received at 3468 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
This patch implements drag-and-drop for w32 for files and text, using C,
not C++.
This should work from Windows 95, but I can't test it. Because of this,
the prior implementation with WM_DROPFILES has been removed with '#if
0', and can probably be completely removed.
I tested with mingw-w64 and mingw on Windows 11.
Text is inserted at point position, not at drop position. I don't know
how this works on other platforms.
[0001-Implement-drag-n-drop-for-w32-with-support-for-files.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sun, 29 Sep 2024 07:21:01 GMT)
Full text and
rfc822 format available.
Message #27 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Date: Sat, 28 Sep 2024 23:52:45 +0200
> From: Cecilio Pardo <cpardo <at> imayhem.com>
>
> This patch implements drag-and-drop for w32 for files and text, using C,
> not C++.
> This should work from Windows 95, but I can't test it. Because of this,
> the prior implementation with WM_DROPFILES has been removed with '#if
> 0', and can probably be completely removed.
I think we should remove those "#if 0" parts, yes. If and when
someone is able to test this on Windows 9X, they will report problems
they encounter, and we can take it from there. The removed code is
available in Git, so it is not lost.
> Text is inserted at point position, not at drop position. I don't know
> how this works on other platforms.
Po Lu, any comments to this particular aspect?
I have some comments to the code below.
> Implement dnd with IDropTarget
This should explicitly mention MS-Windows.
> * lisp/term/w32-win.el (w32-drag-n-drop): changed to handle files or strings
> * src/w32fns.c
> (process_dropfiles): new, convert DROPFILES struct to array of strings
> (w32_createwindow): assign an IDropTarget to each new frame
> (w32_name_of_message): added new messages
> (w32_msg_pump): Changed CoInitialize to OleInitialize, needed by the
> drag-n-drop functions
> (w32_wnd_proc): new struct w32_drop_target, and w32_drop_target_*
> functions to implement the IDropTarget interface
> * src/w32term.c (w32_read_socket): handle WM_EMACS_DROPFILES,
> WM_EMACS_DROPSTRING, skip WM_EMACS_DROPFILES
> * src/w32term.h (): add WM_EMACS_DROPFILES, WM_EMACS_DROPSTRING
Some of these lines are too long (try limiting to 64 columns). Also,
descriptions of changes should be complete sentences: start with a
capital letter and end in a period, like this:
(w32_createwindow): Assign an IDropTarget to each new frame.
> (defun w32-drag-n-drop (event &optional new-frame)
> - "Edit the files listed in the drag-n-drop EVENT.
> -Switch to a buffer editing the last file dropped."
> + "If the drag-n-drop EVENT is for a file or files, edit those
> +files. Switch to a buffer editing the last file dropped.
The first line of a doc string should be a single complete sentence.
In this case, I suggest:
Perform drag-n-drop action according to data in EVENT.
If EVENT is for one or more files, visit those files in corresponding
buffers, and switch to the buffer that visits the last dropped file.
If EVENT is for text, insert that text at point into the buffer
shown in the window that is the target of the drop; if that buffer is
read-only, add the dropped text to kill-ring.
If the optional argument NEW-FRAME is non-nil, perform the
drag-n-drop action in a newly-created frame using its selected-window
and that window's buffer.
> + (if (stringp arg)
> + (dnd-insert-text window 'copy arg)
> + (dnd-handle-multiple-urls
> + window
> + (mapcar #'w32-dropped-file-to-url arg)
> + 'private)))))
Please add a comment here saying that the payload in the EVENT should
be either a string (meaning the text to drop) or a list of strings
(meaning names of files to drop). This is important because a file
name is also a string, so it is not obvious how we distinguish between
the two possible payloads.
> +/* From the DROPFILES struct, extract the list of filenames. Returns a
> + NULL terminated malloc array of malloc strings that should be freed
^^^^^^ ^^^^^^
"malloced"
> +static char **
> +process_dropfiles (DROPFILES *files)
> +{
> + char *start_of_files = (char*)files + files->pFiles;
^^^^^^^^^^^^
Style: "(char *) files".
> + int count = 0;
> + char filename[MAX_PATH];
^^^^^^^^
This should be MAX_UTF8_PATH, since filename[] is UTF-8 encoded.
> + if (files->fWide)
What determines whether we get "wide" file names or ANSI file names?
We want to get "wide" file names where possible, but I don't see where
we request that?
> + {
> + WCHAR *p = (WCHAR*)start_of_files;
^^^^^^^^^^^^^^^^^^^^^^
"(WCHAR *) start_of_files".
> + p = (WCHAR*)start_of_files;
Likewise.
> + for ( int i = 0; *p; p += wcslen (p) + 1, i++)
^^
Style: no space there.
> + filenames = malloc ((count+1) * sizeof (char*));
You call malloc here, but the function which frees uses xfree.
We should probably call xmalloc here, but xmalloc could signal an
error, and this code runs in a non-main thread, doesn't it? If so, I
think the function which frees needs to call 'free', nor 'xfree'. And
we need to handle the case malloc returns NULL.
> + filenames [i] = xstrdup (filename);
For the same reason, we cannot call xstrdup here, and neither can we
call strdup (because it comes from MSVCRT, and will call a different
version of malloc). We need to provide a private version of strdup.
But see below about moving all this processing to the main thread.
Also, "filenames[i]", without the space before the brackets.
> + struct w32_drop_target *target = (struct w32_drop_target *)This;
> + xfree( target->i_drop_target.lpVtbl );
> + xfree( target );
^^^^
Style: missing and extra space again.
> +static HRESULT STDMETHODCALLTYPE
> +w32_drop_target_DragEnter( IDropTarget *This, IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
Please break this long list of arguments into several lines.
Also, our style is to write
w32_drop_target_DragEnter (IDropTarget *This,
That is, one space between the function name and the opening
parenthesis, and no space between the parenthesis and the first
argument.
> +static HRESULT STDMETHODCALLTYPE
> +w32_drop_target_DragOver ( IDropTarget *This, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
Likewise here (and elsewhere in the patch).
> + formatetc.cfFormat = CF_UNICODETEXT;
> + if (SUCCEEDED (IDataObject_GetData (pDataObj, &formatetc, &stgmedium)))
> + {
> + if (stgmedium.tymed == TYMED_HGLOBAL)
> + {
> + WCHAR *text = (WCHAR*)GlobalLock (stgmedium.hGlobal);
> + Lisp_Object text_string = from_unicode_buffer (text);
> + char *utf8 = xstrdup (SSDATA (ENCODE_UTF_8 (text_string)));
> + my_post_msg (&msg, target->hwnd, WM_EMACS_DROPSTRING,
> + 0, (LPARAM)utf8 );
> + GlobalUnlock (stgmedium.hGlobal);
> + }
> + ReleaseStgMedium (&stgmedium);
> + return S_OK;
> + }
If this runs in a non-main thread, then we cannot do this: calling
functions that manipulate Lisp data in non-main threads is a no-no.
Can we instead delegate the actual processing to where
WM_EMACS_DROPSTRING is processed? If not, why not?
To tell the truth, I'd be happier if we could do the same with
WM_EMACS_DROPFILES, i.e. convert the file names and allocate memory
for them in the main thread: that would remove all the issues
mentioned above with xmalloc, xstrdup, etc., and be in general much
safer.
Also, there's no need to call ENCODE_UTF_8, since from_unicode_buffer
already returns the text in the internal representation. You are
basically decoding strings from UTF-16, then encode them in UTF-8,
only to decode them again in the main thread. (This will also be
avoided if we do everything in the main thread.)
> + formatetc.cfFormat = CF_TEXT;
> + if (SUCCEEDED (IDataObject_GetData (pDataObj, &formatetc, &stgmedium)))
> + {
> + if (stgmedium.tymed == TYMED_HGLOBAL)
> + {
> + char *text = (char*)GlobalLock (stgmedium.hGlobal);
> +
> + int l = strlen (text);
> + WCHAR *text_utf16 = xmalloc (sizeof (WCHAR) * l + 1 );;
> + if (MultiByteToWideChar (CP_ACP, 0, text, l, text_utf16, l + 1))
We cannot call MultiByteToWideChar directly: it will prevent Emacs
from running on Windows 9X, where that function is available only
after loading a special DLL. We need to call this function via a
function pointer, pMultiByteToWideChar.
> + {
> + Lisp_Object text_string = from_unicode_buffer (text_utf16);
> + char *utf8 = xstrdup (SSDATA (ENCODE_UTF_8 (text_string)));
> + my_post_msg (&msg, target->hwnd, WM_EMACS_DROPSTRING,
> + 0, (LPARAM)utf8 );
This is a very convoluted way of converting ANSI encoded string to
UTF-8. I would simply use DECODE_SYSTEM here (subject to the same
restriction regarding doing that in a non-main thread).
> @@ -2548,7 +2720,23 @@ w32_createwindow (struct frame *f, int *coords)
> SetWindowLong (hwnd, WND_BACKGROUND_INDEX, FRAME_BACKGROUND_PIXEL (f));
>
> /* Enable drag-n-drop. */
> + struct w32_drop_target *drop_target = xmalloc (sizeof (struct w32_drop_target));
> + drop_target-> hwnd = hwnd;
> +
> + IDropTargetVtbl *vtbl = xmalloc (sizeof (IDropTargetVtbl));
^^^^^^^
w32_createwindow runs in the input thread, so it cannot safely call
xmalloc.
> case WM_EMACS_CREATEWINDOW:
> - /* Initialize COM for this window. Even though we don't use it,
> - some third party shell extensions can cause it to be used in
> + /* Initialize COM for this window. Needed for RegisterDragDrop.
^^
Two spaces between sentences, please.
> + case WM_EMACS_DROPSTRING:
> + f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
> + if (!f)
> + break;
> + XSETFRAME (inev.frame_or_window, f);
> + inev.kind = DRAG_N_DROP_EVENT;
> + inev.code = 0;
> + inev.timestamp = msg.msg.time;
> + inev.modifiers = msg.dwModifiers;
> + ScreenToClient (msg.msg.hwnd, &msg.msg.pt);
> + XSETINT (inev.x, msg.msg.pt.x);
> + XSETINT (inev.y, msg.msg.pt.y);
> + inev.arg = make_string ((char*)msg.msg.lParam, strlen((char*)msg.msg.lParam));
Since we are (hopefully) going to move the prcessing and decoding of
the dropped string to this place, just decoding it from UTF-18 or ANSI
(via DECODE_SYSTEM) should be enough.
> + xfree ((void*)msg.msg.lParam);
This may need to be 'free', see above.
> + case WM_EMACS_DROPFILES:
> + {
> + f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
> + if (!f)
> + break;
> + XSETFRAME (inev.frame_or_window, f);
> + inev.kind = DRAG_N_DROP_EVENT;
> + inev.code = 0;
> + inev.timestamp = msg.msg.time;
> + inev.modifiers = msg.dwModifiers;
> + ScreenToClient (msg.msg.hwnd, &msg.msg.pt);
> + XSETINT (inev.x, msg.msg.pt.x);
> + XSETINT (inev.y, msg.msg.pt.y);
> +
> + Lisp_Object files = Qnil;
> + char **filenames = (char**)msg.msg.lParam;
> + for (int n = 0; filenames[n]; n++ )
> + {
> + files = Fcons (DECODE_FILE (build_string (filenames[n])), files );
> + xfree (filenames[n]);
> + }
> + xfree (filenames);
Similarly here.
Finally, we need a NEWS entry (near the end of NEWS) announcing this
new capability.
Thanks!
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sun, 29 Sep 2024 11:19:02 GMT)
Full text and
rfc822 format available.
Message #30 received at 3468 <at> debbugs.gnu.org (full text, mbox):
On 29/09/2024 9:19, Eli Zaretskii wrote:
>> + if (files->fWide)
>
> What determines whether we get "wide" file names or ANSI file names?
> We want to get "wide" file names where possible, but I don't see where
> we request that?
We can't request it, I suppose it depends on the OS version or the
program sending the drop.
> If this runs in a non-main thread, then we cannot do this: calling
> functions that manipulate Lisp data in non-main threads is a no-no.
> Can we instead delegate the actual processing to where
> WM_EMACS_DROPSTRING is processed? If not, why not?
It runs indeed on the "shell thread". I'll move all the processing to
the message handler.
Thanks a lot for your review, and sorry for all the style mistakes.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sun, 29 Sep 2024 11:38:02 GMT)
Full text and
rfc822 format available.
Message #33 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Date: Sun, 29 Sep 2024 13:17:26 +0200
> Cc: 3468 <at> debbugs.gnu.org
> From: Cecilio Pardo <cpardo <at> imayhem.com>
>
> On 29/09/2024 9:19, Eli Zaretskii wrote:
>
> >> + if (files->fWide)
> >
> > What determines whether we get "wide" file names or ANSI file names?
> > We want to get "wide" file names where possible, but I don't see where
> > we request that?
>
> We can't request it, I suppose it depends on the OS version or the
> program sending the drop.
What did you see on Windows 11? Do we always receive "wide" file
names? Did you try dragging file names whose characters are not
supported by the current ANSI codepage, and if so, did it work?
> > If this runs in a non-main thread, then we cannot do this: calling
> > functions that manipulate Lisp data in non-main threads is a no-no.
> > Can we instead delegate the actual processing to where
> > WM_EMACS_DROPSTRING is processed? If not, why not?
>
> It runs indeed on the "shell thread". I'll move all the processing to
> the message handler.
Thanks. By "message handler" you mean w32_read_socket, yes?
> Thanks a lot for your review, and sorry for all the style mistakes.
No need to apologize, it takes time to learn the subtleties of our
conventions.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sun, 29 Sep 2024 11:47:06 GMT)
Full text and
rfc822 format available.
Message #36 received at 3468 <at> debbugs.gnu.org (full text, mbox):
On 29/09/2024 13:36, Eli Zaretskii wrote:
> What did you see on Windows 11? Do we always receive "wide" file
> names?
Yes, always wide on Windows 11 on my tests.
> Did you try dragging file names whose characters are not supported by
> the current ANSI codepage, and if so, did it work?
I just tried and it works fine.
>> It runs indeed on the "shell thread". I'll move all the processing to
>> the message handler.
>
> Thanks. By "message handler" you mean w32_read_socket, yes?
Yes.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Mon, 30 Sep 2024 21:22:02 GMT)
Full text and
rfc822 format available.
Message #39 received at 3468 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Here is the reworked version.
Now the processing of the drop data is delayed until we process the
WM_EMACS_DROP message at w32_read_socket.
There is no malloc/strdup.
[0001-Implement-drag-n-drop-for-w32-with-support-for-files.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sat, 05 Oct 2024 11:09:01 GMT)
Full text and
rfc822 format available.
Message #42 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Date: Mon, 30 Sep 2024 23:20:32 +0200
> From: Cecilio Pardo <cpardo <at> imayhem.com>
> Cc: 3468 <at> debbugs.gnu.org
>
> Here is the reworked version.
>
> Now the processing of the drop data is delayed until we process the
> WM_EMACS_DROP message at w32_read_socket.
>
> There is no malloc/strdup.
Well, there are still 2 calls to malloc in w32_createwindow. Any
reasons not to call xmalloc instead? Can w32_createwindow be called
before we call init_heap?
And I have a few minor comments below.
> + if (files->fWide)
> + {
> + WCHAR *p = (WCHAR *) start_of_files;
> + for (; *p; p += wcslen (p) + 1)
> + {
> + filename_from_utf16(p, filename);
> + lisp_files = Fcons (DECODE_FILE (build_string (filename)),
^^^^^^^^^^^^
This should use build_unibyte_string instead, since we know we want a
unibyte string here, which we then decode.
> + for (; *p; p += strlen(p) + 1)
> + {
> + filename_from_ansi (p, filename);
> + lisp_files = Fcons (DECODE_FILE (build_string (filename)),
> + lisp_files );
Same here.
> +Lisp_Object
> +w32_process_dnd_data (int format, void *hGlobal)
> +{
> + Lisp_Object result = Qnil;
> + HGLOBAL hg = (HGLOBAL) hGlobal;
> +
> + switch (format)
> + {
> + case CF_HDROP:
> + {
> + DROPFILES *files = (DROPFILES *) GlobalLock (hg);
> + if (files)
> + result = process_dropfiles (files);
> + GlobalUnlock (hg);
> + break;
> + }
> + case CF_UNICODETEXT:
> + {
> + WCHAR *text = (WCHAR *) GlobalLock (hg);
> + result = from_unicode_buffer (text);
> + GlobalUnlock (hg);
> + break;
> + }
> + case CF_TEXT:
> + {
> + char *text = (char *) GlobalLock (hg);
> + result = DECODE_SYSTEM (build_unibyte_string (text));
> + GlobalUnlock (hg);
> + break;
> + }
> + }
> +
> + GlobalFree (hg);
This function should call block_input at entry and unblock_input
before it exits, because we must make sure all the GlobalLock calls
are paired with GlobalUnlock and GlobalFree, while functions we call
here, process_dropfiles etc., all cons Lisp object, and therefore
could potentially QUIT, which throws to top-level.
> +static HRESULT STDMETHODCALLTYPE
> +w32_drop_target_DragEnter (IDropTarget *This, IDataObject *pDataObj,
> + DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
> +{
> + *pdwEffect = DROPEFFECT_COPY;
> + return S_OK;
> +}
> +
> +static HRESULT STDMETHODCALLTYPE
> +w32_drop_target_DragOver (IDropTarget *This, DWORD grfKeyState, POINTL pt,
> + DWORD *pdwEffect)
> +{
> + *pdwEffect = DROPEFFECT_COPY;
> + return S_OK;
It would be good here to have comments that explain the meaning of
DROPEFFECT_COPY and the rationale for returning this value.
> @@ -2548,7 +2725,20 @@ w32_createwindow (struct frame *f, int *coords)
> SetWindowLong (hwnd, WND_BACKGROUND_INDEX, FRAME_BACKGROUND_PIXEL (f));
>
> /* Enable drag-n-drop. */
> - DragAcceptFiles (hwnd, TRUE);
> + struct w32_drop_target *drop_target =
> + malloc (sizeof (struct w32_drop_target));
> + drop_target->hwnd = hwnd;
> +
> + IDropTargetVtbl *vtbl = malloc (sizeof (IDropTargetVtbl));
> + drop_target->i_drop_target.lpVtbl = vtbl;
> + vtbl->QueryInterface = w32_drop_target_QueryInterface;
> + vtbl->AddRef = w32_drop_target_AddRef;
> + vtbl->Release = w32_drop_target_Release;
> + vtbl->DragEnter = w32_drop_target_DragEnter;
> + vtbl->DragOver = w32_drop_target_DragOver;
> + vtbl->DragLeave = w32_drop_target_DragLeave;
> + vtbl->Drop = w32_drop_target_Drop;
> + RegisterDragDrop (hwnd, &drop_target->i_drop_target);
Do we ever have to free the two memory chunks we allocate here? Like
when the window is disposed of?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sat, 05 Oct 2024 12:08:02 GMT)
Full text and
rfc822 format available.
Message #45 received at 3468 <at> debbugs.gnu.org (full text, mbox):
On 05/10/2024 13:07, Eli Zaretskii wrote:
>> There is no malloc/strdup.
>
> Well, there are still 2 calls to malloc in w32_createwindow. Any
> reasons not to call xmalloc instead? Can w32_createwindow be called
> before we call init_heap?
[...]
> Do we ever have to free the two memory chunks we allocate here? Like
> when the window is disposed of?
They are freed in w32_drop_target_Release, which is called internally
when we call RevokeDragDrop while handling the WW_EMACS_DESTROYWINDOW on
w32_wnd_proc.
As this runs on the input thread, I used malloc/free instead of
xmalloc/xfree. I could send a message to handle on w32_read_socket and
then use xmalloc.
> This function should call block_input at entry and unblock_input
> before it exits, because we must make sure all the GlobalLock calls
> are paired with GlobalUnlock and GlobalFree, while functions we call
> here, process_dropfiles etc., all cons Lisp object, and therefore
> could potentially QUIT, which throws to top-level.
The function (w32_process_dnd_data) is called from within the
block_input/unblock_input on w32_read_socket.
Should I add its own calls for clarity? Maybe just a comment?
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sat, 05 Oct 2024 12:31:02 GMT)
Full text and
rfc822 format available.
Message #48 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Date: Sat, 5 Oct 2024 14:07:01 +0200
> Cc: 3468 <at> debbugs.gnu.org
> From: Cecilio Pardo <cpardo <at> imayhem.com>
>
> On 05/10/2024 13:07, Eli Zaretskii wrote:
>
> >> There is no malloc/strdup.
> >
> > Well, there are still 2 calls to malloc in w32_createwindow. Any
> > reasons not to call xmalloc instead? Can w32_createwindow be called
> > before we call init_heap?
>
> [...]
>
> > Do we ever have to free the two memory chunks we allocate here? Like
> > when the window is disposed of?
>
> They are freed in w32_drop_target_Release, which is called internally
> when we call RevokeDragDrop while handling the WW_EMACS_DESTROYWINDOW on
> w32_wnd_proc.
>
> As this runs on the input thread, I used malloc/free instead of
> xmalloc/xfree. I could send a message to handle on w32_read_socket and
> then use xmalloc.
It's okay to use malloc/free in this case, but we must check the
return value of malloc to not be NULL.
> > This function should call block_input at entry and unblock_input
> > before it exits, because we must make sure all the GlobalLock calls
> > are paired with GlobalUnlock and GlobalFree, while functions we call
> > here, process_dropfiles etc., all cons Lisp object, and therefore
> > could potentially QUIT, which throws to top-level.
>
> The function (w32_process_dnd_data) is called from within the
> block_input/unblock_input on w32_read_socket.
Ah, okay.
> Should I add its own calls for clarity? Maybe just a comment?
Yes, please.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sat, 05 Oct 2024 12:35:01 GMT)
Full text and
rfc822 format available.
Message #51 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Cc: 3468 <at> debbugs.gnu.org
> Date: Sat, 05 Oct 2024 15:30:45 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
>
> > Should I add its own calls for clarity? Maybe just a comment?
>
> Yes, please.
I meant to say that a comment will be enough.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sat, 05 Oct 2024 21:43:02 GMT)
Full text and
rfc822 format available.
Message #54 received at 3468 <at> debbugs.gnu.org (full text, mbox):
Here is the new version of the patch, with everything addressed.
Looking at the manual, in the "Drag and Drop" chapter it says:
> It can be difficult to scroll a window or determine where dropped
> text will be inserted while dragging text onto an Emacs window.
> Setting the option ‘dnd-indicate-insertion-point’ to a non-‘nil’ value
> makes point move to the location any dropped text will be inserted
> when the mouse moves in a window during drag, and setting
> ‘dnd-scroll-margin’ to an integer value causes a window to be scrolled
> if the mouse moves within that many lines of the top or bottom of the
> window during drag.
This should be implemented on Windows too, but it will take me some
time. Maybe you prefer to wait before installing the changes.
Also, do you think the manual should be updated too?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sat, 05 Oct 2024 21:44:01 GMT)
Full text and
rfc822 format available.
Message #57 received at 3468 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
This time with the attached patch.
[0001-Implement-drag-n-drop-for-w32-with-support-for-files.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Sun, 06 Oct 2024 06:11:01 GMT)
Full text and
rfc822 format available.
Message #60 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Date: Sat, 5 Oct 2024 23:41:55 +0200
> Cc: 3468 <at> debbugs.gnu.org
> From: Cecilio Pardo <cpardo <at> imayhem.com>
>
> Looking at the manual, in the "Drag and Drop" chapter it says:
>
> > It can be difficult to scroll a window or determine where dropped
> > text will be inserted while dragging text onto an Emacs window.
> > Setting the option ‘dnd-indicate-insertion-point’ to a non-‘nil’ value
> > makes point move to the location any dropped text will be inserted
> > when the mouse moves in a window during drag, and setting
> > ‘dnd-scroll-margin’ to an integer value causes a window to be scrolled
> > if the mouse moves within that many lines of the top or bottom of the
> > window during drag.
>
> This should be implemented on Windows too, but it will take me some
> time. Maybe you prefer to wait before installing the changes.
Up to you. From where I stand, we can install what you have now, and
add support for the above as a separate changeset.
> Also, do you think the manual should be updated too?
If the manual becomes inaccurate or incomplete with your changes, then
yes, of course.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Mon, 07 Oct 2024 10:29:01 GMT)
Full text and
rfc822 format available.
Message #63 received at 3468 <at> debbugs.gnu.org (full text, mbox):
On 06/10/2024 8:10, Eli Zaretskii wrote:
>> This should be implemented on Windows too, but it will take me some
>> time. Maybe you prefer to wait before installing the changes.
>
> Up to you. From where I stand, we can install what you have now, and
> add support for the above as a separate changeset.
Let's do this then.
>> Also, do you think the manual should be updated too?
>
> If the manual becomes inaccurate or incomplete with your changes, then
> yes, of course.
I was thinking about changing this:
The XDND and Motif drag and drop protocols, and the old KDE 1.x
protocol, are currently supported.
To this:
The XDND and Motif drag and drop protocols, and the old KDE 1.x
protocol, are currently supported. There is also support on MS-Windows.
And adding later:
The 'dnd-indicate-insertion-point’ and ‘dnd-scroll-margin’ variables are
not supported on MS-Windows.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Mon, 07 Oct 2024 12:01:02 GMT)
Full text and
rfc822 format available.
Message #66 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Date: Mon, 7 Oct 2024 12:28:20 +0200
> Cc: 3468 <at> debbugs.gnu.org
> From: Cecilio Pardo <cpardo <at> imayhem.com>
>
> On 06/10/2024 8:10, Eli Zaretskii wrote:
> >> This should be implemented on Windows too, but it will take me some
> >> time. Maybe you prefer to wait before installing the changes.
> >
> > Up to you. From where I stand, we can install what you have now, and
> > add support for the above as a separate changeset.
>
> Let's do this then.
Will install when I have time.
> >> Also, do you think the manual should be updated too?
> >
> > If the manual becomes inaccurate or incomplete with your changes, then
> > yes, of course.
>
> I was thinking about changing this:
>
> The XDND and Motif drag and drop protocols, and the old KDE 1.x
> protocol, are currently supported.
>
>
> To this:
>
> The XDND and Motif drag and drop protocols, and the old KDE 1.x
> protocol, are currently supported. There is also support on MS-Windows.
OK.
> And adding later:
>
> The 'dnd-indicate-insertion-point’ and ‘dnd-scroll-margin’ variables are
> not supported on MS-Windows.
If you intend to work on supporting this, there's no need to add this
now.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Tue, 08 Oct 2024 13:17:01 GMT)
Full text and
rfc822 format available.
Message #69 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Cc: 3468 <at> debbugs.gnu.org
> Date: Mon, 07 Oct 2024 15:00:02 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
>
> > Date: Mon, 7 Oct 2024 12:28:20 +0200
> > Cc: 3468 <at> debbugs.gnu.org
> > From: Cecilio Pardo <cpardo <at> imayhem.com>
> >
> > On 06/10/2024 8:10, Eli Zaretskii wrote:
> > >> This should be implemented on Windows too, but it will take me some
> > >> time. Maybe you prefer to wait before installing the changes.
> > >
> > > Up to you. From where I stand, we can install what you have now, and
> > > add support for the above as a separate changeset.
> >
> > Let's do this then.
>
> Will install when I have time.
Done.
I'm not closing the bug, because you said you want to add support for
the dnd-* variables.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Tue, 08 Oct 2024 18:53:02 GMT)
Full text and
rfc822 format available.
Message #72 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> I'm not closing the bug, because you said you want to add support for
> the dnd-* variables.
Thanks, I will.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Wed, 23 Oct 2024 17:18:02 GMT)
Full text and
rfc822 format available.
Message #75 received at 3468 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 08/10/2024 15:15, Eli Zaretskii wrote:
> I'm not closing the bug, because you said you want to add support for
> the dnd-* variables.
This add support for dnd-scroll-margin and dnd-indicate-insertion-point
on MS-Windows.
BTW, I think this variables should be enabled by default. I'd say that
is the expected behaviour for drag and drop.
[0001-Improve-drag-and-drop-on-MS-Windows-bug-3468.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Thu, 24 Oct 2024 07:39:03 GMT)
Full text and
rfc822 format available.
Message #78 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Date: Wed, 23 Oct 2024 19:16:51 +0200
> Cc: 3468 <at> debbugs.gnu.org
> From: Cecilio Pardo <cpardo <at> imayhem.com>
>
> This add support for dnd-scroll-margin and dnd-indicate-insertion-point
> on MS-Windows.
Thanks.
I guess I'm missing some higher-level understanding of how this work,
because I don't think I understand why you needed to add a special
message WM_EMACS_DRAGOVER for this. Can you explain?
> BTW, I think this variables should be enabled by default. I'd say that
> is the expected behaviour for drag and drop.
Maybe. But that is a separate issue.
> * lisp/term/w32-win.el (w32-drag-n-drop): Call dnd-handle-movement
> when applicable.
> * src/w32fns.c (w32_handle_drag_movement): New function, sends a
> WM_EMACS_DRAGOVER message.
> (w32_drop_target_DragEnter): Call w32_handle_drag_movement.
> (w32_drop_target_DragOver): Call w32_handle_drag_movement.
> * src/w32term.c: (w32_read_socket): Handle WM_EMACS_DRAGOVER,
> sending an drag-n-drop event.
Please quote symbols 'like this'.
> * src/w32term.h (): Define new WM_EMACS_DRAGOVER message.
^^^
Please remove these parentheses.
> --- a/lisp/term/w32-win.el
> +++ b/lisp/term/w32-win.el
> @@ -137,35 +137,39 @@ w32-drag-n-drop
> If EVENT is for text, insert that text at point into the buffer
> shown in the window that is the target of the drop; if that buffer is
> read-only, add the dropped text to kill-ring.
> +If EVENT payload is nil, then this is a drag event.
> If the optional argument NEW-FRAME is non-nil, perform the
> drag-n-drop action in a newly-created frame using its selected-window
> and that window's buffer."
> (interactive "e")
> - (save-excursion
What are the reasons for removing save-excursion?
I guess this also needs a NEWS entry, to announce support for these
two variables on MS-Windows?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Thu, 24 Oct 2024 07:58:02 GMT)
Full text and
rfc822 format available.
Message #81 received at submit <at> debbugs.gnu.org (full text, mbox):
On 24/10/2024 9:37, Eli Zaretskii wrote:
> I guess I'm missing some higher-level understanding of how this work,
> because I don't think I understand why you needed to add a special
> message WM_EMACS_DRAGOVER for this. Can you explain?
I could reuse WM_EMACS_DROP, maybe rename to WM_EMACS_DRAGDROP. Added a
new one just for clarity.
> What are the reasons for removing save-excursion?
dnd-handle-movement needs to move the point to apply
dnd-indicate-insertion-point-
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Thu, 24 Oct 2024 08:18:02 GMT)
Full text and
rfc822 format available.
Message #84 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Date: Thu, 24 Oct 2024 09:56:16 +0200
> From: Cecilio Pardo <cpardo <at> imayhem.com>
>
> On 24/10/2024 9:37, Eli Zaretskii wrote:
> > I guess I'm missing some higher-level understanding of how this work,
> > because I don't think I understand why you needed to add a special
> > message WM_EMACS_DRAGOVER for this. Can you explain?
>
> I could reuse WM_EMACS_DROP, maybe rename to WM_EMACS_DRAGDROP. Added a
> new one just for clarity.
I don't mind a new message, I just didn't understand why it was
needed. What is the purpose of WM_EMACS_DROP, and how it differs from
this new message?
> > What are the reasons for removing save-excursion?
>
> dnd-handle-movement needs to move the point to apply
> dnd-indicate-insertion-point-
Then maybe use save-excursion when dnd-handle-movement is NOT called?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Thu, 24 Oct 2024 08:47:01 GMT)
Full text and
rfc822 format available.
Message #87 received at 3468 <at> debbugs.gnu.org (full text, mbox):
On 24/10/2024 10:16, Eli Zaretskii wrote:
>> On 24/10/2024 9:37, Eli Zaretskii wrote:
>>> I guess I'm missing some higher-level understanding of how this work,
>>> because I don't think I understand why you needed to add a special
>>> message WM_EMACS_DRAGOVER for this. Can you explain?
>>
>> I could reuse WM_EMACS_DROP, maybe rename to WM_EMACS_DRAGDROP. Added a
>> new one just for clarity.
>
> I don't mind a new message, I just didn't understand why it was
> needed. What is the purpose of WM_EMACS_DROP, and how it differs from
> this new message?
We receive the drag or drop information in the functions
w32_drop_target_Drop and w32_drop_target_DragOver, which run on another
thread. We need to notify that to the input thread, sending a message to
the window. We use those to custom messages, WM_EMACS_DROP and
WM_EMACS_DRAGDROP. One for the drop, the other for when the mouse moves
over the window.
>
>>> What are the reasons for removing save-excursion?
>>
>> dnd-handle-movement needs to move the point to apply
>> dnd-indicate-insertion-point-
>
> Then maybe use save-excursion when dnd-handle-movement is NOT called?
Ok, I'll do that.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Thu, 24 Oct 2024 09:41:02 GMT)
Full text and
rfc822 format available.
Message #90 received at 3468 <at> debbugs.gnu.org (full text, mbox):
> Date: Thu, 24 Oct 2024 10:46:12 +0200
> Cc: 3468 <at> debbugs.gnu.org
> From: Cecilio Pardo <cpardo <at> imayhem.com>
>
> On 24/10/2024 10:16, Eli Zaretskii wrote:
> >> On 24/10/2024 9:37, Eli Zaretskii wrote:
> >>> I guess I'm missing some higher-level understanding of how this work,
> >>> because I don't think I understand why you needed to add a special
> >>> message WM_EMACS_DRAGOVER for this. Can you explain?
> >>
> >> I could reuse WM_EMACS_DROP, maybe rename to WM_EMACS_DRAGDROP. Added a
> >> new one just for clarity.
> >
> > I don't mind a new message, I just didn't understand why it was
> > needed. What is the purpose of WM_EMACS_DROP, and how it differs from
> > this new message?
>
> We receive the drag or drop information in the functions
> w32_drop_target_Drop and w32_drop_target_DragOver, which run on another
> thread. We need to notify that to the input thread, sending a message to
> the window. We use those to custom messages, WM_EMACS_DROP and
> WM_EMACS_DRAGDROP. One for the drop, the other for when the mouse moves
> over the window.
Ah, okay, thanks. So moving point and/or scrolling use different
message from actually dropping the payload? Makes sense.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#3468
; Package
emacs
.
(Thu, 24 Oct 2024 16:54:02 GMT)
Full text and
rfc822 format available.
Message #93 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 24/10/2024 9:37, Eli Zaretskii wrote:
> What are the reasons for removing save-excursion?
>
> I guess this also needs a NEWS entry, to announce support for these
> two variables on MS-Windows?
All fixed now.
Thanks for your time.
[0001-Improve-drag-and-drop-on-MS-Windows-bug-3468.patch (text/plain, attachment)]
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Fri, 25 Oct 2024 10:44:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
"Erdkern Erdkern" <Erdkern2000 <at> gmx.de>
:
bug acknowledged by developer.
(Fri, 25 Oct 2024 10:44:02 GMT)
Full text and
rfc822 format available.
Message #98 received at 3468-done <at> debbugs.gnu.org (full text, mbox):
> Date: Thu, 24 Oct 2024 18:52:41 +0200
> From: Cecilio Pardo <cpardo <at> imayhem.com>
>
> On 24/10/2024 9:37, Eli Zaretskii wrote:
>
> > What are the reasons for removing save-excursion?
> >
> > I guess this also needs a NEWS entry, to announce support for these
> > two variables on MS-Windows?
>
> All fixed now.
Thanks, installed on the master branch, and closing the bug.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 22 Nov 2024 12:24:12 GMT)
Full text and
rfc822 format available.
This bug report was last modified 86 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.