Ecore_x_selection convert is now a little richer.
authornash <nash@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 9 Jun 2010 09:40:37 +0000 (09:40 +0000)
committernash <nash@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 9 Jun 2010 09:40:37 +0000 (09:40 +0000)
Allows implementation of proper X cut & paste by an applicaiton, exisitng code
should not be affected (may need an recompile).

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@49586 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/ecore_x/Ecore_X.h
src/lib/ecore_x/xlib/ecore_x_dnd.c
src/lib/ecore_x/xlib/ecore_x_events.c
src/lib/ecore_x/xlib/ecore_x_private.h
src/lib/ecore_x/xlib/ecore_x_selection.c

index a8fe707..19b458c 100644 (file)
@@ -1106,9 +1106,9 @@ EAPI void             ecore_x_selection_primary_request(Ecore_X_Window w, const
 EAPI void             ecore_x_selection_secondary_request(Ecore_X_Window w, const char *target);
 EAPI void             ecore_x_selection_xdnd_request(Ecore_X_Window w, const char *target);
 EAPI void             ecore_x_selection_clipboard_request(Ecore_X_Window w, const char *target);
-EAPI int              ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **data_ret);
-EAPI void             ecore_x_selection_converter_add(char *target, int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret));
-EAPI 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));
+EAPI int              ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **data_ret, int *len, Ecore_X_Atom *targprop, int *targsize);
+EAPI 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 *, int *));
+EAPI 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, Ecore_X_Atom *tprop, int *tsize));
 EAPI void             ecore_x_selection_converter_del(char *target);
 EAPI void             ecore_x_selection_converter_atom_del(Ecore_X_Atom target);
 EAPI void             ecore_x_selection_parser_add(const char *target, void *(*func)(const char *target, void *data, int size, int format));
index 1caeb25..ab22044 100644 (file)
@@ -80,7 +80,7 @@ _ecore_x_dnd_shutdown(void)
 }
 
 static int
-_ecore_x_dnd_converter_copy(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret)
+_ecore_x_dnd_converter_copy(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *tprop, int *count)
 {
    XTextProperty text_prop;
    char *mystr;
index a30f610..679f5eb 100644 (file)
@@ -1311,6 +1311,8 @@ _ecore_x_event_handle_selection_request(XEvent *xevent)
    Ecore_X_Event_Selection_Request *e;
    Ecore_X_Selection_Intern *sd;
    void *data;
+   int len;
+   int typesize;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
    _ecore_x_last_event_mouse_move = 0;
@@ -1335,10 +1337,16 @@ _ecore_x_event_handle_selection_request(XEvent *xevent)
        if (si->data)
          {
             Ecore_X_Atom property;
+            Ecore_X_Atom type;
+
+            /* Set up defaults for strings first */
+            type = xevent->xselectionrequest.target;
+            typesize = 8;
+            len = sd->length;
 
             if (!ecore_x_selection_convert(xevent->xselectionrequest.selection,
                                            xevent->xselectionrequest.target,
-                                           &data))
+                                           &data, &len, &type, &typesize))
               {
                  /* Refuse selection, conversion to requested target failed */
                  property = None;
@@ -1348,8 +1356,8 @@ _ecore_x_event_handle_selection_request(XEvent *xevent)
                  /* FIXME: This does not properly handle large data transfers */
                  ecore_x_window_prop_property_set(xevent->xselectionrequest.requestor,
                                                   xevent->xselectionrequest.property,
-                                                  xevent->xselectionrequest.target,
-                                                  8, data, sd->length);
+                                                  type, typesize,
+                                                  data, len);
                  property = xevent->xselectionrequest.property;
                  free(data);
               }
index 17b996c..d9aa988 100644 (file)
@@ -106,8 +106,9 @@ typedef struct _Ecore_X_Selection_Converter Ecore_X_Selection_Converter;
 struct _Ecore_X_Selection_Converter
 {
    Ecore_X_Atom target;
-   int (*convert)(char *target, void *data, int size, 
-                  void **data_ret, int *size_ret);
+   int (*convert)(char *target, void *data, int size,
+                  void **data_ret, int *size_ret,
+                 Ecore_X_Atom *type, int *typeseize);
    Ecore_X_Selection_Converter *next;
 };
 
