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 <dynamicbox_errno.h>
40 #include <dynamicbox_service.h>
41 #include <dynamicbox_script.h>
43 #include "script_port.h"
46 #define TEXT_CLASS "tizen"
47 #define DEFAULT_FONT_SIZE -100
49 #define PUBLIC __attribute__((visibility("default")))
51 #define ACCESS_TYPE_DOWN 0
52 #define ACCESS_TYPE_MOVE 1
53 #define ACCESS_TYPE_UP 2
54 #define ACCESS_TYPE_CUR 0
55 #define ACCESS_TYPE_NEXT 1
56 #define ACCESS_TYPE_PREV 2
57 #define ACCESS_TYPE_OFF 3
96 int (*render_pre)(void *buffer_handle, void *data);
97 int (*render_post)(void *render_handle, void *data);
118 Eina_List *handle_list;
120 Ecore_Evas *(*alloc_canvas)(int w, int h, void *(*a)(void *data, int size), void (*f)(void *data, void *ptr), void *data);
121 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);
129 .alloc_canvas = NULL,
130 .alloc_canvas_with_stride = NULL,
133 static inline Evas_Object *find_edje(struct info *handle, const char *id)
137 struct obj_info *obj_info;
139 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
140 obj_info = evas_object_data_get(edje, "obj_info");
142 ErrPrint("Object info is not valid\n");
152 } else if (!obj_info->id) {
156 if (!strcmp(obj_info->id, id)) {
161 DbgPrint("EDJE[%s] is not found\n", id);
165 PUBLIC const char *script_magic_id(void)
170 PUBLIC int script_update_color(void *h, const char *id, const char *part, const char *rgba)
172 struct info *handle = h;
174 int r[3], g[3], b[3], a[3];
177 edje = find_edje(handle, id);
179 return DBOX_STATUS_ERROR_NOT_EXIST;
182 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
183 r, g, b, a, /* OBJECT */
184 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
185 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
187 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
188 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
191 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
192 r[0], g[0], b[0], a[0], /* OBJECT */
193 r[1], g[1], b[1], a[1], /* OUTLINE */
194 r[2], g[2], b[2], a[2]); /* SHADOW */
196 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
197 return DBOX_STATUS_ERROR_NONE;
200 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
209 e = evas_object_evas_get(part_obj);
210 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
214 #if defined(_USE_ECORE_TIME_GET)
215 timestamp = ecore_time_get();
218 if (gettimeofday(&tv, NULL) < 0) {
219 ErrPrint("Failed to get time\n");
222 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
226 DbgPrint("Cursor is on %dx%d\n", x, y);
227 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
228 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
229 evas_event_feed_mouse_move(e, x, y, (timestamp + 0.02f) * 1000, NULL);
230 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.03f) * 1000, NULL);
233 static void update_focus_chain(struct info *handle, Evas_Object *ao)
235 const Eina_List *list;
237 list = elm_object_focus_custom_chain_get(handle->parent);
238 if (!eina_list_data_find(list, ao)) {
239 DbgPrint("Append again to the focus chain\n");
240 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
244 PUBLIC int script_update_text(void *h, const char *id, const char *part, const char *text)
246 struct obj_info *obj_info;
247 struct info *handle = h;
249 Evas_Object *edje_part;
251 edje = find_edje(handle, id);
253 ErrPrint("Failed to find EDJE\n");
254 return DBOX_STATUS_ERROR_NOT_EXIST;
257 obj_info = evas_object_data_get(edje, "obj_info");
259 ErrPrint("Object info is not available\n");
260 return DBOX_STATUS_ERROR_FAULT;
263 elm_object_part_text_set(edje, part, text ? text : "");
265 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
270 ao = evas_object_data_get(edje_part, "ao");
272 ao = elm_access_object_register(edje_part, handle->parent);
274 ErrPrint("Unable to register an access object(%s)\n", part);
278 evas_object_data_set(edje_part, "ao", ao);
279 elm_access_activate_cb_set(ao, activate_cb, NULL);
280 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
282 DbgPrint("[%s] Register access info: (%s) to, %p\n", part, text, handle->parent);
285 if (!text || !strlen(text)) {
288 * Delete callback will be called
290 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
291 elm_access_object_unregister(ao);
296 utf8 = elm_entry_markup_to_utf8(text);
297 if ((!utf8 || !strlen(utf8))) {
301 * Delete callback will be called
303 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
304 elm_access_object_unregister(ao);
309 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
312 update_focus_chain(handle, ao);
314 ErrPrint("Unable to get text part[%s]\n", part);
318 return DBOX_STATUS_ERROR_NONE;
321 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
323 while (len > 0 && *value == ' ') {
332 img_opt->aspect = !strncasecmp(value, "true", 4);
333 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
336 static void parse_orient(struct image_option *img_opt, const char *value, int len)
338 while (len > 0 && *value == ' ') {
347 img_opt->orient = !strncasecmp(value, "true", 4);
348 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
351 static void parse_size(struct image_option *img_opt, const char *value, int len)
357 while (len > 0 && *value == ' ') {
362 buf = strndup(value, len);
364 ErrPrint("Heap: %s\n", strerror(errno));
368 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
369 img_opt->width = width;
370 img_opt->height = height;
371 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
373 DbgPrint("Invalid size tag[%s]\n", buf);
379 static void parse_shadow(struct image_option *img_opt, const char *value, int len)
386 if (sscanf(value, "%d,%d,%d,%x", &angle, &offset, &softness, &color) != 4) {
387 ErrPrint("Invalid shadow [%s]\n", value);
389 img_opt->shadow.enabled = 1;
390 img_opt->shadow.angle = angle;
391 img_opt->shadow.offset = offset;
392 img_opt->shadow.softness = softness;
393 img_opt->shadow.color = color;
397 static void parse_fill(struct image_option *img_opt, const char *value, int len)
399 while (len > 0 && *value == ' ') {
404 if (!strncasecmp(value, "in-size", len)) {
405 img_opt->fill = FILL_IN_SIZE;
406 } else if (!strncasecmp(value, "over-size", len)) {
407 img_opt->fill = FILL_OVER_SIZE;
408 } else if (!strncasecmp(value, "fit-size", len)) {
409 img_opt->fill = FILL_FIT_SIZE;
411 img_opt->fill = FILL_DISABLE;
414 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
417 static inline void parse_image_option(const char *option, struct image_option *img_opt)
424 void (*handler)(struct image_option *img_opt, const char *value, int len);
427 .cmd = "aspect", /* Keep the aspect ratio */
428 .handler = parse_aspect,
431 .cmd = "orient", /* Keep the orientation value: for the rotated images */
432 .handler = parse_orient,
435 .cmd = "fill", /* Fill the image to its container */
436 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
440 .handler = parse_size,
444 .handler = parse_shadow,
458 if (!option || !*option) {
465 * GCC 4.7 warnings uninitialized idx and tag value.
466 * But it will be initialized by the state machine. :(
467 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
474 for (ptr = option; state != STATE_END; ptr++) {
489 cmd = cmd_list[tag].cmd;
495 } else if (*ptr == '\0') {
500 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
505 state = STATE_IGNORE;
508 } else if (*ptr == '\0') {
510 } else if (cmd[idx] == *ptr) {
516 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
520 cmd = cmd_list[tag].cmd;
526 if (*ptr == ';' || *ptr == '\0') {
527 cmd_list[tag].handler(img_opt, value + 1, idx);
528 state = *ptr ? STATE_START : STATE_END;
536 } else if (*ptr == '\0') {
546 PUBLIC int script_update_access(void *_h, const char *id, const char *part, const char *text, const char *option)
548 struct info *handle = _h;
550 struct obj_info *obj_info;
551 Evas_Object *edje_part;
553 edje = find_edje(handle, id);
555 ErrPrint("No such object: %s\n", id);
556 return DBOX_STATUS_ERROR_NOT_EXIST;
559 obj_info = evas_object_data_get(edje, "obj_info");
561 ErrPrint("Object info is not available\n");
562 return DBOX_STATUS_ERROR_FAULT;
565 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
569 ao = evas_object_data_get(edje_part, "ao");
571 if (text && strlen(text)) {
572 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
573 DbgPrint("Access info is updated: %s [%s], %p\n", part, text, ao);
574 update_focus_chain(handle, ao);
578 * Delete clalback will be called
580 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
581 elm_access_object_unregister(ao);
583 } else if (text && strlen(text)) {
584 ao = elm_access_object_register(edje_part, handle->parent);
586 ErrPrint("Unable to register an access object(%s)\n", part);
588 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
590 evas_object_data_set(edje_part, "ao", ao);
591 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
592 elm_access_activate_cb_set(ao, activate_cb, NULL);
593 DbgPrint("[%s] Register access info: (%s) to, %p (%p)\n", part, text, handle->parent, ao);
597 ErrPrint("[%s] is not exists\n", part);
600 return DBOX_STATUS_ERROR_NONE;
603 PUBLIC int script_operate_access(void *_h, const char *id, const char *part, const char *operation, const char *option)
605 struct info *handle = _h;
607 struct obj_info *obj_info;
608 Elm_Access_Action_Info action_info;
611 if (!operation || !strlen(operation)) {
612 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
615 edje = find_edje(handle, id);
617 ErrPrint("No such object: %s\n", id);
618 return DBOX_STATUS_ERROR_NOT_EXIST;
621 obj_info = evas_object_data_get(edje, "obj_info");
623 ErrPrint("Object info is not available\n");
624 return DBOX_STATUS_ERROR_FAULT;
627 memset(&action_info, 0, sizeof(action_info));
629 /* OPERATION is defined in liblivebox package */
630 if (!strcasecmp(operation, "set,hl")) {
632 Evas_Object *edje_part;
638 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
640 ErrPrint("Invalid part: %s\n", part);
644 evas_object_geometry_get(edje_part, &x, &y, &w, &h);
646 action_info.x = x + w / 2;
647 action_info.y = x + h / 2;
648 } else if (option && sscanf(option, "%dx%d", &action_info.x, &action_info.y) == 2) {
650 ErrPrint("Insufficient info for HL\n");
654 DbgPrint("TXxTY: %dx%d\n", action_info.x, action_info.y);
655 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT, &action_info);
656 if (ret == EINA_FALSE) {
657 ErrPrint("Action error\n");
659 } else if (!strcasecmp(operation, "unset,hl")) {
660 ret = elm_access_action(edje, ELM_ACCESS_ACTION_UNHIGHLIGHT, &action_info);
661 if (ret == EINA_FALSE) {
662 ErrPrint("Action error\n");
664 } else if (!strcasecmp(operation, "next,hl")) {
665 action_info.highlight_cycle = (!!option) && (!!strcasecmp(option, "no,cycle"));
667 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_NEXT, &action_info);
668 if (ret == EINA_FALSE) {
669 ErrPrint("Action error\n");
671 } else if (!strcasecmp(operation, "prev,hl")) {
672 action_info.highlight_cycle = EINA_TRUE;
673 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_PREV, &action_info);
674 if (ret == EINA_FALSE) {
675 ErrPrint("Action error\n");
677 } else if (!strcasecmp(operation, "reset,focus")) {
678 DbgPrint("Reset Focus\n");
679 elm_object_focus_custom_chain_set(edje, NULL);
683 return DBOX_STATUS_ERROR_NONE;
686 static inline void apply_shadow_effect(struct image_option *img_opt, Evas_Object *img)
688 ea_effect_h *ea_effect;
690 if (!img_opt->shadow.enabled) {
694 ea_effect = ea_image_effect_create();
699 // -90, 2, 4, 0x99000000
700 ea_image_effect_add_outer_shadow(ea_effect, img_opt->shadow.angle, img_opt->shadow.offset, img_opt->shadow.softness, img_opt->shadow.color);
701 ea_object_image_effect_set(img, ea_effect);
703 ea_image_effect_destroy(ea_effect);
706 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)
710 Evas_Object *src_img;
716 ee = ecore_evas_buffer_new(part_w, part_h);
718 ErrPrint("Failed to create a EE\n");
722 ecore_evas_alpha_set(ee, EINA_TRUE);
724 e = ecore_evas_get(ee);
726 ErrPrint("Unable to get Evas\n");
731 src_img = evas_object_image_filled_add(e);
733 ErrPrint("Unable to add an image\n");
738 evas_object_image_alpha_set(src_img, EINA_TRUE);
739 evas_object_image_colorspace_set(src_img, EVAS_COLORSPACE_ARGB8888);
740 evas_object_image_smooth_scale_set(src_img, EINA_TRUE);
741 evas_object_image_load_orientation_set(src_img, img_opt->orient);
742 evas_object_image_file_set(src_img, path, NULL);
743 err = evas_object_image_load_error_get(src_img);
744 if (err != EVAS_LOAD_ERROR_NONE) {
745 ErrPrint("Load error: %s\n", evas_load_error_str(err));
746 evas_object_del(src_img);
750 evas_object_image_size_get(src_img, &rw, &rh);
751 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
752 evas_object_resize(src_img, w, h);
753 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
754 evas_object_show(src_img);
756 data = ecore_evas_buffer_pixels_get(ee);
758 ErrPrint("Unable to get pixels\n");
759 evas_object_del(src_img);
764 e = evas_object_evas_get(img);
765 _img = evas_object_image_filled_add(e);
767 evas_object_del(src_img);
772 evas_object_image_colorspace_set(_img, EVAS_COLORSPACE_ARGB8888);
773 evas_object_image_smooth_scale_set(_img, EINA_TRUE);
774 evas_object_image_alpha_set(_img, EINA_TRUE);
775 evas_object_image_data_set(_img, NULL);
776 evas_object_image_size_set(_img, part_w, part_h);
777 evas_object_resize(_img, part_w, part_h);
778 evas_object_image_data_copy_set(_img, (void *)data);
779 evas_object_image_fill_set(_img, 0, 0, part_w, part_h);
780 evas_object_image_data_update_add(_img, 0, 0, part_w, part_h);
782 evas_object_del(src_img);
785 evas_object_del(img);
789 PUBLIC int script_update_image(void *_h, const char *id, const char *part, const char *path, const char *option)
791 struct info *handle = _h;
796 struct obj_info *obj_info;
797 struct image_option img_opt = {
800 .fill = FILL_DISABLE,
808 edje = find_edje(handle, id);
810 ErrPrint("No such object: %s\n", id);
811 return DBOX_STATUS_ERROR_NOT_EXIST;
814 obj_info = evas_object_data_get(edje, "obj_info");
816 ErrPrint("Object info is not available\n");
817 return DBOX_STATUS_ERROR_FAULT;
820 img = elm_object_part_content_unset(edje, part);
822 DbgPrint("delete object %s %p\n", part, img);
823 evas_object_del(img);
826 if (!path || !strlen(path) || access(path, R_OK) != 0) {
827 DbgPrint("SKIP - Path: [%s]\n", path);
828 return DBOX_STATUS_ERROR_NONE;
831 img = evas_object_image_add(handle->e);
833 ErrPrint("Failed to add an image object\n");
834 return DBOX_STATUS_ERROR_FAULT;
837 evas_object_image_preload(img, EINA_FALSE);
838 parse_image_option(option, &img_opt);
839 evas_object_image_load_orientation_set(img, img_opt.orient);
841 evas_object_image_file_set(img, path, NULL);
842 err = evas_object_image_load_error_get(img);
843 if (err != EVAS_LOAD_ERROR_NONE) {
844 ErrPrint("Load error: %s\n", evas_load_error_str(err));
845 evas_object_del(img);
846 return DBOX_STATUS_ERROR_IO_ERROR;
849 apply_shadow_effect(&img_opt, img);
851 evas_object_image_size_get(img, &w, &h);
852 if (img_opt.aspect) {
853 if (img_opt.fill == FILL_OVER_SIZE) {
857 if (img_opt.width >= 0 && img_opt.height >= 0) {
858 part_w = img_opt.width * elm_config_scale_get();
859 part_h = img_opt.height * elm_config_scale_get();
863 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
865 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
867 if (part_w > w || part_h > h) {
871 fw = (double)part_w / (double)w;
872 fh = (double)part_h / (double)h;
883 if (!part_w || !part_h || !w || !h) {
884 evas_object_del(img);
885 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
888 img = crop_image(img, path, part_w, part_h, w, h, &img_opt);
889 } else if (img_opt.fill == FILL_IN_SIZE) {
893 if (img_opt.width >= 0 && img_opt.height >= 0) {
894 part_w = img_opt.width * elm_config_scale_get();
895 part_h = img_opt.height * elm_config_scale_get();
899 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
901 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
903 if (w > part_w || h > part_h) {
907 fw = (double)part_w / (double)w;
908 fh = (double)part_h / (double)h;
919 if (!part_w || !part_h || !w || !h) {
920 evas_object_del(img);
921 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
924 img = crop_image(img, path, part_w, part_h, w, h, &img_opt);
925 } else if (img_opt.fill == FILL_FIT_SIZE) {
931 if (img_opt.width >= 0 && img_opt.height >= 0) {
932 part_w = img_opt.width * elm_config_scale_get();
933 part_h = img_opt.height * elm_config_scale_get();
937 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
939 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
941 fw = (double)part_w / (double)w;
942 fh = (double)part_h / (double)h;
952 if (!part_w || !part_h || !w || !h) {
953 evas_object_del(img);
954 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
957 img = crop_image(img, path, part_w, part_h, w, h, &img_opt);
959 evas_object_image_fill_set(img, 0, 0, w, h);
960 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
961 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
964 apply_shadow_effect(&img_opt, img);
966 if (img_opt.width >= 0 && img_opt.height >= 0) {
969 DbgPrint("Using given image size: %dx%d\n", w, h);
972 evas_object_image_fill_set(img, 0, 0, w, h);
973 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
974 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
975 evas_object_image_filled_set(img, EINA_TRUE);
981 * object will be shown by below statement automatically
983 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
984 elm_object_part_content_set(edje, part, img);
988 * This object is not registered as an access object.
989 * So the developer should add it to access list manually, using DESC_ACCESS block.
991 return DBOX_STATUS_ERROR_NONE;
994 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
996 struct info *handle = data;
1008 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1009 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
1013 sx = (double)px / (double)w;
1014 ex = (double)(px + pw) / (double)w;
1019 sy = (double)py / (double)h;
1020 ey = (double)(py + ph) / (double)h;
1023 DbgPrint("[%s] [%s]\n", emission, source);
1025 script_buffer_signal_emit(handle->buffer_handle, source, emission, sx, sy, ex, ey);
1028 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
1030 struct info *handle = _info;
1031 struct obj_info *obj_info;
1032 struct obj_info *parent_obj_info;
1033 struct child *child;
1035 handle->obj_list = eina_list_remove(handle->obj_list, obj);
1037 obj_info = evas_object_data_get(obj, "obj_info");
1039 ErrPrint("Object info is not valid\n");
1043 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
1045 DbgPrint("delete object %s %p\n", obj_info->id, obj);
1046 if (obj_info->parent == obj) {
1047 DbgPrint("Parent EDJE\n");
1048 } else if (obj_info->parent) {
1052 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
1053 if (parent_obj_info) {
1054 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
1055 if (child->obj != obj) {
1061 * If this code is executed,
1062 * The parent is not deleted by desc, this object is deleted by itself.
1063 * It is not possible, but we care it.
1065 DbgPrint("Children is updated: %s (%s)\n", child->part, parent_obj_info->id);
1066 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
1072 if (!parent_obj_info->children && parent_obj_info->delete_me == 1) {
1073 DbgPrint("Children is cleared: %s (by a child)\n", parent_obj_info->id);
1074 evas_object_data_del(obj_info->parent, "obj_info");
1075 free(parent_obj_info->id);
1076 free(parent_obj_info);
1080 DbgPrint("obj_info->parent is NULL (skipped)\n");
1083 if (!obj_info->children) {
1084 DbgPrint("Children is cleared: %s\n", obj_info->id);
1085 evas_object_data_del(obj, "obj_info");
1089 DbgPrint("Children is remained: %s\n", obj_info->id);
1090 obj_info->delete_me = 1;
1094 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
1096 Evas_Object *o, *ho;
1098 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
1103 ho = evas_object_data_get(o, "_elm_access_target");
1108 DBOX_ACCESS_HIGHLIGHT 0
1109 DBOX_ACCESS_HIGHLIGHT_NEXT 1
1110 DBOX_ACCESS_HIGHLIGHT_PREV 2
1111 DBOX_ACCESS_ACTIVATE 3
1112 DBOX_ACCESS_ACTION 4
1113 DBOX_ACCESS_SCROLL 5
1115 PUBLIC int script_feed_event(void *h, int event_type, int x, int y, int type, unsigned int keycode, double timestamp)
1117 struct info *handle = h;
1119 struct obj_info *obj_info;
1120 int ret = DBOX_STATUS_ERROR_NONE;
1122 edje = find_edje(handle, NULL); /*!< Get the base layout */
1124 ErrPrint("Base layout is not exist\n");
1125 return DBOX_STATUS_ERROR_NOT_EXIST;
1128 obj_info = evas_object_data_get(edje, "obj_info");
1130 ErrPrint("Object info is not valid\n");
1131 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1134 if (event_type & DBOX_SCRIPT_ACCESS_EVENT) {
1135 Elm_Access_Action_Info info;
1136 Elm_Access_Action_Type action;
1138 memset(&info, 0, sizeof(info));
1140 if ((event_type & DBOX_SCRIPT_ACCESS_HIGHLIGHT) == DBOX_SCRIPT_ACCESS_HIGHLIGHT) {
1141 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1144 ret = elm_access_action(edje, action, &info);
1145 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1146 if (ret == EINA_TRUE) {
1147 if (!get_highlighted_object(edje)) {
1148 ErrPrint("Highlighted object is not found\n");
1149 ret = DBOX_ACCESS_STATUS_ERROR;
1151 DbgPrint("Highlighted object is found\n");
1152 ret = DBOX_ACCESS_STATUS_DONE;
1155 ErrPrint("Action error\n");
1156 ret = DBOX_ACCESS_STATUS_ERROR;
1158 } else if ((event_type & DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1159 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1160 info.highlight_cycle = EINA_FALSE;
1161 ret = elm_access_action(edje, action, &info);
1162 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1163 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_LAST : DBOX_ACCESS_STATUS_DONE;
1164 } else if ((event_type & DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV) == DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1165 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1166 info.highlight_cycle = EINA_FALSE;
1167 ret = elm_access_action(edje, action, &info);
1168 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1169 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_FIRST : DBOX_ACCESS_STATUS_DONE;
1170 } else if ((event_type & DBOX_SCRIPT_ACCESS_ACTIVATE) == DBOX_SCRIPT_ACCESS_ACTIVATE) {
1171 action = ELM_ACCESS_ACTION_ACTIVATE;
1172 ret = elm_access_action(edje, action, &info);
1173 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1174 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1175 } else if ((event_type & DBOX_SCRIPT_ACCESS_ACTION) == DBOX_SCRIPT_ACCESS_ACTION) {
1177 case ACCESS_TYPE_UP:
1178 action = ELM_ACCESS_ACTION_UP;
1179 ret = elm_access_action(edje, action, &info);
1180 DbgPrint("ACCESS_ACTION(%d), returns %d\n", type, ret);
1181 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1183 case ACCESS_TYPE_DOWN:
1184 action = ELM_ACCESS_ACTION_DOWN;
1185 ret = elm_access_action(edje, action, &info);
1186 DbgPrint("ACCESS_ACTION(%d), returns %d\n", type, ret);
1187 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1190 ErrPrint("Invalid access event\n");
1191 ret = DBOX_ACCESS_STATUS_ERROR;
1194 } else if ((event_type & DBOX_SCRIPT_ACCESS_SCROLL) == DBOX_SCRIPT_ACCESS_SCROLL) {
1195 action = ELM_ACCESS_ACTION_SCROLL;
1199 case ACCESS_TYPE_DOWN:
1200 info.mouse_type = 0;
1201 ret = elm_access_action(edje, action, &info);
1202 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1203 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1205 case ACCESS_TYPE_MOVE:
1206 info.mouse_type = 1;
1207 ret = elm_access_action(edje, action, &info);
1208 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1209 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1211 case ACCESS_TYPE_UP:
1212 info.mouse_type = 2;
1213 ret = elm_access_action(edje, action, &info);
1214 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1215 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1218 ret = DBOX_ACCESS_STATUS_ERROR;
1221 } else if ((event_type & DBOX_SCRIPT_ACCESS_UNHIGHLIGHT) == DBOX_SCRIPT_ACCESS_UNHIGHLIGHT) {
1222 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1223 ret = elm_access_action(edje, action, &info);
1224 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1225 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1226 } else if ((event_type & DBOX_SCRIPT_ACCESS_VALUE_CHANGE) == DBOX_SCRIPT_ACCESS_VALUE_CHANGE) {
1227 action = ELM_ACCESS_ACTION_VALUE_CHANGE;
1228 info.mouse_type = type;
1231 ret = elm_access_action(edje, action, &info);
1232 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1233 } else if ((event_type & DBOX_SCRIPT_ACCESS_MOUSE) == DBOX_SCRIPT_ACCESS_MOUSE) {
1234 action = ELM_ACCESS_ACTION_MOUSE;
1235 info.mouse_type = type;
1238 ret = elm_access_action(edje, action, &info);
1239 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1240 } else if ((event_type & DBOX_SCRIPT_ACCESS_BACK) == DBOX_SCRIPT_ACCESS_BACK) {
1241 action = ELM_ACCESS_ACTION_BACK;
1242 info.mouse_type = type;
1245 ret = elm_access_action(edje, action, &info);
1246 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1247 } else if ((event_type & DBOX_SCRIPT_ACCESS_OVER) == DBOX_SCRIPT_ACCESS_OVER) {
1248 action = ELM_ACCESS_ACTION_OVER;
1249 info.mouse_type = type;
1252 ret = elm_access_action(edje, action, &info);
1253 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1254 } else if ((event_type & DBOX_SCRIPT_ACCESS_READ) == DBOX_SCRIPT_ACCESS_READ) {
1255 action = ELM_ACCESS_ACTION_READ;
1256 info.mouse_type = type;
1259 ret = elm_access_action(edje, action, &info);
1260 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1261 } else if ((event_type & DBOX_SCRIPT_ACCESS_ENABLE) == DBOX_SCRIPT_ACCESS_ENABLE) {
1262 action = ELM_ACCESS_ACTION_ENABLE;
1263 info.mouse_type = type;
1266 ret = elm_access_action(edje, action, &info);
1267 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1268 } else if ((event_type & DBOX_SCRIPT_ACCESS_DISABLE) == DBOX_SCRIPT_ACCESS_DISABLE) {
1269 action = ELM_ACCESS_ACTION_ENABLE;
1270 info.mouse_type = type;
1273 ret = elm_access_action(edje, action, &info);
1274 ret = (ret == EINA_FALSE) ? DBOX_ACCESS_STATUS_ERROR : DBOX_ACCESS_STATUS_DONE;
1276 DbgPrint("Invalid event\n");
1277 ret = DBOX_ACCESS_STATUS_ERROR;
1280 } else if (event_type & DBOX_SCRIPT_MOUSE_EVENT) {
1281 double cur_timestamp;
1284 #if defined(_USE_ECORE_TIME_GET)
1285 cur_timestamp = ecore_time_get();
1288 if (gettimeofday(&tv, NULL) < 0) {
1289 ErrPrint("Failed to get time\n");
1290 cur_timestamp = 0.0f;
1292 cur_timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1295 if (cur_timestamp - timestamp > 0.1f && handle->is_mouse_down == 0) {
1296 DbgPrint("Discard lazy event : %lf\n", cur_timestamp - timestamp);
1297 return DBOX_STATUS_ERROR_NONE;
1300 switch (event_type) {
1301 case DBOX_SCRIPT_MOUSE_DOWN:
1302 if (handle->is_mouse_down == 0) {
1303 flags = evas_event_default_flags_get(handle->e);
1304 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
1305 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
1306 evas_event_default_flags_set(handle->e, flags);
1308 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1309 evas_event_feed_mouse_down(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1310 handle->is_mouse_down = 1;
1313 case DBOX_SCRIPT_MOUSE_MOVE:
1314 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1316 case DBOX_SCRIPT_MOUSE_UP:
1317 if (handle->is_mouse_down == 1) {
1318 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1319 evas_event_feed_mouse_up(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1320 handle->is_mouse_down = 0;
1323 case DBOX_SCRIPT_MOUSE_IN:
1324 evas_event_feed_mouse_in(handle->e, timestamp * 1000, NULL);
1326 case DBOX_SCRIPT_MOUSE_OUT:
1327 evas_event_feed_mouse_out(handle->e, timestamp * 1000, NULL);
1329 case DBOX_SCRIPT_MOUSE_ON_SCROLL:
1330 flags = evas_event_default_flags_get(handle->e);
1331 flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1332 evas_event_default_flags_set(handle->e, flags);
1334 case DBOX_SCRIPT_MOUSE_ON_HOLD: // To cancel the clicked, enable this
1335 flags = evas_event_default_flags_get(handle->e);
1336 flags |= EVAS_EVENT_FLAG_ON_HOLD;
1337 evas_event_default_flags_set(handle->e, flags);
1339 case DBOX_SCRIPT_MOUSE_OFF_SCROLL:
1340 flags = evas_event_default_flags_get(handle->e);
1341 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
1342 evas_event_default_flags_set(handle->e, flags);
1344 case DBOX_SCRIPT_MOUSE_OFF_HOLD:
1345 flags = evas_event_default_flags_get(handle->e);
1346 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
1347 evas_event_default_flags_set(handle->e, flags);
1350 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1352 } else if (event_type & DBOX_SCRIPT_KEY_EVENT) {
1353 const char *keyname = "";
1354 const char *key = "";
1355 const char *string = "";
1356 const char *compose = "";
1358 switch (event_type) {
1359 case DBOX_SCRIPT_KEY_DOWN:
1360 evas_event_feed_key_down(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1361 ret = DBOX_KEY_STATUS_DONE;
1364 * If the keyname == RIGHT, Need to check that
1365 * Does it reach to the last focusable object?
1369 * if (REACH to the LAST) {
1370 * ret = DBOX_KEY_STATUS_LAST;
1372 * ret = DBOX_KEY_STATUS_DONE;
1375 * if (REACH to the FIRST) {
1376 * ret = DBOX_KEY_STATUS_FIRST;
1378 * ret = DBOX_KEY_STATUS_DONE;
1382 case DBOX_SCRIPT_KEY_UP:
1383 evas_event_feed_key_up(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1384 ret = DBOX_KEY_STATUS_DONE;
1386 case DBOX_SCRIPT_KEY_FOCUS_IN:
1387 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_IN, NULL);
1388 ret = DBOX_KEY_STATUS_DONE;
1390 case DBOX_SCRIPT_KEY_FOCUS_OUT:
1391 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_OUT, NULL);
1392 ret = DBOX_KEY_STATUS_DONE;
1395 DbgPrint("Event is not implemented\n");
1396 ret = DBOX_KEY_STATUS_ERROR;
1404 PUBLIC int script_update_script(void *h, const char *src_id, const char *target_id, const char *part, const char *path, const char *group)
1406 struct info *handle = h;
1409 struct obj_info *obj_info;
1410 struct child *child;
1411 char _target_id[32];
1413 edje = find_edje(handle, src_id);
1415 ErrPrint("Edje is not exists (%s)\n", src_id);
1416 return DBOX_STATUS_ERROR_NOT_EXIST;
1419 obj_info = evas_object_data_get(edje, "obj_info");
1421 ErrPrint("Object info is not valid\n");
1422 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1425 obj = elm_object_part_content_unset(edje, part);
1427 DbgPrint("delete object %s %p\n", part, obj);
1430 * This will call the edje_del_cb.
1431 * It will delete all access objects
1433 evas_object_del(obj);
1436 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1437 DbgPrint("SKIP - Path: [%s]\n", path);
1438 return DBOX_STATUS_ERROR_NONE;
1442 if (find_edje(handle, part)) {
1446 #if defined(_USE_ECORE_TIME_GET)
1447 timestamp = ecore_time_get();
1450 if (gettimeofday(&tv, NULL) < 0) {
1451 static int local_idx = 0;
1452 timestamp = (double)(local_idx++);
1454 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1458 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1459 } while (find_edje(handle, _target_id));
1461 target_id = _target_id;
1466 DbgPrint("Anonymouse target id: %s\n", target_id);
1469 obj = elm_layout_add(edje);
1471 ErrPrint("Failed to add a new edje object\n");
1472 return DBOX_STATUS_ERROR_FAULT;
1475 edje_object_scale_set(elm_layout_edje_get(obj), elm_config_scale_get());
1477 if (!elm_layout_file_set(obj, path, group)) {
1479 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1480 if (err != EDJE_LOAD_ERROR_NONE) {
1481 ErrPrint("Could not load %s from %s: %s\n", group, path, edje_load_error_str(err));
1483 evas_object_del(obj);
1484 return DBOX_STATUS_ERROR_IO_ERROR;
1487 evas_object_show(obj);
1489 obj_info = calloc(1, sizeof(*obj_info));
1491 ErrPrint("Failed to add a obj_info\n");
1492 evas_object_del(obj);
1493 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1496 obj_info->id = strdup(target_id);
1497 if (!obj_info->id) {
1498 ErrPrint("Failed to add a obj_info\n");
1500 evas_object_del(obj);
1501 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1504 obj_info->parent = edje;
1506 child = malloc(sizeof(*child));
1508 ErrPrint("Error: %s\n", strerror(errno));
1511 evas_object_del(obj);
1512 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1515 child->part = strdup(part);
1517 ErrPrint("Error: %s\n", strerror(errno));
1521 evas_object_del(obj);
1522 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1527 evas_object_data_set(obj, "obj_info", obj_info);
1528 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1529 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1530 handle->obj_list = eina_list_append(handle->obj_list, obj);
1532 DbgPrint("%s part swallow edje %p\n", part, obj);
1533 elm_object_part_content_set(edje, part, obj);
1535 obj_info = evas_object_data_get(edje, "obj_info");
1536 obj_info->children = eina_list_append(obj_info->children, child);
1538 return DBOX_STATUS_ERROR_NONE;
1541 PUBLIC int script_update_signal(void *h, const char *id, const char *part, const char *signal)
1543 struct info *handle = h;
1546 edje = find_edje(handle, id);
1548 return DBOX_STATUS_ERROR_NOT_EXIST;
1551 elm_object_signal_emit(edje, signal, part);
1552 return DBOX_STATUS_ERROR_NONE;
1555 PUBLIC int script_update_drag(void *h, const char *id, const char *part, double x, double y)
1557 struct info *handle = h;
1560 edje = find_edje(handle, id);
1562 return DBOX_STATUS_ERROR_NOT_EXIST;
1565 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1566 return DBOX_STATUS_ERROR_NONE;
1569 PUBLIC int script_update_size(void *han, const char *id, int w, int h)
1571 struct info *handle = han;
1574 edje = find_edje(handle, id);
1576 return DBOX_STATUS_ERROR_NOT_EXIST;
1582 * Need to resize the canvas too
1584 ecore_evas_resize(handle->ee, w, h);
1587 DbgPrint("Resize object to %dx%d\n", w, h);
1588 evas_object_resize(edje, w, h);
1589 return DBOX_STATUS_ERROR_NONE;
1592 PUBLIC int script_update_category(void *h, const char *id, const char *category)
1594 struct info *handle = h;
1596 if (handle->category) {
1597 free(handle->category);
1598 handle->category = NULL;
1602 return DBOX_STATUS_ERROR_NONE;
1605 handle->category = strdup(category);
1606 if (!handle->category) {
1607 ErrPrint("Error: %s\n", strerror(errno));
1608 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1611 return DBOX_STATUS_ERROR_NONE;
1614 PUBLIC void *script_create(void *buffer_handle, const char *file, const char *group)
1616 struct info *handle;
1618 handle = calloc(1, sizeof(*handle));
1620 ErrPrint("Error: %s\n", strerror(errno));
1624 handle->file = strdup(file);
1625 if (!handle->file) {
1626 ErrPrint("Error: %s\n", strerror(errno));
1631 handle->group = strdup(group);
1632 if (!handle->group) {
1633 ErrPrint("Error: %s\n", strerror(errno));
1639 handle->buffer_handle = buffer_handle;
1641 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1646 PUBLIC int script_destroy(void *_handle)
1648 struct info *handle;
1653 if (!eina_list_data_find(s_info.handle_list, handle)) {
1654 DbgPrint("Not found (already deleted?)\n");
1655 return DBOX_STATUS_ERROR_NOT_EXIST;
1658 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1660 edje = eina_list_nth(handle->obj_list, 0);
1662 evas_object_del(edje);
1665 DbgPrint("Release handle\n");
1666 free(handle->category);
1668 free(handle->group);
1670 return DBOX_STATUS_ERROR_NONE;
1673 static void sw_render_pre_cb(void *data, Evas *e, void *event_info)
1675 struct info *handle = data;
1677 if (handle->render_pre) {
1678 handle->render_pre(handle->buffer_handle, handle->render_data);
1681 script_buffer_lock(handle->buffer_handle);
1683 if (s_info.premultiplied) {
1687 script_buffer_get_size(handle->buffer_handle, &w, &h);
1688 evas_damage_rectangle_add(handle->e, 0, 0, w, h);
1692 static void sw_render_post_cb(void *data, Evas *e, void *event_info)
1694 struct info *handle = data;
1696 if (s_info.premultiplied) {
1700 // Get a pointer of a buffer of the virtual canvas
1701 canvas = (void *)ecore_evas_buffer_pixels_get(handle->ee);
1703 ErrPrint("Failed to get pixel canvas\n");
1707 ecore_evas_geometry_get(handle->ee, &x, &y, &w, &h);
1708 evas_data_argb_unpremul(canvas, w * h);
1711 script_buffer_unlock(handle->buffer_handle);
1713 if (handle->render_post) {
1714 handle->render_post(handle->buffer_handle, handle->render_data);
1718 static void render_pre_cb(void *data, Evas *e, void *event_info)
1720 struct info *handle = data;
1723 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1725 ErrPrint("Acquired buffer is NULL\n");
1728 sw_render_pre_cb(data, handle->e, event_info);
1731 static void render_post_cb(void *data, Evas *e, void *event_info)
1733 struct info *handle = data;
1736 sw_render_post_cb(data, handle->e, event_info);
1737 canvas = script_buffer_pixmap_buffer(handle->buffer_handle);
1739 ErrPrint("Acquired buffer is NULL\n");
1741 script_buffer_pixmap_release_buffer(canvas);
1745 static void *alloc_fb(void *data, int size)
1747 struct info *handle = data;
1749 if (script_buffer_load(handle->buffer_handle) < 0) {
1750 ErrPrint("Failed to load buffer handler\n");
1754 return script_buffer_fb(handle->buffer_handle);
1757 static void *alloc_with_stride_fb(void *data, int size, int *stride, int *bpp)
1760 struct info *handle = data;
1764 canvas = alloc_fb(data, size);
1766 ErrPrint("Unable to allocate canvas buffer\n");
1769 _bpp = script_buffer_pixels(handle->buffer_handle);
1771 ErrPrint("Failed to get pixel size, fallback to 4\n");
1775 _stride = script_buffer_stride(handle->buffer_handle);
1779 ecore_evas_geometry_get(handle->ee, NULL, NULL, &w, NULL);
1782 ErrPrint("Failed to get stride info, fallback to %d\n", _stride);
1791 static void free_fb(void *data, void *ptr)
1793 struct info *handle = data;
1795 if (!handle->buffer_handle) {
1796 ErrPrint("Buffer is not valid (maybe already released)\n");
1800 if (script_buffer_fb(handle->buffer_handle) != ptr) {
1801 ErrPrint("Buffer pointer is not matched\n");
1804 (void)script_buffer_unload(handle->buffer_handle);
1807 static int destroy_ecore_evas(struct info *handle)
1810 return DBOX_STATUS_ERROR_NONE;
1812 ecore_evas_free(handle->ee);
1815 return DBOX_STATUS_ERROR_NONE;
1818 static int create_ecore_evas(struct info *handle, int *w, int *h)
1820 script_buffer_get_size(handle->buffer_handle, w, h);
1821 if (*w == 0 && *h == 0) {
1822 ErrPrint("ZERO size FB accessed\n");
1823 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
1830 ecore_evas_geometry_get(handle->ee, NULL, NULL, &ow, &oh);
1831 if (*w != ow || *h != oh) {
1832 ErrPrint("EE exists, But different size - buffer_handle(%dx%d) -> ee(%dx%d)\n", ow, oh, *w, *h);
1833 ecore_evas_resize(handle->ee, *w, *h);
1836 return DBOX_STATUS_ERROR_NONE;
1839 if (!script_buffer_auto_align() && s_info.alloc_canvas_with_stride) {
1840 handle->ee = s_info.alloc_canvas_with_stride(*w, *h, alloc_with_stride_fb, free_fb, handle);
1841 } else if (s_info.alloc_canvas) {
1842 handle->ee = s_info.alloc_canvas(*w, *h, alloc_fb, free_fb, handle);
1844 ErrPrint("Failed to allocate canvas\n");
1845 return DBOX_STATUS_ERROR_FAULT;
1849 ErrPrint("Failed to create a buffer\n");
1850 return DBOX_STATUS_ERROR_FAULT;
1853 handle->e = ecore_evas_get(handle->ee);
1855 ErrPrint("Failed to get an Evas\n");
1856 ecore_evas_free(handle->ee);
1858 return DBOX_STATUS_ERROR_FAULT;
1861 if (script_buffer_type(handle->buffer_handle) == BUFFER_TYPE_PIXMAP) {
1864 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb, handle);
1865 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, render_post_cb, handle);
1869 * ecore_evas_alpha_set tries to access the canvas buffer.
1870 * Without any render_pre/render_post callback.
1872 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1874 ErrPrint("Acquired buffer is NULL\n");
1876 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1877 script_buffer_pixmap_release_buffer(canvas);
1880 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, sw_render_pre_cb, handle);
1881 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, sw_render_post_cb, handle);
1882 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1885 ecore_evas_manual_render_set(handle->ee, EINA_FALSE);
1886 ecore_evas_resize(handle->ee, *w, *h);
1887 ecore_evas_show(handle->ee);
1888 ecore_evas_activate(handle->ee);
1890 return DBOX_STATUS_ERROR_NONE;
1893 PUBLIC int script_load(void *_handle, int (*render_pre)(void *buffer_handle, void *data), int (*render_post)(void *render_handle, void *data), void *data)
1895 struct info *handle;
1897 struct obj_info *obj_info;
1904 * Create "Ecore_Evas *"
1909 handle->render_pre = render_pre;
1910 handle->render_post = render_post;
1911 handle->render_data = data;
1913 ret = create_ecore_evas(handle, &w, &h);
1918 obj_info = calloc(1, sizeof(*obj_info));
1920 ErrPrint("Heap: %s\n", strerror(errno));
1921 destroy_ecore_evas(handle);
1922 return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1925 obj_info->parent = evas_object_rectangle_add(handle->e);
1926 if (!obj_info->parent) {
1927 ErrPrint("Unable to create a parent box\n");
1929 destroy_ecore_evas(handle);
1930 return DBOX_STATUS_ERROR_FAULT;
1933 edje = elm_layout_add(obj_info->parent);
1935 ErrPrint("Failed to create an edje object\n");
1936 evas_object_del(obj_info->parent);
1938 destroy_ecore_evas(handle);
1939 return DBOX_STATUS_ERROR_FAULT;
1942 edje_object_scale_set(elm_layout_edje_get(edje), elm_config_scale_get());
1944 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1947 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1948 if (err != EDJE_LOAD_ERROR_NONE) {
1949 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, edje_load_error_str(err));
1951 evas_object_del(edje);
1952 evas_object_del(obj_info->parent);
1954 destroy_ecore_evas(handle);
1955 return DBOX_STATUS_ERROR_IO_ERROR;
1958 handle->parent = edje;
1960 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1961 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1962 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1963 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1964 evas_object_resize(edje, w, h);
1965 evas_object_show(edje);
1966 evas_object_data_set(edje, "obj_info", obj_info);
1968 handle->obj_list = eina_list_append(handle->obj_list, edje);
1969 return DBOX_STATUS_ERROR_NONE;
1972 PUBLIC int script_unload(void *_handle)
1974 struct info *handle;
1978 * Destroy "Ecore_Evas *"
1983 if (handle->parent) {
1984 DbgPrint("Delete parent box\n");
1985 evas_object_del(handle->parent);
1988 (void)destroy_ecore_evas(handle);
1989 return DBOX_STATUS_ERROR_NONE;
1992 static void access_cb(keynode_t *node, void *user_data)
1997 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1998 ErrPrint("Idle lock state is not valid\n");
1999 state = 0; /* DISABLED */
2002 state = vconf_keynode_get_bool(node);
2005 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
2006 elm_config_access_set(state);
2007 s_info.access_on = state;
2010 static void update_font_cb(void *data)
2012 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
2013 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
2016 static void font_changed_cb(keynode_t *node, void *user_data)
2022 if (s_info.font_name) {
2023 font_name = vconf_get_str("db/setting/accessibility/font_name");
2025 ErrPrint("Invalid font name (NULL)\n");
2029 if (!strcmp(s_info.font_name, font_name)) {
2030 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
2035 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
2036 free(s_info.font_name);
2041 * Get the first font name using system_settings API.
2044 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
2045 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
2046 ErrPrint("System setting get: %d, font_name[%p]\n", ret, font_name);
2051 s_info.font_name = font_name;
2052 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
2056 * Try to update all liveboxes
2058 update_font_cb(NULL);
2061 static inline int convert_font_size(int size)
2064 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
2067 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
2070 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
2073 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
2076 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
2084 DbgPrint("Return size: %d\n", size);
2088 static void font_size_cb(system_settings_key_e key, void *user_data)
2092 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE) {
2096 size = convert_font_size(size);
2098 if (size == s_info.font_size) {
2099 DbgPrint("Font size is not changed\n");
2103 s_info.font_size = size;
2104 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
2107 PUBLIC int script_init(double scale, int premultiplied)
2115 s_info.premultiplied = premultiplied;
2117 /* ecore is already initialized */
2119 elm_config_scale_set(scale);
2120 DbgPrint("Scale is updated: %lf\n", scale);
2122 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
2124 DbgPrint("TTS changed: %d\n", ret);
2127 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
2128 DbgPrint("System font is changed: %d\n", ret);
2130 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
2131 DbgPrint("System font size is changed: %d\n", ret);
2133 access_cb(NULL, NULL);
2134 font_changed_cb(NULL, NULL);
2135 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
2137 s_info.alloc_canvas_with_stride = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_with_stride_new");
2138 if (!s_info.alloc_canvas_with_stride) {
2139 DbgPrint("Fallback to allocfunc_new\n");
2142 s_info.alloc_canvas = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_new");
2143 if (!s_info.alloc_canvas) {
2144 ErrPrint("No way to allocate canvas\n");
2147 return DBOX_STATUS_ERROR_NONE;
2150 PUBLIC int script_fini(void)
2155 struct info *handle;
2157 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
2158 script_destroy(handle);
2161 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
2163 DbgPrint("Unset font size change event callback: %d\n", ret);
2166 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
2168 DbgPrint("Unset font name change event callback: %d\n", ret);
2171 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
2173 DbgPrint("Unset tts: %d\n", ret);
2178 free(s_info.font_name);
2179 s_info.font_name = NULL;
2180 return DBOX_STATUS_ERROR_NONE;