2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <Elementary.h>
28 #include <Ecore_Evas.h>
32 #include <system_settings.h>
37 #include <livebox-errno.h>
38 #include <livebox-service.h>
40 #include "script_port.h"
42 #define TEXT_CLASS "tizen"
43 #define DEFAULT_FONT_SIZE -100
45 #define PUBLIC __attribute__((visibility("default")))
81 Eina_List *access_chain;
88 Eina_List *handle_list;
96 static inline Evas_Object *find_edje(struct info *handle, const char *id)
100 struct obj_info *obj_info;
102 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
103 obj_info = evas_object_data_get(edje, "obj_info");
105 ErrPrint("Object info is not valid\n");
115 } else if (!obj_info->id) {
119 if (!strcmp(obj_info->id, id)) {
124 DbgPrint("EDJE[%s] is not found\n", id);
128 static inline void rebuild_focus_chain(Evas_Object *obj)
130 struct obj_info *obj_info;
134 obj_info = evas_object_data_get(obj, "obj_info");
136 ErrPrint("Object info is not available\n");
140 elm_object_focus_custom_chain_unset(obj);
142 EINA_LIST_FOREACH(obj_info->access_chain, l, ao) {
143 DbgPrint("Append %p\n", ao);
144 elm_object_focus_custom_chain_append(obj, ao, NULL);
148 PUBLIC const char *script_magic_id(void)
153 PUBLIC int script_update_color(void *h, Evas *e, const char *id, const char *part, const char *rgba)
155 struct info *handle = h;
157 int r[3], g[3], b[3], a[3];
160 edje = find_edje(handle, id);
162 return LB_STATUS_ERROR_NOT_EXIST;
165 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
166 r, g, b, a, /* OBJECT */
167 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
168 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
170 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
171 return LB_STATUS_ERROR_INVALID;
174 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
175 r[0], g[0], b[0], a[0], /* OBJECT */
176 r[1], g[1], b[1], a[1], /* OUTLINE */
177 r[2], g[2], b[2], a[2]); /* SHADOW */
179 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
180 return LB_STATUS_SUCCESS;
183 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
194 ao = evas_object_data_get(part_obj, "ao");
199 edje = evas_object_data_get(ao, "edje");
204 e = evas_object_evas_get(part_obj);
205 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
209 #if defined(_USE_ECORE_TIME_GET)
210 timestamp = ecore_time_get();
213 if (gettimeofday(&tv, NULL) < 0) {
214 ErrPrint("Failed to get time\n");
217 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
221 DbgPrint("Cursor is on %dx%d\n", x, y);
222 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
223 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
224 evas_event_feed_mouse_move(e, x, y, (timestamp + 0.02f) * 1000, NULL);
225 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.03f) * 1000, NULL);
228 PUBLIC int script_update_text(void *h, Evas *e, const char *id, const char *part, const char *text)
230 struct obj_info *obj_info;
231 struct info *handle = h;
235 edje = find_edje(handle, id);
237 ErrPrint("Failed to find EDJE\n");
238 return LB_STATUS_ERROR_NOT_EXIST;
241 obj_info = evas_object_data_get(edje, "obj_info");
243 ErrPrint("Object info is not available\n");
244 return LB_STATUS_ERROR_FAULT;
247 elm_object_part_text_set(edje, part, text ? text : "");
249 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
254 ao = evas_object_data_get(to, "ao");
256 ao = elm_access_object_register(to, edje);
258 ErrPrint("Unable to add ao: %s\n", part);
261 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
262 evas_object_data_set(to, "ao", ao);
263 evas_object_data_set(ao, "edje", edje);
264 elm_access_activate_cb_set(ao, activate_cb, NULL);
265 elm_object_focus_custom_chain_append(edje, ao, NULL);
268 if (!text || !strlen(text)) {
269 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
270 evas_object_data_del(to, "ao");
271 evas_object_data_del(ao, "edje");
272 elm_access_object_unregister(ao);
273 DbgPrint("[%s] Remove access object\n", part);
275 rebuild_focus_chain(edje);
279 utf8 = elm_entry_markup_to_utf8(text);
280 if ((!utf8 || !strlen(utf8))) {
283 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
284 evas_object_data_del(to, "ao");
285 evas_object_data_del(ao, "edje");
286 elm_access_object_unregister(ao);
287 DbgPrint("[%s] Remove access object\n", part);
289 rebuild_focus_chain(edje);
293 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
296 ErrPrint("Unable to get text part[%s]\n", part);
300 return LB_STATUS_SUCCESS;
303 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
305 while (len > 0 && *value == ' ') {
314 img_opt->aspect = !strncasecmp(value, "true", 4);
315 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
318 static void parse_orient(struct image_option *img_opt, const char *value, int len)
320 while (len > 0 && *value == ' ') {
329 img_opt->orient = !strncasecmp(value, "true", 4);
330 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
333 static void parse_size(struct image_option *img_opt, const char *value, int len)
339 while (len > 0 && *value == ' ') {
344 buf = strndup(value, len);
346 ErrPrint("Heap: %s\n", strerror(errno));
350 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
351 img_opt->width = width;
352 img_opt->height = height;
353 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
355 DbgPrint("Invalid size tag[%s]\n", buf);
361 static void parse_fill(struct image_option *img_opt, const char *value, int len)
363 while (len > 0 && *value == ' ') {
368 if (!strncasecmp(value, "in-size", len)) {
369 img_opt->fill = FILL_IN_SIZE;
370 } else if (!strncasecmp(value, "over-size", len)) {
371 img_opt->fill = FILL_OVER_SIZE;
373 img_opt->fill = FILL_DISABLE;
376 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
379 static inline void parse_image_option(const char *option, struct image_option *img_opt)
386 void (*handler)(struct image_option *img_opt, const char *value, int len);
389 .cmd = "aspect", /* Keep the aspect ratio */
390 .handler = parse_aspect,
393 .cmd = "orient", /* Keep the orientation value: for the rotated images */
394 .handler = parse_orient,
397 .cmd = "fill", /* Fill the image to its container */
398 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
402 .handler = parse_size,
416 if (!option || !*option) {
423 * GCC 4.7 warnings uninitialized idx and tag value.
424 * But it will be initialized by the state machine. :(
425 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
432 for (ptr = option; state != STATE_END; ptr++) {
447 cmd = cmd_list[tag].cmd;
453 } else if (*ptr == '\0') {
458 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
463 state = STATE_IGNORE;
466 } else if (*ptr == '\0') {
468 } else if (cmd[idx] == *ptr) {
474 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
478 cmd = cmd_list[tag].cmd;
484 if (*ptr == ';' || *ptr == '\0') {
485 cmd_list[tag].handler(img_opt, value + 1, idx);
486 state = *ptr ? STATE_START : STATE_END;
494 } else if (*ptr == '\0') {
504 PUBLIC int script_update_access(void *_h, Evas *e, const char *id, const char *part, const char *text, const char *option)
506 struct info *handle = _h;
508 struct obj_info *obj_info;
511 edje = find_edje(handle, id);
513 ErrPrint("No such object: %s\n", id);
514 return LB_STATUS_ERROR_NOT_EXIST;
517 obj_info = evas_object_data_get(edje, "obj_info");
519 ErrPrint("Object info is not available\n");
520 return LB_STATUS_ERROR_FAULT;
523 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
527 ao = evas_object_data_get(to, "ao");
529 if (text && strlen(text)) {
530 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
532 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
533 evas_object_data_del(to, "ao");
534 evas_object_data_del(ao, "edje");
535 elm_access_object_unregister(ao);
536 DbgPrint("Successfully unregistered\n");
538 rebuild_focus_chain(edje);
540 } else if (text && strlen(text)) {
541 ao = elm_access_object_register(to, edje);
543 ErrPrint("Unable to register access object\n");
545 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
546 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
547 evas_object_data_set(to, "ao", ao);
548 elm_object_focus_custom_chain_append(edje, ao, NULL);
549 DbgPrint("[%s] Register access info: (%s)\n", part, text);
550 evas_object_data_set(ao, "edje", edje);
551 elm_access_activate_cb_set(ao, activate_cb, NULL);
555 ErrPrint("[%s] is not exists\n", part);
558 return LB_STATUS_SUCCESS;
561 PUBLIC int script_operate_access(void *_h, Evas *e, const char *id, const char *part, const char *operation, const char *option)
563 struct info *handle = _h;
565 struct obj_info *obj_info;
566 Elm_Access_Action_Info action_info;
569 if (!operation || !strlen(operation)) {
570 return LB_STATUS_ERROR_INVALID;
573 edje = find_edje(handle, id);
575 ErrPrint("No such object: %s\n", id);
576 return LB_STATUS_ERROR_NOT_EXIST;
579 obj_info = evas_object_data_get(edje, "obj_info");
581 ErrPrint("Object info is not available\n");
582 return LB_STATUS_ERROR_FAULT;
585 memset(&action_info, 0, sizeof(action_info));
587 /* OPERATION is defined in liblivebox package */
588 if (!strcasecmp(operation, "set,hl")) {
596 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
598 ErrPrint("Invalid part: %s\n", part);
602 evas_object_geometry_get(to, &x, &y, &w, &h);
604 action_info.x = x + w / 2;
605 action_info.y = x + h / 2;
606 } else if (option && sscanf(option, "%dx%d", &action_info.x, &action_info.y) == 2) {
608 ErrPrint("Insufficient info for HL\n");
612 DbgPrint("TXxTY: %dx%d\n", action_info.x, action_info.y);
613 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT, &action_info);
614 if (ret == EINA_FALSE) {
615 ErrPrint("Action error\n");
617 } else if (!strcasecmp(operation, "unset,hl")) {
618 ret = elm_access_action(edje, ELM_ACCESS_ACTION_UNHIGHLIGHT, &action_info);
619 if (ret == EINA_FALSE) {
620 ErrPrint("Action error\n");
622 } else if (!strcasecmp(operation, "next,hl")) {
623 action_info.highlight_cycle = (!!option) && (!!strcasecmp(option, "no,cycle"));
625 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_NEXT, &action_info);
626 if (ret == EINA_FALSE) {
627 ErrPrint("Action error\n");
629 } else if (!strcasecmp(operation, "prev,hl")) {
630 action_info.highlight_cycle = EINA_TRUE;
631 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_PREV, &action_info);
632 if (ret == EINA_FALSE) {
633 ErrPrint("Action error\n");
638 return LB_STATUS_SUCCESS;
641 PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path, const char *option)
643 struct info *handle = _h;
648 struct obj_info *obj_info;
650 struct image_option img_opt = {
653 .fill = FILL_DISABLE,
658 edje = find_edje(handle, id);
660 ErrPrint("No such object: %s\n", id);
661 return LB_STATUS_ERROR_NOT_EXIST;
664 obj_info = evas_object_data_get(edje, "obj_info");
666 ErrPrint("Object info is not available\n");
667 return LB_STATUS_ERROR_FAULT;
670 img = elm_object_part_content_unset(edje, part);
676 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
677 if (child->obj != img) {
681 obj_info->children = eina_list_remove(obj_info->children, child);
687 DbgPrint("delete object %s %p\n", part, img);
688 ao = evas_object_data_del(img, "ao");
690 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
691 evas_object_data_del(ao, "edje");
692 elm_access_object_unregister(ao);
693 DbgPrint("Successfully unregistered\n");
695 evas_object_del(img);
697 rebuild_focus_chain(edje);
700 if (!path || !strlen(path) || access(path, R_OK) != 0) {
701 DbgPrint("SKIP - Path: [%s]\n", path);
702 return LB_STATUS_SUCCESS;
705 child = malloc(sizeof(*child));
707 ErrPrint("Heap: %s\n", strerror(errno));
708 return LB_STATUS_ERROR_MEMORY;
711 child->part = strdup(part);
713 ErrPrint("Heap: %s\n", strerror(errno));
715 return LB_STATUS_ERROR_MEMORY;
718 img = evas_object_image_add(e);
720 ErrPrint("Failed to add an image object\n");
723 return LB_STATUS_ERROR_FAULT;
726 evas_object_image_preload(img, EINA_FALSE);
727 parse_image_option(option, &img_opt);
728 evas_object_image_load_orientation_set(img, img_opt.orient);
730 evas_object_image_file_set(img, path, NULL);
731 err = evas_object_image_load_error_get(img);
732 if (err != EVAS_LOAD_ERROR_NONE) {
733 ErrPrint("Load error: %s\n", evas_load_error_str(err));
734 evas_object_del(img);
737 return LB_STATUS_ERROR_IO;
740 evas_object_image_size_get(img, &w, &h);
741 if (img_opt.aspect) {
742 if (img_opt.fill == FILL_OVER_SIZE) {
746 if (img_opt.width >= 0 && img_opt.height >= 0) {
747 part_w = img_opt.width * elm_config_scale_get();
748 part_h = img_opt.height * elm_config_scale_get();
752 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
754 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
756 if (part_w > w || part_h > h) {
760 fw = (double)part_w / (double)w;
761 fh = (double)part_h / (double)h;
772 if (!part_w || !part_h || !w || !h) {
773 evas_object_del(img);
776 return LB_STATUS_ERROR_INVALID;
779 if (evas_object_image_region_support_get(img)) {
780 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
781 evas_object_image_load_size_set(img, part_w, part_h);
782 evas_object_image_filled_set(img, EINA_TRUE);
783 //evas_object_image_fill_set(img, 0, 0, part_w, part_h);
784 DbgPrint("Size: %dx%d (region: %dx%d - %dx%d)\n", w, h, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
788 Evas_Object *src_img;
792 DbgPrint("Part loading is not supported\n");
793 ee = ecore_evas_buffer_new(part_w, part_h);
795 ErrPrint("Failed to create a EE\n");
796 evas_object_del(img);
799 return LB_STATUS_ERROR_FAULT;
802 ecore_evas_alpha_set(ee, EINA_TRUE);
804 e = ecore_evas_get(ee);
806 ErrPrint("Unable to get Evas\n");
809 evas_object_del(img);
812 return LB_STATUS_ERROR_FAULT;
815 src_img = evas_object_image_filled_add(e);
817 ErrPrint("Unable to add an image\n");
820 evas_object_del(img);
823 return LB_STATUS_ERROR_FAULT;
826 evas_object_image_alpha_set(src_img, EINA_TRUE);
827 evas_object_image_colorspace_set(src_img, EVAS_COLORSPACE_ARGB8888);
828 evas_object_image_smooth_scale_set(src_img, EINA_TRUE);
829 evas_object_image_load_orientation_set(src_img, img_opt.orient);
830 evas_object_image_file_set(src_img, path, NULL);
831 err = evas_object_image_load_error_get(src_img);
832 if (err != EVAS_LOAD_ERROR_NONE) {
833 ErrPrint("Load error: %s\n", evas_load_error_str(err));
834 evas_object_del(src_img);
837 evas_object_del(img);
840 return LB_STATUS_ERROR_IO;
842 evas_object_image_size_get(src_img, &rw, &rh);
843 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
844 evas_object_resize(src_img, w, h);
845 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
846 evas_object_show(src_img);
848 data = ecore_evas_buffer_pixels_get(ee);
850 ErrPrint("Unable to get pixels\n");
851 evas_object_del(src_img);
854 evas_object_del(img);
857 return LB_STATUS_ERROR_IO;
860 e = evas_object_evas_get(img);
861 evas_object_del(img);
862 img = evas_object_image_filled_add(e);
864 evas_object_del(src_img);
869 return LB_STATUS_ERROR_MEMORY;
872 evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
873 evas_object_image_smooth_scale_set(img, EINA_TRUE);
874 evas_object_image_alpha_set(img, EINA_TRUE);
875 evas_object_image_data_set(img, NULL);
876 evas_object_image_size_set(img, part_w, part_h);
877 evas_object_resize(img, part_w, part_h);
878 evas_object_image_data_copy_set(img, (void *)data);
879 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
880 evas_object_image_data_update_add(img, 0, 0, part_w, part_h);
882 evas_object_del(src_img);
885 } else if (img_opt.fill == FILL_IN_SIZE) {
889 if (img_opt.width >= 0 && img_opt.height >= 0) {
890 part_w = img_opt.width * elm_config_scale_get();
891 part_h = img_opt.height * elm_config_scale_get();
895 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
897 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
899 if (part_w > w || part_h > h) {
903 fw = (double)part_w / (double)w;
904 fh = (double)part_h / (double)h;
914 DbgPrint("Size: %dx%d\n", w, h);
915 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
916 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
917 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
919 evas_object_image_fill_set(img, 0, 0, w, h);
920 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
921 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
924 if (img_opt.width >= 0 && img_opt.height >= 0) {
927 DbgPrint("Using given image size: %dx%d\n", w, h);
930 evas_object_image_fill_set(img, 0, 0, w, h);
931 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
932 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
933 evas_object_image_filled_set(img, EINA_TRUE);
938 * object will be shown by below statement automatically
940 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
942 elm_object_part_content_set(edje, part, img);
943 obj_info->children = eina_list_append(obj_info->children, child);
947 * This object is not registered as an access object.
948 * So the developer should add it to access list manually, using DESC_ACCESS block.
950 return LB_STATUS_SUCCESS;
953 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
955 struct info *handle = data;
967 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
968 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
972 sx = (double)px / (double)w;
973 ex = (double)(px + pw) / (double)w;
978 sy = (double)py / (double)h;
979 ey = (double)(py + ph) / (double)h;
982 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
985 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
987 struct info *handle = _info;
988 struct obj_info *obj_info;
989 struct obj_info *parent_obj_info;
993 handle->obj_list = eina_list_remove(handle->obj_list, obj);
995 obj_info = evas_object_data_del(obj, "obj_info");
997 ErrPrint("Object info is not valid\n");
1001 DbgPrint("delete object %s %p\n", obj_info->id, obj);
1002 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
1003 if (parent_obj_info) {
1007 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
1008 if (child->obj != obj) {
1014 * If this code is executed,
1015 * The parent is not deleted by desc, this object is deleted by itself.
1016 * It is not possible, but we care it.
1018 DbgPrint("Parent's children is updated: %s\n", child->part);
1019 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
1025 DbgPrint("Parent EDJE\n");
1028 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
1030 elm_object_focus_custom_chain_unset(obj);
1032 EINA_LIST_FREE(obj_info->children, child) {
1033 DbgPrint("delete object %s %p\n", child->part, child->obj);
1036 ao = evas_object_data_del(child->obj, "ao");
1038 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
1039 evas_object_data_del(ao, "edje");
1040 elm_access_object_unregister(ao);
1042 evas_object_del(child->obj);
1048 EINA_LIST_FREE(obj_info->access_chain, ao) {
1049 evas_object_data_del(ao, "edje");
1050 elm_access_object_unregister(ao);
1057 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
1059 Evas_Object *o, *ho;
1061 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
1062 if (!o) return NULL;
1064 ho = evas_object_data_get(o, "_elm_access_target");
1069 LB_ACCESS_HIGHLIGHT 0
1070 LB_ACCESS_HIGHLIGHT_NEXT 1
1071 LB_ACCESS_HIGHLIGHT_PREV 2
1072 LB_ACCESS_ACTIVATE 3
1076 PUBLIC int script_feed_event(void *h, Evas *e, int event_type, int x, int y, int down, double timestamp)
1078 struct info *handle = h;
1080 struct obj_info *obj_info;
1081 int ret = LB_STATUS_SUCCESS;
1083 edje = find_edje(handle, NULL); /*!< Get the base layout */
1085 ErrPrint("Base layout is not exist\n");
1086 return LB_STATUS_ERROR_NOT_EXIST;
1089 obj_info = evas_object_data_get(edje, "obj_info");
1091 ErrPrint("Object info is not valid\n");
1092 return LB_STATUS_ERROR_INVALID;
1095 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
1096 Elm_Access_Action_Info info;
1097 Elm_Access_Action_Type action;
1099 memset(&info, 0, sizeof(info));
1101 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
1102 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1105 ret = elm_access_action(edje, action, &info);
1106 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1107 if (ret == EINA_TRUE) {
1108 if (!get_highlighted_object(edje)) {
1109 ErrPrint("Highlighted object is not found\n");
1110 ret = LB_ACCESS_STATUS_ERROR;
1112 DbgPrint("Highlighted object is found\n");
1113 ret = LB_ACCESS_STATUS_DONE;
1116 ErrPrint("Action error\n");
1117 ret = LB_ACCESS_STATUS_ERROR;
1119 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1120 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1121 info.highlight_cycle = EINA_FALSE;
1122 ret = elm_access_action(edje, action, &info);
1123 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1124 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
1125 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1126 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1127 info.highlight_cycle = EINA_FALSE;
1128 ret = elm_access_action(edje, action, &info);
1129 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1130 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
1131 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
1132 action = ELM_ACCESS_ACTION_ACTIVATE;
1133 ret = elm_access_action(edje, action, &info);
1134 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1135 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1136 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
1138 action = ELM_ACCESS_ACTION_UP;
1139 ret = elm_access_action(edje, action, &info);
1140 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1141 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1142 } else if (down == 1) {
1143 action = ELM_ACCESS_ACTION_DOWN;
1144 ret = elm_access_action(edje, action, &info);
1145 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1146 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1148 ErrPrint("Invalid access event\n");
1149 ret = LB_ACCESS_STATUS_ERROR;
1151 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
1152 action = ELM_ACCESS_ACTION_SCROLL;
1157 info.mouse_type = 0;
1158 ret = elm_access_action(edje, action, &info);
1159 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1160 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1163 info.mouse_type = 1;
1164 ret = elm_access_action(edje, action, &info);
1165 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1166 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1169 info.mouse_type = 2;
1170 ret = elm_access_action(edje, action, &info);
1171 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1172 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1175 ret = LB_ACCESS_STATUS_ERROR;
1178 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
1179 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1180 ret = elm_access_action(edje, action, &info);
1181 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1182 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1184 DbgPrint("Invalid event\n");
1185 ret = LB_ACCESS_STATUS_ERROR;
1188 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
1189 switch (event_type) {
1190 case LB_SCRIPT_MOUSE_DOWN:
1191 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
1192 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1194 case LB_SCRIPT_MOUSE_MOVE:
1195 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
1197 case LB_SCRIPT_MOUSE_UP:
1198 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
1199 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1201 case LB_SCRIPT_MOUSE_IN:
1202 evas_event_feed_mouse_in(e, timestamp * 1000, NULL);
1204 case LB_SCRIPT_MOUSE_OUT:
1205 evas_event_feed_mouse_out(e, timestamp * 1000, NULL);
1208 return LB_STATUS_ERROR_INVALID;
1210 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
1211 DbgPrint("Key event is not implemented\n");
1212 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
1218 PUBLIC int script_update_script(void *h, Evas *e, const char *src_id, const char *target_id, const char *part, const char *path, const char *group)
1220 struct info *handle = h;
1223 struct obj_info *obj_info;
1224 struct child *child;
1225 char _target_id[32];
1227 edje = find_edje(handle, src_id);
1229 ErrPrint("Edje is not exists (%s)\n", src_id);
1230 return LB_STATUS_ERROR_NOT_EXIST;
1233 obj_info = evas_object_data_get(edje, "obj_info");
1235 ErrPrint("Object info is not valid\n");
1236 return LB_STATUS_ERROR_INVALID;
1239 obj = elm_object_part_content_unset(edje, part);
1244 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
1245 if (child->obj != obj) {
1249 obj_info->children = eina_list_remove(obj_info->children, child);
1256 DbgPrint("delete object %s %p\n", part, obj);
1259 * This will call the edje_del_cb.
1260 * It will delete all access objects
1262 evas_object_del(obj);
1265 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1266 DbgPrint("SKIP - Path: [%s]\n", path);
1267 return LB_STATUS_SUCCESS;
1271 if (find_edje(handle, part)) {
1275 #if defined(_USE_ECORE_TIME_GET)
1276 timestamp = ecore_time_get();
1279 if (gettimeofday(&tv, NULL) < 0) {
1280 static int local_idx = 0;
1281 timestamp = (double)(local_idx++);
1283 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1287 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1288 } while (find_edje(handle, _target_id));
1290 target_id = _target_id;
1295 DbgPrint("Anonymouse target id: %s\n", target_id);
1298 obj = elm_layout_add(edje);
1300 ErrPrint("Failed to add a new edje object\n");
1301 return LB_STATUS_ERROR_FAULT;
1304 edje_object_scale_set(elm_layout_edje_get(obj), elm_config_scale_get());
1306 if (!elm_layout_file_set(obj, path, group)) {
1308 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1309 ErrPrint("Could not load %s from %s: %s\n", group, path, edje_load_error_str(err));
1310 evas_object_del(obj);
1311 return LB_STATUS_ERROR_IO;
1314 evas_object_show(obj);
1316 obj_info = calloc(1, sizeof(*obj_info));
1318 ErrPrint("Failed to add a obj_info\n");
1319 evas_object_del(obj);
1320 return LB_STATUS_ERROR_MEMORY;
1323 obj_info->id = strdup(target_id);
1324 if (!obj_info->id) {
1325 ErrPrint("Failed to add a obj_info\n");
1327 evas_object_del(obj);
1328 return LB_STATUS_ERROR_MEMORY;
1331 obj_info->parent = edje;
1333 child = malloc(sizeof(*child));
1335 ErrPrint("Error: %s\n", strerror(errno));
1338 evas_object_del(obj);
1339 return LB_STATUS_ERROR_MEMORY;
1342 child->part = strdup(part);
1344 ErrPrint("Error: %s\n", strerror(errno));
1348 evas_object_del(obj);
1349 return LB_STATUS_ERROR_MEMORY;
1354 evas_object_data_set(obj, "obj_info", obj_info);
1355 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1356 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1357 handle->obj_list = eina_list_append(handle->obj_list, obj);
1359 DbgPrint("%s part swallow edje %p\n", part, obj);
1360 elm_object_part_content_set(edje, part, obj);
1362 obj_info = evas_object_data_get(edje, "obj_info");
1363 obj_info->children = eina_list_append(obj_info->children, child);
1364 return LB_STATUS_SUCCESS;
1367 PUBLIC int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
1369 struct info *handle = h;
1372 edje = find_edje(handle, id);
1374 return LB_STATUS_ERROR_NOT_EXIST;
1377 elm_object_signal_emit(edje, signal, part);
1378 return LB_STATUS_SUCCESS;
1381 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1383 struct info *handle = h;
1386 edje = find_edje(handle, id);
1388 return LB_STATUS_ERROR_NOT_EXIST;
1391 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1392 return LB_STATUS_SUCCESS;
1395 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1397 struct info *handle = han;
1400 edje = find_edje(handle, id);
1402 return LB_STATUS_ERROR_NOT_EXIST;
1410 DbgPrint("Resize object to %dx%d\n", w, h);
1411 evas_object_resize(edje, w, h);
1412 return LB_STATUS_SUCCESS;
1415 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1417 struct info *handle = h;
1419 if (handle->category) {
1420 free(handle->category);
1421 handle->category = NULL;
1425 return LB_STATUS_SUCCESS;
1428 handle->category = strdup(category);
1429 if (!handle->category) {
1430 ErrPrint("Error: %s\n", strerror(errno));
1431 return LB_STATUS_ERROR_MEMORY;
1434 return LB_STATUS_SUCCESS;
1437 PUBLIC void *script_create(const char *file, const char *group)
1439 struct info *handle;
1441 handle = calloc(1, sizeof(*handle));
1443 ErrPrint("Error: %s\n", strerror(errno));
1447 handle->file = strdup(file);
1448 if (!handle->file) {
1449 ErrPrint("Error: %s\n", strerror(errno));
1454 handle->group = strdup(group);
1455 if (!handle->group) {
1456 ErrPrint("Error: %s\n", strerror(errno));
1462 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1467 PUBLIC int script_destroy(void *_handle)
1469 struct info *handle;
1474 if (!eina_list_data_find(s_info.handle_list, handle)) {
1475 DbgPrint("Not found (already deleted?)\n");
1476 return LB_STATUS_ERROR_NOT_EXIST;
1479 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1481 edje = eina_list_nth(handle->obj_list, 0);
1483 evas_object_del(edje);
1486 free(handle->category);
1488 free(handle->group);
1490 return LB_STATUS_SUCCESS;
1493 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1495 struct info *handle;
1497 struct obj_info *obj_info;
1501 obj_info = calloc(1, sizeof(*obj_info));
1503 ErrPrint("Heap: %s\n", strerror(errno));
1504 return LB_STATUS_ERROR_MEMORY;
1507 obj_info->parent = evas_object_rectangle_add(e);
1508 if (!obj_info->parent) {
1509 ErrPrint("Unable to create a parent box\n");
1511 return LB_STATUS_ERROR_FAULT;
1514 edje = elm_layout_add(obj_info->parent);
1516 ErrPrint("Failed to create an edje object\n");
1517 evas_object_del(obj_info->parent);
1519 return LB_STATUS_ERROR_FAULT;
1522 edje_object_scale_set(elm_layout_edje_get(edje), elm_config_scale_get());
1524 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1527 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1528 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, edje_load_error_str(err));
1529 evas_object_del(edje);
1530 evas_object_del(obj_info->parent);
1532 return LB_STATUS_ERROR_IO;
1539 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1540 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1541 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1542 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1543 evas_object_resize(edje, handle->w, handle->h);
1544 evas_object_show(edje);
1545 evas_object_data_set(edje, "obj_info", obj_info);
1547 handle->obj_list = eina_list_append(handle->obj_list, edje);
1548 return LB_STATUS_SUCCESS;
1551 PUBLIC int script_unload(void *_handle, Evas *e)
1553 struct info *handle;
1555 Evas_Object *parent = NULL;
1559 edje = eina_list_nth(handle->obj_list, 0);
1561 struct obj_info *obj_info;
1563 obj_info = evas_object_data_get(edje, "obj_info");
1565 parent = obj_info->parent;
1567 evas_object_del(edje);
1571 DbgPrint("Delete parent box\n");
1572 evas_object_del(parent);
1576 return LB_STATUS_SUCCESS;
1579 static void access_cb(keynode_t *node, void *user_data)
1584 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1585 ErrPrint("Idle lock state is not valid\n");
1586 state = 0; /* DISABLED */
1589 state = vconf_keynode_get_bool(node);
1592 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1593 elm_config_access_set(state);
1596 static void update_font_cb(void *data)
1598 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1599 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1602 static void font_changed_cb(keynode_t *node, void *user_data)
1606 if (s_info.font_name) {
1607 font_name = vconf_get_str("db/setting/accessibility/font_name");
1609 ErrPrint("Invalid font name (NULL)\n");
1613 if (!strcmp(s_info.font_name, font_name)) {
1614 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1619 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1620 free(s_info.font_name);
1625 * Get the first font name using system_settings API.
1628 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
1629 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
1630 ErrPrint("System setting get: %d, font_name[%p]\n", ret, font_name);
1635 s_info.font_name = font_name;
1636 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1640 * Try to update all liveboxes
1642 update_font_cb(NULL);
1645 static inline int convert_font_size(int size)
1648 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1651 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1654 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1657 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1660 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1668 DbgPrint("Return size: %d\n", size);
1672 static void font_size_cb(system_settings_key_e key, void *user_data)
1676 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE) {
1680 size = convert_font_size(size);
1682 if (size == s_info.font_size) {
1683 DbgPrint("Font size is not changed\n");
1687 s_info.font_size = size;
1688 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
1691 PUBLIC int script_init(double scale)
1699 /* ecore is already initialized */
1701 elm_config_scale_set(scale);
1702 DbgPrint("Scale is updated: %lf\n", scale);
1704 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1705 DbgPrint("TTS changed: %d\n", ret);
1707 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
1708 DbgPrint("System font is changed: %d\n", ret);
1710 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1711 DbgPrint("System font size is changed: %d\n", ret);
1713 access_cb(NULL, NULL);
1714 font_changed_cb(NULL, NULL);
1715 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
1716 return LB_STATUS_SUCCESS;
1719 PUBLIC int script_fini(void)
1724 struct info *handle;
1726 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
1727 script_destroy(handle);
1730 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1731 DbgPrint("Unset font size change event callback: %d\n", ret);
1733 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
1734 DbgPrint("Unset font name change event callback: %d\n", ret);
1736 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1737 DbgPrint("Unset tts: %d\n", ret);
1741 free(s_info.font_name);
1742 s_info.font_name = NULL;
1743 return LB_STATUS_SUCCESS;