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 "slp"
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_text(void *h, Evas *e, const char *id, const char *part, const char *text)
147 struct info *handle = h;
150 edje = find_edje(handle, id);
154 edje_object_part_text_set(edje, part, text);
158 int script_update_image(void *_h, Evas *e, const char *id, const char *part, const char *path)
160 struct info *handle = _h;
165 struct obj_info *obj_info;
168 edje = find_edje(handle, id);
170 ErrPrint("No such object: %s\n", id);
174 obj_info = evas_object_data_get(edje, "obj_info");
176 ErrPrint("Object info is not available\n");
180 img = edje_object_part_swallow_get(edje, part);
185 edje_object_part_unswallow(edje, img);
187 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
188 if (child->obj != img)
191 obj_info->children = eina_list_remove(obj_info->children, child);
197 DbgPrint("delete object %s %p\n", part, img);
198 evas_object_del(img);
201 if (!path || !strlen(path) || access(path, R_OK) != 0) {
202 DbgPrint("SKIP - Path: [%s]\n", path);
206 child = malloc(sizeof(*child));
208 ErrPrint("Heap: %s\n", strerror(errno));
212 child->part = strdup(part);
214 ErrPrint("Heap: %s\n", strerror(errno));
219 img = evas_object_image_filled_add(e);
221 ErrPrint("Failed to add an image object\n");
229 evas_object_image_file_set(img, path, NULL);
230 err = evas_object_image_load_error_get(img);
231 if (err != EVAS_LOAD_ERROR_NONE) {
232 ErrPrint("Load error: %s\n", evas_load_error_str(err));
233 evas_object_del(img);
239 evas_object_image_size_get(img, &w, &h);
240 evas_object_image_fill_set(img, 0, 0, w, h);
241 evas_object_size_hint_fill_set(img, EVAS_HINT_FILL, EVAS_HINT_FILL);
242 evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
243 evas_object_resize(img, w, h);
247 * object will be shown by below statement automatically
249 DbgPrint("%s part swallow image %p\n", part, img);
250 edje_object_part_swallow(edje, part, img);
251 obj_info->children = eina_list_append(obj_info->children, child);
256 static void script_signal_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
258 struct info *handle = data;
270 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
271 edje_object_part_geometry_get(obj, source, &px, &py, &pw, &ph);
275 sx = (double)px / (double)w;
276 ex = (double)(px + pw) / (double)w;
281 sy = (double)py / (double)h;
282 ey = (double)(py + ph) / (double)h;
285 DbgPrint("Signal emit: source[%s], emission[%s]\n", source, emission);
286 script_signal_emit(handle->e, source, emission, sx, sy, ex, ey);
289 static void edje_del_cb(void *_info, Evas *e, Evas_Object *obj, void *event_info)
291 struct info *handle = _info;
292 struct obj_info *obj_info;
295 handle->obj_list = eina_list_remove(handle->obj_list, obj);
297 obj_info = evas_object_data_del(obj, "obj_info");
299 ErrPrint("Object info is not valid\n");
303 DbgPrint("delete object %s %p\n", obj_info->id, obj);
305 edje_object_signal_callback_del_full(obj, "*", "*", script_signal_cb, handle);
307 EINA_LIST_FREE(obj_info->children, child) {
308 DbgPrint("delete object %s %p\n", child->part, child->obj);
310 evas_object_del(child->obj);
319 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)
321 struct info *handle = h;
324 struct obj_info *obj_info;
327 DbgPrint("src_id[%s] target_id[%s] part[%s] path[%s] group[%s]\n", src_id, target_id, part, path, group);
329 edje = find_edje(handle, src_id);
331 ErrPrint("Edje is not exists\n");
335 obj_info = evas_object_data_get(edje, "obj_info");
337 ErrPrint("Object info is not valid\n");
341 obj = edje_object_part_swallow_get(edje, part);
346 edje_object_part_unswallow(edje, obj);
348 EINA_LIST_FOREACH_SAFE(obj_info->children, l, n, child) {
349 if (child->obj != obj)
352 obj_info->children = eina_list_remove(obj_info->children, child);
358 DbgPrint("delete object %s %p\n", part, obj);
359 evas_object_del(obj);
362 if (!path || !strlen(path) || access(path, R_OK) != 0) {
363 DbgPrint("SKIP - Path: [%s]\n", path);
367 obj = edje_object_add(e);
369 ErrPrint("Failed to add a new edje object\n");
373 //edje_object_text_class_set(obj, TEXT_CLASS, s_info.font, s_info.size);
374 if (!edje_object_file_set(obj, path, group)) {
378 err = edje_object_load_error_get(obj);
379 errmsg = edje_load_error_str(err);
380 ErrPrint("Could not load %s from %s: %s\n", group, path, errmsg);
381 evas_object_del(obj);
385 evas_object_show(obj);
387 obj_info = calloc(1, sizeof(*obj_info));
389 ErrPrint("Failed to add a obj_info\n");
390 evas_object_del(obj);
394 obj_info->id = strdup(target_id);
396 ErrPrint("Failed to add a obj_info\n");
398 evas_object_del(obj);
402 child = malloc(sizeof(*child));
404 ErrPrint("Error: %s\n", strerror(errno));
407 evas_object_del(obj);
411 child->part = strdup(part);
413 ErrPrint("Error: %s\n", strerror(errno));
417 evas_object_del(obj);
423 evas_object_data_set(obj, "obj_info", obj_info);
424 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, edje_del_cb, handle);
425 edje_object_signal_callback_add(obj, "*", "*", script_signal_cb, handle);
426 handle->obj_list = eina_list_append(handle->obj_list, obj);
428 DbgPrint("%s part swallow edje %p\n", part, obj);
429 edje_object_part_swallow(edje, part, obj);
430 obj_info = evas_object_data_get(edje, "obj_info");
431 obj_info->children = eina_list_append(obj_info->children, child);
435 int script_update_signal(void *h, Evas *e, const char *id, const char *part, const char *signal)
437 struct info *handle = h;
440 DbgPrint("id[%s], part[%s], signal[%s]\n", id, part, signal);
442 edje = find_edje(handle, id);
446 edje_object_signal_emit(edje, signal, part);
450 int script_update_drag(void *h, Evas *e, const char *id, const char *part, double x, double y)
452 struct info *handle = h;
455 DbgPrint("id[%s], part[%s], %lfx%lf\n", id, part, x, y);
457 edje = find_edje(handle, id);
461 edje_object_part_drag_value_set(edje, part, x, y);
465 int script_update_size(void *han, Evas *e, const char *id, int w, int h)
467 struct info *handle = han;
470 edje = find_edje(handle, id);
479 DbgPrint("Resize object to %dx%d\n", w, h);
480 evas_object_resize(edje, w, h);
484 int script_update_category(void *h, Evas *e, const char *id, const char *category)
486 struct info *handle = h;
488 DbgPrint("id[%s], category[%s]\n", id, category);
490 if (handle->category) {
491 free(handle->category);
492 handle->category = NULL;
498 handle->category = strdup(category);
499 if (!handle->category) {
500 ErrPrint("Error: %s\n", strerror(errno));
507 void *script_create(const char *file, const char *group)
511 DbgPrint("file[%s], group[%s]\n", file, group);
513 handle = calloc(1, sizeof(*handle));
515 ErrPrint("Error: %s\n", strerror(errno));
519 handle->file = strdup(file);
521 ErrPrint("Error: %s\n", strerror(errno));
526 handle->group = strdup(group);
527 if (!handle->group) {
528 ErrPrint("Error: %s\n", strerror(errno));
537 int script_destroy(void *_handle)
544 edje = eina_list_nth(handle->obj_list, 0);
546 evas_object_del(edje);
548 free(handle->category);
555 int script_load(void *_handle, Evas *e, int w, int h)
559 struct obj_info *obj_info;
563 obj_info = calloc(1, sizeof(*obj_info));
565 ErrPrint("Heap: %s\n", strerror(errno));
569 edje = edje_object_add(e);
571 ErrPrint("Failed to create an edje object\n");
576 //edje_object_text_class_set(edje, TEXT_CLASS, s_info.font, s_info.size);
577 DbgPrint("Load edje: %s - %s\n", handle->file, handle->group);
578 if (!edje_object_file_set(edje, handle->file, handle->group)) {
582 err = edje_object_load_error_get(edje);
583 errmsg = edje_load_error_str(err);
584 ErrPrint("Could not load %s from %s: %s\n", handle->group, handle->file, errmsg);
585 evas_object_del(edje);
594 edje_object_signal_callback_add(edje, "*", "*", script_signal_cb, handle);
595 evas_object_event_callback_add(edje, EVAS_CALLBACK_DEL, edje_del_cb, handle);
596 evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
597 evas_object_size_hint_fill_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL);
598 evas_object_resize(edje, handle->w, handle->h);
599 evas_object_show(edje);
600 evas_object_data_set(edje, "obj_info", obj_info);
602 handle->obj_list = eina_list_append(handle->obj_list, edje);
606 int script_unload(void *_handle, Evas *e)
613 DbgPrint("Unload edje: %s - %s\n", handle->file, handle->group);
614 edje = eina_list_nth(handle->obj_list, 0);
616 evas_object_del(edje);
621 static Eina_Bool property_cb(void *data, int type, void *event)
623 Ecore_X_Event_Window_Property *info = (Ecore_X_Event_Window_Property *)event;
625 if (info->atom == ecore_x_atom_get("FONT_TYPE_change") || info->atom == ecore_x_atom_get("BADA_FONT_change")) {
631 font = vconf_get_str("db/setting/accessibility/font_name");
633 return ECORE_CALLBACK_PASS_ON;
640 cache = evas_common_font_cache_get();
641 evas_common_font_cache_set(0);
642 evas_common_font_flush();
644 list = edje_text_class_list();
645 EINA_LIST_FREE(list, text) {
646 if (!strncasecmp(text, TEXT_CLASS, strlen(TEXT_CLASS))) {
647 edje_text_class_del(text);
648 edje_text_class_set(text, s_info.font, s_info.size);
649 DbgPrint("Update text class %s (%s, %d)\n", text, s_info.font, s_info.size);
651 DbgPrint("Skip text class %s\n", text);
655 evas_common_font_cache_set(cache);
658 return ECORE_CALLBACK_PASS_ON;
661 static void font_name_cb(keynode_t *node, void *user_data)
668 font = vconf_keynode_get_str(node);
672 DbgPrint("Font changed to %s\n", font);
675 static void font_size_cb(keynode_t *node, void *user_data)
683 DbgPrint("Size type: %d\n", vconf_keynode_get_int(node));
686 int script_init(void)
689 /* ecore is already initialized */
692 s_info.property_handler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, property_cb, NULL);
693 if (!s_info.property_handler)
694 ErrPrint("Failed to add a property change event handler\n");
696 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, font_size_cb, NULL);
698 ErrPrint("Failed to add vconf for font size change\n");
700 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_name_cb, NULL);
702 ErrPrint("Failed to add vconf for font name change\n");
707 int script_fini(void)
710 vconf_ignore_key_changed("db/setting/accessibility/font_name", font_name_cb);
711 vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, font_size_cb);
712 ecore_event_handler_del(s_info.property_handler);
713 s_info.property_handler = NULL;