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
44 #define BASE_WIDTH 720.0f
46 #define PUBLIC __attribute__((visibility("default")))
82 Eina_List *access_chain;
89 Eina_List *handle_list;
97 static inline double scale_get(void)
101 ecore_x_window_size_get(0, &width, &height);
102 return (double)width / BASE_WIDTH;
105 static inline Evas_Object *find_edje(struct info *handle, const char *id)
109 struct obj_info *obj_info;
111 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
112 obj_info = evas_object_data_get(edje, "obj_info");
114 ErrPrint("Object info is not valid\n");
123 } else if (!obj_info->id) {
127 if (!strcmp(obj_info->id, id))
131 DbgPrint("EDJE[%s] is not found\n", id);
135 static inline void rebuild_focus_chain(Evas_Object *obj)
137 struct obj_info *obj_info;
141 obj_info = evas_object_data_get(obj, "obj_info");
143 ErrPrint("Object info is not available\n");
147 elm_object_focus_custom_chain_unset(obj);
149 EINA_LIST_FOREACH(obj_info->access_chain, l, ao) {
150 DbgPrint("Append %p\n", ao);
151 elm_object_focus_custom_chain_append(obj, ao, NULL);
155 PUBLIC const char *script_magic_id(void)
160 PUBLIC int script_update_color(void *h, Evas *e, const char *id, const char *part, const char *rgba)
162 struct info *handle = h;
164 int r[3], g[3], b[3], a[3];
167 edje = find_edje(handle, id);
169 return LB_STATUS_ERROR_NOT_EXIST;
171 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
172 r, g, b, a, /* OBJECT */
173 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
174 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
176 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
177 return LB_STATUS_ERROR_INVALID;
180 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
181 r[0], g[0], b[0], a[0], /* OBJECT */
182 r[1], g[1], b[1], a[1], /* OUTLINE */
183 r[2], g[2], b[2], a[2]); /* SHADOW */
185 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
186 return LB_STATUS_SUCCESS;
189 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
201 ao = evas_object_data_get(part_obj, "ao");
205 edje = evas_object_data_get(ao, "edje");
209 e = evas_object_evas_get(part_obj);
210 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
214 if (gettimeofday(&tv, NULL) < 0) {
215 ErrPrint("Failed to get time\n");
218 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, NULL);
223 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
224 evas_event_feed_mouse_move(e, x, y, timestamp + 0.02f, NULL);
225 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.03f, 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);
294 DbgPrint("[%s] Update access object (%s)\n", part, utf8);
297 ErrPrint("Unable to get text part[%s]\n", part);
301 return LB_STATUS_SUCCESS;
304 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
306 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 == ' ') {
328 img_opt->orient = !strncasecmp(value, "true", 4);
329 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
332 static void parse_size(struct image_option *img_opt, const char *value, int len)
338 while (len > 0 && *value == ' ') {
343 buf = strndup(value, len);
345 ErrPrint("Heap: %s\n", strerror(errno));
349 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
350 img_opt->width = width;
351 img_opt->height = height;
352 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
354 DbgPrint("Invalid size tag[%s]\n", buf);
360 static void parse_fill(struct image_option *img_opt, const char *value, int len)
362 while (len > 0 && *value == ' ') {
367 if (!strncasecmp(value, "in-size", len))
368 img_opt->fill = FILL_IN_SIZE;
369 else if (!strncasecmp(value, "over-size", len))
370 img_opt->fill = FILL_OVER_SIZE;
372 img_opt->fill = FILL_DISABLE;
374 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
377 static inline void parse_image_option(const char *option, struct image_option *img_opt)
384 void (*handler)(struct image_option *img_opt, const char *value, int len);
387 .cmd = "aspect", /* Keep the aspect ratio */
388 .handler = parse_aspect,
391 .cmd = "orient", /* Keep the orientation value: for the rotated images */
392 .handler = parse_orient,
395 .cmd = "fill", /* Fill the image to its container */
396 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
400 .handler = parse_size,
414 if (!option || !*option)
420 * GCC 4.7 warnings uninitialized idx and tag value.
421 * But it will be initialized by the state machine. :(
422 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
429 for (ptr = option; state != STATE_END; ptr++) {
444 cmd = cmd_list[tag].cmd;
450 } else if (*ptr == '\0') {
455 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
460 state = STATE_IGNORE;
463 } else if (*ptr == '\0') {
465 } else if (cmd[idx] == *ptr) {
471 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
475 cmd = cmd_list[tag].cmd;
481 if (*ptr == ';' || *ptr == '\0') {
482 cmd_list[tag].handler(img_opt, value + 1, idx);
483 state = *ptr ? STATE_START : STATE_END;
491 else if (*ptr == '\0')
500 PUBLIC int script_update_access(void *_h, Evas *e, const char *id, const char *part, const char *text, const char *option)
502 struct info *handle = _h;
504 struct obj_info *obj_info;
507 edje = find_edje(handle, id);
509 ErrPrint("No such object: %s\n", id);
510 return LB_STATUS_ERROR_NOT_EXIST;
513 obj_info = evas_object_data_get(edje, "obj_info");
515 ErrPrint("Object info is not available\n");
516 return LB_STATUS_ERROR_FAULT;
519 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
523 ao = evas_object_data_get(to, "ao");
525 DbgPrint("[%s] Update access object (%s)\n", part, text);
526 if (text && strlen(text)) {
527 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
529 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
530 evas_object_data_del(to, "ao");
531 evas_object_data_del(ao, "edje");
532 elm_access_object_unregister(ao);
533 DbgPrint("Successfully unregistered\n");
535 rebuild_focus_chain(edje);
537 } else if (text && strlen(text)) {
538 ao = elm_access_object_register(to, edje);
540 ErrPrint("Unable to register access object\n");
542 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
543 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
544 evas_object_data_set(to, "ao", ao);
545 elm_object_focus_custom_chain_append(edje, ao, NULL);
546 DbgPrint("[%s] Register access info: (%s)\n", part, text);
547 evas_object_data_set(ao, "edje", edje);
548 elm_access_activate_cb_set(ao, activate_cb, NULL);
552 ErrPrint("[%s] is not exists\n", part);
555 return LB_STATUS_SUCCESS;
558 PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path, const char *option)
560 struct info *handle = _h;
565 struct obj_info *obj_info;
567 struct image_option img_opt = {
570 .fill = FILL_DISABLE,
575 edje = find_edje(handle, id);
577 ErrPrint("No such object: %s\n", id);
578 return LB_STATUS_ERROR_NOT_EXIST;
581 obj_info = evas_object_data_get(edje, "obj_info");
583 ErrPrint("Object info is not available\n");
584 return LB_STATUS_ERROR_FAULT;
587 img = elm_object_part_content_unset(edje, part);
593 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
594 if (child->obj != img)
597 obj_info->children = eina_list_remove(obj_info->children, child);
603 DbgPrint("delete object %s %p\n", part, img);
604 ao = evas_object_data_del(img, "ao");
606 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
607 evas_object_data_del(ao, "edje");
608 elm_access_object_unregister(ao);
609 DbgPrint("Successfully unregistered\n");
611 evas_object_del(img);
613 rebuild_focus_chain(edje);
616 if (!path || !strlen(path) || access(path, R_OK) != 0) {
617 DbgPrint("SKIP - Path: [%s]\n", path);
618 return LB_STATUS_SUCCESS;
621 child = malloc(sizeof(*child));
623 ErrPrint("Heap: %s\n", strerror(errno));
624 return LB_STATUS_ERROR_MEMORY;
627 child->part = strdup(part);
629 ErrPrint("Heap: %s\n", strerror(errno));
631 return LB_STATUS_ERROR_MEMORY;
634 img = evas_object_image_add(e);
636 ErrPrint("Failed to add an image object\n");
639 return LB_STATUS_ERROR_FAULT;
642 evas_object_image_preload(img, EINA_FALSE);
643 parse_image_option(option, &img_opt);
644 evas_object_image_load_orientation_set(img, img_opt.orient);
646 evas_object_image_file_set(img, path, NULL);
647 err = evas_object_image_load_error_get(img);
648 if (err != EVAS_LOAD_ERROR_NONE) {
649 ErrPrint("Load error: %s\n", evas_load_error_str(err));
650 evas_object_del(img);
653 return LB_STATUS_ERROR_IO;
656 evas_object_image_size_get(img, &w, &h);
657 if (img_opt.aspect) {
658 if (img_opt.fill == FILL_OVER_SIZE) {
662 if (img_opt.width >= 0 && img_opt.height >= 0) {
663 part_w = img_opt.width * scale_get();
664 part_h = img_opt.height * scale_get();
668 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
670 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
672 if (part_w > w || part_h > h) {
676 fw = (double)part_w / (double)w;
677 fh = (double)part_h / (double)h;
688 if (!part_w || !part_h || !w || !h) {
689 evas_object_del(img);
692 return LB_STATUS_ERROR_INVALID;
695 if (evas_object_image_region_support_get(img)) {
696 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
697 evas_object_image_load_size_set(img, part_w, part_h);
698 evas_object_image_filled_set(img, EINA_TRUE);
699 //evas_object_image_fill_set(img, 0, 0, part_w, part_h);
700 DbgPrint("Size: %dx%d (region: %dx%d - %dx%d)\n", w, h, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
704 Evas_Object *src_img;
708 DbgPrint("Part loading is not supported\n");
709 ee = ecore_evas_buffer_new(part_w, part_h);
711 ErrPrint("Failed to create a EE\n");
712 evas_object_del(img);
715 return LB_STATUS_ERROR_FAULT;
718 ecore_evas_alpha_set(ee, EINA_TRUE);
720 e = ecore_evas_get(ee);
722 ErrPrint("Unable to get Evas\n");
725 evas_object_del(img);
728 return LB_STATUS_ERROR_FAULT;
731 src_img = evas_object_image_filled_add(e);
733 ErrPrint("Unable to add an image\n");
736 evas_object_del(img);
739 return LB_STATUS_ERROR_FAULT;
742 evas_object_image_alpha_set(src_img, EINA_TRUE);
743 evas_object_image_colorspace_set(src_img, EVAS_COLORSPACE_ARGB8888);
744 evas_object_image_smooth_scale_set(src_img, EINA_TRUE);
745 evas_object_image_load_orientation_set(src_img, img_opt.orient);
746 evas_object_image_file_set(src_img, path, NULL);
747 err = evas_object_image_load_error_get(src_img);
748 if (err != EVAS_LOAD_ERROR_NONE) {
749 ErrPrint("Load error: %s\n", evas_load_error_str(err));
750 evas_object_del(src_img);
753 evas_object_del(img);
756 return LB_STATUS_ERROR_IO;
758 evas_object_image_size_get(src_img, &rw, &rh);
759 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
760 evas_object_resize(src_img, w, h);
761 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
762 evas_object_show(src_img);
764 data = ecore_evas_buffer_pixels_get(ee);
766 ErrPrint("Unable to get pixels\n");
767 evas_object_del(src_img);
770 evas_object_del(img);
773 return LB_STATUS_ERROR_IO;
776 e = evas_object_evas_get(img);
777 evas_object_del(img);
778 img = evas_object_image_filled_add(e);
780 evas_object_del(src_img);
785 return LB_STATUS_ERROR_MEMORY;
788 evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
789 evas_object_image_smooth_scale_set(img, EINA_TRUE);
790 evas_object_image_alpha_set(img, EINA_TRUE);
791 evas_object_image_data_set(img, NULL);
792 evas_object_image_size_set(img, part_w, part_h);
793 evas_object_resize(img, part_w, part_h);
794 evas_object_image_data_copy_set(img, (void *)data);
795 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
796 evas_object_image_data_update_add(img, 0, 0, part_w, part_h);
798 evas_object_del(src_img);
801 } else if (img_opt.fill == FILL_IN_SIZE) {
805 if (img_opt.width >= 0 && img_opt.height >= 0) {
806 part_w = img_opt.width * scale_get();
807 part_h = img_opt.height * scale_get();
811 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
813 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
815 if (part_w > w || part_h > h) {
819 fw = (double)part_w / (double)w;
820 fh = (double)part_h / (double)h;
830 DbgPrint("Size: %dx%d\n", w, h);
831 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
832 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
833 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
835 evas_object_image_fill_set(img, 0, 0, w, h);
836 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
837 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
840 if (img_opt.width >= 0 && img_opt.height >= 0) {
843 DbgPrint("Using given image size: %dx%d\n", w, h);
846 evas_object_image_fill_set(img, 0, 0, w, h);
847 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
848 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
849 evas_object_image_filled_set(img, EINA_TRUE);
854 * object will be shown by below statement automatically
856 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
858 elm_object_part_content_set(edje, part, img);
859 obj_info->children = eina_list_append(obj_info->children, child);
863 * This object is not registered as an access object.
864 * So the developer should add it to access list manually, using DESC_ACCESS block.
866 return LB_STATUS_SUCCESS;
869 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
871 struct info *handle = data;
883 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
884 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
888 sx = (double)px / (double)w;
889 ex = (double)(px + pw) / (double)w;
894 sy = (double)py / (double)h;
895 ey = (double)(py + ph) / (double)h;
898 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
901 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
903 struct info *handle = _info;
904 struct obj_info *obj_info;
905 struct obj_info *parent_obj_info;
909 handle->obj_list = eina_list_remove(handle->obj_list, obj);
911 obj_info = evas_object_data_del(obj, "obj_info");
913 ErrPrint("Object info is not valid\n");
917 DbgPrint("delete object %s %p\n", obj_info->id, obj);
918 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
919 if (parent_obj_info) {
923 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
924 if (child->obj != obj)
929 * If this code is executed,
930 * The parent is not deleted by desc, this object is deleted by itself.
931 * It is not possible, but we care it.
933 DbgPrint("Parent's children is updated: %s\n", child->part);
934 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
940 DbgPrint("Parent EDJE\n");
943 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
945 elm_object_focus_custom_chain_unset(obj);
947 EINA_LIST_FREE(obj_info->children, child) {
948 DbgPrint("delete object %s %p\n", child->part, child->obj);
951 ao = evas_object_data_del(child->obj, "ao");
953 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
954 evas_object_data_del(ao, "edje");
955 elm_access_object_unregister(ao);
957 evas_object_del(child->obj);
963 EINA_LIST_FREE(obj_info->access_chain, ao) {
964 evas_object_data_del(ao, "edje");
965 elm_access_object_unregister(ao);
973 LB_ACCESS_HIGHLIGHT 0
974 LB_ACCESS_HIGHLIGHT_NEXT 1
975 LB_ACCESS_HIGHLIGHT_PREV 2
980 PUBLIC int script_feed_event(void *h, Evas *e, int event_type, int x, int y, int down, double timestamp)
982 struct info *handle = h;
984 struct obj_info *obj_info;
985 int ret = LB_STATUS_SUCCESS;
987 edje = find_edje(handle, NULL); /*!< Get the base layout */
989 ErrPrint("Base layout is not exist\n");
990 return LB_STATUS_ERROR_NOT_EXIST;
993 obj_info = evas_object_data_get(edje, "obj_info");
995 ErrPrint("Object info is not valid\n");
996 return LB_STATUS_ERROR_INVALID;
999 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
1000 Elm_Access_Action_Info *info;
1001 Elm_Access_Action_Type action;
1002 const Eina_List *chain;
1004 info = calloc(1, sizeof(*info));
1006 ErrPrint("Error: %s\n", strerror(errno));
1007 return LB_STATUS_ERROR_MEMORY;
1010 chain = elm_object_focus_custom_chain_get(edje);
1011 DbgPrint("Focus chain : %d\n", eina_list_count(chain));
1013 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
1014 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1017 ret = elm_access_action(edje, action, info);
1018 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1019 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1020 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1021 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1022 info->highlight_cycle = EINA_FALSE;
1023 ret = elm_access_action(edje, action, info);
1024 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1025 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
1026 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1027 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1028 info->highlight_cycle = EINA_FALSE;
1029 ret = elm_access_action(edje, action, info);
1030 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1031 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
1032 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
1033 action = ELM_ACCESS_ACTION_ACTIVATE;
1034 ret = elm_access_action(edje, action, info);
1035 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1036 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1037 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
1039 action = ELM_ACCESS_ACTION_UP;
1040 ret = elm_access_action(edje, action, info);
1041 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1042 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1043 } else if (down == 1) {
1044 action = ELM_ACCESS_ACTION_DOWN;
1045 ret = elm_access_action(edje, action, info);
1046 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1047 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1049 ErrPrint("Invalid access event\n");
1050 ret = LB_ACCESS_STATUS_ERROR;
1052 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
1053 action = ELM_ACCESS_ACTION_SCROLL;
1058 info->mouse_type = 0;
1059 ret = elm_access_action(edje, action, info);
1060 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1061 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1064 info->mouse_type = 1;
1065 ret = elm_access_action(edje, action, info);
1066 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1067 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1070 info->mouse_type = 2;
1071 ret = elm_access_action(edje, action, info);
1072 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1073 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1076 ret = LB_ACCESS_STATUS_ERROR;
1079 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
1080 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1081 ret = elm_access_action(edje, action, info);
1082 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1083 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1085 DbgPrint("Invalid event\n");
1086 ret = LB_ACCESS_STATUS_ERROR;
1090 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
1091 switch (event_type) {
1092 case LB_SCRIPT_MOUSE_DOWN:
1093 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
1094 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
1096 case LB_SCRIPT_MOUSE_MOVE:
1097 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
1099 case LB_SCRIPT_MOUSE_UP:
1100 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
1101 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.1f, NULL);
1103 case LB_SCRIPT_MOUSE_IN:
1104 evas_event_feed_mouse_in(e, timestamp, NULL);
1106 case LB_SCRIPT_MOUSE_OUT:
1107 evas_event_feed_mouse_out(e, timestamp, NULL);
1110 return LB_STATUS_ERROR_INVALID;
1112 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
1113 DbgPrint("Key event is not implemented\n");
1114 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
1120 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)
1122 struct info *handle = h;
1125 struct obj_info *obj_info;
1126 struct child *child;
1127 char _target_id[32];
1129 edje = find_edje(handle, src_id);
1131 ErrPrint("Edje is not exists (%s)\n", src_id);
1132 return LB_STATUS_ERROR_NOT_EXIST;
1135 obj_info = evas_object_data_get(edje, "obj_info");
1137 ErrPrint("Object info is not valid\n");
1138 return LB_STATUS_ERROR_INVALID;
1141 obj = elm_object_part_content_unset(edje, part);
1146 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
1147 if (child->obj != obj)
1150 obj_info->children = eina_list_remove(obj_info->children, child);
1157 DbgPrint("delete object %s %p\n", part, obj);
1160 * This will call the edje_del_cb.
1161 * It will delete all access objects
1163 evas_object_del(obj);
1166 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1167 DbgPrint("SKIP - Path: [%s]\n", path);
1168 return LB_STATUS_SUCCESS;
1172 if (find_edje(handle, part)) {
1177 if (gettimeofday(&tv, NULL) < 0) {
1178 static int local_idx = 0;
1179 timestamp = (double)(local_idx++);
1181 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1184 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1185 } while (find_edje(handle, _target_id));
1187 target_id = _target_id;
1192 DbgPrint("Anonymouse target id: %s\n", target_id);
1195 obj = elm_layout_add(edje);
1197 ErrPrint("Failed to add a new edje object\n");
1198 return LB_STATUS_ERROR_FAULT;
1201 if (!elm_layout_file_set(obj, path, group)) {
1205 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1206 errmsg = edje_load_error_str(err);
1207 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
1208 evas_object_del(obj);
1209 return LB_STATUS_ERROR_IO;
1212 evas_object_show(obj);
1214 obj_info = calloc(1, sizeof(*obj_info));
1216 ErrPrint("Failed to add a obj_info\n");
1217 evas_object_del(obj);
1218 return LB_STATUS_ERROR_MEMORY;
1221 obj_info->id = strdup(target_id);
1222 if (!obj_info->id) {
1223 ErrPrint("Failed to add a obj_info\n");
1225 evas_object_del(obj);
1226 return LB_STATUS_ERROR_MEMORY;
1229 obj_info->parent = edje;
1231 child = malloc(sizeof(*child));
1233 ErrPrint("Error: %s\n", strerror(errno));
1236 evas_object_del(obj);
1237 return LB_STATUS_ERROR_MEMORY;
1240 child->part = strdup(part);
1242 ErrPrint("Error: %s\n", strerror(errno));
1246 evas_object_del(obj);
1247 return LB_STATUS_ERROR_MEMORY;
1252 evas_object_data_set(obj, "obj_info", obj_info);
1253 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1254 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1255 handle->obj_list = eina_list_append(handle->obj_list, obj);
1257 DbgPrint("%s part swallow edje %p\n", part, obj);
1258 elm_object_part_content_set(edje, part, obj);
1260 obj_info = evas_object_data_get(edje, "obj_info");
1261 obj_info->children = eina_list_append(obj_info->children, child);
1262 return LB_STATUS_SUCCESS;
1265 PUBLIC int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
1267 struct info *handle = h;
1270 edje = find_edje(handle, id);
1272 return LB_STATUS_ERROR_NOT_EXIST;
1274 elm_object_signal_emit(edje, signal, part);
1275 return LB_STATUS_SUCCESS;
1278 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1280 struct info *handle = h;
1283 edje = find_edje(handle, id);
1285 return LB_STATUS_ERROR_NOT_EXIST;
1287 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1288 return LB_STATUS_SUCCESS;
1291 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1293 struct info *handle = han;
1296 edje = find_edje(handle, id);
1298 return LB_STATUS_ERROR_NOT_EXIST;
1305 DbgPrint("Resize object to %dx%d\n", w, h);
1306 evas_object_resize(edje, w, h);
1307 return LB_STATUS_SUCCESS;
1310 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1312 struct info *handle = h;
1314 if (handle->category) {
1315 free(handle->category);
1316 handle->category = NULL;
1320 return LB_STATUS_SUCCESS;
1322 handle->category = strdup(category);
1323 if (!handle->category) {
1324 ErrPrint("Error: %s\n", strerror(errno));
1325 return LB_STATUS_ERROR_MEMORY;
1328 return LB_STATUS_SUCCESS;
1331 PUBLIC void *script_create(const char *file, const char *group)
1333 struct info *handle;
1335 handle = calloc(1, sizeof(*handle));
1337 ErrPrint("Error: %s\n", strerror(errno));
1341 handle->file = strdup(file);
1342 if (!handle->file) {
1343 ErrPrint("Error: %s\n", strerror(errno));
1348 handle->group = strdup(group);
1349 if (!handle->group) {
1350 ErrPrint("Error: %s\n", strerror(errno));
1356 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1361 PUBLIC int script_destroy(void *_handle)
1363 struct info *handle;
1368 if (!eina_list_data_find(s_info.handle_list, handle)) {
1369 DbgPrint("Not found (already deleted?)\n");
1370 return LB_STATUS_ERROR_NOT_EXIST;
1373 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1375 edje = eina_list_nth(handle->obj_list, 0);
1377 evas_object_del(edje);
1379 free(handle->category);
1381 free(handle->group);
1383 return LB_STATUS_SUCCESS;
1386 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1388 struct info *handle;
1390 struct obj_info *obj_info;
1394 obj_info = calloc(1, sizeof(*obj_info));
1396 ErrPrint("Heap: %s\n", strerror(errno));
1397 return LB_STATUS_ERROR_MEMORY;
1400 obj_info->parent = evas_object_rectangle_add(e);
1401 if (!obj_info->parent) {
1402 ErrPrint("Unable to create a parent box\n");
1404 return LB_STATUS_ERROR_FAULT;
1407 edje = elm_layout_add(obj_info->parent);
1409 ErrPrint("Failed to create an edje object\n");
1410 evas_object_del(obj_info->parent);
1412 return LB_STATUS_ERROR_FAULT;
1415 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1419 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1420 errmsg = edje_load_error_str(err);
1421 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
1422 evas_object_del(edje);
1423 evas_object_del(obj_info->parent);
1425 return LB_STATUS_ERROR_IO;
1432 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1433 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1434 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1435 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1436 evas_object_resize(edje, handle->w, handle->h);
1437 evas_object_show(edje);
1438 evas_object_data_set(edje, "obj_info", obj_info);
1440 handle->obj_list = eina_list_append(handle->obj_list, edje);
1441 return LB_STATUS_SUCCESS;
1444 PUBLIC int script_unload(void *_handle, Evas *e)
1446 struct info *handle;
1448 Evas_Object *parent = NULL;
1452 edje = eina_list_nth(handle->obj_list, 0);
1454 struct obj_info *obj_info;
1456 obj_info = evas_object_data_get(edje, "obj_info");
1458 parent = obj_info->parent;
1459 evas_object_del(edje);
1463 DbgPrint("Delete parent box\n");
1464 evas_object_del(parent);
1468 return LB_STATUS_SUCCESS;
1471 static void access_cb(keynode_t *node, void *user_data)
1476 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1477 ErrPrint("Idle lock state is not valid\n");
1478 state = 0; /* DISABLED */
1481 state = vconf_keynode_get_bool(node);
1484 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1485 elm_config_access_set(state);
1488 static void update_font_cb(void *data)
1490 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1491 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1494 static void font_changed_cb(keynode_t *node, void *user_data)
1498 if (s_info.font_name) {
1499 font_name = vconf_get_str("db/setting/accessibility/font_name");
1501 ErrPrint("Invalid font name (NULL)\n");
1505 if (!strcmp(s_info.font_name, font_name)) {
1506 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1511 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1512 free(s_info.font_name);
1517 * Get the first font name using system_settings API.
1520 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
1521 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
1522 ErrPrint("System setting get: %d, font_name[%p]\n", ret, font_name);
1527 s_info.font_name = font_name;
1528 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1532 * Try to update all liveboxes
1534 update_font_cb(NULL);
1537 static inline int convert_font_size(int size)
1540 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1543 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1546 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1549 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1552 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1560 DbgPrint("Return size: %d\n", size);
1564 static void font_size_cb(system_settings_key_e key, void *user_data)
1568 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE)
1571 size = convert_font_size(size);
1573 if (size == s_info.font_size) {
1574 DbgPrint("Font size is not changed\n");
1578 s_info.font_size = size;
1579 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
1582 PUBLIC int script_init(void)
1590 /* ecore is already initialized */
1592 elm_config_scale_set(scale_get());
1594 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1595 DbgPrint("TTS changed: %d\n", ret);
1597 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
1598 DbgPrint("System font is changed: %d\n", ret);
1600 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1601 DbgPrint("System font size is changed: %d\n", ret);
1603 access_cb(NULL, NULL);
1604 font_changed_cb(NULL, NULL);
1605 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
1606 return LB_STATUS_SUCCESS;
1609 PUBLIC int script_fini(void)
1614 struct info *handle;
1616 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
1617 script_destroy(handle);
1620 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1621 DbgPrint("Unset font size change event callback: %d\n", ret);
1623 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
1624 DbgPrint("Unset font name change event callback: %d\n", ret);
1626 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1627 DbgPrint("Unset tts: %d\n", ret);
1631 free(s_info.font_name);
1632 s_info.font_name = NULL;
1633 return LB_STATUS_SUCCESS;