4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
21 #include <setting-common-draw-widget.h>
27 * Hide the input pannel
31 void setting_hide_input_pannel_cb(Evas_Object *entry)
33 ret_if(entry == NULL);
34 Ecore_IMF_Context *imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
36 ecore_imf_context_input_panel_hide(imf_context);
39 elm_object_focus_set(entry, EINA_FALSE);
40 Evas_Object *entry_container = elm_object_parent_widget_get(entry);
43 if (elm_entry_is_empty(entry))
44 elm_object_signal_emit(entry_container, "elm,state,guidetext,show", "elm");
45 elm_object_signal_emit(entry_container, "elm,state,eraser,hide", "elm");
49 Evas_Object *setting_create_button(Evas_Object *parent, const char *btn_str,
50 const char *btn_style,
51 setting_call_back_func btn_click_cb,
54 retv_if(!parent || !btn_str, NULL);
55 if ('\0' == btn_str[0]) {//Empty rectangle
56 return setting_create_blank_rect_customize(parent,
57 SETTING_PADDING_WIDTH,
58 SETTING_PADDING_WIDTH);
61 Evas_Object *button = elm_button_add(parent);
63 elm_object_style_set(button, btn_style);
66 if (0 != safeStrCmp(NAVI_BACK_BUTTON_STYLE, btn_style)) {//not '<-' button
67 elm_object_text_set(button, btn_str);
69 evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
70 evas_object_size_hint_align_set(button,EVAS_HINT_FILL, 0.5);
74 evas_object_smart_callback_add(button, "clicked",
75 btn_click_cb, cb_data);
77 evas_object_show(button);
83 * To create slider object of a genlist item
85 *@return a slider container object
87 Evas_Object *setting_create_slider(Evas_Object *parent, Evas *evas,
88 const char *l_swallow_path,
89 const char *r_swallow_path, double value,
90 bool indicator, double slider_min, double slider_max,
91 setting_call_back_func slider_change_cb,
92 setting_call_back_func slider_start_change_cb,
93 setting_call_back_func slider_stop_change_cb,
96 Evas_Object *slider = elm_slider_add(parent); /* "elm/slider/horizontal/default" */
97 retv_if(slider == NULL, NULL);
101 elm_slider_indicator_format_set(slider, "%1.0f");
105 /* for brightness slider */
106 elm_slider_indicator_show_set(slider, EINA_FALSE);
108 elm_object_style_set(slider, "ebook");
112 evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0);
113 evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5);
115 if (slider_change_cb)
116 evas_object_smart_callback_add(slider, "changed", slider_change_cb, cb_data);
118 if (slider_stop_change_cb)
119 evas_object_smart_callback_add(slider, "slider,drag,stop", slider_stop_change_cb, cb_data);
121 if(slider_start_change_cb)
122 evas_object_smart_callback_add(slider, "slider,drag,start", slider_start_change_cb, cb_data);
124 Evas_Object *icon1 = elm_icon_add(slider);
125 elm_icon_file_set(icon1, l_swallow_path, NULL);
126 evas_object_size_hint_aspect_set(icon1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
128 Evas_Object *icon2 = elm_icon_add(slider);
129 elm_icon_file_set(icon2, r_swallow_path, NULL);
130 evas_object_size_hint_aspect_set(icon2, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
132 elm_object_content_set(slider, icon1);
133 elm_object_part_content_set(slider, "end", icon2);
135 elm_slider_min_max_set(slider, slider_min, slider_max);
136 elm_slider_value_set(slider, value);
141 * The main implement body of create a certain size icon
143 void create_image_box_add_ex(void *data, Evas_Object *win_main, Evas *evas,
144 char *img_path, int img_w, int img_h,
145 Evas_Object_Event_Cb mouse_down_cb,
146 Evas_Object_Event_Cb mouse_up_cb,
147 Evas_Object **image_box, Evas_Object **img)
149 /* SETTING_TRACE_BEGIN; */
150 *image_box = elm_box_add(win_main);
151 retm_if(*image_box == NULL, "Cannot get box");
152 elm_box_horizontal_set(*image_box, 1);
153 evas_object_size_hint_align_set(*image_box, 0.0, EVAS_HINT_FILL); /* */
154 evas_object_show(*image_box);
156 *img = evas_object_image_add(evas);
157 evas_object_size_hint_weight_set(*img, 0.0, EVAS_HINT_EXPAND);
162 evas_object_image_file_set(*img, img_path, NULL);
163 if (img_h <= 0 || temp_w <= 0) //error handling. load the image as it's own size
165 evas_object_image_size_get(*img, &temp_w, &temp_h);
168 evas_object_image_load_size_set(*img, temp_w, temp_h);
169 evas_object_image_fill_set(*img, 0, 0, temp_w, temp_h);
171 evas_object_size_hint_min_set(*img, temp_w, temp_h);
172 evas_object_show(*img);
174 evas_object_event_callback_add(*img, EVAS_CALLBACK_MOUSE_DOWN,
175 mouse_down_cb, data);
176 evas_object_event_callback_add(*img, EVAS_CALLBACK_MOUSE_UP,
179 elm_box_pack_end(*image_box, *img);
183 * To create a size fixed icon
184 * @return a image container object
187 Evas_Object *create_image_box_add(void *data, Evas_Object *win_main,
188 Evas *evas, char *img_path, int img_w,
189 int img_h, Evas_Object_Event_Cb mouse_down_cb,
190 Evas_Object_Event_Cb mouse_up_cb)
192 /* SETTING_TRACE_BEGIN; */
193 Evas_Object *image_box = NULL;
194 Evas_Object *img = NULL;
195 create_image_box_add_ex(data, win_main, evas, img_path,
196 img_w * WIDGET_SCALE_FACTOR,
197 img_h * WIDGET_SCALE_FACTOR, mouse_down_cb,
198 mouse_up_cb, &image_box, &img);
204 * To create a size specialized icon
206 * @return a image container object
209 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 */
210 Evas_Object_Event_Cb mouse_down_cb,
211 Evas_Object_Event_Cb mouse_up_cb)
213 Evas_Object *image_box = NULL;
214 Evas_Object *img = NULL;
215 create_image_box_add_ex(data, win_main, evas, img_path, img_w, img_h,
216 mouse_down_cb, mouse_up_cb, &image_box, &img);
221 * @ create a box container
223 * @param[in] win_main
225 * @return a box container
227 Evas_Object *setting_create_client_bx(Evas_Object *win_main)
229 Evas_Object *client_bx = NULL;
231 client_bx = elm_box_add(win_main);
232 retvm_if(client_bx == NULL, NULL, "Cannot create client box object");
234 elm_box_horizontal_set(client_bx, 0);
235 evas_object_size_hint_weight_set(client_bx, EVAS_HINT_EXPAND, 0.0);
236 evas_object_size_hint_align_set(client_bx, EVAS_HINT_FILL, 0.0);
242 Evas_Object *setting_create_lable(Evas_Object *parent, const char *text,
243 const char *style, const char *align)
245 retvm_if(!parent || !text, NULL, "Cannot create client box object");
246 Evas_Object *label = NULL;
247 if (0 == safeStrCmp(style, "entry"))
249 SETTING_TRACE("style:%s", style);
250 label = elm_entry_add(parent);
251 elm_entry_editable_set(label, EINA_FALSE);
255 label = elm_label_add(parent);
256 elm_object_style_set(label, style);
257 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
259 const char *str = setting_customize_text(text, 0, NULL, align);
260 elm_object_text_set(label, str);
262 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
263 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
264 evas_object_show(label);
268 #define DEMO_STEP 0.4
269 typedef struct _setting_gif_data{
270 Ecore_Timer *update_timer;
271 const char **png_list;
275 static void __gif_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
279 setting_gif_data *gif_data = data;
280 if (gif_data->update_timer) {//first delete the timer
281 ecore_timer_del(gif_data->update_timer);
282 gif_data->update_timer = NULL;
284 FREE(gif_data);//delete the date.
285 evas_object_data_set(obj, "gif_data", NULL);
288 Eina_Bool __gif_updater(void *data)
290 retv_if(!data, FALSE);
291 Evas_Object *gif = data;
292 setting_gif_data *gif_data = evas_object_data_get(gif, "gif_data");
293 retv_if(!gif_data, FALSE);
296 gif_data->cur_png_idx++;
297 if (NULL == gif_data->png_list[gif_data->cur_png_idx]) { //the last element of current array.
298 gif_data->cur_png_idx = 0;
300 elm_image_file_set(gif, gif_data->png_list[gif_data->cur_png_idx], NULL);
303 elm_image_object_size_get(gif, &w, &h);
304 setting_resize_object(gif, w, h);
309 Evas_Object *setting_create_image(Evas_Object *parent, const char *img_path)
311 Evas_Object *image = elm_image_add(parent);
312 //SETTING_TRACE("icon_path:%s", icon_path);
313 elm_image_file_set(image, img_path, NULL);
314 elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
318 elm_image_object_size_get(image, &w, &h);
319 setting_resize_object(image, w, h);
320 evas_object_show(image);
324 /* @png_list is an array end with 'NULL'. like ,
325 const char *png_list[] = {
326 SETTING_ICON_PATH_CFG"motions/motion_overturn_01.png",
327 SETTING_ICON_PATH_CFG"motions/motion_overturn_02.png",
328 SETTING_ICON_PATH_CFG"motions/motion_overturn_03.png",
329 SETTING_ICON_PATH_CFG"motions/motion_overturn_04.png",
330 SETTING_ICON_PATH_CFG"motions/motion_overturn_05.png",
331 NULL //must end with 'NULL'
334 Evas_Object *setting_create_gif(Evas_Object *parent, const char **png_list)
336 retv_if(!png_list, NULL);
337 setting_gif_data *gif_data = calloc(1,sizeof(setting_gif_data));
338 setting_retvm_if(!gif_data, NULL, "calloc failed");
339 gif_data->cur_png_idx = 0;
340 gif_data->png_list = png_list;
344 Evas_Object *gif = setting_create_image(parent, *png_list);//the first element
346 evas_object_data_set(gif, "gif_data", gif_data);
347 evas_object_event_callback_add(gif, EVAS_CALLBACK_DEL, __gif_del_cb, gif_data);
349 if (gif_data->update_timer) {
350 ecore_timer_del(gif_data->update_timer);
351 gif_data->update_timer = NULL;
353 gif_data->update_timer = ecore_timer_add(DEMO_STEP, (Ecore_Task_Cb)__gif_updater, gif);
359 * Set the vconf value via its binded check object.
360 * @return 0: sucess, other: failed
363 int setting_reset_slp_key_by_status(Evas_Object *obj,
364 setting_bool_slp_list key)
370 status = elm_check_state_get(obj);
373 setting_set_bool_slp_key(key, SETTING_ON_OFF_BTN_ON, &err);
376 setting_set_bool_slp_key(key, SETTING_ON_OFF_BTN_OFF, &err);
382 * Alternate the check object status and its binded vcof value via original vcofn value
384 int setting_draw_onoff_status(Evas_Object *obj, setting_bool_slp_list key)
390 setting_get_bool_slp_key(key, &value, &err);
392 elm_check_state_set(obj, !value);
393 ret = setting_set_bool_slp_key(key, !value, &err);
398 * Set the status of check object via its binded vconf value.
399 * @return 0: sucess, other: failed
401 int setting_check_onoff_status(Evas_Object *obj, setting_bool_slp_list key)
407 ret = setting_get_bool_slp_key(key, &value, &err);
408 elm_check_state_set(obj, value);
413 * Set the status of radio group object via its binded vconf value.
414 * @return 0: sucess, other: failed
416 int setting_update_chk_status(Evas_Object *chk, setting_int_slp_list type)
421 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
426 int ret = SETTING_RETURN_FAIL;
431 ret = setting_get_int_slp_key(type, &value, &err);
432 SETTING_TRACE("binded: %d, checked: %d, err: %d", type, value, err);
434 elm_radio_value_set(chk, value);
440 * Create a size specilized rectangle object
441 * @return a size specilized rectangle object
443 Evas_Object *setting_create_blank_rect_customize(Evas_Object *layout, int w,
448 rect = evas_object_rectangle_add(evas_object_evas_get(layout));
449 evas_object_size_hint_min_set(rect, w, h);
450 evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, 0);
451 evas_object_color_set(rect, 0, 0, 0, 0);
457 * Create a size fixed rectangle object
461 * @return a size fixed rectangle object
463 Evas_Object *setting_create_blank_rect(Evas_Object *layout)
465 return setting_create_blank_rect_customize(layout,
466 SETTING_PADDING_WIDTH, 80);
470 * The API to Create an editfiled object
471 * @return an editfiled object
473 Evas_Object * /* multi-line is default, use elm_editfield_entry_single_line_set(ef, EINA_TRUE) to set single-line */
474 setting_create_editfiled(Evas_Object *win_main, char *title, char *def_str)
476 Evas_Object *layout = NULL;
477 Evas_Object *entry = NULL;
478 layout = elm_layout_add(win_main);
482 elm_layout_theme_set(layout, "layout", "editfield", "title");
483 elm_object_part_text_set(layout, "elm.text", title);
487 elm_layout_theme_set(layout, "layout", "editfield", "default");
489 entry = elm_entry_add(win_main);
490 elm_object_part_content_set(layout, "elm.swallow.content", entry);
491 //elm_entry_context_menu_disabled_set(entry, TRUE);
492 //elm_entry_magnifier_disabled_set(entry, TRUE);
493 elm_entry_prediction_allow_set(entry, FALSE);
495 if (def_str && safeStrLen(def_str) > 0) {
496 elm_entry_entry_set(entry, def_str);
498 elm_object_part_text_set(layout, "elm.guidetext", _("IDS_ST_BODY_TAP_TO_INSERT"));
501 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0);
502 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 0);
504 evas_object_show(layout);
509 * Create a text box, which cannot be edited, just to show a specilization segment.
511 * @return a text box, which cannot be edited
513 Evas_Object *setting_create_textbox(Evas_Object *parent, const char *content)
515 Evas_Object *obj = NULL;
517 obj = elm_entry_add(parent);
518 evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, 0.0);
519 evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, 0.5);
520 elm_entry_single_line_set(obj, 0);
521 /* elm_entry_line_wrap_set(obj, 1); */
522 elm_entry_editable_set(obj, 0);
523 elm_entry_context_menu_disabled_set(obj, 1);
525 /* setting_disable_evas_object(obj); ***disable any events on entry */
527 elm_entry_entry_set(obj, content);
528 evas_object_show(obj);
533 * Make it no effect when clicking on a evas object and its sub-objects, such as, layout, genlist
537 void setting_disable_evas_object(Evas_Object *obj)
538 { /* layout\genlist\scroller\elm_entry etc.. */
540 evas_object_pass_events_set(obj, EINA_TRUE);
545 * Make it normal acting when clicking on a evas object, such as, layout, genlist
549 void setting_enable_evas_object(Evas_Object *obj)
552 evas_object_pass_events_set(obj, EINA_FALSE);
557 * To resize a evas object, such as, icon, button..
563 void setting_resize_object(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
566 evas_object_size_hint_min_set(obj, w, h);
567 evas_object_size_hint_max_set(obj, w, h);
568 evas_object_resize(obj, w, h);
573 * To create a bg object
576 * @param[in] bg_style
579 Evas_Object *setting_create_bg(Evas_Object *parent,Evas_Object *win, const char *bg_style)
581 retv_if(!parent, NULL);
582 Evas_Object *bg = elm_bg_add(parent);
584 elm_object_style_set(bg, bg_style);
585 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
587 //elm_win_resize_object_add(win, bg);
588 evas_object_show(bg);
595 * To make an object which is operated by setting_dim_evas_object normal color
598 * @param[in] b_transparency_set:
599 * 1:the appearence of obj is made up of transparent backgroud color.
600 * 0:the appearence of obj is made up of non transparent color.
602 void setting_undo_dim_evas_object(Evas_Object *obj, bool b_transparenct)
609 evas_object_color_get(obj, &r, &g, &b, &a);
610 if (b_transparenct) {//the appearence of obj is made up of transparent backgroud color.
613 evas_object_color_set(obj, r * DIFF_TIMES, g * DIFF_TIMES, b * DIFF_TIMES, a);
618 * To make an object dim color
621 * @param[in] b_transparency_set:
622 * 1:the appearence of obj is made up of transparent backgroud color.
623 * 0:the appearence of obj is made up of non transparent color.
625 void setting_dim_evas_object(Evas_Object *obj, bool b_transparenct)
632 evas_object_color_get(obj, &r, &g, &b, &a);
633 if (b_transparenct) {//the appearence of obj is made up of transparent backgroud color.
636 evas_object_color_set(obj, r / DIFF_TIMES, g / DIFF_TIMES, b / DIFF_TIMES, a);
640 static void __btn_select_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
642 setting_dim_evas_object(obj, FALSE);
645 static void __btn_release_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
647 setting_undo_dim_evas_object(obj, FALSE);
651 * To make an object looks clickable: if pressed, it is dim color;if unpressed, it is normal color;
655 void setting_make_evas_object_clickable(Evas_Object *obj)
658 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN, __btn_select_cb, NULL);
659 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP, __btn_release_cb, NULL);
664 * To create an icon which looks clickable(if pressed, it is dim color;if unpressed, it is normal color)
667 * @param[in] img_path
673 Evas_Object *setting_create_icon(Evas_Object *parent, const char *img_path,
674 Evas_Object_Event_Cb up_cb,
675 Evas_Object_Event_Cb down_cb,
676 Evas_Object_Event_Cb move_cb,
680 retv_if(!parent || !img_path, NULL);
681 Evas_Object *icon = elm_icon_add(parent);
682 retvm_if(!icon, NULL, "Failed Create icon!");
683 elm_icon_file_set(icon, img_path, NULL);
684 setting_make_evas_object_clickable(icon);
687 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_UP,
691 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_DOWN,
695 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_MOVE,
703 * To create a button which only has a image and looks clickable
704 * (if pressed, it is dim color;if unpressed, it is normal color)
706 * @param[in] img_path
712 Evas_Object *setting_create_image_button(Evas_Object *parent,
714 setting_call_back_func clicked_cb,
715 setting_call_back_func unpressed_cb,
719 retv_if(!parent, NULL);
720 Evas_Object *btn = elm_button_add(parent);
721 retvm_if(!btn, NULL, "Failed Create button!");
723 evas_object_smart_callback_add(btn, "clicked", clicked_cb, data);
727 evas_object_smart_callback_add(btn, "unpressed", unpressed_cb, data);
731 Evas_Object *icon = elm_icon_add(parent);
732 retvm_if(!icon, NULL, "Failed Create icon!");
733 elm_icon_file_set(icon, btn_img, NULL);
734 elm_object_part_content_set(btn, "elm.swallow.content", icon);
735 setting_make_evas_object_clickable(btn);
744 * set font_size, color or align(right, left, middle),if need, you
745 * can add </font_siz>, </color> or </align> to controll a segment words; or else
746 * the text will take the same effect until the end of text.
747 * @param[in] input_str
748 * @param[in] font_size
750 * @param[in] align :may be right, left, middle/center
752 char *setting_customize_text(const char *input_str, const int font_size,
753 const char *color, const char *align)
756 retv_if(isEmptyStr(input_str), NULL);
757 SETTING_TRACE("input_str:%s, color:%s", input_str, color);
758 char speciliztion[MAX_SPECIALIZITION_LEN] = { 0, };
759 //<font_size=%d><align=middle><color=#9C9C9C>bbb</color></align></font_size>
762 snprintf(speciliztion, sizeof(speciliztion),
763 "<font_size=%d>", font_size);
768 g_strlcat(speciliztion, "<align=", MAX_SPECIALIZITION_LEN);
769 g_strlcat(speciliztion, align, MAX_SPECIALIZITION_LEN);
770 g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
775 char input_str1[MAX_SPECIALIZITION_LEN] = { 0, };
776 safeCopyStr(input_str1, input_str, MAX_SPECIALIZITION_LEN);
777 char *p = strstr(input_str1, "<color=");
778 if(p) //already has customed color,to replace color sub_string
780 p += strlen("<color=");
781 //memcpy(p, color, strlen(color));
782 char *q = (char *)color;
783 while ('\0' != p[0] && '\0' != q[0])
789 if('>' != p[0]) //invalid format
791 g_strlcat(speciliztion, "<color=", MAX_SPECIALIZITION_LEN);
792 g_strlcat(speciliztion, color, MAX_SPECIALIZITION_LEN);
793 g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
794 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
795 g_strlcat(speciliztion, "</color>", MAX_SPECIALIZITION_LEN);
798 g_strlcat(speciliztion, input_str1, MAX_SPECIALIZITION_LEN);
802 g_strlcat(speciliztion, "<color=", MAX_SPECIALIZITION_LEN);
803 g_strlcat(speciliztion, color, MAX_SPECIALIZITION_LEN);
804 g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
805 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
806 g_strlcat(speciliztion, "</color>", MAX_SPECIALIZITION_LEN);
811 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
815 g_strlcat(speciliztion, "</align>", MAX_SPECIALIZITION_LEN);
819 g_strlcat(speciliztion, "</font_size>", MAX_SPECIALIZITION_LEN);
822 SETTING_TRACE("Exit %s, return :%s", __FUNCTION__, speciliztion);
823 return (char *)strdup(speciliztion);;