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 * 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 == ' ') {
313 img_opt->aspect = !strncasecmp(value, "true", 4);
314 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
317 static void parse_orient(struct image_option *img_opt, const char *value, int len)
319 while (len > 0 && *value == ' ') {
327 img_opt->orient = !strncasecmp(value, "true", 4);
328 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
331 static void parse_size(struct image_option *img_opt, const char *value, int len)
337 while (len > 0 && *value == ' ') {
342 buf = strndup(value, len);
344 ErrPrint("Heap: %s\n", strerror(errno));
348 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
349 img_opt->width = width;
350 img_opt->height = height;
351 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
353 DbgPrint("Invalid size tag[%s]\n", buf);
359 static void parse_fill(struct image_option *img_opt, const char *value, int len)
361 while (len > 0 && *value == ' ') {
366 if (!strncasecmp(value, "in-size", len))
367 img_opt->fill = FILL_IN_SIZE;
368 else if (!strncasecmp(value, "over-size", len))
369 img_opt->fill = FILL_OVER_SIZE;
371 img_opt->fill = FILL_DISABLE;
373 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
376 static inline void parse_image_option(const char *option, struct image_option *img_opt)
383 void (*handler)(struct image_option *img_opt, const char *value, int len);
386 .cmd = "aspect", /* Keep the aspect ratio */
387 .handler = parse_aspect,
390 .cmd = "orient", /* Keep the orientation value: for the rotated images */
391 .handler = parse_orient,
394 .cmd = "fill", /* Fill the image to its container */
395 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
399 .handler = parse_size,
413 if (!option || !*option)
419 * GCC 4.7 warnings uninitialized idx and tag value.
420 * But it will be initialized by the state machine. :(
421 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
428 for (ptr = option; state != STATE_END; ptr++) {
443 cmd = cmd_list[tag].cmd;
449 } else if (*ptr == '\0') {
454 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
459 state = STATE_IGNORE;
462 } else if (*ptr == '\0') {
464 } else if (cmd[idx] == *ptr) {
470 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
474 cmd = cmd_list[tag].cmd;
480 if (*ptr == ';' || *ptr == '\0') {
481 cmd_list[tag].handler(img_opt, value + 1, idx);
482 state = *ptr ? STATE_START : STATE_END;
490 else if (*ptr == '\0')
499 PUBLIC int script_update_access(void *_h, Evas *e, const char *id, const char *part, const char *text, const char *option)
501 struct info *handle = _h;
503 struct obj_info *obj_info;
506 edje = find_edje(handle, id);
508 ErrPrint("No such object: %s\n", id);
509 return LB_STATUS_ERROR_NOT_EXIST;
512 obj_info = evas_object_data_get(edje, "obj_info");
514 ErrPrint("Object info is not available\n");
515 return LB_STATUS_ERROR_FAULT;
518 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
522 ao = evas_object_data_get(to, "ao");
524 if (text && strlen(text)) {
525 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
527 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
528 evas_object_data_del(to, "ao");
529 evas_object_data_del(ao, "edje");
530 elm_access_object_unregister(ao);
531 DbgPrint("Successfully unregistered\n");
533 rebuild_focus_chain(edje);
535 } else if (text && strlen(text)) {
536 ao = elm_access_object_register(to, edje);
538 ErrPrint("Unable to register access object\n");
540 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
541 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
542 evas_object_data_set(to, "ao", ao);
543 elm_object_focus_custom_chain_append(edje, ao, NULL);
544 DbgPrint("[%s] Register access info: (%s)\n", part, text);
545 evas_object_data_set(ao, "edje", edje);
546 elm_access_activate_cb_set(ao, activate_cb, NULL);
550 ErrPrint("[%s] is not exists\n", part);
553 return LB_STATUS_SUCCESS;
556 PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path, const char *option)
558 struct info *handle = _h;
563 struct obj_info *obj_info;
565 struct image_option img_opt = {
568 .fill = FILL_DISABLE,
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 img = elm_object_part_content_unset(edje, part);
591 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
592 if (child->obj != img)
595 obj_info->children = eina_list_remove(obj_info->children, child);
601 DbgPrint("delete object %s %p\n", part, img);
602 ao = evas_object_data_del(img, "ao");
604 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
605 evas_object_data_del(ao, "edje");
606 elm_access_object_unregister(ao);
607 DbgPrint("Successfully unregistered\n");
609 evas_object_del(img);
611 rebuild_focus_chain(edje);
614 if (!path || !strlen(path) || access(path, R_OK) != 0) {
615 DbgPrint("SKIP - Path: [%s]\n", path);
616 return LB_STATUS_SUCCESS;
619 child = malloc(sizeof(*child));
621 ErrPrint("Heap: %s\n", strerror(errno));
622 return LB_STATUS_ERROR_MEMORY;
625 child->part = strdup(part);
627 ErrPrint("Heap: %s\n", strerror(errno));
629 return LB_STATUS_ERROR_MEMORY;
632 img = evas_object_image_add(e);
634 ErrPrint("Failed to add an image object\n");
637 return LB_STATUS_ERROR_FAULT;
640 evas_object_image_preload(img, EINA_FALSE);
641 parse_image_option(option, &img_opt);
642 evas_object_image_load_orientation_set(img, img_opt.orient);
644 evas_object_image_file_set(img, path, NULL);
645 err = evas_object_image_load_error_get(img);
646 if (err != EVAS_LOAD_ERROR_NONE) {
647 ErrPrint("Load error: %s\n", evas_load_error_str(err));
648 evas_object_del(img);
651 return LB_STATUS_ERROR_IO;
654 evas_object_image_size_get(img, &w, &h);
655 if (img_opt.aspect) {
656 if (img_opt.fill == FILL_OVER_SIZE) {
660 if (img_opt.width >= 0 && img_opt.height >= 0) {
661 part_w = img_opt.width * scale_get();
662 part_h = img_opt.height * scale_get();
666 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
668 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
670 if (part_w > w || part_h > h) {
674 fw = (double)part_w / (double)w;
675 fh = (double)part_h / (double)h;
686 if (!part_w || !part_h || !w || !h) {
687 evas_object_del(img);
690 return LB_STATUS_ERROR_INVALID;
693 if (evas_object_image_region_support_get(img)) {
694 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
695 evas_object_image_load_size_set(img, part_w, part_h);
696 evas_object_image_filled_set(img, EINA_TRUE);
697 //evas_object_image_fill_set(img, 0, 0, part_w, part_h);
698 DbgPrint("Size: %dx%d (region: %dx%d - %dx%d)\n", w, h, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
702 Evas_Object *src_img;
706 DbgPrint("Part loading is not supported\n");
707 ee = ecore_evas_buffer_new(part_w, part_h);
709 ErrPrint("Failed to create a EE\n");
710 evas_object_del(img);
713 return LB_STATUS_ERROR_FAULT;
716 ecore_evas_alpha_set(ee, EINA_TRUE);
718 e = ecore_evas_get(ee);
720 ErrPrint("Unable to get Evas\n");
723 evas_object_del(img);
726 return LB_STATUS_ERROR_FAULT;
729 src_img = evas_object_image_filled_add(e);
731 ErrPrint("Unable to add an image\n");
734 evas_object_del(img);
737 return LB_STATUS_ERROR_FAULT;
740 evas_object_image_alpha_set(src_img, EINA_TRUE);
741 evas_object_image_colorspace_set(src_img, EVAS_COLORSPACE_ARGB8888);
742 evas_object_image_smooth_scale_set(src_img, EINA_TRUE);
743 evas_object_image_load_orientation_set(src_img, img_opt.orient);
744 evas_object_image_file_set(src_img, path, NULL);
745 err = evas_object_image_load_error_get(src_img);
746 if (err != EVAS_LOAD_ERROR_NONE) {
747 ErrPrint("Load error: %s\n", evas_load_error_str(err));
748 evas_object_del(src_img);
751 evas_object_del(img);
754 return LB_STATUS_ERROR_IO;
756 evas_object_image_size_get(src_img, &rw, &rh);
757 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
758 evas_object_resize(src_img, w, h);
759 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
760 evas_object_show(src_img);
762 data = ecore_evas_buffer_pixels_get(ee);
764 ErrPrint("Unable to get pixels\n");
765 evas_object_del(src_img);
768 evas_object_del(img);
771 return LB_STATUS_ERROR_IO;
774 e = evas_object_evas_get(img);
775 evas_object_del(img);
776 img = evas_object_image_filled_add(e);
778 evas_object_del(src_img);
783 return LB_STATUS_ERROR_MEMORY;
786 evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
787 evas_object_image_smooth_scale_set(img, EINA_TRUE);
788 evas_object_image_alpha_set(img, EINA_TRUE);
789 evas_object_image_data_set(img, NULL);
790 evas_object_image_size_set(img, part_w, part_h);
791 evas_object_resize(img, part_w, part_h);
792 evas_object_image_data_copy_set(img, (void *)data);
793 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
794 evas_object_image_data_update_add(img, 0, 0, part_w, part_h);
796 evas_object_del(src_img);
799 } else if (img_opt.fill == FILL_IN_SIZE) {
803 if (img_opt.width >= 0 && img_opt.height >= 0) {
804 part_w = img_opt.width * scale_get();
805 part_h = img_opt.height * scale_get();
809 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
811 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
813 if (part_w > w || part_h > h) {
817 fw = (double)part_w / (double)w;
818 fh = (double)part_h / (double)h;
828 DbgPrint("Size: %dx%d\n", w, h);
829 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
830 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
831 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
833 evas_object_image_fill_set(img, 0, 0, w, h);
834 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
835 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
838 if (img_opt.width >= 0 && img_opt.height >= 0) {
841 DbgPrint("Using given image size: %dx%d\n", w, h);
844 evas_object_image_fill_set(img, 0, 0, w, h);
845 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
846 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
847 evas_object_image_filled_set(img, EINA_TRUE);
852 * object will be shown by below statement automatically
854 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
856 elm_object_part_content_set(edje, part, img);
857 obj_info->children = eina_list_append(obj_info->children, child);
861 * This object is not registered as an access object.
862 * So the developer should add it to access list manually, using DESC_ACCESS block.
864 return LB_STATUS_SUCCESS;
867 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
869 struct info *handle = data;
881 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
882 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
886 sx = (double)px / (double)w;
887 ex = (double)(px + pw) / (double)w;
892 sy = (double)py / (double)h;
893 ey = (double)(py + ph) / (double)h;
896 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
899 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
901 struct info *handle = _info;
902 struct obj_info *obj_info;
903 struct obj_info *parent_obj_info;
907 handle->obj_list = eina_list_remove(handle->obj_list, obj);
909 obj_info = evas_object_data_del(obj, "obj_info");
911 ErrPrint("Object info is not valid\n");
915 DbgPrint("delete object %s %p\n", obj_info->id, obj);
916 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
917 if (parent_obj_info) {
921 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
922 if (child->obj != obj)
927 * If this code is executed,
928 * The parent is not deleted by desc, this object is deleted by itself.
929 * It is not possible, but we care it.
931 DbgPrint("Parent's children is updated: %s\n", child->part);
932 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
938 DbgPrint("Parent EDJE\n");
941 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
943 elm_object_focus_custom_chain_unset(obj);
945 EINA_LIST_FREE(obj_info->children, child) {
946 DbgPrint("delete object %s %p\n", child->part, child->obj);
949 ao = evas_object_data_del(child->obj, "ao");
951 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
952 evas_object_data_del(ao, "edje");
953 elm_access_object_unregister(ao);
955 evas_object_del(child->obj);
961 EINA_LIST_FREE(obj_info->access_chain, ao) {
962 evas_object_data_del(ao, "edje");
963 elm_access_object_unregister(ao);
971 LB_ACCESS_HIGHLIGHT 0
972 LB_ACCESS_HIGHLIGHT_NEXT 1
973 LB_ACCESS_HIGHLIGHT_PREV 2
978 PUBLIC int script_feed_event(void *h, Evas *e, int event_type, int x, int y, int down, double timestamp)
980 struct info *handle = h;
982 struct obj_info *obj_info;
983 int ret = LB_STATUS_SUCCESS;
985 edje = find_edje(handle, NULL); /*!< Get the base layout */
987 ErrPrint("Base layout is not exist\n");
988 return LB_STATUS_ERROR_NOT_EXIST;
991 obj_info = evas_object_data_get(edje, "obj_info");
993 ErrPrint("Object info is not valid\n");
994 return LB_STATUS_ERROR_INVALID;
997 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
998 Elm_Access_Action_Info *info;
999 Elm_Access_Action_Type action;
1000 const Eina_List *chain;
1002 info = calloc(1, sizeof(*info));
1004 ErrPrint("Error: %s\n", strerror(errno));
1005 return LB_STATUS_ERROR_MEMORY;
1008 chain = elm_object_focus_custom_chain_get(edje);
1009 DbgPrint("Focus chain : %d\n", eina_list_count(chain));
1011 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
1012 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1015 ret = elm_access_action(edje, action, info);
1016 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1017 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1018 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1019 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1020 info->highlight_cycle = EINA_FALSE;
1021 ret = elm_access_action(edje, action, info);
1022 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1023 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
1024 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1025 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1026 info->highlight_cycle = EINA_FALSE;
1027 ret = elm_access_action(edje, action, info);
1028 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1029 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
1030 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
1031 action = ELM_ACCESS_ACTION_ACTIVATE;
1032 ret = elm_access_action(edje, action, info);
1033 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1034 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1035 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
1037 action = ELM_ACCESS_ACTION_UP;
1038 ret = elm_access_action(edje, action, info);
1039 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1040 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1041 } else if (down == 1) {
1042 action = ELM_ACCESS_ACTION_DOWN;
1043 ret = elm_access_action(edje, action, info);
1044 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1045 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1047 ErrPrint("Invalid access event\n");
1048 ret = LB_ACCESS_STATUS_ERROR;
1050 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
1051 action = ELM_ACCESS_ACTION_SCROLL;
1056 info->mouse_type = 0;
1057 ret = elm_access_action(edje, action, info);
1058 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1059 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1062 info->mouse_type = 1;
1063 ret = elm_access_action(edje, action, info);
1064 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1065 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1068 info->mouse_type = 2;
1069 ret = elm_access_action(edje, action, info);
1070 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1071 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1074 ret = LB_ACCESS_STATUS_ERROR;
1077 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
1078 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1079 ret = elm_access_action(edje, action, info);
1080 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1081 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1083 DbgPrint("Invalid event\n");
1084 ret = LB_ACCESS_STATUS_ERROR;
1088 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
1089 switch (event_type) {
1090 case LB_SCRIPT_MOUSE_DOWN:
1091 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
1092 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1094 case LB_SCRIPT_MOUSE_MOVE:
1095 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
1097 case LB_SCRIPT_MOUSE_UP:
1098 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
1099 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.1f) * 1000, NULL);
1101 case LB_SCRIPT_MOUSE_IN:
1102 evas_event_feed_mouse_in(e, timestamp * 1000, NULL);
1104 case LB_SCRIPT_MOUSE_OUT:
1105 evas_event_feed_mouse_out(e, timestamp * 1000, NULL);
1108 return LB_STATUS_ERROR_INVALID;
1110 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
1111 DbgPrint("Key event is not implemented\n");
1112 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
1118 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)
1120 struct info *handle = h;
1123 struct obj_info *obj_info;
1124 struct child *child;
1125 char _target_id[32];
1127 edje = find_edje(handle, src_id);
1129 ErrPrint("Edje is not exists (%s)\n", src_id);
1130 return LB_STATUS_ERROR_NOT_EXIST;
1133 obj_info = evas_object_data_get(edje, "obj_info");
1135 ErrPrint("Object info is not valid\n");
1136 return LB_STATUS_ERROR_INVALID;
1139 obj = elm_object_part_content_unset(edje, part);
1144 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
1145 if (child->obj != obj)
1148 obj_info->children = eina_list_remove(obj_info->children, child);
1155 DbgPrint("delete object %s %p\n", part, obj);
1158 * This will call the edje_del_cb.
1159 * It will delete all access objects
1161 evas_object_del(obj);
1164 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1165 DbgPrint("SKIP - Path: [%s]\n", path);
1166 return LB_STATUS_SUCCESS;
1170 if (find_edje(handle, part)) {
1175 if (gettimeofday(&tv, NULL) < 0) {
1176 static int local_idx = 0;
1177 timestamp = (double)(local_idx++);
1179 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1182 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1183 } while (find_edje(handle, _target_id));
1185 target_id = _target_id;
1190 DbgPrint("Anonymouse target id: %s\n", target_id);
1193 obj = elm_layout_add(edje);
1195 ErrPrint("Failed to add a new edje object\n");
1196 return LB_STATUS_ERROR_FAULT;
1199 if (!elm_layout_file_set(obj, path, group)) {
1203 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1204 errmsg = edje_load_error_str(err);
1205 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
1206 evas_object_del(obj);
1207 return LB_STATUS_ERROR_IO;
1210 evas_object_show(obj);
1212 obj_info = calloc(1, sizeof(*obj_info));
1214 ErrPrint("Failed to add a obj_info\n");
1215 evas_object_del(obj);
1216 return LB_STATUS_ERROR_MEMORY;
1219 obj_info->id = strdup(target_id);
1220 if (!obj_info->id) {
1221 ErrPrint("Failed to add a obj_info\n");
1223 evas_object_del(obj);
1224 return LB_STATUS_ERROR_MEMORY;
1227 obj_info->parent = edje;
1229 child = malloc(sizeof(*child));
1231 ErrPrint("Error: %s\n", strerror(errno));
1234 evas_object_del(obj);
1235 return LB_STATUS_ERROR_MEMORY;
1238 child->part = strdup(part);
1240 ErrPrint("Error: %s\n", strerror(errno));
1244 evas_object_del(obj);
1245 return LB_STATUS_ERROR_MEMORY;
1250 evas_object_data_set(obj, "obj_info", obj_info);
1251 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1252 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1253 handle->obj_list = eina_list_append(handle->obj_list, obj);
1255 DbgPrint("%s part swallow edje %p\n", part, obj);
1256 elm_object_part_content_set(edje, part, obj);
1258 obj_info = evas_object_data_get(edje, "obj_info");
1259 obj_info->children = eina_list_append(obj_info->children, child);
1260 return LB_STATUS_SUCCESS;
1263 PUBLIC int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
1265 struct info *handle = h;
1268 edje = find_edje(handle, id);
1270 return LB_STATUS_ERROR_NOT_EXIST;
1272 elm_object_signal_emit(edje, signal, part);
1273 return LB_STATUS_SUCCESS;
1276 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1278 struct info *handle = h;
1281 edje = find_edje(handle, id);
1283 return LB_STATUS_ERROR_NOT_EXIST;
1285 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1286 return LB_STATUS_SUCCESS;
1289 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1291 struct info *handle = han;
1294 edje = find_edje(handle, id);
1296 return LB_STATUS_ERROR_NOT_EXIST;
1303 DbgPrint("Resize object to %dx%d\n", w, h);
1304 evas_object_resize(edje, w, h);
1305 return LB_STATUS_SUCCESS;
1308 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1310 struct info *handle = h;
1312 if (handle->category) {
1313 free(handle->category);
1314 handle->category = NULL;
1318 return LB_STATUS_SUCCESS;
1320 handle->category = strdup(category);
1321 if (!handle->category) {
1322 ErrPrint("Error: %s\n", strerror(errno));
1323 return LB_STATUS_ERROR_MEMORY;
1326 return LB_STATUS_SUCCESS;
1329 PUBLIC void *script_create(const char *file, const char *group)
1331 struct info *handle;
1333 handle = calloc(1, sizeof(*handle));
1335 ErrPrint("Error: %s\n", strerror(errno));
1339 handle->file = strdup(file);
1340 if (!handle->file) {
1341 ErrPrint("Error: %s\n", strerror(errno));
1346 handle->group = strdup(group);
1347 if (!handle->group) {
1348 ErrPrint("Error: %s\n", strerror(errno));
1354 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1359 PUBLIC int script_destroy(void *_handle)
1361 struct info *handle;
1366 if (!eina_list_data_find(s_info.handle_list, handle)) {
1367 DbgPrint("Not found (already deleted?)\n");
1368 return LB_STATUS_ERROR_NOT_EXIST;
1371 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1373 edje = eina_list_nth(handle->obj_list, 0);
1375 evas_object_del(edje);
1377 free(handle->category);
1379 free(handle->group);
1381 return LB_STATUS_SUCCESS;
1384 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1386 struct info *handle;
1388 struct obj_info *obj_info;
1392 obj_info = calloc(1, sizeof(*obj_info));
1394 ErrPrint("Heap: %s\n", strerror(errno));
1395 return LB_STATUS_ERROR_MEMORY;
1398 obj_info->parent = evas_object_rectangle_add(e);
1399 if (!obj_info->parent) {
1400 ErrPrint("Unable to create a parent box\n");
1402 return LB_STATUS_ERROR_FAULT;
1405 edje = elm_layout_add(obj_info->parent);
1407 ErrPrint("Failed to create an edje object\n");
1408 evas_object_del(obj_info->parent);
1410 return LB_STATUS_ERROR_FAULT;
1413 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1417 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1418 errmsg = edje_load_error_str(err);
1419 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
1420 evas_object_del(edje);
1421 evas_object_del(obj_info->parent);
1423 return LB_STATUS_ERROR_IO;
1430 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1431 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1432 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1433 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1434 evas_object_resize(edje, handle->w, handle->h);
1435 evas_object_show(edje);
1436 evas_object_data_set(edje, "obj_info", obj_info);
1438 handle->obj_list = eina_list_append(handle->obj_list, edje);
1439 return LB_STATUS_SUCCESS;
1442 PUBLIC int script_unload(void *_handle, Evas *e)
1444 struct info *handle;
1446 Evas_Object *parent = NULL;
1450 edje = eina_list_nth(handle->obj_list, 0);
1452 struct obj_info *obj_info;
1454 obj_info = evas_object_data_get(edje, "obj_info");
1456 parent = obj_info->parent;
1457 evas_object_del(edje);
1461 DbgPrint("Delete parent box\n");
1462 evas_object_del(parent);
1466 return LB_STATUS_SUCCESS;
1469 static void access_cb(keynode_t *node, void *user_data)
1474 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1475 ErrPrint("Idle lock state is not valid\n");
1476 state = 0; /* DISABLED */
1479 state = vconf_keynode_get_bool(node);
1482 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1483 elm_config_access_set(state);
1486 static void update_font_cb(void *data)
1488 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1489 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1492 static void font_changed_cb(keynode_t *node, void *user_data)
1496 if (s_info.font_name) {
1497 font_name = vconf_get_str("db/setting/accessibility/font_name");
1499 ErrPrint("Invalid font name (NULL)\n");
1503 if (!strcmp(s_info.font_name, font_name)) {
1504 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1509 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1510 free(s_info.font_name);
1515 * Get the first font name using system_settings API.
1518 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
1519 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
1520 ErrPrint("System setting get: %d, font_name[%p]\n", ret, font_name);
1525 s_info.font_name = font_name;
1526 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1530 * Try to update all liveboxes
1532 update_font_cb(NULL);
1535 static inline int convert_font_size(int size)
1538 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1541 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1544 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1547 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1550 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1558 DbgPrint("Return size: %d\n", size);
1562 static void font_size_cb(system_settings_key_e key, void *user_data)
1566 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE)
1569 size = convert_font_size(size);
1571 if (size == s_info.font_size) {
1572 DbgPrint("Font size is not changed\n");
1576 s_info.font_size = size;
1577 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
1580 PUBLIC int script_init(void)
1588 /* ecore is already initialized */
1590 elm_config_scale_set(scale_get());
1592 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1593 DbgPrint("TTS changed: %d\n", ret);
1595 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
1596 DbgPrint("System font is changed: %d\n", ret);
1598 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1599 DbgPrint("System font size is changed: %d\n", ret);
1601 access_cb(NULL, NULL);
1602 font_changed_cb(NULL, NULL);
1603 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
1604 return LB_STATUS_SUCCESS;
1607 PUBLIC int script_fini(void)
1612 struct info *handle;
1614 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
1615 script_destroy(handle);
1618 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1619 DbgPrint("Unset font size change event callback: %d\n", ret);
1621 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
1622 DbgPrint("Unset font name change event callback: %d\n", ret);
1624 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1625 DbgPrint("Unset tts: %d\n", ret);
1629 free(s_info.font_name);
1630 s_info.font_name = NULL;
1631 return LB_STATUS_SUCCESS;