X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/5bc6ddff00c50acf546530ef0e08a27140614d27..6ce950f336909aa19d6c5ea6f3e1910b247f3d38:/src/w16select.c
diff --git a/src/w16select.c b/src/w16select.c
index 4a8902b77f..994ad9e543 100644
--- a/src/w16select.c
+++ b/src/w16select.c
@@ -1,13 +1,14 @@
/* 16-bit Windows Selection processing for emacs on MS-Windows
- Copyright (C) 1996, 1997, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+
+Copyright (C) 1996, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+ 2008, 2009, 2010 Free Software Foundation, Inc.
This file is part of GNU Emacs.
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,9 +16,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA. */
+along with GNU Emacs. If not, see . */
/* These functions work by using WinOldAp interface. WinOldAp
(WINOLDAP.MOD) is a Microsoft Windows extension supporting
@@ -25,15 +24,15 @@ Boston, MA 02110-1301, USA. */
menus, and the Windows clipboard. */
/* Written by Dale P. Smith */
-/* Adapted to DJGPP v1 by Eli Zaretskii */
+/* Adapted to DJGPP by Eli Zaretskii */
#ifdef MSDOS
#include
-#include
#include
#include
#include
+#include
#include "lisp.h"
#include "dispextern.h" /* frame.h seems to want this */
#include "frame.h" /* Need this to get the X window of selected_frame */
@@ -95,25 +94,6 @@ static unsigned char *last_clipboard_text;
/* The size of allocated storage for storing the clipboard data. */
static size_t clipboard_storage_size;
-/* Emulation of `__dpmi_int' and friends for DJGPP v1.x */
-
-#if __DJGPP__ < 2
-
-typedef _go32_dpmi_registers __dpmi_regs;
-#define __tb _go32_info_block.linear_address_of_transfer_buffer
-#define _dos_ds _go32_info_block.selector_for_linear_memory
-
-static int
-__dpmi_int (intno, regs)
- int intno;
- __dpmi_regs *regs;
-{
- regs->x.ss = regs->x.sp = regs->x.flags = 0;
- return _go32_dpmi_simulate_int (intno, regs);
-}
-
-#endif /* __DJGPP__ < 2 */
-
/* C functions to access the Windows 3.1x clipboard from DOS apps.
The information was obtained from the Microsoft Knowledge Base,
@@ -129,7 +109,7 @@ __dpmi_int (intno, regs)
/* Return the WinOldAp support version, or 0x1700 if not supported. */
unsigned
-identify_winoldap_version ()
+identify_winoldap_version (void)
{
__dpmi_regs regs;
@@ -144,7 +124,7 @@ identify_winoldap_version ()
/* Open the clipboard, return non-zero if successfull. */
unsigned
-open_clipboard ()
+open_clipboard (void)
{
__dpmi_regs regs;
@@ -167,7 +147,7 @@ open_clipboard ()
/* Empty clipboard, return non-zero if successfull. */
unsigned
-empty_clipboard ()
+empty_clipboard (void)
{
__dpmi_regs regs;
@@ -182,8 +162,7 @@ empty_clipboard ()
/* Ensure we have a buffer in low memory with enough memory for data
of size WANT_SIZE. Return the linear address of the buffer. */
static unsigned long
-alloc_xfer_buf (want_size)
- unsigned want_size;
+alloc_xfer_buf (unsigned want_size)
{
__dpmi_regs regs;
@@ -220,7 +199,7 @@ alloc_xfer_buf (want_size)
The clipboard buffer tends to be large in size, because for small
clipboard data sizes we use the DJGPP transfer buffer. */
static void
-free_xfer_buf ()
+free_xfer_buf (void)
{
/* If the size is 0, we used DJGPP transfer buffer, so don't free. */
if (clipboard_xfer_buf_info.size)
@@ -238,11 +217,7 @@ free_xfer_buf ()
/* Copy data into the clipboard, return zero if successfull. */
unsigned
-set_clipboard_data (Format, Data, Size, Raw)
- unsigned Format;
- void *Data;
- unsigned Size;
- int Raw;
+set_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw)
{
__dpmi_regs regs;
unsigned truelen;
@@ -341,8 +316,7 @@ set_clipboard_data (Format, Data, Size, Raw)
/* Return the size of the clipboard data of format FORMAT. */
unsigned
-get_clipboard_data_size (Format)
- unsigned Format;
+get_clipboard_data_size (unsigned Format)
{
__dpmi_regs regs;
@@ -362,11 +336,7 @@ get_clipboard_data_size (Format)
Warning: this doesn't check whether DATA has enough space to hold
SIZE bytes. */
unsigned
-get_clipboard_data (Format, Data, Size, Raw)
- unsigned Format;
- void *Data;
- unsigned Size;
- int Raw;
+get_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw)
{
__dpmi_regs regs;
unsigned long xbuf_addr;
@@ -445,7 +415,7 @@ get_clipboard_data (Format, Data, Size, Raw)
/* Close clipboard, return non-zero if successfull. */
unsigned
-close_clipboard ()
+close_clipboard (void)
{
__dpmi_regs regs;
@@ -459,8 +429,7 @@ close_clipboard ()
/* Compact clipboard data so that at least SIZE bytes is available. */
unsigned
-clipboard_compact (Size)
- unsigned Size;
+clipboard_compact (unsigned Size)
{
__dpmi_regs regs;
@@ -484,11 +453,10 @@ static char system_error_msg[] =
DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_data, 1, 2, 0,
doc: /* This sets the clipboard data to the given text. */)
- (string, frame)
- Lisp_Object string, frame;
+ (Lisp_Object string, Lisp_Object frame)
{
unsigned ok = 1, put_status = 0;
- int nbytes, charset_info, no_crlf_conversion;
+ int nbytes, no_crlf_conversion;
unsigned char *src, *dst = NULL;
CHECK_STRING (string);
@@ -502,62 +470,55 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
BLOCK_INPUT;
+ if (!open_clipboard ())
+ goto error;
+
nbytes = SBYTES (string);
src = SDATA (string);
- /* Since we are now handling multilingual text, we must consider
- encoding text for the clipboard. */
- charset_info = find_charset_in_text (src, SCHARS (string), nbytes,
- NULL, Qnil);
-
- if (charset_info == 0)
+ /* Do we need to encode this text? */
+ for (dst = src; dst < src + nbytes; dst++)
{
- /* No multibyte character in OBJ. We need not encode it, but we
+ if (*dst == '\0' || *dst >= 0x80)
+ break;
+ }
+ if (dst >= src + nbytes)
+ {
+ /* No multibyte characters in text. We need not encode it, but we
will have to convert it to DOS CR-LF style. */
no_crlf_conversion = 0;
+ Vlast_coding_system_used = Qraw_text;
+ dst = NULL; /* so we don't try to free a random pointer */
}
else
{
/* We must encode contents of STRING according to what
clipboard-coding-system specifies. */
- int bufsize;
struct coding_system coding;
- unsigned char *htext2;
-
- if (NILP (Vnext_selection_coding_system))
- Vnext_selection_coding_system = Vselection_coding_system;
- setup_coding_system
- (Fcheck_coding_system (Vnext_selection_coding_system), &coding);
- if (SYMBOLP (coding.pre_write_conversion)
- && !NILP (Ffboundp (coding.pre_write_conversion)))
- {
- string = run_pre_post_conversion_on_str (string, &coding, 1);
- src = SDATA (string);
- nbytes = SBYTES (string);
- }
- coding.src_multibyte = 1;
- coding.dst_multibyte = 0;
+ Lisp_Object coding_system =
+ NILP (Vnext_selection_coding_system) ?
+ Vselection_coding_system : Vnext_selection_coding_system;
+
+ setup_coding_system (Fcheck_coding_system (coding_system), &coding);
+ coding.dst_bytes = nbytes * 4;
+ coding.destination = (unsigned char *) xmalloc (coding.dst_bytes);
Vnext_selection_coding_system = Qnil;
coding.mode |= CODING_MODE_LAST_BLOCK;
- Vlast_coding_system_used = coding.symbol;
- bufsize = encoding_buffer_size (&coding, nbytes);
- dst = (unsigned char *) xmalloc (bufsize);
- encode_coding (&coding, src, dst, nbytes, bufsize);
+ dst = coding.destination;
+ encode_coding_object (&coding, string, 0, 0,
+ SCHARS (string), nbytes, Qnil);
no_crlf_conversion = 1;
nbytes = coding.produced;
+ Vlast_coding_system_used = CODING_ID_NAME (coding.id);
src = dst;
}
- if (!open_clipboard ())
- goto error;
-
ok = empty_clipboard ()
&& ((put_status
= set_clipboard_data (CF_OEMTEXT, src, nbytes, no_crlf_conversion))
== 0);
if (!no_crlf_conversion)
- Vlast_coding_system_used = Qraw_text;
close_clipboard ();
if (ok) goto unblock;
@@ -567,8 +528,7 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
ok = 0;
unblock:
- if (dst)
- xfree (dst);
+ xfree (dst);
UNBLOCK_INPUT;
/* Notify user if the text is too large to fit into DOS memory.
@@ -600,13 +560,12 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_data, 0, 1, 0,
doc: /* This gets the clipboard data in text format. */)
- (frame)
- Lisp_Object frame;
+ (Lisp_Object frame)
{
unsigned data_size, truelen;
- unsigned char *htext;
+ unsigned char *htext = NULL;
Lisp_Object ret = Qnil;
- int no_crlf_conversion, require_encoding = 0;
+ int require_decoding = 0;
if (NILP (frame))
frame = Fselected_frame ();
@@ -640,39 +599,28 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
{
if (htext[i] >= 0x80)
{
- require_encoding = 1;
+ require_decoding = 1;
break;
}
}
}
- if (require_encoding)
+ if (require_decoding)
{
- int bufsize;
- unsigned char *buf;
struct coding_system coding;
+ Lisp_Object coding_system = Vnext_selection_coding_system;
- if (NILP (Vnext_selection_coding_system))
- Vnext_selection_coding_system = Vselection_coding_system;
- setup_coding_system
- (Fcheck_coding_system (Vnext_selection_coding_system), &coding);
- coding.src_multibyte = 0;
- coding.dst_multibyte = 1;
- Vnext_selection_coding_system = Qnil;
+ truelen = get_clipboard_data (CF_OEMTEXT, htext, data_size, 1);
+ if (NILP (coding_system))
+ coding_system = Vselection_coding_system;
+ setup_coding_system (Fcheck_coding_system (coding_system), &coding);
+ coding.source = htext;
coding.mode |= CODING_MODE_LAST_BLOCK;
- /* We explicitely disable composition handling because selection
+ /* We explicitly disable composition handling because selection
data should not contain any composition sequence. */
- coding.composing = COMPOSITION_DISABLED;
- truelen = get_clipboard_data (CF_OEMTEXT, htext, data_size, 1);
- bufsize = decoding_buffer_size (&coding, truelen);
- buf = (unsigned char *) xmalloc (bufsize);
- decode_coding (&coding, htext, buf, truelen, bufsize);
- ret = make_string_from_bytes ((char *) buf,
- coding.produced_char, coding.produced);
- xfree (buf);
- if (SYMBOLP (coding.post_read_conversion)
- && !NILP (Ffboundp (coding.post_read_conversion)))
- ret = run_pre_post_conversion_on_str (ret, &coding, 0);
- Vlast_coding_system_used = coding.symbol;
+ coding.mode &= CODING_ANNOTATION_MASK;
+ decode_coding_object (&coding, Qnil, 0, 0, truelen, truelen, Qt);
+ ret = coding.dst_object;
+ Vlast_coding_system_used = CODING_ID_NAME (coding.id);
}
else
{
@@ -681,6 +629,7 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
}
xfree (htext);
+ Vnext_selection_coding_system = Qnil;
closeclip:
close_clipboard ();
@@ -703,8 +652,7 @@ the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
\(Those are literal upper-case symbol names, since that's what X expects.)
For convenience, the symbol nil is the same as `PRIMARY',
and t is the same as `SECONDARY'. */)
- (selection)
- Lisp_Object selection;
+ (Lisp_Object selection)
{
CHECK_SYMBOL (selection);
@@ -719,8 +667,8 @@ and t is the same as `SECONDARY'. */)
into the clipboard if we run under Windows, so we cannot check
the clipboard alone.) */
if ((EQ (selection, Qnil) || EQ (selection, QPRIMARY))
- && ! NILP (SYMBOL_VALUE (Fintern_soft (build_string ("kill-ring"),
- Qnil))))
+ && ! NILP (Fsymbol_value (Fintern_soft (build_string ("kill-ring"),
+ Qnil))))
return Qt;
if (EQ (selection, QCLIPBOARD))
@@ -739,25 +687,50 @@ and t is the same as `SECONDARY'. */)
}
void
-syms_of_win16select ()
+syms_of_win16select (void)
{
defsubr (&Sw16_set_clipboard_data);
defsubr (&Sw16_get_clipboard_data);
defsubr (&Sx_selection_exists_p);
DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system,
- doc: /* Coding system for communicating with other X clients.
-When sending or receiving text via cut_buffer, selection, and clipboard,
-the text is encoded or decoded by this coding system.
-The default value is `iso-latin-1-dos'. */);
+ doc: /* Coding system for communicating with other programs.
+
+For MS-Windows and MS-DOS:
+When sending or receiving text via selection and clipboard, the text
+is encoded or decoded by this coding system. The default value is
+the current system default encoding on 9x/Me, `utf-16le-dos'
+\(Unicode) on NT/W2K/XP, and `iso-latin-1-dos' on MS-DOS.
+
+For X Windows:
+When sending text via selection and clipboard, if the target
+data-type matches with the type of this coding system, it is used
+for encoding the text. Otherwise (including the case that this
+variable is nil), a proper coding system is used as below:
+
+data-type coding system
+--------- -------------
+UTF8_STRING utf-8
+COMPOUND_TEXT compound-text-with-extensions
+STRING iso-latin-1
+C_STRING no-conversion
+
+When receiving text, if this coding system is non-nil, it is used
+for decoding regardless of the data-type. If this is nil, a
+proper coding system is used according to the data-type as above.
+
+See also the documentation of the variable `x-select-request-type' how
+to control which data-type to request for receiving text.
+
+The default value is nil. */);
Vselection_coding_system = intern ("iso-latin-1-dos");
DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system,
- doc: /* Coding system for the next communication with other X clients.
+ doc: /* Coding system for the next communication with other programs.
Usually, `selection-coding-system' is used for communicating with
-other X clients. But, if this variable is set, it is used for the
-next communication only. After the communication, this variable is
-set to nil. */);
+other programs (X Windows clients or MS Windows programs). But, if this
+variable is set, it is used for the next communication only.
+After the communication, this variable is set to nil. */);
Vnext_selection_coding_system = Qnil;
QPRIMARY = intern ("PRIMARY"); staticpro (&QPRIMARY);
@@ -766,5 +739,3 @@ set to nil. */);
#endif /* MSDOS */
-/* arch-tag: 085a22c8-7324-436e-a6da-102464ce95d8
- (do not change this comment) */