3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
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 $";
16 /* ICCCM Cut and paste Utilities: */
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <X11/Intrinsic.h>
23 #include <X11/Xatom.h>
25 #include <bitstring.h>
28 #include "../common/common.h"
29 #include "../ipc/ip.h"
34 static PFI icccm_paste
,
42 * PUBLIC: void __vi_InitCopyPaste
43 * PUBLIC: __P((int (*)(), int (*)(), int (*)(), int (*)()));
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
;
52 icccm_error
= f_error
;
57 static void peekProc( Widget widget
,
62 unsigned long *length
,
66 static void peekProc( widget
, data
, selection
, type
, value
, length
, format
)
69 Atom
*selection
, *type
;
71 unsigned long *length
;
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");
86 void _vi_AcquireClipboard( Widget wid
)
88 void _vi_AcquireClipboard( wid
)
92 XtGetSelectionValue( wid
,
95 (XtSelectionCallbackProc
) peekProc
,
97 XtLastTimestampProcessed( XtDisplay(wid
) )
103 #if defined(__STDC__)
104 static void loseProc( Widget widget
)
106 static void loseProc( widget
)
110 /* we have lost ownership of the selection. clear it */
111 (*icccm_clear
)( widget
);
113 /* also participate in the protocols */
114 XtDisownSelection( widget
,
116 XtLastTimestampProcessed( XtDisplay(widget
) )
121 #if defined(__STDC__)
122 static int convertProc( Widget widget
,
131 static int convertProc( widget
, selection
, target
, type
, value
, length
, format
)
133 Atom
*selection
, *target
, *type
;
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
) {
149 *value
= (void *) XtMalloc( len
);
152 memcpy( (char *) *value
, buffer
, *length
);
156 /* do they want the length? */
157 if ( *target
== XInternAtom( XtDisplay(widget
), "LENGTH", FALSE
) ) {
159 *value
= (void *) XtMalloc( sizeof(int) );
162 * ((int *) *value
) = len
;
171 * __vi_AcquirePrimary --
173 * PUBLIC: void __vi_AcquirePrimary __P((Widget));
176 __vi_AcquirePrimary(widget
)
179 /* assert we own the primary selection */
180 XtOwnSelection( widget
,
182 XtLastTimestampProcessed( XtDisplay(widget
) ),
183 (XtConvertSelectionProc
) convertProc
,
184 (XtLoseSelectionProc
) loseProc
,
188 #if defined(OPENLOOK)
189 /* assert we also own the clipboard */
190 XtOwnSelection( widget
,
191 XA_CLIPBOARD( XtDisplay(widget
) ),
192 XtLastTimestampProcessed( XtDisplay(widget
) ),
201 #if defined(__STDC__)
202 static void gotProc( Widget widget
,
207 unsigned long *length
,
211 static void gotProc( widget
, data
, selection
, type
, value
, length
, format
)
214 Atom
*selection
, *type
;
216 unsigned long *length
;
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");
225 (*icccm_paste
)( widget
, value
, *length
);
231 * __vi_PasteFromClipboard --
233 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
236 __vi_PasteFromClipboard(widget
)
239 XtGetSelectionValue( widget
,
242 (XtSelectionCallbackProc
) gotProc
,
244 XtLastTimestampProcessed( XtDisplay(widget
) )