Enlightenment CVS committal Author : xcomputerman Project : e17 Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore_x Modified Files: Ecore_X.h ecore_x_events.c ecore_x_private.h ecore_x_selection.c Log Message: Update request API to use strings for target types instead of enums =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/Ecore_X.h,v retrieving revision 1.24 retrieving revision 1.25 diff -u -3 -r1.24 -r1.25 --- Ecore_X.h 16 Jan 2004 22:34:02 -0000 1.24 +++ Ecore_X.h 17 Jan 2004 00:14:37 -0000 1.25 @@ -22,12 +22,11 @@ typedef void Ecore_X_Reply; #endif -typedef enum _Ecore_X_Selection_Target { - ECORE_X_SELECTION_TARGET_FILENAME, - ECORE_X_SELECTION_TARGET_STRING, - ECORE_X_SELECTION_TARGET_UTF8_STRING, - ECORE_X_SELECTION_TARGET_TEXT -} Ecore_X_Selection_Target; +#define ECORE_X_SELECTION_TARGET_TEXT "TEXT" +#define ECORE_X_SELECTION_TARGET_COMPOUND_TEXT "COMPOUND_TEXT" +#define ECORE_X_SELECTION_TARGET_STRING "STRING" +#define ECORE_X_SELECTION_TARGET_UTF8_STRING "UTF8_STRING" +#define ECORE_X_SELECTION_TARGET_FILENAME "FILENAME" typedef enum _Ecore_X_Selection { ECORE_X_SELECTION_PRIMARY, @@ -376,7 +375,7 @@ Ecore_X_Window win; Ecore_X_Time time; Ecore_X_Selection selection; - Ecore_X_Selection_Target target; + char *target; }; struct _Ecore_X_Event_Client_Message @@ -599,14 +598,12 @@ int ecore_x_selection_secondary_clear(void); int ecore_x_selection_clipboard_set(Ecore_X_Window w, char *data, int len); int ecore_x_selection_clipboard_clear(void); -void ecore_x_selection_primary_request(Ecore_X_Window w, Ecore_X_Selection_Target t); -void ecore_x_selection_secondary_request(Ecore_X_Window w, Ecore_X_Selection_Target t); -void ecore_x_selection_clipboard_request(Ecore_X_Window w, Ecore_X_Selection_Target t); +void ecore_x_selection_primary_request(Ecore_X_Window w, char *target); +void ecore_x_selection_secondary_request(Ecore_X_Window w, char *target); +void ecore_x_selection_clipboard_request(Ecore_X_Window w, char *target); void ecore_x_selection_primary_request_data_get(void **buf, int *len); void ecore_x_selection_secondary_request_data_get(void **buf, int *len); 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); 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); =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_events.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -3 -r1.17 -r1.18 --- ecore_x_events.c 16 Jan 2004 22:34:02 -0000 1.17 +++ ecore_x_events.c 17 Jan 2004 00:14:37 -0000 1.18 @@ -119,6 +119,16 @@ } static void +_ecore_x_event_free_selection_notify(void *data, void *ev) +{ + Ecore_X_Event_Selection_Notify *e; + + e = ev; + if (e->target) free(e->target); + free(e); +} + +static void _ecore_x_event_free_generic(void *data, void *ev) { free(ev); @@ -900,7 +910,7 @@ Ecore_X_Selection_Data *sd; XSelectionEvent xnotify; XEvent *xev; - char *data; + void *data; xev = calloc(1, sizeof(XEvent)); @@ -914,8 +924,6 @@ if((sd = _ecore_x_selection_get(xnotify.selection)) && (sd->win == xevent->xselectionrequest.owner)) { - /* TODO: Use predefined/user-definable callback functions - * to convert selections */ if (_ecore_x_selection_convert(xnotify.selection, xnotify.target, &data) == -1) { @@ -956,7 +964,7 @@ e = calloc(1, sizeof(Ecore_X_Event_Selection_Notify)); e->win = xevent->xselection.requestor; e->time = xevent->xselection.time; - e->target = ecore_x_selection_target_get(xevent->xselection.target); + e->target = _ecore_x_selection_target_get(xevent->xselection.target); selection = xevent->xselection.selection; if (selection == _ecore_x_atom_selection_primary) e->selection = ECORE_X_SELECTION_PRIMARY; @@ -982,7 +990,7 @@ sel_data.data = data; sel_data.length = num_ret; _ecore_x_selection_request_data_set(sel_data); - ecore_event_add(ECORE_X_EVENT_SELECTION_NOTIFY, e, _ecore_x_event_free_generic, NULL); + ecore_event_add(ECORE_X_EVENT_SELECTION_NOTIFY, e, _ecore_x_event_free_selection_notify, NULL); } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_private.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -3 -r1.17 -r1.18 --- ecore_x_private.h 16 Jan 2004 22:34:02 -0000 1.17 +++ ecore_x_private.h 17 Jan 2004 00:14:37 -0000 1.18 @@ -183,8 +183,11 @@ void _ecore_x_event_handle_shape_change(XEvent *xevent); void _ecore_x_selection_data_initialize(void); +Atom _ecore_x_selection_target_atom_get(char *target); +char * _ecore_x_selection_target_get(Atom target); void _ecore_x_selection_request_data_set(Ecore_X_Selection_Data data); Ecore_X_Selection_Data * _ecore_x_selection_get(Atom selection); int _ecore_x_selection_set(Window w, char *data, int len, Atom selection); +int _ecore_x_selection_convert(Atom selection, Atom target, void **data_ret); #endif =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_selection.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- ecore_x_selection.c 16 Jan 2004 22:34:02 -0000 1.5 +++ ecore_x_selection.c 17 Jan 2004 00:14:37 -0000 1.6 @@ -183,27 +183,54 @@ return _ecore_x_selection_set(None, NULL, 0, _ecore_x_atom_selection_clipboard); } +Atom +_ecore_x_selection_target_atom_get(char *target) +{ + Atom x_target; + + if (!strcmp(target, ECORE_X_SELECTION_TARGET_TEXT)) + x_target = _ecore_x_atom_text; + else if (!strcmp(target, ECORE_X_SELECTION_TARGET_COMPOUND_TEXT)) + x_target = _ecore_x_atom_compound_text; + else if (!strcmp(target, ECORE_X_SELECTION_TARGET_STRING)) + x_target = _ecore_x_atom_string; + else if (!strcmp(target, ECORE_X_SELECTION_TARGET_UTF8_STRING)) + x_target = _ecore_x_atom_utf8_string; + else if (!strcmp(target, ECORE_X_SELECTION_TARGET_FILENAME)) + x_target = _ecore_x_atom_file_name; + else + { + char *atom_name; + atom_name = malloc(strlen(target) + 4); + sprintf(atom_name, "_E_%s", target); + x_target = XInternAtom(_ecore_x_disp, atom_name, False); + free(atom_name); + } + + return x_target; +} + +char * +_ecore_x_selection_target_get(Atom target) +{ + 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 strdup(ECORE_X_SELECTION_TARGET_TEXT); +} + static void -_ecore_x_selection_request(Ecore_X_Window w, Ecore_X_Atom selection, Ecore_X_Selection_Target t) +_ecore_x_selection_request(Ecore_X_Window w, Ecore_X_Atom selection, char *target_str) { Ecore_X_Atom target, prop; - switch (t) { - case ECORE_X_SELECTION_TARGET_FILENAME: - target = _ecore_x_atom_file_name; - break; - case ECORE_X_SELECTION_TARGET_STRING: - target = _ecore_x_atom_string; - break; - case ECORE_X_SELECTION_TARGET_UTF8_STRING: - target = _ecore_x_atom_utf8_string; - break; - case ECORE_X_SELECTION_TARGET_TEXT: - target = _ecore_x_atom_text; - break; - default: - target = _ecore_x_atom_text; - } + target = _ecore_x_selection_target_atom_get(target_str); if (selection == _ecore_x_atom_selection_primary) prop = _ecore_x_atom_selection_prop_primary; @@ -217,36 +244,21 @@ } void -ecore_x_selection_primary_request(Ecore_X_Window w, Ecore_X_Selection_Target t) +ecore_x_selection_primary_request(Ecore_X_Window w, char *target) { - _ecore_x_selection_request(w, _ecore_x_atom_selection_primary, t); + _ecore_x_selection_request(w, _ecore_x_atom_selection_primary, target); } void -ecore_x_selection_secondary_request(Ecore_X_Window w, Ecore_X_Selection_Target t) +ecore_x_selection_secondary_request(Ecore_X_Window w, char *target) { - _ecore_x_selection_request(w, _ecore_x_atom_selection_secondary, t); + _ecore_x_selection_request(w, _ecore_x_atom_selection_secondary, target); } void -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); -} - -Ecore_X_Selection_Target -ecore_x_selection_target_get(Ecore_X_Atom target) +ecore_x_selection_clipboard_request(Ecore_X_Window w, char *target) { - if (target == _ecore_x_atom_file_name) - return ECORE_X_SELECTION_TARGET_FILENAME; - else if (target == _ecore_x_atom_string) - return ECORE_X_SELECTION_TARGET_STRING; - else if (target == _ecore_x_atom_utf8_string) - return ECORE_X_SELECTION_TARGET_UTF8_STRING; - else if (target == _ecore_x_atom_text) - return ECORE_X_SELECTION_TARGET_TEXT; - else - return ECORE_X_SELECTION_TARGET_TEXT; + _ecore_x_selection_request(w, _ecore_x_atom_selection_clipboard, target); } void @@ -287,30 +299,12 @@ int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret)) { Ecore_X_Atom x_target; - char *atom_name; 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 (!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); - } - + x_target = _ecore_x_selection_target_atom_get(target); + ecore_x_selection_converter_atom_add(x_target, func); } @@ -352,35 +346,18 @@ 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); - } - + x_target = _ecore_x_selection_target_atom_get(target); 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) +_ecore_x_selection_convert(Atom selection, Atom target, void **data_ret) { Ecore_X_Selection_Data *sel; Ecore_X_Selection_Converter *cnv; @@ -389,23 +366,7 @@ 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) - tgt_str = strdup("UTF8_STRING"); - else if (target == _ecore_x_atom_file_name) - tgt_str = strdup("FILENAME"); - else - { - char *atom_name = XGetAtomName(_ecore_x_disp, target); - tgt_str = strdup(atom_name); - XFree(atom_name); - } + tgt_str = _ecore_x_selection_target_get(target); for (cnv = converters; cnv; cnv = cnv->next) { @@ -423,6 +384,8 @@ } } + free(tgt_str); + return -1; } @@ -436,11 +399,11 @@ if (!data || !size) return 0; - if (!strcmp(target, "TEXT")) + if (!strcmp(target, ECORE_X_SELECTION_TARGET_TEXT)) style = XTextStyle; - else if (!strcmp(target, "COMPOUND_TEXT")) + else if (!strcmp(target, ECORE_X_SELECTION_TARGET_COMPOUND_TEXT)) style = XCompoundTextStyle; - else if (!strcmp(target, "STRING")) + else if (!strcmp(target, ECORE_X_SELECTION_TARGET_STRING)) style = XStringStyle; else return 0; ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ enlightenment-cvs mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs