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.7 1996/12/16 17:27:29 bostic Exp $ (Berkeley) $Date: 1996/12/16 17:27:29 $";
16 /* ICCCM Cut and paste Utilities: */
20 #include <X11/Intrinsic.h>
21 #include <X11/Xatom.h>
25 static PFI icccm_paste
,
33 * PUBLIC: void __vi_InitCopyPaste
34 * PUBLIC: __P((int (*)(), int (*)(), int (*)(), int (*)()));
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
;
43 icccm_error
= f_error
;
48 static void peekProc( Widget widget
,
53 unsigned long *length
,
57 static void peekProc( widget
, data
, selection
, type
, value
, length
, format
)
60 Atom
*selection
, *type
;
62 unsigned long *length
;
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");
77 void _vi_AcquireClipboard( Widget wid
)
79 void _vi_AcquireClipboard( wid
)
83 XtGetSelectionValue( wid
,
86 (XtSelectionCallbackProc
) peekProc
,
88 XtLastTimestampProcessed( XtDisplay(wid
) )
95 static void loseProc( Widget widget
)
97 static void loseProc( widget
)
101 /* we have lost ownership of the selection. clear it */
102 (*icccm_clear
)( widget
);
104 /* also participate in the protocols */
105 XtDisownSelection( widget
,
107 XtLastTimestampProcessed( XtDisplay(widget
) )
112 #if defined(__STDC__)
113 static int convertProc( Widget widget
,
122 static int convertProc( widget
, selection
, target
, type
, value
, length
, format
)
124 Atom
*selection
, *target
, *type
;
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
) {
140 *value
= (void *) XtMalloc( len
);
143 memcpy( (char *) *value
, buffer
, *length
);
147 /* do they want the length? */
148 if ( *target
== XInternAtom( XtDisplay(widget
), "LENGTH", FALSE
) ) {
150 *value
= (void *) XtMalloc( sizeof(int) );
153 * ((int *) *value
) = len
;
162 * __vi_AcquirePrimary --
164 * PUBLIC: void __vi_AcquirePrimary __P((Widget));
167 __vi_AcquirePrimary(widget
)
170 /* assert we own the primary selection */
171 XtOwnSelection( widget
,
173 XtLastTimestampProcessed( XtDisplay(widget
) ),
174 (XtConvertSelectionProc
) convertProc
,
175 (XtLoseSelectionProc
) loseProc
,
179 #if defined(OPENLOOK)
180 /* assert we also own the clipboard */
181 XtOwnSelection( widget
,
182 XA_CLIPBOARD( XtDisplay(widget
) ),
183 XtLastTimestampProcessed( XtDisplay(widget
) ),
192 #if defined(__STDC__)
193 static void gotProc( Widget widget
,
198 unsigned long *length
,
202 static void gotProc( widget
, data
, selection
, type
, value
, length
, format
)
205 Atom
*selection
, *type
;
207 unsigned long *length
;
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");
216 (*icccm_paste
)( widget
, value
, *length
);
222 * __vi_PasteFromClipboard --
224 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
227 __vi_PasteFromClipboard(widget
)
230 XtGetSelectionValue( widget
,
233 (XtSelectionCallbackProc
) gotProc
,
235 XtLastTimestampProcessed( XtDisplay(widget
) )