3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.0 (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>
23 * Hide the input pannel
27 void setting_hide_input_pannel_cb(Evas_Object *entry)
29 ret_if(entry == NULL);
30 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
32 ecore_imf_context_input_panel_hide(imf_context);
35 elm_object_focus_set(entry, EINA_FALSE);
36 Evas_Object *entry_container = elm_object_parent_widget_get(entry);
39 if (elm_entry_is_empty(entry))
40 elm_object_signal_emit(entry_container, "elm,state,guidetext,show", "elm");
41 elm_object_signal_emit(entry_container, "elm,state,eraser,hide", "elm");
45 Evas_Object *setting_create_button(Evas_Object *parent, const char *btn_str,
46 const char *btn_style,
47 setting_call_back_func btn_click_cb,
50 retv_if(!parent || !btn_str, NULL);
51 if ('\0' == btn_str[0]) {//Empty rectangle
52 return setting_create_blank_rect_customize(parent,
53 SETTING_PADDING_WIDTH,
54 SETTING_PADDING_WIDTH);
57 Evas_Object *button = elm_button_add(parent);
59 elm_object_style_set(button, btn_style);
62 if (0 != safeStrCmp(NAVI_BACK_BUTTON_STYLE, btn_style)) {//not '<-' button
63 elm_object_text_set(button, btn_str);
65 evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
66 evas_object_size_hint_align_set(button,EVAS_HINT_FILL, 0.5);
70 evas_object_smart_callback_add(button, "clicked",
71 btn_click_cb, cb_data);
73 evas_object_show(button);
79 * To create slider object of a genlist item
81 *@return a slider container object
83 Evas_Object *setting_create_slider(Evas_Object *parent, Evas *evas,
84 const char *l_swallow_path,
85 const char *r_swallow_path, double value,
86 bool indicator, double slider_min, double slider_max,
87 setting_call_back_func slider_change_cb,
88 setting_call_back_func slider_start_change_cb,
89 setting_call_back_func slider_stop_change_cb,
92 Evas_Object *slider = elm_slider_add(parent); /* "elm/slider/horizontal/default" */
93 retv_if(slider == NULL, NULL);
97 elm_slider_indicator_format_set(slider, "%1.0f");
101 /* for brightness slider */
102 elm_slider_indicator_show_set(slider, EINA_FALSE);
104 elm_object_style_set(slider, "ebook");
108 evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0);
109 evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5);
111 if (slider_change_cb)
112 evas_object_smart_callback_add(slider, "changed", slider_change_cb, cb_data);
114 if (slider_stop_change_cb)
115 evas_object_smart_callback_add(slider, "slider,drag,stop", slider_stop_change_cb, cb_data);
117 if(slider_start_change_cb)
118 evas_object_smart_callback_add(slider, "slider,drag,start", slider_start_change_cb, cb_data);
120 Evas_Object *icon1 = elm_icon_add(slider);
121 elm_icon_file_set(icon1, l_swallow_path, NULL);
122 evas_object_size_hint_aspect_set(icon1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
124 Evas_Object *icon2 = elm_icon_add(slider);
125 elm_icon_file_set(icon2, r_swallow_path, NULL);
126 evas_object_size_hint_aspect_set(icon2, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
128 elm_object_content_set(slider, icon1);
129 elm_object_part_content_set(slider, "end", icon2);
131 elm_slider_min_max_set(slider, slider_min, slider_max);
132 elm_slider_value_set(slider, value);
137 * The main implement body of create a certain size icon
139 void create_image_box_add_ex(void *data, Evas_Object *win_main, Evas *evas,
140 char *img_path, int img_w, int img_h,
141 Evas_Object_Event_Cb mouse_down_cb,
142 Evas_Object_Event_Cb mouse_up_cb,
143 Evas_Object **image_box, Evas_Object **img)
145 /* SETTING_TRACE_BEGIN; */
146 *image_box = elm_box_add(win_main);
147 retm_if(*image_box == NULL, "Cannot get box");
148 elm_box_horizontal_set(*image_box, 1);
149 evas_object_size_hint_align_set(*image_box, 0.0, EVAS_HINT_FILL); /* */
150 evas_object_show(*image_box);
152 *img = evas_object_image_add(evas);
153 evas_object_size_hint_weight_set(*img, 0.0, EVAS_HINT_EXPAND);
158 evas_object_image_file_set(*img, img_path, NULL);
159 if (img_h <= 0 || temp_w <= 0) //error handling. load the image as it's own size
161 evas_object_image_size_get(*img, &temp_w, &temp_h);
164 evas_object_image_load_size_set(*img, temp_w, temp_h);
165 evas_object_image_fill_set(*img, 0, 0, temp_w, temp_h);
167 evas_object_size_hint_min_set(*img, temp_w, temp_h);
168 evas_object_show(*img);
170 evas_object_event_callback_add(*img, EVAS_CALLBACK_MOUSE_DOWN,
171 mouse_down_cb, data);
172 evas_object_event_callback_add(*img, EVAS_CALLBACK_MOUSE_UP,
175 elm_box_pack_end(*image_box, *img);
179 * To create a size fixed icon
180 * @return a image container object
183 Evas_Object *create_image_box_add(void *data, Evas_Object *win_main,
184 Evas *evas, char *img_path, int img_w,
185 int img_h, Evas_Object_Event_Cb mouse_down_cb,
186 Evas_Object_Event_Cb mouse_up_cb)
188 /* SETTING_TRACE_BEGIN; */
189 Evas_Object *image_box = NULL;
190 Evas_Object *img = NULL;
191 create_image_box_add_ex(data, win_main, evas, img_path,
192 img_w * WIDGET_SCALE_FACTOR,
193 img_h * WIDGET_SCALE_FACTOR, mouse_down_cb,
194 mouse_up_cb, &image_box, &img);
200 * To create a size specialized icon
202 * @return a image container object
205 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 */
206 Evas_Object_Event_Cb mouse_down_cb,
207 Evas_Object_Event_Cb mouse_up_cb)
209 Evas_Object *image_box = NULL;
210 Evas_Object *img = NULL;
211 create_image_box_add_ex(data, win_main, evas, img_path, img_w, img_h,
212 mouse_down_cb, mouse_up_cb, &image_box, &img);
217 * @ create a box container
219 * @param[in] win_main
221 * @return a box container
223 Evas_Object *setting_create_client_bx(Evas_Object *win_main)
225 Evas_Object *client_bx = NULL;
227 client_bx = elm_box_add(win_main);
228 retvm_if(client_bx == NULL, NULL, "Cannot create client box object");
230 elm_box_horizontal_set(client_bx, 0);
231 evas_object_size_hint_weight_set(client_bx, EVAS_HINT_EXPAND, 0.0);
232 evas_object_size_hint_align_set(client_bx, EVAS_HINT_FILL, 0.0);
238 Evas_Object *setting_create_lable(Evas_Object *parent, const char *text,
239 const char *style, const char *align)
241 retvm_if(!parent || !text, NULL, "Cannot create client box object");
242 Evas_Object *label = NULL;
243 if (0 == safeStrCmp(style, "entry"))
245 SETTING_TRACE("style:%s", style);
246 label = elm_entry_add(parent);
247 elm_entry_editable_set(label, EINA_FALSE);
251 label = elm_label_add(parent);
252 elm_object_style_set(label, style);
253 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
255 const char *str = setting_customize_text(text, 0, NULL, align);
256 elm_object_text_set(label, str);
258 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
259 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
260 evas_object_show(label);
264 #define DEMO_STEP 0.4
265 typedef struct _setting_gif_data{
266 Ecore_Timer *update_timer;
267 const char **png_list;
271 static void __gif_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
275 setting_gif_data *gif_data = data;
276 if (gif_data->update_timer) {//first delete the timer
277 ecore_timer_del(gif_data->update_timer);
278 gif_data->update_timer = NULL;
280 FREE(gif_data);//delete the date.
281 evas_object_data_set(obj, "gif_data", NULL);
284 Eina_Bool __gif_updater(void *data)
286 retv_if(!data, FALSE);
287 Evas_Object *gif = data;
288 setting_gif_data *gif_data = evas_object_data_get(gif, "gif_data");
289 retv_if(!gif_data, FALSE);
292 gif_data->cur_png_idx++;
293 if (NULL == gif_data->png_list[gif_data->cur_png_idx]) { //the last element of current array.
294 gif_data->cur_png_idx = 0;
296 elm_image_file_set(gif, gif_data->png_list[gif_data->cur_png_idx], NULL);
299 elm_image_object_size_get(gif, &w, &h);
300 setting_resize_object(gif, w, h);
305 Evas_Object *setting_create_image(Evas_Object *parent, const char *img_path)
307 Evas_Object *image = elm_image_add(parent);
308 //SETTING_TRACE("icon_path:%s", icon_path);
309 elm_image_file_set(image, img_path, NULL);
310 elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
314 elm_image_object_size_get(image, &w, &h);
315 setting_resize_object(image, w, h);
316 evas_object_show(image);
320 /* @png_list is an array end with 'NULL'. like ,
321 const char *png_list[] = {
322 SETTING_ICON_PATH_CFG"motions/motion_overturn_01.png",
323 SETTING_ICON_PATH_CFG"motions/motion_overturn_02.png",
324 SETTING_ICON_PATH_CFG"motions/motion_overturn_03.png",
325 SETTING_ICON_PATH_CFG"motions/motion_overturn_04.png",
326 SETTING_ICON_PATH_CFG"motions/motion_overturn_05.png",
327 NULL //must end with 'NULL'
330 Evas_Object *setting_create_gif(Evas_Object *parent, const char **png_list)
332 retv_if(!png_list, NULL);
333 setting_gif_data *gif_data = calloc(1,sizeof(setting_gif_data));
334 setting_retvm_if(!gif_data, NULL, "calloc failed");
335 gif_data->cur_png_idx = 0;
336 gif_data->png_list = png_list;
340 Evas_Object *gif = setting_create_image(parent, *png_list);//the first element
342 evas_object_data_set(gif, "gif_data", gif_data);
343 evas_object_event_callback_add(gif, EVAS_CALLBACK_DEL, __gif_del_cb, gif_data);
345 if (gif_data->update_timer) {
346 ecore_timer_del(gif_data->update_timer);
347 gif_data->update_timer = NULL;
349 gif_data->update_timer = ecore_timer_add(DEMO_STEP, (Ecore_Task_Cb)__gif_updater, gif);
355 * Set the vconf value via its binded check object.
356 * @return 0: sucess, other: failed
359 int setting_reset_slp_key_by_status(Evas_Object *obj,
360 setting_bool_slp_list key)
366 status = elm_check_state_get(obj);
369 setting_set_bool_slp_key(key, SETTING_ON_OFF_BTN_ON, &err);
372 setting_set_bool_slp_key(key, SETTING_ON_OFF_BTN_OFF, &err);
378 * Alternate the check object status and its binded vcof value via original vcofn value
380 int setting_draw_onoff_status(Evas_Object *obj, setting_bool_slp_list key)
386 setting_get_bool_slp_key(key, &value, &err);
388 elm_check_state_set(obj, !value);
389 ret = setting_set_bool_slp_key(key, !value, &err);
394 * Set the status of check object via its binded vconf value.
395 * @return 0: sucess, other: failed
397 int setting_check_onoff_status(Evas_Object *obj, setting_bool_slp_list key)
403 ret = setting_get_bool_slp_key(key, &value, &err);
404 elm_check_state_set(obj, value);
409 * Set the status of radio group object via its binded vconf value.
410 * @return 0: sucess, other: failed
412 int setting_update_chk_status(Evas_Object *chk, setting_int_slp_list type)
417 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
422 int ret = SETTING_RETURN_FAIL;
427 ret = setting_get_int_slp_key(type, &value, &err);
428 SETTING_TRACE("binded: %d, checked: %d, err: %d", type, value, err);
430 elm_radio_value_set(chk, value);
436 * Create a size specilized rectangle object
437 * @return a size specilized rectangle object
439 Evas_Object *setting_create_blank_rect_customize(Evas_Object *layout, int w,
444 rect = evas_object_rectangle_add(evas_object_evas_get(layout));
445 evas_object_size_hint_min_set(rect, w, h);
446 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, 0);
447 evas_object_color_set(rect, 0, 0, 0, 0);
453 * Create a size fixed rectangle object
457 * @return a size fixed rectangle object
459 Evas_Object *setting_create_blank_rect(Evas_Object *layout)
461 return setting_create_blank_rect_customize(layout,
462 SETTING_PADDING_WIDTH, 80);
466 * The API to Create an editfiled object
467 * @return an editfiled object
469 Evas_Object * /* multi-line is default, use elm_editfield_entry_single_line_set(ef, EINA_TRUE) to set single-line */
470 setting_create_editfiled(Evas_Object *win_main, char *title, char *def_str)
472 Evas_Object *layout = NULL;
473 Evas_Object *entry = NULL;
474 layout = elm_layout_add(win_main);
478 elm_layout_theme_set(layout, "layout", "editfield", "title");
479 elm_object_part_text_set(layout, "elm.text", title);
483 elm_layout_theme_set(layout, "layout", "editfield", "default");
485 entry = elm_entry_add(win_main);
486 elm_object_part_content_set(layout, "elm.swallow.content", entry);
487 //elm_entry_context_menu_disabled_set(entry, TRUE);
488 //elm_entry_magnifier_disabled_set(entry, TRUE);
489 elm_entry_prediction_allow_set(entry, FALSE);
491 if (def_str && safeStrLen(def_str) > 0) {
492 elm_entry_entry_set(entry, def_str);
494 elm_object_part_text_set(layout, "elm.guidetext", _("IDS_ST_BODY_TAP_TO_INSERT"));
497 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0);
498 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 0);
500 evas_object_show(layout);
505 * Create a text box, which cannot be edited, just to show a specilization segment.
507 * @return a text box, which cannot be edited
509 Evas_Object *setting_create_textbox(Evas_Object *parent, const char *content)
511 Evas_Object *obj = NULL;
513 obj = elm_entry_add(parent);
514 evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, 0.0);
515 evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, 0.5);
516 elm_entry_single_line_set(obj, 0);
517 /* elm_entry_line_wrap_set(obj, 1); */
518 elm_entry_editable_set(obj, 0);
519 elm_entry_context_menu_disabled_set(obj, 1);
521 /* setting_disable_evas_object(obj); ***disable any events on entry */
523 elm_entry_entry_set(obj, content);
524 evas_object_show(obj);
529 * Make it no effect when clicking on a evas object and its sub-objects, such as, layout, genlist
533 void setting_disable_evas_object(Evas_Object *obj)
534 { /* layout\genlist\scroller\elm_entry etc.. */
536 evas_object_pass_events_set(obj, EINA_TRUE);
541 * Make it normal acting when clicking on a evas object, such as, layout, genlist
545 void setting_enable_evas_object(Evas_Object *obj)
548 evas_object_pass_events_set(obj, EINA_FALSE);
553 * To resize a evas object, such as, icon, button..
559 void setting_resize_object(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
562 evas_object_size_hint_min_set(obj, w, h);
563 evas_object_size_hint_max_set(obj, w, h);
564 evas_object_resize(obj, w, h);
569 * To create a bg object
572 * @param[in] bg_style
575 Evas_Object *setting_create_bg(Evas_Object *parent,Evas_Object *win, const char *bg_style)
577 retv_if(!parent, NULL);
578 Evas_Object *bg = elm_bg_add(parent);
580 elm_object_style_set(bg, bg_style);
581 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
583 //elm_win_resize_object_add(win, bg);
584 evas_object_show(bg);
591 * To make an object which is operated by setting_dim_evas_object normal color
594 * @param[in] b_transparency_set:
595 * 1:the appearence of obj is made up of transparent backgroud color.
596 * 0:the appearence of obj is made up of non transparent color.
598 void setting_undo_dim_evas_object(Evas_Object *obj, bool b_transparenct)
605 evas_object_color_get(obj, &r, &g, &b, &a);
606 if (b_transparenct) {//the appearence of obj is made up of transparent backgroud color.
609 evas_object_color_set(obj, r * DIFF_TIMES, g * DIFF_TIMES, b * DIFF_TIMES, a);
614 * To make an object dim color
617 * @param[in] b_transparency_set:
618 * 1:the appearence of obj is made up of transparent backgroud color.
619 * 0:the appearence of obj is made up of non transparent color.
621 void setting_dim_evas_object(Evas_Object *obj, bool b_transparenct)
628 evas_object_color_get(obj, &r, &g, &b, &a);
629 if (b_transparenct) {//the appearence of obj is made up of transparent backgroud color.
632 evas_object_color_set(obj, r / DIFF_TIMES, g / DIFF_TIMES, b / DIFF_TIMES, a);
636 static void __btn_select_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
638 setting_dim_evas_object(obj, FALSE);
641 static void __btn_release_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
643 setting_undo_dim_evas_object(obj, FALSE);
647 * To make an object looks clickable: if pressed, it is dim color;if unpressed, it is normal color;
651 void setting_make_evas_object_clickable(Evas_Object *obj)
654 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN, __btn_select_cb, NULL);
655 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP, __btn_release_cb, NULL);
660 * To create an icon which looks clickable(if pressed, it is dim color;if unpressed, it is normal color)
663 * @param[in] img_path
669 Evas_Object *setting_create_icon(Evas_Object *parent, const char *img_path,
670 Evas_Object_Event_Cb up_cb,
671 Evas_Object_Event_Cb down_cb,
672 Evas_Object_Event_Cb move_cb,
676 retv_if(!parent || !img_path, NULL);
677 Evas_Object *icon = elm_icon_add(parent);
678 retvm_if(!icon, NULL, "Failed Create icon!");
679 elm_icon_file_set(icon, img_path, NULL);
680 setting_make_evas_object_clickable(icon);
683 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_UP,
687 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_DOWN,
691 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_MOVE,
699 * To create a button which only has a image and looks clickable
700 * (if pressed, it is dim color;if unpressed, it is normal color)
702 * @param[in] img_path
708 Evas_Object *setting_create_image_button(Evas_Object *parent,
710 setting_call_back_func clicked_cb,
711 setting_call_back_func unpressed_cb,
715 retv_if(!parent, NULL);
716 Evas_Object *btn = elm_button_add(parent);
717 retvm_if(!btn, NULL, "Failed Create button!");
719 evas_object_smart_callback_add(btn, "clicked", clicked_cb, data);
723 evas_object_smart_callback_add(btn, "unpressed", unpressed_cb, data);
727 Evas_Object *icon = elm_icon_add(parent);
728 retvm_if(!icon, NULL, "Failed Create icon!");
729 elm_icon_file_set(icon, btn_img, NULL);
730 elm_object_part_content_set(btn, "elm.swallow.content", icon);
731 setting_make_evas_object_clickable(btn);
740 * set font_size, color or align(right, left, middle),if need, you
741 * can add </font_siz>, </color> or </align> to controll a segment words; or else
742 * the text will take the same effect until the end of text.
743 * @param[in] input_str
744 * @param[in] font_size
746 * @param[in] align :may be right, left, middle/center
748 char *setting_customize_text(const char *input_str, const int font_size,
749 const char *color, const char *align)
752 retv_if(isEmptyStr(input_str), NULL);
753 SETTING_TRACE("input_str:%s, color:%s", input_str, color);
754 char speciliztion[MAX_SPECIALIZITION_LEN] = { 0, };
755 //<font_size=%d><align=middle><color=#9C9C9C>bbb</color></align></font_size>
758 snprintf(speciliztion, sizeof(speciliztion),
759 "<font_size=%d>", font_size);
764 g_strlcat(speciliztion, "<align=", MAX_SPECIALIZITION_LEN);
765 g_strlcat(speciliztion, align, MAX_SPECIALIZITION_LEN);
766 g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
771 char input_str1[MAX_SPECIALIZITION_LEN] = { 0, };
772 safeCopyStr(input_str1, input_str, MAX_SPECIALIZITION_LEN);
773 char *p = strstr(input_str1, "<color=");
774 if(p) //already has customed color,to replace color sub_string
776 p += strlen("<color=");
777 //memcpy(p, color, strlen(color));
778 char *q = (char *)color;
779 while ('\0' != p[0] && '\0' != q[0])
785 if('>' != p[0]) //invalid format
787 g_strlcat(speciliztion, "<color=", MAX_SPECIALIZITION_LEN);
788 g_strlcat(speciliztion, color, MAX_SPECIALIZITION_LEN);
789 g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
790 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
791 g_strlcat(speciliztion, "</color>", MAX_SPECIALIZITION_LEN);
794 g_strlcat(speciliztion, input_str1, MAX_SPECIALIZITION_LEN);
798 g_strlcat(speciliztion, "<color=", MAX_SPECIALIZITION_LEN);
799 g_strlcat(speciliztion, color, MAX_SPECIALIZITION_LEN);
800 g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
801 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
802 g_strlcat(speciliztion, "</color>", MAX_SPECIALIZITION_LEN);
807 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
811 g_strlcat(speciliztion, "</align>", MAX_SPECIALIZITION_LEN);
815 g_strlcat(speciliztion, "</font_size>", MAX_SPECIALIZITION_LEN);
818 SETTING_TRACE("Exit %s, return :%s", __FUNCTION__, speciliztion);
819 return (char *)strdup(speciliztion);;