Check for addnwstr if --enable-wide and don't build curses frontend
[nvi.git] / motif_l / m_copypaste.c
blob0d1dfc6d072525fa4c1f35c13e39bb9bfba00651
1 /*-
2 * Copyright (c) 1996
3 * Rob Zimmermann. All rights reserved.
4 * Copyright (c) 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: m_copypaste.c,v 8.8 1996/12/18 10:25:23 bostic Exp $ (Berkeley) $Date: 1996/12/18 10:25:23 $";
14 #endif /* not lint */
16 /* ICCCM Cut and paste Utilities: */
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <X11/X.h>
22 #include <X11/Intrinsic.h>
23 #include <X11/Xatom.h>
25 #include <bitstring.h>
26 #include <stdio.h>
28 #include "../common/common.h"
29 #include "../ipc/ip.h"
30 #include "m_motif.h"
32 typedef int (*PFI)();
34 static PFI icccm_paste,
35 icccm_copy,
36 icccm_clear,
37 icccm_error;
40 * InitCopyPaste --
42 * PUBLIC: void __vi_InitCopyPaste
43 * PUBLIC: __P((int (*)(), int (*)(), int (*)(), int (*)()));
45 void
46 __vi_InitCopyPaste(f_copy, f_paste, f_clear, f_error)
47 PFI f_copy, f_paste, f_clear, f_error;
49 icccm_paste = f_paste;
50 icccm_clear = f_clear;
51 icccm_copy = f_copy;
52 icccm_error = f_error;
56 #if defined(__STDC__)
57 static void peekProc( Widget widget,
58 void *data,
59 Atom *selection,
60 Atom *type,
61 void *value,
62 unsigned long *length,
63 int *format
65 #else
66 static void peekProc( widget, data, selection, type, value, length, format )
67 Widget widget;
68 void *data;
69 Atom *selection, *type;
70 void *value;
71 unsigned long *length;
72 int *format;
73 #endif
75 if ( *type == 0 )
76 (*icccm_error)( stderr, "Nothing in the primary selection buffer");
77 else if ( *type != XA_STRING )
78 (*icccm_error)( stderr, "Unknown type return from selection");
79 else
80 XtFree( value );
84 #if 0
85 #if defined(__STDC__)
86 void _vi_AcquireClipboard( Widget wid )
87 #else
88 void _vi_AcquireClipboard( wid )
89 Widget wid;
90 #endif
92 XtGetSelectionValue( wid,
93 XA_PRIMARY,
94 XA_STRING,
95 (XtSelectionCallbackProc) peekProc,
96 NULL,
97 XtLastTimestampProcessed( XtDisplay(wid) )
100 #endif
103 #if defined(__STDC__)
104 static void loseProc( Widget widget )
105 #else
106 static void loseProc( widget )
107 Widget widget;
108 #endif
110 /* we have lost ownership of the selection. clear it */
111 (*icccm_clear)( widget );
113 /* also participate in the protocols */
114 XtDisownSelection( widget,
115 XA_PRIMARY,
116 XtLastTimestampProcessed( XtDisplay(widget) )
121 #if defined(__STDC__)
122 static int convertProc( Widget widget,
123 Atom *selection,
124 Atom *target,
125 Atom *type,
126 void **value,
127 int *length,
128 int *format
130 #else
131 static int convertProc( widget, selection, target, type, value, length, format )
132 Widget widget;
133 Atom *selection, *target, *type;
134 void **value;
135 int *length;
136 int *format;
137 #endif
139 String buffer;
140 int len;
142 /* someone wants a copy of the selection. is there one? */
143 (*icccm_copy)( &buffer, &len );
144 if ( len == 0 ) return False;
146 /* do they want the string? */
147 if ( *target == XA_STRING ) {
148 *length = len;
149 *value = (void *) XtMalloc( len );
150 *type = XA_STRING;
151 *format = 8;
152 memcpy( (char *) *value, buffer, *length );
153 return True;
156 /* do they want the length? */
157 if ( *target == XInternAtom( XtDisplay(widget), "LENGTH", FALSE) ) {
158 *length = 1;
159 *value = (void *) XtMalloc( sizeof(int) );
160 *type = *target;
161 *format = 32;
162 * ((int *) *value) = len;
163 return True;
166 /* we lose */
167 return False;
171 * __vi_AcquirePrimary --
173 * PUBLIC: void __vi_AcquirePrimary __P((Widget));
175 void
176 __vi_AcquirePrimary(widget)
177 Widget widget;
179 /* assert we own the primary selection */
180 XtOwnSelection( widget,
181 XA_PRIMARY,
182 XtLastTimestampProcessed( XtDisplay(widget) ),
183 (XtConvertSelectionProc) convertProc,
184 (XtLoseSelectionProc) loseProc,
185 NULL
188 #if defined(OPENLOOK)
189 /* assert we also own the clipboard */
190 XtOwnSelection( widget,
191 XA_CLIPBOARD( XtDisplay(widget) ),
192 XtLastTimestampProcessed( XtDisplay(widget) ),
193 convertProc,
194 loseProc,
195 NULL
197 #endif
201 #if defined(__STDC__)
202 static void gotProc( Widget widget,
203 void *data,
204 Atom *selection,
205 Atom *type,
206 void *value,
207 unsigned long *length,
208 int *format
210 #else
211 static void gotProc( widget, data, selection, type, value, length, format )
212 Widget widget;
213 void *data;
214 Atom *selection, *type;
215 void *value;
216 unsigned long *length;
217 int *format;
218 #endif
220 if ( *type == 0 )
221 (*icccm_error)( stderr, "Nothing in the primary selection buffer");
222 else if ( *type != XA_STRING )
223 (*icccm_error)( stderr, "Unknown type return from selection");
224 else {
225 (*icccm_paste)( widget, value, *length );
226 XtFree( value );
231 * __vi_PasteFromClipboard --
233 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
235 void
236 __vi_PasteFromClipboard(widget)
237 Widget widget;
239 XtGetSelectionValue( widget,
240 XA_PRIMARY,
241 XA_STRING,
242 (XtSelectionCallbackProc) gotProc,
243 NULL,
244 XtLastTimestampProcessed( XtDisplay(widget) )