Home | History | Annotate | Line # | Download | only in motif_l
m_copypaste.c revision 1.2.8.2
      1  1.2.8.2  tls /*-
      2  1.2.8.2  tls  * Copyright (c) 1996
      3  1.2.8.2  tls  *	Rob Zimmermann.  All rights reserved.
      4  1.2.8.2  tls  * Copyright (c) 1996
      5  1.2.8.2  tls  *	Keith Bostic.  All rights reserved.
      6  1.2.8.2  tls  *
      7  1.2.8.2  tls  * See the LICENSE file for redistribution information.
      8  1.2.8.2  tls  */
      9  1.2.8.2  tls 
     10  1.2.8.2  tls #include "config.h"
     11  1.2.8.2  tls 
     12  1.2.8.2  tls #include <sys/cdefs.h>
     13  1.2.8.2  tls #if 0
     14  1.2.8.2  tls #ifndef lint
     15  1.2.8.2  tls 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  1.2.8.2  tls #endif /* not lint */
     17  1.2.8.2  tls #else
     18  1.2.8.2  tls __RCSID("$NetBSD: m_copypaste.c,v 1.2.8.2 2014/08/19 23:51:52 tls Exp $");
     19  1.2.8.2  tls #endif
     20  1.2.8.2  tls 
     21  1.2.8.2  tls /* ICCCM Cut and paste Utilities: */
     22  1.2.8.2  tls 
     23  1.2.8.2  tls #include	<sys/types.h>
     24  1.2.8.2  tls #include	<sys/queue.h>
     25  1.2.8.2  tls 
     26  1.2.8.2  tls #include	<X11/X.h>
     27  1.2.8.2  tls #include	<X11/Intrinsic.h>
     28  1.2.8.2  tls #include	<X11/Xatom.h>
     29  1.2.8.2  tls 
     30  1.2.8.2  tls #include	<bitstring.h>
     31  1.2.8.2  tls #include	<stdio.h>
     32  1.2.8.2  tls 
     33  1.2.8.2  tls #undef LOCK_SUCCESS
     34  1.2.8.2  tls #include	"../common/common.h"
     35  1.2.8.2  tls #include	"../ipc/ip.h"
     36  1.2.8.2  tls #include	"m_motif.h"
     37  1.2.8.2  tls 
     38  1.2.8.2  tls typedef	int	(*PFI)();
     39  1.2.8.2  tls 
     40  1.2.8.2  tls static	PFI	icccm_paste,
     41  1.2.8.2  tls 		icccm_copy,
     42  1.2.8.2  tls 		icccm_clear,
     43  1.2.8.2  tls 		icccm_error;
     44  1.2.8.2  tls 
     45  1.2.8.2  tls /*
     46  1.2.8.2  tls  * InitCopyPaste --
     47  1.2.8.2  tls  *
     48  1.2.8.2  tls  * PUBLIC: void __vi_InitCopyPaste
     49  1.2.8.2  tls  * PUBLIC:    __P((int (*)(), int (*)(), int (*)(), int (*)()));
     50  1.2.8.2  tls  */
     51  1.2.8.2  tls void
     52  1.2.8.2  tls __vi_InitCopyPaste(PFI f_copy, PFI f_paste, PFI f_clear, PFI f_error)
     53  1.2.8.2  tls {
     54  1.2.8.2  tls     icccm_paste	= f_paste;
     55  1.2.8.2  tls     icccm_clear	= f_clear;
     56  1.2.8.2  tls     icccm_copy	= f_copy;
     57  1.2.8.2  tls     icccm_error	= f_error;
     58  1.2.8.2  tls }
     59  1.2.8.2  tls 
     60  1.2.8.2  tls 
     61  1.2.8.2  tls #if defined(__STDC__)
     62  1.2.8.2  tls static	void	peekProc( Widget widget,
     63  1.2.8.2  tls 			  void *data,
     64  1.2.8.2  tls 			  Atom *selection,
     65  1.2.8.2  tls 			  Atom *type,
     66  1.2.8.2  tls 			  void *value,
     67  1.2.8.2  tls 			  unsigned long *length,
     68  1.2.8.2  tls 			  int *format
     69  1.2.8.2  tls 			  )
     70  1.2.8.2  tls #else
     71  1.2.8.2  tls static	void	peekProc( widget, data, selection, type, value, length, format )
     72  1.2.8.2  tls 	Widget	widget;
     73  1.2.8.2  tls 	void	*data;
     74  1.2.8.2  tls 	Atom	*selection, *type;
     75  1.2.8.2  tls 	void	*value;
     76  1.2.8.2  tls 	unsigned long *length;
     77  1.2.8.2  tls 	int	*format;
     78  1.2.8.2  tls #endif
     79  1.2.8.2  tls {
     80  1.2.8.2  tls     if ( *type == 0 )
     81  1.2.8.2  tls 	(*icccm_error)( stderr, "Nothing in the primary selection buffer");
     82  1.2.8.2  tls     else if ( *type != XA_STRING )
     83  1.2.8.2  tls 	(*icccm_error)( stderr, "Unknown type return from selection");
     84  1.2.8.2  tls     else
     85  1.2.8.2  tls 	XtFree( value );
     86  1.2.8.2  tls }
     87  1.2.8.2  tls 
     88  1.2.8.2  tls 
     89  1.2.8.2  tls #if 0
     90  1.2.8.2  tls #if defined(__STDC__)
     91  1.2.8.2  tls void 	_vi_AcquireClipboard( Widget wid )
     92  1.2.8.2  tls #else
     93  1.2.8.2  tls void 	_vi_AcquireClipboard( wid )
     94  1.2.8.2  tls Widget	wid;
     95  1.2.8.2  tls #endif
     96  1.2.8.2  tls {
     97  1.2.8.2  tls     XtGetSelectionValue( wid,
     98  1.2.8.2  tls 			 XA_PRIMARY,
     99  1.2.8.2  tls 			 XA_STRING,
    100  1.2.8.2  tls 			 (XtSelectionCallbackProc) peekProc,
    101  1.2.8.2  tls 			 NULL,
    102  1.2.8.2  tls 			 XtLastTimestampProcessed( XtDisplay(wid) )
    103  1.2.8.2  tls 			 );
    104  1.2.8.2  tls }
    105  1.2.8.2  tls #endif
    106  1.2.8.2  tls 
    107  1.2.8.2  tls 
    108  1.2.8.2  tls #if defined(__STDC__)
    109  1.2.8.2  tls static	void	loseProc( Widget widget )
    110  1.2.8.2  tls #else
    111  1.2.8.2  tls static	void	loseProc( widget )
    112  1.2.8.2  tls 	Widget	widget;
    113  1.2.8.2  tls #endif
    114  1.2.8.2  tls {
    115  1.2.8.2  tls     /* we have lost ownership of the selection.  clear it */
    116  1.2.8.2  tls     (*icccm_clear)( widget );
    117  1.2.8.2  tls 
    118  1.2.8.2  tls     /* also participate in the protocols */
    119  1.2.8.2  tls     XtDisownSelection(	widget,
    120  1.2.8.2  tls 			XA_PRIMARY,
    121  1.2.8.2  tls 			XtLastTimestampProcessed( XtDisplay(widget) )
    122  1.2.8.2  tls 			);
    123  1.2.8.2  tls }
    124  1.2.8.2  tls 
    125  1.2.8.2  tls 
    126  1.2.8.2  tls #if defined(__STDC__)
    127  1.2.8.2  tls static	int convertProc( Widget widget,
    128  1.2.8.2  tls 		     Atom *selection,
    129  1.2.8.2  tls 		     Atom *target,
    130  1.2.8.2  tls 		     Atom *type,
    131  1.2.8.2  tls 		     void **value,
    132  1.2.8.2  tls 		     int *length,
    133  1.2.8.2  tls 		     int *format
    134  1.2.8.2  tls 		     )
    135  1.2.8.2  tls #else
    136  1.2.8.2  tls static	int convertProc( widget, selection, target, type, value, length, format )
    137  1.2.8.2  tls Widget	widget;
    138  1.2.8.2  tls Atom	*selection, *target, *type;
    139  1.2.8.2  tls void	**value;
    140  1.2.8.2  tls int	*length;
    141  1.2.8.2  tls int	*format;
    142  1.2.8.2  tls #endif
    143  1.2.8.2  tls {
    144  1.2.8.2  tls     String	buffer;
    145  1.2.8.2  tls     int		len;
    146  1.2.8.2  tls 
    147  1.2.8.2  tls     /* someone wants a copy of the selection.  is there one? */
    148  1.2.8.2  tls     (*icccm_copy)( &buffer, &len );
    149  1.2.8.2  tls     if ( len == 0 ) return False;
    150  1.2.8.2  tls 
    151  1.2.8.2  tls     /* do they want the string? */
    152  1.2.8.2  tls     if ( *target == XA_STRING ) {
    153  1.2.8.2  tls 	*length = len;
    154  1.2.8.2  tls 	*value  = (void *) XtMalloc( len );
    155  1.2.8.2  tls 	*type   = XA_STRING;
    156  1.2.8.2  tls 	*format = 8;
    157  1.2.8.2  tls 	memcpy( (char *) *value, buffer, *length );
    158  1.2.8.2  tls 	return True;
    159  1.2.8.2  tls 	}
    160  1.2.8.2  tls 
    161  1.2.8.2  tls     /* do they want the length? */
    162  1.2.8.2  tls     if ( *target == XInternAtom( XtDisplay(widget), "LENGTH", FALSE) ) {
    163  1.2.8.2  tls 	*length = 1;
    164  1.2.8.2  tls 	*value  = (void *) XtMalloc( sizeof(int) );
    165  1.2.8.2  tls 	*type   = *target;
    166  1.2.8.2  tls 	*format = 32;
    167  1.2.8.2  tls 	* ((int *) *value) = len;
    168  1.2.8.2  tls 	return True;
    169  1.2.8.2  tls 	}
    170  1.2.8.2  tls 
    171  1.2.8.2  tls     /* we lose */
    172  1.2.8.2  tls     return False;
    173  1.2.8.2  tls }
    174  1.2.8.2  tls 
    175  1.2.8.2  tls /*
    176  1.2.8.2  tls  * __vi_AcquirePrimary --
    177  1.2.8.2  tls  *
    178  1.2.8.2  tls  * PUBLIC: void	__vi_AcquirePrimary __P((Widget));
    179  1.2.8.2  tls  */
    180  1.2.8.2  tls void
    181  1.2.8.2  tls __vi_AcquirePrimary(Widget widget)
    182  1.2.8.2  tls {
    183  1.2.8.2  tls     /* assert we own the primary selection */
    184  1.2.8.2  tls     XtOwnSelection( widget,
    185  1.2.8.2  tls 		    XA_PRIMARY,
    186  1.2.8.2  tls 		    XtLastTimestampProcessed( XtDisplay(widget) ),
    187  1.2.8.2  tls 		    (XtConvertSelectionProc) convertProc,
    188  1.2.8.2  tls 		    (XtLoseSelectionProc) loseProc,
    189  1.2.8.2  tls 		    NULL
    190  1.2.8.2  tls 		    );
    191  1.2.8.2  tls 
    192  1.2.8.2  tls #if defined(OPENLOOK)
    193  1.2.8.2  tls     /* assert we also own the clipboard */
    194  1.2.8.2  tls     XtOwnSelection( widget,
    195  1.2.8.2  tls 		    XA_CLIPBOARD( XtDisplay(widget) ),
    196  1.2.8.2  tls 		    XtLastTimestampProcessed( XtDisplay(widget) ),
    197  1.2.8.2  tls 		    convertProc,
    198  1.2.8.2  tls 		    loseProc,
    199  1.2.8.2  tls 		    NULL
    200  1.2.8.2  tls 		    );
    201  1.2.8.2  tls #endif
    202  1.2.8.2  tls }
    203  1.2.8.2  tls 
    204  1.2.8.2  tls 
    205  1.2.8.2  tls #if defined(__STDC__)
    206  1.2.8.2  tls static	void	gotProc( Widget widget,
    207  1.2.8.2  tls 			 void *data,
    208  1.2.8.2  tls 			 Atom *selection,
    209  1.2.8.2  tls 			 Atom *type,
    210  1.2.8.2  tls 			 void *value,
    211  1.2.8.2  tls 			 unsigned long *length,
    212  1.2.8.2  tls 			 int *format
    213  1.2.8.2  tls 			 )
    214  1.2.8.2  tls #else
    215  1.2.8.2  tls static	void	gotProc( widget, data, selection, type, value, length, format )
    216  1.2.8.2  tls 	Widget	widget;
    217  1.2.8.2  tls 	void	*data;
    218  1.2.8.2  tls 	Atom	*selection, *type;
    219  1.2.8.2  tls 	void	*value;
    220  1.2.8.2  tls 	unsigned long *length;
    221  1.2.8.2  tls 	int	*format;
    222  1.2.8.2  tls #endif
    223  1.2.8.2  tls {
    224  1.2.8.2  tls     if ( *type == 0 )
    225  1.2.8.2  tls 	(*icccm_error)( stderr, "Nothing in the primary selection buffer");
    226  1.2.8.2  tls     else if ( *type != XA_STRING )
    227  1.2.8.2  tls 	(*icccm_error)( stderr, "Unknown type return from selection");
    228  1.2.8.2  tls     else {
    229  1.2.8.2  tls 	(*icccm_paste)( widget, value, *length );
    230  1.2.8.2  tls 	XtFree( value );
    231  1.2.8.2  tls     }
    232  1.2.8.2  tls }
    233  1.2.8.2  tls 
    234  1.2.8.2  tls /*
    235  1.2.8.2  tls  * __vi_PasteFromClipboard --
    236  1.2.8.2  tls  *
    237  1.2.8.2  tls  * PUBLIC: void	__vi_PasteFromClipboard __P((Widget));
    238  1.2.8.2  tls  */
    239  1.2.8.2  tls void
    240  1.2.8.2  tls __vi_PasteFromClipboard(Widget widget)
    241  1.2.8.2  tls {
    242  1.2.8.2  tls     XtGetSelectionValue( widget,
    243  1.2.8.2  tls 			 XA_PRIMARY,
    244  1.2.8.2  tls 			 XA_STRING,
    245  1.2.8.2  tls 			 (XtSelectionCallbackProc) gotProc,
    246  1.2.8.2  tls 			 NULL,
    247  1.2.8.2  tls 			 XtLastTimestampProcessed( XtDisplay(widget) )
    248  1.2.8.2  tls 			 );
    249  1.2.8.2  tls }
    250