2 * Copyright 2012 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.
26 #include <Ecore_Evas.h>
34 #include "script_port.h"
36 #define TEXT_CLASS "tizen"
38 extern void evas_common_font_flush(void);
39 extern int evas_common_font_cache_get(void);
40 extern void evas_common_font_cache_set(int size);
65 Ecore_Event_Handler *property_handler;
69 .property_handler = NULL,
76 * Reservce this for future use
77 static inline void common_cache_flush(void *evas)
84 file_cache = edje_file_cache_get();
85 collection_cache = edje_collection_cache_get();
86 image_cache = evas_image_cache_get(evas);
87 font_cache = evas_font_cache_get(evas);
89 edje_file_cache_set(file_cache);
90 edje_collection_cache_set(collection_cache);
91 evas_image_cache_set(evas, 0);
92 evas_font_cache_set(evas, 0);
94 evas_image_cache_flush(evas);
95 evas_render_idle_flush(evas);
96 evas_font_cache_flush(evas);
98 edje_file_cache_flush();
99 edje_collection_cache_flush();
101 edje_file_cache_set(file_cache);
102 edje_collection_cache_set(collection_cache);
103 evas_image_cache_set(evas, image_cache);
104 evas_font_cache_set(evas, font_cache);
110 static inline Evas_Object *find_edje(struct info *handle, const char *id)
114 struct obj_info *obj_info;
116 EINA_LIST_FOREACH(handle->obj_list, l, edje) {
117 obj_info = evas_object_data_get(edje, "obj_info");
119 ErrPrint("Object info is not valid\n");
128 } else if (!obj_info->id) {
132 if (!strcmp(obj_info->id, id))
136 DbgPrint("EDJE[%s] is not found\n", id);
140 const char *script_magic_id(void)
145 int script_update_color(void *h, Evas *e, const char *id, const char *part, const char *rgba)
147 struct info *handle = h;
149 int r[3], g[3], b[3], a[3];
152 edje = find_edje(handle, id);
156 ret = sscanf(rgba, "%d %d %d %d %d %d %d %d %d %d %d %d",
157 r, g, b, a, /* OBJECT */
158 r + 1, g + 1, b + 1, a + 1, /* OUTLINE */
159 r + 2, g + 2, b + 2, a + 2); /* SHADOW */
161 DbgPrint("id[%s] part[%s] rgba[%s]\n", id, part, rgba);
165 ret = edje_object_color_class_set(edje, part,
166 r[0], g[0], b[0], a[0], /* OBJECT */
167 r[1], g[1], b[1], a[1], /* OUTLINE */
168 r[2], g[2], b[2], a[2]); /* SHADOW */
170 DbgPrint("EDJE[%s] color class is %s changed", id, ret == EINA_TRUE ? "successfully" : "not");
174 int script_update_text(void *h, Evas *e, const char *id, const char *part, const char *text)
176 struct info *handle = h;
179 edje = find_edje(handle, id);
183 edje_object_part_text_set(edje, part, text);
187 int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path)
189 struct info *handle = _h;
194 struct obj_info *obj_info;
197 edje = find_edje(handle, id);
199 ErrPrint("No such object: %s\n", id);
203 obj_info = evas_object_data_get(edje, "obj_info");
205 ErrPrint("Object info is not available\n");
209 img = edje_object_part_swallow_get(edje, part);
214 edje_object_part_unswallow(edje, img);
216 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
217 if (child->obj != img)
220 obj_info->children = eina_list_remove(obj_info->children, child);
226 DbgPrint("delete object %s %p\n", part, img);
227 evas_object_del(img);
230 if (!path || !strlen(path) || access(path, R_OK) != 0) {
231 DbgPrint("SKIP - Path: [%s]\n", path);
235 child = malloc(sizeof(*child));
237 ErrPrint("Heap: %s\n", strerror(errno));
241 child->part = strdup(part);
243 ErrPrint("Heap: %s\n", strerror(errno));
248 img = evas_object_image_filled_add(e);
250 ErrPrint("Failed to add an image object\n");
258 evas_object_image_file_set(img, path, NULL);
259 err = evas_object_image_load_error_get(img);
260 if (err != EVAS_LOAD_ERROR_NONE) {
261 ErrPrint("Load error: %s\n", evas_load_error_str(err));
262 evas_object_del(img);
268 evas_object_image_size_get(img, &w, &h);
269 evas_object_image_fill_set(img, 0, 0, w, h);
270 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
271 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
272 evas_object_resize(img, w, h);
276 * object will be shown by below statement automatically
278 DbgPrint("%s part swallow image %p\n", part, img);
279 edje_object_part_swallow(edje, part, img);
280 obj_info->children = eina_list_append(obj_info->children, child);
285 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
287 struct info *handle = data;
299 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
300 edje_object_part_geometry_get(obj, source, &px, &py, &pw, &ph);
304 sx = (double)px / (double)w;
305 ex = (double)(px + pw) / (double)w;
310 sy = (double)py / (double)h;
311 ey = (double)(py + ph) / (double)h;
314 DbgPrint("Signal emit: source[%s], emission[%s]\n", source, emission);
315 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
318 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
320 struct info *handle = _info;
321 struct obj_info *obj_info;
324 handle->obj_list = eina_list_remove(handle->obj_list, obj);
326 obj_info = evas_object_data_del(obj, "obj_info");
328 ErrPrint("Object info is not valid\n");
332 DbgPrint("delete object %s %p\n", obj_info->id, obj);
334 edje_object_signal_callback_del_full(obj, "*", "*", script_signal_cb, handle);
336 EINA_LIST_FREE(obj_info->children, child) {
337 DbgPrint("delete object %s %p\n", child->part, child->obj);
339 evas_object_del(child->obj);
348 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)
350 struct info *handle = h;
353 struct obj_info *obj_info;
356 DbgPrint("src_id[%s] target_id[%s] part[%s] path[%s] group[%s]\n", src_id, target_id, part, path, group);
358 edje = find_edje(handle, src_id);
360 ErrPrint("Edje is not exists\n");
364 obj_info = evas_object_data_get(edje, "obj_info");
366 ErrPrint("Object info is not valid\n");
370 obj = edje_object_part_swallow_get(edje, part);
375 edje_object_part_unswallow(edje, obj);
377 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
378 if (child->obj != obj)
381 obj_info->children = eina_list_remove(obj_info->children, child);
387 DbgPrint("delete object %s %p\n", part, obj);
388 evas_object_del(obj);
391 if (!path || !strlen(path) || access(path, R_OK) != 0) {
392 DbgPrint("SKIP - Path: [%s]\n", path);
396 obj = edje_object_add(e);
398 ErrPrint("Failed to add a new edje object\n");
402 //edje_object_text_class_set(obj, TEXT_CLASS, s_info.font, s_info.size);
403 if (!edje_object_file_set(obj, path, group)) {
407 err = edje_object_load_error_get(obj);
408 errmsg = edje_load_error_str(err);
409 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
410 evas_object_del(obj);
414 evas_object_show(obj);
416 obj_info = calloc(1, sizeof(*obj_info));
418 ErrPrint("Failed to add a obj_info\n");
419 evas_object_del(obj);
423 obj_info->id = strdup(target_id);
425 ErrPrint("Failed to add a obj_info\n");
427 evas_object_del(obj);
431 child = malloc(sizeof(*child));
433 ErrPrint("Error: %s\n", strerror(errno));
436 evas_object_del(obj);
440 child->part = strdup(part);
442 ErrPrint("Error: %s\n", strerror(errno));
446 evas_object_del(obj);
452 evas_object_data_set(obj, "obj_info", obj_info);
453 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
454 edje_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
455 handle->obj_list = eina_list_append(handle->obj_list, obj);
457 DbgPrint("%s part swallow edje %p\n", part, obj);
458 edje_object_part_swallow(edje, part, obj);
459 obj_info = evas_object_data_get(edje, "obj_info");
460 obj_info->children = eina_list_append(obj_info->children, child);
464 int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
466 struct info *handle = h;
469 DbgPrint("id[%s], part[%s], signal[%s]\n", id, part, signal);
471 edje = find_edje(handle, id);
475 edje_object_signal_emit(edje, signal, part);
479 int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
481 struct info *handle = h;
484 DbgPrint("id[%s], part[%s], %lfx%lf\n", id, part, x, y);
486 edje = find_edje(handle, id);
490 edje_object_part_drag_value_set(edje, part, x, y);
494 int script_update_size(void *han, Evas *e, const char *id, int w, int h)
496 struct info *handle = han;
499 edje = find_edje(handle, id);
508 DbgPrint("Resize object to %dx%d\n", w, h);
509 evas_object_resize(edje, w, h);
513 int script_update_category(void *h, Evas *e, const char *id, const char *category)
515 struct info *handle = h;
517 DbgPrint("id[%s], category[%s]\n", id, category);
519 if (handle->category) {
520 free(handle->category);
521 handle->category = NULL;
527 handle->category = strdup(category);
528 if (!handle->category) {
529 ErrPrint("Error: %s\n", strerror(errno));
536 void *script_create(const char *file, const char *group)
540 DbgPrint("file[%s], group[%s]\n", file, group);
542 handle = calloc(1, sizeof(*handle));
544 ErrPrint("Error: %s\n", strerror(errno));
548 handle->file = strdup(file);
550 ErrPrint("Error: %s\n", strerror(errno));
555 handle->group = strdup(group);
556 if (!handle->group) {
557 ErrPrint("Error: %s\n", strerror(errno));
566 int script_destroy(void *_handle)
573 edje = eina_list_nth(handle->obj_list, 0);
575 evas_object_del(edje);
577 free(handle->category);
584 int script_load(void *_handle, Evas *e, int w, int h)
588 struct obj_info *obj_info;
592 obj_info = calloc(1, sizeof(*obj_info));
594 ErrPrint("Heap: %s\n", strerror(errno));
598 edje = edje_object_add(e);
600 ErrPrint("Failed to create an edje object\n");
605 //edje_object_text_class_set(edje, TEXT_CLASS, s_info.font, s_info.size);
606 DbgPrint("Load edje: %s - %s\n", handle->file, handle->group);
607 if (!edje_object_file_set(edje, handle->file, handle->group)) {
611 err = edje_object_load_error_get(edje);
612 errmsg = edje_load_error_str(err);
613 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
614 evas_object_del(edje);
623 edje_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
624 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
625 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
626 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
627 evas_object_resize(edje, handle->w, handle->h);
628 evas_object_show(edje);
629 evas_object_data_set(edje, "obj_info", obj_info);
631 handle->obj_list = eina_list_append(handle->obj_list, edje);
635 int script_unload(void *_handle, Evas *e)
642 DbgPrint("Unload edje: %s - %s\n", handle->file, handle->group);
643 edje = eina_list_nth(handle->obj_list, 0);
645 evas_object_del(edje);
650 static Eina_Bool property_cb(void *data, int type, void *event)
652 Ecore_X_Event_Window_Property *info = (Ecore_X_Event_Window_Property *)event;
654 if (info->atom == ecore_x_atom_get("FONT_TYPE_change") || info->atom == ecore_x_atom_get("BADA_FONT_change")) {
660 font = vconf_get_str("db/setting/accessibility/font_name");
662 return ECORE_CALLBACK_PASS_ON;
669 cache = evas_common_font_cache_get();
670 evas_common_font_cache_set(0);
671 evas_common_font_flush();
673 list = edje_text_class_list();
674 EINA_LIST_FREE(list, text) {
675 if (!strncasecmp(text, TEXT_CLASS, strlen(TEXT_CLASS))) {
676 edje_text_class_del(text);
677 edje_text_class_set(text, s_info.font, s_info.size);
678 DbgPrint("Update text class %s (%s, %d)\n", text, s_info.font, s_info.size);
680 DbgPrint("Skip text class %s\n", text);
684 evas_common_font_cache_set(cache);
687 return ECORE_CALLBACK_PASS_ON;
690 static void font_name_cb(keynode_t *node, void *user_data)
697 font = vconf_keynode_get_str(node);
701 DbgPrint("Font changed to %s\n", font);
704 static void font_size_cb(keynode_t *node, void *user_data)
712 DbgPrint("Size type: %d\n", vconf_keynode_get_int(node));
715 int script_init(void)
718 /* ecore is already initialized */
721 s_info.property_handler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, property_cb, NULL);
722 if (!s_info.property_handler)
723 ErrPrint("Failed to add a property change event handler\n");
725 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, font_size_cb, NULL);
727 ErrPrint("Failed to add vconf for font size change\n");
729 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_name_cb, NULL);
731 ErrPrint("Failed to add vconf for font name change\n");
736 int script_fini(void)
739 vconf_ignore_key_changed("db/setting/accessibility/font_name", font_name_cb);
740 vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, font_size_cb);
741 ecore_event_handler_del(s_info.property_handler);
742 s_info.property_handler = NULL;