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.9 2001/06/25 15:19:26 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:26 $";
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(PFI f_copy
, PFI f_paste
, PFI f_clear
, PFI f_error
)
48 icccm_paste
= f_paste
;
49 icccm_clear
= f_clear
;
51 icccm_error
= f_error
;
56 static void peekProc( Widget widget
,
61 unsigned long *length
,
65 static void peekProc( widget
, data
, selection
, type
, value
, length
, format
)
68 Atom
*selection
, *type
;
70 unsigned long *length
;
75 (*icccm_error
)( stderr
, "Nothing in the primary selection buffer");
76 else if ( *type
!= XA_STRING
)
77 (*icccm_error
)( stderr
, "Unknown type return from selection");
85 void _vi_AcquireClipboard( Widget wid
)
87 void _vi_AcquireClipboard( wid
)
91 XtGetSelectionValue( wid
,
94 (XtSelectionCallbackProc
) peekProc
,
96 XtLastTimestampProcessed( XtDisplay(wid
) )
102 #if defined(__STDC__)
103 static void loseProc( Widget widget
)
105 static void loseProc( widget
)
109 /* we have lost ownership of the selection. clear it */
110 (*icccm_clear
)( widget
);
112 /* also participate in the protocols */
113 XtDisownSelection( widget
,
115 XtLastTimestampProcessed( XtDisplay(widget
) )
120 #if defined(__STDC__)
121 static int convertProc( Widget widget
,
130 static int convertProc( widget
, selection
, target
, type
, value
, length
, format
)
132 Atom
*selection
, *target
, *type
;
141 /* someone wants a copy of the selection. is there one? */
142 (*icccm_copy
)( &buffer
, &len
);
143 if ( len
== 0 ) return False
;
145 /* do they want the string? */
146 if ( *target
== XA_STRING
) {
148 *value
= (void *) XtMalloc( len
);
151 memcpy( (char *) *value
, buffer
, *length
);
155 /* do they want the length? */
156 if ( *target
== XInternAtom( XtDisplay(widget
), "LENGTH", FALSE
) ) {
158 *value
= (void *) XtMalloc( sizeof(int) );
161 * ((int *) *value
) = len
;
170 * __vi_AcquirePrimary --
172 * PUBLIC: void __vi_AcquirePrimary __P((Widget));
175 __vi_AcquirePrimary(Widget widget
)
177 /* assert we own the primary selection */
178 XtOwnSelection( widget
,
180 XtLastTimestampProcessed( XtDisplay(widget
) ),
181 (XtConvertSelectionProc
) convertProc
,
182 (XtLoseSelectionProc
) loseProc
,
186 #if defined(OPENLOOK)
187 /* assert we also own the clipboard */
188 XtOwnSelection( widget
,
189 XA_CLIPBOARD( XtDisplay(widget
) ),
190 XtLastTimestampProcessed( XtDisplay(widget
) ),
199 #if defined(__STDC__)
200 static void gotProc( Widget widget
,
205 unsigned long *length
,
209 static void gotProc( widget
, data
, selection
, type
, value
, length
, format
)
212 Atom
*selection
, *type
;
214 unsigned long *length
;
219 (*icccm_error
)( stderr
, "Nothing in the primary selection buffer");
220 else if ( *type
!= XA_STRING
)
221 (*icccm_error
)( stderr
, "Unknown type return from selection");
223 (*icccm_paste
)( widget
, value
, *length
);
229 * __vi_PasteFromClipboard --
231 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
234 __vi_PasteFromClipboard(Widget widget
)
236 XtGetSelectionValue( widget
,
239 (XtSelectionCallbackProc
) gotProc
,
241 XtLastTimestampProcessed( XtDisplay(widget
) )