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.
25 #include <Elementary.h>
30 #include <Ecore_Evas.h>
32 #include <efl_assist.h>
34 #include <system_settings.h>
39 #include <livebox-errno.h>
40 #include <livebox-service.h>
42 #include "script_port.h"
45 #define TEXT_CLASS "tizen"
46 #define DEFAULT_FONT_SIZE -100
48 #define PUBLIC __attribute__((visibility("default")))
87 int (*render_pre)(void *buffer_handle, void *data);
88 int (*render_post)(void *render_handle, void *data);
109 Eina_List *handle_list;
111 Ecore_Evas *(*alloc_canvas)(int w, int h, void *(*a)(void *data, int size), void (*f)(void *data, void *ptr), void *data);
112 Ecore_Evas *(*alloc_canvas_with_stride)(int w, int h, void *(*a)(void *data, int size, int *stride, int *bpp), void (*f)(void *data, void *ptr), void *data);
120 .alloc_canvas = NULL,
121 .alloc_canvas_with_stride = NULL,
124 static inline Evas_Object *find_edje(struct info *handle, const char *id)
128 struct obj_info *obj_info;
130 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
131 obj_info = evas_object_data_get(edje, "obj_info");
133 ErrPrint("Object info is not valid\n");
143 } else if (!obj_info->id) {
147 if (!strcmp(obj_info->id, id)) {
152 DbgPrint("EDJE[%s] is not found\n", id);
156 PUBLIC const char *script_magic_id(void)
161 PUBLIC int script_update_color(void *h, const char *id, const char *part, const char *rgba)
163 struct info *handle = h;
165 int r[3], g[3], b[3], a[3];
168 edje = find_edje(handle, id);
170 return LB_STATUS_ERROR_NOT_EXIST;
173 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
174 r, g, b, a, /* OBJECT */
175 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
176 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
178 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
179 return LB_STATUS_ERROR_INVALID;
182 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
183 r[0], g[0], b[0], a[0], /* OBJECT */
184 r[1], g[1], b[1], a[1], /* OUTLINE */
185 r[2], g[2], b[2], a[2]); /* SHADOW */
187 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
188 return LB_STATUS_SUCCESS;
191 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
200 e = evas_object_evas_get(part_obj);
201 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
205 #if defined(_USE_ECORE_TIME_GET)
206 timestamp = ecore_time_get();
209 if (gettimeofday(&tv, NULL) < 0) {
210 ErrPrint("Failed to get time\n");
213 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
217 DbgPrint("Cursor is on %dx%d\n", x, y);
218 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
219 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
220 evas_event_feed_mouse_move(e, x, y, (timestamp + 0.02f) * 1000, NULL);
221 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.03f) * 1000, NULL);
224 static void update_focus_chain(struct info *handle, Evas_Object *ao)
226 const Eina_List *list;
228 list = elm_object_focus_custom_chain_get(handle->parent);
229 if (!eina_list_data_find(list, ao)) {
230 DbgPrint("Append again to the focus chain\n");
231 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
235 PUBLIC int script_update_text(void *h, const char *id, const char *part, const char *text)
237 struct obj_info *obj_info;
238 struct info *handle = h;
240 Evas_Object *edje_part;
242 edje = find_edje(handle, id);
244 ErrPrint("Failed to find EDJE\n");
245 return LB_STATUS_ERROR_NOT_EXIST;
248 obj_info = evas_object_data_get(edje, "obj_info");
250 ErrPrint("Object info is not available\n");
251 return LB_STATUS_ERROR_FAULT;
254 elm_object_part_text_set(edje, part, text ? text : "");
256 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
261 ao = evas_object_data_get(edje_part, "ao");
263 ao = elm_access_object_register(edje_part, handle->parent);
265 ErrPrint("Unable to register an access object(%s)\n", part);
269 evas_object_data_set(edje_part, "ao", ao);
270 elm_access_activate_cb_set(ao, activate_cb, NULL);
271 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
273 DbgPrint("[%s] Register access info: (%s) to, %p\n", part, text, handle->parent);
276 if (!text || !strlen(text)) {
279 * Delete callback will be called
281 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
282 elm_access_object_unregister(ao);
287 utf8 = elm_entry_markup_to_utf8(text);
288 if ((!utf8 || !strlen(utf8))) {
292 * Delete callback will be called
294 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
295 elm_access_object_unregister(ao);
300 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
303 update_focus_chain(handle, ao);
305 ErrPrint("Unable to get text part[%s]\n", part);
309 return LB_STATUS_SUCCESS;
312 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
314 while (len > 0 && *value == ' ') {
323 img_opt->aspect = !strncasecmp(value, "true", 4);
324 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
327 static void parse_orient(struct image_option *img_opt, const char *value, int len)
329 while (len > 0 && *value == ' ') {
338 img_opt->orient = !strncasecmp(value, "true", 4);
339 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
342 static void parse_size(struct image_option *img_opt, const char *value, int len)
348 while (len > 0 && *value == ' ') {
353 buf = strndup(value, len);
355 ErrPrint("Heap: %s\n", strerror(errno));
359 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
360 img_opt->width = width;
361 img_opt->height = height;
362 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
364 DbgPrint("Invalid size tag[%s]\n", buf);
370 static void parse_shadow(struct image_option *img_opt, const char *value, int len)
377 if (sscanf(value, "%d,%d,%d,%x", &angle, &offset, &softness, &color) != 4) {
378 ErrPrint("Invalid shadow [%s]\n", value);
380 img_opt->shadow.enabled = 1;
381 img_opt->shadow.angle = angle;
382 img_opt->shadow.offset = offset;
383 img_opt->shadow.softness = softness;
384 img_opt->shadow.color = color;
388 static void parse_fill(struct image_option *img_opt, const char *value, int len)
390 while (len > 0 && *value == ' ') {
395 if (!strncasecmp(value, "in-size", len)) {
396 img_opt->fill = FILL_IN_SIZE;
397 } else if (!strncasecmp(value, "over-size", len)) {
398 img_opt->fill = FILL_OVER_SIZE;
399 } else if (!strncasecmp(value, "fit-size", len)) {
400 img_opt->fill = FILL_FIT_SIZE;
402 img_opt->fill = FILL_DISABLE;
405 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
408 static inline void parse_image_option(const char *option, struct image_option *img_opt)
415 void (*handler)(struct image_option *img_opt, const char *value, int len);
418 .cmd = "aspect", /* Keep the aspect ratio */
419 .handler = parse_aspect,
422 .cmd = "orient", /* Keep the orientation value: for the rotated images */
423 .handler = parse_orient,
426 .cmd = "fill", /* Fill the image to its container */
427 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
431 .handler = parse_size,
435 .handler = parse_shadow,
449 if (!option || !*option) {
456 * GCC 4.7 warnings uninitialized idx and tag value.
457 * But it will be initialized by the state machine. :(
458 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
465 for (ptr = option; state != STATE_END; ptr++) {
480 cmd = cmd_list[tag].cmd;
486 } else if (*ptr == '\0') {
491 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
496 state = STATE_IGNORE;
499 } else if (*ptr == '\0') {
501 } else if (cmd[idx] == *ptr) {
507 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
511 cmd = cmd_list[tag].cmd;
517 if (*ptr == ';' || *ptr == '\0') {
518 cmd_list[tag].handler(img_opt, value + 1, idx);
519 state = *ptr ? STATE_START : STATE_END;
527 } else if (*ptr == '\0') {
537 PUBLIC int script_update_access(void *_h, const char *id, const char *part, const char *text, const char *option)
539 struct info *handle = _h;
541 struct obj_info *obj_info;
542 Evas_Object *edje_part;
544 edje = find_edje(handle, id);
546 ErrPrint("No such object: %s\n", id);
547 return LB_STATUS_ERROR_NOT_EXIST;
550 obj_info = evas_object_data_get(edje, "obj_info");
552 ErrPrint("Object info is not available\n");
553 return LB_STATUS_ERROR_FAULT;
556 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
560 ao = evas_object_data_get(edje_part, "ao");
562 if (text && strlen(text)) {
563 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
564 DbgPrint("Access info is updated: %s [%s], %p\n", part, text, ao);
565 update_focus_chain(handle, ao);
569 * Delete clalback will be called
571 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
572 elm_access_object_unregister(ao);
574 } else if (text && strlen(text)) {
575 ao = elm_access_object_register(edje_part, handle->parent);
577 ErrPrint("Unable to register an access object(%s)\n", part);
579 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
581 evas_object_data_set(edje_part, "ao", ao);
582 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
583 elm_access_activate_cb_set(ao, activate_cb, NULL);
584 DbgPrint("[%s] Register access info: (%s) to, %p (%p)\n", part, text, handle->parent, ao);
588 ErrPrint("[%s] is not exists\n", part);
591 return LB_STATUS_SUCCESS;
594 PUBLIC int script_operate_access(void *_h, const char *id, const char *part, const char *operation, const char *option)
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;
677 static inline void apply_shadow_effect(struct image_option *img_opt, Evas_Object *img)
679 ea_effect_h *ea_effect;
681 if (!img_opt->shadow.enabled) {
685 ea_effect = ea_image_effect_create();
690 // -90, 2, 4, 0x99000000
691 ea_image_effect_add_outer_shadow(ea_effect, img_opt->shadow.angle, img_opt->shadow.offset, img_opt->shadow.softness, img_opt->shadow.color);
692 ea_object_image_effect_set(img, ea_effect);
694 ea_image_effect_destroy(ea_effect);
697 static Evas_Object *crop_image(Evas_Object *img, const char *path, int part_w, int part_h, int w, int h, struct image_option *img_opt)
701 Evas_Object *src_img;
706 ee = ecore_evas_buffer_new(part_w, part_h);
708 ErrPrint("Failed to create a EE\n");
709 evas_object_del(img);
713 ecore_evas_alpha_set(ee, EINA_TRUE);
715 e = ecore_evas_get(ee);
717 ErrPrint("Unable to get Evas\n");
719 evas_object_del(img);
723 src_img = evas_object_image_filled_add(e);
725 ErrPrint("Unable to add an image\n");
727 evas_object_del(img);
731 evas_object_image_alpha_set(src_img, EINA_TRUE);
732 evas_object_image_colorspace_set(src_img, EVAS_COLORSPACE_ARGB8888);
733 evas_object_image_smooth_scale_set(src_img, EINA_TRUE);
734 evas_object_image_load_orientation_set(src_img, img_opt->orient);
735 evas_object_image_file_set(src_img, path, NULL);
736 err = evas_object_image_load_error_get(src_img);
737 if (err != EVAS_LOAD_ERROR_NONE) {
738 ErrPrint("Load error: %s\n", evas_load_error_str(err));
739 evas_object_del(src_img);
741 evas_object_del(img);
744 evas_object_image_size_get(src_img, &rw, &rh);
745 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
746 evas_object_resize(src_img, w, h);
747 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
748 evas_object_show(src_img);
750 data = ecore_evas_buffer_pixels_get(ee);
752 ErrPrint("Unable to get pixels\n");
753 evas_object_del(src_img);
755 evas_object_del(img);
759 e = evas_object_evas_get(img);
760 evas_object_del(img);
761 img = evas_object_image_filled_add(e);
763 evas_object_del(src_img);
768 evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
769 evas_object_image_smooth_scale_set(img, EINA_TRUE);
770 evas_object_image_alpha_set(img, EINA_TRUE);
771 evas_object_image_data_set(img, NULL);
772 evas_object_image_size_set(img, part_w, part_h);
773 evas_object_resize(img, part_w, part_h);
774 evas_object_image_data_copy_set(img, (void *)data);
775 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
776 evas_object_image_data_update_add(img, 0, 0, part_w, part_h);
778 evas_object_del(src_img);
784 PUBLIC int script_update_image(void *_h, const char *id, const char *part, const char *path, const char *option)
786 struct info *handle = _h;
791 struct obj_info *obj_info;
792 struct image_option img_opt = {
795 .fill = FILL_DISABLE,
803 edje = find_edje(handle, id);
805 ErrPrint("No such object: %s\n", id);
806 return LB_STATUS_ERROR_NOT_EXIST;
809 obj_info = evas_object_data_get(edje, "obj_info");
811 ErrPrint("Object info is not available\n");
812 return LB_STATUS_ERROR_FAULT;
815 img = elm_object_part_content_unset(edje, part);
817 DbgPrint("delete object %s %p\n", part, img);
818 evas_object_del(img);
821 if (!path || !strlen(path) || access(path, R_OK) != 0) {
822 DbgPrint("SKIP - Path: [%s]\n", path);
823 return LB_STATUS_SUCCESS;
826 img = evas_object_image_add(handle->e);
828 ErrPrint("Failed to add an image object\n");
829 return LB_STATUS_ERROR_FAULT;
832 evas_object_image_preload(img, EINA_FALSE);
833 parse_image_option(option, &img_opt);
834 evas_object_image_load_orientation_set(img, img_opt.orient);
836 evas_object_image_file_set(img, path, NULL);
837 err = evas_object_image_load_error_get(img);
838 if (err != EVAS_LOAD_ERROR_NONE) {
839 ErrPrint("Load error: %s\n", evas_load_error_str(err));
840 evas_object_del(img);
841 return LB_STATUS_ERROR_IO;
844 apply_shadow_effect(&img_opt, img);
846 evas_object_image_size_get(img, &w, &h);
847 if (img_opt.aspect) {
848 if (img_opt.fill == FILL_OVER_SIZE) {
852 if (img_opt.width >= 0 && img_opt.height >= 0) {
853 part_w = img_opt.width * elm_config_scale_get();
854 part_h = img_opt.height * elm_config_scale_get();
858 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
860 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
862 if (part_w > w || part_h > h) {
866 fw = (double)part_w / (double)w;
867 fh = (double)part_h / (double)h;
878 if (!part_w || !part_h || !w || !h) {
879 evas_object_del(img);
880 return LB_STATUS_ERROR_INVALID;
883 img = crop_image(img, path, part_w, part_h, w, h, &img_opt);
884 } else if (img_opt.fill == FILL_IN_SIZE) {
888 if (img_opt.width >= 0 && img_opt.height >= 0) {
889 part_w = img_opt.width * elm_config_scale_get();
890 part_h = img_opt.height * elm_config_scale_get();
894 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
896 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
898 if (w > part_w || h > part_h) {
902 fw = (double)part_w / (double)w;
903 fh = (double)part_h / (double)h;
914 if (!part_w || !part_h || !w || !h) {
915 evas_object_del(img);
916 return LB_STATUS_ERROR_INVALID;
919 img = crop_image(img, path, part_w, part_h, w, h, &img_opt);
920 } else if (img_opt.fill == FILL_FIT_SIZE) {
926 if (img_opt.width >= 0 && img_opt.height >= 0) {
927 part_w = img_opt.width * elm_config_scale_get();
928 part_h = img_opt.height * elm_config_scale_get();
932 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
934 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
936 fw = (double)part_w / (double)w;
937 fh = (double)part_h / (double)h;
947 if (!part_w || !part_h || !w || !h) {
948 evas_object_del(img);
949 return LB_STATUS_ERROR_INVALID;
952 img = crop_image(img, path, part_w, part_h, w, h, &img_opt);
954 evas_object_image_fill_set(img, 0, 0, w, h);
955 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
956 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
959 apply_shadow_effect(&img_opt, img);
961 if (img_opt.width >= 0 && img_opt.height >= 0) {
964 DbgPrint("Using given image size: %dx%d\n", w, h);
967 evas_object_image_fill_set(img, 0, 0, w, h);
968 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
969 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
970 evas_object_image_filled_set(img, EINA_TRUE);
976 * object will be shown by below statement automatically
978 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
979 elm_object_part_content_set(edje, part, img);
983 * This object is not registered as an access object.
984 * So the developer should add it to access list manually, using DESC_ACCESS block.
986 return LB_STATUS_SUCCESS;
989 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
991 struct info *handle = data;
1003 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1004 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
1008 sx = (double)px / (double)w;
1009 ex = (double)(px + pw) / (double)w;
1014 sy = (double)py / (double)h;
1015 ey = (double)(py + ph) / (double)h;
1018 DbgPrint("[%s] [%s]\n", emission, source);
1020 script_buffer_signal_emit(handle->buffer_handle, source, emission, sx, sy, ex, ey);
1023 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
1025 struct info *handle = _info;
1026 struct obj_info *obj_info;
1027 struct obj_info *parent_obj_info;
1028 struct child *child;
1030 handle->obj_list = eina_list_remove(handle->obj_list, obj);
1032 obj_info = evas_object_data_get(obj, "obj_info");
1034 ErrPrint("Object info is not valid\n");
1038 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
1040 DbgPrint("delete object %s %p\n", obj_info->id, obj);
1041 if (obj_info->parent == obj) {
1042 DbgPrint("Parent EDJE\n");
1043 } else if (obj_info->parent) {
1047 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
1048 if (parent_obj_info) {
1049 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
1050 if (child->obj != obj) {
1056 * If this code is executed,
1057 * The parent is not deleted by desc, this object is deleted by itself.
1058 * It is not possible, but we care it.
1060 DbgPrint("Children is updated: %s (%s)\n", child->part, parent_obj_info->id);
1061 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
1067 if (!parent_obj_info->children && parent_obj_info->delete_me == 1) {
1068 DbgPrint("Children is cleared: %s (by a child)\n", parent_obj_info->id);
1069 evas_object_data_del(obj_info->parent, "obj_info");
1070 free(parent_obj_info->id);
1071 free(parent_obj_info);
1075 DbgPrint("obj_info->parent is NULL (skipped)\n");
1078 if (!obj_info->children) {
1079 DbgPrint("Children is cleared: %s\n", obj_info->id);
1080 evas_object_data_del(obj, "obj_info");
1084 DbgPrint("Children is remained: %s\n", obj_info->id);
1085 obj_info->delete_me = 1;
1089 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
1091 Evas_Object *o, *ho;
1093 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
1098 ho = evas_object_data_get(o, "_elm_access_target");
1103 LB_ACCESS_HIGHLIGHT 0
1104 LB_ACCESS_HIGHLIGHT_NEXT 1
1105 LB_ACCESS_HIGHLIGHT_PREV 2
1106 LB_ACCESS_ACTIVATE 3
1110 PUBLIC int script_feed_event(void *h, int event_type, int x, int y, int down, unsigned int keycode, double timestamp)
1112 struct info *handle = h;
1114 struct obj_info *obj_info;
1115 int ret = LB_STATUS_SUCCESS;
1117 edje = find_edje(handle, NULL); /*!< Get the base layout */
1119 ErrPrint("Base layout is not exist\n");
1120 return LB_STATUS_ERROR_NOT_EXIST;
1123 obj_info = evas_object_data_get(edje, "obj_info");
1125 ErrPrint("Object info is not valid\n");
1126 return LB_STATUS_ERROR_INVALID;
1129 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
1130 Elm_Access_Action_Info info;
1131 Elm_Access_Action_Type action;
1133 memset(&info, 0, sizeof(info));
1135 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
1136 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1139 ret = elm_access_action(edje, action, &info);
1140 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1141 if (ret == EINA_TRUE) {
1142 if (!get_highlighted_object(edje)) {
1143 ErrPrint("Highlighted object is not found\n");
1144 ret = LB_ACCESS_STATUS_ERROR;
1146 DbgPrint("Highlighted object is found\n");
1147 ret = LB_ACCESS_STATUS_DONE;
1150 ErrPrint("Action error\n");
1151 ret = LB_ACCESS_STATUS_ERROR;
1153 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1154 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1155 info.highlight_cycle = EINA_FALSE;
1156 ret = elm_access_action(edje, action, &info);
1157 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1158 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
1159 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1160 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1161 info.highlight_cycle = EINA_FALSE;
1162 ret = elm_access_action(edje, action, &info);
1163 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1164 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
1165 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
1166 action = ELM_ACCESS_ACTION_ACTIVATE;
1167 ret = elm_access_action(edje, action, &info);
1168 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1169 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1170 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
1172 action = ELM_ACCESS_ACTION_UP;
1173 ret = elm_access_action(edje, action, &info);
1174 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1175 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1176 } else if (down == 1) {
1177 action = ELM_ACCESS_ACTION_DOWN;
1178 ret = elm_access_action(edje, action, &info);
1179 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
1180 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1182 ErrPrint("Invalid access event\n");
1183 ret = LB_ACCESS_STATUS_ERROR;
1185 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
1186 action = ELM_ACCESS_ACTION_SCROLL;
1191 info.mouse_type = 0;
1192 ret = elm_access_action(edje, action, &info);
1193 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1194 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1197 info.mouse_type = 1;
1198 ret = elm_access_action(edje, action, &info);
1199 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1200 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1203 info.mouse_type = 2;
1204 ret = elm_access_action(edje, action, &info);
1205 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1206 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1209 ret = LB_ACCESS_STATUS_ERROR;
1212 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
1213 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1214 ret = elm_access_action(edje, action, &info);
1215 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1216 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
1218 DbgPrint("Invalid event\n");
1219 ret = LB_ACCESS_STATUS_ERROR;
1222 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
1223 double cur_timestamp;
1226 #if defined(_USE_ECORE_TIME_GET)
1227 cur_timestamp = ecore_time_get();
1230 if (gettimeofday(&tv, NULL) < 0) {
1231 ErrPrint("Failed to get time\n");
1232 cur_timestamp = 0.0f;
1234 cur_timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1237 if (cur_timestamp - timestamp > 0.1f && handle->is_mouse_down == 0) {
1238 DbgPrint("Discard lazy event : %lf\n", cur_timestamp - timestamp);
1239 return LB_STATUS_SUCCESS;
1242 switch (event_type) {
1243 case LB_SCRIPT_MOUSE_DOWN:
1244 if (handle->is_mouse_down == 0) {
1245 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1246 evas_event_feed_mouse_down(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1247 handle->is_mouse_down = 1;
1250 case LB_SCRIPT_MOUSE_MOVE:
1251 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1253 case LB_SCRIPT_MOUSE_UP:
1254 if (handle->is_mouse_down == 1) {
1255 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1256 evas_event_feed_mouse_up(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1257 handle->is_mouse_down = 0;
1260 flags = evas_event_default_flags_get(handle->e);
1261 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
1262 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
1263 evas_event_default_flags_set(handle->e, flags);
1265 case LB_SCRIPT_MOUSE_IN:
1266 evas_event_feed_mouse_in(handle->e, timestamp * 1000, NULL);
1268 case LB_SCRIPT_MOUSE_OUT:
1269 evas_event_feed_mouse_out(handle->e, timestamp * 1000, NULL);
1271 case LB_SCRIPT_MOUSE_ON_SCROLL:
1272 flags = evas_event_default_flags_get(handle->e);
1273 flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1274 evas_event_default_flags_set(handle->e, flags);
1276 case LB_SCRIPT_MOUSE_ON_HOLD: // To cancel the clicked, enable this
1277 flags = evas_event_default_flags_get(handle->e);
1278 flags |= EVAS_EVENT_FLAG_ON_HOLD;
1279 evas_event_default_flags_set(handle->e, flags);
1281 case LB_SCRIPT_MOUSE_OFF_SCROLL:
1282 flags = evas_event_default_flags_get(handle->e);
1283 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
1284 evas_event_default_flags_set(handle->e, flags);
1286 case LB_SCRIPT_MOUSE_OFF_HOLD:
1287 flags = evas_event_default_flags_get(handle->e);
1288 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
1289 evas_event_default_flags_set(handle->e, flags);
1292 return LB_STATUS_ERROR_INVALID;
1294 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
1295 const char *keyname = "";
1296 const char *key = "";
1297 const char *string = "";
1298 const char *compose = "";
1300 switch (event_type) {
1301 case LB_SCRIPT_KEY_DOWN:
1302 evas_event_feed_key_down(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1303 ret = LB_KEY_STATUS_DONE;
1306 * If the keyname == RIGHT, Need to check that
1307 * Does it reach to the last focusable object?
1311 * if (REACH to the LAST) {
1312 * ret = LB_KEY_STATUS_LAST;
1314 * ret = LB_KEY_STATUS_DONE;
1317 * if (REACH to the FIRST) {
1318 * ret = LB_KEY_STATUS_FIRST;
1320 * ret = LB_KEY_STATUS_DONE;
1324 case LB_SCRIPT_KEY_UP:
1325 evas_event_feed_key_up(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1326 ret = LB_KEY_STATUS_DONE;
1328 case LB_SCRIPT_KEY_FOCUS_IN:
1329 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_IN, NULL);
1330 ret = LB_KEY_STATUS_DONE;
1332 case LB_SCRIPT_KEY_FOCUS_OUT:
1333 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_OUT, NULL);
1334 ret = LB_KEY_STATUS_DONE;
1337 DbgPrint("Event is not implemented\n");
1338 ret = LB_KEY_STATUS_ERROR;
1346 PUBLIC int script_update_script(void *h, const char *src_id, const char *target_id, const char *part, const char *path, const char *group)
1348 struct info *handle = h;
1351 struct obj_info *obj_info;
1352 struct child *child;
1353 char _target_id[32];
1355 edje = find_edje(handle, src_id);
1357 ErrPrint("Edje is not exists (%s)\n", src_id);
1358 return LB_STATUS_ERROR_NOT_EXIST;
1361 obj_info = evas_object_data_get(edje, "obj_info");
1363 ErrPrint("Object info is not valid\n");
1364 return LB_STATUS_ERROR_INVALID;
1367 obj = elm_object_part_content_unset(edje, part);
1369 DbgPrint("delete object %s %p\n", part, obj);
1372 * This will call the edje_del_cb.
1373 * It will delete all access objects
1375 evas_object_del(obj);
1378 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1379 DbgPrint("SKIP - Path: [%s]\n", path);
1380 return LB_STATUS_SUCCESS;
1384 if (find_edje(handle, part)) {
1388 #if defined(_USE_ECORE_TIME_GET)
1389 timestamp = ecore_time_get();
1392 if (gettimeofday(&tv, NULL) < 0) {
1393 static int local_idx = 0;
1394 timestamp = (double)(local_idx++);
1396 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1400 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1401 } while (find_edje(handle, _target_id));
1403 target_id = _target_id;
1408 DbgPrint("Anonymouse target id: %s\n", target_id);
1411 obj = elm_layout_add(edje);
1413 ErrPrint("Failed to add a new edje object\n");
1414 return LB_STATUS_ERROR_FAULT;
1417 edje_object_scale_set(elm_layout_edje_get(obj), elm_config_scale_get());
1419 if (!elm_layout_file_set(obj, path, group)) {
1421 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1422 if (err != EDJE_LOAD_ERROR_NONE) {
1423 ErrPrint("Could not load %s from %s: %s\n", group, path, edje_load_error_str(err));
1425 evas_object_del(obj);
1426 return LB_STATUS_ERROR_IO;
1429 evas_object_show(obj);
1431 obj_info = calloc(1, sizeof(*obj_info));
1433 ErrPrint("Failed to add a obj_info\n");
1434 evas_object_del(obj);
1435 return LB_STATUS_ERROR_MEMORY;
1438 obj_info->id = strdup(target_id);
1439 if (!obj_info->id) {
1440 ErrPrint("Failed to add a obj_info\n");
1442 evas_object_del(obj);
1443 return LB_STATUS_ERROR_MEMORY;
1446 obj_info->parent = edje;
1448 child = malloc(sizeof(*child));
1450 ErrPrint("Error: %s\n", strerror(errno));
1453 evas_object_del(obj);
1454 return LB_STATUS_ERROR_MEMORY;
1457 child->part = strdup(part);
1459 ErrPrint("Error: %s\n", strerror(errno));
1463 evas_object_del(obj);
1464 return LB_STATUS_ERROR_MEMORY;
1469 evas_object_data_set(obj, "obj_info", obj_info);
1470 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1471 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1472 handle->obj_list = eina_list_append(handle->obj_list, obj);
1474 DbgPrint("%s part swallow edje %p\n", part, obj);
1475 elm_object_part_content_set(edje, part, obj);
1477 obj_info = evas_object_data_get(edje, "obj_info");
1478 obj_info->children = eina_list_append(obj_info->children, child);
1480 return LB_STATUS_SUCCESS;
1483 PUBLIC int script_update_signal(void *h, const char *id, const char *part, const char *signal)
1485 struct info *handle = h;
1488 edje = find_edje(handle, id);
1490 return LB_STATUS_ERROR_NOT_EXIST;
1493 elm_object_signal_emit(edje, signal, part);
1494 return LB_STATUS_SUCCESS;
1497 PUBLIC int script_update_drag(void *h, const char *id, const char *part, double x, double y)
1499 struct info *handle = h;
1502 edje = find_edje(handle, id);
1504 return LB_STATUS_ERROR_NOT_EXIST;
1507 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1508 return LB_STATUS_SUCCESS;
1511 PUBLIC int script_update_size(void *han, const char *id, int w, int h)
1513 struct info *handle = han;
1516 edje = find_edje(handle, id);
1518 return LB_STATUS_ERROR_NOT_EXIST;
1524 * Need to resize the canvas too
1526 ecore_evas_resize(handle->ee, w, h);
1529 DbgPrint("Resize object to %dx%d\n", w, h);
1530 evas_object_resize(edje, w, h);
1531 return LB_STATUS_SUCCESS;
1534 PUBLIC int script_update_category(void *h, const char *id, const char *category)
1536 struct info *handle = h;
1538 if (handle->category) {
1539 free(handle->category);
1540 handle->category = NULL;
1544 return LB_STATUS_SUCCESS;
1547 handle->category = strdup(category);
1548 if (!handle->category) {
1549 ErrPrint("Error: %s\n", strerror(errno));
1550 return LB_STATUS_ERROR_MEMORY;
1553 return LB_STATUS_SUCCESS;
1556 PUBLIC void *script_create(void *buffer_handle, const char *file, const char *group)
1558 struct info *handle;
1560 handle = calloc(1, sizeof(*handle));
1562 ErrPrint("Error: %s\n", strerror(errno));
1566 handle->file = strdup(file);
1567 if (!handle->file) {
1568 ErrPrint("Error: %s\n", strerror(errno));
1573 handle->group = strdup(group);
1574 if (!handle->group) {
1575 ErrPrint("Error: %s\n", strerror(errno));
1581 handle->buffer_handle = buffer_handle;
1583 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1588 PUBLIC int script_destroy(void *_handle)
1590 struct info *handle;
1595 if (!eina_list_data_find(s_info.handle_list, handle)) {
1596 DbgPrint("Not found (already deleted?)\n");
1597 return LB_STATUS_ERROR_NOT_EXIST;
1600 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1602 edje = eina_list_nth(handle->obj_list, 0);
1604 evas_object_del(edje);
1607 DbgPrint("Release handle\n");
1608 free(handle->category);
1610 free(handle->group);
1612 return LB_STATUS_SUCCESS;
1615 static void sw_render_pre_cb(void *data, Evas *e, void *event_info)
1617 struct info *handle = data;
1619 if (handle->render_pre) {
1620 handle->render_pre(handle->buffer_handle, handle->render_data);
1623 script_buffer_lock(handle->buffer_handle);
1625 if (s_info.premultiplied) {
1629 script_buffer_get_size(handle->buffer_handle, &w, &h);
1630 evas_damage_rectangle_add(handle->e, 0, 0, w, h);
1634 static void sw_render_post_cb(void *data, Evas *e, void *event_info)
1636 struct info *handle = data;
1638 if (s_info.premultiplied) {
1642 // Get a pointer of a buffer of the virtual canvas
1643 canvas = (void *)ecore_evas_buffer_pixels_get(handle->ee);
1645 ErrPrint("Failed to get pixel canvas\n");
1649 ecore_evas_geometry_get(handle->ee, &x, &y, &w, &h);
1650 evas_data_argb_unpremul(canvas, w * h);
1653 script_buffer_unlock(handle->buffer_handle);
1655 if (handle->render_post) {
1656 handle->render_post(handle->buffer_handle, handle->render_data);
1660 static void render_pre_cb(void *data, Evas *e, void *event_info)
1662 struct info *handle = data;
1665 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1667 ErrPrint("Acquired buffer is NULL\n");
1670 sw_render_pre_cb(data, handle->e, event_info);
1673 static void render_post_cb(void *data, Evas *e, void *event_info)
1675 struct info *handle = data;
1678 sw_render_post_cb(data, handle->e, event_info);
1679 canvas = script_buffer_pixmap_buffer(handle->buffer_handle);
1681 ErrPrint("Acquired buffer is NULL\n");
1683 script_buffer_pixmap_release_buffer(canvas);
1687 static void *alloc_fb(void *data, int size)
1689 struct info *handle = data;
1691 if (script_buffer_load(handle->buffer_handle) < 0) {
1692 ErrPrint("Failed to load buffer handler\n");
1696 return script_buffer_fb(handle->buffer_handle);
1699 static void *alloc_with_stride_fb(void *data, int size, int *stride, int *bpp)
1701 struct info *handle = data;
1705 _bpp = script_buffer_pixels(handle->buffer_handle);
1707 ErrPrint("Failed to get pixel size, fallback to 4\n");
1711 _stride = script_buffer_stride(handle->buffer_handle);
1715 ecore_evas_geometry_get(handle->ee, NULL, NULL, &w, NULL);
1718 ErrPrint("Failed to get stride info, fallback to %d\n", _stride);
1724 return alloc_fb(data, size);
1727 static void free_fb(void *data, void *ptr)
1729 struct info *handle = data;
1731 if (!handle->buffer_handle) {
1732 ErrPrint("Buffer is not valid (maybe already released)\n");
1736 if (script_buffer_fb(handle->buffer_handle) != ptr) {
1737 ErrPrint("Buffer pointer is not matched\n");
1740 (void)script_buffer_unload(handle->buffer_handle);
1743 static int destroy_ecore_evas(struct info *handle)
1746 return LB_STATUS_SUCCESS;
1748 ecore_evas_free(handle->ee);
1751 return LB_STATUS_SUCCESS;
1754 static int create_ecore_evas(struct info *handle, int *w, int *h)
1756 script_buffer_get_size(handle->buffer_handle, w, h);
1757 if (*w == 0 && *h == 0) {
1758 ErrPrint("ZERO size FB accessed\n");
1759 return LB_STATUS_ERROR_INVALID;
1766 ecore_evas_geometry_get(handle->ee, NULL, NULL, &ow, &oh);
1767 if (*w != ow || *h != oh) {
1768 ErrPrint("EE exists, But different size - buffer_handle(%dx%d) -> ee(%dx%d)\n", ow, oh, *w, *h);
1769 ecore_evas_resize(handle->ee, *w, *h);
1772 return LB_STATUS_SUCCESS;
1775 if (!script_buffer_auto_align() && s_info.alloc_canvas_with_stride) {
1776 handle->ee = s_info.alloc_canvas_with_stride(*w, *h, alloc_with_stride_fb, free_fb, handle);
1777 } else if (s_info.alloc_canvas) {
1778 handle->ee = s_info.alloc_canvas(*w, *h, alloc_fb, free_fb, handle);
1780 ErrPrint("Failed to allocate canvas\n");
1781 return LB_STATUS_ERROR_FAULT;
1785 ErrPrint("Failed to create a buffer\n");
1786 return LB_STATUS_ERROR_FAULT;
1789 handle->e = ecore_evas_get(handle->ee);
1791 ErrPrint("Failed to get an Evas\n");
1792 ecore_evas_free(handle->ee);
1794 return LB_STATUS_ERROR_FAULT;
1797 if (script_buffer_type(handle->buffer_handle) == BUFFER_TYPE_PIXMAP) {
1800 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb, handle);
1801 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, render_post_cb, handle);
1805 * ecore_evas_alpha_set tries to access the canvas buffer.
1806 * Without any render_pre/render_post callback.
1808 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1810 ErrPrint("Acquired buffer is NULL\n");
1812 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1813 script_buffer_pixmap_release_buffer(canvas);
1816 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, sw_render_pre_cb, handle);
1817 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, sw_render_post_cb, handle);
1818 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1821 ecore_evas_manual_render_set(handle->ee, EINA_FALSE);
1822 ecore_evas_resize(handle->ee, *w, *h);
1823 ecore_evas_show(handle->ee);
1824 ecore_evas_activate(handle->ee);
1826 return LB_STATUS_SUCCESS;
1829 PUBLIC int script_load(void *_handle, int (*render_pre)(void *buffer_handle, void *data), int (*render_post)(void *render_handle, void *data), void *data)
1831 struct info *handle;
1833 struct obj_info *obj_info;
1840 * Create "Ecore_Evas *"
1845 handle->render_pre = render_pre;
1846 handle->render_post = render_post;
1847 handle->render_data = data;
1849 ret = create_ecore_evas(handle, &w, &h);
1854 obj_info = calloc(1, sizeof(*obj_info));
1856 ErrPrint("Heap: %s\n", strerror(errno));
1857 destroy_ecore_evas(handle);
1858 return LB_STATUS_ERROR_MEMORY;
1861 obj_info->parent = evas_object_rectangle_add(handle->e);
1862 if (!obj_info->parent) {
1863 ErrPrint("Unable to create a parent box\n");
1865 destroy_ecore_evas(handle);
1866 return LB_STATUS_ERROR_FAULT;
1869 edje = elm_layout_add(obj_info->parent);
1871 ErrPrint("Failed to create an edje object\n");
1872 evas_object_del(obj_info->parent);
1874 destroy_ecore_evas(handle);
1875 return LB_STATUS_ERROR_FAULT;
1878 edje_object_scale_set(elm_layout_edje_get(edje), elm_config_scale_get());
1880 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1883 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1884 if (err != EDJE_LOAD_ERROR_NONE) {
1885 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, edje_load_error_str(err));
1887 evas_object_del(edje);
1888 evas_object_del(obj_info->parent);
1890 destroy_ecore_evas(handle);
1891 return LB_STATUS_ERROR_IO;
1894 handle->parent = edje;
1896 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1897 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1898 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1899 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1900 evas_object_resize(edje, w, h);
1901 evas_object_show(edje);
1902 evas_object_data_set(edje, "obj_info", obj_info);
1904 handle->obj_list = eina_list_append(handle->obj_list, edje);
1905 return LB_STATUS_SUCCESS;
1908 PUBLIC int script_unload(void *_handle)
1910 struct info *handle;
1914 * Destroy "Ecore_Evas *"
1919 if (handle->parent) {
1920 DbgPrint("Delete parent box\n");
1921 evas_object_del(handle->parent);
1924 (void)destroy_ecore_evas(handle);
1925 return LB_STATUS_SUCCESS;
1928 static void access_cb(keynode_t *node, void *user_data)
1933 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1934 ErrPrint("Idle lock state is not valid\n");
1935 state = 0; /* DISABLED */
1938 state = vconf_keynode_get_bool(node);
1941 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1942 elm_config_access_set(state);
1943 s_info.access_on = state;
1946 static void update_font_cb(void *data)
1948 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1949 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
1952 static void font_changed_cb(keynode_t *node, void *user_data)
1958 if (s_info.font_name) {
1959 font_name = vconf_get_str("db/setting/accessibility/font_name");
1961 ErrPrint("Invalid font name (NULL)\n");
1965 if (!strcmp(s_info.font_name, font_name)) {
1966 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
1971 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
1972 free(s_info.font_name);
1977 * Get the first font name using system_settings API.
1980 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
1981 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
1982 ErrPrint("System setting get: %d, font_name[%p]\n", ret, font_name);
1987 s_info.font_name = font_name;
1988 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
1992 * Try to update all liveboxes
1994 update_font_cb(NULL);
1997 static inline int convert_font_size(int size)
2000 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
2003 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
2006 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
2009 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
2012 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
2020 DbgPrint("Return size: %d\n", size);
2024 static void font_size_cb(system_settings_key_e key, void *user_data)
2028 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE) {
2032 size = convert_font_size(size);
2034 if (size == s_info.font_size) {
2035 DbgPrint("Font size is not changed\n");
2039 s_info.font_size = size;
2040 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
2043 PUBLIC int script_init(double scale, int premultiplied)
2051 s_info.premultiplied = premultiplied;
2053 /* ecore is already initialized */
2055 elm_config_scale_set(scale);
2056 DbgPrint("Scale is updated: %lf\n", scale);
2058 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
2060 DbgPrint("TTS changed: %d\n", ret);
2063 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
2064 DbgPrint("System font is changed: %d\n", ret);
2066 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
2067 DbgPrint("System font size is changed: %d\n", ret);
2069 access_cb(NULL, NULL);
2070 font_changed_cb(NULL, NULL);
2071 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
2073 s_info.alloc_canvas_with_stride = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_with_stride_new");
2074 if (!s_info.alloc_canvas_with_stride) {
2075 DbgPrint("Fallback to allocfunc_new\n");
2078 s_info.alloc_canvas = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_new");
2079 if (!s_info.alloc_canvas) {
2080 ErrPrint("No way to allocate canvas\n");
2083 return LB_STATUS_SUCCESS;
2086 PUBLIC int script_fini(void)
2091 struct info *handle;
2093 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
2094 script_destroy(handle);
2097 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
2099 DbgPrint("Unset font size change event callback: %d\n", ret);
2102 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
2104 DbgPrint("Unset font name change event callback: %d\n", ret);
2107 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
2109 DbgPrint("Unset tts: %d\n", ret);
2114 free(s_info.font_name);
2115 s_info.font_name = NULL;
2116 return LB_STATUS_SUCCESS;