aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2016-11-01 18:04:07 +0200
committerEli Zaretskii2016-11-01 18:04:07 +0200
commitc3640fcc96ed80368209c73d7ac9a0f0d1833d93 (patch)
tree0de0a41fcf5807bd01f72c0db1eac44144a79e32 /src
parent2664eb539416bf4cf3f87578726d849ec6560a76 (diff)
downloademacs-c3640fcc96ed80368209c73d7ac9a0f0d1833d93.tar.gz
emacs-c3640fcc96ed80368209c73d7ac9a0f0d1833d93.zip
Support 'TARGETS' in clipboard selections on MS-Windows
* src/w32select.c (Fw32_selection_targets): New function. * lisp/term/w32-win.el (w32--get-selection): Call 'w32-selection-targets' to obtain the list of data formats available in the clipboard.
Diffstat (limited to 'src')
-rw-r--r--src/w32select.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/w32select.c b/src/w32select.c
index a38a42ca050..1754534c3d3 100644
--- a/src/w32select.c
+++ b/src/w32select.c
@@ -1052,6 +1052,113 @@ frame's display, or the first available X display. */)
1052 return Qnil; 1052 return Qnil;
1053} 1053}
1054 1054
1055/* Support enumerating available clipboard selection formats. */
1056
1057DEFUN ("w32-selection-targets", Fw32_selection_targets, Sw32_selection_targets,
1058 0, 2, 0,
1059 doc: /* Return a vector of data formats available in the specified SELECTION.
1060SELECTION should be the name of the selection in question, typically
1061one of the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
1062The symbol nil is the same as `PRIMARY', and t is the same as `SECONDARY'.
1063
1064TERMINAL should be a terminal object or a frame specifying the X
1065server to query. If omitted or nil, that stands for the selected
1066frame's display, or the first available X display.
1067
1068This function currently ignores TERMINAL, and only returns non-nil
1069for `CLIPBOARD'. The return value is a vector of symbols, each symbol
1070representing a data format that is currently available in the clipboard. */)
1071 (Lisp_Object selection, Lisp_Object terminal)
1072{
1073 /* Xlib-like names for standard Windows clipboard data formats.
1074 They are in upper-case to mimic xselect.c. A couple of the names
1075 were changed to be more like their X counterparts. */
1076 static const char *stdfmt_name[] = {
1077 "UNDEFINED",
1078 "STRING",
1079 "BITMAP",
1080 "METAFILE",
1081 "SYMLINK",
1082 "DIF",
1083 "TIFF",
1084 "OEM_STRING",
1085 "DIB",
1086 "PALETTE",
1087 "PENDATA",
1088 "RIFF",
1089 "WAVE",
1090 "UTF8_STRING",
1091 "ENHMETAFILE",
1092 "FILE_NAMES", /* DND */
1093 "LOCALE", /* not used */
1094 "DIBV5"
1095 };
1096 CHECK_SYMBOL (selection);
1097
1098 /* Return nil for PRIMARY and SECONDARY selections; for CLIPBOARD, check
1099 if the clipboard currently has valid text format contents. */
1100
1101 if (EQ (selection, QCLIPBOARD))
1102 {
1103 Lisp_Object val = Qnil;
1104
1105 setup_config ();
1106
1107 if (OpenClipboard (NULL))
1108 {
1109 UINT format = 0;
1110
1111 /* Count how many formats are available. We ignore the
1112 CF_LOCALE format, and don't put it into the vector we
1113 return, because CF_LOCALE is automatically created by
1114 Windows for any text in the clipboard, so its presence in
1115 the value will simply confuse. */
1116 int fmtcount = 0;
1117 while ((format = EnumClipboardFormats (format)))
1118 if (format != CF_LOCALE)
1119 fmtcount++;
1120
1121 if (fmtcount > 0)
1122 {
1123 int i;
1124
1125 /* We generate a vector because that's what xselect.c
1126 does in this case. */
1127 val = Fmake_vector (make_number (fmtcount), Qnil);
1128 /* Note: when stepping with GDB through this code, the
1129 loop below terminates immediately because
1130 EnumClipboardFormats for some reason returns with
1131 "Thread does not have a clipboard open" error. */
1132 for (i = 0, format = 0;
1133 (format = EnumClipboardFormats (format)) != 0; )
1134 {
1135 const char *name;
1136
1137 if (format == CF_LOCALE)
1138 continue;
1139 else if (format < CF_MAX)
1140 name = stdfmt_name[format];
1141 else
1142 {
1143 char fmt_name[256];
1144
1145 if (!GetClipboardFormatName (format, fmt_name,
1146 sizeof (fmt_name)))
1147 continue;
1148 name = fmt_name;
1149 }
1150 ASET (val, i, intern (name));
1151 i++;
1152 }
1153 }
1154 CloseClipboard ();
1155 }
1156 return val;
1157 }
1158 /* For PRIMARY and SECONDARY we cons the values in w32--get-selection. */
1159 return Qnil;
1160}
1161
1055/* One-time init. Called in the un-dumped Emacs, but not in the 1162/* One-time init. Called in the un-dumped Emacs, but not in the
1056 dumped version. */ 1163 dumped version. */
1057 1164
@@ -1061,6 +1168,7 @@ syms_of_w32select (void)
1061 defsubr (&Sw32_set_clipboard_data); 1168 defsubr (&Sw32_set_clipboard_data);
1062 defsubr (&Sw32_get_clipboard_data); 1169 defsubr (&Sw32_get_clipboard_data);
1063 defsubr (&Sw32_selection_exists_p); 1170 defsubr (&Sw32_selection_exists_p);
1171 defsubr (&Sw32_selection_targets);
1064 1172
1065 DEFVAR_LISP ("selection-coding-system", Vselection_coding_system, 1173 DEFVAR_LISP ("selection-coding-system", Vselection_coding_system,
1066 doc: /* Coding system for communicating with other programs. 1174 doc: /* Coding system for communicating with other programs.