forked from enlightenment/efl
Selections:
- Framework for conversion functions complete - Added default function for TEXT, COMPOUND_TEXT and STRING SVN revision: 8508
This commit is contained in:
parent
2c69b06922
commit
b26938f6c3
|
@ -607,9 +607,12 @@ void ecore_x_selection_secondary_request_data_get(void **buf, int *l
|
|||
void ecore_x_selection_clipboard_request_data_get(void **buf, int *len);
|
||||
Ecore_X_Selection_Target
|
||||
ecore_x_selection_target_get(Ecore_X_Atom target);
|
||||
char * ecore_x_selection_convert_to_string(char *data);
|
||||
char * ecore_x_selection_convert_to_utf8_string(char *data);
|
||||
void ecore_x_selection_converter_add(char *target, int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret));
|
||||
void ecore_x_selection_converter_atom_add(Ecore_X_Atom target, int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret));
|
||||
void ecore_x_selection_converter_del(char *target);
|
||||
void ecore_x_selection_converter_atom_del(Ecore_X_Atom target);
|
||||
|
||||
|
||||
Ecore_X_Window ecore_x_window_new(Ecore_X_Window parent, int x, int y, int w, int h);
|
||||
Ecore_X_Window ecore_x_window_override_new(Ecore_X_Window parent, int x, int y, int w, int h);
|
||||
Ecore_X_Window ecore_x_window_input_new(Ecore_X_Window parent, int x, int y, int w, int h);
|
||||
|
|
|
@ -107,6 +107,7 @@ Atom _ecore_x_atom_file_name = 0;
|
|||
Atom _ecore_x_atom_string = 0;
|
||||
Atom _ecore_x_atom_text = 0;
|
||||
Atom _ecore_x_atom_utf8_string = 0;
|
||||
Atom _ecore_x_atom_compound_text = 0;
|
||||
|
||||
Atom _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_NUM] = {0};
|
||||
|
||||
|
@ -361,7 +362,8 @@ ecore_x_init(const char *name)
|
|||
_ecore_x_atom_net_wm_state_below = XInternAtom(_ecore_x_disp, "_NET_WM_STATE_BELOW", False);
|
||||
_ecore_x_atom_net_wm_window_opacity = XInternAtom(_ecore_x_disp, "_NET_WM_WINDOW_OPACITY", False);
|
||||
|
||||
_ecore_x_atom_utf8_string = XInternAtom(_ecore_x_disp, "UTF8_STRING", False);
|
||||
_ecore_x_atom_compound_text = XInternAtom(_ecore_x_disp, "COMPOUND_TEXT", False);
|
||||
_ecore_x_atom_utf8_string = XInternAtom(_ecore_x_disp, "UTF8_STRING", False);
|
||||
_ecore_x_atom_file_name = XInternAtom(_ecore_x_disp, "FILE_NAME", False);
|
||||
_ecore_x_atom_string = XInternAtom(_ecore_x_disp, "STRING", False);
|
||||
_ecore_x_atom_text = XInternAtom(_ecore_x_disp, "TEXT", False);
|
||||
|
|
|
@ -916,12 +916,12 @@ _ecore_x_event_handle_selection_request(XEvent *xevent)
|
|||
{
|
||||
/* TODO: Use predefined/user-definable callback functions
|
||||
* to convert selections */
|
||||
if (xnotify.target == _ecore_x_atom_string)
|
||||
data = ecore_x_selection_convert_to_string(sd->data);
|
||||
else if (xnotify.target == _ecore_x_atom_utf8_string)
|
||||
data = ecore_x_selection_convert_to_utf8_string(sd->data);
|
||||
else
|
||||
data = sd->data;
|
||||
if (_ecore_x_selection_convert(xnotify.selection, xnotify.target,
|
||||
&data) == -1)
|
||||
{
|
||||
data = malloc(sd->length);
|
||||
memcpy(data, sd->data, sd->length);
|
||||
}
|
||||
|
||||
/* FIXME: This does not properly handle large data transfers */
|
||||
ecore_x_window_prop_property_set(xevent->xselectionrequest.requestor,
|
||||
|
@ -929,6 +929,7 @@ _ecore_x_event_handle_selection_request(XEvent *xevent)
|
|||
xevent->xselectionrequest.target,
|
||||
8, data, sd->length);
|
||||
xnotify.property = xevent->xselectionrequest.property;
|
||||
free(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -138,6 +138,7 @@ extern Atom _ecore_x_atom_utf8_string;
|
|||
extern Atom _ecore_x_atom_file_name;
|
||||
extern Atom _ecore_x_atom_string;
|
||||
extern Atom _ecore_x_atom_text;
|
||||
extern Atom _ecore_x_atom_compound_text;
|
||||
|
||||
extern Atom _ecore_x_atom_selection_primary;
|
||||
extern Atom _ecore_x_atom_selection_secondary;
|
||||
|
|
|
@ -8,13 +8,23 @@ static Ecore_X_Selection_Data selections[3];
|
|||
static Ecore_X_Selection_Data request_data[3];
|
||||
static Ecore_X_Selection_Converter *converters;
|
||||
|
||||
static int _ecore_x_selection_converter_text(char *target, void *data, int size, void **data_ret, int *size_ret);
|
||||
|
||||
void
|
||||
_ecore_x_selection_data_initialize(void)
|
||||
{
|
||||
memset(selections, 0, sizeof(selections));
|
||||
memset(request_data, 0, sizeof(request_data));
|
||||
converters = calloc(1, sizeof(Ecore_X_Selection_Converter));
|
||||
/* TODO: Write predefined converters */
|
||||
|
||||
/* Initialize converters */
|
||||
converters = NULL;
|
||||
ecore_x_selection_converter_atom_add(_ecore_x_atom_text,
|
||||
_ecore_x_selection_converter_text);
|
||||
ecore_x_selection_converter_atom_add(_ecore_x_atom_compound_text,
|
||||
_ecore_x_selection_converter_text);
|
||||
ecore_x_selection_converter_atom_add(_ecore_x_atom_string,
|
||||
_ecore_x_selection_converter_text);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -224,20 +234,6 @@ ecore_x_selection_clipboard_request(Ecore_X_Window w, Ecore_X_Selection_Target t
|
|||
_ecore_x_selection_request(w, _ecore_x_atom_selection_clipboard, t);
|
||||
}
|
||||
|
||||
char *
|
||||
ecore_x_selection_convert_to_string(char *data)
|
||||
{
|
||||
/* FIXME: Do something */
|
||||
return data;
|
||||
}
|
||||
|
||||
char *
|
||||
ecore_x_selection_convert_to_utf8_string(char *data)
|
||||
{
|
||||
/* FIXME: Do something */
|
||||
return data;
|
||||
}
|
||||
|
||||
Ecore_X_Selection_Target
|
||||
ecore_x_selection_target_get(Ecore_X_Atom target)
|
||||
{
|
||||
|
@ -254,7 +250,7 @@ ecore_x_selection_target_get(Ecore_X_Atom target)
|
|||
}
|
||||
|
||||
void
|
||||
ecore_x_selection_converter_atom_add(Ecore_X_Atom atom,
|
||||
ecore_x_selection_converter_atom_add(Ecore_X_Atom target,
|
||||
int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret))
|
||||
{
|
||||
Ecore_X_Selection_Converter *cnv;
|
||||
|
@ -264,7 +260,7 @@ ecore_x_selection_converter_atom_add(Ecore_X_Atom atom,
|
|||
{
|
||||
while (1)
|
||||
{
|
||||
if (cnv->target == atom)
|
||||
if (cnv->target == target)
|
||||
{
|
||||
cnv->convert = func;
|
||||
return;
|
||||
|
@ -281,7 +277,7 @@ ecore_x_selection_converter_atom_add(Ecore_X_Atom atom,
|
|||
converters = calloc(1, sizeof(Ecore_X_Selection_Converter));
|
||||
cnv = converters;
|
||||
}
|
||||
cnv->target = atom;
|
||||
cnv->target = target;
|
||||
cnv->convert = func;
|
||||
}
|
||||
|
||||
|
@ -293,14 +289,16 @@ ecore_x_selection_converter_add(char *target,
|
|||
Ecore_X_Atom x_target;
|
||||
char *atom_name;
|
||||
|
||||
if (!func)
|
||||
if (!func || !target)
|
||||
return;
|
||||
|
||||
/* FIXME: Some of these are just made up because I can't find
|
||||
* standard "mime type" strings for them at the moment" */
|
||||
if (!target || !strcmp(target, "TEXT"))
|
||||
if (!strcmp(target, "TEXT"))
|
||||
x_target = _ecore_x_atom_text;
|
||||
if (!strcmp(target, "STRING"))
|
||||
else if (!strcmp(target, "COMPOUND_TEXT"))
|
||||
x_target = _ecore_x_atom_compound_text;
|
||||
else if (!strcmp(target, "STRING"))
|
||||
x_target = _ecore_x_atom_string;
|
||||
else if (!strcmp(target, "UTF8_STRING"))
|
||||
x_target = _ecore_x_atom_utf8_string;
|
||||
|
@ -317,7 +315,7 @@ ecore_x_selection_converter_add(char *target,
|
|||
}
|
||||
|
||||
void
|
||||
ecore_x_selection_converter_atom_del(Ecore_X_Atom atom)
|
||||
ecore_x_selection_converter_atom_del(Ecore_X_Atom target)
|
||||
{
|
||||
Ecore_X_Selection_Converter *cnv, *prev_cnv;
|
||||
|
||||
|
@ -326,13 +324,23 @@ ecore_x_selection_converter_atom_del(Ecore_X_Atom atom)
|
|||
|
||||
while (cnv)
|
||||
{
|
||||
if (cnv->target == atom)
|
||||
if (cnv->target == target)
|
||||
{
|
||||
if(prev_cnv)
|
||||
prev_cnv->next = cnv->next;
|
||||
if (target == _ecore_x_atom_text ||
|
||||
target == _ecore_x_atom_compound_text ||
|
||||
target == _ecore_x_atom_string)
|
||||
{
|
||||
cnv->convert = _ecore_x_selection_converter_text;
|
||||
}
|
||||
else
|
||||
converters = NULL; /* This was the only converter */
|
||||
free(cnv);
|
||||
{
|
||||
if(prev_cnv)
|
||||
prev_cnv->next = cnv->next;
|
||||
else
|
||||
converters = NULL; /* This was the only converter */
|
||||
free(cnv);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
prev_cnv = cnv;
|
||||
|
@ -340,6 +348,37 @@ ecore_x_selection_converter_atom_del(Ecore_X_Atom atom)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
ecore_x_selection_converter_del(char *target)
|
||||
{
|
||||
Ecore_X_Atom x_target;
|
||||
char *atom_name;
|
||||
|
||||
if (!target)
|
||||
return;
|
||||
|
||||
if (!strcmp(target, "TEXT"))
|
||||
x_target = _ecore_x_atom_text;
|
||||
else if (!strcmp(target, "COMPOUND_TEXT"))
|
||||
x_target = _ecore_x_atom_compound_text;
|
||||
else if (!strcmp(target, "STRING"))
|
||||
x_target = _ecore_x_atom_string;
|
||||
else if (!strcmp(target, "UTF8_STRING"))
|
||||
x_target = _ecore_x_atom_utf8_string;
|
||||
else if (!strcmp(target, "FILENAME"))
|
||||
x_target = _ecore_x_atom_file_name;
|
||||
else
|
||||
{
|
||||
atom_name = malloc(strlen(target) + 4);
|
||||
sprintf(atom_name, "_E_%s", target);
|
||||
x_target = XInternAtom(_ecore_x_disp, atom_name, False);
|
||||
}
|
||||
|
||||
ecore_x_selection_converter_atom_del(x_target);
|
||||
}
|
||||
|
||||
|
||||
/* Locate and run conversion callback for specified selection target */
|
||||
int
|
||||
_ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **data_ret)
|
||||
{
|
||||
|
@ -350,8 +389,11 @@ _ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **d
|
|||
char *tgt_str;
|
||||
|
||||
sel = _ecore_x_selection_get(selection);
|
||||
/* COMPOUND_TEXT will be the default format for text requests */
|
||||
if (target == _ecore_x_atom_text)
|
||||
tgt_str = strdup("TEXT");
|
||||
else if (target == _ecore_x_atom_compound_text)
|
||||
tgt_str = strdup("COMPOUND_TEXT");
|
||||
else if (target == _ecore_x_atom_string)
|
||||
tgt_str = strdup("STRING");
|
||||
else if (target == _ecore_x_atom_utf8_string)
|
||||
|
@ -384,3 +426,37 @@ _ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **d
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* Converter for standard non-utf8 text targets */
|
||||
static int _ecore_x_selection_converter_text(char *target, void *data, int size, void **data_ret, int *size_ret)
|
||||
{
|
||||
XTextProperty text_prop;
|
||||
char *mystr;
|
||||
XICCEncodingStyle style;
|
||||
|
||||
if (!data || !size)
|
||||
return 0;
|
||||
|
||||
if (!strcmp(target, "TEXT"))
|
||||
style = XTextStyle;
|
||||
else if (!strcmp(target, "COMPOUND_TEXT"))
|
||||
style = XCompoundTextStyle;
|
||||
else if (!strcmp(target, "STRING"))
|
||||
style = XStringStyle;
|
||||
else
|
||||
return 0;
|
||||
|
||||
mystr = strdup(data);
|
||||
|
||||
if (XmbTextListToTextProperty(_ecore_x_disp, &mystr, 1, style, &text_prop) == Success)
|
||||
{
|
||||
int bufsize = strlen(text_prop.value) + 1;
|
||||
*data_ret = malloc(bufsize);
|
||||
memcpy(*data_ret, text_prop.value, bufsize);
|
||||
*size_ret = bufsize;
|
||||
XFree(text_prop.value);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue