annotate src/w32select.c @ 54949:95d283fb2215

(Fbuffer_base_buffer): Doc fix.
author Luc Teirlinck <teirllm@auburn.edu>
date Sat, 17 Apr 2004 02:01:27 +0000
parents ad0a7541533d
children 64d01f3f16e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16884
36babc489b0c Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents: 16588
diff changeset
1 /* Selection processing for Emacs on the Microsoft W32 API.
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
2 Copyright (C) 1993, 1994 Free Software Foundation.
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
3
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
4 This file is part of GNU Emacs.
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
5
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
7 it under the terms of the GNU General Public License as published by
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
9 any later version.
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
10
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
14 GNU General Public License for more details.
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
15
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
16 You should have received a copy of the GNU General Public License
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13434
diff changeset
19 Boston, MA 02111-1307, USA. */
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
20
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
21 /* Written by Kevin Gallo */
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
22
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
23 #include <config.h>
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
24 #include "lisp.h"
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
25 #include "w32term.h" /* for all of the w32 includes */
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
26 #include "dispextern.h" /* frame.h seems to want this */
31117
f390b90e3495 Include keyboard.h before frame.h.
Andrew Innes <andrewi@gnu.org>
parents: 29332
diff changeset
27 #include "keyboard.h"
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
28 #include "frame.h" /* Need this to get the X window of selected_frame */
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
29 #include "blockinput.h"
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
30 #include "buffer.h"
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
31 #include "charset.h"
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
32 #include "coding.h"
45988
37913830a881 Include composite.h
Juanma Barranquero <lekktu@gmail.com>
parents: 45984
diff changeset
33 #include "composite.h"
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
34
15235
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
35 Lisp_Object QCLIPBOARD;
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
36
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
37 /* Coding system for communicating with other Windows programs via the
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
38 clipboard. */
22914
4d4e775cf6f7 (Vselection_coding_system): Renamed from Vclipboard_coding_system.
Richard M. Stallman <rms@gnu.org>
parents: 22745
diff changeset
39 static Lisp_Object Vselection_coding_system;
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
40
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
41 /* Coding system for the next communicating with other Windows programs. */
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
42 static Lisp_Object Vnext_selection_coding_system;
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
43
51777
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
44 /* Sequence number, used where possible to detect when we are pasting
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
45 our own text. */
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
46 static DWORD last_clipboard_sequence_number;
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
47 extern ClipboardSequence_Proc clipboard_sequence_fn;
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
48
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
49 /* The last text we put into the clipboard. This is used when the OS
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
50 does not support sequence numbers (NT4, 95). It is undesirable to
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
51 use data put on the clipboard by Emacs because the clipboard data
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
52 could be MULEtilated by inappropriately chosen
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
53 (next-)selection-coding-system. For this reason, we must store the
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
54 text *after* it was encoded/Unix-to-DOS-converted. */
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
55 static unsigned char *last_clipboard_text = NULL;
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
56 static size_t clipboard_storage_size = 0;
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
57
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
58 #if 0
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
59 DEFUN ("w32-open-clipboard", Fw32_open_clipboard, Sw32_open_clipboard, 0, 1, 0,
40962
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
60 doc: /* This opens the clipboard with the given frame pointer. */)
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
61 (frame)
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
62 Lisp_Object frame;
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
63 {
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
64 BOOL ok = FALSE;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
65
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
66 if (!NILP (frame))
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 33697
diff changeset
67 CHECK_LIVE_FRAME (frame);
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
68
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
69 BLOCK_INPUT;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
70
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
71 ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL);
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
72
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
73 UNBLOCK_INPUT;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
74
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
75 return (ok ? frame : Qnil);
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
76 }
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
77
40962
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
78 DEFUN ("w32-empty-clipboard", Fw32_empty_clipboard,
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
79 Sw32_empty_clipboard, 0, 0, 0,
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
80 doc: /* Empty the clipboard.
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
81 Assigns ownership of the clipboard to the window which opened it. */)
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
82 ()
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
83 {
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
84 BOOL ok = FALSE;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
85
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
86 BLOCK_INPUT;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
87
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
88 ok = EmptyClipboard ();
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
89
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
90 UNBLOCK_INPUT;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
91
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
92 return (ok ? Qt : Qnil);
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
93 }
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
94
40962
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
95 DEFUN ("w32-close-clipboard", Fw32_close_clipboard,
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
96 Sw32_close_clipboard, 0, 0, 0,
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
97 doc: /* Close the clipboard. */)
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
98 ()
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
99 {
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
100 BOOL ok = FALSE;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
101
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
102 BLOCK_INPUT;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
103
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
104 ok = CloseClipboard ();
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
105
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
106 UNBLOCK_INPUT;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
107
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
108 return (ok ? Qt : Qnil);
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
109 }
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
110
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
111 #endif
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
112
40962
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
113 DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
114 Sw32_set_clipboard_data, 1, 2, 0,
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
115 doc: /* This sets the clipboard data to the given text. */)
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
116 (string, frame)
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
117 Lisp_Object string, frame;
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
118 {
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
119 BOOL ok = TRUE;
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
120 HANDLE htext;
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
121 int nbytes;
24518
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
122 int truelen, nlines = 0;
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
123 unsigned char *src;
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
124 unsigned char *dst;
24518
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
125
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 33697
diff changeset
126 CHECK_STRING (string);
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
127
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
128 if (!NILP (frame))
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 33697
diff changeset
129 CHECK_LIVE_FRAME (frame);
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
130
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
131 BLOCK_INPUT;
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
132
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45988
diff changeset
133 nbytes = SBYTES (string) + 1;
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45988
diff changeset
134 src = SDATA (string);
24518
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
135 dst = src;
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
136
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
137 /* We need to know how many lines there are, since we need CRLF line
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
138 termination for compatibility with other Windows Programs.
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
139 avoid using strchr because it recomputes the length every time */
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
140 while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL)
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
141 {
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
142 nlines++;
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
143 dst++;
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
144 }
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
145
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
146 {
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
147 /* Since we are now handling multilingual text, we must consider
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
148 encoding text for the clipboard. */
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45988
diff changeset
149 int charset_info = find_charset_in_text (src, SCHARS (string),
29332
f2308eae15d7 (Fw32_set_clipboard_data): Change QNil to Qnil.
Jason Rumney <jasonr@gnu.org>
parents: 29022
diff changeset
150 nbytes, NULL, Qnil);
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
151
29022
3eec558de0ef (Fw32_set_clipboard_data): Setup members
Kenichi Handa <handa@m17n.org>
parents: 27401
diff changeset
152 if (charset_info == 0)
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
153 {
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
154 /* No multibyte character in OBJ. We need not encode it. */
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
155
23835
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
156 /* Need to know final size after CR chars are inserted (the
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
157 standard CF_TEXT clipboard format uses CRLF line endings,
23835
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
158 while Emacs uses just LF internally). */
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
159
24518
a0423d2b9302 (Fw32_set_clipboard_data): Take into account line
Andrew Innes <andrewi@gnu.org>
parents: 23874
diff changeset
160 truelen = nbytes + nlines;
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
161
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
162 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL)
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
163 goto error;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
164
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
165 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL)
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
166 goto error;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
167
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
168 /* convert to CRLF line endings expected by clipboard */
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
169 while (1)
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
170 {
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
171 unsigned char *next;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
172 /* copy next line or remaining bytes including '\0' */
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
173 next = _memccpy (dst, src, '\n', nbytes);
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
174 if (next)
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
175 {
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
176 /* copied one line ending with '\n' */
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
177 int copied = next - dst;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
178 nbytes -= copied;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
179 src += copied;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
180 /* insert '\r' before '\n' */
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
181 next[-1] = '\r';
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
182 next[0] = '\n';
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
183 dst = next + 1;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
184 }
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
185 else
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
186 /* copied remaining partial line -> now finished */
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
187 break;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
188 }
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
189
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
190 GlobalUnlock (htext);
22745
ef9607e709bc (Fw32_set_clipboard_data): Set Vlast_coding_system_used.
Andrew Innes <andrewi@gnu.org>
parents: 22545
diff changeset
191
ef9607e709bc (Fw32_set_clipboard_data): Set Vlast_coding_system_used.
Andrew Innes <andrewi@gnu.org>
parents: 22545
diff changeset
192 Vlast_coding_system_used = Qraw_text;
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
193 }
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
194 else
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
195 {
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
196 /* We must encode contents of OBJ to the selection coding
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
197 system. */
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
198 int bufsize;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
199 struct coding_system coding;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
200 HANDLE htext2;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
201
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
202 if (NILP (Vnext_selection_coding_system))
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
203 Vnext_selection_coding_system = Vselection_coding_system;
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
204 setup_coding_system
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
205 (Fcheck_coding_system (Vnext_selection_coding_system), &coding);
43483
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
206 if (SYMBOLP (coding.pre_write_conversion)
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
207 && !NILP (Ffboundp (coding.pre_write_conversion)))
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
208 {
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
209 string = run_pre_post_conversion_on_str (string, &coding, 1);
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45988
diff changeset
210 src = SDATA (string);
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45988
diff changeset
211 nbytes = SBYTES (string);
43483
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
212 }
29022
3eec558de0ef (Fw32_set_clipboard_data): Setup members
Kenichi Handa <handa@m17n.org>
parents: 27401
diff changeset
213 coding.src_multibyte = 1;
3eec558de0ef (Fw32_set_clipboard_data): Setup members
Kenichi Handa <handa@m17n.org>
parents: 27401
diff changeset
214 coding.dst_multibyte = 0;
53798
ad0a7541533d * w32select.c (Fw32_set_clipboard_data): Make coding iso2022 safe.
Jason Rumney <jasonr@gnu.org>
parents: 52401
diff changeset
215 /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in
ad0a7541533d * w32select.c (Fw32_set_clipboard_data): Make coding iso2022 safe.
Jason Rumney <jasonr@gnu.org>
parents: 52401
diff changeset
216 encode_coding_iso2022 trying to dereference a null pointer. */
ad0a7541533d * w32select.c (Fw32_set_clipboard_data): Make coding iso2022 safe.
Jason Rumney <jasonr@gnu.org>
parents: 52401
diff changeset
217 coding.composing = COMPOSITION_DISABLED;
ad0a7541533d * w32select.c (Fw32_set_clipboard_data): Make coding iso2022 safe.
Jason Rumney <jasonr@gnu.org>
parents: 52401
diff changeset
218 if (coding.type == coding_type_iso2022)
ad0a7541533d * w32select.c (Fw32_set_clipboard_data): Make coding iso2022 safe.
Jason Rumney <jasonr@gnu.org>
parents: 52401
diff changeset
219 coding.flags |= CODING_FLAG_ISO_SAFE;
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
220 Vnext_selection_coding_system = Qnil;
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
221 coding.mode |= CODING_MODE_LAST_BLOCK;
24673
ea7d8435d078 (Fw32_set_clipboard_data): Undo last change to add
Andrew Innes <andrewi@gnu.org>
parents: 24518
diff changeset
222 bufsize = encoding_buffer_size (&coding, nbytes);
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
223 if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize)) == NULL)
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
224 goto error;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
225 if ((dst = (unsigned char *) GlobalLock (htext)) == NULL)
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
226 goto error;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
227 encode_coding (&coding, src, dst, nbytes, bufsize);
22745
ef9607e709bc (Fw32_set_clipboard_data): Set Vlast_coding_system_used.
Andrew Innes <andrewi@gnu.org>
parents: 22545
diff changeset
228 Vlast_coding_system_used = coding.symbol;
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
229
51777
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
230 /* If clipboard sequence numbers are not supported, keep a copy for
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
231 later comparison. */
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
232 if (!clipboard_sequence_fn)
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
233 {
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
234 /* Stash away the data we are about to put into the
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
235 clipboard, so we could later check inside
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
236 Fw32_get_clipboard_data whether the clipboard still
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
237 holds our data. */
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
238 if (clipboard_storage_size < coding.produced)
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
239 {
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
240 clipboard_storage_size = coding.produced + 100;
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
241 last_clipboard_text = (char *) xrealloc (last_clipboard_text,
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
242 clipboard_storage_size);
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
243 }
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
244 if (last_clipboard_text)
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
245 memcpy (last_clipboard_text, dst, coding.produced);
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
246 }
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
247
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
248 GlobalUnlock (htext);
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
249
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
250 /* Shrink data block to actual size. */
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
251 htext2 = GlobalReAlloc (htext, coding.produced,
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
252 GMEM_MOVEABLE | GMEM_DDESHARE);
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
253 if (htext2 != NULL) htext = htext2;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
254 }
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
255 }
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
256
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
257 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL))
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
258 goto error;
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
259
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
260 ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext);
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
261
51777
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
262 if (clipboard_sequence_fn)
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
263 last_clipboard_sequence_number = clipboard_sequence_fn ();
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
264
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
265 CloseClipboard ();
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
266
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
267 if (ok) goto done;
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
268
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
269 error:
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
270
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
271 ok = FALSE;
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
272 if (htext) GlobalFree (htext);
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
273 if (last_clipboard_text)
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
274 *last_clipboard_text = '\0';
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
275
51777
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
276 last_clipboard_sequence_number = 0;
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
277
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
278 done:
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
279 UNBLOCK_INPUT;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
280
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
281 return (ok ? string : Qnil);
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
282 }
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
283
40962
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
284 DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data,
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
285 Sw32_get_clipboard_data, 0, 1, 0,
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
286 doc: /* This gets the clipboard data in text format. */)
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
287 (frame)
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
288 Lisp_Object frame;
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
289 {
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
290 HANDLE htext;
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
291 Lisp_Object ret = Qnil;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
292
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
293 if (!NILP (frame))
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 33697
diff changeset
294 CHECK_LIVE_FRAME (frame);
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
295
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
296 BLOCK_INPUT;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
297
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
298 if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL))
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
299 goto done;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
300
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
301 if ((htext = GetClipboardData (CF_TEXT)) == NULL)
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
302 goto closeclip;
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
303
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
304 {
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
305 unsigned char *src;
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
306 unsigned char *dst;
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
307 int nbytes;
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
308 int truelen;
23835
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
309 int require_decoding = 0;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
310
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
311 if ((src = (unsigned char *) GlobalLock (htext)) == NULL)
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
312 goto closeclip;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
313
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
314 nbytes = strlen (src);
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
315
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
316 /* If the text in clipboard is identical to what we put there
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
317 last time w32_set_clipboard_data was called, pretend there's no
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
318 data in the clipboard. This is so we don't pass our own text
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
319 from the clipboard (which might be troublesome if the killed
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
320 text includes null characters). */
51777
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
321 if ((clipboard_sequence_fn
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
322 && clipboard_sequence_fn () == last_clipboard_sequence_number)
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
323 || (last_clipboard_text
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
324 && clipboard_storage_size >= nbytes
940c7de274a2 (last_clipboard_sequence_number): New variable.
Jason Rumney <jasonr@gnu.org>
parents: 47879
diff changeset
325 && memcmp(last_clipboard_text, src, nbytes) == 0))
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
326 goto closeclip;
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
327
43483
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
328 {
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
329 /* If the clipboard data contains any non-ascii code, we
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
330 need to decode it. */
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
331 int i;
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
332
43483
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
333 for (i = 0; i < nbytes; i++)
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
334 {
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
335 if (src[i] >= 0x80)
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
336 {
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
337 require_decoding = 1;
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
338 break;
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
339 }
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
340 }
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
341 }
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
342
23835
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
343 if (require_decoding)
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
344 {
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
345 int bufsize;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
346 unsigned char *buf;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
347 struct coding_system coding;
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
348
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
349 if (NILP (Vnext_selection_coding_system))
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
350 Vnext_selection_coding_system = Vselection_coding_system;
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
351 setup_coding_system
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
352 (Fcheck_coding_system (Vnext_selection_coding_system), &coding);
29022
3eec558de0ef (Fw32_set_clipboard_data): Setup members
Kenichi Handa <handa@m17n.org>
parents: 27401
diff changeset
353 coding.src_multibyte = 0;
3eec558de0ef (Fw32_set_clipboard_data): Setup members
Kenichi Handa <handa@m17n.org>
parents: 27401
diff changeset
354 coding.dst_multibyte = 1;
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
355 Vnext_selection_coding_system = Qnil;
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
356 coding.mode |= CODING_MODE_LAST_BLOCK;
45984
f95eb5f690c3 (Fw32_get_clipboard_data): Disable composition handling.
Kenichi Handa <handa@m17n.org>
parents: 43483
diff changeset
357 /* We explicitely disable composition handling because
f95eb5f690c3 (Fw32_get_clipboard_data): Disable composition handling.
Kenichi Handa <handa@m17n.org>
parents: 43483
diff changeset
358 selection data should not contain any composition
f95eb5f690c3 (Fw32_get_clipboard_data): Disable composition handling.
Kenichi Handa <handa@m17n.org>
parents: 43483
diff changeset
359 sequence. */
f95eb5f690c3 (Fw32_get_clipboard_data): Disable composition handling.
Kenichi Handa <handa@m17n.org>
parents: 43483
diff changeset
360 coding.composing = COMPOSITION_DISABLED;
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
361 bufsize = decoding_buffer_size (&coding, nbytes);
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
362 buf = (unsigned char *) xmalloc (bufsize);
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
363 decode_coding (&coding, src, buf, nbytes, bufsize);
22745
ef9607e709bc (Fw32_set_clipboard_data): Set Vlast_coding_system_used.
Andrew Innes <andrewi@gnu.org>
parents: 22545
diff changeset
364 Vlast_coding_system_used = coding.symbol;
33697
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
365 ret = make_string_from_bytes ((char *) buf,
e7765cb122c3 (Fw32_set_clipboard_data): Save a copy of what is put on the clipboard.
Jason Rumney <jasonr@gnu.org>
parents: 31117
diff changeset
366 coding.produced_char, coding.produced);
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
367 xfree (buf);
43483
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
368 if (SYMBOLP (coding.post_read_conversion)
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
369 && !NILP (Ffboundp (coding.post_read_conversion)))
dcb45a76827f (Fw32_set_clipboard_data): Run pre-write-conversion
Jason Rumney <jasonr@gnu.org>
parents: 40962
diff changeset
370 ret = run_pre_post_conversion_on_str (ret, &coding, 0);
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
371 }
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
372 else
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
373 {
23835
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
374 /* Need to know final size after CR chars are removed because we
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
375 can't change the string size manually, and doing an extra
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
376 copy is silly. Note that we only remove CR when it appears
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
377 as part of CRLF. */
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
378
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
379 truelen = nbytes;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
380 dst = src;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
381 /* avoid using strchr because it recomputes the length everytime */
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
382 while ((dst = memchr (dst, '\r', nbytes - (dst - src))) != NULL)
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
383 {
23835
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
384 if (dst[1] == '\n') /* safe because of trailing '\0' */
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
385 truelen--;
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
386 dst++;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
387 }
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
388
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
389 ret = make_uninit_string (truelen);
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
390
23835
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
391 /* Convert CRLF line endings (the standard CF_TEXT clipboard
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
392 format) to LF endings as used internally by Emacs. */
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
393
46370
40db0673e6f0 Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
parents: 45988
diff changeset
394 dst = SDATA (ret);
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
395 while (1)
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
396 {
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
397 unsigned char *next;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
398 /* copy next line or remaining bytes excluding '\0' */
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
399 next = _memccpy (dst, src, '\r', nbytes);
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
400 if (next)
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
401 {
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
402 /* copied one line ending with '\r' */
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
403 int copied = next - dst;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
404 nbytes -= copied;
23835
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
405 dst += copied;
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
406 src += copied;
23835
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
407 if (*src == '\n')
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
408 dst--; /* overwrite '\r' with '\n' */
ad04307ef465 (Fw32_get_clipboard_data): Do not delete isolated CR
Geoff Voelker <voelker@cs.washington.edu>
parents: 23562
diff changeset
409 }
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
410 else
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
411 /* copied remaining partial line -> now finished */
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
412 break;
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
413 }
22745
ef9607e709bc (Fw32_set_clipboard_data): Set Vlast_coding_system_used.
Andrew Innes <andrewi@gnu.org>
parents: 22545
diff changeset
414
ef9607e709bc (Fw32_set_clipboard_data): Set Vlast_coding_system_used.
Andrew Innes <andrewi@gnu.org>
parents: 22545
diff changeset
415 Vlast_coding_system_used = Qraw_text;
15150
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
416 }
e37489592e27 (Fwin32_set_clipboard_data, Fwin32_get_clipboard_data):
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
417
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
418 GlobalUnlock (htext);
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
419 }
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
420
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
421 closeclip:
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
422 CloseClipboard ();
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
423
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
424 done:
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
425 UNBLOCK_INPUT;
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
426
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
427 return (ret);
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
428 }
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
429
15235
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
430 /* Support checking for a clipboard selection. */
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
431
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
432 DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p,
40962
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
433 0, 1, 0,
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
434 doc: /* Whether there is an owner for the given X Selection.
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
435 The arg should be the name of the selection in question, typically one of
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
436 the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
437 \(Those are literal upper-case symbol names, since that's what X expects.)
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
438 For convenience, the symbol nil is the same as `PRIMARY',
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
439 and t is the same as `SECONDARY'. */)
15235
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
440 (selection)
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
441 Lisp_Object selection;
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
442 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 33697
diff changeset
443 CHECK_SYMBOL (selection);
15235
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
444
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
445 /* Return nil for PRIMARY and SECONDARY selections; for CLIPBOARD, check
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
446 if the clipboard currently has valid text format contents. */
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
447
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
448 if (EQ (selection, QCLIPBOARD))
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
449 {
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
450 Lisp_Object val = Qnil;
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
451
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
452 if (OpenClipboard (NULL))
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
453 {
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
454 int format = 0;
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
455 while (format = EnumClipboardFormats (format))
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
456 if (format == CF_TEXT)
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
457 {
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
458 val = Qt;
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
459 break;
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
460 }
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
461 CloseClipboard ();
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
462 }
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
463 return val;
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
464 }
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
465 return Qnil;
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
466 }
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
467
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
468 void
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
469 syms_of_w32select ()
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
470 {
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
471 #if 0
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
472 defsubr (&Sw32_open_clipboard);
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
473 defsubr (&Sw32_empty_clipboard);
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
474 defsubr (&Sw32_close_clipboard);
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
475 #endif
16588
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
476 defsubr (&Sw32_set_clipboard_data);
481b7874a1e9 Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents: 15235
diff changeset
477 defsubr (&Sw32_get_clipboard_data);
15235
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
478 defsubr (&Sx_selection_exists_p);
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
479
22914
4d4e775cf6f7 (Vselection_coding_system): Renamed from Vclipboard_coding_system.
Richard M. Stallman <rms@gnu.org>
parents: 22745
diff changeset
480 DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system,
40962
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
481 doc: /* Coding system for communicating with other programs.
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
482 When sending or receiving text via cut_buffer, selection, and clipboard,
47879
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
483 the text is encoded or decoded by this coding system.
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
484 The default value is `iso-latin-1-dos'. */);
4ef507bc376e (syms_of_win32select): Fix docstring for `selection-coding-system'.
Juanma Barranquero <lekktu@gmail.com>
parents: 47280
diff changeset
485 Vselection_coding_system = intern ("iso-latin-1-dos");
22545
5d3f50b4c8d2 Include buffer.h, charset.h, and coding.h.
Andrew Innes <andrewi@gnu.org>
parents: 16884
diff changeset
486
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
487 DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system,
40962
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
488 doc: /* Coding system for the next communication with other programs.
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
489 Usually, `selection-coding-system' is used for communicating with
47280
7e81df5e2e1a (syms_of_w32select): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents: 46370
diff changeset
490 other programs. But, if this variable is set, it is used for the
7e81df5e2e1a (syms_of_w32select): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents: 46370
diff changeset
491 next communication only. After the communication, this variable is
40962
f66d09d1bb2f Change doc-string comments to `new style'. [w/`doc:' keyword]. Doc fixes.
Jason Rumney <jasonr@gnu.org>
parents: 40656
diff changeset
492 set to nil. */);
23562
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
493 Vnext_selection_coding_system = Qnil;
5f3243813b18 (Vnext_selection_coding_system): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents: 23422
diff changeset
494
15235
440d937a60f7 (QCLIPBOARD): New symbol.
Karl Heuer <kwzh@gnu.org>
parents: 15150
diff changeset
495 QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD);
13434
53ba95a88cf2 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
496 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51777
diff changeset
497
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51777
diff changeset
498 /* arch-tag: c96e9724-5eb1-4dad-be07-289f092fd2af
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51777
diff changeset
499 (do not change this comment) */