Beispiel #1
0
/**
 * @internal
 * Return a -1 terminated array of the indexes of the delimiters (passed in
 * delim) found in the string. This result should be used with par_props_get.
 *
 * @param str The string to parse
 * @param delim a list of delimiters to work with.
 * @return returns a -1 terminated array of indexes according to positions of the delimiters found. NULL if there were none.
 */
int *
evas_bidi_segment_idxs_get(const Eina_Unicode *str, const char *delim)
{
   Eina_Unicode *udelim;
   const Eina_Unicode *str_base = str;
   int *ret, *tmp_ret;
   int ret_idx = 0, ret_len = 10; /* arbitrary choice */
   udelim = eina_unicode_utf8_to_unicode(delim, NULL);
   ret = malloc(ret_len * sizeof(int));
   for ( ; *str ; str++)
     {
        const Eina_Unicode *del;
        for (del = udelim ; *del ; del++)
          {
             if (*str == *del)
               {
                  if (ret_idx >= ret_len)
                    {
                       /* arbitrary choice */
                       ret_len += 20;
                       tmp_ret = realloc(ret, ret_len * sizeof(int));
                       if (!tmp_ret)
                         {
                            free(ret);
                            free(udelim);
                            return NULL;
                         }
                       ret = tmp_ret;
                    }
                  ret[ret_idx++] = str - str_base;
                  break;
               }
          }
     }
   free(udelim);

   /* If no indexes were found return NULL */
   if (ret_idx == 0)
     {
        free(ret);
        return NULL;
     }

   ret[ret_idx] = -1;
   tmp_ret = realloc(ret, (ret_idx + 1) * sizeof(int));

   return (tmp_ret) ? tmp_ret : ret;
}
END_TEST

