3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.1 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 #include <setting-common-draw-widget.h>
22 #include <efl_assist.h>
25 * Hide the input pannel
29 void setting_hide_input_pannel_cb(Evas_Object *entry)
31 ret_if(entry == NULL);
32 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
34 ecore_imf_context_input_panel_hide(imf_context);
37 elm_object_focus_set(entry, EINA_FALSE);
38 Evas_Object *entry_container = elm_object_parent_widget_get(entry);
41 if (elm_entry_is_empty(entry))
42 elm_object_signal_emit(entry_container, "elm,state,guidetext,show", "elm");
43 elm_object_signal_emit(entry_container, "elm,state,eraser,hide", "elm");
47 Evas_Object *setting_create_button(Evas_Object *parent, const char *btn_str,
48 const char *btn_style,
49 setting_call_back_func btn_click_cb,
52 retv_if(!parent || !btn_str, NULL);
53 if ('\0' == btn_str[0]) {//Empty rectangle
54 return setting_create_blank_rect_customize(parent,
55 SETTING_PADDING_WIDTH,
56 SETTING_PADDING_WIDTH);
59 Evas_Object *button = elm_button_add(parent);
61 elm_object_style_set(button, btn_style);
64 if (0 != safeStrCmp(NAVI_BACK_BUTTON_STYLE, btn_style)) {//not '<-' button
65 elm_object_text_set(button, btn_str);
67 evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
68 evas_object_size_hint_align_set(button,EVAS_HINT_FILL, 0.5);
72 evas_object_smart_callback_add(button, "clicked",
73 btn_click_cb, cb_data);
75 evas_object_show(button);
81 * To create slider object of a genlist item
83 *@return a slider container object
85 Evas_Object *setting_create_slider(Evas_Object *parent, Evas *evas,
86 const char *l_swallow_path,
87 const char *r_swallow_path, double value,
88 bool indicator, double slider_min, double slider_max,
89 setting_call_back_func slider_change_cb,
90 setting_call_back_func slider_start_change_cb,
91 setting_call_back_func slider_stop_change_cb,
94 Evas_Object *slider = elm_slider_add(parent); /* "elm/slider/horizontal/default" */
95 retv_if(slider == NULL, NULL);
99 elm_slider_indicator_format_set(slider, "%1.0f");
103 /* for brightness slider */
104 elm_slider_indicator_show_set(slider, EINA_FALSE);
106 elm_object_style_set(slider, "ebook");
110 evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0);
111 evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5);
113 if (slider_change_cb)
114 evas_object_smart_callback_add(slider, "changed", slider_change_cb, cb_data);
116 if (slider_stop_change_cb)
117 evas_object_smart_callback_add(slider, "slider,drag,stop", slider_stop_change_cb, cb_data);
119 if(slider_start_change_cb)
120 evas_object_smart_callback_add(slider, "slider,drag,start", slider_start_change_cb, cb_data);
122 Evas_Object *icon1 = elm_icon_add(slider);
123 elm_icon_file_set(icon1, l_swallow_path, NULL);
124 evas_object_size_hint_aspect_set(icon1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
126 Evas_Object *icon2 = elm_icon_add(slider);
127 elm_icon_file_set(icon2, r_swallow_path, NULL);
128 evas_object_size_hint_aspect_set(icon2, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
130 elm_object_content_set(slider, icon1);
131 elm_object_part_content_set(slider, "end", icon2);
133 elm_slider_min_max_set(slider, slider_min, slider_max);
134 elm_slider_value_set(slider, value);
139 * The main implement body of create a certain size icon
141 void create_image_box_add_ex(void *data, Evas_Object *win_main, Evas *evas,
142 char *img_path, int img_w, int img_h,
143 Evas_Object_Event_Cb mouse_down_cb,
144 Evas_Object_Event_Cb mouse_up_cb,
145 Evas_Object **image_box, Evas_Object **img)
147 /* SETTING_TRACE_BEGIN; */
148 *image_box = elm_box_add(win_main);
149 retm_if(*image_box == NULL, "Cannot get box");
150 elm_box_horizontal_set(*image_box, 1);
151 evas_object_size_hint_align_set(*image_box, 0.0, EVAS_HINT_FILL); /* */
152 evas_object_show(*image_box);
154 *img = evas_object_image_add(evas);
155 evas_object_size_hint_weight_set(*img, 0.0, EVAS_HINT_EXPAND);
160 evas_object_image_file_set(*img, img_path, NULL);
161 if (img_h <= 0 || temp_w <= 0) //error handling. load the image as it's own size
163 evas_object_image_size_get(*img, &temp_w, &temp_h);
166 evas_object_image_load_size_set(*img, temp_w, temp_h);
167 evas_object_image_fill_set(*img, 0, 0, temp_w, temp_h);
169 evas_object_size_hint_min_set(*img, temp_w, temp_h);
170 evas_object_show(*img);
172 evas_object_event_callback_add(*img, EVAS_CALLBACK_MOUSE_DOWN,
173 mouse_down_cb, data);
174 evas_object_event_callback_add(*img, EVAS_CALLBACK_MOUSE_UP,
177 elm_box_pack_end(*image_box, *img);
181 * To create a size fixed icon
182 * @return a image container object
185 Evas_Object *create_image_box_add(void *data, Evas_Object *win_main,
186 Evas *evas, char *img_path, int img_w,
187 int img_h, Evas_Object_Event_Cb mouse_down_cb,
188 Evas_Object_Event_Cb mouse_up_cb)
190 /* SETTING_TRACE_BEGIN; */
191 Evas_Object *image_box = NULL;
192 Evas_Object *img = NULL;
193 create_image_box_add_ex(data, win_main, evas, img_path,
194 img_w * WIDGET_SCALE_FACTOR,
195 img_h * WIDGET_SCALE_FACTOR, mouse_down_cb,
196 mouse_up_cb, &image_box, &img);
202 * To create a size specialized icon
204 * @return a image container object
207 Evas_Object *create_bgimage_box_add(void *data, Evas_Object *win_main, Evas *evas, char *img_path, int img_w, int img_h, /* if img_w<0 or img_h <0, load the image as it's own size */
208 Evas_Object_Event_Cb mouse_down_cb,
209 Evas_Object_Event_Cb mouse_up_cb)
211 Evas_Object *image_box = NULL;
212 Evas_Object *img = NULL;
213 create_image_box_add_ex(data, win_main, evas, img_path, img_w, img_h,
214 mouse_down_cb, mouse_up_cb, &image_box, &img);
219 * @ create a box container
221 * @param[in] win_main
223 * @return a box container
225 Evas_Object *setting_create_client_bx(Evas_Object *win_main)
227 Evas_Object *client_bx = NULL;
229 client_bx = elm_box_add(win_main);
230 retvm_if(client_bx == NULL, NULL, "Cannot create client box object");
232 elm_box_horizontal_set(client_bx, 0);
233 evas_object_size_hint_weight_set(client_bx, EVAS_HINT_EXPAND, 0.0);
234 evas_object_size_hint_align_set(client_bx, EVAS_HINT_FILL, 0.0);
240 Evas_Object *setting_create_lable(Evas_Object *parent, const char *text,
241 const char *style, const char *align)
243 retvm_if(!parent || !text, NULL, "Cannot create client box object");
244 Evas_Object *label = NULL;
245 if (0 == safeStrCmp(style, "entry"))
247 SETTING_TRACE("style:%s", style);
248 label = elm_entry_add(parent);
249 elm_entry_editable_set(label, EINA_FALSE);
253 label = elm_label_add(parent);
254 elm_object_style_set(label, style);
255 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
257 const char *str = setting_customize_text(text, 0, NULL, align);
258 elm_object_text_set(label, str);
260 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
261 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
262 evas_object_show(label);
266 #define DEMO_STEP 0.4
267 typedef struct _setting_gif_data{
268 Ecore_Timer *update_timer;
269 const char **png_list;
273 static void __gif_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
277 setting_gif_data *gif_data = data;
278 if (gif_data->update_timer) {//first delete the timer
279 ecore_timer_del(gif_data->update_timer);
280 gif_data->update_timer = NULL;
282 FREE(gif_data);//delete the date.
283 evas_object_data_set(obj, "gif_data", NULL);
286 Eina_Bool __gif_updater(void *data)
288 retv_if(!data, FALSE);
289 Evas_Object *gif = data;
290 setting_gif_data *gif_data = evas_object_data_get(gif, "gif_data");
291 retv_if(!gif_data, FALSE);
294 gif_data->cur_png_idx++;
295 if (NULL == gif_data->png_list[gif_data->cur_png_idx]) { //the last element of current array.
296 gif_data->cur_png_idx = 0;
298 elm_image_file_set(gif, gif_data->png_list[gif_data->cur_png_idx], NULL);
301 elm_image_object_size_get(gif, &w, &h);
302 setting_resize_object(gif, w, h);
307 Evas_Object *setting_create_image(Evas_Object *parent, const char *img_path)
309 Evas_Object *image = elm_image_add(parent);
310 //SETTING_TRACE("icon_path:%s", icon_path);
311 elm_image_file_set(image, img_path, NULL);
312 elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
316 elm_image_object_size_get(image, &w, &h);
317 setting_resize_object(image, w, h);
318 evas_object_show(image);
322 /* @png_list is an array end with 'NULL'. like ,
323 const char *png_list[] = {
324 SETTING_ICON_PATH_CFG"motions/motion_overturn_01.png",
325 SETTING_ICON_PATH_CFG"motions/motion_overturn_02.png",
326 SETTING_ICON_PATH_CFG"motions/motion_overturn_03.png",
327 SETTING_ICON_PATH_CFG"motions/motion_overturn_04.png",
328 SETTING_ICON_PATH_CFG"motions/motion_overturn_05.png",
329 NULL //must end with 'NULL'
332 Evas_Object *setting_create_gif(Evas_Object *parent, const char **png_list)
334 retv_if(!png_list, NULL);
335 setting_gif_data *gif_data = calloc(1,sizeof(setting_gif_data));
336 setting_retvm_if(!gif_data, NULL, "calloc failed");
337 gif_data->cur_png_idx = 0;
338 gif_data->png_list = png_list;
342 Evas_Object *gif = setting_create_image(parent, *png_list);//the first element
344 evas_object_data_set(gif, "gif_data", gif_data);
345 evas_object_event_callback_add(gif, EVAS_CALLBACK_DEL, __gif_del_cb, gif_data);
347 if (gif_data->update_timer) {
348 ecore_timer_del(gif_data->update_timer);
349 gif_data->update_timer = NULL;
351 gif_data->update_timer = ecore_timer_add(DEMO_STEP, (Ecore_Task_Cb)__gif_updater, gif);
357 * Set the vconf value via its binded check object.
358 * @return 0: sucess, other: failed
361 int setting_reset_slp_key_by_status(Evas_Object *obj,
362 setting_bool_slp_list key)
368 status = elm_check_state_get(obj);
371 setting_set_bool_slp_key(key, SETTING_ON_OFF_BTN_ON, &err);
374 setting_set_bool_slp_key(key, SETTING_ON_OFF_BTN_OFF, &err);
380 * Alternate the check object status and its binded vcof value via original vcofn value
382 int setting_draw_onoff_status(Evas_Object *obj, setting_bool_slp_list key)
388 setting_get_bool_slp_key(key, &value, &err);
390 elm_check_state_set(obj, !value);
391 ret = setting_set_bool_slp_key(key, !value, &err);
396 * Set the status of check object via its binded vconf value.
397 * @return 0: sucess, other: failed
399 int setting_check_onoff_status(Evas_Object *obj, setting_bool_slp_list key)
405 ret = setting_get_bool_slp_key(key, &value, &err);
406 elm_check_state_set(obj, value);
411 * Set the status of radio group object via its binded vconf value.
412 * @return 0: sucess, other: failed
414 int setting_update_chk_status(Evas_Object *chk, setting_int_slp_list type)
419 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
424 int ret = SETTING_RETURN_FAIL;
429 ret = setting_get_int_slp_key(type, &value, &err);
430 SETTING_TRACE("binded: %d, checked: %d, err: %d", type, value, err);
432 elm_radio_value_set(chk, value);
438 * Create a size specilized rectangle object
439 * @return a size specilized rectangle object
441 Evas_Object *setting_create_blank_rect_customize(Evas_Object *layout, int w,
446 rect = evas_object_rectangle_add(evas_object_evas_get(layout));
447 evas_object_size_hint_min_set(rect, w, h);
448 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, 0);
449 evas_object_color_set(rect, 0, 0, 0, 0);
455 * Create a size fixed rectangle object
459 * @return a size fixed rectangle object
461 Evas_Object *setting_create_blank_rect(Evas_Object *layout)
463 return setting_create_blank_rect_customize(layout,
464 SETTING_PADDING_WIDTH, 80);
468 * The API to Create an editfiled object
469 * @return an editfiled object
471 Evas_Object * /* multi-line is default, use elm_editfield_entry_single_line_set(ef, EINA_TRUE) to set single-line */
472 setting_create_editfiled(Evas_Object *win_main, char *title, char *def_str)
474 Evas_Object *layout = NULL;
475 Evas_Object *entry = NULL;
476 layout = elm_layout_add(win_main);
480 elm_layout_theme_set(layout, "layout", "editfield", "title");
481 elm_object_part_text_set(layout, "elm.text", title);
485 elm_layout_theme_set(layout, "layout", "editfield", "default");
487 entry = elm_entry_add(win_main);
488 elm_object_part_content_set(layout, "elm.swallow.content", entry);
489 //elm_entry_context_menu_disabled_set(entry, TRUE);
490 //elm_entry_magnifier_disabled_set(entry, TRUE);
491 elm_entry_prediction_allow_set(entry, FALSE);
493 if (def_str && safeStrLen(def_str) > 0) {
494 elm_entry_entry_set(entry, def_str);
496 elm_object_part_text_set(layout, "elm.guidetext", _("IDS_ST_BODY_TAP_TO_INSERT"));
499 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0);
500 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 0);
502 evas_object_show(layout);
507 * Create a text box, which cannot be edited, just to show a specilization segment.
509 * @return a text box, which cannot be edited
511 Evas_Object *setting_create_textbox(Evas_Object *parent, const char *content)
513 Evas_Object *obj = NULL;
515 obj = elm_entry_add(parent);
516 evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, 0.0);
517 evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, 0.5);
518 elm_entry_single_line_set(obj, 0);
519 /* elm_entry_line_wrap_set(obj, 1); */
520 elm_entry_editable_set(obj, 0);
521 elm_entry_context_menu_disabled_set(obj, 1);
523 /* setting_disable_evas_object(obj); ***disable any events on entry */
525 elm_entry_entry_set(obj, content);
526 evas_object_show(obj);
531 * Make it no effect when clicking on a evas object and its sub-objects, such as, layout, genlist
535 void setting_disable_evas_object(Evas_Object *obj)
536 { /* layout\genlist\scroller\elm_entry etc.. */
538 evas_object_pass_events_set(obj, EINA_TRUE);
543 * Make it normal acting when clicking on a evas object, such as, layout, genlist
547 void setting_enable_evas_object(Evas_Object *obj)
550 evas_object_pass_events_set(obj, EINA_FALSE);
555 * To resize a evas object, such as, icon, button..
561 void setting_resize_object(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
564 evas_object_size_hint_min_set(obj, w, h);
565 evas_object_size_hint_max_set(obj, w, h);
566 evas_object_resize(obj, w, h);
571 * To create a bg object
574 * @param[in] bg_style
577 Evas_Object *setting_create_bg(Evas_Object *parent,Evas_Object *win, const char *bg_style)
579 retv_if(!parent, NULL);
580 Evas_Object *bg = elm_bg_add(parent);
582 elm_object_style_set(bg, bg_style);
583 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
585 //elm_win_resize_object_add(win, bg);
586 evas_object_show(bg);
593 * To make an object which is operated by setting_dim_evas_object normal color
596 * @param[in] b_transparency_set:
597 * 1:the appearence of obj is made up of transparent backgroud color.
598 * 0:the appearence of obj is made up of non transparent color.
600 void setting_undo_dim_evas_object(Evas_Object *obj, bool b_transparenct)
607 evas_object_color_get(obj, &r, &g, &b, &a);
608 if (b_transparenct) {//the appearence of obj is made up of transparent backgroud color.
611 evas_object_color_set(obj, r * DIFF_TIMES, g * DIFF_TIMES, b * DIFF_TIMES, a);
616 * To make an object dim color
619 * @param[in] b_transparency_set:
620 * 1:the appearence of obj is made up of transparent backgroud color.
621 * 0:the appearence of obj is made up of non transparent color.
623 void setting_dim_evas_object(Evas_Object *obj, bool b_transparenct)
630 evas_object_color_get(obj, &r, &g, &b, &a);
631 if (b_transparenct) {//the appearence of obj is made up of transparent backgroud color.
634 evas_object_color_set(obj, r / DIFF_TIMES, g / DIFF_TIMES, b / DIFF_TIMES, a);
638 static void __btn_select_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
640 setting_dim_evas_object(obj, FALSE);
643 static void __btn_release_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
645 setting_undo_dim_evas_object(obj, FALSE);
649 * To make an object looks clickable: if pressed, it is dim color;if unpressed, it is normal color;
653 void setting_make_evas_object_clickable(Evas_Object *obj)
656 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN, __btn_select_cb, NULL);
657 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP, __btn_release_cb, NULL);
662 * To create an icon which looks clickable(if pressed, it is dim color;if unpressed, it is normal color)
665 * @param[in] img_path
671 Evas_Object *setting_create_icon(Evas_Object *parent, const char *img_path,
672 Evas_Object_Event_Cb up_cb,
673 Evas_Object_Event_Cb down_cb,
674 Evas_Object_Event_Cb move_cb,
678 retv_if(!parent || !img_path, NULL);
679 Evas_Object *icon = elm_icon_add(parent);
680 retvm_if(!icon, NULL, "Failed Create icon!");
681 elm_icon_file_set(icon, img_path, NULL);
682 setting_make_evas_object_clickable(icon);
685 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_UP,
689 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_DOWN,
693 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_MOVE,
701 * To create a button which only has a image and looks clickable
702 * (if pressed, it is dim color;if unpressed, it is normal color)
704 * @param[in] img_path
710 Evas_Object *setting_create_image_button(Evas_Object *parent,
712 setting_call_back_func clicked_cb,
713 setting_call_back_func unpressed_cb,
717 retv_if(!parent, NULL);
718 Evas_Object *btn = elm_button_add(parent);
719 retvm_if(!btn, NULL, "Failed Create button!");
721 evas_object_smart_callback_add(btn, "clicked", clicked_cb, data);
725 evas_object_smart_callback_add(btn, "unpressed", unpressed_cb, data);
729 Evas_Object *icon = elm_icon_add(parent);
730 retvm_if(!icon, NULL, "Failed Create icon!");
731 elm_icon_file_set(icon, btn_img, NULL);
732 elm_object_part_content_set(btn, "elm.swallow.content", icon);
733 setting_make_evas_object_clickable(btn);
742 * set font_size, color or align(right, left, middle),if need, you
743 * can add </font_siz>, </color> or </align> to controll a segment words; or else
744 * the text will take the same effect until the end of text.
745 * @param[in] input_str
746 * @param[in] font_size
748 * @param[in] align :may be right, left, middle/center
750 char *setting_customize_text(const char *input_str, const int font_size,
751 const char *color, const char *align)
754 retv_if(isEmptyStr(input_str), NULL);
755 SETTING_TRACE("input_str:%s, color:%s", input_str, color);
756 char speciliztion[MAX_SPECIALIZITION_LEN] = { 0, };
757 //<font_size=%d><align=middle><color=#9C9C9C>bbb</color></align></font_size>
760 snprintf(speciliztion, sizeof(speciliztion),
761 "<font_size=%d>", font_size);
766 g_strlcat(speciliztion, "<align=", MAX_SPECIALIZITION_LEN);
767 g_strlcat(speciliztion, align, MAX_SPECIALIZITION_LEN);
768 g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
773 char input_str1[MAX_SPECIALIZITION_LEN] = { 0, };
774 safeCopyStr(input_str1, input_str, MAX_SPECIALIZITION_LEN);
775 char *p = strstr(input_str1, "<color=");
776 if(p) //already has customed color,to replace color sub_string
778 p += strlen("<color=");
779 //memcpy(p, color, strlen(color));
780 char *q = (char *)color;
781 while ('\0' != p[0] && '\0' != q[0])
787 if('>' != p[0]) //invalid format
789 g_strlcat(speciliztion, "<color=", MAX_SPECIALIZITION_LEN);
790 g_strlcat(speciliztion, color, MAX_SPECIALIZITION_LEN);
791 g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
792 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
793 g_strlcat(speciliztion, "</color>", MAX_SPECIALIZITION_LEN);
796 g_strlcat(speciliztion, input_str1, MAX_SPECIALIZITION_LEN);
800 g_strlcat(speciliztion, "<color=", MAX_SPECIALIZITION_LEN);
801 g_strlcat(speciliztion, color, MAX_SPECIALIZITION_LEN);
802 g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
803 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
804 g_strlcat(speciliztion, "</color>", MAX_SPECIALIZITION_LEN);
809 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
813 g_strlcat(speciliztion, "</align>", MAX_SPECIALIZITION_LEN);
817 g_strlcat(speciliztion, "</font_size>", MAX_SPECIALIZITION_LEN);
820 SETTING_TRACE("Exit %s, return :%s", __FUNCTION__, speciliztion);
821 return (char *)strdup(speciliztion);;