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 <widget_errno.h>
40 #include <widget_service.h>
41 #include <widget_service_internal.h>
42 #include <widget_script.h>
44 #include "script_port.h"
47 #define TEXT_CLASS "tizen"
48 #define DEFAULT_FONT_SIZE -100
50 #define PUBLIC __attribute__((visibility("default")))
52 #define ACCESS_TYPE_DOWN 0
53 #define ACCESS_TYPE_MOVE 1
54 #define ACCESS_TYPE_UP 2
55 #define ACCESS_TYPE_CUR 0
56 #define ACCESS_TYPE_NEXT 1
57 #define ACCESS_TYPE_PREV 2
58 #define ACCESS_TYPE_OFF 3
97 int (*render_pre)(void *buffer_handle, void *data);
98 int (*render_post)(void *render_handle, void *data);
119 Eina_List *handle_list;
121 Ecore_Evas *(*alloc_canvas)(int w, int h, void *(*a)(void *data, int size), void (*f)(void *data, void *ptr), void *data);
122 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);
130 .alloc_canvas = NULL,
131 .alloc_canvas_with_stride = NULL,
134 static inline Evas_Object *find_edje(struct info *handle, const char *id)
138 struct obj_info *obj_info;
140 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
141 obj_info = evas_object_data_get(edje, "obj_info");
143 ErrPrint("Object info is not valid\n");
153 } else if (!obj_info->id) {
157 if (!strcmp(obj_info->id, id)) {
162 DbgPrint("EDJE[%s] is not found\n", id);
166 PUBLIC const char *script_magic_id(void)
171 PUBLIC int script_update_color(void *h, const char *id, const char *part, const char *rgba)
173 struct info *handle = h;
175 int r[3], g[3], b[3], a[3];
178 edje = find_edje(handle, id);
180 return WIDGET_ERROR_NOT_EXIST;
183 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
184 r, g, b, a, /* OBJECT */
185 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
186 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
188 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
189 return WIDGET_ERROR_INVALID_PARAMETER;
192 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
193 r[0], g[0], b[0], a[0], /* OBJECT */
194 r[1], g[1], b[1], a[1], /* OUTLINE */
195 r[2], g[2], b[2], a[2]); /* SHADOW */
197 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
198 return WIDGET_ERROR_NONE;
201 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
210 e = evas_object_evas_get(part_obj);
211 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
215 #if defined(_USE_ECORE_TIME_GET)
216 timestamp = ecore_time_get();
219 if (gettimeofday(&tv, NULL) < 0) {
220 ErrPrint("Failed to get time\n");
223 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
227 DbgPrint("Cursor is on %dx%d\n", x, y);
228 evas_event_feed_mouse_move(e, x, y, timestamp * 1000, NULL);
229 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
230 evas_event_feed_mouse_move(e, x, y, (timestamp + 0.02f) * 1000, NULL);
231 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, (timestamp + 0.03f) * 1000, NULL);
234 static void update_focus_chain(struct info *handle, Evas_Object *ao)
236 const Eina_List *list;
238 list = elm_object_focus_custom_chain_get(handle->parent);
239 if (!eina_list_data_find(list, ao)) {
240 DbgPrint("Append again to the focus chain\n");
241 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
245 PUBLIC int script_update_text(void *h, const char *id, const char *part, const char *text)
247 struct obj_info *obj_info;
248 struct info *handle = h;
250 Evas_Object *edje_part;
252 edje = find_edje(handle, id);
254 ErrPrint("Failed to find EDJE\n");
255 return WIDGET_ERROR_NOT_EXIST;
258 obj_info = evas_object_data_get(edje, "obj_info");
260 ErrPrint("Object info is not available\n");
261 return WIDGET_ERROR_FAULT;
264 elm_object_part_text_set(edje, part, text ? text : "");
266 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
271 ao = evas_object_data_get(edje_part, "ao");
273 ao = elm_access_object_register(edje_part, handle->parent);
275 ErrPrint("Unable to register an access object(%s)\n", part);
279 evas_object_data_set(edje_part, "ao", ao);
280 elm_access_activate_cb_set(ao, activate_cb, NULL);
281 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
283 DbgPrint("[%s] Register access info: (%s) to, %p\n", part, text, handle->parent);
286 if (!text || !strlen(text)) {
289 * Delete callback will be called
291 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
292 elm_access_object_unregister(ao);
297 utf8 = elm_entry_markup_to_utf8(text);
298 if ((!utf8 || !strlen(utf8))) {
302 * Delete callback will be called
304 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
305 elm_access_object_unregister(ao);
310 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
313 update_focus_chain(handle, ao);
315 ErrPrint("Unable to get text part[%s]\n", part);
319 return WIDGET_ERROR_NONE;
322 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
324 while (len > 0 && *value == ' ') {
333 img_opt->aspect = !strncasecmp(value, "true", 4);
334 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
337 static void parse_orient(struct image_option *img_opt, const char *value, int len)
339 while (len > 0 && *value == ' ') {
348 img_opt->orient = !strncasecmp(value, "true", 4);
349 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
352 static void parse_size(struct image_option *img_opt, const char *value, int len)
358 while (len > 0 && *value == ' ') {
363 buf = strndup(value, len);
365 ErrPrint("Heap: %d\n", errno);
369 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
370 img_opt->width = width;
371 img_opt->height = height;
372 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
374 DbgPrint("Invalid size tag[%s]\n", buf);
380 static void parse_shadow(struct image_option *img_opt, const char *value, int len)
387 if (sscanf(value, "%d,%d,%d,%x", &angle, &offset, &softness, &color) != 4) {
388 ErrPrint("Invalid shadow [%s]\n", value);
390 img_opt->shadow.enabled = 1;
391 img_opt->shadow.angle = angle;
392 img_opt->shadow.offset = offset;
393 img_opt->shadow.softness = softness;
394 img_opt->shadow.color = color;
398 static void parse_fill(struct image_option *img_opt, const char *value, int len)
400 while (len > 0 && *value == ' ') {
405 if (!strncasecmp(value, "in-size", len)) {
406 img_opt->fill = FILL_IN_SIZE;
407 } else if (!strncasecmp(value, "over-size", len)) {
408 img_opt->fill = FILL_OVER_SIZE;
409 } else if (!strncasecmp(value, "fit-size", len)) {
410 img_opt->fill = FILL_FIT_SIZE;
412 img_opt->fill = FILL_DISABLE;
415 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
418 static inline void parse_image_option(const char *option, struct image_option *img_opt)
425 void (*handler)(struct image_option *img_opt, const char *value, int len);
428 .cmd = "aspect", /* Keep the aspect ratio */
429 .handler = parse_aspect,
432 .cmd = "orient", /* Keep the orientation value: for the rotated images */
433 .handler = parse_orient,
436 .cmd = "fill", /* Fill the image to its container */
437 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
441 .handler = parse_size,
445 .handler = parse_shadow,
459 if (!option || !*option) {
466 * GCC 4.7 warnings uninitialized idx and tag value.
467 * But it will be initialized by the state machine. :(
468 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
475 for (ptr = option; state != STATE_END; ptr++) {
490 cmd = cmd_list[tag].cmd;
496 } else if (*ptr == '\0') {
501 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
506 state = STATE_IGNORE;
509 } else if (*ptr == '\0') {
511 } else if (cmd[idx] == *ptr) {
517 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
521 cmd = cmd_list[tag].cmd;
527 if (*ptr == ';' || *ptr == '\0') {
528 cmd_list[tag].handler(img_opt, value + 1, idx);
529 state = *ptr ? STATE_START : STATE_END;
537 } else if (*ptr == '\0') {
547 PUBLIC int script_update_access(void *_h, const char *id, const char *part, const char *text, const char *option)
549 struct info *handle = _h;
551 struct obj_info *obj_info;
552 Evas_Object *edje_part;
554 edje = find_edje(handle, id);
556 ErrPrint("No such object: %s\n", id);
557 return WIDGET_ERROR_NOT_EXIST;
560 obj_info = evas_object_data_get(edje, "obj_info");
562 ErrPrint("Object info is not available\n");
563 return WIDGET_ERROR_FAULT;
566 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
570 ao = evas_object_data_get(edje_part, "ao");
572 if (text && strlen(text)) {
573 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
574 DbgPrint("Access info is updated: %s [%s], %p\n", part, text, ao);
575 update_focus_chain(handle, ao);
579 * Delete clalback will be called
581 DbgPrint("[%s] Remove access object(%p)\n", part, ao);
582 elm_access_object_unregister(ao);
584 } else if (text && strlen(text)) {
585 ao = elm_access_object_register(edje_part, handle->parent);
587 ErrPrint("Unable to register an access object(%s)\n", part);
589 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
591 evas_object_data_set(edje_part, "ao", ao);
592 elm_object_focus_custom_chain_append(handle->parent, ao, NULL);
593 elm_access_activate_cb_set(ao, activate_cb, NULL);
594 DbgPrint("[%s] Register access info: (%s) to, %p (%p)\n", part, text, handle->parent, ao);
598 ErrPrint("[%s] is not exists\n", part);
601 return WIDGET_ERROR_NONE;
604 PUBLIC int script_operate_access(void *_h, const char *id, const char *part, const char *operation, const char *option)
606 struct info *handle = _h;
608 struct obj_info *obj_info;
609 Elm_Access_Action_Info action_info;
612 if (!operation || !strlen(operation)) {
613 return WIDGET_ERROR_INVALID_PARAMETER;
616 edje = find_edje(handle, id);
618 ErrPrint("No such object: %s\n", id);
619 return WIDGET_ERROR_NOT_EXIST;
622 obj_info = evas_object_data_get(edje, "obj_info");
624 ErrPrint("Object info is not available\n");
625 return WIDGET_ERROR_FAULT;
628 memset(&action_info, 0, sizeof(action_info));
630 /* OPERATION is defined in libwidget package */
631 if (!strcasecmp(operation, "set,hl")) {
633 Evas_Object *edje_part;
639 edje_part = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
641 ErrPrint("Invalid part: %s\n", part);
645 evas_object_geometry_get(edje_part, &x, &y, &w, &h);
647 action_info.x = x + w / 2;
648 action_info.y = x + h / 2;
649 } else if (option && sscanf(option, "%dx%d", &action_info.x, &action_info.y) == 2) {
651 ErrPrint("Insufficient info for HL\n");
655 DbgPrint("TXxTY: %dx%d\n", action_info.x, action_info.y);
656 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT, &action_info);
657 if (ret == EINA_FALSE) {
658 ErrPrint("Action error\n");
660 } else if (!strcasecmp(operation, "unset,hl")) {
661 ret = elm_access_action(edje, ELM_ACCESS_ACTION_UNHIGHLIGHT, &action_info);
662 if (ret == EINA_FALSE) {
663 ErrPrint("Action error\n");
665 } else if (!strcasecmp(operation, "next,hl")) {
666 action_info.highlight_cycle = (!!option) && (!!strcasecmp(option, "no,cycle"));
668 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_NEXT, &action_info);
669 if (ret == EINA_FALSE) {
670 ErrPrint("Action error\n");
672 } else if (!strcasecmp(operation, "prev,hl")) {
673 action_info.highlight_cycle = EINA_TRUE;
674 ret = elm_access_action(edje, ELM_ACCESS_ACTION_HIGHLIGHT_PREV, &action_info);
675 if (ret == EINA_FALSE) {
676 ErrPrint("Action error\n");
678 } else if (!strcasecmp(operation, "reset,focus")) {
679 DbgPrint("Reset Focus\n");
680 elm_object_focus_custom_chain_set(edje, NULL);
684 return WIDGET_ERROR_NONE;
687 static inline void apply_shadow_effect(struct image_option *img_opt, Evas_Object *img)
689 ea_effect_h *ea_effect;
691 if (!img_opt->shadow.enabled) {
695 ea_effect = ea_image_effect_create();
700 // -90, 2, 4, 0x99000000
701 ea_image_effect_add_outer_shadow(ea_effect, img_opt->shadow.angle, img_opt->shadow.offset, img_opt->shadow.softness, img_opt->shadow.color);
702 ea_object_image_effect_set(img, ea_effect);
704 ea_image_effect_destroy(ea_effect);
707 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)
711 Evas_Object *src_img;
717 ee = ecore_evas_buffer_new(part_w, part_h);
719 ErrPrint("Failed to create a EE\n");
723 ecore_evas_alpha_set(ee, EINA_TRUE);
725 e = ecore_evas_get(ee);
727 ErrPrint("Unable to get Evas\n");
732 src_img = evas_object_image_filled_add(e);
734 ErrPrint("Unable to add an image\n");
739 evas_object_image_alpha_set(src_img, EINA_TRUE);
740 evas_object_image_colorspace_set(src_img, EVAS_COLORSPACE_ARGB8888);
741 evas_object_image_smooth_scale_set(src_img, EINA_TRUE);
742 evas_object_image_load_orientation_set(src_img, img_opt->orient);
743 evas_object_image_file_set(src_img, path, NULL);
744 err = evas_object_image_load_error_get(src_img);
745 if (err != EVAS_LOAD_ERROR_NONE) {
746 ErrPrint("Load error: %s\n", evas_load_error_str(err));
747 evas_object_del(src_img);
751 evas_object_image_size_get(src_img, &rw, &rh);
752 evas_object_image_fill_set(src_img, 0, 0, rw, rh);
753 evas_object_resize(src_img, w, h);
754 evas_object_move(src_img, -(w - part_w) / 2, -(h - part_h) / 2);
755 evas_object_show(src_img);
757 data = ecore_evas_buffer_pixels_get(ee);
759 ErrPrint("Unable to get pixels\n");
760 evas_object_del(src_img);
765 e = evas_object_evas_get(img);
766 _img = evas_object_image_filled_add(e);
768 evas_object_del(src_img);
773 evas_object_image_colorspace_set(_img, EVAS_COLORSPACE_ARGB8888);
774 evas_object_image_smooth_scale_set(_img, EINA_TRUE);
775 evas_object_image_alpha_set(_img, EINA_TRUE);
776 evas_object_image_data_set(_img, NULL);
777 evas_object_image_size_set(_img, part_w, part_h);
778 evas_object_resize(_img, part_w, part_h);
779 evas_object_image_data_copy_set(_img, (void *)data);
780 evas_object_image_fill_set(_img, 0, 0, part_w, part_h);
781 evas_object_image_data_update_add(_img, 0, 0, part_w, part_h);
783 evas_object_del(src_img);
786 evas_object_del(img);
790 PUBLIC int script_update_image(void *_h, const char *id, const char *part, const char *path, const char *option)
792 struct info *handle = _h;
797 struct obj_info *obj_info;
798 struct image_option img_opt = {
801 .fill = FILL_DISABLE,
809 edje = find_edje(handle, id);
811 ErrPrint("No such object: %s\n", id);
812 return WIDGET_ERROR_NOT_EXIST;
815 obj_info = evas_object_data_get(edje, "obj_info");
817 ErrPrint("Object info is not available\n");
818 return WIDGET_ERROR_FAULT;
821 img = elm_object_part_content_unset(edje, part);
823 DbgPrint("delete object %s %p\n", part, img);
824 evas_object_del(img);
827 if (!path || !strlen(path) || access(path, R_OK) != 0) {
828 DbgPrint("SKIP - Path: [%s]\n", path);
829 return WIDGET_ERROR_NONE;
832 img = evas_object_image_add(handle->e);
834 ErrPrint("Failed to add an image object\n");
835 return WIDGET_ERROR_FAULT;
838 evas_object_image_preload(img, EINA_FALSE);
839 parse_image_option(option, &img_opt);
840 evas_object_image_load_orientation_set(img, img_opt.orient);
842 evas_object_image_file_set(img, path, NULL);
843 err = evas_object_image_load_error_get(img);
844 if (err != EVAS_LOAD_ERROR_NONE) {
845 ErrPrint("Load error: %s\n", evas_load_error_str(err));
846 evas_object_del(img);
847 return WIDGET_ERROR_IO_ERROR;
850 apply_shadow_effect(&img_opt, img);
852 evas_object_image_size_get(img, &w, &h);
853 if (img_opt.aspect) {
854 if (img_opt.fill == FILL_OVER_SIZE) {
858 if (img_opt.width >= 0 && img_opt.height >= 0) {
859 part_w = img_opt.width * elm_config_scale_get();
860 part_h = img_opt.height * elm_config_scale_get();
864 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
866 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
868 if (part_w > w || part_h > h) {
872 fw = (double)part_w / (double)w;
873 fh = (double)part_h / (double)h;
884 if (!part_w || !part_h || !w || !h) {
885 evas_object_del(img);
886 return WIDGET_ERROR_INVALID_PARAMETER;
889 img = crop_image(img, path, part_w, part_h, w, h, &img_opt);
890 } else if (img_opt.fill == FILL_IN_SIZE) {
894 if (img_opt.width >= 0 && img_opt.height >= 0) {
895 part_w = img_opt.width * elm_config_scale_get();
896 part_h = img_opt.height * elm_config_scale_get();
900 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
902 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
904 if (w > part_w || h > part_h) {
908 fw = (double)part_w / (double)w;
909 fh = (double)part_h / (double)h;
920 if (!part_w || !part_h || !w || !h) {
921 evas_object_del(img);
922 return WIDGET_ERROR_INVALID_PARAMETER;
925 img = crop_image(img, path, part_w, part_h, w, h, &img_opt);
926 } else if (img_opt.fill == FILL_FIT_SIZE) {
932 if (img_opt.width >= 0 && img_opt.height >= 0) {
933 part_w = img_opt.width * elm_config_scale_get();
934 part_h = img_opt.height * elm_config_scale_get();
938 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
940 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
942 fw = (double)part_w / (double)w;
943 fh = (double)part_h / (double)h;
953 if (!part_w || !part_h || !w || !h) {
954 evas_object_del(img);
955 return WIDGET_ERROR_INVALID_PARAMETER;
958 img = crop_image(img, path, part_w, part_h, w, h, &img_opt);
960 evas_object_image_fill_set(img, 0, 0, w, h);
961 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
962 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
965 apply_shadow_effect(&img_opt, img);
967 if (img_opt.width >= 0 && img_opt.height >= 0) {
970 DbgPrint("Using given image size: %dx%d\n", w, h);
973 evas_object_image_fill_set(img, 0, 0, w, h);
974 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
975 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
976 evas_object_image_filled_set(img, EINA_TRUE);
982 * object will be shown by below statement automatically
984 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
985 elm_object_part_content_set(edje, part, img);
989 * This object is not registered as an access object.
990 * So the developer should add it to access list manually, using DESC_ACCESS block.
992 return WIDGET_ERROR_NONE;
995 static void script_signal_cb(void *data, Evas_Object *obj, const char *signal_name, const char *source)
997 struct info *handle = data;
1009 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1010 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
1014 sx = (double)px / (double)w;
1015 ex = (double)(px + pw) / (double)w;
1020 sy = (double)py / (double)h;
1021 ey = (double)(py + ph) / (double)h;
1024 DbgPrint("[%s] [%s]\n", signal_name, source);
1026 script_buffer_signal_emit(handle->buffer_handle, source, signal_name, sx, sy, ex, ey);
1029 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
1031 struct info *handle = _info;
1032 struct obj_info *obj_info;
1033 struct obj_info *parent_obj_info;
1034 struct child *child;
1036 handle->obj_list = eina_list_remove(handle->obj_list, obj);
1038 obj_info = evas_object_data_get(obj, "obj_info");
1040 ErrPrint("Object info is not valid\n");
1044 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
1046 DbgPrint("delete object %s %p\n", obj_info->id, obj);
1047 if (obj_info->parent == obj) {
1048 DbgPrint("Parent EDJE\n");
1049 } else if (obj_info->parent) {
1053 parent_obj_info = evas_object_data_get(obj_info->parent, "obj_info");
1054 if (parent_obj_info) {
1055 EINA_LIST_FOREACH_SAFE(parent_obj_info->children, l, n, child) {
1056 if (child->obj != obj) {
1062 * If this code is executed,
1063 * The parent is not deleted by desc, this object is deleted by itself.
1064 * It is not possible, but we care it.
1066 DbgPrint("Children is updated: %s (%s)\n", child->part, parent_obj_info->id);
1067 parent_obj_info->children = eina_list_remove(parent_obj_info->children, child);
1073 if (!parent_obj_info->children && parent_obj_info->delete_me == 1) {
1074 DbgPrint("Children is cleared: %s (by a child)\n", parent_obj_info->id);
1075 evas_object_data_del(obj_info->parent, "obj_info");
1076 free(parent_obj_info->id);
1077 free(parent_obj_info);
1081 DbgPrint("obj_info->parent is NULL (skipped)\n");
1084 if (!obj_info->children) {
1085 DbgPrint("Children is cleared: %s\n", obj_info->id);
1086 evas_object_data_del(obj, "obj_info");
1090 DbgPrint("Children is remained: %s\n", obj_info->id);
1091 obj_info->delete_me = 1;
1095 static inline Evas_Object *get_highlighted_object(Evas_Object *obj)
1097 Evas_Object *o, *ho;
1099 o = evas_object_name_find(evas_object_evas_get(obj), "_elm_access_disp");
1104 ho = evas_object_data_get(o, "_elm_access_target");
1109 WIDGET_ACCESS_HIGHLIGHT 0
1110 WIDGET_ACCESS_HIGHLIGHT_NEXT 1
1111 WIDGET_ACCESS_HIGHLIGHT_PREV 2
1112 WIDGET_ACCESS_ACTIVATE 3
1113 WIDGET_ACCESS_ACTION 4
1114 WIDGET_ACCESS_SCROLL 5
1116 PUBLIC int script_feed_event(void *h, int event_type, int x, int y, int type, unsigned int keycode, double timestamp)
1118 struct info *handle = h;
1120 struct obj_info *obj_info;
1121 int ret = WIDGET_ERROR_NONE;
1123 edje = find_edje(handle, NULL); /*!< Get the base layout */
1125 ErrPrint("Base layout is not exist\n");
1126 return WIDGET_ERROR_NOT_EXIST;
1129 obj_info = evas_object_data_get(edje, "obj_info");
1131 ErrPrint("Object info is not valid\n");
1132 return WIDGET_ERROR_INVALID_PARAMETER;
1135 if (event_type & WIDGET_SCRIPT_ACCESS_EVENT) {
1136 Elm_Access_Action_Info info;
1137 Elm_Access_Action_Type action;
1139 memset(&info, 0, sizeof(info));
1141 if ((event_type & WIDGET_SCRIPT_ACCESS_HIGHLIGHT) == WIDGET_SCRIPT_ACCESS_HIGHLIGHT) {
1142 action = ELM_ACCESS_ACTION_HIGHLIGHT;
1145 ret = elm_access_action(edje, action, &info);
1146 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
1147 if (ret == EINA_TRUE) {
1148 if (!get_highlighted_object(edje)) {
1149 ErrPrint("Highlighted object is not found\n");
1150 ret = WIDGET_ACCESS_STATUS_ERROR;
1152 DbgPrint("Highlighted object is found\n");
1153 ret = WIDGET_ACCESS_STATUS_DONE;
1156 ErrPrint("Action error\n");
1157 ret = WIDGET_ACCESS_STATUS_ERROR;
1159 } else if ((event_type & WIDGET_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == WIDGET_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
1160 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
1161 info.highlight_cycle = EINA_FALSE;
1162 ret = elm_access_action(edje, action, &info);
1163 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
1164 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_LAST : WIDGET_ACCESS_STATUS_DONE;
1165 } else if ((event_type & WIDGET_SCRIPT_ACCESS_HIGHLIGHT_PREV) == WIDGET_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
1166 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
1167 info.highlight_cycle = EINA_FALSE;
1168 ret = elm_access_action(edje, action, &info);
1169 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
1170 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_FIRST : WIDGET_ACCESS_STATUS_DONE;
1171 } else if ((event_type & WIDGET_SCRIPT_ACCESS_ACTIVATE) == WIDGET_SCRIPT_ACCESS_ACTIVATE) {
1172 action = ELM_ACCESS_ACTION_ACTIVATE;
1173 ret = elm_access_action(edje, action, &info);
1174 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
1175 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1176 } else if ((event_type & WIDGET_SCRIPT_ACCESS_ACTION) == WIDGET_SCRIPT_ACCESS_ACTION) {
1178 case ACCESS_TYPE_UP:
1179 action = ELM_ACCESS_ACTION_UP;
1180 ret = elm_access_action(edje, action, &info);
1181 DbgPrint("ACCESS_ACTION(%d), returns %d\n", type, ret);
1182 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1184 case ACCESS_TYPE_DOWN:
1185 action = ELM_ACCESS_ACTION_DOWN;
1186 ret = elm_access_action(edje, action, &info);
1187 DbgPrint("ACCESS_ACTION(%d), returns %d\n", type, ret);
1188 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1191 ErrPrint("Invalid access event\n");
1192 ret = WIDGET_ACCESS_STATUS_ERROR;
1195 } else if ((event_type & WIDGET_SCRIPT_ACCESS_SCROLL) == WIDGET_SCRIPT_ACCESS_SCROLL) {
1196 action = ELM_ACCESS_ACTION_SCROLL;
1200 case ACCESS_TYPE_DOWN:
1201 info.mouse_type = 0;
1202 ret = elm_access_action(edje, action, &info);
1203 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1204 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1206 case ACCESS_TYPE_MOVE:
1207 info.mouse_type = 1;
1208 ret = elm_access_action(edje, action, &info);
1209 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1210 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1212 case ACCESS_TYPE_UP:
1213 info.mouse_type = 2;
1214 ret = elm_access_action(edje, action, &info);
1215 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
1216 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1219 ret = WIDGET_ACCESS_STATUS_ERROR;
1222 } else if ((event_type & WIDGET_SCRIPT_ACCESS_UNHIGHLIGHT) == WIDGET_SCRIPT_ACCESS_UNHIGHLIGHT) {
1223 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
1224 ret = elm_access_action(edje, action, &info);
1225 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
1226 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1227 } else if ((event_type & WIDGET_SCRIPT_ACCESS_VALUE_CHANGE) == WIDGET_SCRIPT_ACCESS_VALUE_CHANGE) {
1228 action = ELM_ACCESS_ACTION_VALUE_CHANGE;
1229 info.mouse_type = type;
1232 ret = elm_access_action(edje, action, &info);
1233 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1234 } else if ((event_type & WIDGET_SCRIPT_ACCESS_MOUSE) == WIDGET_SCRIPT_ACCESS_MOUSE) {
1235 action = ELM_ACCESS_ACTION_MOUSE;
1236 info.mouse_type = type;
1239 ret = elm_access_action(edje, action, &info);
1240 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1241 } else if ((event_type & WIDGET_SCRIPT_ACCESS_BACK) == WIDGET_SCRIPT_ACCESS_BACK) {
1242 action = ELM_ACCESS_ACTION_BACK;
1243 info.mouse_type = type;
1246 ret = elm_access_action(edje, action, &info);
1247 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1248 } else if ((event_type & WIDGET_SCRIPT_ACCESS_OVER) == WIDGET_SCRIPT_ACCESS_OVER) {
1249 action = ELM_ACCESS_ACTION_OVER;
1250 info.mouse_type = type;
1253 ret = elm_access_action(edje, action, &info);
1254 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1255 } else if ((event_type & WIDGET_SCRIPT_ACCESS_READ) == WIDGET_SCRIPT_ACCESS_READ) {
1256 action = ELM_ACCESS_ACTION_READ;
1257 info.mouse_type = type;
1260 ret = elm_access_action(edje, action, &info);
1261 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1262 } else if ((event_type & WIDGET_SCRIPT_ACCESS_ENABLE) == WIDGET_SCRIPT_ACCESS_ENABLE) {
1263 action = ELM_ACCESS_ACTION_ENABLE;
1264 info.mouse_type = type;
1267 ret = elm_access_action(edje, action, &info);
1268 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1269 } else if ((event_type & WIDGET_SCRIPT_ACCESS_DISABLE) == WIDGET_SCRIPT_ACCESS_DISABLE) {
1270 action = ELM_ACCESS_ACTION_ENABLE;
1271 info.mouse_type = type;
1274 ret = elm_access_action(edje, action, &info);
1275 ret = (ret == EINA_FALSE) ? WIDGET_ACCESS_STATUS_ERROR : WIDGET_ACCESS_STATUS_DONE;
1277 DbgPrint("Invalid event\n");
1278 ret = WIDGET_ACCESS_STATUS_ERROR;
1281 } else if (event_type & WIDGET_SCRIPT_MOUSE_EVENT) {
1282 double cur_timestamp;
1285 #if defined(_USE_ECORE_TIME_GET)
1286 cur_timestamp = ecore_time_get();
1289 if (gettimeofday(&tv, NULL) < 0) {
1290 ErrPrint("Failed to get time\n");
1291 cur_timestamp = 0.0f;
1293 cur_timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1296 if (cur_timestamp - timestamp > 0.1f && handle->is_mouse_down == 0) {
1297 DbgPrint("Discard lazy event : %lf\n", cur_timestamp - timestamp);
1298 return WIDGET_ERROR_NONE;
1301 switch (event_type) {
1302 case WIDGET_SCRIPT_MOUSE_DOWN:
1303 if (handle->is_mouse_down == 0) {
1304 flags = evas_event_default_flags_get(handle->e);
1305 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
1306 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
1307 evas_event_default_flags_set(handle->e, flags);
1309 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1310 evas_event_feed_mouse_down(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1311 handle->is_mouse_down = 1;
1314 case WIDGET_SCRIPT_MOUSE_MOVE:
1315 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1317 case WIDGET_SCRIPT_MOUSE_UP:
1318 if (handle->is_mouse_down == 1) {
1319 evas_event_feed_mouse_move(handle->e, x, y, timestamp * 1000, NULL);
1320 evas_event_feed_mouse_up(handle->e, 1, EVAS_BUTTON_NONE, (timestamp + 0.01f) * 1000, NULL);
1321 handle->is_mouse_down = 0;
1324 case WIDGET_SCRIPT_MOUSE_IN:
1325 evas_event_feed_mouse_in(handle->e, timestamp * 1000, NULL);
1327 case WIDGET_SCRIPT_MOUSE_OUT:
1328 evas_event_feed_mouse_out(handle->e, timestamp * 1000, NULL);
1330 case WIDGET_SCRIPT_MOUSE_ON_SCROLL:
1331 flags = evas_event_default_flags_get(handle->e);
1332 flags |= EVAS_EVENT_FLAG_ON_SCROLL;
1333 evas_event_default_flags_set(handle->e, flags);
1335 case WIDGET_SCRIPT_MOUSE_ON_HOLD: // To cancel the clicked, enable this
1336 flags = evas_event_default_flags_get(handle->e);
1337 flags |= EVAS_EVENT_FLAG_ON_HOLD;
1338 evas_event_default_flags_set(handle->e, flags);
1340 case WIDGET_SCRIPT_MOUSE_OFF_SCROLL:
1341 flags = evas_event_default_flags_get(handle->e);
1342 flags &= ~EVAS_EVENT_FLAG_ON_SCROLL;
1343 evas_event_default_flags_set(handle->e, flags);
1345 case WIDGET_SCRIPT_MOUSE_OFF_HOLD:
1346 flags = evas_event_default_flags_get(handle->e);
1347 flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
1348 evas_event_default_flags_set(handle->e, flags);
1351 return WIDGET_ERROR_INVALID_PARAMETER;
1353 } else if (event_type & WIDGET_SCRIPT_KEY_EVENT) {
1354 const char *keyname = "";
1355 const char *key = "";
1356 const char *string = "";
1357 const char *compose = "";
1359 switch (event_type) {
1360 case WIDGET_SCRIPT_KEY_DOWN:
1361 evas_event_feed_key_down(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1362 ret = WIDGET_KEY_STATUS_DONE;
1365 * If the keyname == RIGHT, Need to check that
1366 * Does it reach to the last focusable object?
1370 * if (REACH to the LAST) {
1371 * ret = WIDGET_KEY_STATUS_LAST;
1373 * ret = WIDGET_KEY_STATUS_DONE;
1376 * if (REACH to the FIRST) {
1377 * ret = WIDGET_KEY_STATUS_FIRST;
1379 * ret = WIDGET_KEY_STATUS_DONE;
1383 case WIDGET_SCRIPT_KEY_UP:
1384 evas_event_feed_key_up(handle->e, keyname, key, string, compose, timestamp * 1000, NULL);
1385 ret = WIDGET_KEY_STATUS_DONE;
1387 case WIDGET_SCRIPT_KEY_FOCUS_IN:
1388 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_IN, NULL);
1389 ret = WIDGET_KEY_STATUS_DONE;
1391 case WIDGET_SCRIPT_KEY_FOCUS_OUT:
1392 // evas_event_callback_call(handle->e, EVAS_CALLBACK_CANVAS_FOCUS_OUT, NULL);
1393 ret = WIDGET_KEY_STATUS_DONE;
1396 DbgPrint("Event is not implemented\n");
1397 ret = WIDGET_KEY_STATUS_ERROR;
1405 PUBLIC int script_update_script(void *h, const char *src_id, const char *target_id, const char *part, const char *path, const char *group)
1407 struct info *handle = h;
1410 struct obj_info *obj_info;
1411 struct child *child;
1412 char _target_id[32];
1414 edje = find_edje(handle, src_id);
1416 ErrPrint("Edje is not exists (%s)\n", src_id);
1417 return WIDGET_ERROR_NOT_EXIST;
1420 obj_info = evas_object_data_get(edje, "obj_info");
1422 ErrPrint("Object info is not valid\n");
1423 return WIDGET_ERROR_INVALID_PARAMETER;
1426 obj = elm_object_part_content_unset(edje, part);
1428 DbgPrint("delete object %s %p\n", part, obj);
1431 * This will call the edje_del_cb.
1432 * It will delete all access objects
1434 evas_object_del(obj);
1437 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1438 DbgPrint("SKIP - Path: [%s]\n", path);
1439 return WIDGET_ERROR_NONE;
1443 if (find_edje(handle, part)) {
1447 #if defined(_USE_ECORE_TIME_GET)
1448 timestamp = ecore_time_get();
1451 if (gettimeofday(&tv, NULL) < 0) {
1452 static int local_idx = 0;
1453 timestamp = (double)(local_idx++);
1455 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
1459 snprintf(_target_id, sizeof(_target_id), "%lf", timestamp);
1460 } while (find_edje(handle, _target_id));
1462 target_id = _target_id;
1467 DbgPrint("Anonymouse target id: %s\n", target_id);
1470 obj = elm_layout_add(edje);
1472 ErrPrint("Failed to add a new edje object\n");
1473 return WIDGET_ERROR_FAULT;
1476 edje_object_scale_set(elm_layout_edje_get(obj), elm_config_scale_get());
1478 if (!elm_layout_file_set(obj, path, group)) {
1480 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1481 if (err != EDJE_LOAD_ERROR_NONE) {
1482 ErrPrint("Could not load %s from %s: %s\n", group, path, edje_load_error_str(err));
1484 evas_object_del(obj);
1485 return WIDGET_ERROR_IO_ERROR;
1488 evas_object_show(obj);
1490 obj_info = calloc(1, sizeof(*obj_info));
1492 ErrPrint("Failed to add a obj_info\n");
1493 evas_object_del(obj);
1494 return WIDGET_ERROR_OUT_OF_MEMORY;
1497 obj_info->id = strdup(target_id);
1498 if (!obj_info->id) {
1499 ErrPrint("Failed to add a obj_info\n");
1501 evas_object_del(obj);
1502 return WIDGET_ERROR_OUT_OF_MEMORY;
1505 obj_info->parent = edje;
1507 child = malloc(sizeof(*child));
1509 ErrPrint("Error: %d\n", errno);
1512 evas_object_del(obj);
1513 return WIDGET_ERROR_OUT_OF_MEMORY;
1516 child->part = strdup(part);
1518 ErrPrint("Error: %d\n", errno);
1522 evas_object_del(obj);
1523 return WIDGET_ERROR_OUT_OF_MEMORY;
1528 evas_object_data_set(obj, "obj_info", obj_info);
1529 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1530 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1531 handle->obj_list = eina_list_append(handle->obj_list, obj);
1533 DbgPrint("%s part swallow edje %p\n", part, obj);
1534 elm_object_part_content_set(edje, part, obj);
1536 obj_info = evas_object_data_get(edje, "obj_info");
1538 if (obj_info == NULL) {
1539 ErrPrint("evas_object_data_get failed\n");
1543 evas_object_del(obj);
1544 return WIDGET_ERROR_FAULT;
1547 obj_info->children = eina_list_append(obj_info->children, child);
1549 return WIDGET_ERROR_NONE;
1552 PUBLIC int script_update_signal(void *h, const char *id, const char *part, const char *signal)
1554 struct info *handle = h;
1557 edje = find_edje(handle, id);
1559 return WIDGET_ERROR_NOT_EXIST;
1562 elm_object_signal_emit(edje, signal, part);
1563 return WIDGET_ERROR_NONE;
1566 PUBLIC int script_update_drag(void *h, const char *id, const char *part, double x, double y)
1568 struct info *handle = h;
1571 edje = find_edje(handle, id);
1573 return WIDGET_ERROR_NOT_EXIST;
1576 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1577 return WIDGET_ERROR_NONE;
1580 PUBLIC int script_update_size(void *han, const char *id, int w, int h)
1582 struct info *handle = han;
1585 edje = find_edje(handle, id);
1587 return WIDGET_ERROR_NOT_EXIST;
1593 * Need to resize the canvas too
1595 ecore_evas_resize(handle->ee, w, h);
1598 DbgPrint("Resize object to %dx%d\n", w, h);
1599 evas_object_resize(edje, w, h);
1600 return WIDGET_ERROR_NONE;
1603 PUBLIC int script_update_category(void *h, const char *id, const char *category)
1605 struct info *handle = h;
1607 if (handle->category) {
1608 free(handle->category);
1609 handle->category = NULL;
1613 return WIDGET_ERROR_NONE;
1616 handle->category = strdup(category);
1617 if (!handle->category) {
1618 ErrPrint("Error: %d\n", errno);
1619 return WIDGET_ERROR_OUT_OF_MEMORY;
1622 return WIDGET_ERROR_NONE;
1625 PUBLIC void *script_create(void *buffer_handle, const char *file, const char *group)
1627 struct info *handle;
1629 handle = calloc(1, sizeof(*handle));
1631 ErrPrint("Error: %d\n", errno);
1635 handle->file = strdup(file);
1636 if (!handle->file) {
1637 ErrPrint("Error: %d\n", errno);
1642 handle->group = strdup(group);
1643 if (!handle->group) {
1644 ErrPrint("Error: %d\n", errno);
1650 handle->buffer_handle = buffer_handle;
1652 s_info.handle_list = eina_list_append(s_info.handle_list, handle);
1657 PUBLIC int script_destroy(void *_handle)
1659 struct info *handle;
1664 if (!eina_list_data_find(s_info.handle_list, handle)) {
1665 DbgPrint("Not found (already deleted?)\n");
1666 return WIDGET_ERROR_NOT_EXIST;
1669 s_info.handle_list = eina_list_remove(s_info.handle_list, handle);
1671 edje = eina_list_nth(handle->obj_list, 0);
1673 evas_object_del(edje);
1676 DbgPrint("Release handle\n");
1677 free(handle->category);
1679 free(handle->group);
1681 return WIDGET_ERROR_NONE;
1684 static void sw_render_pre_cb(void *data, Evas *e, void *event_info)
1686 struct info *handle = data;
1688 if (handle->render_pre) {
1689 handle->render_pre(handle->buffer_handle, handle->render_data);
1692 script_buffer_lock(handle->buffer_handle);
1694 if (s_info.premultiplied) {
1698 script_buffer_get_size(handle->buffer_handle, &w, &h);
1699 evas_damage_rectangle_add(handle->e, 0, 0, w, h);
1703 static void sw_render_post_cb(void *data, Evas *e, void *event_info)
1705 struct info *handle = data;
1707 if (s_info.premultiplied) {
1711 // Get a pointer of a buffer of the virtual canvas
1712 canvas = (void *)ecore_evas_buffer_pixels_get(handle->ee);
1714 ErrPrint("Failed to get pixel canvas\n");
1718 ecore_evas_geometry_get(handle->ee, &x, &y, &w, &h);
1719 evas_data_argb_unpremul(canvas, w * h);
1722 script_buffer_unlock(handle->buffer_handle);
1724 if (handle->render_post) {
1725 handle->render_post(handle->buffer_handle, handle->render_data);
1729 static void render_pre_cb(void *data, Evas *e, void *event_info)
1731 struct info *handle = data;
1734 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1736 ErrPrint("Acquired buffer is NULL\n");
1739 sw_render_pre_cb(data, handle->e, event_info);
1742 static void render_post_cb(void *data, Evas *e, void *event_info)
1744 struct info *handle = data;
1747 sw_render_post_cb(data, handle->e, event_info);
1748 canvas = script_buffer_pixmap_buffer(handle->buffer_handle);
1750 ErrPrint("Acquired buffer is NULL\n");
1752 script_buffer_pixmap_release_buffer(canvas);
1756 static void *alloc_fb(void *data, int size)
1758 struct info *handle = data;
1760 if (script_buffer_load(handle->buffer_handle) < 0) {
1761 ErrPrint("Failed to load buffer handler\n");
1765 return script_buffer_fb(handle->buffer_handle);
1768 static void *alloc_with_stride_fb(void *data, int size, int *stride, int *bpp)
1771 struct info *handle = data;
1775 canvas = alloc_fb(data, size);
1777 ErrPrint("Unable to allocate canvas buffer\n");
1780 _bpp = script_buffer_pixels(handle->buffer_handle);
1782 ErrPrint("Failed to get pixel size, fallback to 4\n");
1786 _stride = script_buffer_stride(handle->buffer_handle);
1790 ecore_evas_geometry_get(handle->ee, NULL, NULL, &w, NULL);
1793 ErrPrint("Failed to get stride info, fallback to %d\n", _stride);
1802 static void free_fb(void *data, void *ptr)
1804 struct info *handle = data;
1806 if (!handle->buffer_handle) {
1807 ErrPrint("Buffer is not valid (maybe already released)\n");
1811 if (script_buffer_fb(handle->buffer_handle) != ptr) {
1812 ErrPrint("Buffer pointer is not matched\n");
1815 (void)script_buffer_unload(handle->buffer_handle);
1818 static int destroy_ecore_evas(struct info *handle)
1821 return WIDGET_ERROR_NONE;
1823 ecore_evas_free(handle->ee);
1826 return WIDGET_ERROR_NONE;
1829 static int create_ecore_evas(struct info *handle, int *w, int *h)
1831 script_buffer_get_size(handle->buffer_handle, w, h);
1832 if (*w == 0 && *h == 0) {
1833 ErrPrint("ZERO size FB accessed\n");
1834 return WIDGET_ERROR_INVALID_PARAMETER;
1841 ecore_evas_geometry_get(handle->ee, NULL, NULL, &ow, &oh);
1842 if (*w != ow || *h != oh) {
1843 ErrPrint("EE exists, But different size - buffer_handle(%dx%d) -> ee(%dx%d)\n", ow, oh, *w, *h);
1844 ecore_evas_resize(handle->ee, *w, *h);
1847 return WIDGET_ERROR_NONE;
1850 if (!script_buffer_auto_align() && s_info.alloc_canvas_with_stride) {
1851 handle->ee = s_info.alloc_canvas_with_stride(*w, *h, alloc_with_stride_fb, free_fb, handle);
1852 } else if (s_info.alloc_canvas) {
1853 handle->ee = s_info.alloc_canvas(*w, *h, alloc_fb, free_fb, handle);
1855 ErrPrint("Failed to allocate canvas\n");
1856 return WIDGET_ERROR_FAULT;
1860 ErrPrint("Failed to create a buffer\n");
1861 return WIDGET_ERROR_FAULT;
1864 handle->e = ecore_evas_get(handle->ee);
1866 ErrPrint("Failed to get an Evas\n");
1867 ecore_evas_free(handle->ee);
1869 return WIDGET_ERROR_FAULT;
1872 if (script_buffer_type(handle->buffer_handle) == BUFFER_TYPE_PIXMAP) {
1875 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, render_pre_cb, handle);
1876 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, render_post_cb, handle);
1880 * ecore_evas_alpha_set tries to access the canvas buffer.
1881 * Without any render_pre/render_post callback.
1883 canvas = script_buffer_pixmap_acquire_buffer(handle->buffer_handle);
1885 ErrPrint("Acquired buffer is NULL\n");
1887 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1888 script_buffer_pixmap_release_buffer(canvas);
1891 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_PRE, sw_render_pre_cb, handle);
1892 evas_event_callback_add(handle->e, EVAS_CALLBACK_RENDER_POST, sw_render_post_cb, handle);
1893 ecore_evas_alpha_set(handle->ee, EINA_TRUE);
1896 ecore_evas_manual_render_set(handle->ee, EINA_FALSE);
1897 ecore_evas_resize(handle->ee, *w, *h);
1898 ecore_evas_show(handle->ee);
1899 ecore_evas_activate(handle->ee);
1901 return WIDGET_ERROR_NONE;
1904 PUBLIC int script_load(void *_handle, int (*render_pre)(void *buffer_handle, void *data), int (*render_post)(void *render_handle, void *data), void *data)
1906 struct info *handle;
1908 struct obj_info *obj_info;
1915 * Create "Ecore_Evas *"
1920 handle->render_pre = render_pre;
1921 handle->render_post = render_post;
1922 handle->render_data = data;
1924 ret = create_ecore_evas(handle, &w, &h);
1929 obj_info = calloc(1, sizeof(*obj_info));
1931 ErrPrint("Heap: %d\n", errno);
1932 destroy_ecore_evas(handle);
1933 return WIDGET_ERROR_OUT_OF_MEMORY;
1936 obj_info->parent = evas_object_rectangle_add(handle->e);
1937 if (!obj_info->parent) {
1938 ErrPrint("Unable to create a parent box\n");
1940 destroy_ecore_evas(handle);
1941 return WIDGET_ERROR_FAULT;
1944 edje = elm_layout_add(obj_info->parent);
1946 ErrPrint("Failed to create an edje object\n");
1947 evas_object_del(obj_info->parent);
1949 destroy_ecore_evas(handle);
1950 return WIDGET_ERROR_FAULT;
1953 edje_object_scale_set(elm_layout_edje_get(edje), elm_config_scale_get());
1955 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1958 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1959 if (err != EDJE_LOAD_ERROR_NONE) {
1960 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, edje_load_error_str(err));
1962 evas_object_del(edje);
1963 evas_object_del(obj_info->parent);
1965 destroy_ecore_evas(handle);
1966 return WIDGET_ERROR_IO_ERROR;
1969 handle->parent = edje;
1971 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1972 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1973 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1974 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1975 evas_object_resize(edje, w, h);
1976 evas_object_show(edje);
1977 evas_object_data_set(edje, "obj_info", obj_info);
1979 handle->obj_list = eina_list_append(handle->obj_list, edje);
1980 return WIDGET_ERROR_NONE;
1983 PUBLIC int script_unload(void *_handle)
1985 struct info *handle;
1989 * Destroy "Ecore_Evas *"
1994 if (handle->parent) {
1995 DbgPrint("Delete parent box\n");
1996 evas_object_del(handle->parent);
1999 (void)destroy_ecore_evas(handle);
2000 return WIDGET_ERROR_NONE;
2003 static void access_cb(keynode_t *node, void *user_data)
2008 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
2009 ErrPrint("Idle lock state is not valid\n");
2010 state = 0; /* DISABLED */
2013 state = vconf_keynode_get_bool(node);
2016 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
2017 elm_config_access_set(state);
2018 s_info.access_on = state;
2021 static void update_font_cb(void *data)
2023 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
2024 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
2027 static void font_changed_cb(keynode_t *node, void *user_data)
2033 if (s_info.font_name) {
2034 font_name = vconf_get_str("db/setting/accessibility/font_name");
2036 ErrPrint("Invalid font name (NULL)\n");
2040 if (!strcmp(s_info.font_name, font_name)) {
2041 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
2046 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
2047 free(s_info.font_name);
2052 * Get the first font name using system_settings API.
2055 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
2056 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
2057 ErrPrint("System setting get: %d, font_name[%p]\n", ret, font_name);
2062 s_info.font_name = font_name;
2063 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
2067 * Try to update all widgets
2069 update_font_cb(NULL);
2072 static inline int convert_font_size(int size)
2075 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
2078 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
2081 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
2084 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
2087 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
2095 DbgPrint("Return size: %d\n", size);
2099 static void font_size_cb(system_settings_key_e key, void *user_data)
2103 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE) {
2107 size = convert_font_size(size);
2109 if (size == s_info.font_size) {
2110 DbgPrint("Font size is not changed\n");
2114 s_info.font_size = size;
2115 DbgPrint("Font size is changed to %d, but don't update the font info\n", size);
2118 PUBLIC int script_init(double scale, int premultiplied)
2126 s_info.premultiplied = premultiplied;
2128 /* ecore is already initialized */
2130 elm_config_scale_set(scale);
2131 DbgPrint("Scale is updated: %lf\n", scale);
2133 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
2135 DbgPrint("TTS changed: %d\n", ret);
2138 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
2139 DbgPrint("System font is changed: %d\n", ret);
2141 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
2142 DbgPrint("System font size is changed: %d\n", ret);
2144 access_cb(NULL, NULL);
2145 font_changed_cb(NULL, NULL);
2146 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
2148 s_info.alloc_canvas_with_stride = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_with_stride_new");
2149 if (!s_info.alloc_canvas_with_stride) {
2150 DbgPrint("Fallback to allocfunc_new\n");
2153 s_info.alloc_canvas = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_new");
2154 if (!s_info.alloc_canvas) {
2155 ErrPrint("No way to allocate canvas\n");
2158 return WIDGET_ERROR_NONE;
2161 PUBLIC int script_fini(void)
2166 struct info *handle;
2168 EINA_LIST_FOREACH_SAFE(s_info.handle_list, l, n, handle) {
2169 script_destroy(handle);
2172 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
2174 DbgPrint("Unset font size change event callback: %d\n", ret);
2177 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
2179 DbgPrint("Unset font name change event callback: %d\n", ret);
2182 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
2184 DbgPrint("Unset tts: %d\n", ret);
2189 free(s_info.font_name);
2190 s_info.font_name = NULL;
2191 return WIDGET_ERROR_NONE;