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.10 2003/11/05 17:09:59 skimo Exp (Berkeley) Date: 2003/11/05 17:09:59 ";
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>
29 #include "../common/common.h"
30 #include "../ipc/ip.h"
35 static PFI icccm_paste
,
43 * PUBLIC: void __vi_InitCopyPaste
44 * PUBLIC: __P((int (*)(), int (*)(), int (*)(), int (*)()));
47 __vi_InitCopyPaste(PFI f_copy
, PFI f_paste
, PFI f_clear
, PFI 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 widget
)
178 /* assert we own the primary selection */
179 XtOwnSelection( widget
,
181 XtLastTimestampProcessed( XtDisplay(widget
) ),
182 (XtConvertSelectionProc
) convertProc
,
183 (XtLoseSelectionProc
) loseProc
,
187 #if defined(OPENLOOK)
188 /* assert we also own the clipboard */
189 XtOwnSelection( widget
,
190 XA_CLIPBOARD( XtDisplay(widget
) ),
191 XtLastTimestampProcessed( XtDisplay(widget
) ),
200 #if defined(__STDC__)
201 static void gotProc( Widget widget
,
206 unsigned long *length
,
210 static void gotProc( widget
, data
, selection
, type
, value
, length
, format
)
213 Atom
*selection
, *type
;
215 unsigned long *length
;
220 (*icccm_error
)( stderr
, "Nothing in the primary selection buffer");
221 else if ( *type
!= XA_STRING
)
222 (*icccm_error
)( stderr
, "Unknown type return from selection");
224 (*icccm_paste
)( widget
, value
, *length
);
230 * __vi_PasteFromClipboard --
232 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
235 __vi_PasteFromClipboard(Widget widget
)
237 XtGetSelectionValue( widget
,
240 (XtSelectionCallbackProc
) gotProc
,
242 XtLastTimestampProcessed( XtDisplay(widget
) )