#include "keymap.h"
#ifdef WINDOWSNT
+#include "w32.h" /* for filename_from_utf16, filename_from_ansi */
#include "w32heap.h"
#endif
HDROP hdrop;
POINT p;
WORD num_files;
- guichar_t *name;
+ wchar_t name_w[MAX_PATH];
+#ifdef NTGUI_UNICODE
+ const int use_unicode = 1;
+#else
+ int use_unicode = w32_unicode_filenames;
+ char name_a[MAX_PATH];
+ char file[MAX_UTF8_PATH];
+#endif
int i, len;
result->kind = DRAG_N_DROP_EVENT;
for (i = 0; i < num_files; i++)
{
- len = GUI_FN (DragQueryFile) (hdrop, i, NULL, 0);
- if (len <= 0)
- continue;
-
- name = alloca ((len + 1) * sizeof (*name));
- GUI_FN (DragQueryFile) (hdrop, i, name, len + 1);
+ if (use_unicode)
+ {
+ eassert (DragQueryFileW (hdrop, i, NULL, 0) < MAX_PATH);
+ /* If DragQueryFile returns zero, it failed to fetch a file
+ name. */
+ if (DragQueryFileW (hdrop, i, name_w, MAX_PATH) == 0)
+ continue;
#ifdef NTGUI_UNICODE
- files = Fcons (from_unicode_buffer (name), files);
+ files = Fcons (from_unicode_buffer (name_w), files);
#else
- files = Fcons (DECODE_FILE (build_string (name)), files);
+ filename_from_utf16 (name_w, file);
+ files = Fcons (DECODE_FILE (build_unibyte_string (file)), files);
#endif /* NTGUI_UNICODE */
+ }
+#ifndef NTGUI_UNICODE
+ else
+ {
+ eassert (DragQueryFileA (hdrop, i, NULL, 0) < MAX_PATH);
+ if (DragQueryFileA (hdrop, i, name_a, MAX_PATH) == 0)
+ continue;
+ filename_from_ansi (name_a, file);
+ files = Fcons (DECODE_FILE (build_unibyte_string (file)), files);
+ }
+#endif
}
DragFinish (hdrop);
With MS Windows or Nextstep, the value is t. */);
Vx_toolkit_scroll_bars = Qt;
+ DEFVAR_BOOL ("w32-unicode-filenames",
+ w32_unicode_filenames,
+ doc: /* Non-nil means use Unicode APIs when passing file names to the OS.
+A value of nil means file names passed to the OS APIs and returned
+from those APIs are encoded/decoded using the ANSI codepage
+specified by `file-name-coding-system'.
+
+This variable is set to non-nil by default when Emacs runs on Windows
+systems of the NT family, including W2K, XP, Vista, Windows 7 and
+Windows 8. It is set to nil on Windows 9X. */);
+ w32_unicode_filenames = 0;
+
/* Tell Emacs about this window system. */
Fprovide (Qw32, Qnil);
}