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 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_load_orientation_set(src_img, img_opt.orient);
741 evas_object_image_file_set(src_img, path, NULL);
742 err = evas_object_image_load_error_get(src_img);
743 if (err != EVAS_LOAD_ERROR_NONE) {
744 ErrPrint("Load error: %s\n", evas_load_error_str(err));
745 evas_object_del(src_img);
748 evas_object_del(img);
751 return LB_STATUS_ERROR_IO;
753 evas_object_image_size_get(src_img, &rw, &rh);
754 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
755 evas_object_resize(src_img, w, h);
756 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
757 evas_object_show(src_img);
759 data = ecore_evas_buffer_pixels_get(ee);
761 ErrPrint("Unable to get pixels\n");
762 evas_object_del(src_img);
765 evas_object_del(img);
768 return LB_STATUS_ERROR_IO;
771 e = evas_object_evas_get(img);
772 evas_object_del(img);
773 img = evas_object_image_filled_add(e);
775 evas_object_del(src_img);
780 return LB_STATUS_ERROR_MEMORY;
783 evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
784 evas_object_image_smooth_scale_set(img, EINA_TRUE);
785 evas_object_image_alpha_set(img, EINA_TRUE);
786 evas_object_image_data_set(img, NULL);
787 evas_object_image_size_set(img, part_w, part_h);
788 evas_object_resize(img, part_w, part_h);
789 evas_object_image_data_copy_set(img, (void *)data);
790 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
791 evas_object_image_data_update_add(img, 0, 0, part_w, part_h);
793 evas_object_del(src_img);
796 } else if (img_opt.fill == FILL_IN_SIZE) {
800 if (img_opt.width >= 0 && img_opt.height >= 0) {
801 part_w = img_opt.width * scale_get();
802 part_h = img_opt.height * scale_get();
806 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
808 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
810 if (part_w > w || part_h > h) {
814 fw = (double)part_w / (double)w;
815 fh = (double)part_h / (double)h;
825 DbgPrint("Size: %dx%d\n", w, h);
826 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
827 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
828 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
830 evas_object_image_fill_set(img, 0, 0, w, h);
831 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
832 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
835 if (img_opt.width >= 0 && img_opt.height >= 0) {
838 DbgPrint("Using given image size: %dx%d\n", w, h);
841 evas_object_image_fill_set(img, 0, 0, w, h);
842 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
843 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
844 evas_object_image_filled_set(img, EINA_TRUE);
849 * object will be shown by below statement automatically
851 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
853 elm_object_part_content_set(edje, part, img);
854 obj_info->children = eina_list_append(obj_info->children, child);
858 * This object is not registered as an access object.
859 * So the developer should add it to access list manually, using DESC_ACCESS block.
861 return LB_STATUS_SUCCESS;
864 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
866 struct info *handle = data;
878 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
879 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
883 sx = (double)px / (double)w;
884 ex = (double)(px + pw) / (double)w;
889 sy = (double)py / (double)h;
890 ey = (double)(py + ph) / (double)h;
893 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
896 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
898 struct info *handle = _info;
899 struct obj_info *obj_info;
900 struct obj_info *parent_obj_info;
904 handle->obj_list = eina_list_remove(handle->obj_list, obj);
906 obj_info = evas_object_data_del(obj, "obj_info");
908 ErrPrint("Object info is not valid\n");
912 DbgPrint("delete object %s %p\n", obj_info->id, obj);
913 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
914 if (parent_obj_info) {
918 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
919 if (child->obj != obj)
924 * If this code is executed,
925 * The parent is not deleted by desc, this object is deleted by itself.
926 * It is not possible, but we care it.
928 DbgPrint("Parent's children is updated: %s\n", child->part);
929 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
935 DbgPrint("Parent EDJE\n");
938 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
940 elm_object_focus_custom_chain_unset(obj);
942 EINA_LIST_FREE(obj_info->children, child) {
943 DbgPrint("delete object %s %p\n", child->part, child->obj);
946 ao = evas_object_data_del(child->obj, "ao");
948 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
949 evas_object_data_del(ao, "edje");
950 elm_access_object_unregister(ao);
952 evas_object_del(child->obj);
958 EINA_LIST_FREE(obj_info->access_chain, ao) {
959 evas_object_data_del(ao, "edje");
960 elm_access_object_unregister(ao);
968 LB_ACCESS_HIGHLIGHT 0
969 LB_ACCESS_HIGHLIGHT_NEXT 1
970 LB_ACCESS_HIGHLIGHT_PREV 2
975 PUBLIC int script_feed_event(void *h, Evas *e, int event_type, int x, int y, int down, double timestamp)
977 struct info *handle = h;
979 struct obj_info *obj_info;
980 int ret = LB_STATUS_SUCCESS;
982 edje = find_edje(handle, NULL); /*!< Get the base layout */
984 ErrPrint("Base layout is not exist\n");
985 return LB_STATUS_ERROR_NOT_EXIST;
988 obj_info = evas_object_data_get(edje, "obj_info");
990 ErrPrint("Object info is not valid\n");
991 return LB_STATUS_ERROR_INVALID;
994 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
995 Elm_Access_Action_Info *info;
996 Elm_Access_Action_Type action;
997 const Eina_List *chain;
999 info = calloc(1, sizeof(*info));
1001 ErrPrint("Error: %s\n", strerror(errno));
1002 return LB_STATUS_ERROR_MEMORY;
1005 chain = elm_object_focus_custom_chain_get(edje);
1006 DbgPrint("Focus chain : %d\n", eina_list_count(chain));
1008 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
1009 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1012 ret = elm_access_action(edje, action, info);
1013 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1014 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1015 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1016 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1017 info->highlight_cycle = EINA_FALSE;
1018 ret = elm_access_action(edje, action, info);
1019 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1020 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
1021 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1022 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1023 info->highlight_cycle = EINA_FALSE;
1024 ret = elm_access_action(edje, action, info);
1025 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1026 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
1027 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
1028 action = ELM_ACCESS_ACTION_ACTIVATE;
1029 ret = elm_access_action(edje, action, info);
1030 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1031 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1032 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
1034 action = ELM_ACCESS_ACTION_UP;
1035 ret = elm_access_action(edje, action, info);
1036 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1037 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1038 } else if (down == 1) {
1039 action = ELM_ACCESS_ACTION_DOWN;
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;
1044 ErrPrint("Invalid access event\n");
1045 ret = LB_ACCESS_STATUS_ERROR;
1047 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
1048 action = ELM_ACCESS_ACTION_SCROLL;
1053 info->mouse_type = 0;
1054 ret = elm_access_action(edje, action, info);
1055 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1056 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1059 info->mouse_type = 1;
1060 ret = elm_access_action(edje, action, info);
1061 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1062 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1065 info->mouse_type = 2;
1066 ret = elm_access_action(edje, action, info);
1067 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1068 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1071 ret = LB_ACCESS_STATUS_ERROR;
1074 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
1075 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1076 ret = elm_access_action(edje, action, info);
1077 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1078 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1080 DbgPrint("Invalid event\n");
1081 ret = LB_ACCESS_STATUS_ERROR;
1085 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
1086 switch (event_type) {
1087 case LB_SCRIPT_MOUSE_DOWN:
1088 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
1089 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
1091 case LB_SCRIPT_MOUSE_MOVE:
1092 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
1094 case LB_SCRIPT_MOUSE_UP:
1095 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
1096 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.1f, NULL);
1098 case LB_SCRIPT_MOUSE_IN:
1099 evas_event_feed_mouse_in(e, timestamp, NULL);
1101 case LB_SCRIPT_MOUSE_OUT:
1102 evas_event_feed_mouse_out(e, timestamp, NULL);
1105 return LB_STATUS_ERROR_INVALID;
1107 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
1108 DbgPrint("Key event is not implemented\n");
1109 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
1115 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)
1117 struct info *handle = h;
1120 struct obj_info *obj_info;
1121 struct child *child;
1122 char _target_id[32];
1124 edje = find_edje(handle, src_id);
1126 ErrPrint("Edje is not exists (%s)\n", src_id);
1127 return LB_STATUS_ERROR_NOT_EXIST;
1130 obj_info = evas_object_data_get(edje, "obj_info");
1132 ErrPrint("Object info is not valid\n");
1133 return LB_STATUS_ERROR_INVALID;
1136 obj = elm_object_part_content_unset(edje, part);
1141 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
1142 if (child->obj != obj)
1145 obj_info->children = eina_list_remove(obj_info->children, child);
1152 DbgPrint("delete object %s %p\n", part, obj);
1155 * This will call the edje_del_cb.
1156 * It will delete all access objects
1158 evas_object_del(obj);
1161 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1162 DbgPrint("SKIP - Path: [%s]\n", path);
1163 return LB_STATUS_SUCCESS;
1167 if (find_edje(handle, part)) {
1172 if (gettimeofday(&tv, NULL) < 0) {
1173 static int local_idx = 0;
1174 timestamp = (double)(local_idx++);
1176 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1179 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1180 } while (find_edje(handle, _target_id));
1182 target_id = _target_id;
1187 DbgPrint("Anonymouse target id: %s\n", target_id);
1190 obj = elm_layout_add(edje);
1192 ErrPrint("Failed to add a new edje object\n");
1193 return LB_STATUS_ERROR_FAULT;
1196 if (!elm_layout_file_set(obj, path, group)) {
1200 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1201 errmsg = edje_load_error_str(err);
1202 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
1203 evas_object_del(obj);
1204 return LB_STATUS_ERROR_IO;
1207 evas_object_show(obj);
1209 obj_info = calloc(1, sizeof(*obj_info));
1211 ErrPrint("Failed to add a obj_info\n");
1212 evas_object_del(obj);
1213 return LB_STATUS_ERROR_MEMORY;
1216 obj_info->id = strdup(target_id);
1217 if (!obj_info->id) {
1218 ErrPrint("Failed to add a obj_info\n");
1220 evas_object_del(obj);
1221 return LB_STATUS_ERROR_MEMORY;
1224 obj_info->parent = edje;
1226 child = malloc(sizeof(*child));
1228 ErrPrint("Error: %s\n", strerror(errno));
1231 evas_object_del(obj);
1232 return LB_STATUS_ERROR_MEMORY;
1235 child->part = strdup(part);
1237 ErrPrint("Error: %s\n", strerror(errno));
1241 evas_object_del(obj);
1242 return LB_STATUS_ERROR_MEMORY;
1247 evas_object_data_set(obj, "obj_info", obj_info);
1248 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1249 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1250 handle->obj_list = eina_list_append(handle->obj_list, obj);
1252 DbgPrint("%s part swallow edje %p\n", part, obj);
1253 elm_object_part_content_set(edje, part, obj);
1255 obj_info = evas_object_data_get(edje, "obj_info");
1256 obj_info->children = eina_list_append(obj_info->children, child);
1257 return LB_STATUS_SUCCESS;
1260 PUBLIC int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
1262 struct info *handle = h;
1265 edje = find_edje(handle, id);
1267 return LB_STATUS_ERROR_NOT_EXIST;
1269 elm_object_signal_emit(edje, signal, part);
1270 return LB_STATUS_SUCCESS;
1273 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1275 struct info *handle = h;
1278 edje = find_edje(handle, id);
1280 return LB_STATUS_ERROR_NOT_EXIST;
1282 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1283 return LB_STATUS_SUCCESS;
1286 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1288 struct info *handle = han;
1291 edje = find_edje(handle, id);
1293 return LB_STATUS_ERROR_NOT_EXIST;
1300 DbgPrint("Resize object to %dx%d\n", w, h);
1301 evas_object_resize(edje, w, h);
1302 return LB_STATUS_SUCCESS;
1305 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1307 struct info *handle = h;
1309 if (handle->category) {
1310 free(handle->category);
1311 handle->category = NULL;
1315 return LB_STATUS_SUCCESS;
1317 handle->category = strdup(category);
1318 if (!handle->category) {
1319 ErrPrint("Error: %s\n", strerror(errno));
1320 return LB_STATUS_ERROR_MEMORY;
1323 return LB_STATUS_SUCCESS;
1326 PUBLIC void *script_create(const char *file, const char *group)
1328 struct info *handle;
1330 handle = calloc(1, sizeof(*handle));
1332 ErrPrint("Error: %s\n", strerror(errno));
1336 handle->file = strdup(file);
1337 if (!handle->file) {
1338 ErrPrint("Error: %s\n", strerror(errno));
1343 handle->group = strdup(group);
1344 if (!handle->group) {
1345 ErrPrint("Error: %s\n", strerror(errno));
1351 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1356 PUBLIC int script_destroy(void *_handle)
1358 struct info *handle;
1363 if (!eina_list_data_find(s_info.handle_list, handle)) {
1364 DbgPrint("Not found (already deleted?)\n");
1365 return LB_STATUS_ERROR_NOT_EXIST;
1368 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1370 edje = eina_list_nth(handle->obj_list, 0);
1372 evas_object_del(edje);
1374 free(handle->category);
1376 free(handle->group);
1378 return LB_STATUS_SUCCESS;
1381 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1383 struct info *handle;
1385 struct obj_info *obj_info;
1389 obj_info = calloc(1, sizeof(*obj_info));
1391 ErrPrint("Heap: %s\n", strerror(errno));
1392 return LB_STATUS_ERROR_MEMORY;
1395 obj_info->parent = evas_object_rectangle_add(e);
1396 if (!obj_info->parent) {
1397 ErrPrint("Unable to create a parent box\n");
1399 return LB_STATUS_ERROR_FAULT;
1402 edje = elm_layout_add(obj_info->parent);
1404 ErrPrint("Failed to create an edje object\n");
1405 evas_object_del(obj_info->parent);
1407 return LB_STATUS_ERROR_FAULT;
1410 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1414 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1415 errmsg = edje_load_error_str(err);
1416 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
1417 evas_object_del(edje);
1418 evas_object_del(obj_info->parent);
1420 return LB_STATUS_ERROR_IO;
1427 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1428 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1429 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1430 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1431 evas_object_resize(edje, handle->w, handle->h);
1432 evas_object_show(edje);
1433 evas_object_data_set(edje, "obj_info", obj_info);
1435 handle->obj_list = eina_list_append(handle->obj_list, edje);
1436 return LB_STATUS_SUCCESS;
1439 PUBLIC int script_unload(void *_handle, Evas *e)
1441 struct info *handle;
1443 Evas_Object *parent = NULL;
1447 edje = eina_list_nth(handle->obj_list, 0);
1449 struct obj_info *obj_info;
1451 obj_info = evas_object_data_get(edje, "obj_info");
1453 parent = obj_info->parent;
1454 evas_object_del(edje);
1458 DbgPrint("Delete parent box\n");
1459 evas_object_del(parent);
1463 return LB_STATUS_SUCCESS;
1466 static void access_cb(keynode_t *node, void *user_data)
1471 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1472 ErrPrint("Idle lock state is not valid\n");
1473 state = 0; /* DISABLED */
1476 state = vconf_keynode_get_bool(node);
1479 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1480 elm_config_access_set(state);
1483 static void update_font_cb(void *data)
1485 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1486 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1489 static void font_changed_cb(keynode_t *node, void *user_data)
1493 font_name = vconf_get_str("db/setting/accessibility/font_name");
1495 ErrPrint("Invalid font name (NULL)\n");
1499 if (s_info.font_name && !strcmp(s_info.font_name, font_name)) {
1500 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1505 if (s_info.font_name) {
1506 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1507 free(s_info.font_name);
1508 s_info.font_name = NULL;
1511 s_info.font_name = font_name;
1512 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1516 * Try to update all liveboxes
1518 update_font_cb(NULL);
1521 static inline int convert_font_size(int size)
1524 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1527 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1530 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1533 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1536 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1544 DbgPrint("Return size: %d\n", size);
1548 static void font_size_cb(system_settings_key_e key, void *user_data)
1552 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE)
1555 size = convert_font_size(size);
1557 if (size == s_info.font_size) {
1558 DbgPrint("Font size is not changed\n");
1562 s_info.font_size = size;
1563 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
1566 PUBLIC int script_init(void)
1569 int size = DEFAULT_FONT_SIZE;
1574 /* ecore is already initialized */
1576 elm_config_scale_set(scale_get());
1578 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1580 ErrPrint("Failed to access cb\n");
1582 access_cb(NULL, NULL);
1584 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
1585 DbgPrint("System font is changed: %d\n", ret);
1587 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1588 DbgPrint("System font size is changed: %d\n", ret);
1590 s_info.font_name = vconf_get_str("db/setting/accessibility/font_name");
1591 DbgPrint("Current font: %s\n", s_info.font_name);
1593 ret = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size);
1594 s_info.font_size = convert_font_size(size);
1595 DbgPrint("Current size: %d\n", s_info.font_size);
1597 return LB_STATUS_SUCCESS;
1600 PUBLIC int script_fini(void)
1605 struct info *handle;
1607 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
1608 script_destroy(handle);
1611 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1612 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
1613 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1615 return LB_STATUS_SUCCESS;