annotate src/xselect.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1 /* X Selection processing for XEmacs
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2 Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
3
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
5
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
9 later version.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
10
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
14 for more details.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
15
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
20
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
21 /* Synched up with: Not synched with FSF. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
22
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
23 /* Rewritten by jwz */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
24
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
25 #include <config.h>
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
26 #include "lisp.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
27
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
28 #include "buffer.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
29 #include "console-x.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
30 #include "objects-x.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
31
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
32 #include "frame.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
33 #include "opaque.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
34 #include "systime.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
35
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
36 int lisp_to_time (Lisp_Object, time_t *);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
37 Lisp_Object time_to_lisp (time_t);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
38
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
39 #ifdef LWLIB_USES_MOTIF
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
40 # define MOTIF_CLIPBOARDS
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
41 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
42
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
43 #ifdef MOTIF_CLIPBOARDS
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
44 # include <Xm/CutPaste.h>
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
45 static void hack_motif_clipboard_selection (Atom selection_atom,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
46 Lisp_Object selection_value,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
47 Time thyme, Display *display,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
48 Window selecting_window,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
49 Bool owned_p);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
50 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
51
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
52 #define CUT_BUFFER_SUPPORT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
53
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
54 Lisp_Object QPRIMARY, QSECONDARY, QSTRING, QINTEGER, QCLIPBOARD, QTIMESTAMP,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
55 QTEXT, QDELETE, QMULTIPLE, QINCR, QEMACS_TMP, QTARGETS, QATOM, QNULL,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
56 QATOM_PAIR, QCOMPOUND_TEXT;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
57
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
58 #ifdef CUT_BUFFER_SUPPORT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
59 Lisp_Object QCUT_BUFFER0, QCUT_BUFFER1, QCUT_BUFFER2, QCUT_BUFFER3,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
60 QCUT_BUFFER4, QCUT_BUFFER5, QCUT_BUFFER6, QCUT_BUFFER7;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
61 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
62
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
63 Lisp_Object Vx_lost_selection_hooks;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
64 Lisp_Object Vx_sent_selection_hooks;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
65
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
66 /* If this is a smaller number than the max-request-size of the display,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
67 emacs will use INCR selection transfer when the selection is larger
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
68 than this. The max-request-size is usually around 64k, so if you want
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
69 emacs to use incremental selection transfers when the selection is
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
70 smaller than that, set this. I added this mostly for debugging the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
71 incremental transfer stuff, but it might improve server performance.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
72 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
73 #define MAX_SELECTION_QUANTUM 0xFFFFFF
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
74
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
75 #define SELECTION_QUANTUM(dpy) ((XMaxRequestSize (dpy) << 2) - 100)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
76
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
77 /* This is an association list whose elements are of the form
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
78 ( selection-name selection-value selection-timestamp )
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
79 selection-name is a lisp symbol, whose name is the name of an X Atom.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
80 selection-value is the value that emacs owns for that selection.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
81 It may be any kind of Lisp object.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
82 selection-timestamp is the time at which emacs began owning this selection,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
83 as a cons of two 16-bit numbers (making a 32 bit time).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
84 If there is an entry in this alist, then it can be assumed that emacs owns
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
85 that selection.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
86 The only (eq) parts of this list that are visible from elisp are the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
87 selection-values.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
88 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
89 Lisp_Object Vselection_alist;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
90
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
91 /* This is an alist whose CARs are selection-types (whose names are the same
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
92 as the names of X Atoms) and whose CDRs are the names of Lisp functions to
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
93 call to convert the given Emacs selection value to a string representing
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
94 the given selection type. This is for elisp-level extension of the emacs
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
95 selection handling.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
96 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
97 Lisp_Object Vselection_converter_alist;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
98
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
99 /* "Selection owner couldn't convert selection" */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
100 Lisp_Object Qselection_conversion_error;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
101
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
102 /* If the selection owner takes too long to reply to a selection request,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
103 we give up on it. This is in seconds (0 = no timeout).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
104 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
105 int x_selection_timeout;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
106
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
107
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
108 /* Utility functions */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
109
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
110 static void lisp_data_to_selection_data (struct device *,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
111 Lisp_Object obj,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
112 unsigned char **data_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
113 Atom *type_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
114 unsigned int *size_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
115 int *format_ret);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
116 static Lisp_Object selection_data_to_lisp_data (struct device *,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
117 unsigned char *data,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
118 size_t size,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
119 Atom type,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
120 int format);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
121 static Lisp_Object x_get_window_property_as_lisp_data (Display *,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
122 Window,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
123 Atom property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
124 Lisp_Object target_type,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
125 Atom selection_atom);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
126
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
127 static int expect_property_change (Display *, Window, Atom prop, int state);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
128 static void wait_for_property_change (long);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
129 static void unexpect_property_change (int);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
130 static int waiting_for_other_props_on_window (Display *, Window);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
131
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
132 /* This converts a Lisp symbol to a server Atom, avoiding a server
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
133 roundtrip whenever possible.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
134 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
135 static Atom
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
136 symbol_to_x_atom (struct device *d, Lisp_Object sym, int only_if_exists)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
137 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
138 Display *display = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
139
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
140 if (NILP (sym)) return XA_PRIMARY;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
141 if (EQ (sym, Qt)) return XA_SECONDARY;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
142 if (EQ (sym, QPRIMARY)) return XA_PRIMARY;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
143 if (EQ (sym, QSECONDARY)) return XA_SECONDARY;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
144 if (EQ (sym, QSTRING)) return XA_STRING;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
145 if (EQ (sym, QINTEGER)) return XA_INTEGER;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
146 if (EQ (sym, QATOM)) return XA_ATOM;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
147 if (EQ (sym, QCLIPBOARD)) return DEVICE_XATOM_CLIPBOARD (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
148 if (EQ (sym, QTIMESTAMP)) return DEVICE_XATOM_TIMESTAMP (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
149 if (EQ (sym, QTEXT)) return DEVICE_XATOM_TEXT (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
150 if (EQ (sym, QDELETE)) return DEVICE_XATOM_DELETE (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
151 if (EQ (sym, QMULTIPLE)) return DEVICE_XATOM_MULTIPLE (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
152 if (EQ (sym, QINCR)) return DEVICE_XATOM_INCR (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
153 if (EQ (sym, QEMACS_TMP)) return DEVICE_XATOM_EMACS_TMP (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
154 if (EQ (sym, QTARGETS)) return DEVICE_XATOM_TARGETS (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
155 if (EQ (sym, QNULL)) return DEVICE_XATOM_NULL (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
156 if (EQ (sym, QATOM_PAIR)) return DEVICE_XATOM_ATOM_PAIR (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
157 if (EQ (sym, QCOMPOUND_TEXT)) return DEVICE_XATOM_COMPOUND_TEXT (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
158
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
159 #ifdef CUT_BUFFER_SUPPORT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
160 if (EQ (sym, QCUT_BUFFER0)) return XA_CUT_BUFFER0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
161 if (EQ (sym, QCUT_BUFFER1)) return XA_CUT_BUFFER1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
162 if (EQ (sym, QCUT_BUFFER2)) return XA_CUT_BUFFER2;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
163 if (EQ (sym, QCUT_BUFFER3)) return XA_CUT_BUFFER3;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
164 if (EQ (sym, QCUT_BUFFER4)) return XA_CUT_BUFFER4;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
165 if (EQ (sym, QCUT_BUFFER5)) return XA_CUT_BUFFER5;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
166 if (EQ (sym, QCUT_BUFFER6)) return XA_CUT_BUFFER6;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
167 if (EQ (sym, QCUT_BUFFER7)) return XA_CUT_BUFFER7;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
168 #endif /* CUT_BUFFER_SUPPORT */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
169
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
170 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
171 CONST char *nameext;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
172 GET_C_STRING_CTEXT_DATA_ALLOCA (Fsymbol_name (sym), nameext);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
173 return XInternAtom (display, nameext, only_if_exists ? True : False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
174 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
175 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
176
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
177
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
178 /* This converts a server Atom to a Lisp symbol, avoiding server roundtrips
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
179 and calls to intern whenever possible.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
180 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
181 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
182 x_atom_to_symbol (struct device *d, Atom atom)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
183 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
184 Display *display = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
185
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
186 if (! atom) return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
187 if (atom == XA_PRIMARY) return QPRIMARY;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
188 if (atom == XA_SECONDARY) return QSECONDARY;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
189 if (atom == XA_STRING) return QSTRING;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
190 if (atom == XA_INTEGER) return QINTEGER;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
191 if (atom == XA_ATOM) return QATOM;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
192 if (atom == DEVICE_XATOM_CLIPBOARD (d)) return QCLIPBOARD;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
193 if (atom == DEVICE_XATOM_TIMESTAMP (d)) return QTIMESTAMP;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
194 if (atom == DEVICE_XATOM_TEXT (d)) return QTEXT;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
195 if (atom == DEVICE_XATOM_DELETE (d)) return QDELETE;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
196 if (atom == DEVICE_XATOM_MULTIPLE (d)) return QMULTIPLE;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
197 if (atom == DEVICE_XATOM_INCR (d)) return QINCR;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
198 if (atom == DEVICE_XATOM_EMACS_TMP (d)) return QEMACS_TMP;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
199 if (atom == DEVICE_XATOM_TARGETS (d)) return QTARGETS;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
200 if (atom == DEVICE_XATOM_NULL (d)) return QNULL;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
201 if (atom == DEVICE_XATOM_ATOM_PAIR (d)) return QATOM_PAIR;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
202 if (atom == DEVICE_XATOM_COMPOUND_TEXT (d)) return QCOMPOUND_TEXT;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
203
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
204 #ifdef CUT_BUFFER_SUPPORT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
205 if (atom == XA_CUT_BUFFER0) return QCUT_BUFFER0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
206 if (atom == XA_CUT_BUFFER1) return QCUT_BUFFER1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
207 if (atom == XA_CUT_BUFFER2) return QCUT_BUFFER2;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
208 if (atom == XA_CUT_BUFFER3) return QCUT_BUFFER3;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
209 if (atom == XA_CUT_BUFFER4) return QCUT_BUFFER4;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
210 if (atom == XA_CUT_BUFFER5) return QCUT_BUFFER5;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
211 if (atom == XA_CUT_BUFFER6) return QCUT_BUFFER6;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
212 if (atom == XA_CUT_BUFFER7) return QCUT_BUFFER7;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
213 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
214
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
215 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
216 Lisp_Object newsym;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
217 CONST Bufbyte *intstr;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
218 char *str = XGetAtomName (display, atom);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
219
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
220 if (! str) return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
221
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
222 GET_C_CHARPTR_INT_CTEXT_DATA_ALLOCA (str, intstr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
223 newsym = intern ((char *) intstr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
224 XFree (str);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
225 return newsym;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
226 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
227 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
228
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
229
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
230 /* Do protocol to assert ourself as a selection owner.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
231 Update the Vselection_alist so that we can reply to later requests for
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
232 our selection.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
233 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
234 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
235 x_own_selection (Lisp_Object selection_name, Lisp_Object selection_value)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
236 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
237 struct device *d = decode_x_device (Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
238 Display *display = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
239 struct frame *sel_frame = selected_frame ();
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
240 Window selecting_window = XtWindow (FRAME_X_TEXT_WIDGET (sel_frame));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
241 /* Use the time of the last-read mouse or keyboard event.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
242 For selection purposes, we use this as a sleazy way of knowing what the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
243 current time is in server-time. This assumes that the most recently read
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
244 mouse or keyboard event has something to do with the assertion of the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
245 selection, which is probably true.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
246 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
247 Time thyme = DEVICE_X_MOUSE_TIMESTAMP (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
248 Atom selection_atom;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
249
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
250 CHECK_SYMBOL (selection_name);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
251 selection_atom = symbol_to_x_atom (d, selection_name, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
252
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
253 XSetSelectionOwner (display, selection_atom, selecting_window, thyme);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
254
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
255 /* Now update the local cache */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
256 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
257 /* We do NOT use time_to_lisp() here any more, like we used to.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
258 That assumed equivalence of time_t and Time, which is not
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
259 necessarily the case (e.g. under OSF on the Alphas, where
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
260 Time is a 64-bit quantity and time_t is a 32-bit quantity).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
261
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
262 Opaque pointers are the clean way to go here.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
263 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
264 Lisp_Object selection_time = make_opaque (sizeof (thyme), (void *) &thyme);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
265 Lisp_Object selection_data = list3 (selection_name,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
266 selection_value,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
267 selection_time);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
268 Lisp_Object prev_value = assq_no_quit (selection_name, Vselection_alist);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
269 Vselection_alist = Fcons (selection_data, Vselection_alist);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
270
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
271 /* If we already owned the selection, remove the old selection data.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
272 Perhaps we should destructively modify it instead.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
273 Don't use Fdelq() as that may QUIT;.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
274 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
275 if (!NILP (prev_value))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
276 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
277 Lisp_Object rest; /* we know it's not the CAR, so it's easy. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
278 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
279 if (EQ (prev_value, Fcar (XCDR (rest))))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
280 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
281 XCDR (rest) = Fcdr (XCDR (rest));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
282 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
283 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
284 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
285 #ifdef MOTIF_CLIPBOARDS
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
286 hack_motif_clipboard_selection (selection_atom, selection_value,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
287 thyme, display, selecting_window,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
288 !NILP (prev_value));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
289 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
290 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
291 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
292
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
293
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
294 #ifdef MOTIF_CLIPBOARDS /* Bend over baby. Take it and like it. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
295
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
296 # ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
297 static void motif_clipboard_cb ();
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
298 # endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
299
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
300 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
301 hack_motif_clipboard_selection (Atom selection_atom,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
302 Lisp_Object selection_value,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
303 Time thyme,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
304 Display *display,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
305 Window selecting_window,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
306 Bool owned_p)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
307 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
308 struct device *d = get_device_from_display (display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
309 /* Those Motif wankers can't be bothered to follow the ICCCM, and do
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
310 their own non-Xlib non-Xt clipboard processing. So we have to do
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
311 this so that linked-in Motif widgets don't get themselves wedged.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
312 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
313 if (selection_atom == DEVICE_XATOM_CLIPBOARD (d)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
314 && STRINGP (selection_value)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
315
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
316 /* If we already own the clipboard, don't own it again in the Motif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
317 way. This might lose in some subtle way, since the timestamp won't
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
318 be current, but owning the selection on the Motif way does a
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
319 SHITLOAD of X protocol, and it makes killing text be incredibly
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
320 slow when using an X terminal. ARRRRGGGHHH!!!!
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
321 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
322 /* No, this is no good, because then Motif text fields don't bother
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
323 to look up the new value, and you can't Copy from a buffer, Paste
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
324 into a text field, then Copy something else from the buffer and
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
325 paste it into the text field -- it pastes the first thing again. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
326 /* && !owned_p */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
327 )
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
328 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
329 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
330 Widget widget = FRAME_X_TEXT_WIDGET (selected_frame());
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
331 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
332 long itemid;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
333 #if XmVersion >= 1002
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
334 long dataid;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
335 #else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
336 int dataid; /* 1.2 wants long, but 1.1.5 wants int... */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
337 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
338 XmString fmh;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
339 String encoding = "STRING";
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
340 CONST Extbyte *data = XSTRING_DATA (selection_value);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
341 Extcount bytes = XSTRING_LENGTH (selection_value);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
342
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
343 #ifdef MULE
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
344 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
345 enum { ASCII, LATIN_1, WORLD } chartypes = ASCII;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
346 CONST Bufbyte *ptr = data, *end = ptr + bytes;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
347 /* Optimize for the common ASCII case */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
348 while (ptr <= end)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
349 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
350 if (BYTE_ASCII_P (*ptr))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
351 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
352 ptr++;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
353 continue;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
354 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
355
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
356 if ((*ptr) == LEADING_BYTE_LATIN_ISO8859_1 ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
357 (*ptr) == LEADING_BYTE_CONTROL_1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
358 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
359 chartypes = LATIN_1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
360 ptr += 2;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
361 continue;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
362 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
363
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
364 chartypes = WORLD;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
365 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
366 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
367
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
368 if (chartypes == LATIN_1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
369 GET_STRING_BINARY_DATA_ALLOCA (selection_value, data, bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
370 else if (chartypes == WORLD)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
371 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
372 GET_STRING_CTEXT_DATA_ALLOCA (selection_value, data, bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
373 encoding = "COMPOUND_TEXT";
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
374 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
375 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
376 #endif /* MULE */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
377
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
378 fmh = XmStringCreateLtoR ("Clipboard", XmSTRING_DEFAULT_CHARSET);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
379 while (ClipboardSuccess !=
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
380 XmClipboardStartCopy (display, selecting_window, fmh, thyme,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
381 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
382 widget, motif_clipboard_cb,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
383 #else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
384 0, NULL,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
385 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
386 &itemid))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
387 ;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
388 XmStringFree (fmh);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
389 while (ClipboardSuccess !=
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
390 XmClipboardCopy (display, selecting_window, itemid, encoding,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
391 #ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
392 /* O'Reilly examples say size can be 0,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
393 but this clearly is not the case. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
394 0, bytes, (int) selecting_window, /* private id */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
395 #else /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
396 (XtPointer) data, bytes, 0,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
397 #endif /* !MOTIF_INCREMENTAL_CLIPBOARDS_WORK */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
398 &dataid))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
399 ;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
400 while (ClipboardSuccess !=
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
401 XmClipboardEndCopy (display, selecting_window, itemid))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
402 ;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
403 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
404 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
405
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
406 # ifdef MOTIF_INCREMENTAL_CLIPBOARDS_WORK
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
407 /* I tried to treat the clipboard like a real selection, and not send
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
408 the data until it was requested, but it looks like that just doesn't
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
409 work at all unless the selection owner and requestor are in different
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
410 processes. From reading the Motif source, it looks like they never
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
411 even considered having two widgets in the same application transfer
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
412 data between each other using "by-name" clipboard values. What a
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
413 bunch of fuckups.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
414 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
415 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
416 motif_clipboard_cb (Widget widget, int *data_id, int *private_id, int *reason)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
417 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
418 switch (*reason)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
419 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
420 case XmCR_CLIPBOARD_DATA_REQUEST:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
421 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
422 Display *dpy = XtDisplay (widget);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
423 Window window = (Window) *private_id;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
424 Lisp_Object selection = assq_no_quit (QCLIPBOARD, Vselection_alist);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
425 if (NILP (selection)) abort ();
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
426 selection = XCDR (selection);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
427 if (!STRINGP (selection)) abort ();
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
428 XmClipboardCopyByName (dpy, window, *data_id,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
429 (char *) XSTRING_DATA (selection),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
430 XSTRING_LENGTH (selection) + 1,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
431 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
432 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
433 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
434 case XmCR_CLIPBOARD_DATA_DELETE:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
435 default:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
436 /* don't need to free anything */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
437 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
438 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
439 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
440 # endif /* MOTIF_INCREMENTAL_CLIPBOARDS_WORK */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
441 #endif /* MOTIF_CLIPBOARDS */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
442
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
443
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
444 /* Given a selection-name and desired type, this looks up our local copy of
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
445 the selection value and converts it to the type. It returns nil or a
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
446 string. This calls random elisp code, and may signal or gc.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
447 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
448 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
449 x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
450 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
451 /* This function can GC */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
452 Lisp_Object local_value = assq_no_quit (selection_symbol, Vselection_alist);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
453 Lisp_Object handler_fn, value, check;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
454
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
455 if (NILP (local_value)) return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
456
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
457 /* TIMESTAMP and MULTIPLE are special cases 'cause that's easiest. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
458 if (EQ (target_type, QTIMESTAMP))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
459 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
460 handler_fn = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
461 value = XCAR (XCDR (XCDR (local_value)));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
462 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
463
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
464 #if 0 /* #### MULTIPLE doesn't work yet */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
465 else if (CONSP (target_type) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
466 XCAR (target_type) == QMULTIPLE)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
467 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
468 Lisp_Object pairs = XCDR (target_type);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
469 int len = XVECTOR_LENGTH (pairs);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
470 int i;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
471 /* If the target is MULTIPLE, then target_type looks like
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
472 (MULTIPLE . [[SELECTION1 TARGET1] [SELECTION2 TARGET2] ... ])
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
473 We modify the second element of each pair in the vector and
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
474 return it as [[SELECTION1 <value1>] [SELECTION2 <value2>] ... ]
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
475 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
476 for (i = 0; i < len; i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
477 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
478 Lisp_Object pair = XVECTOR_DATA (pairs) [i];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
479 XVECTOR_DATA (pair) [1] =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
480 x_get_local_selection (XVECTOR_DATA (pair) [0],
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
481 XVECTOR_DATA (pair) [1]);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
482 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
483 return pairs;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
484 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
485 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
486 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
487 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
488 CHECK_SYMBOL (target_type);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
489 handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
490 if (NILP (handler_fn)) return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
491 value = call3 (handler_fn,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
492 selection_symbol, target_type,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
493 XCAR (XCDR (local_value)));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
494 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
495
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
496 /* This lets the selection function to return (TYPE . VALUE). For example,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
497 when the selected type is LINE_NUMBER, the returned type is SPAN, not
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
498 INTEGER.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
499 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
500 check = value;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
501 if (CONSP (value) && SYMBOLP (XCAR (value)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
502 check = XCDR (value);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
503
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
504 /* Strings, vectors, and symbols are converted to selection data format in
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
505 the obvious way. Integers are converted to 16 bit quantities if they're
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
506 small enough, otherwise 32 bits are used.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
507 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
508 if (STRINGP (check) ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
509 VECTORP (check) ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
510 SYMBOLP (check) ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
511 INTP (check) ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
512 CHARP (check) ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
513 NILP (value))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
514 return value;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
515
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
516 /* (N . M) or (N M) get turned into a 32 bit quantity. So if you want to
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
517 always return a small quantity as 32 bits, your converter routine needs
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
518 to return a cons.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
519 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
520 else if (CONSP (check) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
521 INTP (XCAR (check)) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
522 (INTP (XCDR (check)) ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
523 (CONSP (XCDR (check)) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
524 INTP (XCAR (XCDR (check))) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
525 NILP (XCDR (XCDR (check))))))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
526 return value;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
527 /* Otherwise the lisp converter function returned something unrecognized.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
528 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
529 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
530 signal_error (Qerror,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
531 list3 (build_string
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
532 ("unrecognized selection-conversion type"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
533 handler_fn,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
534 value));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
535
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
536 return Qnil; /* suppress compiler warning */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
537 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
538
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
539
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
540
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
541 /* Send a SelectionNotify event to the requestor with property=None, meaning
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
542 we were unable to do what they wanted.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
543 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
544 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
545 x_decline_selection_request (XSelectionRequestEvent *event)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
546 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
547 XSelectionEvent reply;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
548 reply.type = SelectionNotify;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
549 reply.display = event->display;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
550 reply.requestor = event->requestor;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
551 reply.selection = event->selection;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
552 reply.time = event->time;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
553 reply.target = event->target;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
554 reply.property = None;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
555
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
556 XSendEvent (reply.display, reply.requestor, False, 0L, (XEvent *) &reply);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
557 XFlush (reply.display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
558 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
559
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
560
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
561 /* Used as an unwind-protect clause so that, if a selection-converter signals
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
562 an error, we tell the requestor that we were unable to do what they wanted
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
563 before we throw to top-level or go into the debugger or whatever.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
564 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
565 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
566 x_selection_request_lisp_error (Lisp_Object closure)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
567 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
568 XSelectionRequestEvent *event = (XSelectionRequestEvent *)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
569 get_opaque_ptr (closure);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
570
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
571 free_opaque_ptr (closure);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
572 if (event->type == 0) /* we set this to mean "completed normally" */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
573 return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
574 x_decline_selection_request (event);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
575 return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
576 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
577
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
578
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
579 /* Convert our selection to the requested type, and put that data where the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
580 requestor wants it. Then tell them whether we've succeeded.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
581 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
582 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
583 x_reply_selection_request (XSelectionRequestEvent *event, int format,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
584 unsigned char *data, int size, Atom type)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
585 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
586 /* This function can GC */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
587 XSelectionEvent reply;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
588 Display *display = event->display;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
589 struct device *d = get_device_from_display (display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
590 Window window = event->requestor;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
591 int bytes_remaining;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
592 int format_bytes = format/8;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
593 int max_bytes = SELECTION_QUANTUM (display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
594 if (max_bytes > MAX_SELECTION_QUANTUM) max_bytes = MAX_SELECTION_QUANTUM;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
595
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
596 reply.type = SelectionNotify;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
597 reply.display = display;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
598 reply.requestor = window;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
599 reply.selection = event->selection;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
600 reply.time = event->time;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
601 reply.target = event->target;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
602 reply.property = (event->property == None ? event->target : event->property);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
603
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
604 /* #### XChangeProperty can generate BadAlloc, and we must handle it! */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
605
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
606 /* Store the data on the requested property.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
607 If the selection is large, only store the first N bytes of it.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
608 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
609 bytes_remaining = size * format_bytes;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
610 if (bytes_remaining <= max_bytes)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
611 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
612 /* Send all the data at once, with minimal handshaking. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
613 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
614 stderr_out ("\nStoring all %d\n", bytes_remaining);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
615 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
616 XChangeProperty (display, window, reply.property, type, format,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
617 PropModeReplace, data, size);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
618 /* At this point, the selection was successfully stored; ack it. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
619 XSendEvent (display, window, False, 0L, (XEvent *) &reply);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
620 XFlush (display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
621 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
622 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
623 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
624 /* Send an INCR selection. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
625 int prop_id;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
626
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
627 if (x_window_to_frame (d, window)) /* #### debug */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
628 error ("attempt to transfer an INCR to ourself!");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
629 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
630 stderr_out ("\nINCR %d\n", bytes_remaining);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
631 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
632 prop_id = expect_property_change (display, window, reply.property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
633 PropertyDelete);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
634
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
635 XChangeProperty (display, window, reply.property, DEVICE_XATOM_INCR (d),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
636 32, PropModeReplace, (unsigned char *)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
637 &bytes_remaining, 1);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
638 XSelectInput (display, window, PropertyChangeMask);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
639 /* Tell 'em the INCR data is there... */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
640 XSendEvent (display, window, False, 0L, (XEvent *) &reply);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
641 XFlush (display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
642
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
643 /* First, wait for the requestor to ack by deleting the property.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
644 This can run random lisp code (process handlers) or signal.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
645 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
646 wait_for_property_change (prop_id);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
647
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
648 while (bytes_remaining)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
649 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
650 int i = ((bytes_remaining < max_bytes)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
651 ? bytes_remaining
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
652 : max_bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
653 prop_id = expect_property_change (display, window, reply.property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
654 PropertyDelete);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
655 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
656 stderr_out (" INCR adding %d\n", i);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
657 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
658 /* Append the next chunk of data to the property. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
659 XChangeProperty (display, window, reply.property, type, format,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
660 PropModeAppend, data, i / format_bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
661 bytes_remaining -= i;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
662 data += i;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
663
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
664 /* Now wait for the requestor to ack this chunk by deleting the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
665 property. This can run random lisp code or signal.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
666 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
667 wait_for_property_change (prop_id);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
668 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
669 /* Now write a zero-length chunk to the property to tell the requestor
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
670 that we're done. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
671 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
672 stderr_out (" INCR done\n");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
673 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
674 if (! waiting_for_other_props_on_window (display, window))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
675 XSelectInput (display, window, 0L);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
676
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
677 XChangeProperty (display, window, reply.property, type, format,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
678 PropModeReplace, data, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
679 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
680 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
681
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
682
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
683
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
684 /* Called from the event-loop in response to a SelectionRequest event.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
685 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
686 void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
687 x_handle_selection_request (XSelectionRequestEvent *event)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
688 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
689 /* This function can GC */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
690 struct gcpro gcpro1, gcpro2, gcpro3;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
691 Lisp_Object local_selection_data = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
692 Lisp_Object selection_symbol;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
693 Lisp_Object target_symbol = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
694 Lisp_Object converted_selection = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
695 Time local_selection_time;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
696 Lisp_Object successful_p = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
697 int count;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
698 struct device *d = get_device_from_display (event->display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
699
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
700 GCPRO3 (local_selection_data, converted_selection, target_symbol);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
701
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
702 selection_symbol = x_atom_to_symbol (d, event->selection);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
703
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
704 local_selection_data = assq_no_quit (selection_symbol, Vselection_alist);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
705
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
706 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
707 /* This list isn't user-visible, so it can't "go bad." */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
708 assert (CONSP (local_selection_data));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
709 assert (CONSP (XCDR (local_selection_data)));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
710 assert (CONSP (XCDR (XCDR (local_selection_data))));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
711 assert (NILP (XCDR (XCDR (XCDR (local_selection_data)))));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
712 assert (CONSP (XCAR (XCDR (XCDR (local_selection_data)))));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
713 assert (INTP (XCAR (XCAR (XCDR (XCDR (local_selection_data))))));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
714 assert (INTP (XCDR (XCAR (XCDR (XCDR (local_selection_data))))));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
715 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
716
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
717 if (NILP (local_selection_data))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
718 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
719 /* Someone asked for the selection, but we don't have it any more. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
720 x_decline_selection_request (event);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
721 goto DONE_LABEL;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
722 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
723
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
724 local_selection_time =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
725 * (Time *) XOPAQUE_DATA (XCAR (XCDR (XCDR (local_selection_data))));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
726
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
727 if (event->time != CurrentTime &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
728 local_selection_time > event->time)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
729 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
730 /* Someone asked for the selection, and we have one, but not the one
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
731 they're looking for. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
732 x_decline_selection_request (event);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
733 goto DONE_LABEL;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
734 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
735
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
736 count = specpdl_depth ();
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
737 record_unwind_protect (x_selection_request_lisp_error,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
738 make_opaque_ptr (event));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
739 target_symbol = x_atom_to_symbol (d, event->target);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
740
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
741 #if 0 /* #### MULTIPLE doesn't work yet */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
742 if (EQ (target_symbol, QMULTIPLE))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
743 target_symbol = fetch_multiple_target (event);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
744 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
745
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
746 /* Convert lisp objects back into binary data */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
747
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
748 converted_selection =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
749 x_get_local_selection (selection_symbol, target_symbol);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
750
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
751 if (! NILP (converted_selection))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
752 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
753 unsigned char *data;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
754 unsigned int size;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
755 int format;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
756 Atom type;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
757 lisp_data_to_selection_data (d, converted_selection,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
758 &data, &type, &size, &format);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
759
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
760 x_reply_selection_request (event, format, data, size, type);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
761 successful_p = Qt;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
762 /* Tell x_selection_request_lisp_error() it's cool. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
763 event->type = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
764 xfree (data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
765 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
766 unbind_to (count, Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
767
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
768 DONE_LABEL:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
769
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
770 UNGCPRO;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
771
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
772 /* Let random lisp code notice that the selection has been asked for. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
773 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
774 Lisp_Object rest;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
775 Lisp_Object val = Vx_sent_selection_hooks;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
776 if (!UNBOUNDP (val) && !NILP (val))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
777 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
778 if (CONSP (val) && !EQ (XCAR (val), Qlambda))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
779 for (rest = val; !NILP (rest); rest = Fcdr (rest))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
780 call3 (Fcar(rest), selection_symbol, target_symbol,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
781 successful_p);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
782 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
783 call3 (val, selection_symbol, target_symbol,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
784 successful_p);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
785 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
786 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
787 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
788
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
789
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
790 /* Called from the event-loop in response to a SelectionClear event.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
791 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
792 void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
793 x_handle_selection_clear (XSelectionClearEvent *event)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
794 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
795 Display *display = event->display;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
796 struct device *d = get_device_from_display (display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
797 Atom selection = event->selection;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
798 Time changed_owner_time = event->time;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
799
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
800 Lisp_Object selection_symbol, local_selection_data;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
801 Time local_selection_time;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
802
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
803 selection_symbol = x_atom_to_symbol (d, selection);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
804
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
805 local_selection_data = assq_no_quit (selection_symbol, Vselection_alist);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
806
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
807 /* Well, we already believe that we don't own it, so that's just fine. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
808 if (NILP (local_selection_data)) return;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
809
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
810 local_selection_time =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
811 * (Time *) XOPAQUE_DATA (XCAR (XCDR (XCDR (local_selection_data))));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
812
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
813 /* This SelectionClear is for a selection that we no longer own, so we can
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
814 disregard it. (That is, we have reasserted the selection since this
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
815 request was generated.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
816 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
817 if (changed_owner_time != CurrentTime &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
818 local_selection_time > changed_owner_time)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
819 return;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
820
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
821 /* Otherwise, we're really honest and truly being told to drop it.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
822 Don't use Fdelq() as that may QUIT;.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
823 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
824 if (EQ (local_selection_data, Fcar (Vselection_alist)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
825 Vselection_alist = Fcdr (Vselection_alist);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
826 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
827 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
828 Lisp_Object rest;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
829 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
830 if (EQ (local_selection_data, Fcar (XCDR (rest))))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
831 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
832 XCDR (rest) = Fcdr (XCDR (rest));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
833 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
834 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
835 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
836
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
837 /* Let random lisp code notice that the selection has been stolen.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
838 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
839 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
840 Lisp_Object rest;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
841 Lisp_Object val = Vx_lost_selection_hooks;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
842 if (!UNBOUNDP (val) && !NILP (val))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
843 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
844 if (CONSP (val) && !EQ (XCAR (val), Qlambda))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
845 for (rest = val; !NILP (rest); rest = Fcdr (rest))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
846 call1 (Fcar (rest), selection_symbol);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
847 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
848 call1 (val, selection_symbol);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
849 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
850 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
851 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
852
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
853
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
854 /* This stuff is so that INCR selections are reentrant (that is, so we can
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
855 be servicing multiple INCR selection requests simultaneously). I haven't
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
856 actually tested that yet.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
857 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
858
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
859 static int prop_location_tick;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
860
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
861 static struct prop_location {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
862 int tick;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
863 Display *display;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
864 Window window;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
865 Atom property;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
866 int desired_state;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
867 struct prop_location *next;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
868 } *for_whom_the_bell_tolls;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
869
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
870
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
871 static int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
872 property_deleted_p (void *tick)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
873 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
874 struct prop_location *rest = for_whom_the_bell_tolls;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
875 while (rest)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
876 if (rest->tick == (long) tick)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
877 return 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
878 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
879 rest = rest->next;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
880 return 1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
881 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
882
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
883 static int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
884 waiting_for_other_props_on_window (Display *display, Window window)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
885 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
886 struct prop_location *rest = for_whom_the_bell_tolls;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
887 while (rest)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
888 if (rest->display == display && rest->window == window)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
889 return 1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
890 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
891 rest = rest->next;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
892 return 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
893 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
894
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
895
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
896 static int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
897 expect_property_change (Display *display, Window window,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
898 Atom property, int state)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
899 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
900 struct prop_location *pl = xnew (struct prop_location);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
901 pl->tick = ++prop_location_tick;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
902 pl->display = display;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
903 pl->window = window;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
904 pl->property = property;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
905 pl->desired_state = state;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
906 pl->next = for_whom_the_bell_tolls;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
907 for_whom_the_bell_tolls = pl;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
908 return pl->tick;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
909 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
910
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
911 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
912 unexpect_property_change (int tick)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
913 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
914 struct prop_location *prev = 0, *rest = for_whom_the_bell_tolls;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
915 while (rest)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
916 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
917 if (rest->tick == tick)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
918 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
919 if (prev)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
920 prev->next = rest->next;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
921 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
922 for_whom_the_bell_tolls = rest->next;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
923 xfree (rest);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
924 return;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
925 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
926 prev = rest;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
927 rest = rest->next;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
928 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
929 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
930
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
931 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
932 wait_for_property_change (long tick)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
933 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
934 /* This function can GC */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
935 wait_delaying_user_input (property_deleted_p, (void *) tick);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
936 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
937
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
938
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
939 /* Called from the event-loop in response to a PropertyNotify event.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
940 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
941 void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
942 x_handle_property_notify (XPropertyEvent *event)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
943 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
944 struct prop_location *prev = 0, *rest = for_whom_the_bell_tolls;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
945 while (rest)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
946 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
947 if (rest->property == event->atom &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
948 rest->window == event->window &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
949 rest->display == event->display &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
950 rest->desired_state == event->state)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
951 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
952 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
953 stderr_out ("Saw expected prop-%s on %s\n",
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
954 (event->state == PropertyDelete ? "delete" : "change"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
955 (char *) string_data (XSYMBOL (x_atom_to_symbol (get_device_from_display (event->display), event->atom))->name);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
956 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
957 if (prev)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
958 prev->next = rest->next;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
959 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
960 for_whom_the_bell_tolls = rest->next;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
961 xfree (rest);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
962 return;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
963 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
964 prev = rest;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
965 rest = rest->next;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
966 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
967 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
968 stderr_out ("Saw UNexpected prop-%s on %s\n",
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
969 (event->state == PropertyDelete ? "delete" : "change"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
970 (char *) string_data (XSYMBOL (x_atom_to_symbol (get_device_from_display (event->display), event->atom))->name));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
971 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
972 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
973
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
974
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
975
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
976 #if 0 /* #### MULTIPLE doesn't work yet */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
977
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
978 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
979 fetch_multiple_target (XSelectionRequestEvent *event)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
980 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
981 /* This function can GC */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
982 Display *display = event->display;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
983 Window window = event->requestor;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
984 Atom target = event->target;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
985 Atom selection_atom = event->selection;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
986 int result;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
987
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
988 return
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
989 Fcons (QMULTIPLE,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
990 x_get_window_property_as_lisp_data (display, window, target,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
991 QMULTIPLE,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
992 selection_atom));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
993 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
994
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
995 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
996 copy_multiple_data (Lisp_Object obj)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
997 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
998 Lisp_Object vec;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
999 int i;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1000 int len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1001 if (CONSP (obj))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1002 return Fcons (XCAR (obj), copy_multiple_data (XCDR (obj)));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1003
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1004 CHECK_VECTOR (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1005 len = XVECTOR_LENGTH (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1006 vec = make_vector (len, Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1007 for (i = 0; i < len; i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1008 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1009 Lisp_Object vec2 = XVECTOR_DATA (obj) [i];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1010 CHECK_VECTOR (vec2);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1011 if (XVECTOR_LENGTH (vec2) != 2)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1012 signal_error (Qerror, list2 (build_string
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1013 ("vectors must be of length 2"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1014 vec2));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1015 XVECTOR_DATA (vec) [i] = make_vector (2, Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1016 XVECTOR_DATA (XVECTOR_DATA (vec) [i]) [0] = XVECTOR_DATA (vec2) [0];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1017 XVECTOR_DATA (XVECTOR_DATA (vec) [i]) [1] = XVECTOR_DATA (vec2) [1];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1018 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1019 return vec;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1020 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1021
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1022 #endif /* 0 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1023
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1024
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1025 static Window reading_selection_reply;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1026 static Atom reading_which_selection;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1027 static int selection_reply_timed_out;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1028
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1029 static int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1030 selection_reply_done (void *ignore)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1031 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1032 return !reading_selection_reply;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1033 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1034
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1035 static Lisp_Object Qx_selection_reply_timeout_internal;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1036
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1037 DEFUN ("x-selection-reply-timeout-internal", Fx_selection_reply_timeout_internal,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1038 1, 1, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1039 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1040 (arg))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1041 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1042 selection_reply_timed_out = 1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1043 reading_selection_reply = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1044 return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1045 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1046
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1047
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1048 /* Do protocol to read selection-data from the server.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1049 Converts this to lisp data and returns it.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1050 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1051 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1052 x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1053 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1054 /* This function can GC */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1055 struct device *d = decode_x_device (Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1056 Display *display = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1057 struct frame *sel_frame = selected_frame ();
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1058 Window requestor_window = XtWindow (FRAME_X_TEXT_WIDGET (sel_frame));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1059 Time requestor_time = DEVICE_X_MOUSE_TIMESTAMP (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1060 Atom target_property = DEVICE_XATOM_EMACS_TMP (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1061 Atom selection_atom = symbol_to_x_atom (d, selection_symbol, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1062 int speccount;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1063 Atom type_atom = symbol_to_x_atom (d, (CONSP (target_type) ?
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1064 XCAR (target_type) : target_type), 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1065
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1066 XConvertSelection (display, selection_atom, type_atom, target_property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1067 requestor_window, requestor_time);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1068
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1069 /* Block until the reply has been read. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1070 reading_selection_reply = requestor_window;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1071 reading_which_selection = selection_atom;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1072 selection_reply_timed_out = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1073
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1074 speccount = specpdl_depth ();
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1075
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1076 /* add a timeout handler */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1077 if (x_selection_timeout > 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1078 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1079 Lisp_Object id = Fadd_timeout (make_int (x_selection_timeout),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1080 Qx_selection_reply_timeout_internal,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1081 Qnil, Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1082 record_unwind_protect (Fdisable_timeout, id);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1083 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1084
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1085 /* This is ^Gable */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1086 wait_delaying_user_input (selection_reply_done, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1087
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1088 if (selection_reply_timed_out)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1089 error ("timed out waiting for reply from selection owner");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1090
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1091 unbind_to (speccount, Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1092
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1093 /* otherwise, the selection is waiting for us on the requested property. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1094 return
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1095 x_get_window_property_as_lisp_data (display, requestor_window,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1096 target_property, target_type,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1097 selection_atom);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1098 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1099
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1100
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1101 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1102 x_get_window_property (Display *display, Window window, Atom property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1103 unsigned char **data_ret, int *bytes_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1104 Atom *actual_type_ret, int *actual_format_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1105 unsigned long *actual_size_ret, int delete_p)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1106 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1107 int total_size;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1108 unsigned long bytes_remaining;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1109 int offset = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1110 unsigned char *tmp_data = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1111 int result;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1112 int buffer_size = SELECTION_QUANTUM (display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1113 if (buffer_size > MAX_SELECTION_QUANTUM) buffer_size = MAX_SELECTION_QUANTUM;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1114
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1115 /* First probe the thing to find out how big it is. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1116 result = XGetWindowProperty (display, window, property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1117 0, 0, False, AnyPropertyType,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1118 actual_type_ret, actual_format_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1119 actual_size_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1120 &bytes_remaining, &tmp_data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1121 if (result != Success)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1122 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1123 *data_ret = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1124 *bytes_ret = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1125 return;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1126 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1127 XFree ((char *) tmp_data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1128
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1129 if (*actual_type_ret == None || *actual_format_ret == 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1130 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1131 if (delete_p) XDeleteProperty (display, window, property);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1132 *data_ret = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1133 *bytes_ret = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1134 return;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1135 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1136
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1137 total_size = bytes_remaining + 1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1138 *data_ret = (unsigned char *) xmalloc (total_size);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1139
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1140 /* Now read, until we've gotten it all. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1141 while (bytes_remaining)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1142 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1143 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1144 int last = bytes_remaining;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1145 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1146 result =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1147 XGetWindowProperty (display, window, property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1148 offset/4, buffer_size/4,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1149 (delete_p ? True : False),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1150 AnyPropertyType,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1151 actual_type_ret, actual_format_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1152 actual_size_ret, &bytes_remaining, &tmp_data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1153 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1154 stderr_out ("<< read %d\n", last-bytes_remaining);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1155 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1156 /* If this doesn't return Success at this point, it means that
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1157 some clod deleted the selection while we were in the midst of
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1158 reading it. Deal with that, I guess....
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1159 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1160 if (result != Success) break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1161 *actual_size_ret *= *actual_format_ret / 8;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1162 memcpy ((*data_ret) + offset, tmp_data, *actual_size_ret);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1163 offset += *actual_size_ret;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1164 XFree ((char *) tmp_data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1165 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1166 *bytes_ret = offset;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1167 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1168
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1169
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1170 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1171 receive_incremental_selection (Display *display, Window window, Atom property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1172 /* this one is for error messages only */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1173 Lisp_Object target_type,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1174 unsigned int min_size_bytes,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1175 unsigned char **data_ret, int *size_bytes_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1176 Atom *type_ret, int *format_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1177 unsigned long *size_ret)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1178 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1179 /* This function can GC */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1180 int offset = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1181 int prop_id;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1182 *size_bytes_ret = min_size_bytes;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1183 *data_ret = (unsigned char *) xmalloc (*size_bytes_ret);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1184 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1185 stderr_out ("\nread INCR %d\n", min_size_bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1186 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1187 /* At this point, we have read an INCR property, and deleted it (which
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1188 is how we ack its receipt: the sending window will be selecting
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1189 PropertyNotify events on our window to notice this).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1190
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1191 Now, we must loop, waiting for the sending window to put a value on
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1192 that property, then reading the property, then deleting it to ack.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1193 We are done when the sender places a property of length 0.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1194 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1195 prop_id = expect_property_change (display, window, property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1196 PropertyNewValue);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1197 while (1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1198 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1199 unsigned char *tmp_data;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1200 int tmp_size_bytes;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1201 wait_for_property_change (prop_id);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1202 /* expect it again immediately, because x_get_window_property may
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1203 .. no it won't, I don't get it.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1204 .. Ok, I get it now, the Xt code that implements INCR is broken.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1205 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1206 prop_id = expect_property_change (display, window, property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1207 PropertyNewValue);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1208 x_get_window_property (display, window, property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1209 &tmp_data, &tmp_size_bytes,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1210 type_ret, format_ret, size_ret, 1);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1211
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1212 if (tmp_size_bytes == 0) /* we're done */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1213 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1214 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1215 stderr_out (" read INCR done\n");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1216 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1217 unexpect_property_change (prop_id);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1218 if (tmp_data) xfree (tmp_data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1219 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1220 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1221 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1222 stderr_out (" read INCR %d\n", tmp_size_bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1223 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1224 if (*size_bytes_ret < offset + tmp_size_bytes)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1225 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1226 #if 0
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1227 stderr_out (" read INCR realloc %d -> %d\n",
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1228 *size_bytes_ret, offset + tmp_size_bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1229 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1230 *size_bytes_ret = offset + tmp_size_bytes;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1231 *data_ret = (unsigned char *) xrealloc (*data_ret, *size_bytes_ret);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1232 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1233 memcpy ((*data_ret) + offset, tmp_data, tmp_size_bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1234 offset += tmp_size_bytes;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1235 xfree (tmp_data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1236 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1237 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1238
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1239
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1240 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1241 x_get_window_property_as_lisp_data (Display *display,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1242 Window window,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1243 Atom property,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1244 /* next two for error messages only */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1245 Lisp_Object target_type,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1246 Atom selection_atom)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1247 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1248 /* This function can GC */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1249 Atom actual_type;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1250 int actual_format;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1251 unsigned long actual_size;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1252 unsigned char *data = NULL;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1253 int bytes = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1254 Lisp_Object val;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1255 struct device *d = get_device_from_display (display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1256
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1257 x_get_window_property (display, window, property, &data, &bytes,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1258 &actual_type, &actual_format, &actual_size, 1);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1259 if (! data)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1260 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1261 if (XGetSelectionOwner (display, selection_atom))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1262 /* there is a selection owner */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1263 signal_error
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1264 (Qselection_conversion_error,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1265 Fcons (build_string ("selection owner couldn't convert"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1266 Fcons (x_atom_to_symbol (d, selection_atom),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1267 actual_type ?
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1268 list2 (target_type, x_atom_to_symbol (d, actual_type)) :
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1269 list1 (target_type))));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1270 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1271 signal_error (Qerror,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1272 list2 (build_string ("no selection"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1273 x_atom_to_symbol (d, selection_atom)));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1274 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1275
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1276 if (actual_type == DEVICE_XATOM_INCR (d))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1277 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1278 /* Ok, that data wasn't *the* data, it was just the beginning. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1279
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1280 unsigned int min_size_bytes = * ((unsigned int *) data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1281 xfree (data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1282 receive_incremental_selection (display, window, property, target_type,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1283 min_size_bytes, &data, &bytes,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1284 &actual_type, &actual_format,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1285 &actual_size);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1286 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1287
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1288 /* It's been read. Now convert it to a lisp object in some semi-rational
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1289 manner. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1290 val = selection_data_to_lisp_data (d, data, bytes,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1291 actual_type, actual_format);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1292
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1293 xfree (data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1294 return val;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1295 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1296
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1297 /* These functions convert from the selection data read from the server into
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1298 something that we can use from elisp, and vice versa.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1299
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1300 Type: Format: Size: Elisp Type:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1301 ----- ------- ----- -----------
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1302 * 8 * String
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1303 ATOM 32 1 Symbol
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1304 ATOM 32 > 1 Vector of Symbols
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1305 * 16 1 Integer
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1306 * 16 > 1 Vector of Integers
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1307 * 32 1 if <=16 bits: Integer
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1308 if > 16 bits: Cons of top16, bot16
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1309 * 32 > 1 Vector of the above
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1310
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1311 When converting a Lisp number to C, it is assumed to be of format 16 if
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1312 it is an integer, and of format 32 if it is a cons of two integers.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1313
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1314 When converting a vector of numbers from Elisp to C, it is assumed to be
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1315 of format 16 if every element in the vector is an integer, and is assumed
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1316 to be of format 32 if any element is a cons of two integers.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1317
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1318 When converting an object to C, it may be of the form (SYMBOL . <data>)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1319 where SYMBOL is what we should claim that the type is. Format and
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1320 representation are as above.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1321
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1322 NOTE: Under Mule, when someone shoves us a string without a type, we
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1323 set the type to 'COMPOUND_TEXT and automatically convert to Compound
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1324 Text. If the string has a type, we assume that the user wants the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1325 data sent as-is so we just do "binary" conversion.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1326 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1327
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1328
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1329 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1330 selection_data_to_lisp_data (struct device *d,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1331 unsigned char *data,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1332 size_t size,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1333 Atom type,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1334 int format)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1335 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1336 if (type == DEVICE_XATOM_NULL (d))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1337 return QNULL;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1338
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1339 /* Convert any 8-bit data to a string, for compactness. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1340 else if (format == 8)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1341 return make_ext_string (data, size,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1342 type == DEVICE_XATOM_TEXT (d) ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1343 type == DEVICE_XATOM_COMPOUND_TEXT (d)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1344 ? FORMAT_CTEXT : FORMAT_BINARY);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1345
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1346 /* Convert a single atom to a Lisp Symbol.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1347 Convert a set of atoms to a vector of symbols. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1348 else if (type == XA_ATOM)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1349 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1350 if (size == sizeof (Atom))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1351 return x_atom_to_symbol (d, *((Atom *) data));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1352 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1353 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1354 int i;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1355 int len = size / sizeof (Atom);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1356 Lisp_Object v = Fmake_vector (make_int (len), Qzero);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1357 for (i = 0; i < len; i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1358 Faset (v, make_int (i), x_atom_to_symbol (d, ((Atom *) data) [i]));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1359 return v;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1360 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1361 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1362
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1363 /* Convert a single 16 or small 32 bit number to a Lisp Int.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1364 If the number is > 16 bits, convert it to a cons of integers,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1365 16 bits in each half.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1366 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1367 else if (format == 32 && size == sizeof (long))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1368 return word_to_lisp (((unsigned long *) data) [0]);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1369 else if (format == 16 && size == sizeof (short))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1370 return make_int ((int) (((unsigned short *) data) [0]));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1371
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1372 /* Convert any other kind of data to a vector of numbers, represented
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1373 as above (as an integer, or a cons of two 16 bit integers).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1374
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1375 #### Perhaps we should return the actual type to lisp as well.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1376
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1377 (x-get-selection-internal 'PRIMARY 'LINE_NUMBER)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1378 ==> [4 4]
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1379
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1380 and perhaps it should be
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1381
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1382 (x-get-selection-internal 'PRIMARY 'LINE_NUMBER)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1383 ==> (SPAN . [4 4])
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1384
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1385 Right now the fact that the return type was SPAN is discarded before
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1386 lisp code gets to see it.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1387 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1388 else if (format == 16)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1389 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1390 int i;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1391 Lisp_Object v = make_vector (size / 4, Qzero);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1392 for (i = 0; i < (int) size / 4; i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1393 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1394 int j = (int) ((unsigned short *) data) [i];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1395 Faset (v, make_int (i), make_int (j));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1396 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1397 return v;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1398 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1399 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1400 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1401 int i;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1402 Lisp_Object v = make_vector (size / 4, Qzero);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1403 for (i = 0; i < (int) size / 4; i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1404 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1405 unsigned long j = ((unsigned long *) data) [i];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1406 Faset (v, make_int (i), word_to_lisp (j));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1407 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1408 return v;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1409 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1410 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1411
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1413 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1414 lisp_data_to_selection_data (struct device *d,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1415 Lisp_Object obj,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1416 unsigned char **data_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1417 Atom *type_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1418 unsigned int *size_ret,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1419 int *format_ret)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1420 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1421 Lisp_Object type = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1422
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1423 if (CONSP (obj) && SYMBOLP (XCAR (obj)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1424 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1425 type = XCAR (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1426 obj = XCDR (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1427 if (CONSP (obj) && NILP (XCDR (obj)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1428 obj = XCAR (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1429 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1430
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1431 if (EQ (obj, QNULL) || (EQ (type, QNULL)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1432 { /* This is not the same as declining */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1433 *format_ret = 32;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1434 *size_ret = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1435 *data_ret = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1436 type = QNULL;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1437 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1438 else if (STRINGP (obj))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1439 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1440 CONST Extbyte *extval;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1441 Extcount extvallen;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1442
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1443 if (NILP (type))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1444 GET_STRING_CTEXT_DATA_ALLOCA (obj, extval, extvallen);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1445 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1446 GET_STRING_BINARY_DATA_ALLOCA (obj, extval, extvallen);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1447 *format_ret = 8;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1448 *size_ret = extvallen;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1449 *data_ret = (unsigned char *) xmalloc (*size_ret);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1450 memcpy (*data_ret, extval, *size_ret);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1451 #ifdef MULE
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1452 if (NILP (type)) type = QCOMPOUND_TEXT;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1453 #else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1454 if (NILP (type)) type = QSTRING;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1455 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1456 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1457 else if (CHARP (obj))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1458 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1459 Bufbyte buf[MAX_EMCHAR_LEN];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1460 Bytecount len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1461 CONST Extbyte *extval;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1462 Extcount extvallen;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1463
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1464 *format_ret = 8;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1465 len = set_charptr_emchar (buf, XCHAR (obj));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1466 GET_CHARPTR_EXT_CTEXT_DATA_ALLOCA (buf, len, extval, extvallen);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1467 *size_ret = extvallen;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1468 *data_ret = (unsigned char *) xmalloc (*size_ret);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1469 memcpy (*data_ret, extval, *size_ret);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1470 #ifdef MULE
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1471 if (NILP (type)) type = QCOMPOUND_TEXT;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1472 #else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1473 if (NILP (type)) type = QSTRING;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1474 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1475 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1476 else if (SYMBOLP (obj))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1477 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1478 *format_ret = 32;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1479 *size_ret = 1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1480 *data_ret = (unsigned char *) xmalloc (sizeof (Atom) + 1);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1481 (*data_ret) [sizeof (Atom)] = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1482 (*(Atom **) data_ret) [0] = symbol_to_x_atom (d, obj, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1483 if (NILP (type)) type = QATOM;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1484 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1485 else if (INTP (obj) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1486 XINT (obj) <= 0x7FFF &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1487 XINT (obj) >= -0x8000)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1488 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1489 *format_ret = 16;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1490 *size_ret = 1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1491 *data_ret = (unsigned char *) xmalloc (sizeof (short) + 1);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1492 (*data_ret) [sizeof (short)] = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1493 (*(short **) data_ret) [0] = (short) XINT (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1494 if (NILP (type)) type = QINTEGER;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1495 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1496 else if (INTP (obj) || CONSP (obj))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1497 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1498 *format_ret = 32;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1499 *size_ret = 1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1500 *data_ret = (unsigned char *) xmalloc (sizeof (long) + 1);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1501 (*data_ret) [sizeof (long)] = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1502 (*(unsigned long **) data_ret) [0] = lisp_to_word (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1503 if (NILP (type)) type = QINTEGER;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1504 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1505 else if (VECTORP (obj))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1506 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1507 /* Lisp Vectors may represent a set of ATOMs;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1508 a set of 16 or 32 bit INTEGERs;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1509 or a set of ATOM_PAIRs (represented as [[A1 A2] [A3 A4] ...]
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1510 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1511 int i;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1512
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1513 if (SYMBOLP (XVECTOR_DATA (obj) [0]))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1514 /* This vector is an ATOM set */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1515 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1516 if (NILP (type)) type = QATOM;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1517 *size_ret = XVECTOR_LENGTH (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1518 *format_ret = 32;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1519 *data_ret = (unsigned char *) xmalloc ((*size_ret) * sizeof (Atom));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1520 for (i = 0; i < (int) (*size_ret); i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1521 if (SYMBOLP (XVECTOR_DATA (obj) [i]))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1522 (*(Atom **) data_ret) [i] =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1523 symbol_to_x_atom (d, XVECTOR_DATA (obj) [i], 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1524 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1525 signal_error (Qerror, /* Qselection_error */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1526 list2 (build_string
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1527 ("all elements of the vector must be of the same type"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1528 obj));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1529 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1530 #if 0 /* #### MULTIPLE doesn't work yet */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1531 else if (VECTORP (XVECTOR_DATA (obj) [0]))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1532 /* This vector is an ATOM_PAIR set */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1533 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1534 if (NILP (type)) type = QATOM_PAIR;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1535 *size_ret = XVECTOR_LENGTH (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1536 *format_ret = 32;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1537 *data_ret = (unsigned char *)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1538 xmalloc ((*size_ret) * sizeof (Atom) * 2);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1539 for (i = 0; i < *size_ret; i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1540 if (VECTORP (XVECTOR_DATA (obj) [i]))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1541 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1542 Lisp_Object pair = XVECTOR_DATA (obj) [i];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1543 if (XVECTOR_LENGTH (pair) != 2)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1544 signal_error (Qerror,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1545 list2 (build_string
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1546 ("elements of the vector must be vectors of exactly two elements"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1547 pair));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1548
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1549 (*(Atom **) data_ret) [i * 2] =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1550 symbol_to_x_atom (d, XVECTOR_DATA (pair) [0], 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1551 (*(Atom **) data_ret) [(i * 2) + 1] =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1552 symbol_to_x_atom (d, XVECTOR_DATA (pair) [1], 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1553 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1554 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1555 signal_error (Qerror,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1556 list2 (build_string
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1557 ("all elements of the vector must be of the same type"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1558 obj));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1559 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1560 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1561 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1562 /* This vector is an INTEGER set, or something like it */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1563 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1564 *size_ret = XVECTOR_LENGTH (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1565 if (NILP (type)) type = QINTEGER;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1566 *format_ret = 16;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1567 for (i = 0; i < (int) (*size_ret); i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1568 if (CONSP (XVECTOR_DATA (obj) [i]))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1569 *format_ret = 32;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1570 else if (!INTP (XVECTOR_DATA (obj) [i]))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1571 signal_error (Qerror, /* Qselection_error */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1572 list2 (build_string
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1573 ("all elements of the vector must be integers or conses of integers"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1574 obj));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1575
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1576 *data_ret = (unsigned char *) xmalloc (*size_ret * (*format_ret/8));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1577 for (i = 0; i < (int) (*size_ret); i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1578 if (*format_ret == 32)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1579 (*((unsigned long **) data_ret)) [i] =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1580 lisp_to_word (XVECTOR_DATA (obj) [i]);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1581 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1582 (*((unsigned short **) data_ret)) [i] =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1583 (unsigned short) lisp_to_word (XVECTOR_DATA (obj) [i]);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1584 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1585 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1586 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1587 signal_error (Qerror, /* Qselection_error */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1588 list2 (build_string ("unrecognized selection data"),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1589 obj));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1590
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1591 *type_ret = symbol_to_x_atom (d, type, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1592 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1593
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1594 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1595 clean_local_selection_data (Lisp_Object obj)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1596 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1597 if (CONSP (obj) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1598 INTP (XCAR (obj)) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1599 CONSP (XCDR (obj)) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1600 INTP (XCAR (XCDR (obj))) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1601 NILP (XCDR (XCDR (obj))))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1602 obj = Fcons (XCAR (obj), XCDR (obj));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1603
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1604 if (CONSP (obj) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1605 INTP (XCAR (obj)) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1606 INTP (XCDR (obj)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1607 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1608 if (XINT (XCAR (obj)) == 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1609 return XCDR (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1610 if (XINT (XCAR (obj)) == -1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1611 return make_int (- XINT (XCDR (obj)));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1612 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1613 if (VECTORP (obj))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1614 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1615 int i;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1616 int len = XVECTOR_LENGTH (obj);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1617 Lisp_Object copy;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1618 if (len == 1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1619 return clean_local_selection_data (XVECTOR_DATA (obj) [0]);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1620 copy = make_vector (len, Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1621 for (i = 0; i < len; i++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1622 XVECTOR_DATA (copy) [i] =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1623 clean_local_selection_data (XVECTOR_DATA (obj) [i]);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1624 return copy;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1625 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1626 return obj;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1627 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1628
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1629
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1630 /* Called from the event loop to handle SelectionNotify events.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1631 I don't think this needs to be reentrant.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1632 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1633 void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1634 x_handle_selection_notify (XSelectionEvent *event)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1635 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1636 if (! reading_selection_reply)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1637 message ("received an unexpected SelectionNotify event");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1638 else if (event->requestor != reading_selection_reply)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1639 message ("received a SelectionNotify event for the wrong window");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1640 else if (event->selection != reading_which_selection)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1641 message ("received the wrong selection type in SelectionNotify!");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1642 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1643 reading_selection_reply = 0; /* we're done now. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1644 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1645
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1646
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1647 DEFUN ("x-own-selection-internal", Fx_own_selection_internal, 2, 2, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1648 Assert an X selection of the given TYPE with the given VALUE.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1649 TYPE is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1650 VALUE is typically a string, or a cons of two markers, but may be
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1651 anything that the functions on selection-converter-alist know about.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1652 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1653 (selection_name, selection_value))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1654 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1655 CHECK_SYMBOL (selection_name);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1656 if (NILP (selection_value)) error ("selection-value may not be nil.");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1657 x_own_selection (selection_name, selection_value);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1658 return selection_value;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1659 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1660
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1661
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1662 /* Request the selection value from the owner. If we are the owner,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1663 simply return our selection value. If we are not the owner, this
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1664 will block until all of the data has arrived.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1665 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1666 DEFUN ("x-get-selection-internal", Fx_get_selection_internal, 2, 2, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1667 Return text selected from some X window.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1668 SELECTION_SYMBOL is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1669 TARGET_TYPE is the type of data desired, typically STRING or COMPOUND_TEXT.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1670 Under Mule, if the resultant data comes back as 8-bit data in type
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1671 TEXT or COMPOUND_TEXT, it will be decoded as Compound Text.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1672 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1673 (selection_symbol, target_type))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1674 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1675 /* This function can GC */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1676 Lisp_Object val = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1677 struct gcpro gcpro1, gcpro2;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1678 GCPRO2 (target_type, val); /* we store newly consed data into these */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1679 CHECK_SYMBOL (selection_symbol);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1680
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1681 #if 0 /* #### MULTIPLE doesn't work yet */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1682 if (CONSP (target_type) &&
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1683 XCAR (target_type) == QMULTIPLE)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1684 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1685 CHECK_VECTOR (XCDR (target_type));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1686 /* So we don't destructively modify this... */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1687 target_type = copy_multiple_data (target_type);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1688 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1689 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1690 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1691 CHECK_SYMBOL (target_type);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1692
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1693 val = x_get_local_selection (selection_symbol, target_type);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1694
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1695 if (NILP (val))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1696 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1697 val = x_get_foreign_selection (selection_symbol, target_type);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1698 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1699 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1700 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1701 if (CONSP (val) && SYMBOLP (XCAR (val)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1702 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1703 val = XCDR (val);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1704 if (CONSP (val) && NILP (XCDR (val)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1705 val = XCAR (val);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1706 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1707 val = clean_local_selection_data (val);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1708 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1709 UNGCPRO;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1710 return val;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1711 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1712
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1713 DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal, 1, 2, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1714 If we own the named selection, then disown it (make there be no selection).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1715 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1716 (selection, timeval))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1717 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1718 struct device *d = decode_x_device (Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1719 Display *display = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1720 Time timestamp;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1721 Atom selection_atom;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1722 XSelectionClearEvent event;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1723
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1724 CHECK_SYMBOL (selection);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1725 if (NILP (timeval))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1726 timestamp = DEVICE_X_MOUSE_TIMESTAMP (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1727 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1728 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1729 /* #### This is bogus. See the comment above about problems
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1730 on OSF/1 and DEC Alphas. Yet another reason why it sucks
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1731 to have the implementation (i.e. cons of two 16-bit
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1732 integers) exposed. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1733 time_t the_time;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1734 lisp_to_time (timeval, &the_time);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1735 timestamp = (Time) the_time;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1736 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1737
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1738 if (NILP (assq_no_quit (selection, Vselection_alist)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1739 return Qnil; /* Don't disown the selection when we're not the owner. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1740
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1741 selection_atom = symbol_to_x_atom (d, selection, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1742
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1743 XSetSelectionOwner (display, selection_atom, None, timestamp);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1744
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1745 /* It doesn't seem to be guaranteed that a SelectionClear event will be
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1746 generated for a window which owns the selection when that window sets
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1747 the selection owner to None. The NCD server does, the MIT Sun4 server
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1748 doesn't. So we synthesize one; this means we might get two, but
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1749 that's ok, because the second one won't have any effect.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1750 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1751 event.display = display;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1752 event.selection = selection_atom;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1753 event.time = timestamp;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1754 x_handle_selection_clear (&event);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1755
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1756 return Qt;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1757 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1758
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1759
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1760 DEFUN ("x-selection-owner-p", Fx_selection_owner_p, 0, 1, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1761 Return t if current emacs process owns the given X Selection.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1762 The arg should be the name of the selection in question, typically one of
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1763 the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience, the symbol
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1764 nil is the same as PRIMARY, and t is the same as SECONDARY.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1765 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1766 (selection))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1767 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1768 CHECK_SYMBOL (selection);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1769 if (EQ (selection, Qnil)) selection = QPRIMARY;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1770 else if (EQ (selection, Qt)) selection = QSECONDARY;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1771
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1772 return NILP (Fassq (selection, Vselection_alist)) ? Qnil : Qt;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1773 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1774
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1775 DEFUN ("x-selection-exists-p", Fx_selection_exists_p, 0, 1, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1776 Whether there is an owner for the given X Selection.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1777 The arg should be the name of the selection in question, typically one of
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1778 the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience, the symbol
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1779 nil is the same as PRIMARY, and t is the same as SECONDARY.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1780 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1781 (selection))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1782 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1783 struct device *d = decode_x_device (Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1784 Display *dpy = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1785 CHECK_SYMBOL (selection);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1786 if (!NILP (Fx_selection_owner_p (selection)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1787 return Qt;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1788 return XGetSelectionOwner (dpy, symbol_to_x_atom (d, selection, 0)) != None ?
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1789 Qt : Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1790 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1791
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1792
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1793 #ifdef CUT_BUFFER_SUPPORT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1794
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1795 static int cut_buffers_initialized; /* Whether we're sure they all exist */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1796
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1797 /* Ensure that all 8 cut buffers exist. ICCCM says we gotta... */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1798 static void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1799 initialize_cut_buffers (Display *display, Window window)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1800 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1801 static unsigned CONST char * CONST data = (unsigned CONST char *) "";
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1802 #define FROB(atom) XChangeProperty (display, window, atom, XA_STRING, 8, \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1803 PropModeAppend, data, 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1804 FROB (XA_CUT_BUFFER0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1805 FROB (XA_CUT_BUFFER1);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1806 FROB (XA_CUT_BUFFER2);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1807 FROB (XA_CUT_BUFFER3);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1808 FROB (XA_CUT_BUFFER4);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1809 FROB (XA_CUT_BUFFER5);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1810 FROB (XA_CUT_BUFFER6);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1811 FROB (XA_CUT_BUFFER7);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1812 #undef FROB
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1813 cut_buffers_initialized = 1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1814 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1815
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1816 #define CHECK_CUTBUFFER(symbol) \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1817 { CHECK_SYMBOL (symbol); \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1818 if (!EQ((symbol),QCUT_BUFFER0) && !EQ((symbol),QCUT_BUFFER1) && \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1819 !EQ((symbol),QCUT_BUFFER2) && !EQ((symbol),QCUT_BUFFER3) && \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1820 !EQ((symbol),QCUT_BUFFER4) && !EQ((symbol),QCUT_BUFFER5) && \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1821 !EQ((symbol),QCUT_BUFFER6) && !EQ((symbol),QCUT_BUFFER7)) \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1822 signal_error (Qerror, list2 (build_string ("Doesn't name a cutbuffer"), \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1823 (symbol))); \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1824 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1825
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1826 DEFUN ("x-get-cutbuffer-internal", Fx_get_cutbuffer_internal, 1, 1, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1827 Return the value of the named CUTBUFFER (typically CUT_BUFFER0).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1828 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1829 (cutbuffer))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1830 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1831 struct device *d = decode_x_device (Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1832 Display *display = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1833 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1834 Atom cut_buffer_atom;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1835 unsigned char *data;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1836 int bytes;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1837 Atom type;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1838 int format;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1839 unsigned long size;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1840 Lisp_Object ret;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1841
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1842 CHECK_CUTBUFFER (cutbuffer);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1843 cut_buffer_atom = symbol_to_x_atom (d, cutbuffer, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1844
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1845 x_get_window_property (display, window, cut_buffer_atom, &data, &bytes,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1846 &type, &format, &size, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1847 if (!data) return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1848
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1849 if (format != 8 || type != XA_STRING)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1850 signal_simple_error_2 ("Cut buffer doesn't contain 8-bit STRING data",
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1851 x_atom_to_symbol (d, type),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1852 make_int (format));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1853
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1854 /* We cheat - if the string contains an ESC character, that's
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1855 technically not allowed in a STRING, so we assume it's
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1856 COMPOUND_TEXT that we stored there ourselves earlier,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1857 in x-store-cutbuffer-internal */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1858 ret = (bytes ?
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1859 make_ext_string (data, bytes,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1860 memchr (data, 0x1b, bytes) ?
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1861 FORMAT_CTEXT : FORMAT_BINARY)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1862 : Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1863 xfree (data);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1864 return ret;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1865 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1866
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1867
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1868 DEFUN ("x-store-cutbuffer-internal", Fx_store_cutbuffer_internal, 2, 2, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1869 Set the value of the named CUTBUFFER (typically CUT_BUFFER0) to STRING.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1870 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1871 (cutbuffer, string))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1872 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1873 struct device *d = decode_x_device (Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1874 Display *display = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1875 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1876 Atom cut_buffer_atom;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1877 CONST Extbyte *data = XSTRING_DATA (string);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1878 Extcount bytes = XSTRING_LENGTH (string);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1879 Extcount bytes_remaining;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1880 int max_bytes = SELECTION_QUANTUM (display);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1881 #ifdef MULE
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1882 CONST Bufbyte *ptr, *end;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1883 enum { ASCII, LATIN_1, WORLD } chartypes = ASCII;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1884 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1885
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1886 if (max_bytes > MAX_SELECTION_QUANTUM)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1887 max_bytes = MAX_SELECTION_QUANTUM;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1888
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1889 CHECK_CUTBUFFER (cutbuffer);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1890 CHECK_STRING (string);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1891 cut_buffer_atom = symbol_to_x_atom (d, cutbuffer, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1892
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1893 if (! cut_buffers_initialized)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1894 initialize_cut_buffers (display, window);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1895
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1896 /* We use the STRING encoding (Latin-1 only) if we can, else COMPOUND_TEXT.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1897 We cheat and use type = `STRING' even when using COMPOUND_TEXT.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1898 The ICCCM requires that this be so, and other clients assume it,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1899 as we do ourselves in initialize_cut_buffers. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1900
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1901 #ifdef MULE
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1902 /* Optimize for the common ASCII case */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1903 for (ptr = data, end = ptr + bytes; ptr <= end; )
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1904 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1905 if (BYTE_ASCII_P (*ptr))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1906 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1907 ptr++;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1908 continue;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1909 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1910
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1911 if ((*ptr) == LEADING_BYTE_LATIN_ISO8859_1 ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1912 (*ptr) == LEADING_BYTE_CONTROL_1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1913 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1914 chartypes = LATIN_1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1915 ptr += 2;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1916 continue;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1917 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1918
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1919 chartypes = WORLD;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1920 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1921 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1922
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1923 if (chartypes == LATIN_1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1924 GET_STRING_BINARY_DATA_ALLOCA (string, data, bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1925 else if (chartypes == WORLD)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1926 GET_STRING_CTEXT_DATA_ALLOCA (string, data, bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1927 #endif /* MULE */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1928
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1929 bytes_remaining = bytes;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1930
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1931 while (bytes_remaining)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1932 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1933 int chunk = bytes_remaining < max_bytes ? bytes_remaining : max_bytes;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1934 XChangeProperty (display, window, cut_buffer_atom, XA_STRING, 8,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1935 (bytes_remaining == bytes
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1936 ? PropModeReplace : PropModeAppend),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1937 data, chunk);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1938 data += chunk;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1939 bytes_remaining -= chunk;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1940 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1941 return string;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1942 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1943
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1944
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1945 DEFUN ("x-rotate-cutbuffers-internal", Fx_rotate_cutbuffers_internal, 1, 1, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1946 Rotate the values of the cutbuffers by the given number of steps;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1947 positive means move values forward, negative means backward.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1948 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1949 (n))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1950 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1951 struct device *d = decode_x_device (Qnil);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1952 Display *display = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1953 Window window = RootWindow (display, 0); /* Cutbuffers are on frame 0 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1954 Atom props [8];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1955
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1956 CHECK_INT (n);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1957 if (XINT (n) == 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1958 return n;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1959 if (! cut_buffers_initialized)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1960 initialize_cut_buffers (display, window);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1961 props[0] = XA_CUT_BUFFER0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1962 props[1] = XA_CUT_BUFFER1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1963 props[2] = XA_CUT_BUFFER2;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1964 props[3] = XA_CUT_BUFFER3;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1965 props[4] = XA_CUT_BUFFER4;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1966 props[5] = XA_CUT_BUFFER5;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1967 props[6] = XA_CUT_BUFFER6;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1968 props[7] = XA_CUT_BUFFER7;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1969 XRotateWindowProperties (display, window, props, 8, XINT (n));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1970 return n;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1971 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1972
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1973 #endif /* CUT_BUFFER_SUPPORT */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1974
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1975
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1976
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1977 /************************************************************************/
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1978 /* initialization */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1979 /************************************************************************/
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1980
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1981 void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1982 syms_of_xselect (void)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1983 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1984 DEFSUBR (Fx_get_selection_internal);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1985 DEFSUBR (Fx_own_selection_internal);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1986 DEFSUBR (Fx_disown_selection_internal);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1987 DEFSUBR (Fx_selection_owner_p);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1988 DEFSUBR (Fx_selection_exists_p);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1989
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1990 #ifdef CUT_BUFFER_SUPPORT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1991 DEFSUBR (Fx_get_cutbuffer_internal);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1992 DEFSUBR (Fx_store_cutbuffer_internal);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1993 DEFSUBR (Fx_rotate_cutbuffers_internal);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1994 #endif /* CUT_BUFFER_SUPPORT */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1995
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1996 /* Unfortunately, timeout handlers must be lisp functions. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1997 defsymbol (&Qx_selection_reply_timeout_internal,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1998 "x-selection-reply-timeout-internal");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1999 DEFSUBR (Fx_selection_reply_timeout_internal);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2000
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2001 defsymbol (&QPRIMARY, "PRIMARY");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2002 defsymbol (&QSECONDARY, "SECONDARY");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2003 defsymbol (&QSTRING, "STRING");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2004 defsymbol (&QINTEGER, "INTEGER");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2005 defsymbol (&QCLIPBOARD, "CLIPBOARD");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2006 defsymbol (&QTIMESTAMP, "TIMESTAMP");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2007 defsymbol (&QTEXT, "TEXT");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2008 defsymbol (&QDELETE, "DELETE");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2009 defsymbol (&QMULTIPLE, "MULTIPLE");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2010 defsymbol (&QINCR, "INCR");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2011 defsymbol (&QEMACS_TMP, "_EMACS_TMP_");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2012 defsymbol (&QTARGETS, "TARGETS");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2013 defsymbol (&QATOM, "ATOM");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2014 defsymbol (&QATOM_PAIR, "ATOM_PAIR");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2015 defsymbol (&QCOMPOUND_TEXT, "COMPOUND_TEXT");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2016 defsymbol (&QNULL, "NULL");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2017
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2018 #ifdef CUT_BUFFER_SUPPORT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2019 defsymbol (&QCUT_BUFFER0, "CUT_BUFFER0");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2020 defsymbol (&QCUT_BUFFER1, "CUT_BUFFER1");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2021 defsymbol (&QCUT_BUFFER2, "CUT_BUFFER2");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2022 defsymbol (&QCUT_BUFFER3, "CUT_BUFFER3");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2023 defsymbol (&QCUT_BUFFER4, "CUT_BUFFER4");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2024 defsymbol (&QCUT_BUFFER5, "CUT_BUFFER5");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2025 defsymbol (&QCUT_BUFFER6, "CUT_BUFFER6");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2026 defsymbol (&QCUT_BUFFER7, "CUT_BUFFER7");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2027 #endif /* CUT_BUFFER_SUPPORT */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2028
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2029 deferror (&Qselection_conversion_error,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2030 "selection-conversion-error",
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2031 "selection-conversion error", Qio_error);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2032 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2033
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2034 void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2035 vars_of_xselect (void)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2036 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2037 #ifdef CUT_BUFFER_SUPPORT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2038 cut_buffers_initialized = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2039 Fprovide (intern ("cut-buffer"));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2040 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2041
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2042 reading_selection_reply = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2043 reading_which_selection = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2044 selection_reply_timed_out = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2045 for_whom_the_bell_tolls = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2046 prop_location_tick = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2047
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2048 Vselection_alist = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2049 staticpro (&Vselection_alist);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2050
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2051 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2052 An alist associating selection-types (such as STRING and TIMESTAMP) with
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2053 functions. These functions will be called with three args: the name of the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2054 selection (typically PRIMARY, SECONDARY, or CLIPBOARD); a desired type to
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2055 which the selection should be converted; and the local selection value
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2056 (whatever had been passed to `x-own-selection'). These functions should
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2057 return the value to send to the X server, which should be one of:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2058
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2059 -- nil (the conversion could not be done)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2060 -- a cons of a symbol and any of the following values; the symbol
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2061 explicitly specifies the type that will be sent.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2062 -- a string (If the type is not specified, then if Mule support exists,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2063 the string will be converted to Compound Text and sent in
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2064 the 'COMPOUND_TEXT format; otherwise (no Mule support),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2065 the string will be left as-is and sent in the 'STRING
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2066 format. If the type is specified, the string will be
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2067 left as-is (or converted to binary format under Mule).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2068 In all cases, 8-bit data it sent.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2069 -- a character (With Mule support, will be converted to Compound Text
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2070 whether or not a type is specified. If a type is not
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2071 specified, a type of 'STRING or 'COMPOUND_TEXT will be
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2072 sent, as for strings.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2073 -- the symbol 'NULL (Indicates that there is no meaningful return value.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2074 Empty 32-bit data with a type of 'NULL will be sent.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2075 -- a symbol (Will be converted into an atom. If the type is not specified,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2076 a type of 'ATOM will be sent.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2077 -- an integer (Will be converted into a 16-bit or 32-bit integer depending
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2078 on the value. If the type is not specified, a type of
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2079 'INTEGER will be sent.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2080 -- a cons (HIGH . LOW) of integers (Will be converted into a 32-bit integer.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2081 If the type is not specified, a type of
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2082 'INTEGER will be sent.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2083 -- a vector of symbols (Will be converted into a list of atoms. If the type
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2084 is not specified, a type of 'ATOM will be sent.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2085 -- a vector of integers (Will be converted into a list of 16-bit integers.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2086 If the type is not specified, a type of 'INTEGER
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2087 will be sent.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2088 -- a vector of integers and/or conses (HIGH . LOW) of integers
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2089 (Will be converted into a list of 16-bit integers.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2090 If the type is not specified, a type of 'INTEGER
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2091 will be sent.)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2092 */ );
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2093 Vselection_converter_alist = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2094
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2095 DEFVAR_LISP ("x-lost-selection-hooks", &Vx_lost_selection_hooks /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2096 A function or functions to be called after the X server has notified us
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2097 that we have lost the selection. The function(s) will be called with one
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2098 argument, a symbol naming the selection (typically PRIMARY, SECONDARY, or
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2099 CLIPBOARD).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2100 */ );
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2101 Vx_lost_selection_hooks = Qunbound;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2102
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2103 DEFVAR_LISP ("x-sent-selection-hooks", &Vx_sent_selection_hooks /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2104 A function or functions to be called after we have responded to some
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2105 other client's request for the value of a selection that we own. The
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2106 function(s) will be called with four arguments:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2107 - the name of the selection (typically PRIMARY, SECONDARY, or CLIPBOARD);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2108 - the name of the selection-type which we were requested to convert the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2109 selection into before sending (for example, STRING or LENGTH);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2110 - and whether we successfully transmitted the selection.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2111 We might have failed (and declined the request) for any number of reasons,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2112 including being asked for a selection that we no longer own, or being asked
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2113 to convert into a type that we don't know about or that is inappropriate.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2114 This hook doesn't let you change the behavior of emacs's selection replies,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2115 it merely informs you that they have happened.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2116 */ );
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2117 Vx_sent_selection_hooks = Qunbound;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2118
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2119 DEFVAR_INT ("x-selection-timeout", &x_selection_timeout /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2120 If the selection owner doesn't reply in this many seconds, we give up.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2121 A value of 0 means wait as long as necessary. This is initialized from the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2122 \"*selectionTimeout\" resource (which is expressed in milliseconds).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2123 */ );
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2124 x_selection_timeout = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2125 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2126
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2127 void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2128 Xatoms_of_xselect (struct device *d)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2129 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2130 Display *D = DEVICE_X_DISPLAY (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2131
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2132 /* Non-predefined atoms that we might end up using a lot */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2133 DEVICE_XATOM_CLIPBOARD (d) = XInternAtom (D, "CLIPBOARD", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2134 DEVICE_XATOM_TIMESTAMP (d) = XInternAtom (D, "TIMESTAMP", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2135 DEVICE_XATOM_TEXT (d) = XInternAtom (D, "TEXT", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2136 DEVICE_XATOM_DELETE (d) = XInternAtom (D, "DELETE", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2137 DEVICE_XATOM_MULTIPLE (d) = XInternAtom (D, "MULTIPLE", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2138 DEVICE_XATOM_INCR (d) = XInternAtom (D, "INCR", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2139 DEVICE_XATOM_TARGETS (d) = XInternAtom (D, "TARGETS", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2140 DEVICE_XATOM_NULL (d) = XInternAtom (D, "NULL", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2141 DEVICE_XATOM_ATOM_PAIR (d) = XInternAtom (D, "ATOM_PAIR", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2142 DEVICE_XATOM_COMPOUND_TEXT (d) = XInternAtom (D, "COMPOUND_TEXT", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2143 DEVICE_XATOM_EMACS_TMP (d) = XInternAtom (D, "_EMACS_TMP_", False);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2144 }