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>
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
841 LB_ACCESS_VALUE_CHANGE 4
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_HIGHLIGHT_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_VALUE_CHANGE) == LB_SCRIPT_ACCESS_VALUE_CHANGE) {
904 action = ELM_ACCESS_ACTION_VALUE_CHANGE;
905 ret = elm_access_action(edje, action, info);
906 DbgPrint("ACCESS_HIGHLIGHT_VALUE_CHANGE, returns %d\n", ret);
907 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
908 } else if ((event_type & LB_SCRIPT_ACCESS_SCROLL) == LB_SCRIPT_ACCESS_SCROLL) {
909 action = ELM_ACCESS_ACTION_SCROLL;
913 case 0: info->mouse_type = 0; break;
914 case -1: info->mouse_type = 1; break;
915 case 1: info->mouse_type = 2; break;
919 ret = elm_access_action(edje, action, info);
920 DbgPrint("ACCESS_HIGHLIGHT_SCROLL, returns %d\n", ret);
921 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
922 } else if ((event_type & LB_SCRIPT_ACCESS_UNHIGHLIGHT) == LB_SCRIPT_ACCESS_UNHIGHLIGHT) {
923 action = ELM_ACCESS_ACTION_UNHIGHLIGHT;
924 ret = elm_access_action(edje, action, info);
925 DbgPrint("ACCESS_UNHIGHLIGHT, returns %d\n", ret);
926 ret = (ret == EINA_FALSE) ? LB_ACCESS_STATUS_ERROR : LB_ACCESS_STATUS_DONE;
928 DbgPrint("Invalid event\n");
929 ret = LB_ACCESS_STATUS_ERROR;
933 } else if (event_type & LB_SCRIPT_MOUSE_EVENT) {
934 switch (event_type) {
935 case LB_SCRIPT_MOUSE_DOWN:
936 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
937 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
939 case LB_SCRIPT_MOUSE_MOVE:
940 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
942 case LB_SCRIPT_MOUSE_UP:
943 evas_event_feed_mouse_move(e, x, y, timestamp, NULL);
944 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.1f, NULL);
946 case LB_SCRIPT_MOUSE_IN:
947 evas_event_feed_mouse_in(e, timestamp, NULL);
949 case LB_SCRIPT_MOUSE_OUT:
950 evas_event_feed_mouse_out(e, timestamp, NULL);
953 return LB_STATUS_ERROR_INVALID;
955 } else if (event_type & LB_SCRIPT_KEY_EVENT) {
956 DbgPrint("Key event is not implemented\n");
957 return LB_STATUS_ERROR_NOT_IMPLEMENTED;
963 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)
965 struct info *handle = h;
968 struct obj_info *obj_info;
971 DbgPrint("src_id[%s] target_id[%s] part[%s] path[%s] group[%s]\n", src_id, target_id, part, path, group);
973 edje = find_edje(handle, src_id);
975 ErrPrint("Edje is not exists\n");
976 return LB_STATUS_ERROR_NOT_EXIST;
979 obj_info = evas_object_data_get(edje, "obj_info");
981 ErrPrint("Object info is not valid\n");
982 return LB_STATUS_ERROR_INVALID;
985 obj = elm_object_part_content_unset(edje, part);
990 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
991 if (child->obj != obj)
994 obj_info->children = eina_list_remove(obj_info->children, child);
1001 DbgPrint("delete object %s %p\n", part, obj);
1004 * This will call the edje_del_cb.
1005 * It will delete all access objects
1007 evas_object_del(obj);
1010 if (!path || !strlen(path) || access(path, R_OK) != 0) {
1011 DbgPrint("SKIP - Path: [%s]\n", path);
1012 return LB_STATUS_SUCCESS;
1015 obj = elm_layout_add(edje);
1017 ErrPrint("Failed to add a new edje object\n");
1018 return LB_STATUS_ERROR_FAULT;
1021 if (!elm_layout_file_set(obj, path, group)) {
1025 err = edje_object_load_error_get(elm_layout_edje_get(obj));
1026 errmsg = edje_load_error_str(err);
1027 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
1028 evas_object_del(obj);
1029 return LB_STATUS_ERROR_IO;
1032 evas_object_show(obj);
1034 obj_info = calloc(1, sizeof(*obj_info));
1036 ErrPrint("Failed to add a obj_info\n");
1037 evas_object_del(obj);
1038 return LB_STATUS_ERROR_MEMORY;
1041 obj_info->id = strdup(target_id);
1042 if (!obj_info->id) {
1043 ErrPrint("Failed to add a obj_info\n");
1045 evas_object_del(obj);
1046 return LB_STATUS_ERROR_MEMORY;
1049 child = malloc(sizeof(*child));
1051 ErrPrint("Error: %s\n", strerror(errno));
1054 evas_object_del(obj);
1055 return LB_STATUS_ERROR_MEMORY;
1058 child->part = strdup(part);
1060 ErrPrint("Error: %s\n", strerror(errno));
1064 evas_object_del(obj);
1065 return LB_STATUS_ERROR_MEMORY;
1070 evas_object_data_set(obj, "obj_info", obj_info);
1071 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1072 elm_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
1073 handle->obj_list = eina_list_append(handle->obj_list, obj);
1075 DbgPrint("%s part swallow edje %p\n", part, obj);
1076 elm_object_part_content_set(edje, part, obj);
1077 obj_info = evas_object_data_get(edje, "obj_info");
1078 obj_info->children = eina_list_append(obj_info->children, child);
1079 return LB_STATUS_SUCCESS;
1082 PUBLIC int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
1084 struct info *handle = h;
1087 DbgPrint("id[%s], part[%s], signal[%s]\n", id, part, signal);
1089 edje = find_edje(handle, id);
1091 return LB_STATUS_ERROR_NOT_EXIST;
1093 elm_object_signal_emit(edje, signal, part);
1094 return LB_STATUS_SUCCESS;
1097 PUBLIC int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
1099 struct info *handle = h;
1102 DbgPrint("id[%s], part[%s], %lfx%lf\n", id, part, x, y);
1104 edje = find_edje(handle, id);
1106 return LB_STATUS_ERROR_NOT_EXIST;
1108 edje_object_part_drag_value_set(elm_layout_edje_get(edje), part, x, y);
1109 return LB_STATUS_SUCCESS;
1112 PUBLIC int script_update_size(void *han, Evas *e, const char *id, int w, int h)
1114 struct info *handle = han;
1117 edje = find_edje(handle, id);
1119 return LB_STATUS_ERROR_NOT_EXIST;
1126 DbgPrint("Resize object to %dx%d\n", w, h);
1127 evas_object_resize(edje, w, h);
1128 return LB_STATUS_SUCCESS;
1131 PUBLIC int script_update_category(void *h, Evas *e, const char *id, const char *category)
1133 struct info *handle = h;
1135 DbgPrint("id[%s], category[%s]\n", id, category);
1137 if (handle->category) {
1138 free(handle->category);
1139 handle->category = NULL;
1143 return LB_STATUS_SUCCESS;
1145 handle->category = strdup(category);
1146 if (!handle->category) {
1147 ErrPrint("Error: %s\n", strerror(errno));
1148 return LB_STATUS_ERROR_MEMORY;
1151 return LB_STATUS_SUCCESS;
1154 PUBLIC void *script_create(const char *file, const char *group)
1156 struct info *handle;
1158 DbgPrint("file[%s], group[%s]\n", file, group);
1160 handle = calloc(1, sizeof(*handle));
1162 ErrPrint("Error: %s\n", strerror(errno));
1166 handle->file = strdup(file);
1167 if (!handle->file) {
1168 ErrPrint("Error: %s\n", strerror(errno));
1173 handle->group = strdup(group);
1174 if (!handle->group) {
1175 ErrPrint("Error: %s\n", strerror(errno));
1184 PUBLIC int script_destroy(void *_handle)
1186 struct info *handle;
1191 edje = eina_list_nth(handle->obj_list, 0);
1193 evas_object_del(edje);
1195 free(handle->category);
1197 free(handle->group);
1199 return LB_STATUS_SUCCESS;
1202 PUBLIC int script_load(void *_handle, Evas *e, int w, int h)
1204 struct info *handle;
1206 struct obj_info *obj_info;
1210 obj_info = calloc(1, sizeof(*obj_info));
1212 ErrPrint("Heap: %s\n", strerror(errno));
1213 return LB_STATUS_ERROR_MEMORY;
1216 obj_info->win = evas_object_rectangle_add(e);
1217 if (!obj_info->win) {
1219 return LB_STATUS_ERROR_FAULT;
1222 edje = elm_layout_add(obj_info->win);
1224 ErrPrint("Failed to create an edje object\n");
1225 evas_object_del(obj_info->win);
1227 return LB_STATUS_ERROR_FAULT;
1230 DbgPrint("Load edje: %s - %s\n", handle->file, handle->group);
1231 if (!elm_layout_file_set(edje, handle->file, handle->group)) {
1235 err = edje_object_load_error_get(elm_layout_edje_get(edje));
1236 errmsg = edje_load_error_str(err);
1237 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
1238 evas_object_del(edje);
1239 evas_object_del(obj_info->win);
1241 return LB_STATUS_ERROR_IO;
1248 elm_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
1249 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
1250 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1251 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
1252 evas_object_resize(edje, handle->w, handle->h);
1253 evas_object_show(edje);
1254 evas_object_data_set(edje, "obj_info", obj_info);
1256 handle->obj_list = eina_list_append(handle->obj_list, edje);
1257 return LB_STATUS_SUCCESS;
1260 PUBLIC int script_unload(void *_handle, Evas *e)
1262 struct info *handle;
1267 DbgPrint("Unload edje: %s - %s\n", handle->file, handle->group);
1268 edje = eina_list_nth(handle->obj_list, 0);
1270 evas_object_del(edje);
1272 return LB_STATUS_SUCCESS;
1275 static void access_cb(keynode_t *node, void *user_data)
1280 if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &state) != 0) {
1281 ErrPrint("Idle lock state is not valid\n");
1282 state = 0; /* DISABLED */
1285 state = vconf_keynode_get_bool(node);
1288 DbgPrint("ELM CONFIG ACCESS: %d\n", state);
1289 elm_config_access_set(state);
1292 static void update_font_cb(void *data)
1294 elm_config_font_overlay_set(TEXT_CLASS, s_info.font_name, s_info.font_size);
1295 DbgPrint("Update text class %s (%s, %d)\n", TEXT_CLASS, s_info.font_name, s_info.font_size);
1298 static void font_changed_cb(system_settings_key_e key, void *user_data)
1303 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
1304 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name)
1307 if (s_info.font_name && !strcmp(s_info.font_name, font_name)) {
1308 DbgPrint("Font is not changed\n");
1313 if (s_info.font_name) {
1314 free(s_info.font_name);
1315 s_info.font_name = NULL;
1318 s_info.font_name = font_name;
1319 DbgPrint("Font name is changed to %s\n", s_info.font_name);
1323 * Try to update all liveboxes
1325 update_font_cb(NULL);
1328 static void font_size_cb(system_settings_key_e key, void *user_data)
1332 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE)
1335 if (size == s_info.font_size) {
1336 DbgPrint("Font size is not changed\n");
1340 s_info.font_size = size;
1341 DbgPrint("Font size is changed to %d\n", size);
1343 update_font_cb(NULL);
1346 PUBLIC int script_init(void)
1353 /* ecore is already initialized */
1355 elm_config_scale_set(scale_get());
1357 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb, NULL);
1359 ErrPrint("Failed to access cb\n");
1361 access_cb(NULL, NULL);
1363 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_TYPE, font_changed_cb, NULL);
1364 DbgPrint("System font is changed: %d\n", ret);
1366 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
1367 DbgPrint("System font size is changed: %d\n", ret);
1369 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &s_info.font_name);
1370 if (ret == SYSTEM_SETTINGS_ERROR_NONE)
1371 DbgPrint("Current font: %s\n", s_info.font_name);
1373 ret = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &s_info.font_size);
1374 if (ret == SYSTEM_SETTINGS_ERROR_NONE)
1375 DbgPrint("Current size: %d\n", s_info.font_size);
1377 return LB_STATUS_SUCCESS;
1380 PUBLIC int script_fini(void)
1383 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
1384 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_TYPE);
1385 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, access_cb);
1387 return LB_STATUS_SUCCESS;