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://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <Elementary.h>
28 #include <Ecore_Evas.h>
32 #include <system_settings.h>
37 #include <livebox-errno.h>
38 #include <livebox-service.h>
40 #include "script_port.h"
42 #define TEXT_CLASS "tizen"
43 #define BASE_WIDTH 720.0f
45 #define PUBLIC __attribute__((visibility("default")))
81 Eina_List *access_chain;
92 static inline double scale_get(void)
96 ecore_x_window_size_get(0, &width, &height);
97 return (double)width / BASE_WIDTH;
100 static inline Evas_Object *find_edje(struct info *handle, const char *id)
104 struct obj_info *obj_info;
106 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
107 obj_info = evas_object_data_get(edje, "obj_info");
109 ErrPrint("Object info is not valid\n");
118 } else if (!obj_info->id) {
122 if (!strcmp(obj_info->id, id))
126 DbgPrint("EDJE[%s] is not found\n", id);
130 static inline void rebuild_focus_chain(Evas_Object *obj)
132 struct obj_info *obj_info;
136 obj_info = evas_object_data_get(obj, "obj_info");
138 ErrPrint("Object info is not available\n");
142 elm_object_focus_custom_chain_unset(obj);
144 DbgPrint("Rebuild focus chain begin\n");
145 EINA_LIST_FOREACH(obj_info->access_chain, l, ao) {
146 DbgPrint("Append %p\n", ao);
147 elm_object_focus_custom_chain_append(obj, ao, NULL);
149 DbgPrint("Rebuild focus chain done\n");
152 PUBLIC const char *script_magic_id(void)
157 PUBLIC int script_update_color(void *h, Evas *e, const char *id, const char *part, const char *rgba)
159 struct info *handle = h;
161 int r[3], g[3], b[3], a[3];
164 edje = find_edje(handle, id);
166 return LB_STATUS_ERROR_NOT_EXIST;
168 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
169 r, g, b, a, /* OBJECT */
170 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
171 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
173 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
174 return LB_STATUS_ERROR_INVALID;
177 ret = edje_object_color_class_set(elm_layout_edje_get(edje), part,
178 r[0], g[0], b[0], a[0], /* OBJECT */
179 r[1], g[1], b[1], a[1], /* OUTLINE */
180 r[2], g[2], b[2], a[2]); /* SHADOW */
182 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
183 return LB_STATUS_SUCCESS;
186 static void activate_cb(void *data, Evas_Object *part_obj, Elm_Object_Item *item)
198 ao = evas_object_data_get(part_obj, "ao");
202 edje = evas_object_data_get(ao, "edje");
206 e = evas_object_evas_get(part_obj);
207 evas_object_geometry_get(part_obj, &x, &y, &w, &h);
211 if (gettimeofday(&tv, NULL) < 0) {
212 ErrPrint("Failed to get time\n");
215 timestamp = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
218 DbgPrint("Cursor is on %dx%d\n", x, y);
219 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
220 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
221 evas_event_feed_mouse_move(e, x, y, timestamp + 0.02f, NULL);
222 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.03f, NULL);
225 PUBLIC int script_update_text(void *h, Evas *e, const char *id, const char *part, const char *text)
227 struct obj_info *obj_info;
228 struct info *handle = h;
232 edje = find_edje(handle, id);
234 ErrPrint("Failed to find EDJE\n");
235 return LB_STATUS_ERROR_NOT_EXIST;
238 obj_info = evas_object_data_get(edje, "obj_info");
240 ErrPrint("Object info is not available\n");
241 return LB_STATUS_ERROR_FAULT;
244 elm_object_part_text_set(edje, part, text ? text : "");
246 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
251 ao = evas_object_data_get(to, "ao");
253 ao = elm_access_object_register(to, edje);
255 ErrPrint("Unable to add ao: %s\n", part);
258 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
259 evas_object_data_set(to, "ao", ao);
260 evas_object_data_set(ao, "edje", edje);
261 elm_access_activate_cb_set(ao, activate_cb, NULL);
262 elm_object_focus_custom_chain_append(edje, ao, NULL);
265 if (!text || !strlen(text)) {
266 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
267 evas_object_data_del(to, "ao");
268 evas_object_data_del(ao, "edje");
269 elm_access_object_unregister(ao);
270 DbgPrint("[%s] Remove access object\n", part);
272 rebuild_focus_chain(edje);
276 utf8 = elm_entry_markup_to_utf8(text);
277 if ((!utf8 || !strlen(utf8))) {
280 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
281 evas_object_data_del(to, "ao");
282 evas_object_data_del(ao, "edje");
283 elm_access_object_unregister(ao);
284 DbgPrint("[%s] Remove access object\n", part);
286 rebuild_focus_chain(edje);
290 elm_access_info_set(ao, ELM_ACCESS_INFO, utf8);
291 DbgPrint("[%s] Update access object (%s)\n", part, utf8);
294 ErrPrint("Unable to get text part[%s]\n", part);
298 return LB_STATUS_SUCCESS;
301 static void parse_aspect(struct image_option *img_opt, const char *value, int len)
303 while (len > 0 && *value == ' ') {
311 img_opt->aspect = !strncasecmp(value, "true", 4);
312 DbgPrint("Parsed ASPECT: %d (%s)\n", img_opt->aspect, value);
315 static void parse_orient(struct image_option *img_opt, const char *value, int len)
317 while (len > 0 && *value == ' ') {
325 img_opt->orient = !strncasecmp(value, "true", 4);
326 DbgPrint("Parsed ORIENT: %d (%s)\n", img_opt->orient, value);
329 static void parse_size(struct image_option *img_opt, const char *value, int len)
335 while (len > 0 && *value == ' ') {
340 buf = strndup(value, len);
342 ErrPrint("Heap: %s\n", strerror(errno));
346 if (sscanf(buf, "%dx%d", &width, &height) == 2) {
347 img_opt->width = width;
348 img_opt->height = height;
349 DbgPrint("Parsed size : %dx%d (%s)\n", width, height, buf);
351 DbgPrint("Invalid size tag[%s]\n", buf);
357 static void parse_fill(struct image_option *img_opt, const char *value, int len)
359 while (len > 0 && *value == ' ') {
364 if (!strncasecmp(value, "in-size", len))
365 img_opt->fill = FILL_IN_SIZE;
366 else if (!strncasecmp(value, "over-size", len))
367 img_opt->fill = FILL_OVER_SIZE;
369 img_opt->fill = FILL_DISABLE;
371 DbgPrint("Parsed FILL: %d (%s)\n", img_opt->fill, value);
374 static inline void parse_image_option(const char *option, struct image_option *img_opt)
381 void (*handler)(struct image_option *img_opt, const char *value, int len);
384 .cmd = "aspect", /* Keep the aspect ratio */
385 .handler = parse_aspect,
388 .cmd = "orient", /* Keep the orientation value: for the rotated images */
389 .handler = parse_orient,
392 .cmd = "fill", /* Fill the image to its container */
393 .handler = parse_fill, /* Value: in-size, over-size, disable(default) */
397 .handler = parse_size,
411 if (!option || !*option)
417 * GCC 4.7 warnings uninitialized idx and tag value.
418 * But it will be initialized by the state machine. :(
419 * Anyway, I just reset idx and tag for reducing the GCC4.7 complains.
426 for (ptr = option; state != STATE_END; ptr++) {
441 cmd = cmd_list[tag].cmd;
447 } else if (*ptr == '\0') {
452 if (cmd[idx] == '\0' && (*ptr == ' ' || *ptr == '\t' || *ptr == '=')) {
457 state = STATE_IGNORE;
460 } else if (*ptr == '\0') {
462 } else if (cmd[idx] == *ptr) {
468 if (tag == sizeof(cmd_list) / sizeof(cmd_list[0])) {
472 cmd = cmd_list[tag].cmd;
478 if (*ptr == ';' || *ptr == '\0') {
479 cmd_list[tag].handler(img_opt, value + 1, idx);
480 state = *ptr ? STATE_START : STATE_END;
488 else if (*ptr == '\0')
497 PUBLIC int script_update_access(void *_h, Evas *e, const char *id, const char *part, const char *text, const char *option)
499 struct info *handle = _h;
501 struct obj_info *obj_info;
504 edje = find_edje(handle, id);
506 ErrPrint("No such object: %s\n", id);
507 return LB_STATUS_ERROR_NOT_EXIST;
510 obj_info = evas_object_data_get(edje, "obj_info");
512 ErrPrint("Object info is not available\n");
513 return LB_STATUS_ERROR_FAULT;
516 to = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(edje), part);
520 ao = evas_object_data_get(to, "ao");
522 DbgPrint("[%s] Update access object (%s)\n", part, text);
523 if (text && strlen(text)) {
524 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
526 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
527 evas_object_data_del(to, "ao");
528 evas_object_data_del(ao, "edje");
529 elm_access_object_unregister(ao);
530 DbgPrint("Successfully unregistered\n");
532 rebuild_focus_chain(edje);
534 } else if (text && strlen(text)) {
535 ao = elm_access_object_register(to, edje);
537 ErrPrint("Unable to register access object\n");
539 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
540 obj_info->access_chain = eina_list_append(obj_info->access_chain, ao);
541 evas_object_data_set(to, "ao", ao);
542 elm_object_focus_custom_chain_append(edje, ao, NULL);
543 DbgPrint("[%s] Register access info: (%s)\n", part, text);
544 evas_object_data_set(ao, "edje", edje);
545 elm_access_activate_cb_set(ao, activate_cb, NULL);
549 ErrPrint("[%s] is not exists\n", part);
552 return LB_STATUS_SUCCESS;
555 PUBLIC int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path, const char *option)
557 struct info *handle = _h;
562 struct obj_info *obj_info;
564 struct image_option img_opt = {
567 .fill = FILL_DISABLE,
572 edje = find_edje(handle, id);
574 ErrPrint("No such object: %s\n", id);
575 return LB_STATUS_ERROR_NOT_EXIST;
578 obj_info = evas_object_data_get(edje, "obj_info");
580 ErrPrint("Object info is not available\n");
581 return LB_STATUS_ERROR_FAULT;
584 img = elm_object_part_content_unset(edje, part);
590 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
591 if (child->obj != img)
594 obj_info->children = eina_list_remove(obj_info->children, child);
600 DbgPrint("delete object %s %p\n", part, img);
601 ao = evas_object_data_del(img, "ao");
603 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
604 evas_object_data_del(ao, "edje");
605 elm_access_object_unregister(ao);
606 DbgPrint("Successfully unregistered\n");
608 evas_object_del(img);
610 rebuild_focus_chain(edje);
613 if (!path || !strlen(path) || access(path, R_OK) != 0) {
614 DbgPrint("SKIP - Path: [%s]\n", path);
615 return LB_STATUS_SUCCESS;
618 child = malloc(sizeof(*child));
620 ErrPrint("Heap: %s\n", strerror(errno));
621 return LB_STATUS_ERROR_MEMORY;
624 child->part = strdup(part);
626 ErrPrint("Heap: %s\n", strerror(errno));
628 return LB_STATUS_ERROR_MEMORY;
631 img = evas_object_image_add(e);
633 ErrPrint("Failed to add an image object\n");
636 return LB_STATUS_ERROR_FAULT;
639 evas_object_image_preload(img, EINA_FALSE);
640 parse_image_option(option, &img_opt);
641 evas_object_image_load_orientation_set(img, img_opt.orient);
643 evas_object_image_file_set(img, path, NULL);
644 err = evas_object_image_load_error_get(img);
645 if (err != EVAS_LOAD_ERROR_NONE) {
646 ErrPrint("Load error: %s\n", evas_load_error_str(err));
647 evas_object_del(img);
650 return LB_STATUS_ERROR_IO;
653 evas_object_image_size_get(img, &w, &h);
654 if (img_opt.aspect) {
655 if (img_opt.fill == FILL_OVER_SIZE) {
659 if (img_opt.width >= 0 && img_opt.height >= 0) {
660 part_w = img_opt.width * scale_get();
661 part_h = img_opt.height * scale_get();
665 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
667 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
669 if (part_w > w || part_h > h) {
673 fw = (double)part_w / (double)w;
674 fh = (double)part_h / (double)h;
684 DbgPrint("Size: %dx%d\n", w, h);
686 evas_object_image_load_size_set(img, w, h);
687 evas_object_image_load_region_set(img, (w - part_w) / 2, (h - part_h) / 2, part_w, part_h);
688 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
689 evas_object_image_reload(img);
690 } else if (img_opt.fill == FILL_IN_SIZE) {
694 if (img_opt.width >= 0 && img_opt.height >= 0) {
695 part_w = img_opt.width * scale_get();
696 part_h = img_opt.height * scale_get();
700 edje_object_part_geometry_get(elm_layout_edje_get(edje), part, NULL, NULL, &part_w, &part_h);
702 DbgPrint("Original %dx%d (part: %dx%d)\n", w, h, part_w, part_h);
704 if (part_w > w || part_h > h) {
708 fw = (double)part_w / (double)w;
709 fh = (double)part_h / (double)h;
719 DbgPrint("Size: %dx%d\n", w, h);
720 evas_object_image_fill_set(img, 0, 0, part_w, part_h);
721 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
722 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
724 evas_object_image_fill_set(img, 0, 0, w, h);
725 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
726 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
729 if (img_opt.width >= 0 && img_opt.height >= 0) {
732 DbgPrint("Using given image size: %dx%d\n", w, h);
735 evas_object_image_fill_set(img, 0, 0, w, h);
736 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
737 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
742 * object will be shown by below statement automatically
744 DbgPrint("%s part swallow image %p (%dx%d)\n", part, img, w, h);
746 elm_object_part_content_set(edje, part, img);
747 obj_info->children = eina_list_append(obj_info->children, child);
751 * This object is not registered as an access object.
752 * So the developer should add it to access list manually, using DESC_ACCESS block.
754 return LB_STATUS_SUCCESS;
757 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
759 struct info *handle = data;
771 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
772 edje_object_part_geometry_get(elm_layout_edje_get(obj), source, &px, &py, &pw, &ph);
776 sx = (double)px / (double)w;
777 ex = (double)(px + pw) / (double)w;
782 sy = (double)py / (double)h;
783 ey = (double)(py + ph) / (double)h;
786 DbgPrint("Signal emit: source[%s], emission[%s]\n", source, emission);
787 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
790 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
792 struct info *handle = _info;
793 struct obj_info *obj_info;
797 handle->obj_list = eina_list_remove(handle->obj_list, obj);
799 obj_info = evas_object_data_del(obj, "obj_info");
801 ErrPrint("Object info is not valid\n");
805 DbgPrint("delete object %s %p\n", obj_info->id, obj);
807 elm_object_signal_callback_del(obj, "*", "*", script_signal_cb);
809 elm_object_focus_custom_chain_unset(obj);
811 EINA_LIST_FREE(obj_info->children, child) {
812 DbgPrint("delete object %s %p\n", child->part, child->obj);
815 ao = evas_object_data_del(child->obj, "ao");
817 obj_info->access_chain = eina_list_remove(obj_info->access_chain, ao);
818 evas_object_data_del(ao, "edje");
819 elm_access_object_unregister(ao);
821 evas_object_del(child->obj);
827 EINA_LIST_FREE(obj_info->access_chain, ao) {
828 evas_object_data_del(ao, "edje");
829 elm_access_object_unregister(ao);
837 LB_ACCESS_HIGHLIGHT 0
838 LB_ACCESS_HIGHLIGHT_NEXT 1
839 LB_ACCESS_HIGHLIGHT_PREV 2
844 PUBLIC int script_feed_event(void *h, Evas *e, int event_type, int x, int y, int down, double timestamp)
846 struct info *handle = h;
848 struct obj_info *obj_info;
849 int ret = LB_STATUS_SUCCESS;
851 DbgPrint("event: %d, x: %d, y: %d\n", event_type, x, y);
853 edje = find_edje(handle, NULL); /*!< Get the base layout */
855 ErrPrint("Base layout is not exist\n");
856 return LB_STATUS_ERROR_NOT_EXIST;
859 obj_info = evas_object_data_get(edje, "obj_info");
861 ErrPrint("Object info is not valid\n");
862 return LB_STATUS_ERROR_INVALID;
865 if (event_type & LB_SCRIPT_ACCESS_EVENT) {
866 Elm_Access_Action_Info *info;
867 Elm_Access_Action_Type action;
868 const Eina_List *chain;
870 info = calloc(1, sizeof(*info));
872 ErrPrint("Error: %s\n", strerror(errno));
873 return LB_STATUS_ERROR_MEMORY;
876 chain = elm_object_focus_custom_chain_get(edje);
877 DbgPrint("Focus chain : %d\n", eina_list_count(chain));
879 if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT) == LB_SCRIPT_ACCESS_HIGHLIGHT) {
880 action = ELM_ACCESS_ACTION_HIGHLIGHT;
883 ret = elm_access_action(edje, action, info);
884 DbgPrint("ACCESS_HIGHLIGHT: %dx%d returns %d\n", x, y, ret);
885 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
886 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) == LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT) {
887 action = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
888 info->highlight_cycle = EINA_FALSE;
889 ret = elm_access_action(edje, action, info);
890 DbgPrint("ACCESS_HIGHLIGHT_NEXT, returns %d\n", ret);
891 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_LAST : LB_ACCESS_STATUS_DONE;
892 } else if ((event_type & LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) == LB_SCRIPT_ACCESS_HIGHLIGHT_PREV) {
893 action = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
894 info->highlight_cycle = EINA_FALSE;
895 ret = elm_access_action(edje, action, info);
896 DbgPrint("ACCESS_HIGHLIGHT_PREV, returns %d\n", ret);
897 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_FIRST : LB_ACCESS_STATUS_DONE;
898 } else if ((event_type & LB_SCRIPT_ACCESS_ACTIVATE) == LB_SCRIPT_ACCESS_ACTIVATE) {
899 action = ELM_ACCESS_ACTION_ACTIVATE;
900 ret = elm_access_action(edje, action, info);
901 DbgPrint("ACCESS_ACTIVATE, returns %d\n", ret);
902 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
903 } else if ((event_type & LB_SCRIPT_ACCESS_ACTION) == LB_SCRIPT_ACCESS_ACTION) {
905 action = ELM_ACCESS_ACTION_ACTION_UP;
906 } else if (down == 1) {
907 action = ELM_ACCESS_ACTION_ACTION_DOWN;
909 ErrPrint("Invalid access event\n");
913 ret = elm_access_action(edje, action, info);
914 DbgPrint("ACCESS_ACTION(%d), returns %d\n", down, ret);
915 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
916 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
917 action = ELM_ACCESS_ACTION_SCROLL;
921 case 0: info->mouse_type = 0; break;
922 case -1: info->mouse_type = 1; break;
923 case 1: info->mouse_type = 2; break;
927 ret = elm_access_action(edje, action, info);
928 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
929 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
930 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
931 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
932 ret = elm_access_action(edje, action, info);
933 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
934 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
936 DbgPrint("Invalid event\n");
937 ret = LB_ACCESS_STATUS_ERROR;
941 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
942 switch (event_type) {
943 case LB_SCRIPT_MOUSE_DOWN:
944 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
945 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
947 case LB_SCRIPT_MOUSE_MOVE:
948 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
950 case LB_SCRIPT_MOUSE_UP:
951 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
952 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.1f, NULL);
954 case LB_SCRIPT_MOUSE_IN:
955 evas_event_feed_mouse_in(e, timestamp, NULL);
957 case LB_SCRIPT_MOUSE_OUT:
958 evas_event_feed_mouse_out(e, timestamp, NULL);
961 return LB_STATUS_ERROR_INVALID;
963 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
964 DbgPrint("Key event is not implemented\n");
965 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
971 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)
973 struct info *handle = h;
976 struct obj_info *obj_info;
979 DbgPrint("src_id[%s] target_id[%s] part[%s] path[%s] group[%s]\n", src_id, target_id, part, path, group);
981 edje = find_edje(handle, src_id);
983 ErrPrint("Edje is not exists\n");
984 return LB_STATUS_ERROR_NOT_EXIST;
987 obj_info = evas_object_data_get(edje, "obj_info");
989 ErrPrint("Object info is not valid\n");
990 return LB_STATUS_ERROR_INVALID;
993 obj = elm_object_part_content_unset(edje, part);
998 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
999 if (child->obj != obj)
1002 obj_info->children = eina_list_remove(obj_info->children, child);
1009 DbgPrint("delete object %s %p\n", part, obj);
1012 * This will call the edje_del_cb.
1013 * It will delete all access objects
1015 evas_object_del(obj);
1018 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1019 DbgPrint("SKIP - Path: [%s]\n", path);
1020 return LB_STATUS_SUCCESS;
1023 obj = elm_layout_add(edje);
1025 ErrPrint("Failed to add a new edje object\n");
1026 return LB_STATUS_ERROR_FAULT;
1029 if (!elm_layout_file_set(obj, path, group)) {
1033 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1034 errmsg = edje_load_error_str(err);
1035 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
1036 evas_object_del(obj);
1037 return LB_STATUS_ERROR_IO;
1040 evas_object_show(obj);
1042 obj_info = calloc(1, sizeof(*obj_info));
1044 ErrPrint("Failed to add a obj_info\n");
1045 evas_object_del(obj);
1046 return LB_STATUS_ERROR_MEMORY;
1049 obj_info->id = strdup(target_id);
1050 if (!obj_info->id) {
1051 ErrPrint("Failed to add a obj_info\n");
1053 evas_object_del(obj);
1054 return LB_STATUS_ERROR_MEMORY;
1057 child = malloc(sizeof(*child));
1059 ErrPrint("Error: %s\n", strerror(errno));
1062 evas_object_del(obj);
1063 return LB_STATUS_ERROR_MEMORY;
1066 child->part = strdup(part);
1068 ErrPrint("Error: %s\n", strerror(errno));
1072 evas_object_del(obj);
1073 return LB_STATUS_ERROR_MEMORY;
1078 evas_object_data_set(obj, "obj_info", obj_info);
1079 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1080 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1081 handle->obj_list = eina_list_append(handle->obj_list, obj);
1083 DbgPrint("%s part swallow edje %p\n", part, obj);
1084 elm_object_part_content_set(edje, part, obj);
1085 obj_info = evas_object_data_get(edje, "obj_info");
1086 obj_info->children = eina_list_append(obj_info->children, child);
1087 return LB_STATUS_SUCCESS;
1090 PUBLIC int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
1092 struct info *handle = h;
1095 DbgPrint("id[%s], part[%s], signal[%s]\n", id, part, signal);
1097 edje = find_edje(handle, id);
1099 return LB_STATUS_ERROR_NOT_EXIST;
1101 elm_object_signal_emit(edje, signal, part);
1102 return LB_STATUS_SUCCESS;
1105 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1107 struct info *handle = h;
1110 DbgPrint("id[%s], part[%s], %lfx%lf\n", id, part, x, y);
1112 edje = find_edje(handle, id);
1114 return LB_STATUS_ERROR_NOT_EXIST;
1116 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1117 return LB_STATUS_SUCCESS;
1120 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1122 struct info *handle = han;
1125 edje = find_edje(handle, id);
1127 return LB_STATUS_ERROR_NOT_EXIST;
1134 DbgPrint("Resize object to %dx%d\n", w, h);
1135 evas_object_resize(edje, w, h);
1136 return LB_STATUS_SUCCESS;
1139 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1141 struct info *handle = h;
1143 DbgPrint("id[%s], category[%s]\n", id, category);
1145 if (handle->category) {
1146 free(handle->category);
1147 handle->category = NULL;
1151 return LB_STATUS_SUCCESS;
1153 handle->category = strdup(category);
1154 if (!handle->category) {
1155 ErrPrint("Error: %s\n", strerror(errno));
1156 return LB_STATUS_ERROR_MEMORY;
1159 return LB_STATUS_SUCCESS;
1162 PUBLIC void *script_create(const char *file, const char *group)
1164 struct info *handle;
1166 DbgPrint("file[%s], group[%s]\n", file, group);
1168 handle = calloc(1, sizeof(*handle));
1170 ErrPrint("Error: %s\n", strerror(errno));
1174 handle->file = strdup(file);
1175 if (!handle->file) {
1176 ErrPrint("Error: %s\n", strerror(errno));
1181 handle->group = strdup(group);
1182 if (!handle->group) {
1183 ErrPrint("Error: %s\n", strerror(errno));
1192 PUBLIC int script_destroy(void *_handle)
1194 struct info *handle;
1199 edje = eina_list_nth(handle->obj_list, 0);
1201 evas_object_del(edje);
1203 free(handle->category);
1205 free(handle->group);
1207 return LB_STATUS_SUCCESS;
1210 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1212 struct info *handle;
1214 struct obj_info *obj_info;
1218 obj_info = calloc(1, sizeof(*obj_info));
1220 ErrPrint("Heap: %s\n", strerror(errno));
1221 return LB_STATUS_ERROR_MEMORY;
1224 obj_info->win = evas_object_rectangle_add(e);
1225 if (!obj_info->win) {
1227 return LB_STATUS_ERROR_FAULT;
1230 edje = elm_layout_add(obj_info->win);
1232 ErrPrint("Failed to create an edje object\n");
1233 evas_object_del(obj_info->win);
1235 return LB_STATUS_ERROR_FAULT;
1238 DbgPrint("Load edje: %s - %s\n", handle->file, handle->group);
1239 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1243 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1244 errmsg = edje_load_error_str(err);
1245 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
1246 evas_object_del(edje);
1247 evas_object_del(obj_info->win);
1249 return LB_STATUS_ERROR_IO;
1256 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1257 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1258 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1259 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1260 evas_object_resize(edje, handle->w, handle->h);
1261 evas_object_show(edje);
1262 evas_object_data_set(edje, "obj_info", obj_info);
1264 handle->obj_list = eina_list_append(handle->obj_list, edje);
1265 return LB_STATUS_SUCCESS;
1268 PUBLIC int script_unload(void *_handle, Evas *e)
1270 struct info *handle;
1275 DbgPrint("Unload edje: %s - %s\n", handle->file, handle->group);
1276 edje = eina_list_nth(handle->obj_list, 0);
1278 evas_object_del(edje);
1280 return LB_STATUS_SUCCESS;
1283 static void access_cb(keynode_t *node, void *user_data)
1288 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1289 ErrPrint("Idle lock state is not valid\n");
1290 state = 0; /* DISABLED */
1293 state = vconf_keynode_get_bool(node);
1296 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1297 elm_config_access_set(state);
1300 static void update_font_cb(void *data)
1302 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, s_info.font_size);
1303 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, s_info.font_size);
1306 static void font_changed_cb(system_settings_key_e key, void *user_data)
1311 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
1312 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name)
1315 if (s_info.font_name && !strcmp(s_info.font_name, font_name)) {
1316 DbgPrint("Font is not changed\n");
1321 if (s_info.font_name) {
1322 free(s_info.font_name);
1323 s_info.font_name = NULL;
1326 s_info.font_name = font_name;
1327 DbgPrint("Font name is changed to %s\n", s_info.font_name);
1331 * Try to update all liveboxes
1333 update_font_cb(NULL);
1336 static void font_size_cb(system_settings_key_e key, void *user_data)
1340 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE)
1343 if (size == s_info.font_size) {
1344 DbgPrint("Font size is not changed\n");
1348 s_info.font_size = size;
1349 DbgPrint("Font size is changed to %d\n", size);
1351 update_font_cb(NULL);
1354 PUBLIC int script_init(void)
1361 /* ecore is already initialized */
1363 elm_config_scale_set(scale_get());
1365 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1367 ErrPrint("Failed to access cb\n");
1369 access_cb(NULL, NULL);
1371 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_TYPE, font_changed_cb, NULL);
1372 DbgPrint("System font is changed: %d\n", ret);
1374 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1375 DbgPrint("System font size is changed: %d\n", ret);
1377 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &s_info.font_name);
1378 if (ret == SYSTEM_SETTINGS_ERROR_NONE)
1379 DbgPrint("Current font: %s\n", s_info.font_name);
1381 ret = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &s_info.font_size);
1382 if (ret == SYSTEM_SETTINGS_ERROR_NONE)
1383 DbgPrint("Current size: %d\n", s_info.font_size);
1385 return LB_STATUS_SUCCESS;
1388 PUBLIC int script_fini(void)
1391 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1392 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_TYPE);
1393 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1395 return LB_STATUS_SUCCESS;