2009-01-31 10:33:39 -08:00
# ifdef HAVE_CONFIG_H
# include <config.h>
2010-08-02 10:47:49 -07:00
# endif /* ifdef HAVE_CONFIG_H */
2009-01-31 10:33:39 -08:00
# include <stdlib.h>
2009-02-19 14:25:07 -08:00
# include <string.h>
2009-01-31 10:33:39 -08:00
2004-11-23 07:17:56 -08:00
# include "Ecore.h"
2009-12-22 13:15:12 -08:00
# include "ecore_private.h"
2003-11-23 22:41:43 -08:00
# include "ecore_x_private.h"
2004-11-23 07:17:56 -08:00
# include "Ecore_X.h"
2004-12-04 02:10:29 -08:00
# include "Ecore_X_Atoms.h"
2003-11-23 22:41:43 -08:00
2005-04-10 03:20:18 -07:00
static Ecore_X_Selection_Intern selections [ 4 ] ;
2004-02-04 09:43:41 -08:00
static Ecore_X_Selection_Converter * converters = NULL ;
2005-04-10 03:20:18 -07:00
static Ecore_X_Selection_Parser * parsers = NULL ;
2004-01-16 12:41:45 -08:00
2011-10-20 22:40:59 -07:00
static int _ecore_x_selection_data_default_free ( void * data ) ;
static void * _ecore_x_selection_parser_files ( const char * target ,
2011-12-03 12:05:48 -08:00
void * data ,
int size ,
int format ) ;
2011-10-20 22:40:59 -07:00
static int _ecore_x_selection_data_files_free ( void * data ) ;
static void * _ecore_x_selection_parser_text ( const char * target ,
2011-12-03 12:05:48 -08:00
void * data ,
int size ,
int format ) ;
2011-10-20 22:40:59 -07:00
static int _ecore_x_selection_data_text_free ( void * data ) ;
static void * _ecore_x_selection_parser_targets ( const char * target ,
2011-12-03 12:05:48 -08:00
void * data ,
int size ,
int format ) ;
static int _ecore_x_selection_data_targets_free ( void * data ) ;
2005-04-10 03:20:18 -07:00
# define ECORE_X_SELECTION_DATA(x) ((Ecore_X_Selection_Data *)(x))
2004-01-16 14:34:02 -08:00
2004-01-16 12:41:45 -08:00
void
2004-02-04 23:14:56 -08:00
_ecore_x_selection_data_init ( void )
2004-01-16 12:41:45 -08:00
{
2005-03-01 23:06:44 -08:00
/* Initialize global data */
2011-12-03 12:05:48 -08:00
memset ( selections , 0 , sizeof ( selections ) ) ;
2005-03-01 23:06:44 -08:00
2011-12-03 12:05:48 -08:00
/* Initialize converters */
ecore_x_selection_converter_atom_add ( ECORE_X_ATOM_TEXT ,
2012-10-04 16:18:18 -07:00
ecore_x_selection_converter_text ) ;
2004-02-07 23:49:16 -08:00
# ifdef X_HAVE_UTF8_STRING
2011-12-03 12:05:48 -08:00
ecore_x_selection_converter_atom_add ( ECORE_X_ATOM_UTF8_STRING ,
2012-10-04 16:18:18 -07:00
ecore_x_selection_converter_text ) ;
2010-08-02 10:47:49 -07:00
# endif /* ifdef X_HAVE_UTF8_STRING */
2011-12-03 12:05:48 -08:00
ecore_x_selection_converter_atom_add ( ECORE_X_ATOM_COMPOUND_TEXT ,
2012-10-04 16:18:18 -07:00
ecore_x_selection_converter_text ) ;
2011-12-03 12:05:48 -08:00
ecore_x_selection_converter_atom_add ( ECORE_X_ATOM_STRING ,
2012-10-04 16:18:18 -07:00
ecore_x_selection_converter_text ) ;
2011-12-03 12:05:48 -08:00
/* Initialize parsers */
ecore_x_selection_parser_add ( " text/plain " ,
_ecore_x_selection_parser_text ) ;
ecore_x_selection_parser_add ( ECORE_X_SELECTION_TARGET_UTF8_STRING ,
_ecore_x_selection_parser_text ) ;
ecore_x_selection_parser_add ( " text/uri-list " ,
_ecore_x_selection_parser_files ) ;
ecore_x_selection_parser_add ( " _NETSCAPE_URL " ,
_ecore_x_selection_parser_files ) ;
ecore_x_selection_parser_add ( ECORE_X_SELECTION_TARGET_TARGETS ,
_ecore_x_selection_parser_targets ) ;
2011-12-03 11:41:12 -08:00
}
2004-02-04 09:43:41 -08:00
void
_ecore_x_selection_shutdown ( void )
{
2005-04-10 03:20:18 -07:00
Ecore_X_Selection_Converter * cnv ;
Ecore_X_Selection_Parser * prs ;
2004-02-04 09:43:41 -08:00
2005-02-10 04:27:13 -08:00
/* free the selection converters */
2005-04-10 03:20:18 -07:00
cnv = converters ;
2005-03-23 02:53:34 -08:00
while ( cnv )
2005-04-10 03:20:18 -07:00
{
2010-07-27 22:23:42 -07:00
Ecore_X_Selection_Converter * tmp ;
2005-04-10 03:20:18 -07:00
2010-07-27 22:23:42 -07:00
tmp = cnv - > next ;
free ( cnv ) ;
cnv = tmp ;
2005-03-23 02:53:34 -08:00
}
2005-02-10 04:27:13 -08:00
converters = NULL ;
2004-01-10 13:01:18 -08:00
2005-04-10 03:20:18 -07:00
/* free the selection parsers */
prs = parsers ;
while ( prs )
2005-03-23 02:53:34 -08:00
{
2010-07-27 22:23:42 -07:00
Ecore_X_Selection_Parser * tmp ;
2004-01-10 13:01:18 -08:00
2010-07-27 22:23:42 -07:00
tmp = prs ;
prs = prs - > next ;
free ( tmp - > target ) ;
free ( tmp ) ;
2005-04-10 03:20:18 -07:00
}
parsers = NULL ;
2011-12-03 11:41:12 -08:00
}
2004-01-10 13:01:18 -08:00
2005-04-10 03:20:18 -07:00
Ecore_X_Selection_Intern *
_ecore_x_selection_get ( Ecore_X_Atom selection )
2004-01-10 13:01:18 -08:00
{
2004-12-04 02:10:29 -08:00
if ( selection = = ECORE_X_ATOM_SELECTION_PRIMARY )
2011-10-20 22:40:59 -07:00
return & selections [ 0 ] ;
2004-12-04 02:10:29 -08:00
else if ( selection = = ECORE_X_ATOM_SELECTION_SECONDARY )
2011-10-20 22:40:59 -07:00
return & selections [ 1 ] ;
2005-03-23 02:53:34 -08:00
else if ( selection = = ECORE_X_ATOM_SELECTION_XDND )
2011-10-20 22:40:59 -07:00
return & selections [ 2 ] ;
2004-12-04 02:10:29 -08:00
else if ( selection = = ECORE_X_ATOM_SELECTION_CLIPBOARD )
2011-10-20 22:40:59 -07:00
return & selections [ 3 ] ;
2004-01-10 13:01:18 -08:00
else
2011-10-20 22:40:59 -07:00
return NULL ;
2011-12-03 11:41:12 -08:00
}
2004-01-10 13:01:18 -08:00
2010-09-26 10:49:05 -07:00
Eina_Bool
2011-12-03 12:05:48 -08:00
_ecore_x_selection_set ( Window w ,
const void * data ,
int size ,
2010-07-27 22:23:42 -07:00
Ecore_X_Atom selection )
2003-11-23 22:41:43 -08:00
{
2004-01-10 13:01:18 -08:00
int in ;
2004-02-04 23:14:56 -08:00
unsigned char * buf = NULL ;
2010-06-09 02:40:37 -07:00
2003-11-23 22:41:43 -08:00
XSetSelectionOwner ( _ecore_x_disp , selection , w , _ecore_x_event_last_time ) ;
if ( XGetSelectionOwner ( _ecore_x_disp , selection ) ! = w )
2011-10-20 22:40:59 -07:00
return EINA_FALSE ;
2010-06-09 02:40:37 -07:00
2004-12-04 02:10:29 -08:00
if ( selection = = ECORE_X_ATOM_SELECTION_PRIMARY )
2011-10-20 22:40:59 -07:00
in = 0 ;
2004-12-04 02:10:29 -08:00
else if ( selection = = ECORE_X_ATOM_SELECTION_SECONDARY )
2011-10-20 22:40:59 -07:00
in = 1 ;
2005-03-23 02:53:34 -08:00
else if ( selection = = ECORE_X_ATOM_SELECTION_XDND )
2011-10-20 22:40:59 -07:00
in = 2 ;
2005-04-10 03:20:18 -07:00
else if ( selection = = ECORE_X_ATOM_SELECTION_CLIPBOARD )
2011-10-20 22:40:59 -07:00
in = 3 ;
2005-04-10 03:20:18 -07:00
else
2011-10-20 22:40:59 -07:00
return EINA_FALSE ;
2005-03-23 02:53:34 -08:00
2004-01-10 13:01:18 -08:00
if ( data )
2005-03-23 02:53:34 -08:00
{
2010-07-27 22:23:42 -07:00
selections [ in ] . win = w ;
selections [ in ] . selection = selection ;
selections [ in ] . length = size ;
selections [ in ] . time = _ecore_x_event_last_time ;
buf = malloc ( size ) ;
2011-01-13 23:03:33 -08:00
if ( ! buf ) return EINA_FALSE ;
2010-07-27 22:23:42 -07:00
memcpy ( buf , data , size ) ;
selections [ in ] . data = buf ;
2005-03-23 02:53:34 -08:00
}
2010-07-27 22:23:42 -07:00
else if ( selections [ in ] . data )
2005-03-23 02:53:34 -08:00
{
2010-07-27 22:23:42 -07:00
free ( selections [ in ] . data ) ;
memset ( & selections [ in ] , 0 , sizeof ( Ecore_X_Selection_Data ) ) ;
2005-03-23 02:53:34 -08:00
}
2010-09-26 10:49:05 -07:00
return EINA_TRUE ;
2011-12-03 11:41:12 -08:00
}
2003-11-23 22:41:43 -08:00
2004-01-16 16:52:22 -08:00
/**
* Claim ownership of the PRIMARY selection and set its data .
* @ param w The window to which this selection belongs
* @ param data The data associated with the selection
* @ param size The size of the data buffer in bytes
2010-07-27 22:23:42 -07:00
* @ return Returns 1 if the ownership of the selection was successfully
2004-01-16 16:52:22 -08:00
* claimed , or 0 if unsuccessful .
*/
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2011-10-20 22:40:59 -07:00
ecore_x_selection_primary_set ( Ecore_X_Window w ,
2011-12-03 12:05:48 -08:00
const void * data ,
int size )
2003-11-23 22:41:43 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-12-04 02:10:29 -08:00
return _ecore_x_selection_set ( w , data , size , ECORE_X_ATOM_SELECTION_PRIMARY ) ;
2011-12-03 11:41:12 -08:00
}
2003-11-23 22:41:43 -08:00
2004-01-16 16:52:22 -08:00
/**
* Release ownership of the primary selection
* @ return Returns 1 if the selection was successfully cleared ,
* or 0 if unsuccessful .
*
*/
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2004-01-10 13:01:18 -08:00
ecore_x_selection_primary_clear ( void )
2003-11-23 22:41:43 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-12-04 02:10:29 -08:00
return _ecore_x_selection_set ( None , NULL , 0 , ECORE_X_ATOM_SELECTION_PRIMARY ) ;
2011-12-03 11:41:12 -08:00
}
2003-11-23 22:41:43 -08:00
2004-01-16 16:52:22 -08:00
/**
* Claim ownership of the SECONDARY selection and set its data .
* @ param w The window to which this selection belongs
* @ param data The data associated with the selection
* @ param size The size of the data buffer in bytes
2010-07-27 22:23:42 -07:00
* @ return Returns 1 if the ownership of the selection was successfully
2004-01-16 16:52:22 -08:00
* claimed , or 0 if unsuccessful .
*/
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2011-10-20 22:40:59 -07:00
ecore_x_selection_secondary_set ( Ecore_X_Window w ,
2011-12-03 12:05:48 -08:00
const void * data ,
int size )
2003-11-23 22:41:43 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2010-07-27 22:23:42 -07:00
return _ecore_x_selection_set ( w ,
data ,
size ,
ECORE_X_ATOM_SELECTION_SECONDARY ) ;
2011-12-03 11:41:12 -08:00
}
2003-11-23 22:41:43 -08:00
2004-01-16 16:52:22 -08:00
/**
* Release ownership of the secondary selection
* @ return Returns 1 if the selection was successfully cleared ,
* or 0 if unsuccessful .
*
*/
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2004-01-10 13:01:18 -08:00
ecore_x_selection_secondary_clear ( void )
2003-11-23 22:41:43 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2010-07-27 22:23:42 -07:00
return _ecore_x_selection_set ( None ,
NULL ,
0 ,
ECORE_X_ATOM_SELECTION_SECONDARY ) ;
2011-12-03 11:41:12 -08:00
}
2003-11-23 22:41:43 -08:00
2005-03-23 02:53:34 -08:00
/**
* Claim ownership of the XDND selection and set its data .
* @ param w The window to which this selection belongs
* @ param data The data associated with the selection
* @ param size The size of the data buffer in bytes
2010-07-27 22:23:42 -07:00
* @ return Returns 1 if the ownership of the selection was successfully
2005-03-23 02:53:34 -08:00
* claimed , or 0 if unsuccessful .
*/
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2011-10-20 22:40:59 -07:00
ecore_x_selection_xdnd_set ( Ecore_X_Window w ,
2011-12-03 12:05:48 -08:00
const void * data ,
int size )
2005-03-23 02:53:34 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2005-03-23 02:53:34 -08:00
return _ecore_x_selection_set ( w , data , size , ECORE_X_ATOM_SELECTION_XDND ) ;
2011-12-03 11:41:12 -08:00
}
2005-03-23 02:53:34 -08:00
/**
* Release ownership of the XDND selection
* @ return Returns 1 if the selection was successfully cleared ,
* or 0 if unsuccessful .
*
*/
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2005-03-23 02:53:34 -08:00
ecore_x_selection_xdnd_clear ( void )
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2005-03-23 02:53:34 -08:00
return _ecore_x_selection_set ( None , NULL , 0 , ECORE_X_ATOM_SELECTION_XDND ) ;
2011-12-03 11:41:12 -08:00
}
2005-03-23 02:53:34 -08:00
2004-01-16 16:52:22 -08:00
/**
* Claim ownership of the CLIPBOARD selection and set its data .
* @ param w The window to which this selection belongs
* @ param data The data associated with the selection
* @ param size The size of the data buffer in bytes
2010-07-27 22:23:42 -07:00
* @ return Returns 1 if the ownership of the selection was successfully
2004-01-16 16:52:22 -08:00
* claimed , or 0 if unsuccessful .
*
* Get the converted data from a previous CLIPBOARD selection
* request . The buffer must be freed when done with .
*/
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2011-10-20 22:40:59 -07:00
ecore_x_selection_clipboard_set ( Ecore_X_Window w ,
2011-12-03 12:05:48 -08:00
const void * data ,
int size )
2003-11-23 22:41:43 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2010-07-27 22:23:42 -07:00
return _ecore_x_selection_set ( w ,
data ,
size ,
ECORE_X_ATOM_SELECTION_CLIPBOARD ) ;
2011-12-03 11:41:12 -08:00
}
2003-11-23 22:41:43 -08:00
2004-01-16 16:52:22 -08:00
/**
* Release ownership of the clipboard selection
* @ return Returns 1 if the selection was successfully cleared ,
* or 0 if unsuccessful .
*
*/
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2004-01-10 13:01:18 -08:00
ecore_x_selection_clipboard_clear ( void )
2003-11-23 22:41:43 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2010-07-27 22:23:42 -07:00
return _ecore_x_selection_set ( None ,
NULL ,
0 ,
ECORE_X_ATOM_SELECTION_CLIPBOARD ) ;
2011-12-03 11:41:12 -08:00
}
2003-11-23 22:41:43 -08:00
2005-04-10 03:20:18 -07:00
Ecore_X_Atom
_ecore_x_selection_target_atom_get ( const char * target )
2004-01-16 16:14:37 -08:00
{
2005-04-10 03:20:18 -07:00
Ecore_X_Atom x_target ;
2005-03-23 02:53:34 -08:00
2004-01-16 16:14:37 -08:00
if ( ! strcmp ( target , ECORE_X_SELECTION_TARGET_TEXT ) )
2011-10-20 22:40:59 -07:00
x_target = ECORE_X_ATOM_TEXT ;
2004-01-16 16:14:37 -08:00
else if ( ! strcmp ( target , ECORE_X_SELECTION_TARGET_COMPOUND_TEXT ) )
2011-10-20 22:40:59 -07:00
x_target = ECORE_X_ATOM_COMPOUND_TEXT ;
2004-01-16 16:14:37 -08:00
else if ( ! strcmp ( target , ECORE_X_SELECTION_TARGET_STRING ) )
2011-10-20 22:40:59 -07:00
x_target = ECORE_X_ATOM_STRING ;
2004-01-16 16:14:37 -08:00
else if ( ! strcmp ( target , ECORE_X_SELECTION_TARGET_UTF8_STRING ) )
2011-10-20 22:40:59 -07:00
x_target = ECORE_X_ATOM_UTF8_STRING ;
2004-01-16 16:14:37 -08:00
else if ( ! strcmp ( target , ECORE_X_SELECTION_TARGET_FILENAME ) )
2011-10-20 22:40:59 -07:00
x_target = ECORE_X_ATOM_FILE_NAME ;
2004-01-16 16:14:37 -08:00
else
2011-10-20 22:40:59 -07:00
x_target = ecore_x_atom_get ( target ) ;
2004-01-16 16:14:37 -08:00
return x_target ;
2011-12-03 11:41:12 -08:00
}
2004-01-16 16:14:37 -08:00
char *
2005-04-10 03:20:18 -07:00
_ecore_x_selection_target_get ( Ecore_X_Atom target )
2004-01-16 16:14:37 -08:00
{
2006-12-18 22:40:30 -08:00
/* FIXME: Should not return mem allocated with strdup or X mixed,
* one should use free to free , the other XFree */
2011-12-03 12:05:48 -08:00
if ( target = = ECORE_X_ATOM_FILE_NAME )
return strdup ( ECORE_X_SELECTION_TARGET_FILENAME ) ;
else if ( target = = ECORE_X_ATOM_STRING )
return strdup ( ECORE_X_SELECTION_TARGET_STRING ) ;
else if ( target = = ECORE_X_ATOM_UTF8_STRING )
return strdup ( ECORE_X_SELECTION_TARGET_UTF8_STRING ) ;
else if ( target = = ECORE_X_ATOM_TEXT )
return strdup ( ECORE_X_SELECTION_TARGET_TEXT ) ;
else
return XGetAtomName ( _ecore_x_disp , target ) ;
2011-12-03 11:41:12 -08:00
}
2004-01-16 16:14:37 -08:00
2010-07-27 22:23:42 -07:00
static void
_ecore_x_selection_request ( Ecore_X_Window w ,
2011-12-03 12:05:48 -08:00
Ecore_X_Atom selection ,
const char * target_str )
2003-11-24 22:10:18 -08:00
{
Ecore_X_Atom target , prop ;
2004-01-16 16:14:37 -08:00
target = _ecore_x_selection_target_atom_get ( target_str ) ;
2005-03-23 02:53:34 -08:00
2004-12-04 02:10:29 -08:00
if ( selection = = ECORE_X_ATOM_SELECTION_PRIMARY )
2011-10-20 22:40:59 -07:00
prop = ECORE_X_ATOM_SELECTION_PROP_PRIMARY ;
2004-12-04 02:10:29 -08:00
else if ( selection = = ECORE_X_ATOM_SELECTION_SECONDARY )
2011-10-20 22:40:59 -07:00
prop = ECORE_X_ATOM_SELECTION_PROP_SECONDARY ;
2005-04-10 03:20:18 -07:00
else if ( selection = = ECORE_X_ATOM_SELECTION_CLIPBOARD )
2011-10-20 22:40:59 -07:00
prop = ECORE_X_ATOM_SELECTION_PROP_CLIPBOARD ;
2005-04-10 03:20:18 -07:00
else
2011-10-20 22:40:59 -07:00
return ;
2003-11-24 22:10:18 -08:00
XConvertSelection ( _ecore_x_disp , selection , target , prop ,
2010-07-27 22:23:42 -07:00
w , CurrentTime ) ;
2011-12-03 11:41:12 -08:00
}
2003-11-24 22:10:18 -08:00
2010-07-27 22:23:42 -07:00
EAPI void
2011-10-20 22:40:59 -07:00
ecore_x_selection_primary_request ( Ecore_X_Window w ,
2011-12-03 12:05:48 -08:00
const char * target )
2003-11-24 22:10:18 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-12-04 02:10:29 -08:00
_ecore_x_selection_request ( w , ECORE_X_ATOM_SELECTION_PRIMARY , target ) ;
2011-12-03 11:41:12 -08:00
}
2003-11-24 22:10:18 -08:00
2010-07-27 22:23:42 -07:00
EAPI void
2011-10-20 22:40:59 -07:00
ecore_x_selection_secondary_request ( Ecore_X_Window w ,
2011-12-03 12:05:48 -08:00
const char * target )
2003-11-24 22:10:18 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-12-04 02:10:29 -08:00
_ecore_x_selection_request ( w , ECORE_X_ATOM_SELECTION_SECONDARY , target ) ;
2011-12-03 11:41:12 -08:00
}
2003-11-24 22:10:18 -08:00
2010-07-27 22:23:42 -07:00
EAPI void
2011-10-20 22:40:59 -07:00
ecore_x_selection_xdnd_request ( Ecore_X_Window w ,
2011-12-03 12:05:48 -08:00
const char * target )
2005-03-23 02:53:34 -08:00
{
Ecore_X_Atom atom ;
2005-03-24 07:45:33 -08:00
Ecore_X_DND_Target * _target ;
2005-03-23 02:53:34 -08:00
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2005-03-24 07:45:33 -08:00
_target = _ecore_x_dnd_target_get ( ) ;
atom = _ecore_x_selection_target_atom_get ( target ) ;
2005-03-23 02:53:34 -08:00
XConvertSelection ( _ecore_x_disp , ECORE_X_ATOM_SELECTION_XDND , atom ,
2010-07-27 22:23:42 -07:00
ECORE_X_ATOM_SELECTION_PROP_XDND , w ,
_target - > time ) ;
2011-12-03 11:41:12 -08:00
}
2005-03-23 02:53:34 -08:00
2010-07-27 22:23:42 -07:00
EAPI void
2011-10-20 22:40:59 -07:00
ecore_x_selection_clipboard_request ( Ecore_X_Window w ,
2011-12-03 12:05:48 -08:00
const char * target )
2004-01-10 13:01:18 -08:00
{
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-12-04 02:10:29 -08:00
_ecore_x_selection_request ( w , ECORE_X_ATOM_SELECTION_CLIPBOARD , target ) ;
2011-12-03 11:41:12 -08:00
}
2004-01-10 13:01:18 -08:00
2006-01-06 12:22:09 -08:00
EAPI void
2011-12-03 12:05:48 -08:00
ecore_x_selection_converter_atom_add ( Ecore_X_Atom target ,
Eina_Bool ( * func ) ( char * target ,
void * data ,
int size ,
void * * data_ret ,
int * size_ret ,
Ecore_X_Atom * ttype ,
int * tsize ) )
2004-01-16 12:41:45 -08:00
{
Ecore_X_Selection_Converter * cnv ;
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-01-16 12:41:45 -08:00
cnv = converters ;
2010-06-09 02:40:37 -07:00
if ( converters )
2005-02-10 04:27:13 -08:00
{
2010-07-27 22:23:42 -07:00
while ( 1 )
{
if ( cnv - > target = = target )
{
cnv - > convert = func ;
return ;
}
if ( cnv - > next )
2011-10-20 22:40:59 -07:00
cnv = cnv - > next ;
2010-07-27 22:23:42 -07:00
else
2011-10-20 22:40:59 -07:00
break ;
2010-07-27 22:23:42 -07:00
}
cnv - > next = calloc ( 1 , sizeof ( Ecore_X_Selection_Converter ) ) ;
2011-01-13 23:03:33 -08:00
if ( ! cnv - > next ) return ;
2010-07-27 22:23:42 -07:00
cnv = cnv - > next ;
2005-03-23 02:53:34 -08:00
}
else
{
2010-07-27 22:23:42 -07:00
converters = calloc ( 1 , sizeof ( Ecore_X_Selection_Converter ) ) ;
2011-01-13 23:03:33 -08:00
if ( ! converters ) return ;
2010-07-27 22:23:42 -07:00
cnv = converters ;
2005-02-10 04:27:13 -08:00
}
2010-07-27 22:23:42 -07:00
2004-01-16 14:34:02 -08:00
cnv - > target = target ;
2004-01-16 12:41:45 -08:00
cnv - > convert = func ;
2011-12-03 11:41:12 -08:00
}
2004-01-16 12:41:45 -08:00
2006-01-06 12:22:09 -08:00
EAPI void
2011-12-03 12:05:48 -08:00
ecore_x_selection_converter_add ( char * target ,
Eina_Bool ( * func ) ( char * target ,
void * data ,
int size ,
void * * data_ret ,
int * size_ret ,
Ecore_X_Atom * ,
int * ) )
2004-01-16 12:41:45 -08:00
{
Ecore_X_Atom x_target ;
2005-03-23 02:53:34 -08:00
2004-01-16 14:34:02 -08:00
if ( ! func | | ! target )
2011-10-20 22:40:59 -07:00
return ;
2004-01-16 12:41:45 -08:00
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-01-16 16:14:37 -08:00
x_target = _ecore_x_selection_target_atom_get ( target ) ;
2005-03-23 02:53:34 -08:00
2004-01-16 12:41:45 -08:00
ecore_x_selection_converter_atom_add ( x_target , func ) ;
2011-12-03 11:41:12 -08:00
}
2004-01-16 12:41:45 -08:00
2006-01-06 12:22:09 -08:00
EAPI void
2004-01-16 14:34:02 -08:00
ecore_x_selection_converter_atom_del ( Ecore_X_Atom target )
2004-01-16 12:41:45 -08:00
{
Ecore_X_Selection_Converter * cnv , * prev_cnv ;
2005-03-23 02:53:34 -08:00
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-01-16 12:41:45 -08:00
prev_cnv = NULL ;
cnv = converters ;
2005-03-23 02:53:34 -08:00
2004-01-16 12:41:45 -08:00
while ( cnv )
2005-02-10 04:27:13 -08:00
{
2010-07-27 22:23:42 -07:00
if ( cnv - > target = = target )
{
if ( prev_cnv )
2011-10-20 22:40:59 -07:00
prev_cnv - > next = cnv - > next ;
2010-07-27 22:23:42 -07:00
else
{
converters = cnv - > next ; /* This was the first converter */
}
free ( cnv ) ;
return ;
}
prev_cnv = cnv ;
cnv = cnv - > next ;
2005-02-10 04:27:13 -08:00
}
2011-12-03 11:41:12 -08:00
}
2004-01-16 12:41:45 -08:00
2006-01-06 12:22:09 -08:00
EAPI void
2004-01-16 14:34:02 -08:00
ecore_x_selection_converter_del ( char * target )
{
Ecore_X_Atom x_target ;
2005-03-23 02:53:34 -08:00
2004-01-16 14:34:02 -08:00
if ( ! target )
2011-10-20 22:40:59 -07:00
return ;
2005-03-23 02:53:34 -08:00
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-01-16 16:14:37 -08:00
x_target = _ecore_x_selection_target_atom_get ( target ) ;
2004-01-16 14:34:02 -08:00
ecore_x_selection_converter_atom_del ( x_target ) ;
2011-12-03 11:41:12 -08:00
}
2004-01-16 14:34:02 -08:00
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2010-07-27 22:23:42 -07:00
ecore_x_selection_notify_send ( Ecore_X_Window requestor ,
2011-12-03 12:05:48 -08:00
Ecore_X_Atom selection ,
Ecore_X_Atom target ,
Ecore_X_Atom property ,
Ecore_X_Time tim )
2006-12-11 15:05:48 -08:00
{
2010-07-27 22:23:42 -07:00
XEvent xev ;
2006-12-11 15:05:48 -08:00
XSelectionEvent xnotify ;
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2006-12-11 15:05:48 -08:00
xnotify . type = SelectionNotify ;
xnotify . display = _ecore_x_disp ;
xnotify . requestor = requestor ;
xnotify . selection = selection ;
xnotify . target = target ;
xnotify . property = property ;
2011-08-18 03:59:24 -07:00
xnotify . time = tim ;
2006-12-11 15:05:48 -08:00
xnotify . send_event = True ;
xnotify . serial = 0 ;
xev . xselection = xnotify ;
2011-10-20 22:40:59 -07:00
return ( XSendEvent ( _ecore_x_disp , requestor , False , 0 , & xev ) > 0 ) ? EINA_TRUE : EINA_FALSE ;
2011-12-03 11:41:12 -08:00
}
2006-12-11 15:05:48 -08:00
2004-01-16 14:34:02 -08:00
/* Locate and run conversion callback for specified selection target */
2010-09-26 10:49:05 -07:00
EAPI Eina_Bool
2011-12-03 12:05:48 -08:00
ecore_x_selection_convert ( Ecore_X_Atom selection ,
Ecore_X_Atom target ,
void * * data_ret ,
int * size ,
2010-07-27 22:23:42 -07:00
Ecore_X_Atom * targtype ,
2011-12-03 12:05:48 -08:00
int * typesize )
2004-01-16 12:41:45 -08:00
{
2005-04-10 03:20:18 -07:00
Ecore_X_Selection_Intern * sel ;
2004-01-16 12:41:45 -08:00
Ecore_X_Selection_Converter * cnv ;
void * data ;
char * tgt_str ;
2010-06-09 02:40:37 -07:00
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-01-16 12:41:45 -08:00
sel = _ecore_x_selection_get ( selection ) ;
2004-01-16 16:14:37 -08:00
tgt_str = _ecore_x_selection_target_get ( target ) ;
2005-03-23 02:53:34 -08:00
2005-03-24 07:45:33 -08:00
for ( cnv = converters ; cnv ; cnv = cnv - > next )
2005-02-10 04:27:13 -08:00
{
2010-07-27 22:23:42 -07:00
if ( cnv - > target = = target )
{
int r ;
r = cnv - > convert ( tgt_str , sel - > data , sel - > length , & data , size ,
targtype , typesize ) ;
free ( tgt_str ) ;
if ( r )
{
* data_ret = data ;
return r ;
}
else
2011-10-20 22:40:59 -07:00
return EINA_FALSE ;
2010-07-27 22:23:42 -07:00
}
2005-03-23 10:33:50 -08:00
}
2004-01-16 16:14:37 -08:00
2007-04-20 19:57:51 -07:00
/* ICCCM says "If the selection cannot be converted into a form based on the target (and parameters, if any), the owner should refuse the SelectionRequest as previously described." */
2010-09-26 10:49:05 -07:00
return EINA_FALSE ;
2007-04-20 19:57:51 -07:00
2010-07-27 22:23:42 -07:00
/* Default, just return the data
2011-12-03 12:05:48 -08:00
* data_ret = malloc ( sel - > length ) ;
2010-07-27 22:23:42 -07:00
memcpy ( * data_ret , sel - > data , sel - > length ) ;
free ( tgt_str ) ;
return 1 ;
*/
2011-12-03 11:41:12 -08:00
}
2004-01-16 12:41:45 -08:00
2004-01-24 19:17:09 -08:00
/* TODO: We need to work out a mechanism for automatic conversion to any requested
* locale using Ecore_Txt functions */
2004-01-16 14:34:02 -08:00
/* Converter for standard non-utf8 text targets */
2012-10-04 16:18:18 -07:00
EAPI Eina_Bool
ecore_x_selection_converter_text ( char * target ,
void * data ,
int size ,
void * * data_ret ,
int * size_ret ,
Ecore_X_Atom * targprop __UNUSED__ ,
int * s __UNUSED__ )
2004-01-16 14:34:02 -08:00
{
XTextProperty text_prop ;
char * mystr ;
XICCEncodingStyle style ;
2005-03-23 02:53:34 -08:00
2004-01-16 14:34:02 -08:00
if ( ! data | | ! size )
2011-10-20 22:40:59 -07:00
return EINA_FALSE ;
2004-01-16 14:34:02 -08:00
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2004-01-16 16:14:37 -08:00
if ( ! strcmp ( target , ECORE_X_SELECTION_TARGET_TEXT ) )
2011-10-20 22:40:59 -07:00
style = XTextStyle ;
2004-01-16 16:14:37 -08:00
else if ( ! strcmp ( target , ECORE_X_SELECTION_TARGET_COMPOUND_TEXT ) )
2011-10-20 22:40:59 -07:00
style = XCompoundTextStyle ;
2004-01-16 16:14:37 -08:00
else if ( ! strcmp ( target , ECORE_X_SELECTION_TARGET_STRING ) )
2011-10-20 22:40:59 -07:00
style = XStringStyle ;
2010-07-27 22:23:42 -07:00
2004-01-21 21:56:14 -08:00
# ifdef X_HAVE_UTF8_STRING
else if ( ! strcmp ( target , ECORE_X_SELECTION_TARGET_UTF8_STRING ) )
2011-10-20 22:40:59 -07:00
style = XUTF8StringStyle ;
2010-08-02 10:47:49 -07:00
# endif /* ifdef X_HAVE_UTF8_STRING */
2004-01-16 14:34:02 -08:00
else
2011-10-20 22:40:59 -07:00
return EINA_FALSE ;
2011-06-16 02:16:03 -07:00
mystr = alloca ( size + 1 ) ;
memcpy ( mystr , data , size ) ;
mystr [ size ] = ' \0 ' ;
2005-03-23 02:53:34 -08:00
2005-04-10 03:20:18 -07:00
# ifdef X_HAVE_UTF8_STRING
2010-07-27 22:23:42 -07:00
if ( Xutf8TextListToTextProperty ( _ecore_x_disp , & mystr , 1 , style ,
& text_prop ) = = Success )
2005-04-10 03:20:18 -07:00
{
2010-07-27 22:23:42 -07:00
int bufsize = strlen ( ( char * ) text_prop . value ) + 1 ;
* data_ret = malloc ( bufsize ) ;
2011-01-13 23:03:33 -08:00
if ( ! * data_ret )
{
return EINA_FALSE ;
}
2010-07-27 22:23:42 -07:00
memcpy ( * data_ret , text_prop . value , bufsize ) ;
* size_ret = bufsize ;
XFree ( text_prop . value ) ;
2010-09-26 10:49:05 -07:00
return EINA_TRUE ;
2005-04-10 03:20:18 -07:00
}
2010-07-27 22:23:42 -07:00
2010-08-02 10:47:49 -07:00
# else /* ifdef X_HAVE_UTF8_STRING */
2010-07-27 22:23:42 -07:00
if ( XmbTextListToTextProperty ( _ecore_x_disp , & mystr , 1 , style ,
& text_prop ) = = Success )
2005-02-10 04:27:13 -08:00
{
2010-07-27 22:23:42 -07:00
int bufsize = strlen ( text_prop . value ) + 1 ;
* data_ret = malloc ( bufsize ) ;
2011-01-13 23:03:33 -08:00
if ( ! * data_ret ) return EINA_FALSE ;
2010-07-27 22:23:42 -07:00
memcpy ( * data_ret , text_prop . value , bufsize ) ;
* size_ret = bufsize ;
XFree ( text_prop . value ) ;
2010-09-26 10:49:05 -07:00
return EINA_TRUE ;
2005-02-10 04:27:13 -08:00
}
2010-07-27 22:23:42 -07:00
2010-08-02 10:47:49 -07:00
# endif /* ifdef X_HAVE_UTF8_STRING */
2004-01-16 14:34:02 -08:00
else
2005-02-10 04:27:13 -08:00
{
2010-09-26 10:49:05 -07:00
return EINA_TRUE ;
2005-02-10 04:27:13 -08:00
}
2011-12-03 11:41:12 -08:00
}
2004-01-16 14:34:02 -08:00
2006-01-06 12:22:09 -08:00
EAPI void
2005-04-10 03:20:18 -07:00
ecore_x_selection_parser_add ( const char * target ,
2010-07-27 22:23:42 -07:00
void * ( * func ) ( const char * target , void * data ,
int size ,
int format ) )
2005-04-10 03:20:18 -07:00
{
Ecore_X_Selection_Parser * prs ;
if ( ! target )
2011-10-20 22:40:59 -07:00
return ;
2005-04-10 03:20:18 -07:00
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2005-04-10 03:20:18 -07:00
prs = parsers ;
2010-06-09 02:40:37 -07:00
if ( parsers )
2005-04-10 03:20:18 -07:00
{
2010-07-27 22:23:42 -07:00
while ( prs - > next )
{
if ( ! strcmp ( prs - > target , target ) )
{
prs - > parse = func ;
return ;
}
prs = prs - > next ;
}
prs - > next = calloc ( 1 , sizeof ( Ecore_X_Selection_Parser ) ) ;
2011-01-13 23:03:33 -08:00
if ( ! prs - > next ) return ;
2010-07-27 22:23:42 -07:00
prs = prs - > next ;
2005-04-10 03:20:18 -07:00
}
else
{
2010-07-27 22:23:42 -07:00
parsers = calloc ( 1 , sizeof ( Ecore_X_Selection_Parser ) ) ;
2011-01-13 23:03:33 -08:00
if ( ! parsers ) return ;
2010-07-27 22:23:42 -07:00
prs = parsers ;
2005-04-10 03:20:18 -07:00
}
2010-07-27 22:23:42 -07:00
2005-04-10 03:20:18 -07:00
prs - > target = strdup ( target ) ;
prs - > parse = func ;
2011-12-03 11:41:12 -08:00
}
2005-04-10 03:20:18 -07:00
2006-01-06 12:22:09 -08:00
EAPI void
2005-04-10 03:20:18 -07:00
ecore_x_selection_parser_del ( const char * target )
{
Ecore_X_Selection_Parser * prs , * prev_prs ;
if ( ! target )
2011-10-20 22:40:59 -07:00
return ;
2005-04-10 03:20:18 -07:00
2010-02-25 04:19:02 -08:00
LOGFN ( __FILE__ , __LINE__ , __FUNCTION__ ) ;
2005-04-10 03:20:18 -07:00
prev_prs = NULL ;
prs = parsers ;
while ( prs )
{
2010-07-27 22:23:42 -07:00
if ( ! strcmp ( prs - > target , target ) )
{
if ( prev_prs )
2011-10-20 22:40:59 -07:00
prev_prs - > next = prs - > next ;
2010-07-27 22:23:42 -07:00
else
{
parsers = prs - > next ; /* This was the first parser */
}
free ( prs - > target ) ;
free ( prs ) ;
return ;
}
prev_prs = prs ;
prs = prs - > next ;
2005-04-10 03:20:18 -07:00
}
2011-12-03 11:41:12 -08:00
}
2005-04-10 03:20:18 -07:00
2011-07-21 07:05:27 -07:00
/**
* Change the owner and last - change time for the specified selection .
* @ param win The owner of the specified atom .
* @ param atom The selection atom
2012-01-17 03:37:35 -08:00
* @ param tim Specifies the time
2011-07-21 07:05:27 -07:00
* @ since 1.1 .0
*/
2011-10-20 22:40:59 -07:00
EAPI void
ecore_x_selection_owner_set ( Ecore_X_Window win ,
2011-12-03 12:05:48 -08:00
Ecore_X_Atom atom ,
Ecore_X_Time tim )
2011-07-21 05:09:33 -07:00
{
2011-08-18 03:59:24 -07:00
XSetSelectionOwner ( _ecore_x_disp , atom , win , tim ) ;
2011-07-21 05:09:33 -07:00
}
2011-07-21 07:05:27 -07:00
/**
* Return the window that currently owns the specified selection .
2011-10-20 22:40:59 -07:00
*
2011-07-21 07:05:27 -07:00
* @ param atom The specified selection atom .
2011-10-20 22:40:59 -07:00
*
2011-07-21 07:05:27 -07:00
* @ return The window that currently owns the specified selection .
* @ since 1.1 .0
*/
2011-10-20 22:40:59 -07:00
EAPI Ecore_X_Window
ecore_x_selection_owner_get ( Ecore_X_Atom atom )
2011-07-21 05:09:33 -07:00
{
return XGetSelectionOwner ( _ecore_x_disp , atom ) ;
}
2005-04-10 03:20:18 -07:00
/* Locate and run conversion callback for specified selection target */
void *
2011-10-20 22:40:59 -07:00
_ecore_x_selection_parse ( const char * target ,
2011-12-03 12:05:48 -08:00
void * data ,
int size ,
int format )
2005-04-10 03:20:18 -07:00
{
Ecore_X_Selection_Parser * prs ;
Ecore_X_Selection_Data * sel ;
2010-06-09 02:40:37 -07:00
2005-04-10 03:20:18 -07:00
for ( prs = parsers ; prs ; prs = prs - > next )
{
2010-07-27 22:23:42 -07:00
if ( ! strcmp ( prs - > target , target ) )
{
sel = prs - > parse ( target , data , size , format ) ;
2011-10-20 22:40:59 -07:00
if ( sel ) return sel ;
2010-07-27 22:23:42 -07:00
}
2005-04-10 03:20:18 -07:00
}
/* Default, just return the data */
sel = calloc ( 1 , sizeof ( Ecore_X_Selection_Data ) ) ;
2011-01-13 23:03:33 -08:00
if ( ! sel ) return NULL ;
2005-04-10 03:20:18 -07:00
sel - > free = _ecore_x_selection_data_default_free ;
sel - > length = size ;
2006-09-28 22:49:14 -07:00
sel - > format = format ;
2005-04-10 03:20:18 -07:00
sel - > data = data ;
return sel ;
2011-12-03 11:41:12 -08:00
}
2005-04-10 03:20:18 -07:00
static int
_ecore_x_selection_data_default_free ( void * data )
{
Ecore_X_Selection_Data * sel ;
sel = data ;
2010-08-02 10:47:49 -07:00
free ( sel - > data ) ;
free ( sel ) ;
2005-04-10 03:20:18 -07:00
return 1 ;
2011-12-03 11:41:12 -08:00
}
2005-04-10 03:20:18 -07:00
static void *
2010-07-27 22:23:42 -07:00
_ecore_x_selection_parser_files ( const char * target ,
2011-12-03 12:05:48 -08:00
void * _data ,
int size ,
int format __UNUSED__ )
2005-04-10 03:20:18 -07:00
{
Ecore_X_Selection_Data_Files * sel ;
2011-01-13 23:03:33 -08:00
char * t , * data = _data ;
2005-04-10 03:20:18 -07:00
int i , is ;
char * tmp ;
2011-01-13 23:03:33 -08:00
char * * t2 ;
2005-04-10 03:20:18 -07:00
2005-10-07 11:18:17 -07:00
if ( strcmp ( target , " text/uri-list " ) & &
strcmp ( target , " _NETSCAPE_URL " ) )
2011-10-20 22:40:59 -07:00
return NULL ;
2005-04-10 03:20:18 -07:00
sel = calloc ( 1 , sizeof ( Ecore_X_Selection_Data_Files ) ) ;
2011-01-13 23:03:33 -08:00
if ( ! sel ) return NULL ;
2005-04-10 03:20:18 -07:00
ECORE_X_SELECTION_DATA ( sel ) - > free = _ecore_x_selection_data_files_free ;
2012-10-10 02:17:21 -07:00
if ( data & & data [ size - 1 ] )
2005-04-10 03:20:18 -07:00
{
2010-07-27 22:23:42 -07:00
/* Isn't nul terminated */
2011-12-03 12:05:48 -08:00
size + + ;
t = realloc ( data , size ) ;
if ( ! t )
{
free ( sel ) ;
return NULL ;
}
data = t ;
data [ size - 1 ] = 0 ;
2005-04-10 03:20:18 -07:00
}
tmp = malloc ( size ) ;
2011-01-13 23:03:33 -08:00
if ( ! tmp )
{
free ( sel ) ;
return NULL ;
}
2005-04-10 03:20:18 -07:00
i = 0 ;
is = 0 ;
while ( ( is < size ) & & ( data [ is ] ) )
{
2010-07-27 22:23:42 -07:00
if ( ( i = = 0 ) & & ( data [ is ] = = ' # ' ) )
2011-10-20 22:40:59 -07:00
for ( ; ( ( data [ is ] ) & & ( data [ is ] ! = ' \n ' ) ) ; is + + ) ;
2010-07-27 22:23:42 -07:00
else
{
if ( ( data [ is ] ! = ' \r ' ) & &
( data [ is ] ! = ' \n ' ) )
2011-10-20 22:40:59 -07:00
tmp [ i + + ] = data [ is + + ] ;
2010-07-27 22:23:42 -07:00
else
{
2011-12-03 12:05:48 -08:00
while ( ( data [ is ] = = ' \r ' ) | | ( data [ is ] = = ' \n ' ) )
is + + ;
2010-07-27 22:23:42 -07:00
tmp [ i ] = 0 ;
sel - > num_files + + ;
2011-01-13 23:03:33 -08:00
t2 = realloc ( sel - > files , sel - > num_files * sizeof ( char * ) ) ;
if ( t2 )
{
sel - > files = t2 ;
sel - > files [ sel - > num_files - 1 ] = strdup ( tmp ) ;
}
2010-07-27 22:23:42 -07:00
tmp [ 0 ] = 0 ;
i = 0 ;
}
}
2005-04-10 03:20:18 -07:00
}
if ( i > 0 )
{
2010-07-27 22:23:42 -07:00
tmp [ i ] = 0 ;
sel - > num_files + + ;
2011-01-13 23:03:33 -08:00
t2 = realloc ( sel - > files , sel - > num_files * sizeof ( char * ) ) ;
if ( t2 )
{
sel - > files = t2 ;
sel - > files [ sel - > num_files - 1 ] = strdup ( tmp ) ;
}
2005-04-10 03:20:18 -07:00
}
2010-07-27 22:23:42 -07:00
2005-04-10 03:20:18 -07:00
free ( tmp ) ;
free ( data ) ;
2006-07-14 02:37:11 -07:00
ECORE_X_SELECTION_DATA ( sel ) - > content = ECORE_X_SELECTION_CONTENT_FILES ;
ECORE_X_SELECTION_DATA ( sel ) - > length = sel - > num_files ;
2005-04-10 03:20:18 -07:00
return ECORE_X_SELECTION_DATA ( sel ) ;
2011-12-03 11:41:12 -08:00
}
2005-04-10 03:20:18 -07:00
static int
_ecore_x_selection_data_files_free ( void * data )
{
Ecore_X_Selection_Data_Files * sel ;
int i ;
2004-10-23 20:58:11 -07:00
2005-04-10 03:20:18 -07:00
sel = data ;
if ( sel - > files )
{
2010-07-27 22:23:42 -07:00
for ( i = 0 ; i < sel - > num_files ; i + + )
2011-10-20 22:40:59 -07:00
free ( sel - > files [ i ] ) ;
2010-08-02 10:47:49 -07:00
free ( sel - > files ) ;
2005-04-10 03:20:18 -07:00
}
2010-07-27 22:23:42 -07:00
2010-08-02 10:47:49 -07:00
free ( sel ) ;
2005-04-10 03:20:18 -07:00
return 0 ;
2011-12-03 11:41:12 -08:00
}
2005-04-10 03:20:18 -07:00
static void *
2010-07-27 22:23:42 -07:00
_ecore_x_selection_parser_text ( const char * target __UNUSED__ ,
2011-12-03 12:05:48 -08:00
void * _data ,
int size ,
int format __UNUSED__ )
2005-04-10 03:20:18 -07:00
{
Ecore_X_Selection_Data_Text * sel ;
2010-09-18 20:29:30 -07:00
unsigned char * data = _data ;
2011-01-13 23:03:33 -08:00
void * t ;
2005-04-10 03:20:18 -07:00
sel = calloc ( 1 , sizeof ( Ecore_X_Selection_Data_Text ) ) ;
2011-01-13 23:03:33 -08:00
if ( ! sel ) return NULL ;
2012-10-10 02:17:21 -07:00
if ( data & & data [ size - 1 ] )
2005-04-10 03:20:18 -07:00
{
2010-07-27 22:23:42 -07:00
/* Isn't nul terminated */
2011-12-03 12:05:48 -08:00
size + + ;
t = realloc ( data , size ) ;
if ( ! t )
{
free ( sel ) ;
return NULL ;
}
data = t ;
data [ size - 1 ] = 0 ;
2005-04-10 03:20:18 -07:00
}
2005-05-16 05:59:26 -07:00
sel - > text = ( char * ) data ;
2006-07-14 02:37:11 -07:00
ECORE_X_SELECTION_DATA ( sel ) - > length = size ;
ECORE_X_SELECTION_DATA ( sel ) - > content = ECORE_X_SELECTION_CONTENT_TEXT ;
2010-09-06 23:56:16 -07:00
ECORE_X_SELECTION_DATA ( sel ) - > data = data ;
2005-04-10 03:20:18 -07:00
ECORE_X_SELECTION_DATA ( sel ) - > free = _ecore_x_selection_data_text_free ;
return sel ;
2011-12-03 11:41:12 -08:00
}
2005-04-10 03:20:18 -07:00
static int
_ecore_x_selection_data_text_free ( void * data )
{
Ecore_X_Selection_Data_Text * sel ;
sel = data ;
free ( sel - > text ) ;
free ( sel ) ;
return 1 ;
2011-12-03 11:41:12 -08:00
}
2005-04-10 03:20:18 -07:00
static void *
2010-07-27 22:23:42 -07:00
_ecore_x_selection_parser_targets ( const char * target __UNUSED__ ,
2011-12-03 12:05:48 -08:00
void * data ,
int size ,
int format __UNUSED__ )
2005-04-10 03:20:18 -07:00
{
Ecore_X_Selection_Data_Targets * sel ;
unsigned long * targets ;
int i ;
sel = calloc ( 1 , sizeof ( Ecore_X_Selection_Data_Targets ) ) ;
2011-01-13 23:03:33 -08:00
if ( ! sel ) return NULL ;
2005-04-10 03:20:18 -07:00
targets = ( unsigned long * ) data ;
sel - > num_targets = size - 2 ;
sel - > targets = malloc ( ( size - 2 ) * sizeof ( char * ) ) ;
2011-01-13 23:03:33 -08:00
if ( ! sel - > targets )
{
free ( sel ) ;
return NULL ;
}
2005-04-10 03:20:18 -07:00
for ( i = 2 ; i < size ; i + + )
2011-10-20 22:40:59 -07:00
sel - > targets [ i - 2 ] = XGetAtomName ( _ecore_x_disp , targets [ i ] ) ;
2010-06-09 02:40:37 -07:00
2005-04-10 03:20:18 -07:00
ECORE_X_SELECTION_DATA ( sel ) - > free = _ecore_x_selection_data_targets_free ;
2006-07-14 02:37:11 -07:00
ECORE_X_SELECTION_DATA ( sel ) - > content = ECORE_X_SELECTION_CONTENT_TARGETS ;
ECORE_X_SELECTION_DATA ( sel ) - > length = size ;
2010-06-23 01:01:43 -07:00
ECORE_X_SELECTION_DATA ( sel ) - > data = data ;
2005-04-10 03:20:18 -07:00
return sel ;
2011-12-03 11:41:12 -08:00
}
2005-04-10 03:20:18 -07:00
static int
_ecore_x_selection_data_targets_free ( void * data )
{
Ecore_X_Selection_Data_Targets * sel ;
int i ;
sel = data ;
if ( sel - > targets )
{
2010-07-27 22:23:42 -07:00
for ( i = 0 ; i < sel - > num_targets ; i + + )
2011-10-20 22:40:59 -07:00
XFree ( sel - > targets [ i ] ) ;
2010-07-27 22:23:42 -07:00
free ( sel - > targets ) ;
2005-04-10 03:20:18 -07:00
}
2010-07-27 22:23:42 -07:00
2010-08-02 10:47:49 -07:00
free ( ECORE_X_SELECTION_DATA ( sel ) - > data ) ;
free ( sel ) ;
2005-04-10 03:20:18 -07:00
return 1 ;
2011-12-03 11:41:12 -08:00
}
2010-08-02 10:47:49 -07:00