/* * setting * * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. * * Contact: MyoungJune Park * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include "setting-common-draw-widget.h" #include /** * Hide the input panel * * @param[in] entry */ EXPORT_PUBLIC void setting_hide_input_panel_cb(Evas_Object *entry) { ret_if(entry == NULL); Ecore_IMF_Context *imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(entry); if (imf_context) ecore_imf_context_input_panel_hide(imf_context); elm_object_focus_set(entry, EINA_FALSE); Evas_Object *entry_container = elm_object_parent_widget_get(entry); if (entry_container) { if (elm_entry_is_empty(entry)) elm_object_signal_emit(entry_container, "elm,state,guidetext,show", "elm"); elm_object_signal_emit(entry_container, "elm,state,eraser,hide", "elm"); } } EXPORT_PUBLIC Evas_Object *setting_create_button( Evas_Object *parent, const char *btn_str, const char *btn_style, Evas_Smart_Cb btn_click_cb, void *cb_data) { retv_if(!parent, NULL); Evas_Object *button = elm_button_add(parent); retv_if(!button, NULL); if (btn_style) elm_object_style_set(button, btn_style); /* not '<-' button */ if (0 != safeStrCmp("naviframe/end_btn/default", btn_style)) { elm_object_text_set(button, _(btn_str)); evas_object_size_hint_weight_set( button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0.5); } if (btn_click_cb) { evas_object_smart_callback_add( button, "clicked", btn_click_cb, cb_data); } evas_object_show(button); LAUNCH_SETTING_OUT(); return button; } EXPORT_PUBLIC Evas_Object *setting_create_button_with_translatable_text( Evas_Object *parent, const char *btn_str_key, const char *btn_style, Evas_Smart_Cb btn_click_cb, void *cb_data) { Evas_Object *button = setting_create_button(parent, "", btn_style, btn_click_cb, cb_data); elm_object_translatable_text_set(button, btn_str_key); return button; } static double _step_size_calculate(Evas_Object *obj, double min, double max) { double step = 0.0; int steps = 0; steps = max - min; if (steps) step = (1.0 / steps); return step; } /** * To create slider object of a genlist item * *@return a slider container object */ EXPORT_PUBLIC Evas_Object *setting_create_5step_slider( Evas_Object *parent, Evas *evas, const char *l_swallow_path, const char *r_swallow_path, double value, bool indicator, double slider_min, double slider_max, setting_call_back_func slider_change_cb, setting_call_back_func slider_start_change_cb, setting_call_back_func slider_stop_change_cb, void *cb_data) { char path_str[PATH_MAX] = {'\0',}; Evas_Object *layout = elm_layout_add(parent); char *app_res_path = app_get_resource_path(); snprintf(path_str, PATH_MAX, "%sedje/font-slider.edj", app_res_path); free(app_res_path); int r = elm_layout_file_set(layout, path_str, "elm/slider/horizontal/music/soundalive"); if (!r) { SETTING_TRACE_ERROR("elm_layout_add failed : %s", "elm/slider/horizontal/music/soundalive"); evas_object_del(layout); return NULL; } /* "elm/slider/horizontal/default" */ Evas_Object *slider = elm_slider_add(layout); retv_if(slider == NULL, NULL); elm_object_style_set(slider, "music/soundalive"); elm_slider_indicator_format_set(slider, "%1.0f"); elm_slider_indicator_show_set(slider, 5); evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5); double step = _step_size_calculate(slider, slider_min, slider_max); elm_slider_step_set(slider, step); SETTING_TRACE("slider_change_cb:%p", slider_change_cb); if (slider_change_cb) evas_object_smart_callback_add( slider, "changed", slider_change_cb, cb_data); if (slider_stop_change_cb) evas_object_smart_callback_add( slider, "slider,drag,stop", slider_stop_change_cb, cb_data); if (slider_start_change_cb) evas_object_smart_callback_add( slider, "slider,drag,start", slider_start_change_cb, cb_data); if (l_swallow_path) { Evas_Object *icon1 = elm_icon_add(slider); elm_image_file_set(icon1, l_swallow_path, NULL); evas_object_size_hint_aspect_set( icon1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); elm_object_content_set(slider, icon1); } if (r_swallow_path) { Evas_Object *icon2 = elm_icon_add(slider); elm_image_file_set(icon2, r_swallow_path, NULL); evas_object_size_hint_aspect_set( icon2, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); elm_object_part_content_set(slider, "end", icon2); } elm_slider_min_max_set(slider, slider_min, slider_max); elm_slider_value_set(slider, value); return slider; } /** * To create slider object of a genlist item * *@return a slider container object */ EXPORT_PUBLIC Evas_Object *setting_create_slider( Evas_Object *parent, Setting_GenGroupItem_Data *item_data) { /* "elm/slider/horizontal/default" */ Evas_Object *slider = elm_slider_add(parent); retv_if(slider == NULL, NULL); if (item_data->isIndicatorVisible) { elm_slider_indicator_format_set(slider, "%1.0f"); elm_slider_indicator_show_set(slider, EINA_TRUE); } else { /* for brightness slider */ elm_slider_indicator_show_set(slider, EINA_FALSE); } evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5); double step = _step_size_calculate( slider, item_data->slider_min, item_data->slider_max); elm_slider_step_set(slider, step); SETTING_TRACE("slider_change_cb:%p", item_data->chk_change_cb); if (item_data->chk_change_cb) evas_object_smart_callback_add( slider, "changed", item_data->chk_change_cb, item_data); if (item_data->stop_change_cb) evas_object_smart_callback_add( slider, "slider,drag,stop", item_data->stop_change_cb, item_data); if (item_data->start_change_cb) evas_object_smart_callback_add( slider, "slider,drag,start", item_data->start_change_cb, item_data); if (item_data->l_swallow_path) { Evas_Object *icon1 = elm_icon_add(slider); elm_image_file_set(icon1, item_data->l_swallow_path, NULL); evas_object_size_hint_aspect_set( icon1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); elm_object_content_set(slider, icon1); } if (item_data->r_swallow_path) { Evas_Object *icon2 = elm_icon_add(slider); elm_image_file_set(icon2, item_data->r_swallow_path, NULL); evas_object_size_hint_aspect_set( icon2, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); elm_object_part_content_set(slider, "end", icon2); } elm_slider_min_max_set( slider, item_data->slider_min, item_data->slider_max); elm_slider_value_set(slider, item_data->chk_status); return slider; } #define DEMO_STEP 0.8 typedef struct _setting_gif_data { Ecore_Timer *update_timer; const char **png_list; int cur_png_idx; } setting_gif_data; static void __gif_del_cb( void *data, Evas *e, Evas_Object *obj, void *event_info) { SETTING_TRACE_BEGIN; ret_if(!data); setting_gif_data *gif_data = data; if (gif_data->update_timer) {/*first delete the timer */ ecore_timer_del(gif_data->update_timer); gif_data->update_timer = NULL; } FREE(gif_data);/*delete the date. */ evas_object_data_set(obj, "gif_data", NULL); } Eina_Bool __gif_updater(void *data) { retv_if(!data, FALSE); Evas_Object *gif = data; setting_gif_data *gif_data = evas_object_data_get(gif, "gif_data"); retv_if(!gif_data, FALSE); /*SETTING_TRACE_BEGIN; */ gif_data->cur_png_idx++; /*the last element of current array. */ if (NULL == gif_data->png_list[gif_data->cur_png_idx]) gif_data->cur_png_idx = 0; elm_image_file_set( gif, gif_data->png_list[gif_data->cur_png_idx], NULL); int w = 0; int h = 0; elm_image_object_size_get(gif, &w, &h); setting_resize_object(gif, w, h); return TRUE; } EXPORT_PUBLIC Evas_Object *setting_create_image(Evas_Object *parent, const char *img_path) { Evas_Object *image = elm_image_add(parent); elm_image_file_set(image, img_path, NULL); elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE); int w = 0; int h = 0; elm_image_object_size_get(image, &w, &h); setting_resize_object(image, w, h); evas_object_show(image); return image; } /* @png_list is an array end with 'NULL'. like , const char *png_list[] = { SETTING_ICON_PATH_CFG"motions/motion_overturn_01.png", SETTING_ICON_PATH_CFG"motions/motion_overturn_02.png", SETTING_ICON_PATH_CFG"motions/motion_overturn_03.png", SETTING_ICON_PATH_CFG"motions/motion_overturn_04.png", SETTING_ICON_PATH_CFG"motions/motion_overturn_05.png", NULL //must end with 'NULL' }; */ EXPORT_PUBLIC Evas_Object *setting_create_gif(Evas_Object *parent, const char **png_list) { retv_if(!png_list, NULL); setting_gif_data *gif_data = calloc(1, sizeof(setting_gif_data)); setting_retvm_if(!gif_data, NULL, "calloc failed"); gif_data->cur_png_idx = 0; gif_data->png_list = png_list; SETTING_TRACE_BEGIN; /*the first element */ Evas_Object *gif = setting_create_image(parent, *png_list); /*bind object data */ evas_object_data_set(gif, "gif_data", gif_data); evas_object_event_callback_add( gif, EVAS_CALLBACK_DEL, __gif_del_cb, gif_data); if (gif_data->update_timer) { ecore_timer_del(gif_data->update_timer); gif_data->update_timer = NULL; } gif_data->update_timer = ecore_timer_add( DEMO_STEP, (Ecore_Task_Cb)__gif_updater, gif); /* W011:bg, T051:text */ setting_decorate_image_RGBA(gif, 14, 41, 73, 255); return gif; } /** * Set the status of radio group object via its binded vconf value. * @return 0: success, other: failed */ EXPORT_PUBLIC int setting_update_chk_status(Evas_Object *chk, setting_int_slp_list type) { SETTING_TRACE_BEGIN; /* error check */ if (chk == NULL) return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER; SETTING_TRACE_BEGIN; int ret = SETTING_RETURN_FAIL; int value; int err; /* value set */ ret = setting_get_int_slp_key(type, &value, &err); SETTING_TRACE("binded: %d, checked: %d, err: %d", type, value, err); elm_radio_value_set(chk, value); return ret; } /** * Create a size specialized rectangle object * @return a size specialized rectangle object */ EXPORT_PUBLIC Evas_Object *setting_create_blank_rect_customize( Evas_Object *layout, int w, int h) { Evas_Object *rect; rect = evas_object_rectangle_add(evas_object_evas_get(layout)); evas_object_size_hint_min_set( rect, ELM_SCALE_SIZE(w), ELM_SCALE_SIZE(h)); evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, 0); evas_object_color_set(rect, 8, 8, 8, 8); return rect; } /** * Create a text box, which cannot be edited, just to show a specialization * segment. * * @return a text box, which cannot be edited */ EXPORT_PUBLIC Evas_Object *setting_create_textbox(Evas_Object *parent, const char *content) { Evas_Object *obj = NULL; obj = elm_entry_add(parent); evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, 0.5); elm_entry_single_line_set(obj, 0); elm_entry_editable_set(obj, 0); elm_entry_context_menu_disabled_set(obj, 1); elm_entry_entry_set(obj, content); evas_object_show(obj); return obj; } /** * To resize a evas object, such as, icon, button.. * * @param[in] obj * @param[in] w * @param[in] h */ EXPORT_PUBLIC void setting_resize_object(Evas_Object *obj, Evas_Coord w, Evas_Coord h) { if (obj) { evas_object_size_hint_min_set( obj, ELM_SCALE_SIZE(w), ELM_SCALE_SIZE(h)); evas_object_size_hint_max_set(obj, w, h); evas_object_resize(obj, w, h); } } /** * To create a bg object * * @param[in] parent * @param[in] bg_style * @return bg object */ EXPORT_PUBLIC Evas_Object *setting_create_bg( Evas_Object *parent, Evas_Object *win, const char *bg_style) { retv_if(!parent, NULL); Evas_Object *bg = elm_bg_add(parent); retv_if(!bg, NULL); if (bg_style) elm_object_style_set(bg, bg_style); evas_object_size_hint_weight_set( bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(bg); return bg; } #define DIFF_TIMES 2 /** * To make an object which is operated by setting_dim_evas_object normal color * * @param[in] obj * @param[in] b_transparency_set: * 1:the appearance of obj is made up of transparent background color. * 0:the appearance of obj is made up of non transparent color. */ EXPORT_PUBLIC void setting_undo_dim_evas_object(Evas_Object *obj, bool b_transparency) { if (obj) { int r; int g; int b; int a; evas_object_color_get(obj, &r, &g, &b, &a); /*the appearance of obj is made up of transparent background * color. */ if (b_transparency) a *= DIFF_TIMES; evas_object_color_set( obj, r * DIFF_TIMES, g * DIFF_TIMES, b * DIFF_TIMES, a); } } /** * To make an object dim color * * @param[in] obj * @param[in] b_transparency_set: * 1:the appearance of obj is made up of transparent background color. * 0:the appearance of obj is made up of non transparent color. */ EXPORT_PUBLIC void setting_dim_evas_object(Evas_Object *obj, bool b_transparency) { if (obj) { int r; int g; int b; int a; evas_object_color_get(obj, &r, &g, &b, &a); /*the appearance of obj is made up of transparent background * color. */ if (b_transparency) a /= DIFF_TIMES; evas_object_color_set( obj, r / DIFF_TIMES, g / DIFF_TIMES, b / DIFF_TIMES, a); } } /* * set font_size, color or align(right, left, middle),if need, you * can add , or to controll a segment words; * or else the text will take the same effect until the end of text. * @param[in] input_str * @param[in] font_size * @param[in] color * @param[in] align :may be right, left, middle/center */ EXPORT_PUBLIC char *setting_customize_text( const char *input_str, const int font_size, const char *color, const char *align) { /*SETTING_TRACE_BEGIN; */ retv_if(isEmptyStr(input_str), NULL); char specialization[MAX_SPECIALIZATION_LEN] = { 0, }; /*bbb * */ if (font_size > 0) { snprintf(specialization, sizeof(specialization), "", font_size); } if (align) { g_strlcat(specialization, "", MAX_SPECIALIZATION_LEN); } if (color) { char input_str1[MAX_SPECIALIZATION_LEN] = { 0, }; safeCopyStr(input_str1, input_str, MAX_SPECIALIZATION_LEN - 1); char *p = strstr(input_str1, "' != p[0]) { /*invalid format */ g_strlcat(specialization, "", MAX_SPECIALIZATION_LEN); g_strlcat(specialization, input_str, MAX_SPECIALIZATION_LEN); g_strlcat(specialization, "", MAX_SPECIALIZATION_LEN); } else g_strlcat(specialization, input_str1, MAX_SPECIALIZATION_LEN); } else { g_strlcat(specialization, "", MAX_SPECIALIZATION_LEN); g_strlcat(specialization, input_str, MAX_SPECIALIZATION_LEN); g_strlcat(specialization, "", MAX_SPECIALIZATION_LEN); } } else { g_strlcat(specialization, input_str, MAX_SPECIALIZATION_LEN); } if (align) { g_strlcat(specialization, "", MAX_SPECIALIZATION_LEN); } if (font_size > 0) { g_strlcat(specialization, "", MAX_SPECIALIZATION_LEN); } return strdup(specialization);; } EXPORT_PUBLIC void setting_conformant_keypad_state( Evas_Object *window, bool enable) { Evas_Object *conform = evas_object_data_get(window, "conformant"); if (conform) { SETTING_TRACE("conformant keypad %d", enable); if (enable) { elm_object_signal_emit(conform, "elm,state,virtualkeypad,enable", ""); elm_object_signal_emit(conform, "elm,state,clipboard,enable", ""); } else { elm_object_signal_emit(conform, "elm,state,virtualkeypad,disable", ""); elm_object_signal_emit(conform, "elm,state,clipboard,disable", ""); } } } EXPORT_PUBLIC void setting_decorate_image_RGBA(Evas_Object *obj, int r, int g, int b, int a) { if (obj) evas_object_color_set(obj, r, g, b, a); } EXPORT_PUBLIC void setting_protect_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) { if (NULL != data) *((void **)data) = NULL; } EXPORT_PUBLIC void setting_add_gl_help(Evas_Object *scroller, const char *str) { if (str) { Setting_GenGroupItem_Data *item_data = setting_create_Gendial_field_def( scroller, &itc_multiline_text, NULL, NULL, SWALLOW_Type_LAYOUT_SPECIALIZATION_X, NULL, NULL, 0, str, NULL, NULL); if (NULL == item_data) { SETTING_TRACE_ERROR("item_data is NULL"); return; } elm_genlist_item_select_mode_set( item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); } } EXPORT_PUBLIC Evas_Object *setting_add_empty_page(Evas_Object *parent, const char *text, const char *help) { Evas_Object *layout = NULL; layout = elm_layout_add(parent); elm_layout_theme_set(layout, "layout", "nocontents", "default"); evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_object_part_text_set(layout, "elm.text", _(text)); if (help) { elm_object_part_text_set(layout, "elm.help.text", _(help)); elm_layout_signal_emit(layout, "align.center", "elm"); } return layout; }