5 * Rob Zimmermann. All rights reserved.
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 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";
18 /* ICCCM Cut and paste Utilities: */
20 #include <sys/types.h>
21 #include <sys/queue.h>
24 #include <X11/Intrinsic.h>
25 #include <X11/Xatom.h>
27 #include <bitstring.h>
31 #include "../common/common.h"
32 #include "../ipc/ip.h"
37 static PFI icccm_paste
,
45 * PUBLIC: void __vi_InitCopyPaste
46 * PUBLIC: __P((int (*)(), int (*)(), int (*)(), int (*)()));
49 __vi_InitCopyPaste(PFI f_copy
, PFI f_paste
, PFI f_clear
, PFI f_error
)
51 icccm_paste
= f_paste
;
52 icccm_clear
= f_clear
;
54 icccm_error
= f_error
;
59 static void peekProc( Widget widget
,
64 unsigned long *length
,
68 static void peekProc( widget
, data
, selection
, type
, value
, length
, format
)
71 Atom
*selection
, *type
;
73 unsigned long *length
;
78 (*icccm_error
)( stderr
, "Nothing in the primary selection buffer");
79 else if ( *type
!= XA_STRING
)
80 (*icccm_error
)( stderr
, "Unknown type return from selection");
88 void _vi_AcquireClipboard( Widget wid
)
90 void _vi_AcquireClipboard( wid
)
94 XtGetSelectionValue( wid
,
97 (XtSelectionCallbackProc
) peekProc
,
99 XtLastTimestampProcessed( XtDisplay(wid
) )
105 #if defined(__STDC__)
106 static void loseProc( Widget widget
)
108 static void loseProc( widget
)
112 /* we have lost ownership of the selection. clear it */
113 (*icccm_clear
)( widget
);
115 /* also participate in the protocols */
116 XtDisownSelection( widget
,
118 XtLastTimestampProcessed( XtDisplay(widget
) )
123 #if defined(__STDC__)
124 static int convertProc( Widget widget
,
133 static int convertProc( widget
, selection
, target
, type
, value
, length
, format
)
135 Atom
*selection
, *target
, *type
;
144 /* someone wants a copy of the selection. is there one? */
145 (*icccm_copy
)( &buffer
, &len
);
146 if ( len
== 0 ) return False
;
148 /* do they want the string? */
149 if ( *target
== XA_STRING
) {
151 *value
= (void *) XtMalloc( len
);
154 memcpy( (char *) *value
, buffer
, *length
);
158 /* do they want the length? */
159 if ( *target
== XInternAtom( XtDisplay(widget
), "LENGTH", FALSE
) ) {
161 *value
= (void *) XtMalloc( sizeof(int) );
164 * ((int *) *value
) = len
;
173 * __vi_AcquirePrimary --
175 * PUBLIC: void __vi_AcquirePrimary __P((Widget));
178 __vi_AcquirePrimary(Widget widget
)
180 /* assert we own the primary selection */
181 XtOwnSelection( widget
,
183 XtLastTimestampProcessed( XtDisplay(widget
) ),
184 (XtConvertSelectionProc
) convertProc
,
185 (XtLoseSelectionProc
) loseProc
,
189 #if defined(OPENLOOK)
190 /* assert we also own the clipboard */
191 XtOwnSelection( widget
,
192 XA_CLIPBOARD( XtDisplay(widget
) ),
193 XtLastTimestampProcessed( XtDisplay(widget
) ),
202 #if defined(__STDC__)
203 static void gotProc( Widget widget
,
208 unsigned long *length
,
212 static void gotProc( widget
, data
, selection
, type
, value
, length
, format
)
215 Atom
*selection
, *type
;
217 unsigned long *length
;
222 (*icccm_error
)( stderr
, "Nothing in the primary selection buffer");
223 else if ( *type
!= XA_STRING
)
224 (*icccm_error
)( stderr
, "Unknown type return from selection");
226 (*icccm_paste
)( widget
, value
, *length
);
232 * __vi_PasteFromClipboard --
234 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
237 __vi_PasteFromClipboard(Widget widget
)
239 XtGetSelectionValue( widget
,
242 (XtSelectionCallbackProc
) gotProc
,
244 XtLastTimestampProcessed( XtDisplay(widget
) )