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 DbgPrint("Rebuild focus chain begin\n");
150 EINA_LIST_FOREACH(obj_info->access_chain, l, ao) {
151 DbgPrint("Append %p\n", ao);
152 elm_object_focus_custom_chain_append(obj, ao, NULL);
154 DbgPrint("Rebuild focus chain done\n");
157 PUBLIC const char *script_magic_id(void)
162 PUBLIC int script_update_color(void *h, Evas *e, const char *id, const char *part, const char *rgba)
164 struct info *handle = h;
166 int r[3], g[3], b[3], a[3];
169 edje = find_edje(handle, id);
171 return LB_STATUS_ERROR_NOT_EXIST;
173 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
174 r, g, b, a, /* OBJECT */
175 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
176 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
178 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
179 return LB_STATUS_ERROR_INVALID;
182 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
183 r[0], g[0], b[0], a[0], /* OBJECT */
184 r[1], g[1], b[1], a[1], /* OUTLINE */
185 r[2], g[2], b[2], a[2]); /* SHADOW */
187 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
188 return LB_STATUS_SUCCESS;
191 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
203 ao = evas_object_data_get(part_obj, "ao");
207 edje = evas_object_data_get(ao, "edje");
211 e = evas_object_evas_get(part_obj);
212 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
216 if (gettimeofday(&tv, NULL) < 0) {
217 ErrPrint("Failed to get time\n");
220 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
223 DbgPrint("Cursor is on %dx%d\n", x, y);
224 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
225 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
226 evas_event_feed_mouse_move(e, x, y, timestamp + 0.02f, NULL);
227 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.03f, NULL);
230 PUBLIC int script_update_text(void *h, Evas *e, const char *id, const char *part, const char *text)
232 struct obj_info *obj_info;
233 struct info *handle = h;
237 edje = find_edje(handle, id);
239 ErrPrint("Failed to find EDJE\n");
240 return LB_STATUS_ERROR_NOT_EXIST;
243 obj_info = evas_object_data_get(edje, "obj_info");
245 ErrPrint("Object info is not available\n");
246 return LB_STATUS_ERROR_FAULT;
249 elm_object_part_text_set(edje, part, text ? text : "");
251 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
256 ao = evas_object_data_get(to, "ao");
258 ao = elm_access_object_register(to, edje);
260 ErrPrint("Unable to add ao: %s\n", part);
263 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
264 evas_object_data_set(to, "ao", ao);
265 evas_object_data_set(ao, "edje", edje);
266 elm_access_activate_cb_set(ao, activate_cb, NULL);
267 elm_object_focus_custom_chain_append(edje, ao, NULL);
270 if (!text || !strlen(text)) {
271 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
272 evas_object_data_del(to, "ao");
273 evas_object_data_del(ao, "edje");
274 elm_access_object_unregister(ao);
275 DbgPrint("[%s] Remove access object\n", part);
277 rebuild_focus_chain(edje);
281 utf8 = elm_entry_markup_to_utf8(text);
282 if ((!utf8 || !strlen(utf8))) {
285 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
286 evas_object_data_del(to, "ao");
287 evas_object_data_del(ao, "edje");
288 elm_access_object_unregister(ao);
289 DbgPrint("[%s] Remove access object\n", part);
291 rebuild_focus_chain(edje);
295 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
296 DbgPrint("[%s] Update access object (%s)\n", part, utf8);
299 ErrPrint("Unable to get text part[%s]\n", part);
303 return LB_STATUS_SUCCESS;
306 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
308 while (len > 0 && *value == ' ') {
316 img_opt->aspect = !strncasecmp(value, "true", 4);
317 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
320 static void parse_orient(struct image_option *img_opt, const char *value, int len)
322 while (len > 0 && *value == ' ') {
330 img_opt->orient = !strncasecmp(value, "true", 4);
331 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
334 static void parse_size(struct image_option *img_opt, const char *value, int len)
340 while (len > 0 && *value == ' ') {
345 buf = strndup(value, len);
347 ErrPrint("Heap: %s\n", strerror(errno));
351 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
352 img_opt->width = width;
353 img_opt->height = height;
354 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
356 DbgPrint("Invalid size tag[%s]\n", buf);
362 static void parse_fill(struct image_option *img_opt, const char *value, int len)
364 while (len > 0 && *value == ' ') {
369 if (!strncasecmp(value, "in-size", len))
370 img_opt->fill = FILL_IN_SIZE;
371 else if (!strncasecmp(value, "over-size", len))
372 img_opt->fill = FILL_OVER_SIZE;
374 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)
422 * GCC 4.7 warnings uninitialized idx and tag value.
423 * But it will be initialized by the state machine. :(
424 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
431 for (ptr = option; state != STATE_END; ptr++) {
446 cmd = cmd_list[tag].cmd;
452 } else if (*ptr == '\0') {
457 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
462 state = STATE_IGNORE;
465 } else if (*ptr == '\0') {
467 } else if (cmd[idx] == *ptr) {
473 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
477 cmd = cmd_list[tag].cmd;
483 if (*ptr == ';' || *ptr == '\0') {
484 cmd_list[tag].handler(img_opt, value + 1, idx);
485 state = *ptr ? STATE_START : STATE_END;
493 else if (*ptr == '\0')
502 PUBLIC int script_update_access(void *_h, Evas *e, const char *id, const char *part, const char *text, const char *option)
504 struct info *handle = _h;
506 struct obj_info *obj_info;
509 edje = find_edje(handle, id);
511 ErrPrint("No such object: %s\n", id);
512 return LB_STATUS_ERROR_NOT_EXIST;
515 obj_info = evas_object_data_get(edje, "obj_info");
517 ErrPrint("Object info is not available\n");
518 return LB_STATUS_ERROR_FAULT;
521 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
525 ao = evas_object_data_get(to, "ao");
527 DbgPrint("[%s] Update access object (%s)\n", part, text);
528 if (text && strlen(text)) {
529 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
531 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
532 evas_object_data_del(to, "ao");
533 evas_object_data_del(ao, "edje");
534 elm_access_object_unregister(ao);
535 DbgPrint("Successfully unregistered\n");
537 rebuild_focus_chain(edje);
539 } else if (text && strlen(text)) {
540 ao = elm_access_object_register(to, edje);
542 ErrPrint("Unable to register access object\n");
544 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
545 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
546 evas_object_data_set(to, "ao", ao);
547 elm_object_focus_custom_chain_append(edje, ao, NULL);
548 DbgPrint("[%s] Register access info: (%s)\n", part, text);
549 evas_object_data_set(ao, "edje", edje);
550 elm_access_activate_cb_set(ao, activate_cb, NULL);
554 ErrPrint("[%s] is not exists\n", part);
557 return LB_STATUS_SUCCESS;
560 PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path, const char *option)
562 struct info *handle = _h;
567 struct obj_info *obj_info;
569 struct image_option img_opt = {
572 .fill = FILL_DISABLE,
577 edje = find_edje(handle, id);
579 ErrPrint("No such object: %s\n", id);
580 return LB_STATUS_ERROR_NOT_EXIST;
583 obj_info = evas_object_data_get(edje, "obj_info");
585 ErrPrint("Object info is not available\n");
586 return LB_STATUS_ERROR_FAULT;
589 img = elm_object_part_content_unset(edje, part);
595 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
596 if (child->obj != img)
599 obj_info->children = eina_list_remove(obj_info->children, child);
605 DbgPrint("delete object %s %p\n", part, img);
606 ao = evas_object_data_del(img, "ao");
608 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
609 evas_object_data_del(ao, "edje");
610 elm_access_object_unregister(ao);
611 DbgPrint("Successfully unregistered\n");
613 evas_object_del(img);
615 rebuild_focus_chain(edje);
618 if (!path || !strlen(path) || access(path, R_OK) != 0) {
619 DbgPrint("SKIP - Path: [%s]\n", path);
620 return LB_STATUS_SUCCESS;
623 child = malloc(sizeof(*child));
625 ErrPrint("Heap: %s\n", strerror(errno));
626 return LB_STATUS_ERROR_MEMORY;
629 child->part = strdup(part);
631 ErrPrint("Heap: %s\n", strerror(errno));
633 return LB_STATUS_ERROR_MEMORY;
636 img = evas_object_image_add(e);
638 ErrPrint("Failed to add an image object\n");
641 return LB_STATUS_ERROR_FAULT;
644 evas_object_image_preload(img, EINA_FALSE);
645 parse_image_option(option, &img_opt);
646 evas_object_image_load_orientation_set(img, img_opt.orient);
648 evas_object_image_file_set(img, path, NULL);
649 err = evas_object_image_load_error_get(img);
650 if (err != EVAS_LOAD_ERROR_NONE) {
651 ErrPrint("Load error: %s\n", evas_load_error_str(err));
652 evas_object_del(img);
655 return LB_STATUS_ERROR_IO;
658 evas_object_image_size_get(img, &w, &h);
659 if (img_opt.aspect) {
660 if (img_opt.fill == FILL_OVER_SIZE) {
664 if (img_opt.width >= 0 && img_opt.height >= 0) {
665 part_w = img_opt.width * scale_get();
666 part_h = img_opt.height * scale_get();
670 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
672 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
674 if (part_w > w || part_h > h) {
678 fw = (double)part_w / (double)w;
679 fh = (double)part_h / (double)h;
690 if (!part_w || !part_h || !w || !h) {
691 evas_object_del(img);
694 return LB_STATUS_ERROR_INVALID;
697 if (evas_object_image_region_support_get(img)) {
698 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
699 evas_object_image_load_size_set(img, part_w, part_h);
700 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
701 DbgPrint("Size: %dx%d (region: %dx%d - %dx%d)\n", w, h, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
705 Evas_Object *src_img;
709 DbgPrint("Part loading is not supported\n");
710 ee = ecore_evas_buffer_new(part_w, part_h);
712 ErrPrint("Failed to create a EE\n");
713 evas_object_del(img);
716 return LB_STATUS_ERROR_FAULT;
719 e = ecore_evas_get(ee);
721 ErrPrint("Unable to get Evas\n");
724 evas_object_del(img);
727 return LB_STATUS_ERROR_FAULT;
730 src_img = evas_object_image_filled_add(e);
732 ErrPrint("Unable to add an image\n");
735 evas_object_del(img);
738 return LB_STATUS_ERROR_FAULT;
741 evas_object_image_load_orientation_set(src_img, img_opt.orient);
742 evas_object_image_file_set(src_img, path, NULL);
743 err = evas_object_image_load_error_get(src_img);
744 if (err != EVAS_LOAD_ERROR_NONE) {
745 ErrPrint("Load error: %s\n", evas_load_error_str(err));
746 evas_object_del(src_img);
749 evas_object_del(img);
752 return LB_STATUS_ERROR_IO;
754 evas_object_image_size_get(src_img, &rw, &rh);
755 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
756 evas_object_resize(src_img, w, h);
757 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
758 evas_object_show(src_img);
760 data = ecore_evas_buffer_pixels_get(ee);
762 ErrPrint("Unable to get pixels\n");
763 evas_object_del(src_img);
766 evas_object_del(img);
769 return LB_STATUS_ERROR_IO;
772 e = evas_object_evas_get(img);
773 evas_object_del(img);
774 img = evas_object_image_filled_add(e);
776 evas_object_del(src_img);
781 return LB_STATUS_ERROR_MEMORY;
784 evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
785 evas_object_image_smooth_scale_set(img, EINA_TRUE);
786 evas_object_image_alpha_set(img, EINA_TRUE);
787 evas_object_image_data_set(img, NULL);
788 evas_object_image_size_set(img, part_w, part_h);
789 evas_object_resize(img, part_w, part_h);
790 evas_object_image_data_copy_set(img, (void *)data);
791 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
792 evas_object_image_data_update_add(img, 0, 0, part_w, part_h);
794 evas_object_del(src_img);
797 } else if (img_opt.fill == FILL_IN_SIZE) {
801 if (img_opt.width >= 0 && img_opt.height >= 0) {
802 part_w = img_opt.width * scale_get();
803 part_h = img_opt.height * scale_get();
807 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
809 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
811 if (part_w > w || part_h > h) {
815 fw = (double)part_w / (double)w;
816 fh = (double)part_h / (double)h;
826 DbgPrint("Size: %dx%d\n", w, h);
827 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
828 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
829 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
831 evas_object_image_fill_set(img, 0, 0, w, h);
832 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
833 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
836 if (img_opt.width >= 0 && img_opt.height >= 0) {
839 DbgPrint("Using given image size: %dx%d\n", w, h);
842 evas_object_image_fill_set(img, 0, 0, w, h);
843 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
844 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
845 evas_object_image_filled_set(img, EINA_TRUE);
850 * object will be shown by below statement automatically
852 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
854 elm_object_part_content_set(edje, part, img);
855 obj_info->children = eina_list_append(obj_info->children, child);
859 * This object is not registered as an access object.
860 * So the developer should add it to access list manually, using DESC_ACCESS block.
862 return LB_STATUS_SUCCESS;
865 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
867 struct info *handle = data;
879 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
880 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
884 sx = (double)px / (double)w;
885 ex = (double)(px + pw) / (double)w;
890 sy = (double)py / (double)h;
891 ey = (double)(py + ph) / (double)h;
894 DbgPrint("Signal emit: source[%s], emission[%s]\n", source, emission);
895 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
898 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
900 struct info *handle = _info;
901 struct obj_info *obj_info;
902 struct obj_info *parent_obj_info;
906 handle->obj_list = eina_list_remove(handle->obj_list, obj);
908 obj_info = evas_object_data_del(obj, "obj_info");
910 ErrPrint("Object info is not valid\n");
914 DbgPrint("delete object %s %p\n", obj_info->id, obj);
915 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
916 if (parent_obj_info) {
920 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
921 if (child->obj != obj)
926 * If this code is executed,
927 * The parent is not deleted by desc, this object is deleted by itself.
928 * It is not possible, but we care it.
930 DbgPrint("Parent's children is updated: %s\n", child->part);
931 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
937 DbgPrint("Parent EDJE\n");
940 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
942 elm_object_focus_custom_chain_unset(obj);
944 EINA_LIST_FREE(obj_info->children, child) {
945 DbgPrint("delete object %s %p\n", child->part, child->obj);
948 ao = evas_object_data_del(child->obj, "ao");
950 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
951 evas_object_data_del(ao, "edje");
952 elm_access_object_unregister(ao);
954 evas_object_del(child->obj);
960 EINA_LIST_FREE(obj_info->access_chain, ao) {
961 evas_object_data_del(ao, "edje");
962 elm_access_object_unregister(ao);
970 LB_ACCESS_HIGHLIGHT 0
971 LB_ACCESS_HIGHLIGHT_NEXT 1
972 LB_ACCESS_HIGHLIGHT_PREV 2
977 PUBLIC int script_feed_event(void *h, Evas *e, int event_type, int x, int y, int down, double timestamp)
979 struct info *handle = h;
981 struct obj_info *obj_info;
982 int ret = LB_STATUS_SUCCESS;
984 DbgPrint("event: %d, x: %d, y: %d\n", event_type, x, y);
986 edje = find_edje(handle, NULL); /*!< Get the base layout */
988 ErrPrint("Base layout is not exist\n");
989 return LB_STATUS_ERROR_NOT_EXIST;
992 obj_info = evas_object_data_get(edje, "obj_info");
994 ErrPrint("Object info is not valid\n");
995 return LB_STATUS_ERROR_INVALID;
998 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
999 Elm_Access_Action_Info *info;
1000 Elm_Access_Action_Type action;
1001 const Eina_List *chain;
1003 info = calloc(1, sizeof(*info));
1005 ErrPrint("Error: %s\n", strerror(errno));
1006 return LB_STATUS_ERROR_MEMORY;
1009 chain = elm_object_focus_custom_chain_get(edje);
1010 DbgPrint("Focus chain : %d\n", eina_list_count(chain));
1012 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
1013 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1016 ret = elm_access_action(edje, action, info);
1017 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1018 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1019 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1020 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1021 info->highlight_cycle = EINA_FALSE;
1022 ret = elm_access_action(edje, action, info);
1023 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1024 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
1025 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1026 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1027 info->highlight_cycle = EINA_FALSE;
1028 ret = elm_access_action(edje, action, info);
1029 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1030 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
1031 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
1032 action = ELM_ACCESS_ACTION_ACTIVATE;
1033 ret = elm_access_action(edje, action, info);
1034 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1035 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1036 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
1038 action = ELM_ACCESS_ACTION_UP;
1039 ret = elm_access_action(edje, action, info);
1040 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1041 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1042 } else if (down == 1) {
1043 action = ELM_ACCESS_ACTION_DOWN;
1044 ret = elm_access_action(edje, action, info);
1045 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1046 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1048 ErrPrint("Invalid access event\n");
1049 ret = LB_ACCESS_STATUS_ERROR;
1051 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
1052 action = ELM_ACCESS_ACTION_SCROLL;
1057 info->mouse_type = 0;
1058 ret = elm_access_action(edje, action, info);
1059 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1060 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1063 info->mouse_type = 1;
1064 ret = elm_access_action(edje, action, info);
1065 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1066 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1069 info->mouse_type = 2;
1070 ret = elm_access_action(edje, action, info);
1071 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1072 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1075 ret = LB_ACCESS_STATUS_ERROR;
1078 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
1079 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1080 ret = elm_access_action(edje, action, info);
1081 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1082 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1084 DbgPrint("Invalid event\n");
1085 ret = LB_ACCESS_STATUS_ERROR;
1089 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
1090 switch (event_type) {
1091 case LB_SCRIPT_MOUSE_DOWN:
1092 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
1093 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
1095 case LB_SCRIPT_MOUSE_MOVE:
1096 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
1098 case LB_SCRIPT_MOUSE_UP:
1099 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
1100 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.1f, NULL);
1102 case LB_SCRIPT_MOUSE_IN:
1103 evas_event_feed_mouse_in(e, timestamp, NULL);
1105 case LB_SCRIPT_MOUSE_OUT:
1106 evas_event_feed_mouse_out(e, timestamp, NULL);
1109 return LB_STATUS_ERROR_INVALID;
1111 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
1112 DbgPrint("Key event is not implemented\n");
1113 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
1119 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)
1121 struct info *handle = h;
1124 struct obj_info *obj_info;
1125 struct child *child;
1126 char _target_id[32];
1128 DbgPrint("src_id[%s] target_id[%s] part[%s] path[%s] group[%s]\n", src_id, target_id, part, path, group);
1130 edje = find_edje(handle, src_id);
1132 ErrPrint("Edje is not exists\n");
1133 return LB_STATUS_ERROR_NOT_EXIST;
1136 obj_info = evas_object_data_get(edje, "obj_info");
1138 ErrPrint("Object info is not valid\n");
1139 return LB_STATUS_ERROR_INVALID;
1142 obj = elm_object_part_content_unset(edje, part);
1147 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
1148 if (child->obj != obj)
1151 obj_info->children = eina_list_remove(obj_info->children, child);
1158 DbgPrint("delete object %s %p\n", part, obj);
1161 * This will call the edje_del_cb.
1162 * It will delete all access objects
1164 evas_object_del(obj);
1167 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1168 DbgPrint("SKIP - Path: [%s]\n", path);
1169 return LB_STATUS_SUCCESS;
1173 if (find_edje(handle, part)) {
1178 if (gettimeofday(&tv, NULL) < 0) {
1179 static int local_idx = 0;
1180 timestamp = (double)(local_idx++);
1182 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 if (!elm_layout_file_set(obj, path, group)) {
1206 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1207 errmsg = edje_load_error_str(err);
1208 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
1209 evas_object_del(obj);
1210 return LB_STATUS_ERROR_IO;
1213 evas_object_show(obj);
1215 obj_info = calloc(1, sizeof(*obj_info));
1217 ErrPrint("Failed to add a obj_info\n");
1218 evas_object_del(obj);
1219 return LB_STATUS_ERROR_MEMORY;
1222 obj_info->id = strdup(target_id);
1223 if (!obj_info->id) {
1224 ErrPrint("Failed to add a obj_info\n");
1226 evas_object_del(obj);
1227 return LB_STATUS_ERROR_MEMORY;
1230 obj_info->parent = edje;
1232 child = malloc(sizeof(*child));
1234 ErrPrint("Error: %s\n", strerror(errno));
1237 evas_object_del(obj);
1238 return LB_STATUS_ERROR_MEMORY;
1241 child->part = strdup(part);
1243 ErrPrint("Error: %s\n", strerror(errno));
1247 evas_object_del(obj);
1248 return LB_STATUS_ERROR_MEMORY;
1253 evas_object_data_set(obj, "obj_info", obj_info);
1254 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1255 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1256 handle->obj_list = eina_list_append(handle->obj_list, obj);
1258 DbgPrint("%s part swallow edje %p\n", part, obj);
1259 elm_object_part_content_set(edje, part, obj);
1261 obj_info = evas_object_data_get(edje, "obj_info");
1262 obj_info->children = eina_list_append(obj_info->children, child);
1263 return LB_STATUS_SUCCESS;
1266 PUBLIC int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
1268 struct info *handle = h;
1271 DbgPrint("id[%s], part[%s], signal[%s]\n", id, part, signal);
1273 edje = find_edje(handle, id);
1275 return LB_STATUS_ERROR_NOT_EXIST;
1277 elm_object_signal_emit(edje, signal, part);
1278 return LB_STATUS_SUCCESS;
1281 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1283 struct info *handle = h;
1286 DbgPrint("id[%s], part[%s], %lfx%lf\n", id, part, x, y);
1288 edje = find_edje(handle, id);
1290 return LB_STATUS_ERROR_NOT_EXIST;
1292 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1293 return LB_STATUS_SUCCESS;
1296 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1298 struct info *handle = han;
1301 edje = find_edje(handle, id);
1303 return LB_STATUS_ERROR_NOT_EXIST;
1310 DbgPrint("Resize object to %dx%d\n", w, h);
1311 evas_object_resize(edje, w, h);
1312 return LB_STATUS_SUCCESS;
1315 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1317 struct info *handle = h;
1319 DbgPrint("id[%s], category[%s]\n", id, category);
1321 if (handle->category) {
1322 free(handle->category);
1323 handle->category = NULL;
1327 return LB_STATUS_SUCCESS;
1329 handle->category = strdup(category);
1330 if (!handle->category) {
1331 ErrPrint("Error: %s\n", strerror(errno));
1332 return LB_STATUS_ERROR_MEMORY;
1335 return LB_STATUS_SUCCESS;
1338 PUBLIC void *script_create(const char *file, const char *group)
1340 struct info *handle;
1342 DbgPrint("file[%s], group[%s]\n", file, group);
1344 handle = calloc(1, sizeof(*handle));
1346 ErrPrint("Error: %s\n", strerror(errno));
1350 handle->file = strdup(file);
1351 if (!handle->file) {
1352 ErrPrint("Error: %s\n", strerror(errno));
1357 handle->group = strdup(group);
1358 if (!handle->group) {
1359 ErrPrint("Error: %s\n", strerror(errno));
1365 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1370 PUBLIC int script_destroy(void *_handle)
1372 struct info *handle;
1377 if (!eina_list_data_find(s_info.handle_list, handle)) {
1378 DbgPrint("Not found (already deleted?)\n");
1379 return LB_STATUS_ERROR_NOT_EXIST;
1382 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1384 edje = eina_list_nth(handle->obj_list, 0);
1386 evas_object_del(edje);
1388 free(handle->category);
1390 free(handle->group);
1392 return LB_STATUS_SUCCESS;
1395 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1397 struct info *handle;
1399 struct obj_info *obj_info;
1403 obj_info = calloc(1, sizeof(*obj_info));
1405 ErrPrint("Heap: %s\n", strerror(errno));
1406 return LB_STATUS_ERROR_MEMORY;
1409 obj_info->parent = evas_object_rectangle_add(e);
1410 if (!obj_info->parent) {
1411 ErrPrint("Unable to create a parent box\n");
1413 return LB_STATUS_ERROR_FAULT;
1416 edje = elm_layout_add(obj_info->parent);
1418 ErrPrint("Failed to create an edje object\n");
1419 evas_object_del(obj_info->parent);
1421 return LB_STATUS_ERROR_FAULT;
1424 DbgPrint("Load edje: %s - %s\n", handle->file, handle->group);
1425 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1429 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1430 errmsg = edje_load_error_str(err);
1431 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
1432 evas_object_del(edje);
1433 evas_object_del(obj_info->parent);
1435 return LB_STATUS_ERROR_IO;
1442 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1443 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1444 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1445 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1446 evas_object_resize(edje, handle->w, handle->h);
1447 evas_object_show(edje);
1448 evas_object_data_set(edje, "obj_info", obj_info);
1450 handle->obj_list = eina_list_append(handle->obj_list, edje);
1451 return LB_STATUS_SUCCESS;
1454 PUBLIC int script_unload(void *_handle, Evas *e)
1456 struct info *handle;
1458 Evas_Object *parent = NULL;
1462 DbgPrint("Unload edje: %s - %s\n", handle->file, handle->group);
1463 edje = eina_list_nth(handle->obj_list, 0);
1465 struct obj_info *obj_info;
1467 obj_info = evas_object_data_get(edje, "obj_info");
1469 parent = obj_info->parent;
1470 evas_object_del(edje);
1474 DbgPrint("Delete parent box\n");
1475 evas_object_del(parent);
1479 return LB_STATUS_SUCCESS;
1482 static void access_cb(keynode_t *node, void *user_data)
1487 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1488 ErrPrint("Idle lock state is not valid\n");
1489 state = 0; /* DISABLED */
1492 state = vconf_keynode_get_bool(node);
1495 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1496 elm_config_access_set(state);
1499 static void update_font_cb(void *data)
1501 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1502 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1505 static void font_changed_cb(keynode_t *node, void *user_data)
1509 font_name = vconf_get_str("db/setting/accessibility/font_name");
1511 ErrPrint("Invalid font name (NULL)\n");
1515 if (s_info.font_name && !strcmp(s_info.font_name, font_name)) {
1516 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1521 if (s_info.font_name) {
1522 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1523 free(s_info.font_name);
1524 s_info.font_name = NULL;
1527 s_info.font_name = font_name;
1528 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1532 * Try to update all liveboxes
1534 update_font_cb(NULL);
1537 static inline int convert_font_size(int size)
1540 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1543 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1546 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1549 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1552 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1560 DbgPrint("Return size: %d\n", size);
1564 static void font_size_cb(system_settings_key_e key, void *user_data)
1568 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE)
1571 size = convert_font_size(size);
1573 if (size == s_info.font_size) {
1574 DbgPrint("Font size is not changed\n");
1578 s_info.font_size = size;
1579 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
1582 PUBLIC int script_init(void)
1585 int size = DEFAULT_FONT_SIZE;
1590 /* ecore is already initialized */
1592 elm_config_scale_set(scale_get());
1594 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1596 ErrPrint("Failed to access cb\n");
1598 access_cb(NULL, NULL);
1600 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
1601 DbgPrint("System font is changed: %d\n", ret);
1603 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1604 DbgPrint("System font size is changed: %d\n", ret);
1606 s_info.font_name = vconf_get_str("db/setting/accessibility/font_name");
1607 DbgPrint("Current font: %s\n", s_info.font_name);
1609 ret = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size);
1610 s_info.font_size = convert_font_size(size);
1611 DbgPrint("Current size: %d\n", s_info.font_size);
1613 return LB_STATUS_SUCCESS;
1616 PUBLIC int script_fini(void)
1621 struct info *handle;
1623 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
1624 script_destroy(handle);
1627 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1628 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
1629 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1631 return LB_STATUS_SUCCESS;