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 #if defined(ENABLE_ACCESSIBILITY)
185 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
194 e = evas_object_evas_get(part_obj);
195 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
199 #if defined(_USE_ECORE_TIME_GET)
200 timestamp = ecore_time_get();
203 if (gettimeofday(&tv, NULL) < 0) {
204 ErrPrint("Failed to get time\n");
207 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
211 DbgPrint("Cursor is on %dx%d\n", x, y);
212 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
213 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
214 evas_event_feed_mouse_move(e, x, y, (timestamp + 0.02f) * 1000, NULL);
215 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.03f) * 1000, NULL);
218 static void update_focus_chain(struct info *handle, Evas_Object *ao)
220 const Eina_List *list;
222 list = elm_object_focus_custom_chain_get(handle->parent);
223 if (!eina_list_data_find(list, ao)) {
224 DbgPrint("Append again to the focus chain\n");
225 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
230 PUBLIC int script_update_text(void *h, const char *id, const char *part, const char *text)
232 struct obj_info *obj_info;
233 struct info *handle = h;
236 edje = find_edje(handle, id);
238 ErrPrint("Failed to find EDJE\n");
239 return LB_STATUS_ERROR_NOT_EXIST;
242 obj_info = evas_object_data_get(edje, "obj_info");
244 ErrPrint("Object info is not available\n");
245 return LB_STATUS_ERROR_FAULT;
248 elm_object_part_text_set(edje, part, text ? text : "");
250 #if defined(ENABLE_ACCESSIBILITY)
251 Evas_Object *edje_part;
253 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
258 ao = evas_object_data_get(edje_part, "ao");
260 ao = elm_access_object_register(edje_part, handle->parent);
262 ErrPrint("Unable to register an access object(%s)\n", part);
266 evas_object_data_set(edje_part, "ao", ao);
267 elm_access_activate_cb_set(ao, activate_cb, NULL);
268 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
270 DbgPrint("[%s] Register access info: (%s) to, %p\n", part, text, handle->parent);
273 if (!text || !strlen(text)) {
276 * Delete callback will be called
278 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
279 elm_access_object_unregister(ao);
284 utf8 = elm_entry_markup_to_utf8(text);
285 if ((!utf8 || !strlen(utf8))) {
289 * Delete callback will be called
291 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
292 elm_access_object_unregister(ao);
297 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
300 update_focus_chain(handle, ao);
302 ErrPrint("Unable to get text part[%s]\n", part);
307 return LB_STATUS_SUCCESS;
310 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
312 while (len > 0 && *value == ' ') {
321 img_opt->aspect = !strncasecmp(value, "true", 4);
322 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
325 static void parse_orient(struct image_option *img_opt, const char *value, int len)
327 while (len > 0 && *value == ' ') {
336 img_opt->orient = !strncasecmp(value, "true", 4);
337 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
340 static void parse_size(struct image_option *img_opt, const char *value, int len)
346 while (len > 0 && *value == ' ') {
351 buf = strndup(value, len);
353 ErrPrint("Heap: %s\n", strerror(errno));
357 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
358 img_opt->width = width;
359 img_opt->height = height;
360 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
362 DbgPrint("Invalid size tag[%s]\n", buf);
368 static void parse_shadow(struct image_option *img_opt, const char *value, int len)
375 if (sscanf(value, "%d,%d,%d,%x", &angle, &offset, &softness, &color) != 4) {
376 ErrPrint("Invalid shadow [%s]\n", value);
378 img_opt->shadow.enabled = 1;
379 img_opt->shadow.angle = angle;
380 img_opt->shadow.offset = offset;
381 img_opt->shadow.softness = softness;
382 img_opt->shadow.color = color;
386 static void parse_fill(struct image_option *img_opt, const char *value, int len)
388 while (len > 0 && *value == ' ') {
393 if (!strncasecmp(value, "in-size", len)) {
394 img_opt->fill = FILL_IN_SIZE;
395 } else if (!strncasecmp(value, "over-size", len)) {
396 img_opt->fill = FILL_OVER_SIZE;
398 img_opt->fill = FILL_DISABLE;
401 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
404 static inline void parse_image_option(const char *option, struct image_option *img_opt)
411 void (*handler)(struct image_option *img_opt, const char *value, int len);
414 .cmd = "aspect", /* Keep the aspect ratio */
415 .handler = parse_aspect,
418 .cmd = "orient", /* Keep the orientation value: for the rotated images */
419 .handler = parse_orient,
422 .cmd = "fill", /* Fill the image to its container */
423 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
427 .handler = parse_size,
431 .handler = parse_shadow,
445 if (!option || !*option) {
452 * GCC 4.7 warnings uninitialized idx and tag value.
453 * But it will be initialized by the state machine. :(
454 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
461 for (ptr = option; state != STATE_END; ptr++) {
476 cmd = cmd_list[tag].cmd;
482 } else if (*ptr == '\0') {
487 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
492 state = STATE_IGNORE;
495 } else if (*ptr == '\0') {
497 } else if (cmd[idx] == *ptr) {
503 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
507 cmd = cmd_list[tag].cmd;
513 if (*ptr == ';' || *ptr == '\0') {
514 cmd_list[tag].handler(img_opt, value + 1, idx);
515 state = *ptr ? STATE_START : STATE_END;
523 } else if (*ptr == '\0') {
533 PUBLIC int script_update_access(void *_h, const char *id, const char *part, const char *text, const char *option)
535 struct info *handle = _h;
537 struct obj_info *obj_info;
539 edje = find_edje(handle, id);
541 ErrPrint("No such object: %s\n", id);
542 return LB_STATUS_ERROR_NOT_EXIST;
545 obj_info = evas_object_data_get(edje, "obj_info");
547 ErrPrint("Object info is not available\n");
548 return LB_STATUS_ERROR_FAULT;
551 #if defined(ENABLE_ACCESSIBILITY)
552 Evas_Object *edje_part;
554 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
558 ao = evas_object_data_get(edje_part, "ao");
560 if (text && strlen(text)) {
561 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
562 DbgPrint("Access info is updated: %s [%s], %p\n", part, text, ao);
563 update_focus_chain(handle, ao);
567 * Delete clalback will be called
569 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
570 elm_access_object_unregister(ao);
572 } else if (text && strlen(text)) {
573 ao = elm_access_object_register(edje_part, handle->parent);
575 ErrPrint("Unable to register an access object(%s)\n", part);
577 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
579 evas_object_data_set(edje_part, "ao", ao);
580 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
581 elm_access_activate_cb_set(ao, activate_cb, NULL);
582 DbgPrint("[%s] Register access info: (%s) to, %p (%p)\n", part, text, handle->parent, ao);
586 ErrPrint("[%s] is not exists\n", part);
590 return LB_STATUS_SUCCESS;
593 PUBLIC int script_operate_access(void *_h, const char *id, const char *part, const char *operation, const char *option)
595 #if defined(ENABLE_ACCESSIBILITY)
596 struct info *handle = _h;
598 struct obj_info *obj_info;
599 Elm_Access_Action_Info action_info;
602 if (!operation || !strlen(operation)) {
603 return LB_STATUS_ERROR_INVALID;
606 edje = find_edje(handle, id);
608 ErrPrint("No such object: %s\n", id);
609 return LB_STATUS_ERROR_NOT_EXIST;
612 obj_info = evas_object_data_get(edje, "obj_info");
614 ErrPrint("Object info is not available\n");
615 return LB_STATUS_ERROR_FAULT;
618 memset(&action_info, 0, sizeof(action_info));
620 /* OPERATION is defined in liblivebox package */
621 if (!strcasecmp(operation, "set,hl")) {
623 Evas_Object *edje_part;
629 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
631 ErrPrint("Invalid part: %s\n", part);
635 evas_object_geometry_get(edje_part, &x, &y, &w, &h);
637 action_info.x = x + w / 2;
638 action_info.y = x + h / 2;
639 } else if (option && sscanf(option, "%dx%d", &action_info.x, &action_info.y) == 2) {
641 ErrPrint("Insufficient info for HL\n");
645 DbgPrint("TXxTY: %dx%d\n", action_info.x, action_info.y);
646 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT, &action_info);
647 if (ret == EINA_FALSE) {
648 ErrPrint("Action error\n");
650 } else if (!strcasecmp(operation, "unset,hl")) {
651 ret = elm_access_action(edje, ELM_ACCESS_ACTION_UNHIGHLIGHT, &action_info);
652 if (ret == EINA_FALSE) {
653 ErrPrint("Action error\n");
655 } else if (!strcasecmp(operation, "next,hl")) {
656 action_info.highlight_cycle = (!!option) && (!!strcasecmp(option, "no,cycle"));
658 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_NEXT, &action_info);
659 if (ret == EINA_FALSE) {
660 ErrPrint("Action error\n");
662 } else if (!strcasecmp(operation, "prev,hl")) {
663 action_info.highlight_cycle = EINA_TRUE;
664 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_PREV, &action_info);
665 if (ret == EINA_FALSE) {
666 ErrPrint("Action error\n");
668 } else if (!strcasecmp(operation, "reset,focus")) {
669 DbgPrint("Reset Focus\n");
670 elm_object_focus_custom_chain_set(edje, NULL);
674 return LB_STATUS_SUCCESS;
676 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
680 static inline void apply_shadow_effect(struct image_option *img_opt, Evas_Object *img)
682 #if defined(WEARABLE)
683 ea_effect_h *ea_effect;
685 if (!img_opt->shadow.enabled) {
689 ea_effect = ea_image_effect_create();
694 // -90, 2, 4, 0x99000000
695 ea_image_effect_add_outer_shadow(ea_effect, img_opt->shadow.angle, img_opt->shadow.offset, img_opt->shadow.softness, img_opt->shadow.color);
696 ea_object_image_effect_set(img, ea_effect);
698 ea_image_effect_destroy(ea_effect);
700 // Only supported from the wearable profile
705 PUBLIC int script_update_image(void *_h, const char *id, const char *part, const char *path, const char *option)
707 struct info *handle = _h;
712 struct obj_info *obj_info;
713 struct image_option img_opt = {
716 .fill = FILL_DISABLE,
724 edje = find_edje(handle, id);
726 ErrPrint("No such object: %s\n", id);
727 return LB_STATUS_ERROR_NOT_EXIST;
730 obj_info = evas_object_data_get(edje, "obj_info");
732 ErrPrint("Object info is not available\n");
733 return LB_STATUS_ERROR_FAULT;
736 img = elm_object_part_content_unset(edje, part);
738 DbgPrint("delete object %s %p\n", part, img);
739 evas_object_del(img);
742 if (!path || !strlen(path) || access(path, R_OK) != 0) {
743 DbgPrint("SKIP - Path: [%s]\n", path);
744 return LB_STATUS_SUCCESS;
747 img = evas_object_image_add(handle->e);
749 ErrPrint("Failed to add an image object\n");
750 return LB_STATUS_ERROR_FAULT;
753 evas_object_image_preload(img, EINA_FALSE);
754 parse_image_option(option, &img_opt);
755 evas_object_image_load_orientation_set(img, img_opt.orient);
757 evas_object_image_file_set(img, path, NULL);
758 err = evas_object_image_load_error_get(img);
759 if (err != EVAS_LOAD_ERROR_NONE) {
760 ErrPrint("Load error: %s\n", evas_load_error_str(err));
761 evas_object_del(img);
762 return LB_STATUS_ERROR_IO;
765 apply_shadow_effect(&img_opt, img);
767 evas_object_image_size_get(img, &w, &h);
768 if (img_opt.aspect) {
769 if (img_opt.fill == FILL_OVER_SIZE) {
773 if (img_opt.width >= 0 && img_opt.height >= 0) {
774 part_w = img_opt.width * elm_config_scale_get();
775 part_h = img_opt.height * elm_config_scale_get();
779 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
781 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
783 if (part_w > w || part_h > h) {
787 fw = (double)part_w / (double)w;
788 fh = (double)part_h / (double)h;
799 if (!part_w || !part_h || !w || !h) {
800 evas_object_del(img);
801 return LB_STATUS_ERROR_INVALID;
804 if (evas_object_image_region_support_get(img)) {
805 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
806 evas_object_image_load_size_set(img, part_w, part_h);
807 evas_object_image_filled_set(img, EINA_TRUE);
808 //evas_object_image_fill_set(img, 0, 0, part_w, part_h);
809 DbgPrint("Size: %dx%d (region: %dx%d - %dx%d)\n", w, h, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
813 Evas_Object *src_img;
817 DbgPrint("Part loading is not supported\n");
818 ee = ecore_evas_buffer_new(part_w, part_h);
820 ErrPrint("Failed to create a EE\n");
821 evas_object_del(img);
822 return LB_STATUS_ERROR_FAULT;
825 ecore_evas_alpha_set(ee, EINA_TRUE);
827 e = ecore_evas_get(ee);
829 ErrPrint("Unable to get Evas\n");
831 evas_object_del(img);
832 return LB_STATUS_ERROR_FAULT;
835 src_img = evas_object_image_filled_add(e);
837 ErrPrint("Unable to add an image\n");
839 evas_object_del(img);
840 return LB_STATUS_ERROR_FAULT;
843 evas_object_image_alpha_set(src_img, EINA_TRUE);
844 evas_object_image_colorspace_set(src_img, EVAS_COLORSPACE_ARGB8888);
845 evas_object_image_smooth_scale_set(src_img, EINA_TRUE);
846 evas_object_image_load_orientation_set(src_img, img_opt.orient);
847 evas_object_image_file_set(src_img, path, NULL);
848 err = evas_object_image_load_error_get(src_img);
849 if (err != EVAS_LOAD_ERROR_NONE) {
850 ErrPrint("Load error: %s\n", evas_load_error_str(err));
851 evas_object_del(src_img);
853 evas_object_del(img);
854 return LB_STATUS_ERROR_IO;
856 evas_object_image_size_get(src_img, &rw, &rh);
857 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
858 evas_object_resize(src_img, w, h);
859 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
860 evas_object_show(src_img);
862 data = ecore_evas_buffer_pixels_get(ee);
864 ErrPrint("Unable to get pixels\n");
865 evas_object_del(src_img);
867 evas_object_del(img);
868 return LB_STATUS_ERROR_IO;
871 e = evas_object_evas_get(img);
872 evas_object_del(img);
873 img = evas_object_image_filled_add(e);
875 evas_object_del(src_img);
877 return LB_STATUS_ERROR_MEMORY;
880 evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
881 evas_object_image_smooth_scale_set(img, EINA_TRUE);
882 evas_object_image_alpha_set(img, EINA_TRUE);
883 evas_object_image_data_set(img, NULL);
884 evas_object_image_size_set(img, part_w, part_h);
885 evas_object_resize(img, part_w, part_h);
886 evas_object_image_data_copy_set(img, (void *)data);
887 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
888 evas_object_image_data_update_add(img, 0, 0, part_w, part_h);
890 evas_object_del(src_img);
893 apply_shadow_effect(&img_opt, img);
895 } else if (img_opt.fill == FILL_IN_SIZE) {
899 if (img_opt.width >= 0 && img_opt.height >= 0) {
900 part_w = img_opt.width * elm_config_scale_get();
901 part_h = img_opt.height * elm_config_scale_get();
905 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
907 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
909 if (part_w > w || part_h > h) {
913 fw = (double)part_w / (double)w;
914 fh = (double)part_h / (double)h;
924 DbgPrint("Size: %dx%d\n", w, h);
925 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
926 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
927 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
929 evas_object_image_fill_set(img, 0, 0, w, h);
930 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
931 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
934 if (img_opt.width >= 0 && img_opt.height >= 0) {
937 DbgPrint("Using given image size: %dx%d\n", w, h);
940 evas_object_image_fill_set(img, 0, 0, w, h);
941 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
942 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
943 evas_object_image_filled_set(img, EINA_TRUE);
949 * object will be shown by below statement automatically
951 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
952 elm_object_part_content_set(edje, part, img);
956 * This object is not registered as an access object.
957 * So the developer should add it to access list manually, using DESC_ACCESS block.
959 return LB_STATUS_SUCCESS;
962 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
964 struct info *handle = data;
976 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
977 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
981 sx = (double)px / (double)w;
982 ex = (double)(px + pw) / (double)w;
987 sy = (double)py / (double)h;
988 ey = (double)(py + ph) / (double)h;
991 DbgPrint("[%s] [%s]\n", emission, source);
993 script_buffer_signal_emit(handle->buffer_handle, source, emission, sx, sy, ex, ey);
996 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
998 struct info *handle = _info;
999 struct obj_info *obj_info;
1000 struct obj_info *parent_obj_info;
1001 struct child *child;
1003 handle->obj_list = eina_list_remove(handle->obj_list, obj);
1005 obj_info = evas_object_data_get(obj, "obj_info");
1007 ErrPrint("Object info is not valid\n");
1011 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
1013 DbgPrint("delete object %s %p\n", obj_info->id, obj);
1014 if (obj_info->parent == obj) {
1015 DbgPrint("Parent EDJE\n");
1016 } else if (obj_info->parent) {
1020 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
1021 if (parent_obj_info) {
1022 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
1023 if (child->obj != obj) {
1029 * If this code is executed,
1030 * The parent is not deleted by desc, this object is deleted by itself.
1031 * It is not possible, but we care it.
1033 DbgPrint("Children is updated: %s (%s)\n", child->part, parent_obj_info->id);
1034 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
1040 if (!parent_obj_info->children && parent_obj_info->delete_me == 1) {
1041 DbgPrint("Children is cleared: %s (by a child)\n", parent_obj_info->id);
1042 evas_object_data_del(obj_info->parent, "obj_info");
1043 free(parent_obj_info->id);
1044 free(parent_obj_info);
1048 DbgPrint("obj_info->parent is NULL (skipped)\n");
1051 if (!obj_info->children) {
1052 DbgPrint("Children is cleared: %s\n", obj_info->id);
1053 evas_object_data_del(obj, "obj_info");
1057 DbgPrint("Children is remained: %s\n", obj_info->id);
1058 obj_info->delete_me = 1;
1062 #if defined(ENABLE_ACCESSIBILITY)
1063 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
1065 Evas_Object *o, *ho;
1067 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
1072 ho = evas_object_data_get(o, "_elm_access_target");
1078 LB_ACCESS_HIGHLIGHT 0
1079 LB_ACCESS_HIGHLIGHT_NEXT 1
1080 LB_ACCESS_HIGHLIGHT_PREV 2
1081 LB_ACCESS_ACTIVATE 3
1085 PUBLIC int script_feed_event(void *h, int event_type, int x, int y, int down, unsigned int keycode, double timestamp)
1087 struct info *handle = h;
1089 struct obj_info *obj_info;
1090 int ret = LB_STATUS_SUCCESS;
1092 edje = find_edje(handle, NULL); /*!< Get the base layout */
1094 ErrPrint("Base layout is not exist\n");
1095 return LB_STATUS_ERROR_NOT_EXIST;
1098 obj_info = evas_object_data_get(edje, "obj_info");
1100 ErrPrint("Object info is not valid\n");
1101 return LB_STATUS_ERROR_INVALID;
1104 #if defined(ENABLE_ACCESSIBILITY)
1105 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
1106 Elm_Access_Action_Info info;
1107 Elm_Access_Action_Type action;
1109 memset(&info, 0, sizeof(info));
1111 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
1112 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1115 ret = elm_access_action(edje, action, &info);
1116 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1117 if (ret == EINA_TRUE) {
1118 if (!get_highlighted_object(edje)) {
1119 ErrPrint("Highlighted object is not found\n");
1120 ret = LB_ACCESS_STATUS_ERROR;
1122 DbgPrint("Highlighted object is found\n");
1123 ret = LB_ACCESS_STATUS_DONE;
1126 ErrPrint("Action error\n");
1127 ret = LB_ACCESS_STATUS_ERROR;
1129 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1130 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1131 info.highlight_cycle = EINA_FALSE;
1132 ret = elm_access_action(edje, action, &info);
1133 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1134 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
1135 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1136 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1137 info.highlight_cycle = EINA_FALSE;
1138 ret = elm_access_action(edje, action, &info);
1139 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1140 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
1141 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
1142 action = ELM_ACCESS_ACTION_ACTIVATE;
1143 ret = elm_access_action(edje, action, &info);
1144 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1145 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1146 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
1148 action = ELM_ACCESS_ACTION_UP;
1149 ret = elm_access_action(edje, action, &info);
1150 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1151 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1152 } else if (down == 1) {
1153 action = ELM_ACCESS_ACTION_DOWN;
1154 ret = elm_access_action(edje, action, &info);
1155 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1156 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1158 ErrPrint("Invalid access event\n");
1159 ret = LB_ACCESS_STATUS_ERROR;
1161 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
1162 action = ELM_ACCESS_ACTION_SCROLL;
1167 info.mouse_type = 0;
1168 ret = elm_access_action(edje, action, &info);
1169 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1170 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1173 info.mouse_type = 1;
1174 ret = elm_access_action(edje, action, &info);
1175 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1176 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1179 info.mouse_type = 2;
1180 ret = elm_access_action(edje, action, &info);
1181 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1182 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1185 ret = LB_ACCESS_STATUS_ERROR;
1188 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
1189 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1190 ret = elm_access_action(edje, action, &info);
1191 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1192 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1194 DbgPrint("Invalid event\n");
1195 ret = LB_ACCESS_STATUS_ERROR;
1200 if (event_type & LB_SCRIPT_MOUSE_EVENT) {
1201 double cur_timestamp;
1204 #if defined(_USE_ECORE_TIME_GET)
1205 cur_timestamp = ecore_time_get();
1208 if (gettimeofday(&tv, NULL) < 0) {
1209 ErrPrint("Failed to get time\n");
1210 cur_timestamp = 0.0f;
1212 cur_timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1215 if (cur_timestamp - timestamp > 0.1f && handle->is_mouse_down == 0) {
1216 DbgPrint("Discard lazy event : %lf\n", cur_timestamp - timestamp);
1217 return LB_STATUS_SUCCESS;
1220 switch (event_type) {
1221 case LB_SCRIPT_MOUSE_DOWN:
1222 if (handle->is_mouse_down == 0) {
1223 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1224 evas_event_feed_mouse_down(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1225 handle->is_mouse_down = 1;
1228 case LB_SCRIPT_MOUSE_MOVE:
1229 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1231 case LB_SCRIPT_MOUSE_UP:
1232 if (handle->is_mouse_down == 1) {
1233 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1234 evas_event_feed_mouse_up(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1235 handle->is_mouse_down = 0;
1238 flags = evas_event_default_flags_get(handle->e);
1239 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
1240 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
1241 evas_event_default_flags_set(handle->e, flags);
1243 case LB_SCRIPT_MOUSE_IN:
1244 evas_event_feed_mouse_in(handle->e, timestamp * 1000, NULL);
1246 case LB_SCRIPT_MOUSE_OUT:
1247 evas_event_feed_mouse_out(handle->e, timestamp * 1000, NULL);
1249 case LB_SCRIPT_MOUSE_ON_SCROLL:
1250 flags = evas_event_default_flags_get(handle->e);
1251 flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1252 evas_event_default_flags_set(handle->e, flags);
1254 case LB_SCRIPT_MOUSE_ON_HOLD: // To cancel the clicked, enable this
1255 flags = evas_event_default_flags_get(handle->e);
1256 flags |= EVAS_EVENT_FLAG_ON_HOLD;
1257 evas_event_default_flags_set(handle->e, flags);
1259 case LB_SCRIPT_MOUSE_OFF_SCROLL:
1260 flags = evas_event_default_flags_get(handle->e);
1261 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
1262 evas_event_default_flags_set(handle->e, flags);
1264 case LB_SCRIPT_MOUSE_OFF_HOLD:
1265 flags = evas_event_default_flags_get(handle->e);
1266 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
1267 evas_event_default_flags_set(handle->e, flags);
1270 return LB_STATUS_ERROR_INVALID;
1272 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
1273 const char *keyname = "";
1274 const char *key = "";
1275 const char *string = "";
1276 const char *compose = "";
1278 switch (event_type) {
1279 case LB_SCRIPT_KEY_DOWN:
1280 evas_event_feed_key_down(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1281 ret = LB_KEY_STATUS_DONE;
1284 * If the keyname == RIGHT, Need to check that
1285 * Does it reach to the last focusable object?
1289 * if (REACH to the LAST) {
1290 * ret = LB_KEY_STATUS_LAST;
1292 * ret = LB_KEY_STATUS_DONE;
1295 * if (REACH to the FIRST) {
1296 * ret = LB_KEY_STATUS_FIRST;
1298 * ret = LB_KEY_STATUS_DONE;
1302 case LB_SCRIPT_KEY_UP:
1303 evas_event_feed_key_up(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1304 ret = LB_KEY_STATUS_DONE;
1306 case LB_SCRIPT_KEY_FOCUS_IN:
1307 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_IN, NULL);
1308 ret = LB_KEY_STATUS_DONE;
1310 case LB_SCRIPT_KEY_FOCUS_OUT:
1311 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_OUT, NULL);
1312 ret = LB_KEY_STATUS_DONE;
1315 DbgPrint("Event is not implemented\n");
1316 ret = LB_KEY_STATUS_ERROR;
1324 PUBLIC int script_update_script(void *h, const char *src_id, const char *target_id, const char *part, const char *path, const char *group)
1326 struct info *handle = h;
1329 struct obj_info *obj_info;
1330 struct child *child;
1331 char _target_id[32];
1333 edje = find_edje(handle, src_id);
1335 ErrPrint("Edje is not exists (%s)\n", src_id);
1336 return LB_STATUS_ERROR_NOT_EXIST;
1339 obj_info = evas_object_data_get(edje, "obj_info");
1341 ErrPrint("Object info is not valid\n");
1342 return LB_STATUS_ERROR_INVALID;
1345 obj = elm_object_part_content_unset(edje, part);
1347 DbgPrint("delete object %s %p\n", part, obj);
1350 * This will call the edje_del_cb.
1351 * It will delete all access objects
1353 evas_object_del(obj);
1356 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1357 DbgPrint("SKIP - Path: [%s]\n", path);
1358 return LB_STATUS_SUCCESS;
1362 if (find_edje(handle, part)) {
1366 #if defined(_USE_ECORE_TIME_GET)
1367 timestamp = ecore_time_get();
1370 if (gettimeofday(&tv, NULL) < 0) {
1371 static int local_idx = 0;
1372 timestamp = (double)(local_idx++);
1374 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1378 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1379 } while (find_edje(handle, _target_id));
1381 target_id = _target_id;
1386 DbgPrint("Anonymouse target id: %s\n", target_id);
1389 obj = elm_layout_add(edje);
1391 ErrPrint("Failed to add a new edje object\n");
1392 return LB_STATUS_ERROR_FAULT;
1395 edje_object_scale_set(elm_layout_edje_get(obj), elm_config_scale_get());
1397 if (!elm_layout_file_set(obj, path, group)) {
1399 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1400 if (err != EDJE_LOAD_ERROR_NONE) {
1401 ErrPrint("Could not load %s from %s: %s\n", group, path, edje_load_error_str(err));
1403 evas_object_del(obj);
1404 return LB_STATUS_ERROR_IO;
1407 evas_object_show(obj);
1409 obj_info = calloc(1, sizeof(*obj_info));
1411 ErrPrint("Failed to add a obj_info\n");
1412 evas_object_del(obj);
1413 return LB_STATUS_ERROR_MEMORY;
1416 obj_info->id = strdup(target_id);
1417 if (!obj_info->id) {
1418 ErrPrint("Failed to add a obj_info\n");
1420 evas_object_del(obj);
1421 return LB_STATUS_ERROR_MEMORY;
1424 obj_info->parent = edje;
1426 child = malloc(sizeof(*child));
1428 ErrPrint("Error: %s\n", strerror(errno));
1431 evas_object_del(obj);
1432 return LB_STATUS_ERROR_MEMORY;
1435 child->part = strdup(part);
1437 ErrPrint("Error: %s\n", strerror(errno));
1441 evas_object_del(obj);
1442 return LB_STATUS_ERROR_MEMORY;
1447 evas_object_data_set(obj, "obj_info", obj_info);
1448 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1449 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1450 handle->obj_list = eina_list_append(handle->obj_list, obj);
1452 DbgPrint("%s part swallow edje %p\n", part, obj);
1453 elm_object_part_content_set(edje, part, obj);
1455 obj_info = evas_object_data_get(edje, "obj_info");
1456 obj_info->children = eina_list_append(obj_info->children, child);
1458 return LB_STATUS_SUCCESS;
1461 PUBLIC int script_update_signal(void *h, const char *id, const char *part, const char *signal)
1463 struct info *handle = h;
1466 edje = find_edje(handle, id);
1468 return LB_STATUS_ERROR_NOT_EXIST;
1471 elm_object_signal_emit(edje, signal, part);
1472 return LB_STATUS_SUCCESS;
1475 PUBLIC int script_update_drag(void *h, const char *id, const char *part, double x, double y)
1477 struct info *handle = h;
1480 edje = find_edje(handle, id);
1482 return LB_STATUS_ERROR_NOT_EXIST;
1485 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1486 return LB_STATUS_SUCCESS;
1489 PUBLIC int script_update_size(void *han, const char *id, int w, int h)
1491 struct info *handle = han;
1494 edje = find_edje(handle, id);
1496 return LB_STATUS_ERROR_NOT_EXIST;
1502 * Need to resize the canvas too
1504 ecore_evas_resize(handle->ee, w, h);
1507 DbgPrint("Resize object to %dx%d\n", w, h);
1508 evas_object_resize(edje, w, h);
1509 return LB_STATUS_SUCCESS;
1512 PUBLIC int script_update_category(void *h, const char *id, const char *category)
1514 struct info *handle = h;
1516 if (handle->category) {
1517 free(handle->category);
1518 handle->category = NULL;
1522 return LB_STATUS_SUCCESS;
1525 handle->category = strdup(category);
1526 if (!handle->category) {
1527 ErrPrint("Error: %s\n", strerror(errno));
1528 return LB_STATUS_ERROR_MEMORY;
1531 return LB_STATUS_SUCCESS;
1534 PUBLIC void *script_create(void *buffer_handle, const char *file, const char *group)
1536 struct info *handle;
1538 handle = calloc(1, sizeof(*handle));
1540 ErrPrint("Error: %s\n", strerror(errno));
1544 handle->file = strdup(file);
1545 if (!handle->file) {
1546 ErrPrint("Error: %s\n", strerror(errno));
1551 handle->group = strdup(group);
1552 if (!handle->group) {
1553 ErrPrint("Error: %s\n", strerror(errno));
1559 handle->buffer_handle = buffer_handle;
1561 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1566 PUBLIC int script_destroy(void *_handle)
1568 struct info *handle;
1573 if (!eina_list_data_find(s_info.handle_list, handle)) {
1574 DbgPrint("Not found (already deleted?)\n");
1575 return LB_STATUS_ERROR_NOT_EXIST;
1578 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1580 edje = eina_list_nth(handle->obj_list, 0);
1582 evas_object_del(edje);
1585 DbgPrint("Release handle\n");
1586 free(handle->category);
1588 free(handle->group);
1590 return LB_STATUS_SUCCESS;
1593 static void sw_render_pre_cb(void *data, Evas *e, void *event_info)
1595 struct info *handle = data;
1597 if (handle->render_pre) {
1598 handle->render_pre(handle->buffer_handle, handle->render_data);
1601 script_buffer_lock(handle->buffer_handle);
1603 if (s_info.premultiplied) {
1607 script_buffer_get_size(handle->buffer_handle, &w, &h);
1608 evas_damage_rectangle_add(handle->e, 0, 0, w, h);
1612 static void sw_render_post_cb(void *data, Evas *e, void *event_info)
1614 struct info *handle = data;
1616 if (s_info.premultiplied) {
1620 // Get a pointer of a buffer of the virtual canvas
1621 canvas = (void *)ecore_evas_buffer_pixels_get(handle->ee);
1623 ErrPrint("Failed to get pixel canvas\n");
1627 ecore_evas_geometry_get(handle->ee, &x, &y, &w, &h);
1628 evas_data_argb_unpremul(canvas, w * h);
1631 script_buffer_unlock(handle->buffer_handle);
1633 if (handle->render_post) {
1634 handle->render_post(handle->buffer_handle, handle->render_data);
1638 static void render_pre_cb(void *data, Evas *e, void *event_info)
1640 struct info *handle = data;
1643 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1645 ErrPrint("Acquired buffer is NULL\n");
1648 sw_render_pre_cb(data, handle->e, event_info);
1651 static void render_post_cb(void *data, Evas *e, void *event_info)
1653 struct info *handle = data;
1656 sw_render_post_cb(data, handle->e, event_info);
1657 canvas = script_buffer_pixmap_buffer(handle->buffer_handle);
1659 ErrPrint("Acquired buffer is NULL\n");
1661 script_buffer_pixmap_release_buffer(canvas);
1665 static void *alloc_fb(void *data, int size)
1667 struct info *handle = data;
1669 if (script_buffer_load(handle->buffer_handle) < 0) {
1670 ErrPrint("Failed to load buffer handler\n");
1674 return script_buffer_fb(handle->buffer_handle);
1677 static void free_fb(void *data, void *ptr)
1679 struct info *handle = data;
1681 if (!handle->buffer_handle) {
1682 ErrPrint("Buffer is not valid (maybe already released)\n");
1686 if (script_buffer_fb(handle->buffer_handle) != ptr) {
1687 ErrPrint("Buffer pointer is not matched\n");
1690 (void)script_buffer_unload(handle->buffer_handle);
1693 static int destroy_ecore_evas(struct info *handle)
1696 return LB_STATUS_SUCCESS;
1698 ecore_evas_free(handle->ee);
1701 return LB_STATUS_SUCCESS;
1704 static int create_ecore_evas(struct info *handle, int *w, int *h)
1706 script_buffer_get_size(handle->buffer_handle, w, h);
1707 if (*w == 0 && *h == 0) {
1708 ErrPrint("ZERO size FB accessed\n");
1709 return LB_STATUS_ERROR_INVALID;
1716 ecore_evas_geometry_get(handle->ee, NULL, NULL, &ow, &oh);
1717 if (*w != ow || *h != oh) {
1718 ErrPrint("EE exists, But different size - buffer_handle(%dx%d) -> ee(%dx%d)\n", ow, oh, *w, *h);
1719 ecore_evas_resize(handle->ee, *w, *h);
1722 return LB_STATUS_SUCCESS;
1725 handle->ee = ecore_evas_buffer_allocfunc_new(*w, *h, alloc_fb, free_fb, handle);
1727 ErrPrint("Failed to create a buffer\n");
1728 return LB_STATUS_ERROR_FAULT;
1731 handle->e = ecore_evas_get(handle->ee);
1733 ErrPrint("Failed to get an Evas\n");
1734 ecore_evas_free(handle->ee);
1736 return LB_STATUS_ERROR_FAULT;
1739 if (script_buffer_type(handle->buffer_handle) == BUFFER_TYPE_PIXMAP) {
1742 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb, handle);
1743 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, render_post_cb, handle);
1747 * ecore_evas_alpha_set tries to access the canvas buffer.
1748 * Without any render_pre/render_post callback.
1750 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1752 ErrPrint("Acquired buffer is NULL\n");
1754 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1755 script_buffer_pixmap_release_buffer(canvas);
1758 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, sw_render_pre_cb, handle);
1759 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, sw_render_post_cb, handle);
1760 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1763 ecore_evas_manual_render_set(handle->ee, EINA_FALSE);
1764 ecore_evas_resize(handle->ee, *w, *h);
1765 ecore_evas_show(handle->ee);
1766 ecore_evas_activate(handle->ee);
1768 return LB_STATUS_SUCCESS;
1771 PUBLIC int script_load(void *_handle, int (*render_pre)(void *buffer_handle, void *data), int (*render_post)(void *render_handle, void *data), void *data)
1773 struct info *handle;
1775 struct obj_info *obj_info;
1782 * Create "Ecore_Evas *"
1787 handle->render_pre = render_pre;
1788 handle->render_post = render_post;
1789 handle->render_data = data;
1791 ret = create_ecore_evas(handle, &w, &h);
1796 obj_info = calloc(1, sizeof(*obj_info));
1798 ErrPrint("Heap: %s\n", strerror(errno));
1799 destroy_ecore_evas(handle);
1800 return LB_STATUS_ERROR_MEMORY;
1803 obj_info->parent = evas_object_rectangle_add(handle->e);
1804 if (!obj_info->parent) {
1805 ErrPrint("Unable to create a parent box\n");
1807 destroy_ecore_evas(handle);
1808 return LB_STATUS_ERROR_FAULT;
1811 edje = elm_layout_add(obj_info->parent);
1813 ErrPrint("Failed to create an edje object\n");
1814 evas_object_del(obj_info->parent);
1816 destroy_ecore_evas(handle);
1817 return LB_STATUS_ERROR_FAULT;
1820 edje_object_scale_set(elm_layout_edje_get(edje), elm_config_scale_get());
1822 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1825 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1826 if (err != EDJE_LOAD_ERROR_NONE) {
1827 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, edje_load_error_str(err));
1829 evas_object_del(edje);
1830 evas_object_del(obj_info->parent);
1832 destroy_ecore_evas(handle);
1833 return LB_STATUS_ERROR_IO;
1836 handle->parent = edje;
1838 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1839 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1840 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1841 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1842 evas_object_resize(edje, w, h);
1843 evas_object_show(edje);
1844 evas_object_data_set(edje, "obj_info", obj_info);
1846 handle->obj_list = eina_list_append(handle->obj_list, edje);
1847 return LB_STATUS_SUCCESS;
1850 PUBLIC int script_unload(void *_handle)
1852 struct info *handle;
1856 * Destroy "Ecore_Evas *"
1861 if (handle->parent) {
1862 DbgPrint("Delete parent box\n");
1863 evas_object_del(handle->parent);
1866 (void)destroy_ecore_evas(handle);
1867 return LB_STATUS_SUCCESS;
1870 static void access_cb(keynode_t *node, void *user_data)
1875 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1876 ErrPrint("Idle lock state is not valid\n");
1877 state = 0; /* DISABLED */
1880 state = vconf_keynode_get_bool(node);
1883 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1884 elm_config_access_set(state);
1885 s_info.access_on = state;
1888 static void update_font_cb(void *data)
1890 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1891 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1894 static void font_changed_cb(keynode_t *node, void *user_data)
1898 #if defined(WEARABLE)
1902 if (s_info.font_name) {
1903 font_name = vconf_get_str("db/setting/accessibility/font_name");
1905 ErrPrint("Invalid font name (NULL)\n");
1909 if (!strcmp(s_info.font_name, font_name)) {
1910 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1915 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1916 free(s_info.font_name);
1921 * Get the first font name using system_settings API.
1924 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
1925 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
1926 ErrPrint("System setting get: %d, font_name[%p]\n", ret, font_name);
1931 s_info.font_name = font_name;
1932 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1936 * Try to update all liveboxes
1938 update_font_cb(NULL);
1941 static inline int convert_font_size(int size)
1944 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
1947 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
1950 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
1953 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
1956 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
1964 DbgPrint("Return size: %d\n", size);
1968 static void font_size_cb(system_settings_key_e key, void *user_data)
1972 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE) {
1976 size = convert_font_size(size);
1978 if (size == s_info.font_size) {
1979 DbgPrint("Font size is not changed\n");
1983 s_info.font_size = size;
1984 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
1987 PUBLIC int script_init(double scale, int premultiplied)
1995 s_info.premultiplied = premultiplied;
1997 /* ecore is already initialized */
1999 elm_config_scale_set(scale);
2000 DbgPrint("Scale is updated: %lf\n", scale);
2002 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
2004 DbgPrint("TTS changed: %d\n", ret);
2007 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
2008 DbgPrint("System font is changed: %d\n", ret);
2010 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
2011 DbgPrint("System font size is changed: %d\n", ret);
2013 access_cb(NULL, NULL);
2014 font_changed_cb(NULL, NULL);
2015 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
2016 return LB_STATUS_SUCCESS;
2019 PUBLIC int script_fini(void)
2024 struct info *handle;
2026 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
2027 script_destroy(handle);
2030 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
2032 DbgPrint("Unset font size change event callback: %d\n", ret);
2035 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
2037 DbgPrint("Unset font name change event callback: %d\n", ret);
2040 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
2042 DbgPrint("Unset tts: %d\n", ret);
2047 free(s_info.font_name);
2048 s_info.font_name = NULL;
2049 return LB_STATUS_SUCCESS;