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;
93 static inline double scale_get(void)
97 ecore_x_window_size_get(0, &width, &height);
98 return (double)width / BASE_WIDTH;
101 static inline Evas_Object *find_edje(struct info *handle, const char *id)
105 struct obj_info *obj_info;
107 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
108 obj_info = evas_object_data_get(edje, "obj_info");
110 ErrPrint("Object info is not valid\n");
119 } else if (!obj_info->id) {
123 if (!strcmp(obj_info->id, id))
127 DbgPrint("EDJE[%s] is not found\n", id);
131 static inline void rebuild_focus_chain(Evas_Object *obj)
133 struct obj_info *obj_info;
137 obj_info = evas_object_data_get(obj, "obj_info");
139 ErrPrint("Object info is not available\n");
143 elm_object_focus_custom_chain_unset(obj);
145 DbgPrint("Rebuild focus chain begin\n");
146 EINA_LIST_FOREACH(obj_info->access_chain, l, ao) {
147 DbgPrint("Append %p\n", ao);
148 elm_object_focus_custom_chain_append(obj, ao, NULL);
150 DbgPrint("Rebuild focus chain done\n");
153 PUBLIC const char *script_magic_id(void)
158 PUBLIC int script_update_color(void *h, Evas *e, const char *id, const char *part, const char *rgba)
160 struct info *handle = h;
162 int r[3], g[3], b[3], a[3];
165 edje = find_edje(handle, id);
167 return LB_STATUS_ERROR_NOT_EXIST;
169 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
170 r, g, b, a, /* OBJECT */
171 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
172 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
174 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
175 return LB_STATUS_ERROR_INVALID;
178 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
179 r[0], g[0], b[0], a[0], /* OBJECT */
180 r[1], g[1], b[1], a[1], /* OUTLINE */
181 r[2], g[2], b[2], a[2]); /* SHADOW */
183 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
184 return LB_STATUS_SUCCESS;
187 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
199 ao = evas_object_data_get(part_obj, "ao");
203 edje = evas_object_data_get(ao, "edje");
207 e = evas_object_evas_get(part_obj);
208 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
212 if (gettimeofday(&tv, NULL) < 0) {
213 ErrPrint("Failed to get time\n");
216 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
219 DbgPrint("Cursor is on %dx%d\n", x, y);
220 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
221 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
222 evas_event_feed_mouse_move(e, x, y, timestamp + 0.02f, NULL);
223 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.03f, NULL);
226 PUBLIC int script_update_text(void *h, Evas *e, const char *id, const char *part, const char *text)
228 struct obj_info *obj_info;
229 struct info *handle = h;
233 edje = find_edje(handle, id);
235 ErrPrint("Failed to find EDJE\n");
236 return LB_STATUS_ERROR_NOT_EXIST;
239 obj_info = evas_object_data_get(edje, "obj_info");
241 ErrPrint("Object info is not available\n");
242 return LB_STATUS_ERROR_FAULT;
245 elm_object_part_text_set(edje, part, text ? text : "");
247 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
252 ao = evas_object_data_get(to, "ao");
254 ao = elm_access_object_register(to, edje);
256 ErrPrint("Unable to add ao: %s\n", part);
259 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
260 evas_object_data_set(to, "ao", ao);
261 evas_object_data_set(ao, "edje", edje);
262 elm_access_activate_cb_set(ao, activate_cb, NULL);
263 elm_object_focus_custom_chain_append(edje, ao, NULL);
266 if (!text || !strlen(text)) {
267 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
268 evas_object_data_del(to, "ao");
269 evas_object_data_del(ao, "edje");
270 elm_access_object_unregister(ao);
271 DbgPrint("[%s] Remove access object\n", part);
273 rebuild_focus_chain(edje);
277 utf8 = elm_entry_markup_to_utf8(text);
278 if ((!utf8 || !strlen(utf8))) {
281 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
282 evas_object_data_del(to, "ao");
283 evas_object_data_del(ao, "edje");
284 elm_access_object_unregister(ao);
285 DbgPrint("[%s] Remove access object\n", part);
287 rebuild_focus_chain(edje);
291 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
292 DbgPrint("[%s] Update access object (%s)\n", part, utf8);
295 ErrPrint("Unable to get text part[%s]\n", part);
299 return LB_STATUS_SUCCESS;
302 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
304 while (len > 0 && *value == ' ') {
312 img_opt->aspect = !strncasecmp(value, "true", 4);
313 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
316 static void parse_orient(struct image_option *img_opt, const char *value, int len)
318 while (len > 0 && *value == ' ') {
326 img_opt->orient = !strncasecmp(value, "true", 4);
327 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
330 static void parse_size(struct image_option *img_opt, const char *value, int len)
336 while (len > 0 && *value == ' ') {
341 buf = strndup(value, len);
343 ErrPrint("Heap: %s\n", strerror(errno));
347 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
348 img_opt->width = width;
349 img_opt->height = height;
350 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
352 DbgPrint("Invalid size tag[%s]\n", buf);
358 static void parse_fill(struct image_option *img_opt, const char *value, int len)
360 while (len > 0 && *value == ' ') {
365 if (!strncasecmp(value, "in-size", len))
366 img_opt->fill = FILL_IN_SIZE;
367 else if (!strncasecmp(value, "over-size", len))
368 img_opt->fill = FILL_OVER_SIZE;
370 img_opt->fill = FILL_DISABLE;
372 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
375 static inline void parse_image_option(const char *option, struct image_option *img_opt)
382 void (*handler)(struct image_option *img_opt, const char *value, int len);
385 .cmd = "aspect", /* Keep the aspect ratio */
386 .handler = parse_aspect,
389 .cmd = "orient", /* Keep the orientation value: for the rotated images */
390 .handler = parse_orient,
393 .cmd = "fill", /* Fill the image to its container */
394 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
398 .handler = parse_size,
412 if (!option || !*option)
418 * GCC 4.7 warnings uninitialized idx and tag value.
419 * But it will be initialized by the state machine. :(
420 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
427 for (ptr = option; state != STATE_END; ptr++) {
442 cmd = cmd_list[tag].cmd;
448 } else if (*ptr == '\0') {
453 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
458 state = STATE_IGNORE;
461 } else if (*ptr == '\0') {
463 } else if (cmd[idx] == *ptr) {
469 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
473 cmd = cmd_list[tag].cmd;
479 if (*ptr == ';' || *ptr == '\0') {
480 cmd_list[tag].handler(img_opt, value + 1, idx);
481 state = *ptr ? STATE_START : STATE_END;
489 else if (*ptr == '\0')
498 PUBLIC int script_update_access(void *_h, Evas *e, const char *id, const char *part, const char *text, const char *option)
500 struct info *handle = _h;
502 struct obj_info *obj_info;
505 edje = find_edje(handle, id);
507 ErrPrint("No such object: %s\n", id);
508 return LB_STATUS_ERROR_NOT_EXIST;
511 obj_info = evas_object_data_get(edje, "obj_info");
513 ErrPrint("Object info is not available\n");
514 return LB_STATUS_ERROR_FAULT;
517 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
521 ao = evas_object_data_get(to, "ao");
523 DbgPrint("[%s] Update access object (%s)\n", part, text);
524 if (text && strlen(text)) {
525 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
527 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
528 evas_object_data_del(to, "ao");
529 evas_object_data_del(ao, "edje");
530 elm_access_object_unregister(ao);
531 DbgPrint("Successfully unregistered\n");
533 rebuild_focus_chain(edje);
535 } else if (text && strlen(text)) {
536 ao = elm_access_object_register(to, edje);
538 ErrPrint("Unable to register access object\n");
540 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
541 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
542 evas_object_data_set(to, "ao", ao);
543 elm_object_focus_custom_chain_append(edje, ao, NULL);
544 DbgPrint("[%s] Register access info: (%s)\n", part, text);
545 evas_object_data_set(ao, "edje", edje);
546 elm_access_activate_cb_set(ao, activate_cb, NULL);
550 ErrPrint("[%s] is not exists\n", part);
553 return LB_STATUS_SUCCESS;
556 PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path, const char *option)
558 struct info *handle = _h;
563 struct obj_info *obj_info;
565 struct image_option img_opt = {
568 .fill = FILL_DISABLE,
573 edje = find_edje(handle, id);
575 ErrPrint("No such object: %s\n", id);
576 return LB_STATUS_ERROR_NOT_EXIST;
579 obj_info = evas_object_data_get(edje, "obj_info");
581 ErrPrint("Object info is not available\n");
582 return LB_STATUS_ERROR_FAULT;
585 img = elm_object_part_content_unset(edje, part);
591 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
592 if (child->obj != img)
595 obj_info->children = eina_list_remove(obj_info->children, child);
601 DbgPrint("delete object %s %p\n", part, img);
602 ao = evas_object_data_del(img, "ao");
604 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
605 evas_object_data_del(ao, "edje");
606 elm_access_object_unregister(ao);
607 DbgPrint("Successfully unregistered\n");
609 evas_object_del(img);
611 rebuild_focus_chain(edje);
614 if (!path || !strlen(path) || access(path, R_OK) != 0) {
615 DbgPrint("SKIP - Path: [%s]\n", path);
616 return LB_STATUS_SUCCESS;
619 child = malloc(sizeof(*child));
621 ErrPrint("Heap: %s\n", strerror(errno));
622 return LB_STATUS_ERROR_MEMORY;
625 child->part = strdup(part);
627 ErrPrint("Heap: %s\n", strerror(errno));
629 return LB_STATUS_ERROR_MEMORY;
632 img = evas_object_image_add(e);
634 ErrPrint("Failed to add an image object\n");
637 return LB_STATUS_ERROR_FAULT;
640 evas_object_image_preload(img, EINA_FALSE);
641 parse_image_option(option, &img_opt);
642 evas_object_image_load_orientation_set(img, img_opt.orient);
644 evas_object_image_file_set(img, path, NULL);
645 err = evas_object_image_load_error_get(img);
646 if (err != EVAS_LOAD_ERROR_NONE) {
647 ErrPrint("Load error: %s\n", evas_load_error_str(err));
648 evas_object_del(img);
651 return LB_STATUS_ERROR_IO;
654 evas_object_image_size_get(img, &w, &h);
655 if (img_opt.aspect) {
656 if (img_opt.fill == FILL_OVER_SIZE) {
660 if (img_opt.width >= 0 && img_opt.height >= 0) {
661 part_w = img_opt.width * scale_get();
662 part_h = img_opt.height * scale_get();
666 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
668 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
670 if (part_w > w || part_h > h) {
674 fw = (double)part_w / (double)w;
675 fh = (double)part_h / (double)h;
685 DbgPrint("Size: %dx%d\n", w, h);
687 evas_object_image_load_size_set(img, w, h);
688 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
689 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
690 evas_object_image_reload(img);
691 } else if (img_opt.fill == FILL_IN_SIZE) {
695 if (img_opt.width >= 0 && img_opt.height >= 0) {
696 part_w = img_opt.width * scale_get();
697 part_h = img_opt.height * scale_get();
701 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
703 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
705 if (part_w > w || part_h > h) {
709 fw = (double)part_w / (double)w;
710 fh = (double)part_h / (double)h;
720 DbgPrint("Size: %dx%d\n", w, h);
721 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
722 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
723 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
725 evas_object_image_fill_set(img, 0, 0, w, h);
726 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
727 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
730 if (img_opt.width >= 0 && img_opt.height >= 0) {
733 DbgPrint("Using given image size: %dx%d\n", w, h);
736 evas_object_image_fill_set(img, 0, 0, w, h);
737 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
738 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
743 * object will be shown by below statement automatically
745 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
747 elm_object_part_content_set(edje, part, img);
748 obj_info->children = eina_list_append(obj_info->children, child);
752 * This object is not registered as an access object.
753 * So the developer should add it to access list manually, using DESC_ACCESS block.
755 return LB_STATUS_SUCCESS;
758 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
760 struct info *handle = data;
772 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
773 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
777 sx = (double)px / (double)w;
778 ex = (double)(px + pw) / (double)w;
783 sy = (double)py / (double)h;
784 ey = (double)(py + ph) / (double)h;
787 DbgPrint("Signal emit: source[%s], emission[%s]\n", source, emission);
788 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
791 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
793 struct info *handle = _info;
794 struct obj_info *obj_info;
798 handle->obj_list = eina_list_remove(handle->obj_list, obj);
800 obj_info = evas_object_data_del(obj, "obj_info");
802 ErrPrint("Object info is not valid\n");
806 DbgPrint("delete object %s %p\n", obj_info->id, obj);
808 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
810 elm_object_focus_custom_chain_unset(obj);
812 EINA_LIST_FREE(obj_info->children, child) {
813 DbgPrint("delete object %s %p\n", child->part, child->obj);
816 ao = evas_object_data_del(child->obj, "ao");
818 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
819 evas_object_data_del(ao, "edje");
820 elm_access_object_unregister(ao);
822 evas_object_del(child->obj);
828 EINA_LIST_FREE(obj_info->access_chain, ao) {
829 evas_object_data_del(ao, "edje");
830 elm_access_object_unregister(ao);
838 LB_ACCESS_HIGHLIGHT 0
839 LB_ACCESS_HIGHLIGHT_NEXT 1
840 LB_ACCESS_HIGHLIGHT_PREV 2
845 PUBLIC int script_feed_event(void *h, Evas *e, int event_type, int x, int y, int down, double timestamp)
847 struct info *handle = h;
849 struct obj_info *obj_info;
850 int ret = LB_STATUS_SUCCESS;
852 DbgPrint("event: %d, x: %d, y: %d\n", event_type, x, y);
854 edje = find_edje(handle, NULL); /*!< Get the base layout */
856 ErrPrint("Base layout is not exist\n");
857 return LB_STATUS_ERROR_NOT_EXIST;
860 obj_info = evas_object_data_get(edje, "obj_info");
862 ErrPrint("Object info is not valid\n");
863 return LB_STATUS_ERROR_INVALID;
866 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
867 Elm_Access_Action_Info *info;
868 Elm_Access_Action_Type action;
869 const Eina_List *chain;
871 info = calloc(1, sizeof(*info));
873 ErrPrint("Error: %s\n", strerror(errno));
874 return LB_STATUS_ERROR_MEMORY;
877 chain = elm_object_focus_custom_chain_get(edje);
878 DbgPrint("Focus chain : %d\n", eina_list_count(chain));
880 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
881 action = ELM_ACCESS_ACTION_HIGHLIGHT;
884 ret = elm_access_action(edje, action, info);
885 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
886 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
887 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
888 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
889 info->highlight_cycle = EINA_FALSE;
890 ret = elm_access_action(edje, action, info);
891 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
892 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
893 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
894 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
895 info->highlight_cycle = EINA_FALSE;
896 ret = elm_access_action(edje, action, info);
897 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
898 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
899 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
900 action = ELM_ACCESS_ACTION_ACTIVATE;
901 ret = elm_access_action(edje, action, info);
902 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
903 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
904 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
906 action = ELM_ACCESS_ACTION_UP;
907 ret = elm_access_action(edje, action, info);
908 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
909 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
910 } else if (down == 1) {
911 action = ELM_ACCESS_ACTION_DOWN;
912 ret = elm_access_action(edje, action, info);
913 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
914 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
916 ErrPrint("Invalid access event\n");
917 ret = LB_ACCESS_STATUS_ERROR;
919 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
920 action = ELM_ACCESS_ACTION_SCROLL;
925 info->mouse_type = 0;
926 ret = elm_access_action(edje, action, info);
927 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
928 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
931 info->mouse_type = 1;
932 ret = elm_access_action(edje, action, info);
933 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
934 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
937 info->mouse_type = 2;
938 ret = elm_access_action(edje, action, info);
939 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
940 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
943 ret = LB_ACCESS_STATUS_ERROR;
946 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
947 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
948 ret = elm_access_action(edje, action, info);
949 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
950 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
952 DbgPrint("Invalid event\n");
953 ret = LB_ACCESS_STATUS_ERROR;
957 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
958 switch (event_type) {
959 case LB_SCRIPT_MOUSE_DOWN:
960 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
961 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
963 case LB_SCRIPT_MOUSE_MOVE:
964 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
966 case LB_SCRIPT_MOUSE_UP:
967 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
968 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.1f, NULL);
970 case LB_SCRIPT_MOUSE_IN:
971 evas_event_feed_mouse_in(e, timestamp, NULL);
973 case LB_SCRIPT_MOUSE_OUT:
974 evas_event_feed_mouse_out(e, timestamp, NULL);
977 return LB_STATUS_ERROR_INVALID;
979 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
980 DbgPrint("Key event is not implemented\n");
981 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
987 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)
989 struct info *handle = h;
992 struct obj_info *obj_info;
995 DbgPrint("src_id[%s] target_id[%s] part[%s] path[%s] group[%s]\n", src_id, target_id, part, path, group);
997 edje = find_edje(handle, src_id);
999 ErrPrint("Edje is not exists\n");
1000 return LB_STATUS_ERROR_NOT_EXIST;
1003 obj_info = evas_object_data_get(edje, "obj_info");
1005 ErrPrint("Object info is not valid\n");
1006 return LB_STATUS_ERROR_INVALID;
1009 obj = elm_object_part_content_unset(edje, part);
1014 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
1015 if (child->obj != obj)
1018 obj_info->children = eina_list_remove(obj_info->children, child);
1025 DbgPrint("delete object %s %p\n", part, obj);
1028 * This will call the edje_del_cb.
1029 * It will delete all access objects
1031 evas_object_del(obj);
1034 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1035 DbgPrint("SKIP - Path: [%s]\n", path);
1036 return LB_STATUS_SUCCESS;
1039 obj = elm_layout_add(edje);
1041 ErrPrint("Failed to add a new edje object\n");
1042 return LB_STATUS_ERROR_FAULT;
1045 if (!elm_layout_file_set(obj, path, group)) {
1049 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1050 errmsg = edje_load_error_str(err);
1051 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
1052 evas_object_del(obj);
1053 return LB_STATUS_ERROR_IO;
1056 evas_object_show(obj);
1058 obj_info = calloc(1, sizeof(*obj_info));
1060 ErrPrint("Failed to add a obj_info\n");
1061 evas_object_del(obj);
1062 return LB_STATUS_ERROR_MEMORY;
1065 obj_info->id = strdup(target_id);
1066 if (!obj_info->id) {
1067 ErrPrint("Failed to add a obj_info\n");
1069 evas_object_del(obj);
1070 return LB_STATUS_ERROR_MEMORY;
1073 child = malloc(sizeof(*child));
1075 ErrPrint("Error: %s\n", strerror(errno));
1078 evas_object_del(obj);
1079 return LB_STATUS_ERROR_MEMORY;
1082 child->part = strdup(part);
1084 ErrPrint("Error: %s\n", strerror(errno));
1088 evas_object_del(obj);
1089 return LB_STATUS_ERROR_MEMORY;
1094 evas_object_data_set(obj, "obj_info", obj_info);
1095 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1096 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1097 handle->obj_list = eina_list_append(handle->obj_list, obj);
1099 DbgPrint("%s part swallow edje %p\n", part, obj);
1100 elm_object_part_content_set(edje, part, obj);
1101 obj_info = evas_object_data_get(edje, "obj_info");
1102 obj_info->children = eina_list_append(obj_info->children, child);
1103 return LB_STATUS_SUCCESS;
1106 PUBLIC int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
1108 struct info *handle = h;
1111 DbgPrint("id[%s], part[%s], signal[%s]\n", id, part, signal);
1113 edje = find_edje(handle, id);
1115 return LB_STATUS_ERROR_NOT_EXIST;
1117 elm_object_signal_emit(edje, signal, part);
1118 return LB_STATUS_SUCCESS;
1121 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1123 struct info *handle = h;
1126 DbgPrint("id[%s], part[%s], %lfx%lf\n", id, part, x, y);
1128 edje = find_edje(handle, id);
1130 return LB_STATUS_ERROR_NOT_EXIST;
1132 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1133 return LB_STATUS_SUCCESS;
1136 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1138 struct info *handle = han;
1141 edje = find_edje(handle, id);
1143 return LB_STATUS_ERROR_NOT_EXIST;
1150 DbgPrint("Resize object to %dx%d\n", w, h);
1151 evas_object_resize(edje, w, h);
1152 return LB_STATUS_SUCCESS;
1155 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1157 struct info *handle = h;
1159 DbgPrint("id[%s], category[%s]\n", id, category);
1161 if (handle->category) {
1162 free(handle->category);
1163 handle->category = NULL;
1167 return LB_STATUS_SUCCESS;
1169 handle->category = strdup(category);
1170 if (!handle->category) {
1171 ErrPrint("Error: %s\n", strerror(errno));
1172 return LB_STATUS_ERROR_MEMORY;
1175 return LB_STATUS_SUCCESS;
1178 PUBLIC void *script_create(const char *file, const char *group)
1180 struct info *handle;
1182 DbgPrint("file[%s], group[%s]\n", file, group);
1184 handle = calloc(1, sizeof(*handle));
1186 ErrPrint("Error: %s\n", strerror(errno));
1190 handle->file = strdup(file);
1191 if (!handle->file) {
1192 ErrPrint("Error: %s\n", strerror(errno));
1197 handle->group = strdup(group);
1198 if (!handle->group) {
1199 ErrPrint("Error: %s\n", strerror(errno));
1208 PUBLIC int script_destroy(void *_handle)
1210 struct info *handle;
1215 edje = eina_list_nth(handle->obj_list, 0);
1217 evas_object_del(edje);
1219 free(handle->category);
1221 free(handle->group);
1223 return LB_STATUS_SUCCESS;
1226 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1228 struct info *handle;
1230 struct obj_info *obj_info;
1234 obj_info = calloc(1, sizeof(*obj_info));
1236 ErrPrint("Heap: %s\n", strerror(errno));
1237 return LB_STATUS_ERROR_MEMORY;
1240 obj_info->win = evas_object_rectangle_add(e);
1241 if (!obj_info->win) {
1243 return LB_STATUS_ERROR_FAULT;
1246 edje = elm_layout_add(obj_info->win);
1248 ErrPrint("Failed to create an edje object\n");
1249 evas_object_del(obj_info->win);
1251 return LB_STATUS_ERROR_FAULT;
1254 DbgPrint("Load edje: %s - %s\n", handle->file, handle->group);
1255 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1259 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1260 errmsg = edje_load_error_str(err);
1261 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
1262 evas_object_del(edje);
1263 evas_object_del(obj_info->win);
1265 return LB_STATUS_ERROR_IO;
1272 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1273 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1274 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1275 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1276 evas_object_resize(edje, handle->w, handle->h);
1277 evas_object_show(edje);
1278 evas_object_data_set(edje, "obj_info", obj_info);
1280 handle->obj_list = eina_list_append(handle->obj_list, edje);
1281 return LB_STATUS_SUCCESS;
1284 PUBLIC int script_unload(void *_handle, Evas *e)
1286 struct info *handle;
1291 DbgPrint("Unload edje: %s - %s\n", handle->file, handle->group);
1292 edje = eina_list_nth(handle->obj_list, 0);
1294 evas_object_del(edje);
1296 return LB_STATUS_SUCCESS;
1299 static void access_cb(keynode_t *node, void *user_data)
1304 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1305 ErrPrint("Idle lock state is not valid\n");
1306 state = 0; /* DISABLED */
1309 state = vconf_keynode_get_bool(node);
1312 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1313 elm_config_access_set(state);
1316 static void update_font_cb(void *data)
1318 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1319 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1322 static void font_changed_cb(keynode_t *node, void *user_data)
1326 font_name = vconf_get_str("db/setting/accessibility/font_name");
1328 ErrPrint("Invalid font name (NULL)\n");
1332 if (s_info.font_name && !strcmp(s_info.font_name, font_name)) {
1333 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1338 if (s_info.font_name) {
1339 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1340 free(s_info.font_name);
1341 s_info.font_name = NULL;
1344 s_info.font_name = font_name;
1345 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1349 * Try to update all liveboxes
1351 update_font_cb(NULL);
1354 static inline int convert_font_size(int size)
1357 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1360 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1363 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1366 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1369 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1377 DbgPrint("Return size: %d\n", size);
1381 static void font_size_cb(system_settings_key_e key, void *user_data)
1385 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE)
1388 size = convert_font_size(size);
1390 if (size == s_info.font_size) {
1391 DbgPrint("Font size is not changed\n");
1395 s_info.font_size = size;
1396 DbgPrint("Font size is changed to %d\n", size);
1398 update_font_cb(NULL);
1401 PUBLIC int script_init(void)
1404 int size = DEFAULT_FONT_SIZE;
1409 /* ecore is already initialized */
1411 elm_config_scale_set(scale_get());
1413 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1415 ErrPrint("Failed to access cb\n");
1417 access_cb(NULL, NULL);
1419 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
1420 DbgPrint("System font is changed: %d\n", ret);
1422 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1423 DbgPrint("System font size is changed: %d\n", ret);
1425 s_info.font_name = vconf_get_str("db/setting/accessibility/font_name");
1426 DbgPrint("Current font: %s\n", s_info.font_name);
1428 ret = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size);
1429 s_info.font_size = convert_font_size(size);
1430 DbgPrint("Current size: %d\n", s_info.font_size);
1432 return LB_STATUS_SUCCESS;
1435 PUBLIC int script_fini(void)
1438 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1439 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_TYPE);
1440 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1442 return LB_STATUS_SUCCESS;