3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
12 #include <sys/cdefs.h>
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 __RCSID("$NetBSD: m_copypaste.c,v 1.2 2014/01/26 21:43:45 christos Exp $");
21 /* ICCCM Cut and paste Utilities: */
23 #include <sys/types.h>
24 #include <sys/queue.h>
27 #include <X11/Intrinsic.h>
28 #include <X11/Xatom.h>
30 #include <bitstring.h>
34 #include "../common/common.h"
35 #include "../ipc/ip.h"
40 static PFI icccm_paste
,
48 * PUBLIC: void __vi_InitCopyPaste
49 * PUBLIC: __P((int (*)(), int (*)(), int (*)(), int (*)()));
52 __vi_InitCopyPaste(PFI f_copy
, PFI f_paste
, PFI f_clear
, PFI f_error
)
54 icccm_paste
= f_paste
;
55 icccm_clear
= f_clear
;
57 icccm_error
= f_error
;
62 static void peekProc( Widget widget
,
67 unsigned long *length
,
71 static void peekProc( widget
, data
, selection
, type
, value
, length
, format
)
74 Atom
*selection
, *type
;
76 unsigned long *length
;
81 (*icccm_error
)( stderr
, "Nothing in the primary selection buffer");
82 else if ( *type
!= XA_STRING
)
83 (*icccm_error
)( stderr
, "Unknown type return from selection");
91 void _vi_AcquireClipboard( Widget wid
)
93 void _vi_AcquireClipboard( wid
)
97 XtGetSelectionValue( wid
,
100 (XtSelectionCallbackProc
) peekProc
,
102 XtLastTimestampProcessed( XtDisplay(wid
) )
108 #if defined(__STDC__)
109 static void loseProc( Widget widget
)
111 static void loseProc( widget
)
115 /* we have lost ownership of the selection. clear it */
116 (*icccm_clear
)( widget
);
118 /* also participate in the protocols */
119 XtDisownSelection( widget
,
121 XtLastTimestampProcessed( XtDisplay(widget
) )
126 #if defined(__STDC__)
127 static int convertProc( Widget widget
,
136 static int convertProc( widget
, selection
, target
, type
, value
, length
, format
)
138 Atom
*selection
, *target
, *type
;
147 /* someone wants a copy of the selection. is there one? */
148 (*icccm_copy
)( &buffer
, &len
);
149 if ( len
== 0 ) return False
;
151 /* do they want the string? */
152 if ( *target
== XA_STRING
) {
154 *value
= (void *) XtMalloc( len
);
157 memcpy( (char *) *value
, buffer
, *length
);
161 /* do they want the length? */
162 if ( *target
== XInternAtom( XtDisplay(widget
), "LENGTH", FALSE
) ) {
164 *value
= (void *) XtMalloc( sizeof(int) );
167 * ((int *) *value
) = len
;
176 * __vi_AcquirePrimary --
178 * PUBLIC: void __vi_AcquirePrimary __P((Widget));
181 __vi_AcquirePrimary(Widget widget
)
183 /* assert we own the primary selection */
184 XtOwnSelection( widget
,
186 XtLastTimestampProcessed( XtDisplay(widget
) ),
187 (XtConvertSelectionProc
) convertProc
,
188 (XtLoseSelectionProc
) loseProc
,
192 #if defined(OPENLOOK)
193 /* assert we also own the clipboard */
194 XtOwnSelection( widget
,
195 XA_CLIPBOARD( XtDisplay(widget
) ),
196 XtLastTimestampProcessed( XtDisplay(widget
) ),
205 #if defined(__STDC__)
206 static void gotProc( Widget widget
,
211 unsigned long *length
,
215 static void gotProc( widget
, data
, selection
, type
, value
, length
, format
)
218 Atom
*selection
, *type
;
220 unsigned long *length
;
225 (*icccm_error
)( stderr
, "Nothing in the primary selection buffer");
226 else if ( *type
!= XA_STRING
)
227 (*icccm_error
)( stderr
, "Unknown type return from selection");
229 (*icccm_paste
)( widget
, value
, *length
);
235 * __vi_PasteFromClipboard --
237 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
240 __vi_PasteFromClipboard(Widget widget
)
242 XtGetSelectionValue( widget
,
245 (XtSelectionCallbackProc
) gotProc
,
247 XtLastTimestampProcessed( XtDisplay(widget
) )