annotate src/select-x.c @ 398:74fd4e045ea6 r21-2-29

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