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_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path, const char *option)
563 struct info *handle = _h;
568 struct obj_info *obj_info;
570 struct image_option img_opt = {
573 .fill = FILL_DISABLE,
578 edje = find_edje(handle, id);
580 ErrPrint("No such object: %s\n", id);
581 return LB_STATUS_ERROR_NOT_EXIST;
584 obj_info = evas_object_data_get(edje, "obj_info");
586 ErrPrint("Object info is not available\n");
587 return LB_STATUS_ERROR_FAULT;
590 img = elm_object_part_content_unset(edje, part);
596 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
597 if (child->obj != img) {
601 obj_info->children = eina_list_remove(obj_info->children, child);
607 DbgPrint("delete object %s %p\n", part, img);
608 ao = evas_object_data_del(img, "ao");
610 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
611 evas_object_data_del(ao, "edje");
612 elm_access_object_unregister(ao);
613 DbgPrint("Successfully unregistered\n");
615 evas_object_del(img);
617 rebuild_focus_chain(edje);
620 if (!path || !strlen(path) || access(path, R_OK) != 0) {
621 DbgPrint("SKIP - Path: [%s]\n", path);
622 return LB_STATUS_SUCCESS;
625 child = malloc(sizeof(*child));
627 ErrPrint("Heap: %s\n", strerror(errno));
628 return LB_STATUS_ERROR_MEMORY;
631 child->part = strdup(part);
633 ErrPrint("Heap: %s\n", strerror(errno));
635 return LB_STATUS_ERROR_MEMORY;
638 img = evas_object_image_add(e);
640 ErrPrint("Failed to add an image object\n");
643 return LB_STATUS_ERROR_FAULT;
646 evas_object_image_preload(img, EINA_FALSE);
647 parse_image_option(option, &img_opt);
648 evas_object_image_load_orientation_set(img, img_opt.orient);
650 evas_object_image_file_set(img, path, NULL);
651 err = evas_object_image_load_error_get(img);
652 if (err != EVAS_LOAD_ERROR_NONE) {
653 ErrPrint("Load error: %s\n", evas_load_error_str(err));
654 evas_object_del(img);
657 return LB_STATUS_ERROR_IO;
660 evas_object_image_size_get(img, &w, &h);
661 if (img_opt.aspect) {
662 if (img_opt.fill == FILL_OVER_SIZE) {
666 if (img_opt.width >= 0 && img_opt.height >= 0) {
667 part_w = img_opt.width * elm_config_scale_get();
668 part_h = img_opt.height * elm_config_scale_get();
672 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
674 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
676 if (part_w > w || part_h > h) {
680 fw = (double)part_w / (double)w;
681 fh = (double)part_h / (double)h;
692 if (!part_w || !part_h || !w || !h) {
693 evas_object_del(img);
696 return LB_STATUS_ERROR_INVALID;
699 if (evas_object_image_region_support_get(img)) {
700 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
701 evas_object_image_load_size_set(img, part_w, part_h);
702 evas_object_image_filled_set(img, EINA_TRUE);
703 //evas_object_image_fill_set(img, 0, 0, part_w, part_h);
704 DbgPrint("Size: %dx%d (region: %dx%d - %dx%d)\n", w, h, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
708 Evas_Object *src_img;
712 DbgPrint("Part loading is not supported\n");
713 ee = ecore_evas_buffer_new(part_w, part_h);
715 ErrPrint("Failed to create a EE\n");
716 evas_object_del(img);
719 return LB_STATUS_ERROR_FAULT;
722 ecore_evas_alpha_set(ee, EINA_TRUE);
724 e = ecore_evas_get(ee);
726 ErrPrint("Unable to get Evas\n");
729 evas_object_del(img);
732 return LB_STATUS_ERROR_FAULT;
735 src_img = evas_object_image_filled_add(e);
737 ErrPrint("Unable to add an image\n");
740 evas_object_del(img);
743 return LB_STATUS_ERROR_FAULT;
746 evas_object_image_alpha_set(src_img, EINA_TRUE);
747 evas_object_image_colorspace_set(src_img, EVAS_COLORSPACE_ARGB8888);
748 evas_object_image_smooth_scale_set(src_img, EINA_TRUE);
749 evas_object_image_load_orientation_set(src_img, img_opt.orient);
750 evas_object_image_file_set(src_img, path, NULL);
751 err = evas_object_image_load_error_get(src_img);
752 if (err != EVAS_LOAD_ERROR_NONE) {
753 ErrPrint("Load error: %s\n", evas_load_error_str(err));
754 evas_object_del(src_img);
757 evas_object_del(img);
760 return LB_STATUS_ERROR_IO;
762 evas_object_image_size_get(src_img, &rw, &rh);
763 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
764 evas_object_resize(src_img, w, h);
765 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
766 evas_object_show(src_img);
768 data = ecore_evas_buffer_pixels_get(ee);
770 ErrPrint("Unable to get pixels\n");
771 evas_object_del(src_img);
774 evas_object_del(img);
777 return LB_STATUS_ERROR_IO;
780 e = evas_object_evas_get(img);
781 evas_object_del(img);
782 img = evas_object_image_filled_add(e);
784 evas_object_del(src_img);
789 return LB_STATUS_ERROR_MEMORY;
792 evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
793 evas_object_image_smooth_scale_set(img, EINA_TRUE);
794 evas_object_image_alpha_set(img, EINA_TRUE);
795 evas_object_image_data_set(img, NULL);
796 evas_object_image_size_set(img, part_w, part_h);
797 evas_object_resize(img, part_w, part_h);
798 evas_object_image_data_copy_set(img, (void *)data);
799 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
800 evas_object_image_data_update_add(img, 0, 0, part_w, part_h);
802 evas_object_del(src_img);
805 } else if (img_opt.fill == FILL_IN_SIZE) {
809 if (img_opt.width >= 0 && img_opt.height >= 0) {
810 part_w = img_opt.width * elm_config_scale_get();
811 part_h = img_opt.height * elm_config_scale_get();
815 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
817 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
819 if (part_w > w || part_h > h) {
823 fw = (double)part_w / (double)w;
824 fh = (double)part_h / (double)h;
834 DbgPrint("Size: %dx%d\n", w, h);
835 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
836 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
837 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
839 evas_object_image_fill_set(img, 0, 0, w, h);
840 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
841 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
844 if (img_opt.width >= 0 && img_opt.height >= 0) {
847 DbgPrint("Using given image size: %dx%d\n", w, h);
850 evas_object_image_fill_set(img, 0, 0, w, h);
851 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
852 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
853 evas_object_image_filled_set(img, EINA_TRUE);
858 * object will be shown by below statement automatically
860 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
862 elm_object_part_content_set(edje, part, img);
863 obj_info->children = eina_list_append(obj_info->children, child);
867 * This object is not registered as an access object.
868 * So the developer should add it to access list manually, using DESC_ACCESS block.
870 return LB_STATUS_SUCCESS;
873 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
875 struct info *handle = data;
887 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
888 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
892 sx = (double)px / (double)w;
893 ex = (double)(px + pw) / (double)w;
898 sy = (double)py / (double)h;
899 ey = (double)(py + ph) / (double)h;
902 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
905 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
907 struct info *handle = _info;
908 struct obj_info *obj_info;
909 struct obj_info *parent_obj_info;
913 handle->obj_list = eina_list_remove(handle->obj_list, obj);
915 obj_info = evas_object_data_del(obj, "obj_info");
917 ErrPrint("Object info is not valid\n");
921 DbgPrint("delete object %s %p\n", obj_info->id, obj);
922 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
923 if (parent_obj_info) {
927 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
928 if (child->obj != obj) {
934 * If this code is executed,
935 * The parent is not deleted by desc, this object is deleted by itself.
936 * It is not possible, but we care it.
938 DbgPrint("Parent's children is updated: %s\n", child->part);
939 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
945 DbgPrint("Parent EDJE\n");
948 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
950 elm_object_focus_custom_chain_unset(obj);
952 EINA_LIST_FREE(obj_info->children, child) {
953 DbgPrint("delete object %s %p\n", child->part, child->obj);
956 ao = evas_object_data_del(child->obj, "ao");
958 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
959 evas_object_data_del(ao, "edje");
960 elm_access_object_unregister(ao);
962 evas_object_del(child->obj);
968 EINA_LIST_FREE(obj_info->access_chain, ao) {
969 evas_object_data_del(ao, "edje");
970 elm_access_object_unregister(ao);
978 LB_ACCESS_HIGHLIGHT 0
979 LB_ACCESS_HIGHLIGHT_NEXT 1
980 LB_ACCESS_HIGHLIGHT_PREV 2
985 PUBLIC int script_feed_event(void *h, Evas *e, int event_type, int x, int y, int down, double timestamp)
987 struct info *handle = h;
989 struct obj_info *obj_info;
990 int ret = LB_STATUS_SUCCESS;
992 edje = find_edje(handle, NULL); /*!< Get the base layout */
994 ErrPrint("Base layout is not exist\n");
995 return LB_STATUS_ERROR_NOT_EXIST;
998 obj_info = evas_object_data_get(edje, "obj_info");
1000 ErrPrint("Object info is not valid\n");
1001 return LB_STATUS_ERROR_INVALID;
1004 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
1005 Elm_Access_Action_Info info;
1006 Elm_Access_Action_Type action;
1008 memset(&info, 0, sizeof(info));
1010 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
1011 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1014 ret = elm_access_action(edje, action, &info);
1015 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1016 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1017 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1018 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1019 info.highlight_cycle = EINA_FALSE;
1020 ret = elm_access_action(edje, action, &info);
1021 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1022 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
1023 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1024 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1025 info.highlight_cycle = EINA_FALSE;
1026 ret = elm_access_action(edje, action, &info);
1027 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1028 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
1029 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
1030 action = ELM_ACCESS_ACTION_ACTIVATE;
1031 ret = elm_access_action(edje, action, &info);
1032 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1033 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1034 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
1036 action = ELM_ACCESS_ACTION_UP;
1037 ret = elm_access_action(edje, action, &info);
1038 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1039 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1040 } else if (down == 1) {
1041 action = ELM_ACCESS_ACTION_DOWN;
1042 ret = elm_access_action(edje, action, &info);
1043 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1044 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1046 ErrPrint("Invalid access event\n");
1047 ret = LB_ACCESS_STATUS_ERROR;
1049 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
1050 action = ELM_ACCESS_ACTION_SCROLL;
1055 info.mouse_type = 0;
1056 ret = elm_access_action(edje, action, &info);
1057 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1058 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1061 info.mouse_type = 1;
1062 ret = elm_access_action(edje, action, &info);
1063 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1064 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1067 info.mouse_type = 2;
1068 ret = elm_access_action(edje, action, &info);
1069 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1070 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1073 ret = LB_ACCESS_STATUS_ERROR;
1076 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
1077 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1078 ret = elm_access_action(edje, action, &info);
1079 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1080 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1082 DbgPrint("Invalid event\n");
1083 ret = LB_ACCESS_STATUS_ERROR;
1086 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
1087 switch (event_type) {
1088 case LB_SCRIPT_MOUSE_DOWN:
1089 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
1090 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1092 case LB_SCRIPT_MOUSE_MOVE:
1093 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
1095 case LB_SCRIPT_MOUSE_UP:
1096 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
1097 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.1f) * 1000, NULL);
1099 case LB_SCRIPT_MOUSE_IN:
1100 evas_event_feed_mouse_in(e, timestamp * 1000, NULL);
1102 case LB_SCRIPT_MOUSE_OUT:
1103 evas_event_feed_mouse_out(e, timestamp * 1000, NULL);
1106 return LB_STATUS_ERROR_INVALID;
1108 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
1109 DbgPrint("Key event is not implemented\n");
1110 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
1116 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)
1118 struct info *handle = h;
1121 struct obj_info *obj_info;
1122 struct child *child;
1123 char _target_id[32];
1125 edje = find_edje(handle, src_id);
1127 ErrPrint("Edje is not exists (%s)\n", src_id);
1128 return LB_STATUS_ERROR_NOT_EXIST;
1131 obj_info = evas_object_data_get(edje, "obj_info");
1133 ErrPrint("Object info is not valid\n");
1134 return LB_STATUS_ERROR_INVALID;
1137 obj = elm_object_part_content_unset(edje, part);
1142 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
1143 if (child->obj != obj) {
1147 obj_info->children = eina_list_remove(obj_info->children, child);
1154 DbgPrint("delete object %s %p\n", part, obj);
1157 * This will call the edje_del_cb.
1158 * It will delete all access objects
1160 evas_object_del(obj);
1163 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1164 DbgPrint("SKIP - Path: [%s]\n", path);
1165 return LB_STATUS_SUCCESS;
1169 if (find_edje(handle, part)) {
1173 #if defined(_USE_ECORE_TIME_GET)
1174 timestamp = ecore_time_get();
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);
1185 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1186 } while (find_edje(handle, _target_id));
1188 target_id = _target_id;
1193 DbgPrint("Anonymouse target id: %s\n", target_id);
1196 obj = elm_layout_add(edje);
1198 ErrPrint("Failed to add a new edje object\n");
1199 return LB_STATUS_ERROR_FAULT;
1202 edje_object_scale_set(elm_layout_edje_get(obj), elm_config_scale_get());
1204 if (!elm_layout_file_set(obj, path, group)) {
1206 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1207 ErrPrint("Could not load %s from %s: %s\n", group, path, edje_load_error_str(err));
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;
1275 elm_object_signal_emit(edje, signal, part);
1276 return LB_STATUS_SUCCESS;
1279 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1281 struct info *handle = h;
1284 edje = find_edje(handle, id);
1286 return LB_STATUS_ERROR_NOT_EXIST;
1289 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1290 return LB_STATUS_SUCCESS;
1293 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1295 struct info *handle = han;
1298 edje = find_edje(handle, id);
1300 return LB_STATUS_ERROR_NOT_EXIST;
1308 DbgPrint("Resize object to %dx%d\n", w, h);
1309 evas_object_resize(edje, w, h);
1310 return LB_STATUS_SUCCESS;
1313 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1315 struct info *handle = h;
1317 if (handle->category) {
1318 free(handle->category);
1319 handle->category = NULL;
1323 return LB_STATUS_SUCCESS;
1326 handle->category = strdup(category);
1327 if (!handle->category) {
1328 ErrPrint("Error: %s\n", strerror(errno));
1329 return LB_STATUS_ERROR_MEMORY;
1332 return LB_STATUS_SUCCESS;
1335 PUBLIC void *script_create(const char *file, const char *group)
1337 struct info *handle;
1339 handle = calloc(1, sizeof(*handle));
1341 ErrPrint("Error: %s\n", strerror(errno));
1345 handle->file = strdup(file);
1346 if (!handle->file) {
1347 ErrPrint("Error: %s\n", strerror(errno));
1352 handle->group = strdup(group);
1353 if (!handle->group) {
1354 ErrPrint("Error: %s\n", strerror(errno));
1360 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1365 PUBLIC int script_destroy(void *_handle)
1367 struct info *handle;
1372 if (!eina_list_data_find(s_info.handle_list, handle)) {
1373 DbgPrint("Not found (already deleted?)\n");
1374 return LB_STATUS_ERROR_NOT_EXIST;
1377 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1379 edje = eina_list_nth(handle->obj_list, 0);
1381 evas_object_del(edje);
1384 free(handle->category);
1386 free(handle->group);
1388 return LB_STATUS_SUCCESS;
1391 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1393 struct info *handle;
1395 struct obj_info *obj_info;
1399 obj_info = calloc(1, sizeof(*obj_info));
1401 ErrPrint("Heap: %s\n", strerror(errno));
1402 return LB_STATUS_ERROR_MEMORY;
1405 obj_info->parent = evas_object_rectangle_add(e);
1406 if (!obj_info->parent) {
1407 ErrPrint("Unable to create a parent box\n");
1409 return LB_STATUS_ERROR_FAULT;
1412 edje = elm_layout_add(obj_info->parent);
1414 ErrPrint("Failed to create an edje object\n");
1415 evas_object_del(obj_info->parent);
1417 return LB_STATUS_ERROR_FAULT;
1420 edje_object_scale_set(elm_layout_edje_get(edje), elm_config_scale_get());
1422 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1425 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1426 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, edje_load_error_str(err));
1427 evas_object_del(edje);
1428 evas_object_del(obj_info->parent);
1430 return LB_STATUS_ERROR_IO;
1437 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1438 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1439 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1440 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1441 evas_object_resize(edje, handle->w, handle->h);
1442 evas_object_show(edje);
1443 evas_object_data_set(edje, "obj_info", obj_info);
1445 handle->obj_list = eina_list_append(handle->obj_list, edje);
1446 return LB_STATUS_SUCCESS;
1449 PUBLIC int script_unload(void *_handle, Evas *e)
1451 struct info *handle;
1453 Evas_Object *parent = NULL;
1457 edje = eina_list_nth(handle->obj_list, 0);
1459 struct obj_info *obj_info;
1461 obj_info = evas_object_data_get(edje, "obj_info");
1463 parent = obj_info->parent;
1465 evas_object_del(edje);
1469 DbgPrint("Delete parent box\n");
1470 evas_object_del(parent);
1474 return LB_STATUS_SUCCESS;
1477 static void access_cb(keynode_t *node, void *user_data)
1482 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1483 ErrPrint("Idle lock state is not valid\n");
1484 state = 0; /* DISABLED */
1487 state = vconf_keynode_get_bool(node);
1490 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1491 elm_config_access_set(state);
1494 static void update_font_cb(void *data)
1496 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1497 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1500 static void font_changed_cb(keynode_t *node, void *user_data)
1504 if (s_info.font_name) {
1505 font_name = vconf_get_str("db/setting/accessibility/font_name");
1507 ErrPrint("Invalid font name (NULL)\n");
1511 if (!strcmp(s_info.font_name, font_name)) {
1512 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1517 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1518 free(s_info.font_name);
1523 * Get the first font name using system_settings API.
1526 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
1527 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
1528 ErrPrint("System setting get: %d, font_name[%p]\n", ret, font_name);
1533 s_info.font_name = font_name;
1534 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1538 * Try to update all liveboxes
1540 update_font_cb(NULL);
1543 static inline int convert_font_size(int size)
1546 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1549 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1552 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1555 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1558 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1566 DbgPrint("Return size: %d\n", size);
1570 static void font_size_cb(system_settings_key_e key, void *user_data)
1574 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE) {
1578 size = convert_font_size(size);
1580 if (size == s_info.font_size) {
1581 DbgPrint("Font size is not changed\n");
1585 s_info.font_size = size;
1586 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
1589 PUBLIC int script_init(double scale)
1597 /* ecore is already initialized */
1599 elm_config_scale_set(scale);
1600 DbgPrint("Scale is updated: %lf\n", scale);
1602 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1603 DbgPrint("TTS changed: %d\n", ret);
1605 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
1606 DbgPrint("System font is changed: %d\n", ret);
1608 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1609 DbgPrint("System font size is changed: %d\n", ret);
1611 access_cb(NULL, NULL);
1612 font_changed_cb(NULL, NULL);
1613 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
1614 return LB_STATUS_SUCCESS;
1617 PUBLIC int script_fini(void)
1622 struct info *handle;
1624 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
1625 script_destroy(handle);
1628 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1629 DbgPrint("Unset font size change event callback: %d\n", ret);
1631 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
1632 DbgPrint("Unset font name change event callback: %d\n", ret);
1634 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1635 DbgPrint("Unset tts: %d\n", ret);
1639 free(s_info.font_name);
1640 s_info.font_name = NULL;
1641 return LB_STATUS_SUCCESS;