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>
30 #include <efl_assist.h>
32 #include <system_settings.h>
37 #include <livebox-errno.h>
38 #include <livebox-service.h>
40 #include "script_port.h"
43 #define TEXT_CLASS "tizen"
44 #define DEFAULT_FONT_SIZE -100
46 #define PUBLIC __attribute__((visibility("default")))
84 int (*render_pre)(void *buffer_handle, void *data);
85 int (*render_post)(void *render_handle, void *data);
106 Eina_List *handle_list;
117 static inline Evas_Object *find_edje(struct info *handle, const char *id)
121 struct obj_info *obj_info;
123 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
124 obj_info = evas_object_data_get(edje, "obj_info");
126 ErrPrint("Object info is not valid\n");
136 } else if (!obj_info->id) {
140 if (!strcmp(obj_info->id, id)) {
145 DbgPrint("EDJE[%s] is not found\n", id);
149 PUBLIC const char *script_magic_id(void)
154 PUBLIC int script_update_color(void *h, const char *id, const char *part, const char *rgba)
156 struct info *handle = h;
158 int r[3], g[3], b[3], a[3];
161 edje = find_edje(handle, id);
163 return LB_STATUS_ERROR_NOT_EXIST;
166 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
167 r, g, b, a, /* OBJECT */
168 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
169 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
171 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
172 return LB_STATUS_ERROR_INVALID;
175 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
176 r[0], g[0], b[0], a[0], /* OBJECT */
177 r[1], g[1], b[1], a[1], /* OUTLINE */
178 r[2], g[2], b[2], a[2]); /* SHADOW */
180 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
181 return LB_STATUS_SUCCESS;
184 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
193 e = evas_object_evas_get(part_obj);
194 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
198 #if defined(_USE_ECORE_TIME_GET)
199 timestamp = ecore_time_get();
202 if (gettimeofday(&tv, NULL) < 0) {
203 ErrPrint("Failed to get time\n");
206 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
210 DbgPrint("Cursor is on %dx%d\n", x, y);
211 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
212 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
213 evas_event_feed_mouse_move(e, x, y, (timestamp + 0.02f) * 1000, NULL);
214 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.03f) * 1000, NULL);
217 static void update_focus_chain(struct info *handle, Evas_Object *ao)
219 const Eina_List *list;
221 list = elm_object_focus_custom_chain_get(handle->parent);
222 if (!eina_list_data_find(list, ao)) {
223 DbgPrint("Append again to the focus chain\n");
224 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
228 PUBLIC int script_update_text(void *h, const char *id, const char *part, const char *text)
230 struct obj_info *obj_info;
231 struct info *handle = h;
233 Evas_Object *edje_part;
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 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
254 ao = evas_object_data_get(edje_part, "ao");
256 ao = elm_access_object_register(edje_part, handle->parent);
258 ErrPrint("Unable to register an access object(%s)\n", part);
262 evas_object_data_set(edje_part, "ao", ao);
263 elm_access_activate_cb_set(ao, activate_cb, NULL);
264 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
266 DbgPrint("[%s] Register access info: (%s) to, %p\n", part, text, handle->parent);
269 if (!text || !strlen(text)) {
272 * Delete callback will be called
274 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
275 elm_access_object_unregister(ao);
280 utf8 = elm_entry_markup_to_utf8(text);
281 if ((!utf8 || !strlen(utf8))) {
285 * Delete callback will be called
287 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
288 elm_access_object_unregister(ao);
293 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
296 update_focus_chain(handle, ao);
298 ErrPrint("Unable to get text part[%s]\n", part);
302 return LB_STATUS_SUCCESS;
305 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
307 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 == ' ') {
331 img_opt->orient = !strncasecmp(value, "true", 4);
332 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
335 static void parse_size(struct image_option *img_opt, const char *value, int len)
341 while (len > 0 && *value == ' ') {
346 buf = strndup(value, len);
348 ErrPrint("Heap: %s\n", strerror(errno));
352 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
353 img_opt->width = width;
354 img_opt->height = height;
355 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
357 DbgPrint("Invalid size tag[%s]\n", buf);
363 static void parse_shadow(struct image_option *img_opt, const char *value, int len)
370 if (sscanf(value, "%d,%d,%d,%x", &angle, &offset, &softness, &color) != 4) {
371 ErrPrint("Invalid shadow [%s]\n", value);
373 img_opt->shadow.enabled = 1;
374 img_opt->shadow.angle = angle;
375 img_opt->shadow.offset = offset;
376 img_opt->shadow.softness = softness;
377 img_opt->shadow.color = color;
381 static void parse_fill(struct image_option *img_opt, const char *value, int len)
383 while (len > 0 && *value == ' ') {
388 if (!strncasecmp(value, "in-size", len)) {
389 img_opt->fill = FILL_IN_SIZE;
390 } else if (!strncasecmp(value, "over-size", len)) {
391 img_opt->fill = FILL_OVER_SIZE;
393 img_opt->fill = FILL_DISABLE;
396 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
399 static inline void parse_image_option(const char *option, struct image_option *img_opt)
406 void (*handler)(struct image_option *img_opt, const char *value, int len);
409 .cmd = "aspect", /* Keep the aspect ratio */
410 .handler = parse_aspect,
413 .cmd = "orient", /* Keep the orientation value: for the rotated images */
414 .handler = parse_orient,
417 .cmd = "fill", /* Fill the image to its container */
418 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
422 .handler = parse_size,
426 .handler = parse_shadow,
440 if (!option || !*option) {
447 * GCC 4.7 warnings uninitialized idx and tag value.
448 * But it will be initialized by the state machine. :(
449 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
456 for (ptr = option; state != STATE_END; ptr++) {
471 cmd = cmd_list[tag].cmd;
477 } else if (*ptr == '\0') {
482 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
487 state = STATE_IGNORE;
490 } else if (*ptr == '\0') {
492 } else if (cmd[idx] == *ptr) {
498 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
502 cmd = cmd_list[tag].cmd;
508 if (*ptr == ';' || *ptr == '\0') {
509 cmd_list[tag].handler(img_opt, value + 1, idx);
510 state = *ptr ? STATE_START : STATE_END;
518 } else if (*ptr == '\0') {
528 PUBLIC int script_update_access(void *_h, const char *id, const char *part, const char *text, const char *option)
530 struct info *handle = _h;
532 struct obj_info *obj_info;
533 Evas_Object *edje_part;
535 edje = find_edje(handle, id);
537 ErrPrint("No such object: %s\n", id);
538 return LB_STATUS_ERROR_NOT_EXIST;
541 obj_info = evas_object_data_get(edje, "obj_info");
543 ErrPrint("Object info is not available\n");
544 return LB_STATUS_ERROR_FAULT;
547 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
551 ao = evas_object_data_get(edje_part, "ao");
553 if (text && strlen(text)) {
554 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
555 DbgPrint("Access info is updated: %s [%s], %p\n", part, text, ao);
556 update_focus_chain(handle, ao);
560 * Delete clalback will be called
562 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
563 elm_access_object_unregister(ao);
565 } else if (text && strlen(text)) {
566 ao = elm_access_object_register(edje_part, handle->parent);
568 ErrPrint("Unable to register an access object(%s)\n", part);
570 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
572 evas_object_data_set(edje_part, "ao", ao);
573 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
574 elm_access_activate_cb_set(ao, activate_cb, NULL);
575 DbgPrint("[%s] Register access info: (%s) to, %p (%p)\n", part, text, handle->parent, ao);
579 ErrPrint("[%s] is not exists\n", part);
582 return LB_STATUS_SUCCESS;
585 PUBLIC int script_operate_access(void *_h, const char *id, const char *part, const char *operation, const char *option)
587 struct info *handle = _h;
589 struct obj_info *obj_info;
590 Elm_Access_Action_Info action_info;
593 if (!operation || !strlen(operation)) {
594 return LB_STATUS_ERROR_INVALID;
597 edje = find_edje(handle, id);
599 ErrPrint("No such object: %s\n", id);
600 return LB_STATUS_ERROR_NOT_EXIST;
603 obj_info = evas_object_data_get(edje, "obj_info");
605 ErrPrint("Object info is not available\n");
606 return LB_STATUS_ERROR_FAULT;
609 memset(&action_info, 0, sizeof(action_info));
611 /* OPERATION is defined in liblivebox package */
612 if (!strcasecmp(operation, "set,hl")) {
614 Evas_Object *edje_part;
620 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
622 ErrPrint("Invalid part: %s\n", part);
626 evas_object_geometry_get(edje_part, &x, &y, &w, &h);
628 action_info.x = x + w / 2;
629 action_info.y = x + h / 2;
630 } else if (option && sscanf(option, "%dx%d", &action_info.x, &action_info.y) == 2) {
632 ErrPrint("Insufficient info for HL\n");
636 DbgPrint("TXxTY: %dx%d\n", action_info.x, action_info.y);
637 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT, &action_info);
638 if (ret == EINA_FALSE) {
639 ErrPrint("Action error\n");
641 } else if (!strcasecmp(operation, "unset,hl")) {
642 ret = elm_access_action(edje, ELM_ACCESS_ACTION_UNHIGHLIGHT, &action_info);
643 if (ret == EINA_FALSE) {
644 ErrPrint("Action error\n");
646 } else if (!strcasecmp(operation, "next,hl")) {
647 action_info.highlight_cycle = (!!option) && (!!strcasecmp(option, "no,cycle"));
649 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_NEXT, &action_info);
650 if (ret == EINA_FALSE) {
651 ErrPrint("Action error\n");
653 } else if (!strcasecmp(operation, "prev,hl")) {
654 action_info.highlight_cycle = EINA_TRUE;
655 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_PREV, &action_info);
656 if (ret == EINA_FALSE) {
657 ErrPrint("Action error\n");
659 } else if (!strcasecmp(operation, "reset,focus")) {
660 DbgPrint("Reset Focus\n");
661 elm_object_focus_custom_chain_set(edje, NULL);
665 return LB_STATUS_SUCCESS;
668 static inline void apply_shadow_effect(struct image_option *img_opt, Evas_Object *img)
670 ea_effect_h *ea_effect;
672 if (!img_opt->shadow.enabled) {
676 ea_effect = ea_image_effect_create();
681 // -90, 2, 4, 0x99000000
682 ea_image_effect_add_outer_shadow(ea_effect, img_opt->shadow.angle, img_opt->shadow.offset, img_opt->shadow.softness, img_opt->shadow.color);
683 ea_object_image_effect_set(img, ea_effect);
685 ea_image_effect_destroy(ea_effect);
688 PUBLIC int script_update_image(void *_h, const char *id, const char *part, const char *path, const char *option)
690 struct info *handle = _h;
695 struct obj_info *obj_info;
696 struct image_option img_opt = {
699 .fill = FILL_DISABLE,
707 edje = find_edje(handle, id);
709 ErrPrint("No such object: %s\n", id);
710 return LB_STATUS_ERROR_NOT_EXIST;
713 obj_info = evas_object_data_get(edje, "obj_info");
715 ErrPrint("Object info is not available\n");
716 return LB_STATUS_ERROR_FAULT;
719 img = elm_object_part_content_unset(edje, part);
721 DbgPrint("delete object %s %p\n", part, img);
722 evas_object_del(img);
725 if (!path || !strlen(path) || access(path, R_OK) != 0) {
726 DbgPrint("SKIP - Path: [%s]\n", path);
727 return LB_STATUS_SUCCESS;
730 img = evas_object_image_add(handle->e);
732 ErrPrint("Failed to add an image object\n");
733 return LB_STATUS_ERROR_FAULT;
736 evas_object_image_preload(img, EINA_FALSE);
737 parse_image_option(option, &img_opt);
738 evas_object_image_load_orientation_set(img, img_opt.orient);
740 evas_object_image_file_set(img, path, NULL);
741 err = evas_object_image_load_error_get(img);
742 if (err != EVAS_LOAD_ERROR_NONE) {
743 ErrPrint("Load error: %s\n", evas_load_error_str(err));
744 evas_object_del(img);
745 return LB_STATUS_ERROR_IO;
748 apply_shadow_effect(&img_opt, img);
750 evas_object_image_size_get(img, &w, &h);
751 if (img_opt.aspect) {
752 if (img_opt.fill == FILL_OVER_SIZE) {
756 if (img_opt.width >= 0 && img_opt.height >= 0) {
757 part_w = img_opt.width * elm_config_scale_get();
758 part_h = img_opt.height * elm_config_scale_get();
762 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
764 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
766 if (part_w > w || part_h > h) {
770 fw = (double)part_w / (double)w;
771 fh = (double)part_h / (double)h;
782 if (!part_w || !part_h || !w || !h) {
783 evas_object_del(img);
784 return LB_STATUS_ERROR_INVALID;
787 if (evas_object_image_region_support_get(img)) {
788 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
789 evas_object_image_load_size_set(img, part_w, part_h);
790 evas_object_image_filled_set(img, EINA_TRUE);
791 //evas_object_image_fill_set(img, 0, 0, part_w, part_h);
792 DbgPrint("Size: %dx%d (region: %dx%d - %dx%d)\n", w, h, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
796 Evas_Object *src_img;
800 DbgPrint("Part loading is not supported\n");
801 ee = ecore_evas_buffer_new(part_w, part_h);
803 ErrPrint("Failed to create a EE\n");
804 evas_object_del(img);
805 return LB_STATUS_ERROR_FAULT;
808 ecore_evas_alpha_set(ee, EINA_TRUE);
810 e = ecore_evas_get(ee);
812 ErrPrint("Unable to get Evas\n");
814 evas_object_del(img);
815 return LB_STATUS_ERROR_FAULT;
818 src_img = evas_object_image_filled_add(e);
820 ErrPrint("Unable to add an image\n");
822 evas_object_del(img);
823 return LB_STATUS_ERROR_FAULT;
826 evas_object_image_alpha_set(src_img, EINA_TRUE);
827 evas_object_image_colorspace_set(src_img, EVAS_COLORSPACE_ARGB8888);
828 evas_object_image_smooth_scale_set(src_img, EINA_TRUE);
829 evas_object_image_load_orientation_set(src_img, img_opt.orient);
830 evas_object_image_file_set(src_img, path, NULL);
831 err = evas_object_image_load_error_get(src_img);
832 if (err != EVAS_LOAD_ERROR_NONE) {
833 ErrPrint("Load error: %s\n", evas_load_error_str(err));
834 evas_object_del(src_img);
836 evas_object_del(img);
837 return LB_STATUS_ERROR_IO;
839 evas_object_image_size_get(src_img, &rw, &rh);
840 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
841 evas_object_resize(src_img, w, h);
842 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
843 evas_object_show(src_img);
845 data = ecore_evas_buffer_pixels_get(ee);
847 ErrPrint("Unable to get pixels\n");
848 evas_object_del(src_img);
850 evas_object_del(img);
851 return LB_STATUS_ERROR_IO;
854 e = evas_object_evas_get(img);
855 evas_object_del(img);
856 img = evas_object_image_filled_add(e);
858 evas_object_del(src_img);
860 return LB_STATUS_ERROR_MEMORY;
863 evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
864 evas_object_image_smooth_scale_set(img, EINA_TRUE);
865 evas_object_image_alpha_set(img, EINA_TRUE);
866 evas_object_image_data_set(img, NULL);
867 evas_object_image_size_set(img, part_w, part_h);
868 evas_object_resize(img, part_w, part_h);
869 evas_object_image_data_copy_set(img, (void *)data);
870 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
871 evas_object_image_data_update_add(img, 0, 0, part_w, part_h);
873 evas_object_del(src_img);
876 apply_shadow_effect(&img_opt, img);
878 } else if (img_opt.fill == FILL_IN_SIZE) {
882 if (img_opt.width >= 0 && img_opt.height >= 0) {
883 part_w = img_opt.width * elm_config_scale_get();
884 part_h = img_opt.height * elm_config_scale_get();
888 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
890 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
892 if (part_w > w || part_h > h) {
896 fw = (double)part_w / (double)w;
897 fh = (double)part_h / (double)h;
907 DbgPrint("Size: %dx%d\n", w, h);
908 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
909 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
910 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
912 evas_object_image_fill_set(img, 0, 0, w, h);
913 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
914 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
917 if (img_opt.width >= 0 && img_opt.height >= 0) {
920 DbgPrint("Using given image size: %dx%d\n", w, h);
923 evas_object_image_fill_set(img, 0, 0, w, h);
924 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
925 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
926 evas_object_image_filled_set(img, EINA_TRUE);
932 * object will be shown by below statement automatically
934 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
935 elm_object_part_content_set(edje, part, img);
939 * This object is not registered as an access object.
940 * So the developer should add it to access list manually, using DESC_ACCESS block.
942 return LB_STATUS_SUCCESS;
945 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
947 struct info *handle = data;
959 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
960 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
964 sx = (double)px / (double)w;
965 ex = (double)(px + pw) / (double)w;
970 sy = (double)py / (double)h;
971 ey = (double)(py + ph) / (double)h;
974 script_buffer_signal_emit(handle->buffer_handle, source, emission, sx, sy, ex, ey);
977 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
979 struct info *handle = _info;
980 struct obj_info *obj_info;
981 struct obj_info *parent_obj_info;
984 handle->obj_list = eina_list_remove(handle->obj_list, obj);
986 obj_info = evas_object_data_get(obj, "obj_info");
988 ErrPrint("Object info is not valid\n");
992 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
994 DbgPrint("delete object %s %p\n", obj_info->id, obj);
995 if (obj_info->parent == obj) {
996 DbgPrint("Parent EDJE\n");
997 } else if (obj_info->parent) {
1001 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
1002 if (parent_obj_info) {
1003 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
1004 if (child->obj != obj) {
1010 * If this code is executed,
1011 * The parent is not deleted by desc, this object is deleted by itself.
1012 * It is not possible, but we care it.
1014 DbgPrint("Children is updated: %s (%s)\n", child->part, parent_obj_info->id);
1015 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
1021 if (!parent_obj_info->children && parent_obj_info->delete_me == 1) {
1022 DbgPrint("Children is cleared: %s (by a child)\n", parent_obj_info->id);
1023 evas_object_data_del(obj_info->parent, "obj_info");
1024 free(parent_obj_info->id);
1025 free(parent_obj_info);
1029 DbgPrint("obj_info->parent is NULL (skipped)\n");
1032 if (!obj_info->children) {
1033 DbgPrint("Children is cleared: %s\n", obj_info->id);
1034 evas_object_data_del(obj, "obj_info");
1038 DbgPrint("Children is remained: %s\n", obj_info->id);
1039 obj_info->delete_me = 1;
1043 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
1045 Evas_Object *o, *ho;
1047 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
1052 ho = evas_object_data_get(o, "_elm_access_target");
1057 LB_ACCESS_HIGHLIGHT 0
1058 LB_ACCESS_HIGHLIGHT_NEXT 1
1059 LB_ACCESS_HIGHLIGHT_PREV 2
1060 LB_ACCESS_ACTIVATE 3
1064 PUBLIC int script_feed_event(void *h, int event_type, int x, int y, int down, unsigned int keycode, double timestamp)
1066 struct info *handle = h;
1068 struct obj_info *obj_info;
1069 int ret = LB_STATUS_SUCCESS;
1071 edje = find_edje(handle, NULL); /*!< Get the base layout */
1073 ErrPrint("Base layout is not exist\n");
1074 return LB_STATUS_ERROR_NOT_EXIST;
1077 obj_info = evas_object_data_get(edje, "obj_info");
1079 ErrPrint("Object info is not valid\n");
1080 return LB_STATUS_ERROR_INVALID;
1083 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
1084 Elm_Access_Action_Info info;
1085 Elm_Access_Action_Type action;
1087 memset(&info, 0, sizeof(info));
1089 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
1090 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1093 ret = elm_access_action(edje, action, &info);
1094 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1095 if (ret == EINA_TRUE) {
1096 if (!get_highlighted_object(edje)) {
1097 ErrPrint("Highlighted object is not found\n");
1098 ret = LB_ACCESS_STATUS_ERROR;
1100 DbgPrint("Highlighted object is found\n");
1101 ret = LB_ACCESS_STATUS_DONE;
1104 ErrPrint("Action error\n");
1105 ret = LB_ACCESS_STATUS_ERROR;
1107 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1108 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1109 info.highlight_cycle = EINA_FALSE;
1110 ret = elm_access_action(edje, action, &info);
1111 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1112 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
1113 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1114 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1115 info.highlight_cycle = EINA_FALSE;
1116 ret = elm_access_action(edje, action, &info);
1117 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1118 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
1119 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
1120 action = ELM_ACCESS_ACTION_ACTIVATE;
1121 ret = elm_access_action(edje, action, &info);
1122 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1123 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1124 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
1126 action = ELM_ACCESS_ACTION_UP;
1127 ret = elm_access_action(edje, action, &info);
1128 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1129 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1130 } else if (down == 1) {
1131 action = ELM_ACCESS_ACTION_DOWN;
1132 ret = elm_access_action(edje, action, &info);
1133 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1134 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1136 ErrPrint("Invalid access event\n");
1137 ret = LB_ACCESS_STATUS_ERROR;
1139 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
1140 action = ELM_ACCESS_ACTION_SCROLL;
1145 info.mouse_type = 0;
1146 ret = elm_access_action(edje, action, &info);
1147 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1148 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1151 info.mouse_type = 1;
1152 ret = elm_access_action(edje, action, &info);
1153 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1154 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1157 info.mouse_type = 2;
1158 ret = elm_access_action(edje, action, &info);
1159 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1160 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1163 ret = LB_ACCESS_STATUS_ERROR;
1166 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
1167 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1168 ret = elm_access_action(edje, action, &info);
1169 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1170 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1172 DbgPrint("Invalid event\n");
1173 ret = LB_ACCESS_STATUS_ERROR;
1176 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
1177 double cur_timestamp;
1179 #if defined(_USE_ECORE_TIME_GET)
1180 cur_timestamp = ecore_time_get();
1183 if (gettimeofday(&tv, NULL) < 0) {
1184 ErrPrint("Failed to get time\n");
1185 cur_timestamp = 0.0f;
1187 cur_timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1190 if (cur_timestamp - timestamp > 0.1f && handle->is_mouse_down == 0) {
1191 DbgPrint("Discard lazy event : %lf\n", cur_timestamp - timestamp);
1192 return LB_STATUS_SUCCESS;
1195 switch (event_type) {
1196 case LB_SCRIPT_MOUSE_DOWN:
1197 if (handle->is_mouse_down == 0) {
1198 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1199 evas_event_feed_mouse_down(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1200 handle->is_mouse_down = 1;
1203 case LB_SCRIPT_MOUSE_MOVE:
1204 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1206 case LB_SCRIPT_MOUSE_UP:
1207 if (handle->is_mouse_down == 1) {
1208 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1209 evas_event_feed_mouse_up(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1210 handle->is_mouse_down = 0;
1213 case LB_SCRIPT_MOUSE_IN:
1214 evas_event_feed_mouse_in(handle->e, timestamp * 1000, NULL);
1216 case LB_SCRIPT_MOUSE_OUT:
1217 evas_event_feed_mouse_out(handle->e, timestamp * 1000, NULL);
1220 return LB_STATUS_ERROR_INVALID;
1222 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
1223 const char *keyname = "";
1224 const char *key = "";
1225 const char *string = "";
1226 const char *compose = "";
1228 switch (event_type) {
1229 case LB_SCRIPT_KEY_DOWN:
1230 evas_event_feed_key_down(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1231 ret = LB_KEY_STATUS_DONE;
1234 * If the keyname == RIGHT, Need to check that
1235 * Does it reach to the last focusable object?
1239 * if (REACH to the LAST) {
1240 * ret = LB_KEY_STATUS_LAST;
1242 * ret = LB_KEY_STATUS_DONE;
1245 * if (REACH to the FIRST) {
1246 * ret = LB_KEY_STATUS_FIRST;
1248 * ret = LB_KEY_STATUS_DONE;
1252 case LB_SCRIPT_KEY_UP:
1253 evas_event_feed_key_up(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1254 ret = LB_KEY_STATUS_DONE;
1256 case LB_SCRIPT_KEY_FOCUS_IN:
1257 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_IN, NULL);
1258 ret = LB_KEY_STATUS_DONE;
1260 case LB_SCRIPT_KEY_FOCUS_OUT:
1261 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_OUT, NULL);
1262 ret = LB_KEY_STATUS_DONE;
1265 DbgPrint("Event is not implemented\n");
1266 ret = LB_KEY_STATUS_ERROR;
1275 PUBLIC int script_update_script(void *h, const char *src_id, const char *target_id, const char *part, const char *path, const char *group)
1277 struct info *handle = h;
1280 struct obj_info *obj_info;
1281 struct child *child;
1282 char _target_id[32];
1284 edje = find_edje(handle, src_id);
1286 ErrPrint("Edje is not exists (%s)\n", src_id);
1287 return LB_STATUS_ERROR_NOT_EXIST;
1290 obj_info = evas_object_data_get(edje, "obj_info");
1292 ErrPrint("Object info is not valid\n");
1293 return LB_STATUS_ERROR_INVALID;
1296 obj = elm_object_part_content_unset(edje, part);
1298 DbgPrint("delete object %s %p\n", part, obj);
1301 * This will call the edje_del_cb.
1302 * It will delete all access objects
1304 evas_object_del(obj);
1307 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1308 DbgPrint("SKIP - Path: [%s]\n", path);
1309 return LB_STATUS_SUCCESS;
1313 if (find_edje(handle, part)) {
1317 #if defined(_USE_ECORE_TIME_GET)
1318 timestamp = ecore_time_get();
1321 if (gettimeofday(&tv, NULL) < 0) {
1322 static int local_idx = 0;
1323 timestamp = (double)(local_idx++);
1325 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1329 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1330 } while (find_edje(handle, _target_id));
1332 target_id = _target_id;
1337 DbgPrint("Anonymouse target id: %s\n", target_id);
1340 obj = elm_layout_add(edje);
1342 ErrPrint("Failed to add a new edje object\n");
1343 return LB_STATUS_ERROR_FAULT;
1346 edje_object_scale_set(elm_layout_edje_get(obj), elm_config_scale_get());
1348 if (!elm_layout_file_set(obj, path, group)) {
1350 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1351 if (err != EDJE_LOAD_ERROR_NONE) {
1352 ErrPrint("Could not load %s from %s: %s\n", group, path, edje_load_error_str(err));
1354 evas_object_del(obj);
1355 return LB_STATUS_ERROR_IO;
1358 evas_object_show(obj);
1360 obj_info = calloc(1, sizeof(*obj_info));
1362 ErrPrint("Failed to add a obj_info\n");
1363 evas_object_del(obj);
1364 return LB_STATUS_ERROR_MEMORY;
1367 obj_info->id = strdup(target_id);
1368 if (!obj_info->id) {
1369 ErrPrint("Failed to add a obj_info\n");
1371 evas_object_del(obj);
1372 return LB_STATUS_ERROR_MEMORY;
1375 obj_info->parent = edje;
1377 child = malloc(sizeof(*child));
1379 ErrPrint("Error: %s\n", strerror(errno));
1382 evas_object_del(obj);
1383 return LB_STATUS_ERROR_MEMORY;
1386 child->part = strdup(part);
1388 ErrPrint("Error: %s\n", strerror(errno));
1392 evas_object_del(obj);
1393 return LB_STATUS_ERROR_MEMORY;
1398 evas_object_data_set(obj, "obj_info", obj_info);
1399 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1400 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1401 handle->obj_list = eina_list_append(handle->obj_list, obj);
1403 DbgPrint("%s part swallow edje %p\n", part, obj);
1404 elm_object_part_content_set(edje, part, obj);
1406 obj_info = evas_object_data_get(edje, "obj_info");
1407 obj_info->children = eina_list_append(obj_info->children, child);
1409 return LB_STATUS_SUCCESS;
1412 PUBLIC int script_update_signal(void *h, const char *id, const char *part, const char *signal)
1414 struct info *handle = h;
1417 edje = find_edje(handle, id);
1419 return LB_STATUS_ERROR_NOT_EXIST;
1422 elm_object_signal_emit(edje, signal, part);
1423 return LB_STATUS_SUCCESS;
1426 PUBLIC int script_update_drag(void *h, const char *id, const char *part, double x, double y)
1428 struct info *handle = h;
1431 edje = find_edje(handle, id);
1433 return LB_STATUS_ERROR_NOT_EXIST;
1436 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1437 return LB_STATUS_SUCCESS;
1440 PUBLIC int script_update_size(void *han, const char *id, int w, int h)
1442 struct info *handle = han;
1445 edje = find_edje(handle, id);
1447 return LB_STATUS_ERROR_NOT_EXIST;
1453 * Need to resize the canvas too
1455 ecore_evas_resize(handle->ee, w, h);
1458 DbgPrint("Resize object to %dx%d\n", w, h);
1459 evas_object_resize(edje, w, h);
1460 return LB_STATUS_SUCCESS;
1463 PUBLIC int script_update_category(void *h, const char *id, const char *category)
1465 struct info *handle = h;
1467 if (handle->category) {
1468 free(handle->category);
1469 handle->category = NULL;
1473 return LB_STATUS_SUCCESS;
1476 handle->category = strdup(category);
1477 if (!handle->category) {
1478 ErrPrint("Error: %s\n", strerror(errno));
1479 return LB_STATUS_ERROR_MEMORY;
1482 return LB_STATUS_SUCCESS;
1485 PUBLIC void *script_create(void *buffer_handle, const char *file, const char *group)
1487 struct info *handle;
1489 handle = calloc(1, sizeof(*handle));
1491 ErrPrint("Error: %s\n", strerror(errno));
1495 handle->file = strdup(file);
1496 if (!handle->file) {
1497 ErrPrint("Error: %s\n", strerror(errno));
1502 handle->group = strdup(group);
1503 if (!handle->group) {
1504 ErrPrint("Error: %s\n", strerror(errno));
1510 handle->buffer_handle = buffer_handle;
1512 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1517 PUBLIC int script_destroy(void *_handle)
1519 struct info *handle;
1524 if (!eina_list_data_find(s_info.handle_list, handle)) {
1525 DbgPrint("Not found (already deleted?)\n");
1526 return LB_STATUS_ERROR_NOT_EXIST;
1529 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1531 edje = eina_list_nth(handle->obj_list, 0);
1533 evas_object_del(edje);
1536 DbgPrint("Release handle\n");
1537 free(handle->category);
1539 free(handle->group);
1541 return LB_STATUS_SUCCESS;
1544 static void sw_render_pre_cb(void *data, Evas *e, void *event_info)
1546 struct info *handle = data;
1548 if (handle->render_pre) {
1549 handle->render_pre(handle->buffer_handle, handle->render_data);
1552 script_buffer_lock(handle->buffer_handle);
1554 if (s_info.premultiplied) {
1558 script_buffer_get_size(handle->buffer_handle, &w, &h);
1559 evas_damage_rectangle_add(handle->e, 0, 0, w, h);
1563 static void sw_render_post_cb(void *data, Evas *e, void *event_info)
1565 struct info *handle = data;
1567 if (s_info.premultiplied) {
1571 // Get a pointer of a buffer of the virtual canvas
1572 canvas = (void *)ecore_evas_buffer_pixels_get(handle->ee);
1574 ErrPrint("Failed to get pixel canvas\n");
1578 ecore_evas_geometry_get(handle->ee, &x, &y, &w, &h);
1579 evas_data_argb_unpremul(canvas, w * h);
1582 script_buffer_unlock(handle->buffer_handle);
1584 if (handle->render_post) {
1585 handle->render_post(handle->buffer_handle, handle->render_data);
1589 static void render_pre_cb(void *data, Evas *e, void *event_info)
1591 struct info *handle = data;
1594 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1596 ErrPrint("Acquired buffer is NULL\n");
1599 sw_render_pre_cb(data, handle->e, event_info);
1602 static void render_post_cb(void *data, Evas *e, void *event_info)
1604 struct info *handle = data;
1607 sw_render_post_cb(data, handle->e, event_info);
1608 canvas = script_buffer_pixmap_buffer(handle->buffer_handle);
1610 ErrPrint("Acquired buffer is NULL\n");
1612 script_buffer_pixmap_release_buffer(canvas);
1616 static void *alloc_fb(void *data, int size)
1618 struct info *handle = data;
1620 if (script_buffer_load(handle->buffer_handle) < 0) {
1621 ErrPrint("Failed to load buffer handler\n");
1625 return script_buffer_fb(handle->buffer_handle);
1628 static void free_fb(void *data, void *ptr)
1630 struct info *handle = data;
1632 if (!handle->buffer_handle) {
1633 ErrPrint("Buffer is not valid (maybe already released)\n");
1637 if (script_buffer_fb(handle->buffer_handle) != ptr) {
1638 ErrPrint("Buffer pointer is not matched\n");
1641 (void)script_buffer_unload(handle->buffer_handle);
1644 static int destroy_ecore_evas(struct info *handle)
1647 return LB_STATUS_SUCCESS;
1649 ecore_evas_free(handle->ee);
1652 return LB_STATUS_SUCCESS;
1655 static int create_ecore_evas(struct info *handle, int *w, int *h)
1657 script_buffer_get_size(handle->buffer_handle, w, h);
1658 if (*w == 0 && *h == 0) {
1659 ErrPrint("ZERO size FB accessed\n");
1660 return LB_STATUS_ERROR_INVALID;
1667 ecore_evas_geometry_get(handle->ee, NULL, NULL, &ow, &oh);
1668 if (*w != ow || *h != oh) {
1669 ErrPrint("EE exists, But different size - buffer_handle(%dx%d) -> ee(%dx%d)\n", ow, oh, *w, *h);
1670 ecore_evas_resize(handle->ee, *w, *h);
1673 return LB_STATUS_SUCCESS;
1676 handle->ee = ecore_evas_buffer_allocfunc_new(*w, *h, alloc_fb, free_fb, handle);
1678 ErrPrint("Failed to create a buffer\n");
1679 return LB_STATUS_ERROR_FAULT;
1682 handle->e = ecore_evas_get(handle->ee);
1684 ErrPrint("Failed to get an Evas\n");
1685 ecore_evas_free(handle->ee);
1687 return LB_STATUS_ERROR_FAULT;
1690 if (script_buffer_type(handle->buffer_handle) == BUFFER_TYPE_PIXMAP) {
1693 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb, handle);
1694 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, render_post_cb, handle);
1698 * ecore_evas_alpha_set tries to access the canvas buffer.
1699 * Without any render_pre/render_post callback.
1701 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1703 ErrPrint("Acquired buffer is NULL\n");
1705 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1706 script_buffer_pixmap_release_buffer(canvas);
1709 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, sw_render_pre_cb, handle);
1710 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, sw_render_post_cb, handle);
1711 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1714 ecore_evas_manual_render_set(handle->ee, EINA_FALSE);
1715 ecore_evas_resize(handle->ee, *w, *h);
1716 ecore_evas_show(handle->ee);
1717 ecore_evas_activate(handle->ee);
1719 return LB_STATUS_SUCCESS;
1722 PUBLIC int script_load(void *_handle, int (*render_pre)(void *buffer_handle, void *data), int (*render_post)(void *render_handle, void *data), void *data)
1724 struct info *handle;
1726 struct obj_info *obj_info;
1733 * Create "Ecore_Evas *"
1738 handle->render_pre = render_pre;
1739 handle->render_post = render_post;
1740 handle->render_data = data;
1742 ret = create_ecore_evas(handle, &w, &h);
1747 obj_info = calloc(1, sizeof(*obj_info));
1749 ErrPrint("Heap: %s\n", strerror(errno));
1750 destroy_ecore_evas(handle);
1751 return LB_STATUS_ERROR_MEMORY;
1754 obj_info->parent = evas_object_rectangle_add(handle->e);
1755 if (!obj_info->parent) {
1756 ErrPrint("Unable to create a parent box\n");
1758 destroy_ecore_evas(handle);
1759 return LB_STATUS_ERROR_FAULT;
1762 edje = elm_layout_add(obj_info->parent);
1764 ErrPrint("Failed to create an edje object\n");
1765 evas_object_del(obj_info->parent);
1767 destroy_ecore_evas(handle);
1768 return LB_STATUS_ERROR_FAULT;
1771 edje_object_scale_set(elm_layout_edje_get(edje), elm_config_scale_get());
1773 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1776 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1777 if (err != EDJE_LOAD_ERROR_NONE) {
1778 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, edje_load_error_str(err));
1780 evas_object_del(edje);
1781 evas_object_del(obj_info->parent);
1783 destroy_ecore_evas(handle);
1784 return LB_STATUS_ERROR_IO;
1787 handle->parent = edje;
1789 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1790 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1791 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1792 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1793 evas_object_resize(edje, w, h);
1794 evas_object_show(edje);
1795 evas_object_data_set(edje, "obj_info", obj_info);
1797 handle->obj_list = eina_list_append(handle->obj_list, edje);
1798 return LB_STATUS_SUCCESS;
1801 PUBLIC int script_unload(void *_handle)
1803 struct info *handle;
1807 * Destroy "Ecore_Evas *"
1812 if (handle->parent) {
1813 DbgPrint("Delete parent box\n");
1814 evas_object_del(handle->parent);
1817 (void)destroy_ecore_evas(handle);
1818 return LB_STATUS_SUCCESS;
1821 static void access_cb(keynode_t *node, void *user_data)
1826 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1827 ErrPrint("Idle lock state is not valid\n");
1828 state = 0; /* DISABLED */
1831 state = vconf_keynode_get_bool(node);
1834 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1835 elm_config_access_set(state);
1836 s_info.access_on = state;
1839 static void update_font_cb(void *data)
1841 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1842 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1845 static void font_changed_cb(keynode_t *node, void *user_data)
1851 if (s_info.font_name) {
1852 font_name = vconf_get_str("db/setting/accessibility/font_name");
1854 ErrPrint("Invalid font name (NULL)\n");
1858 if (!strcmp(s_info.font_name, font_name)) {
1859 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1864 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1865 free(s_info.font_name);
1870 * Get the first font name using system_settings API.
1873 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
1874 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
1875 ErrPrint("System setting get: %d, font_name[%p]\n", ret, font_name);
1880 s_info.font_name = font_name;
1881 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1885 * Try to update all liveboxes
1887 update_font_cb(NULL);
1890 static inline int convert_font_size(int size)
1893 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1896 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1899 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1902 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1905 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1913 DbgPrint("Return size: %d\n", size);
1917 static void font_size_cb(system_settings_key_e key, void *user_data)
1921 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE) {
1925 size = convert_font_size(size);
1927 if (size == s_info.font_size) {
1928 DbgPrint("Font size is not changed\n");
1932 s_info.font_size = size;
1933 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
1936 PUBLIC int script_init(double scale, int premultiplied)
1944 s_info.premultiplied = premultiplied;
1946 /* ecore is already initialized */
1948 elm_config_scale_set(scale);
1949 DbgPrint("Scale is updated: %lf\n", scale);
1951 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1953 DbgPrint("TTS changed: %d\n", ret);
1956 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
1957 DbgPrint("System font is changed: %d\n", ret);
1959 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1960 DbgPrint("System font size is changed: %d\n", ret);
1962 access_cb(NULL, NULL);
1963 font_changed_cb(NULL, NULL);
1964 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
1965 return LB_STATUS_SUCCESS;
1968 PUBLIC int script_fini(void)
1973 struct info *handle;
1975 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
1976 script_destroy(handle);
1979 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1981 DbgPrint("Unset font size change event callback: %d\n", ret);
1984 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
1986 DbgPrint("Unset font name change event callback: %d\n", ret);
1989 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1991 DbgPrint("Unset tts: %d\n", ret);
1996 free(s_info.font_name);
1997 s_info.font_name = NULL;
1998 return LB_STATUS_SUCCESS;