@@ -259,7 +260,7 @@ char *_ecore_x_selection_target_get(Ecore_X_Atom target);
 Ecore_X_Selection_Intern * 
       _ecore_x_selection_get(Ecore_X_Atom selection);
 int   _ecore_x_selection_set(Window w, const void *data, int len, Ecore_X_Atom selection);
-int   _ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **data_ret);
+int   _ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **data_ret, Ecore_X_Atom *targettype, int *targetsize);
 void *_ecore_x_selection_parse(const char *target, void *data, int size, int format);
 
 void _ecore_x_sync_magic_send(int val, Ecore_X_Window swin);
@@ -291,7 +292,7 @@ extern int _ecore_x_xi2_opcode;
 
 void _ecore_x_input_init(void);
 void _ecore_x_input_shutdown(void);
-void _ecore_x_input_handler(XEvent* xevent);    
+void _ecore_x_input_handler(XEvent* xevent);
 /* from sync */
 
 void _ecore_mouse_move(unsigned int timestamp, unsigned int xmodifiers, int x, int y, int x_root, int y_root, unsigned int event_window, unsigned int window, unsigned int root_win, int same_screen, int dev, double radx, double rady, double pressure, double angle, double mx, double my, double mrx, double mry);
index 3f5ff2e..e8e84f8 100644 (file)
@@ -19,7 +19,7 @@ static Ecore_X_Selection_Intern selections[4];
 static Ecore_X_Selection_Converter *converters = NULL;
 static Ecore_X_Selection_Parser *parsers = NULL;
 
-static int _ecore_x_selection_converter_text(char *target, void *data, int size, void **data_ret, int *size_ret);
+static int _ecore_x_selection_converter_text(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *tprop, int *);
 static int _ecore_x_selection_data_default_free(void *data);
 static void *_ecore_x_selection_parser_files(const char *target, void *data, int size, int format);
 static int _ecore_x_selection_data_files_free(void *data);
@@ -37,10 +37,10 @@ _ecore_x_selection_data_init(void)
    memset(selections, 0, sizeof(selections));
 
    /* Initialize converters */
