Update request API to use strings for target types instead of enums
authorxcomputerman <xcomputerman>
Sat, 17 Jan 2004 00:14:37 +0000 (00:14 +0000)
committerxcomputerman <xcomputerman@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 17 Jan 2004 00:14:37 +0000 (00:14 +0000)
SVN revision: 8509

legacy/ecore/src/lib/ecore_x/Ecore_X.h
legacy/ecore/src/lib/ecore_x/ecore_x_events.c
legacy/ecore/src/lib/ecore_x/ecore_x_private.h
legacy/ecore/src/lib/ecore_x/ecore_x_selection.c

index 7159b76fd3c26b058816cf525e9404600c4aa521..94e1cf81f452b1fd38afbe2ef8ccfdb7112a5bc2 100644 (file)
@@ -22,12 +22,11 @@ extern "C" {
 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 @@ struct _Ecore_X_Event_Selection_Notify
    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_set(Ecore_X_Window w, char *data, i
 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);
index 12bce0cbf9bfad3982ee8f2a2e86e57cc8cf7c78..23f5ec084aafa96eb07fb082dc492ab3044e2eff 100644 (file)
@@ -118,6 +118,16 @@ _ecore_x_event_free_key_up(void *data, void *ev)
    free(e);
 }
 
+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)
 {
@@ -900,7 +910,7 @@ _ecore_x_event_handle_selection_request(XEvent *xevent)
    Ecore_X_Selection_Data           *sd;
    XSelectionEvent                  xnotify;
    XEvent                           *xev;
-   char                             *data;
+   void                             *data;
 
    xev = calloc(1, sizeof(XEvent));
    
@@ -914,8 +924,6 @@ _ecore_x_event_handle_selection_request(XEvent *xevent)
    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 @@ _ecore_x_event_handle_selection_notify(XEvent *xevent)
    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 @@ _ecore_x_event_handle_selection_notify(XEvent *xevent)
    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);
 
 }
 
index bdcf794753ca8a2fd29e71b7a8b2da4d86cdb453..43d26a031cb7da8471b1aff71271bc04ce37c7b1 100644 (file)
@@ -183,8 +183,11 @@ 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);
+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
index 16158cd073d873f233992c8e799af63390c80583..dd869a0f714f2172d0dd6a99a76340afe5352a7e 100644 (file)
@@ -183,27 +183,54 @@ ecore_x_selection_clipboard_clear(void)
    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 @@ _ecore_x_selection_request(Ecore_X_Window w, Ecore_X_Atom selection, Ecore_X_Sel
 }
 
 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 @@ 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 || !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 @@ 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);
-   }
-
+   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 @@ _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)
-      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 @@ _ecore_x_selection_convert(Ecore_X_Atom selection, Ecore_X_Atom target, void **d
       }
    }
 
+   free(tgt_str);
+
    return -1;
 }
 
@@ -436,11 +399,11 @@ static int _ecore_x_selection_converter_text(char *target, void *data, int size,
    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;