Enlightenment CVS committal

Author  : xcomputerman
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_x


Modified Files:
        ecore_x.c ecore_x_private.h ecore_x_selection.c 


Log Message:
More work on selections:
- implement functions to add, delete and run conversion callbacks
  (not usable yet)


===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -3 -r1.21 -r1.22
--- ecore_x.c   14 Jan 2004 23:08:58 -0000      1.21
+++ ecore_x.c   16 Jan 2004 20:41:45 -0000      1.22
@@ -368,6 +368,8 @@
 
    _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_DELETE_REQUEST] = 
_ecore_x_atom_wm_delete_window;
    _ecore_x_atoms_wm_protocols[ECORE_X_WM_PROTOCOL_TAKE_FOCUS] = 
_ecore_x_atom_wm_take_focus;
+
+   _ecore_x_selection_data_initialize();
    
    _ecore_x_init_count++;
    return _ecore_x_init_count;
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_private.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -3 -r1.15 -r1.16
--- ecore_x_private.h   14 Jan 2004 23:08:58 -0000      1.15
+++ ecore_x_private.h   16 Jan 2004 20:41:45 -0000      1.16
@@ -45,6 +45,16 @@
    Time              time;
 };
 
+typedef struct _Ecore_X_Selection_Converter Ecore_X_Selection_Converter;
+
+struct _Ecore_X_Selection_Converter
+{
+   Atom     target;
+   int      (*convert)(char *target, void *data, int size, 
+                    void **data_ret, int *size_ret);
+   struct _Ecore_X_Selection_Converter *next;
+};
+
 typedef enum _Ecore_X_WM_Protocol {
        /**
         * If enabled the window manager will be asked to send a
@@ -171,6 +181,7 @@
 void _ecore_x_event_handle_mapping_notify(XEvent *xevent);
 void _ecore_x_event_handle_shape_change(XEvent *xevent);
 
+void _ecore_x_selection_data_initialize(void);
 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);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_selection.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- ecore_x_selection.c 10 Jan 2004 21:01:18 -0000      1.3
+++ ecore_x_selection.c 16 Jan 2004 20:41:45 -0000      1.4
@@ -6,6 +6,16 @@
 /* FIXME: Initialize! */
 static Ecore_X_Selection_Data selections[3];
 static Ecore_X_Selection_Data request_data[3];
+static Ecore_X_Selection_Converter *converters;
+
+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 */
+}
 
 static void
 _ecore_x_selection_request_data_get(Ecore_X_Atom selection, void **buf, int *len)
@@ -243,3 +253,134 @@
       return ECORE_X_SELECTION_TARGET_TEXT;
 }
 
+void
+ecore_x_selection_converter_atom_add(Ecore_X_Atom atom,
+      int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret))
+{
+   Ecore_X_Selection_Converter *cnv;
+
+   cnv = converters;
+   if (converters) 
+   {
+      while (1)
+      {
+         if (cnv->target == atom)
+         {
+            cnv->convert = func;
+            return;
+         }
+         if (cnv->next)
+            cnv = cnv->next;
+         else
+            break;
+      }
+   
+      cnv->next = calloc(1, sizeof(Ecore_X_Selection_Converter));
+      cnv = cnv->next;
+   } else {
+      converters = calloc(1, sizeof(Ecore_X_Selection_Converter));
+      cnv = converters;
+   }
+   cnv->target = atom;
+   cnv->convert = func;
+}
+
+
+void
+ecore_x_selection_converter_add(char *target, 
+      int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret))
+{
+   Ecore_X_Atom x_target;
+   char *atom_name;
+   
+   if (!func)
+      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"))
+      x_target = _ecore_x_atom_text;
+   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_add(x_target, func);
+}
+
+void
+ecore_x_selection_converter_atom_del(Ecore_X_Atom atom)
+{
+   Ecore_X_Selection_Converter *cnv, *prev_cnv;
+   
+   prev_cnv = NULL;
+   cnv = converters;
+   
+   while (cnv)
+   {
+      if (cnv->target == atom)
+      {
+         if(prev_cnv)
+            prev_cnv->next = cnv->next;
+         else
+            converters = NULL; /* This was the only converter */
+         free(cnv);
+         return;
+      }
+      prev_cnv = cnv;
+      cnv = cnv->next;
+   }
+}
+
+int
+_ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void 
**data_ret)
+{
+   Ecore_X_Selection_Data *sel;
+   Ecore_X_Selection_Converter *cnv;
+   void *data;
+   int size;
+   char *tgt_str;
+   
+   sel = _ecore_x_selection_get(selection);
+   if (target == _ecore_x_atom_text)
+      tgt_str = strdup("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);
+   }
+   
+   for (cnv = converters; cnv; cnv = cnv->next)
+   {
+      if (cnv->target == target)
+      {
+         int r;
+         r = cnv->convert(tgt_str, sel->data, sel->length, &data, &size);
+         if (r)
+         {
+            *data_ret = data;
+            return r;
+         }
+         else
+            return -1;
+      }
+   }
+
+   return -1;
+}
+




-------------------------------------------------------
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

Reply via email to