-   ecore_x_selection_converter_atom_add(ECORE_X_ATOM_TEXT, 
+   ecore_x_selection_converter_atom_add(ECORE_X_ATOM_TEXT,
                                        _ecore_x_selection_converter_text);
 #ifdef X_HAVE_UTF8_STRING
-   ecore_x_selection_converter_atom_add(ECORE_X_ATOM_UTF8_STRING, 
+   ecore_x_selection_converter_atom_add(ECORE_X_ATOM_UTF8_STRING,
                                        _ecore_x_selection_converter_text);
 #endif
    ecore_x_selection_converter_atom_add(ECORE_X_ATOM_COMPOUND_TEXT,
@@ -108,16 +108,16 @@ _ecore_x_selection_get(Ecore_X_Atom selection)
      return NULL;
 }
 
-int 
+int
 _ecore_x_selection_set(Window w, const void *data, int size, Ecore_X_Atom selection)
 {
    int in;
    unsigned char *buf = NULL;
-   
+
    XSetSelectionOwner(_ecore_x_disp, selection, w, _ecore_x_event_last_time);
    if (XGetSelectionOwner(_ecore_x_disp, selection) != w)
      return 0;
-   
+
    if (selection == ECORE_X_ATOM_SELECTION_PRIMARY)
      in = 0;
    else if (selection == ECORE_X_ATOM_SELECTION_SECONDARY)
@@ -160,7 +160,7 @@ _ecore_x_selection_set(Window w, const void *data, int size, Ecore_X_Atom select
  * @return     Returns 1 if the ownership of the selection was successfully 
  *             claimed, or 0 if unsuccessful.
  */
-EAPI int 
+EAPI int
 ecore_x_selection_primary_set(Ecore_X_Window w, const void *data, int size)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -173,7 +173,7 @@ ecore_x_selection_primary_set(Ecore_X_Window w, const void *data, int size)
  *             or 0 if unsuccessful.
  *
  */
-EAPI int 
+EAPI int
 ecore_x_selection_primary_clear(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -188,7 +188,7 @@ ecore_x_selection_primary_clear(void)
  * @return     Returns 1 if the ownership of the selection was successfully 
  *             claimed, or 0 if unsuccessful.
  */
-EAPI int 
+EAPI int
 ecore_x_selection_secondary_set(Ecore_X_Window w, const void *data, int size)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -201,7 +201,7 @@ ecore_x_selection_secondary_set(Ecore_X_Window w, const void *data, int size)
  *             or 0 if unsuccessful.
  *
  */
-EAPI int 
+EAPI int
 ecore_x_selection_secondary_clear(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -216,7 +216,7 @@ ecore_x_selection_secondary_clear(void)
  * @return     Returns 1 if the ownership of the selection was successfully 
  *             claimed, or 0 if unsuccessful.
  */
-EAPI int 
+EAPI int
 ecore_x_selection_xdnd_set(Ecore_X_Window w, const void *data, int size)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -229,7 +229,7 @@ ecore_x_selection_xdnd_set(Ecore_X_Window w, const void *data, int size)
  *             or 0 if unsuccessful.
  *
  */
-EAPI int 
+EAPI int
 ecore_x_selection_xdnd_clear(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -247,7 +247,7 @@ ecore_x_selection_xdnd_clear(void)
  * Get the converted data from a previous CLIPBOARD selection
  * request. The buffer must be freed when done with.
  */
-EAPI int 
+EAPI int
 ecore_x_selection_clipboard_set(Ecore_X_Window w, const void *data, int size)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -260,7 +260,7 @@ ecore_x_selection_clipboard_set(Ecore_X_Window w, const void *data, int size)
  *             or 0 if unsuccessful.
  *
  */
-EAPI int 
+EAPI int
 ecore_x_selection_clipboard_clear(void)
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -364,13 +364,13 @@ ecore_x_selection_clipboard_request(Ecore_X_Window w, const char *target)
 
 EAPI 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))
+      int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *tsize))
 {
    Ecore_X_Selection_Converter *cnv;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
    cnv = converters;
-   if (converters) 
+   if (converters)
      {
        while (1)
          {
@@ -398,8 +398,8 @@ ecore_x_selection_converter_atom_add(Ecore_X_Atom target,
 }
 
 EAPI void
-ecore_x_selection_converter_add(char *target, 
-      int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret))
+ecore_x_selection_converter_add(char *target,
+      int (*func)(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *, int *))
 {
    Ecore_X_Atom x_target;
 
@@ -474,14 +474,14 @@ ecore_x_selection_notify_send(Ecore_X_Window requestor, Ecore_X_Atom selection,
 
 /* Locate and run conversion callback for specified selection target */
 EAPI int
-ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **data_ret)
+ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target,
+      void **data_ret, int *size, Ecore_X_Atom *targtype, int *typesize)
 {
    Ecore_X_Selection_Intern *sel;
    Ecore_X_Selection_Converter *cnv;
    void *data;
-   int size;
    char *tgt_str;
-   
+
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
    sel = _ecore_x_selection_get(selection);
    tgt_str = _ecore_x_selection_target_get(target);
@@ -491,7 +491,8 @@ ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **da
        if (cnv->target == target)
          {
             int r;
-            r = cnv->convert(tgt_str, sel->data, sel->length, &data, &size);
+            r = cnv->convert(tgt_str, sel->data, sel->length, &data, size,
+                  targtype, typesize);
             free(tgt_str);
             if (r)
               {
@@ -518,7 +519,7 @@ ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **da
  * locale using Ecore_Txt functions */
 /* 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)
+_ecore_x_selection_converter_text(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *targprop, int *s)
 {
    XTextProperty text_prop;
    char *mystr;
@@ -585,7 +586,7 @@ ecore_x_selection_parser_add(const char *target,
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
    prs = parsers;
-   if (parsers) 
+   if (parsers)
      {
        while (prs->next)
          {
@@ -645,7 +646,7 @@ _ecore_x_selection_parse(const char *target, void *data, int size, int format)
 {
    Ecore_X_Selection_Parser *prs;
    Ecore_X_Selection_Data *sel;
-   
+
    for (prs = parsers; prs; prs = prs->next)
      {
        if (!strcmp(prs->target, target))
@@ -807,6 +808,7 @@ _ecore_x_selection_parser_targets(const char *target __UNUSED__, void *data, int
    sel->targets = malloc((size - 2) * sizeof(char *));
    for (i = 2; i < size; i++)
      sel->targets[i - 2] = XGetAtomName(_ecore_x_disp, targets[i]);
+
    free(data);
 
    ECORE_X_SELECTION_DATA(sel)->free = _ecore_x_selection_data_targets_free;