annotate src/xselect.c @ 173:8eaf7971accc r20-3b13

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