2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <Elementary.h>
28 #include <Ecore_Evas.h>
35 #include <livebox-errno.h>
36 #include <livebox-service.h>
38 #include "script_port.h"
40 #define TEXT_CLASS "tizen"
41 #define BASE_WIDTH 720.0f
43 #define PUBLIC __attribute__((visibility("default")))
79 Eina_List *access_chain;
82 static inline double scale_get(void)
86 ecore_x_window_size_get(0, &width, &height);
87 return (double)width / BASE_WIDTH;
90 static inline Evas_Object *find_edje(struct info *handle, const char *id)
94 struct obj_info *obj_info;
96 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
97 obj_info = evas_object_data_get(edje, "obj_info");
99 ErrPrint("Object info is not valid\n");
108 } else if (!obj_info->id) {
112 if (!strcmp(obj_info->id, id))
116 DbgPrint("EDJE[%s] is not found\n", id);
120 static inline void rebuild_focus_chain(Evas_Object *obj)
122 struct obj_info *obj_info;
126 obj_info = evas_object_data_get(obj, "obj_info");
128 ErrPrint("Object info is not available\n");
132 elm_object_focus_custom_chain_unset(obj);
134 DbgPrint("Rebuild focus chain begin\n");
135 EINA_LIST_FOREACH(obj_info->access_chain, l, ao) {
136 DbgPrint("Append %p\n", ao);
137 elm_object_focus_custom_chain_append(obj, ao, NULL);
139 DbgPrint("Rebuild focus chain done\n");
142 PUBLIC const char *script_magic_id(void)
147 PUBLIC int script_update_color(void *h, Evas *e, const char *id, const char *part, const char *rgba)
149 struct info *handle = h;
151 int r[3], g[3], b[3], a[3];
154 edje = find_edje(handle, id);
156 return LB_STATUS_ERROR_NOT_EXIST;
158 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
159 r, g, b, a, /* OBJECT */
160 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
161 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
163 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
164 return LB_STATUS_ERROR_INVALID;
167 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
168 r[0], g[0], b[0], a[0], /* OBJECT */
169 r[1], g[1], b[1], a[1], /* OUTLINE */
170 r[2], g[2], b[2], a[2]); /* SHADOW */
172 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
173 return LB_STATUS_SUCCESS;
176 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
188 ao = evas_object_data_get(part_obj, "ao");
192 edje = evas_object_data_get(ao, "edje");
196 e = evas_object_evas_get(part_obj);
197 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
201 if (gettimeofday(&tv, NULL) < 0) {
202 ErrPrint("Failed to get time\n");
205 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
208 DbgPrint("Cursor is on %dx%d\n", x, y);
209 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
210 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
211 evas_event_feed_mouse_move(e, x, y, timestamp + 0.02f, NULL);
212 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.03f, NULL);
215 PUBLIC int script_update_text(void *h, Evas *e, const char *id, const char *part, const char *text)
217 struct obj_info *obj_info;
218 struct info *handle = h;
222 edje = find_edje(handle, id);
224 ErrPrint("Failed to find EDJE\n");
225 return LB_STATUS_ERROR_NOT_EXIST;
228 obj_info = evas_object_data_get(edje, "obj_info");
230 ErrPrint("Object info is not available\n");
231 return LB_STATUS_ERROR_FAULT;
234 elm_object_part_text_set(edje, part, text ? text : "");
236 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
241 ao = evas_object_data_get(to, "ao");
243 ao = elm_access_object_register(to, edje);
245 ErrPrint("Unable to add ao: %s\n", part);
248 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
249 evas_object_data_set(to, "ao", ao);
250 evas_object_data_set(ao, "edje", edje);
251 elm_access_activate_cb_set(ao, activate_cb, NULL);
252 elm_object_focus_custom_chain_append(edje, ao, NULL);
255 if (!text || !strlen(text)) {
256 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
257 evas_object_data_del(to, "ao");
258 evas_object_data_del(ao, "edje");
259 elm_access_object_unregister(ao);
260 DbgPrint("[%s] Remove access object\n", part);
262 rebuild_focus_chain(edje);
266 utf8 = elm_entry_markup_to_utf8(text);
267 if ((!utf8 || !strlen(utf8))) {
270 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
271 evas_object_data_del(to, "ao");
272 evas_object_data_del(ao, "edje");
273 elm_access_object_unregister(ao);
274 DbgPrint("[%s] Remove access object\n", part);
276 rebuild_focus_chain(edje);
280 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
281 DbgPrint("[%s] Update access object (%s)\n", part, utf8);
284 ErrPrint("Unable to get text part[%s]\n", part);
288 return LB_STATUS_SUCCESS;
291 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
293 while (len > 0 && *value == ' ') {
301 img_opt->aspect = !strncasecmp(value, "true", 4);
302 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
305 static void parse_orient(struct image_option *img_opt, const char *value, int len)
307 while (len > 0 && *value == ' ') {
315 img_opt->orient = !strncasecmp(value, "true", 4);
316 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->aspect, value);
319 static void parse_size(struct image_option *img_opt, const char *value, int len)
325 while (len > 0 && *value == ' ') {
330 buf = strndup(value, len);
332 ErrPrint("Heap: %s\n", strerror(errno));
336 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
337 img_opt->width = width;
338 img_opt->height = height;
339 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
341 DbgPrint("Invalid size tag[%s]\n", buf);
347 static void parse_fill(struct image_option *img_opt, const char *value, int len)
349 while (len > 0 && *value == ' ') {
354 if (!strncasecmp(value, "in-size", len))
355 img_opt->fill = FILL_IN_SIZE;
356 else if (!strncasecmp(value, "over-size", len))
357 img_opt->fill = FILL_OVER_SIZE;
359 img_opt->fill = FILL_DISABLE;
361 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
364 static inline void parse_image_option(const char *option, struct image_option *img_opt)
371 void (*handler)(struct image_option *img_opt, const char *value, int len);
374 .cmd = "aspect", /* Keep the aspect ratio */
375 .handler = parse_aspect,
378 .cmd = "orient", /* Keep the orientation value: for the rotated images */
379 .handler = parse_orient,
382 .cmd = "fill", /* Fill the image to its container */
383 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
387 .handler = parse_size,
401 if (!option || !*option)
407 * GCC 4.7 warnings uninitialized idx and tag value.
408 * But it will be initialized by the state machine. :(
409 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
416 for (ptr = option; state != STATE_END; ptr++) {
431 cmd = cmd_list[tag].cmd;
437 } else if (*ptr == '\0') {
442 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
447 state = STATE_IGNORE;
450 } else if (*ptr == '\0') {
452 } else if (cmd[idx] == *ptr) {
458 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
462 cmd = cmd_list[tag].cmd;
468 if (*ptr == ';' || *ptr == '\0') {
469 cmd_list[tag].handler(img_opt, value + 1, idx);
470 state = *ptr ? STATE_START : STATE_END;
478 else if (*ptr == '\0')
487 PUBLIC int script_update_access(void *_h, Evas *e, const char *id, const char *part, const char *text, const char *option)
489 struct info *handle = _h;
491 struct obj_info *obj_info;
494 edje = find_edje(handle, id);
496 ErrPrint("No such object: %s\n", id);
497 return LB_STATUS_ERROR_NOT_EXIST;
500 obj_info = evas_object_data_get(edje, "obj_info");
502 ErrPrint("Object info is not available\n");
503 return LB_STATUS_ERROR_FAULT;
506 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
510 ao = evas_object_data_get(to, "ao");
512 DbgPrint("[%s] Update access object (%s)\n", part, text);
513 if (text && strlen(text)) {
514 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
516 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
517 evas_object_data_del(to, "ao");
518 evas_object_data_del(ao, "edje");
519 elm_access_object_unregister(ao);
520 DbgPrint("Successfully unregistered\n");
522 rebuild_focus_chain(edje);
524 } else if (text && strlen(text)) {
525 ao = elm_access_object_register(to, edje);
527 ErrPrint("Unable to register access object\n");
529 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
530 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
531 evas_object_data_set(to, "ao", ao);
532 elm_object_focus_custom_chain_append(edje, ao, NULL);
533 DbgPrint("[%s] Register access info: (%s)\n", part, text);
534 evas_object_data_set(ao, "edje", edje);
535 elm_access_activate_cb_set(ao, activate_cb, NULL);
539 ErrPrint("[%s] is not exists\n", part);
542 return LB_STATUS_SUCCESS;
545 PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path, const char *option)
547 struct info *handle = _h;
552 struct obj_info *obj_info;
554 struct image_option img_opt = {
557 .fill = FILL_DISABLE,
562 edje = find_edje(handle, id);
564 ErrPrint("No such object: %s\n", id);
565 return LB_STATUS_ERROR_NOT_EXIST;
568 obj_info = evas_object_data_get(edje, "obj_info");
570 ErrPrint("Object info is not available\n");
571 return LB_STATUS_ERROR_FAULT;
574 img = elm_object_part_content_unset(edje, part);
580 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
581 if (child->obj != img)
584 obj_info->children = eina_list_remove(obj_info->children, child);
590 DbgPrint("delete object %s %p\n", part, img);
591 ao = evas_object_data_del(img, "ao");
593 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
594 evas_object_data_del(ao, "edje");
595 elm_access_object_unregister(ao);
596 DbgPrint("Successfully unregistered\n");
598 evas_object_del(img);
600 rebuild_focus_chain(edje);
603 if (!path || !strlen(path) || access(path, R_OK) != 0) {
604 DbgPrint("SKIP - Path: [%s]\n", path);
605 return LB_STATUS_SUCCESS;
608 child = malloc(sizeof(*child));
610 ErrPrint("Heap: %s\n", strerror(errno));
611 return LB_STATUS_ERROR_MEMORY;
614 child->part = strdup(part);
616 ErrPrint("Heap: %s\n", strerror(errno));
618 return LB_STATUS_ERROR_MEMORY;
621 img = evas_object_image_add(e);
623 ErrPrint("Failed to add an image object\n");
626 return LB_STATUS_ERROR_FAULT;
629 evas_object_image_preload(img, EINA_FALSE);
630 parse_image_option(option, &img_opt);
631 evas_object_image_load_orientation_set(img, img_opt.orient);
633 evas_object_image_file_set(img, path, NULL);
634 err = evas_object_image_load_error_get(img);
635 if (err != EVAS_LOAD_ERROR_NONE) {
636 ErrPrint("Load error: %s\n", evas_load_error_str(err));
637 evas_object_del(img);
640 return LB_STATUS_ERROR_IO;
643 evas_object_image_size_get(img, &w, &h);
644 if (img_opt.aspect) {
645 if (img_opt.fill == FILL_OVER_SIZE) {
649 if (img_opt.width >= 0 && img_opt.height >= 0) {
650 part_w = img_opt.width * scale_get();
651 part_h = img_opt.height * scale_get();
655 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
657 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
659 if (part_w > w || part_h > h) {
663 fw = (double)part_w / (double)w;
664 fh = (double)part_h / (double)h;
674 DbgPrint("Size: %dx%d\n", w, h);
676 evas_object_image_load_size_set(img, w, h);
677 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
678 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
679 evas_object_image_reload(img);
681 evas_object_image_fill_set(img, 0, 0, w, h);
682 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
683 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
686 if (img_opt.width >= 0 && img_opt.height >= 0) {
689 DbgPrint("Using given image size: %dx%d\n", w, h);
692 evas_object_image_fill_set(img, 0, 0, w, h);
693 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
694 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
699 * object will be shown by below statement automatically
701 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
703 elm_object_part_content_set(edje, part, img);
704 obj_info->children = eina_list_append(obj_info->children, child);
708 * This object is not registered as an access object.
709 * So the developer should add it to access list manually, using DESC_ACCESS block.
711 return LB_STATUS_SUCCESS;
714 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
716 struct info *handle = data;
728 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
729 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
733 sx = (double)px / (double)w;
734 ex = (double)(px + pw) / (double)w;
739 sy = (double)py / (double)h;
740 ey = (double)(py + ph) / (double)h;
743 DbgPrint("Signal emit: source[%s], emission[%s]\n", source, emission);
744 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
747 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
749 struct info *handle = _info;
750 struct obj_info *obj_info;
754 handle->obj_list = eina_list_remove(handle->obj_list, obj);
756 obj_info = evas_object_data_del(obj, "obj_info");
758 ErrPrint("Object info is not valid\n");
762 DbgPrint("delete object %s %p\n", obj_info->id, obj);
764 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
766 elm_object_focus_custom_chain_unset(obj);
768 EINA_LIST_FREE(obj_info->children, child) {
769 DbgPrint("delete object %s %p\n", child->part, child->obj);
772 ao = evas_object_data_del(child->obj, "ao");
774 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
775 evas_object_data_del(ao, "edje");
776 elm_access_object_unregister(ao);
778 evas_object_del(child->obj);
784 EINA_LIST_FREE(obj_info->access_chain, ao) {
785 evas_object_data_del(ao, "edje");
786 elm_access_object_unregister(ao);
794 LB_ACCESS_HIGHLIGHT 0
795 LB_ACCESS_HIGHLIGHT_NEXT 1
796 LB_ACCESS_HIGHLIGHT_PREV 2
798 LB_ACCESS_VALUE_CHANGE 4
801 PUBLIC int script_feed_event(void *h, Evas *e, int event_type, int x, int y, double timestamp)
803 struct info *handle = h;
805 struct obj_info *obj_info;
806 int ret = LB_STATUS_SUCCESS;
808 DbgPrint("event: %d, x: %d, y: %d\n", event_type, x, y);
810 edje = find_edje(handle, NULL); /*!< Get the base layout */
812 ErrPrint("Base layout is not exist\n");
813 return LB_STATUS_ERROR_NOT_EXIST;
816 obj_info = evas_object_data_get(edje, "obj_info");
818 ErrPrint("Object info is not valid\n");
819 return LB_STATUS_ERROR_INVALID;
822 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
823 Elm_Access_Action_Info *info;
824 Elm_Access_Action_Type action;
825 const Eina_List *chain;
827 info = calloc(1, sizeof(*info));
829 ErrPrint("Error: %s\n", strerror(errno));
830 return LB_STATUS_ERROR_MEMORY;
833 chain = elm_object_focus_custom_chain_get(edje);
834 DbgPrint("Focus chain : %d\n", eina_list_count(chain));
836 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
837 action = ELM_ACCESS_ACTION_HIGHLIGHT;
840 ret = elm_access_action(edje, action, info);
841 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
842 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
843 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
844 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
845 info->highlight_cycle = EINA_FALSE;
846 ret = elm_access_action(edje, action, info);
847 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
848 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
849 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
850 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
851 info->highlight_cycle = EINA_FALSE;
852 ret = elm_access_action(edje, action, info);
853 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
854 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
855 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
856 action = ELM_ACCESS_ACTION_ACTIVATE;
857 ret = elm_access_action(edje, action, info);
858 DbgPrint("ACCESS_HIGHLIGHT_ACTIVATE, returns %d\n", ret);
859 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
860 } else if ((event_type & LB_SCRIPT_ACCESS_VALUE_CHANGE) == LB_SCRIPT_ACCESS_VALUE_CHANGE) {
861 action = ELM_ACCESS_ACTION_VALUE_CHANGE;
862 ret = elm_access_action(edje, action, info);
863 DbgPrint("ACCESS_HIGHLIGHT_VALUE_CHANGE, returns %d\n", ret);
864 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
865 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
866 action = ELM_ACCESS_ACTION_SCROLL;
867 ret = elm_access_action(edje, action, info);
868 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
869 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
870 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
871 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
872 ret = elm_access_action(edje, action, info);
873 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
874 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
876 DbgPrint("Invalid event\n");
877 ret = LB_ACCESS_STATUS_ERROR;
881 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
882 switch (event_type) {
883 case LB_SCRIPT_MOUSE_DOWN:
884 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
885 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
887 case LB_SCRIPT_MOUSE_MOVE:
888 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
890 case LB_SCRIPT_MOUSE_UP:
891 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
892 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.1f, NULL);
894 case LB_SCRIPT_MOUSE_IN:
895 evas_event_feed_mouse_in(e, timestamp, NULL);
897 case LB_SCRIPT_MOUSE_OUT:
898 evas_event_feed_mouse_out(e, timestamp, NULL);
901 return LB_STATUS_ERROR_INVALID;
903 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
904 DbgPrint("Key event is not implemented\n");
905 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
911 PUBLIC int script_update_script(void *h, Evas *e, const char *src_id, const char *target_id, const char *part, const char *path, const char *group)
913 struct info *handle = h;
916 struct obj_info *obj_info;
919 DbgPrint("src_id[%s] target_id[%s] part[%s] path[%s] group[%s]\n", src_id, target_id, part, path, group);
921 edje = find_edje(handle, src_id);
923 ErrPrint("Edje is not exists\n");
924 return LB_STATUS_ERROR_NOT_EXIST;
927 obj_info = evas_object_data_get(edje, "obj_info");
929 ErrPrint("Object info is not valid\n");
930 return LB_STATUS_ERROR_INVALID;
933 obj = elm_object_part_content_unset(edje, part);
938 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
939 if (child->obj != obj)
942 obj_info->children = eina_list_remove(obj_info->children, child);
949 DbgPrint("delete object %s %p\n", part, obj);
952 * This will call the edje_del_cb.
953 * It will delete all access objects
955 evas_object_del(obj);
958 if (!path || !strlen(path) || access(path, R_OK) != 0) {
959 DbgPrint("SKIP - Path: [%s]\n", path);
960 return LB_STATUS_SUCCESS;
963 obj = elm_layout_add(edje);
965 ErrPrint("Failed to add a new edje object\n");
966 return LB_STATUS_ERROR_FAULT;
969 if (!elm_layout_file_set(obj, path, group)) {
973 err = edje_object_load_error_get(elm_layout_edje_get(obj));
974 errmsg = edje_load_error_str(err);
975 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
976 evas_object_del(obj);
977 return LB_STATUS_ERROR_IO;
980 evas_object_show(obj);
982 obj_info = calloc(1, sizeof(*obj_info));
984 ErrPrint("Failed to add a obj_info\n");
985 evas_object_del(obj);
986 return LB_STATUS_ERROR_MEMORY;
989 obj_info->id = strdup(target_id);
991 ErrPrint("Failed to add a obj_info\n");
993 evas_object_del(obj);
994 return LB_STATUS_ERROR_MEMORY;
997 child = malloc(sizeof(*child));
999 ErrPrint("Error: %s\n", strerror(errno));
1002 evas_object_del(obj);
1003 return LB_STATUS_ERROR_MEMORY;
1006 child->part = strdup(part);
1008 ErrPrint("Error: %s\n", strerror(errno));
1012 evas_object_del(obj);
1013 return LB_STATUS_ERROR_MEMORY;
1018 evas_object_data_set(obj, "obj_info", obj_info);
1019 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1020 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1021 handle->obj_list = eina_list_append(handle->obj_list, obj);
1023 DbgPrint("%s part swallow edje %p\n", part, obj);
1024 elm_object_part_content_set(edje, part, obj);
1025 obj_info = evas_object_data_get(edje, "obj_info");
1026 obj_info->children = eina_list_append(obj_info->children, child);
1027 return LB_STATUS_SUCCESS;
1030 PUBLIC int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
1032 struct info *handle = h;
1035 DbgPrint("id[%s], part[%s], signal[%s]\n", id, part, signal);
1037 edje = find_edje(handle, id);
1039 return LB_STATUS_ERROR_NOT_EXIST;
1041 elm_object_signal_emit(edje, signal, part);
1042 return LB_STATUS_SUCCESS;
1045 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1047 struct info *handle = h;
1050 DbgPrint("id[%s], part[%s], %lfx%lf\n", id, part, x, y);
1052 edje = find_edje(handle, id);
1054 return LB_STATUS_ERROR_NOT_EXIST;
1056 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1057 return LB_STATUS_SUCCESS;
1060 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1062 struct info *handle = han;
1065 edje = find_edje(handle, id);
1067 return LB_STATUS_ERROR_NOT_EXIST;
1074 DbgPrint("Resize object to %dx%d\n", w, h);
1075 evas_object_resize(edje, w, h);
1076 return LB_STATUS_SUCCESS;
1079 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1081 struct info *handle = h;
1083 DbgPrint("id[%s], category[%s]\n", id, category);
1085 if (handle->category) {
1086 free(handle->category);
1087 handle->category = NULL;
1091 return LB_STATUS_SUCCESS;
1093 handle->category = strdup(category);
1094 if (!handle->category) {
1095 ErrPrint("Error: %s\n", strerror(errno));
1096 return LB_STATUS_ERROR_MEMORY;
1099 return LB_STATUS_SUCCESS;
1102 PUBLIC void *script_create(const char *file, const char *group)
1104 struct info *handle;
1106 DbgPrint("file[%s], group[%s]\n", file, group);
1108 handle = calloc(1, sizeof(*handle));
1110 ErrPrint("Error: %s\n", strerror(errno));
1114 handle->file = strdup(file);
1115 if (!handle->file) {
1116 ErrPrint("Error: %s\n", strerror(errno));
1121 handle->group = strdup(group);
1122 if (!handle->group) {
1123 ErrPrint("Error: %s\n", strerror(errno));
1132 PUBLIC int script_destroy(void *_handle)
1134 struct info *handle;
1139 edje = eina_list_nth(handle->obj_list, 0);
1141 evas_object_del(edje);
1143 free(handle->category);
1145 free(handle->group);
1147 return LB_STATUS_SUCCESS;
1150 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1152 struct info *handle;
1154 struct obj_info *obj_info;
1158 obj_info = calloc(1, sizeof(*obj_info));
1160 ErrPrint("Heap: %s\n", strerror(errno));
1161 return LB_STATUS_ERROR_MEMORY;
1164 obj_info->win = evas_object_rectangle_add(e);
1165 if (!obj_info->win) {
1167 return LB_STATUS_ERROR_FAULT;
1170 edje = elm_layout_add(obj_info->win);
1172 ErrPrint("Failed to create an edje object\n");
1173 evas_object_del(obj_info->win);
1175 return LB_STATUS_ERROR_FAULT;
1178 DbgPrint("Load edje: %s - %s\n", handle->file, handle->group);
1179 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1183 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1184 errmsg = edje_load_error_str(err);
1185 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
1186 evas_object_del(edje);
1187 evas_object_del(obj_info->win);
1189 return LB_STATUS_ERROR_IO;
1196 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1197 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1198 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1199 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1200 evas_object_resize(edje, handle->w, handle->h);
1201 evas_object_show(edje);
1202 evas_object_data_set(edje, "obj_info", obj_info);
1204 handle->obj_list = eina_list_append(handle->obj_list, edje);
1205 return LB_STATUS_SUCCESS;
1208 PUBLIC int script_unload(void *_handle, Evas *e)
1210 struct info *handle;
1215 DbgPrint("Unload edje: %s - %s\n", handle->file, handle->group);
1216 edje = eina_list_nth(handle->obj_list, 0);
1218 evas_object_del(edje);
1220 return LB_STATUS_SUCCESS;
1223 static void access_cb(keynode_t *node, void *user_data)
1228 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1229 ErrPrint("Idle lock state is not valid\n");
1230 state = 0; /* DISABLED */
1233 state = vconf_keynode_get_bool(node);
1236 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1237 elm_config_access_set(state);
1240 PUBLIC int script_init(void)
1247 /* ecore is already initialized */
1249 elm_config_scale_set(scale_get());
1251 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1253 ErrPrint("Failed to access cb\n");
1255 access_cb(NULL, NULL);
1256 return LB_STATUS_SUCCESS;
1259 PUBLIC int script_fini(void)
1261 vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1263 return LB_STATUS_SUCCESS;