add VI_C_SETTOP for scrollbar setting
[nvi.git] / motif_l / m_copypaste.c
blobb898c611ba7e8a82b2f1fd652128eead6fb07268
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.6 1996/12/10 21:05:15 bostic Exp $ (Berkeley) $Date: 1996/12/10 21:05:15 $";
14 #endif /* not lint */
16 /* ICCCM Cut and paste Utilities: */
18 #include <stdio.h>
19 #include <X11/X.h>
20 #include <X11/Intrinsic.h>
21 #include <X11/Xatom.h>
23 typedef int (*PFI)();
25 static PFI icccm_paste,
26 icccm_copy,
27 icccm_clear,
28 icccm_error;
31 * InitCopyPaste --
33 * PUBLIC: void __vi_InitCopyPaste
34 * PUBLIC: __P((int (*)(), int (*)(), int (*)(), int (*)()));
36 void
37 __vi_InitCopyPaste(f_copy, f_paste, f_clear, f_error)
38 PFI f_copy, f_paste, f_clear, f_error;
40 icccm_paste = f_paste;
41 icccm_clear = f_clear;
42 icccm_copy = f_copy;
43 icccm_error = f_error;
47 #if defined(__STDC__)
48 static void peekProc( Widget widget,
49 void *data,
50 Atom *selection,
51 Atom *type,
52 void *value,
53 unsigned long *length,
54 int *format
56 #else
57 static void peekProc( widget, data, selection, type, value, length, format )
58 Widget widget;
59 void *data;
60 Atom *selection, *type;
61 void *value;
62 unsigned long *length;
63 int *format;
64 #endif
66 if ( *type == 0 )
67 (*icccm_error)( stderr, "Nothing in the primary selection buffer");
68 else if ( *type != XA_STRING )
69 (*icccm_error)( stderr, "Unknown type return from selection");
70 else
71 XtFree( value );
75 #ifdef 0
76 #if defined(__STDC__)
77 void _vi_AcquireClipboard( Widget wid )
78 #else
79 void _vi_AcquireClipboard( wid )
80 Widget wid;
81 #endif
83 XtGetSelectionValue( wid,
84 XA_PRIMARY,
85 XA_STRING,
86 (XtSelectionCallbackProc) peekProc,
87 NULL,
88 XtLastTimestampProcessed( XtDisplay(wid) )
91 #endif
94 #if defined(__STDC__)
95 static void loseProc( Widget widget )
96 #else
97 static void loseProc( widget )
98 Widget widget;
99 #endif
101 /* we have lost ownership of the selection. clear it */
102 (*icccm_clear)( widget );
104 /* also participate in the protocols */
105 XtDisownSelection( widget,
106 XA_PRIMARY,
107 XtLastTimestampProcessed( XtDisplay(widget) )
112 #if defined(__STDC__)
113 static int convertProc( Widget widget,
114 Atom *selection,
115 Atom *target,
116 Atom *type,
117 void **value,
118 int *length,
119 int *format
121 #else
122 static int convertProc( widget, selection, target, type, value, length, format )
123 Widget widget;
124 Atom *selection, *target, *type;
125 void **value;
126 int *length;
127 int *format;
128 #endif
130 String buffer;
131 int len;
133 /* someone wants a copy of the selection. is there one? */
134 (*icccm_copy)( &buffer, &len );
135 if ( len == 0 ) return False;
137 /* do they want the string? */
138 if ( *target == XA_STRING ) {
139 *length = len;
140 *value = (void *) XtMalloc( len );
141 *type = XA_STRING;
142 *format = 8;
143 memcpy( (char *) *value, buffer, *length );
144 return True;
147 /* do they want the length? */
148 if ( *target == XInternAtom( XtDisplay(widget), "LENGTH", FALSE) ) {
149 *length = 1;
150 *value = (void *) XtMalloc( sizeof(int) );
151 *type = *target;
152 *format = 32;
153 * ((int *) *value) = len;
154 return True;
157 /* we lose */
158 return False;
162 * __vi_AcquirePrimary --
164 * PUBLIC: void __vi_AcquirePrimary __P((Widget));
166 void
167 __vi_AcquirePrimary(widget)
168 Widget widget;
170 /* assert we own the primary selection */
171 XtOwnSelection( widget,
172 XA_PRIMARY,
173 XtLastTimestampProcessed( XtDisplay(widget) ),
174 (XtConvertSelectionProc) convertProc,
175 (XtLoseSelectionProc) loseProc,
176 NULL
179 #if defined(OPENLOOK)
180 /* assert we also own the clipboard */
181 XtOwnSelection( widget,
182 XA_CLIPBOARD( XtDisplay(widget) ),
183 XtLastTimestampProcessed( XtDisplay(widget) ),
184 convertProc,
185 loseProc,
186 NULL
188 #endif
192 #if defined(__STDC__)
193 static void gotProc( Widget widget,
194 void *data,
195 Atom *selection,
196 Atom *type,
197 void *value,
198 unsigned long *length,
199 int *format
201 #else
202 static void gotProc( widget, data, selection, type, value, length, format )
203 Widget widget;
204 void *data;
205 Atom *selection, *type;
206 void *value;
207 unsigned long *length;
208 int *format;
209 #endif
211 if ( *type == 0 )
212 (*icccm_error)( stderr, "Nothing in the primary selection buffer");
213 else if ( *type != XA_STRING )
214 (*icccm_error)( stderr, "Unknown type return from selection");
215 else {
216 (*icccm_paste)( widget, value, *length );
217 XtFree( value );
222 * __vi_PasteFromClipboard --
224 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
226 void
227 __vi_PasteFromClipboard(widget)
228 Widget widget;
230 XtGetSelectionValue( widget,
231 XA_PRIMARY,
232 XA_STRING,
233 (XtSelectionCallbackProc) gotProc,
234 NULL,
235 XtLastTimestampProcessed( XtDisplay(widget) )