START_TEST (elm_entry_atspi_text_char_get)
{
   Evas_Object *win, *entry;
   Eina_Unicode *expected;
   Eina_Unicode val;

   const char *txt = "ĄA11Y Ł TEST";
   const char *mtxt = "<b>ĄA11Y</b> <title>Ł</> TEST";

   elm_init(1, NULL);
   win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);

   entry = elm_entry_add(win);
   elm_object_text_set(entry, mtxt);

   expected = eina_unicode_utf8_to_unicode(txt, NULL);

   eo_do(entry, val = elm_interface_atspi_text_character_get(-1));
   ck_assert(val == 0);

   eo_do(entry, val = elm_interface_atspi_text_character_get(0));
   ck_assert(val == expected[0]);

   eo_do(entry, val = elm_interface_atspi_text_character_get(1));
   ck_assert(val == expected[1]);

   eo_do(entry, val = elm_interface_atspi_text_character_get(2));
   ck_assert(val == expected[2]);

   eo_do(entry, val = elm_interface_atspi_text_character_get(6));
   ck_assert(val == expected[6]);

   eo_do(entry, val = elm_interface_atspi_text_character_get(26));
   ck_assert(val == 0);

   free(expected);
   elm_shutdown();
}
Beispiel #3
0
static Eina_Bool
_ecore_imf_context_xim_filter_event(Ecore_IMF_Context *ctx,
                                    Ecore_IMF_Event_Type type,
                                    Ecore_IMF_Event *event)
{
   EINA_LOG_DBG("%s in", __FUNCTION__);
#ifdef ENABLE_XIM
   Ecore_IMF_Context_Data *imf_context_data;
   XIC ic;

   Ecore_X_Display *dsp;
   Ecore_X_Window win;

   int val;
   char compose_buffer[256];
   KeySym sym;
   char *compose = NULL;
   char *tmp = NULL;
   Eina_Bool result = EINA_FALSE;

   imf_context_data = ecore_imf_context_data_get(ctx);
   if (!imf_context_data) return EINA_FALSE;
   ic = imf_context_data->ic;
   if (!ic)
     ic = get_ic(ctx);

   if (type == ECORE_IMF_EVENT_KEY_DOWN)
     {
        XKeyPressedEvent xev;
        Ecore_IMF_Event_Key_Down *ev = (Ecore_IMF_Event_Key_Down *)event;
        EINA_LOG_DBG("ECORE_IMF_EVENT_KEY_DOWN");

        dsp = ecore_x_display_get();
        win = imf_context_data->win;

        xev.type = KeyPress;
        xev.serial = 0; /* hope it doesn't matter */
        xev.send_event = 0;
        xev.display = dsp;
        xev.window = win;
        xev.root = ecore_x_window_root_get(win);
        xev.subwindow = win;
        xev.time = ev->timestamp;
        xev.x = xev.x_root = 0;
        xev.y = xev.y_root = 0;
        xev.state = 0;
        xev.state |= _ecore_x_event_reverse_modifiers(ev->modifiers);
        xev.state |= _ecore_x_event_reverse_locks(ev->locks);
        xev.keycode = _keycode_get(dsp, ev->keyname);
        xev.same_screen = True;

        if (ic)
          {
             Status mbstatus;
#ifdef X_HAVE_UTF8_STRING
             val = Xutf8LookupString(ic,
                                     &xev,
                                     compose_buffer,
                                     sizeof(compose_buffer) - 1,
                                     &sym,
                                     &mbstatus);
#else /* ifdef X_HAVE_UTF8_STRING */
             val = XmbLookupString(ic,
                                   &xev,
                                   compose_buffer,
                                   sizeof(compose_buffer) - 1,
                                   &sym,
                                   &mbstatus);
#endif /* ifdef X_HAVE_UTF8_STRING */
             if (mbstatus == XBufferOverflow)
               {
                  tmp = malloc(sizeof (char) * (val + 1));
                  if (!tmp)
                    return EINA_FALSE;

                  compose = tmp;

#ifdef X_HAVE_UTF8_STRING
                  val = Xutf8LookupString(ic,
                                          &xev,
                                          tmp,
                                          val,
                                          &sym,
                                          &mbstatus);
#else /* ifdef X_HAVE_UTF8_STRING */
                  val = XmbLookupString(ic,
                                        &xev,
                                        tmp,
                                        val,
                                        &sym,
                                        &mbstatus);
#endif /* ifdef X_HAVE_UTF8_STRING */
                  if (val > 0)
                    {
                       tmp[val] = '\0';
#ifndef X_HAVE_UTF8_STRING
                       compose = eina_str_convert(nl_langinfo(CODESET),
                                                  "UTF-8", tmp);
                       free(tmp);
                       tmp = compose;
#endif /* ifndef X_HAVE_UTF8_STRING */
                    }
                  else
                    compose = NULL;
               }
             else if (val > 0)
               {
                  compose_buffer[val] = '\0';
#ifdef X_HAVE_UTF8_STRING
                  compose = strdup(compose_buffer);
#else /* ifdef X_HAVE_UTF8_STRING */
                  compose = eina_str_convert(nl_langinfo(CODESET), "UTF-8",
                                             compose_buffer);
#endif /* ifdef X_HAVE_UTF8_STRING */
               }
          }
        else
          {
             compose = strdup(ev->compose);
          }

        if (compose)
          {
             Eina_Unicode *unicode;
             int len;
             unicode = eina_unicode_utf8_to_unicode(compose, &len);
             if (!unicode) abort();
             if (unicode[0] >= 0x20 && unicode[0] != 0x7f)
               {
                  ecore_imf_context_commit_event_add(ctx, compose);
                  ecore_imf_context_event_callback_call(ctx, ECORE_IMF_CALLBACK_COMMIT, compose);
                  result = EINA_TRUE;
               }
             free(compose);
             free(unicode);
          }
     }

   return result;
#else
   (void)ctx;
   (void)type;
   (void)event;
   return EINA_FALSE;
#endif
}