annotate src/select-x.c @ 414:da8ed4261e83 r21-2-15

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