fixed N_SE-47240
[apps/home/settings.git] / setting-common / src / setting-common-draw-widget.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
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
8  *
9  *     http://floralicense.org/license/
10  *
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.
16  */
17 #include <setting-common-draw-widget.h>
18 #include <glib.h>
19 #include <utilX.h>
20 #include <Ecore_X.h>
21
22 #include <efl_assist.h>
23
24 /**
25  * Hide the input pannel
26  *
27  * @param[in] entry
28  */
29 void setting_hide_input_pannel_cb(Evas_Object *entry)
30 {
31         ret_if(entry == NULL);
32         Ecore_IMF_Context *imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
33         if (imf_context) {
34                 ecore_imf_context_input_panel_hide(imf_context);
35         }
36
37         elm_object_focus_set(entry, EINA_FALSE);
38         Evas_Object *entry_container = elm_object_parent_widget_get(entry);
39         if (entry_container)
40         {
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");
44         }
45 }
46
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,
50                                    void *cb_data)
51 {
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);
57         }
58
59         Evas_Object *button = elm_button_add(parent);
60         if (btn_style) {
61                 elm_object_style_set(button, btn_style);
62         }
63
64         if (0 != safeStrCmp(NAVI_BACK_BUTTON_STYLE, btn_style)) {//not '<-' button
65                 elm_object_text_set(button, btn_str);
66
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);
69         }
70
71         if (btn_click_cb) {
72                 evas_object_smart_callback_add(button, "clicked",
73                                                btn_click_cb, cb_data);
74         }
75         evas_object_show(button);
76         return button;
77 }
78
79
80 /**
81  * To create slider object of a genlist item
82  *
83  *@return a slider container object
84  */
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,
92                                    void *cb_data)
93 {
94         Evas_Object *slider = elm_slider_add(parent);   /*  "elm/slider/horizontal/default" */
95         retv_if(slider == NULL, NULL);
96
97         if(indicator)
98         {
99                 elm_slider_indicator_format_set(slider, "%1.0f");
100         }
101         else
102         {
103                 /* for brightness slider */
104                 elm_slider_indicator_show_set(slider, EINA_FALSE);
105 #if DISABLED_CODE
106                 elm_object_style_set(slider, "ebook");
107 #endif
108         }
109
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);
112
113         if (slider_change_cb)
114                 evas_object_smart_callback_add(slider, "changed", slider_change_cb, cb_data);
115
116         if (slider_stop_change_cb)
117                 evas_object_smart_callback_add(slider, "slider,drag,stop", slider_stop_change_cb, cb_data);
118
119         if(slider_start_change_cb)
120                 evas_object_smart_callback_add(slider, "slider,drag,start", slider_start_change_cb, cb_data);
121
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);
125
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);
129
130         elm_object_content_set(slider, icon1);
131         elm_object_part_content_set(slider, "end", icon2);
132
133         elm_slider_min_max_set(slider, slider_min, slider_max);
134         elm_slider_value_set(slider, value);
135         return slider;
136 }
137
138 /**
139  * The main implement body of create a certain size icon
140  */
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)
146 {
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);
153
154         *img = evas_object_image_add(evas);
155         evas_object_size_hint_weight_set(*img, 0.0, EVAS_HINT_EXPAND);
156
157         int temp_h = img_h;
158         int temp_w = img_w;
159
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
162         {
163                 evas_object_image_size_get(*img, &temp_w, &temp_h);
164         }
165
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);
168
169         evas_object_size_hint_min_set(*img, temp_w, temp_h);
170         evas_object_show(*img);
171
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,
175                                        mouse_up_cb, data);
176
177         elm_box_pack_end(*image_box, *img);
178 }
179
180 /**
181  * To create a size fixed icon
182  * @return a image container object
183  */
184
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)
189 {
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);
197         return image_box;
198
199 }
200
201 /**
202 * To create a size specialized icon
203 *
204 * @return a image container object
205 */
206
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)
210 {
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);
215         return image_box;
216 }
217
218 /**
219 * @ create a box container
220 *
221 * @param[in] win_main
222 *
223 * @return a box container
224 */
225 Evas_Object *setting_create_client_bx(Evas_Object *win_main)
226 {
227         Evas_Object *client_bx = NULL;
228
229         client_bx = elm_box_add(win_main);
230         retvm_if(client_bx == NULL, NULL, "Cannot create client box object");
231
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);
235
236         return client_bx;
237 }
238
239
240 Evas_Object *setting_create_lable(Evas_Object *parent, const char *text,
241                                   const char *style, const char *align)
242 {
243         retvm_if(!parent || !text, NULL, "Cannot create client box object");
244         Evas_Object *label = NULL;
245         if (0 == safeStrCmp(style, "entry"))
246         {
247                 SETTING_TRACE("style:%s", style);
248                 label = elm_entry_add(parent);
249                 elm_entry_editable_set(label, EINA_FALSE);
250         }
251         else
252         {
253                 label = elm_label_add(parent);
254                 elm_object_style_set(label, style);
255                 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
256         }
257         const char *str = setting_customize_text(text, 0, NULL, align);
258         elm_object_text_set(label, str);
259         FREE(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);
263         return label;
264 }
265
266 #define DEMO_STEP 0.4
267 typedef struct _setting_gif_data{
268         Ecore_Timer *update_timer;
269         const char  **png_list;
270         int         cur_png_idx;
271 }setting_gif_data;
272
273 static void __gif_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
274 {
275         SETTING_TRACE_BEGIN;
276         ret_if(!data);
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;
281         }
282         FREE(gif_data);//delete the date.
283         evas_object_data_set(obj, "gif_data", NULL);
284 }
285
286 Eina_Bool __gif_updater(void *data)
287 {
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);
292         SETTING_TRACE_BEGIN;
293
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;
297         }
298         elm_image_file_set(gif, gif_data->png_list[gif_data->cur_png_idx], NULL);
299         int w = 0;
300         int h = 0;
301         elm_image_object_size_get(gif, &w, &h);
302         setting_resize_object(gif, w, h);
303
304         return TRUE;
305 }
306
307 Evas_Object *setting_create_image(Evas_Object *parent, const char *img_path)
308 {
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);
313
314         int w = 0;
315         int h = 0;
316         elm_image_object_size_get(image, &w, &h);
317         setting_resize_object(image, w, h);
318         evas_object_show(image);
319         return image;
320 }
321
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'
330                 };
331 */
332 Evas_Object *setting_create_gif(Evas_Object *parent, const char **png_list)
333 {
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;
339
340         SETTING_TRACE_BEGIN;
341
342         Evas_Object *gif = setting_create_image(parent, *png_list);//the first element
343         //bind object data
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);
346
347         if (gif_data->update_timer) {
348                 ecore_timer_del(gif_data->update_timer);
349                 gif_data->update_timer = NULL;
350         }
351         gif_data->update_timer = ecore_timer_add(DEMO_STEP, (Ecore_Task_Cb)__gif_updater, gif);
352
353         return gif;
354 }
355
356 /**
357 * Set the vconf value via its binded check object.
358 * @return 0: sucess, other: failed
359 */
360
361 int setting_reset_slp_key_by_status(Evas_Object *obj,
362                                     setting_bool_slp_list key)
363 {
364         SETTING_TRACE_BEGIN;
365         int err, ret;
366
367         int status = 0;
368         status = elm_check_state_get(obj);
369         if (status) {
370                 ret =
371                     setting_set_bool_slp_key(key, SETTING_ON_OFF_BTN_ON, &err);
372         } else {
373                 ret =
374                     setting_set_bool_slp_key(key, SETTING_ON_OFF_BTN_OFF, &err);
375         }
376         return ret;
377 }
378
379 /**
380 * Alternate the check object status and its binded vcof value via original vcofn value
381 */
382 int setting_draw_onoff_status(Evas_Object *obj, setting_bool_slp_list key)
383 {
384         int value;
385         int err;
386         int ret;
387
388         setting_get_bool_slp_key(key, &value, &err);
389
390         elm_check_state_set(obj, !value);
391         ret = setting_set_bool_slp_key(key, !value, &err);
392         return ret;
393 }
394
395 /**
396 * Set the status of check object via its binded vconf value.
397 * @return  0: sucess, other: failed
398 */
399 int setting_check_onoff_status(Evas_Object *obj, setting_bool_slp_list key)
400 {
401         int value = 0;
402         int err = 0;
403         int ret = 0;
404
405         ret = setting_get_bool_slp_key(key, &value, &err);
406         elm_check_state_set(obj, value);
407         return ret;
408 }
409
410 /**
411 * Set the status of radio group object via its binded vconf value.
412 * @return  0: sucess, other: failed
413 */
414 int setting_update_chk_status(Evas_Object *chk, setting_int_slp_list type)
415 {
416         SETTING_TRACE_BEGIN;
417         /* error check */
418         if (chk == NULL) {
419                 return SETTING_GENERAL_ERR_NULL_DATA_PARAMETER;
420         }
421
422         SETTING_TRACE_BEGIN;
423
424         int ret = SETTING_RETURN_FAIL;
425         int value;
426         int err;
427
428         /* value set */
429         ret = setting_get_int_slp_key(type, &value, &err);
430         SETTING_TRACE("binded: %d, checked: %d, err: %d", type, value, err);
431
432         elm_radio_value_set(chk, value);
433
434         return ret;
435 }
436
437 /**
438 * Create a size specilized rectangle object
439 * @return a size specilized rectangle object
440 */
441 Evas_Object *setting_create_blank_rect_customize(Evas_Object *layout, int w,
442                                                  int h)
443 {
444         Evas_Object *rect;
445
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);
450
451         return rect;
452 }
453
454 /**
455 * Create a size fixed rectangle object
456 *
457 * @param[in] layout
458 *
459 * @return a size fixed rectangle object
460 */
461 Evas_Object *setting_create_blank_rect(Evas_Object *layout)
462 {
463         return setting_create_blank_rect_customize(layout,
464                                                    SETTING_PADDING_WIDTH, 80);
465 }
466
467 /**
468 * The API to Create an editfiled object
469 * @return an editfiled object
470 */
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)
473 {
474         Evas_Object *layout = NULL;
475         Evas_Object *entry = NULL;
476         layout = elm_layout_add(win_main);
477
478         if(title)
479         {
480                 elm_layout_theme_set(layout, "layout", "editfield", "title");
481                 elm_object_part_text_set(layout, "elm.text", title);
482         }
483         else
484         {
485                 elm_layout_theme_set(layout, "layout", "editfield", "default");
486         }
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);
492
493         if (def_str && safeStrLen(def_str) > 0) {
494                 elm_entry_entry_set(entry, def_str);
495         } else {
496                 elm_object_part_text_set(layout, "elm.guidetext", _("IDS_ST_BODY_TAP_TO_INSERT"));
497         }
498
499         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0);
500         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 0);
501
502         evas_object_show(layout);
503         return layout;
504 }
505
506 /**
507 * Create a text box, which cannot be edited, just to show a specilization segment.
508 *
509 * @return a text box, which cannot be edited
510 */
511 Evas_Object *setting_create_textbox(Evas_Object *parent, const char *content)
512 {
513         Evas_Object *obj = NULL;
514
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);
522
523         /* setting_disable_evas_object(obj); ***disable any events on entry */
524
525         elm_entry_entry_set(obj, content);
526         evas_object_show(obj);
527         return obj;
528 }
529
530 /**
531 * Make it no effect when clicking on a evas object and its sub-objects, such as, layout, genlist
532 *
533 * @param[in] obj
534 */
535 void setting_disable_evas_object(Evas_Object *obj)
536 {                               /* layout\genlist\scroller\elm_entry  etc.. */
537         if (obj) {
538                 evas_object_pass_events_set(obj, EINA_TRUE);
539         }
540 }
541
542 /**
543 * Make it normal acting when clicking on a evas object, such as, layout, genlist
544 *
545 * @param[in] obj
546 */
547 void setting_enable_evas_object(Evas_Object *obj)
548 {
549         if (obj) {
550                 evas_object_pass_events_set(obj, EINA_FALSE);
551         }
552 }
553
554 /**
555 * To resize a evas object, such as, icon, button..
556 *
557 * @param[in] obj
558 * @param[in] w
559 * @param[in] h
560 */
561 void setting_resize_object(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
562 {
563         if (obj) {
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);
567         }
568 }
569
570 /**
571 * To create a bg object
572 *
573 * @param[in] parent
574 * @param[in] bg_style
575 * @return bg object
576 */
577 Evas_Object *setting_create_bg(Evas_Object *parent,Evas_Object *win, const char *bg_style)
578 {
579         retv_if(!parent, NULL);
580         Evas_Object *bg = elm_bg_add(parent);
581         retv_if(!bg, NULL);
582         elm_object_style_set(bg, bg_style);
583         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
584                                          EVAS_HINT_EXPAND);
585         //elm_win_resize_object_add(win, bg);
586         evas_object_show(bg);
587         return bg;
588 }
589
590
591 #define DIFF_TIMES      2
592 /**
593 * To make an object which is operated by setting_dim_evas_object normal color
594 *
595 * @param[in] obj
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.
599 */
600 void setting_undo_dim_evas_object(Evas_Object *obj, bool b_transparenct)
601 {
602         if (obj) {
603                 int r;
604                 int g;
605                 int b;
606                 int a;
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.
609                         a *= DIFF_TIMES;
610                 }
611                 evas_object_color_set(obj, r * DIFF_TIMES, g * DIFF_TIMES, b * DIFF_TIMES, a);
612         }
613 }
614
615 /**
616 * To make an object dim color
617 *
618 * @param[in] obj
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.
622 */
623 void setting_dim_evas_object(Evas_Object *obj, bool b_transparenct)
624 {
625         if (obj) {
626                 int r;
627                 int g;
628                 int b;
629                 int a;
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.
632                         a /= DIFF_TIMES;
633                 }
634                 evas_object_color_set(obj, r / DIFF_TIMES, g / DIFF_TIMES, b / DIFF_TIMES, a);
635         }
636 }
637
638 static void __btn_select_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
639 {
640         setting_dim_evas_object(obj, FALSE);
641 }
642
643 static void __btn_release_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
644 {
645         setting_undo_dim_evas_object(obj, FALSE);
646 }
647
648 /**
649 * To make an object looks clickable: if pressed, it is dim color;if unpressed, it is normal color;
650 *
651 * @param[in] obj
652 */
653 void setting_make_evas_object_clickable(Evas_Object *obj)
654 {
655         if (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);
658         }
659 }
660
661 /**
662 * To create an icon which looks clickable(if pressed, it is dim color;if unpressed, it is normal color)
663 *
664 * @param[in] parent
665 * @param[in] img_path
666 * @param[in] up_cb
667 * @param[in] down_cb
668 * @param[in] move_cb
669 * @param[in] data
670 */
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,
675                                  void *data)
676 {
677         SETTING_TRACE_BEGIN;
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);
683
684         if (up_cb) {
685                 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_UP,
686                                                 up_cb, data);
687         }
688         if (down_cb) {
689                 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_DOWN,
690                                                 down_cb, data);
691         }
692         if (move_cb) {
693                 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_MOVE,
694                                                 move_cb, data);
695         }
696
697         return icon;
698 }
699
700 /**
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)
703 * @param[in] parent
704 * @param[in] img_path
705 * @param[in] up_cb
706 * @param[in] down_cb
707 * @param[in] move_cb
708 * @param[in] data
709 */
710 Evas_Object *setting_create_image_button(Evas_Object *parent,
711                                         const char *btn_img,
712                                         setting_call_back_func clicked_cb,
713                                         setting_call_back_func unpressed_cb,
714                                         void *data)
715 {
716         SETTING_TRACE_BEGIN;
717         retv_if(!parent, NULL);
718         Evas_Object *btn = elm_button_add(parent);
719         retvm_if(!btn, NULL, "Failed Create button!");
720         if (clicked_cb) {
721                 evas_object_smart_callback_add(btn, "clicked", clicked_cb, data);
722         }
723
724         if (unpressed_cb) {
725                 evas_object_smart_callback_add(btn, "unpressed", unpressed_cb, data);
726         }
727
728         if (btn_img) {
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);
734         }
735
736         return btn;
737 }
738
739
740
741 /*
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
747 * @param[in] color
748 * @param[in] align :may be right, left, middle/center
749 */
750 char *setting_customize_text(const char *input_str, const int font_size,
751                                  const char *color, const char *align)
752 {
753         SETTING_TRACE_BEGIN;
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>
758         if (font_size > 0)
759         {
760                 snprintf(speciliztion, sizeof(speciliztion),
761                          "<font_size=%d>", font_size);
762         }
763
764         if (align)
765         {
766             g_strlcat(speciliztion, "<align=", MAX_SPECIALIZITION_LEN);
767             g_strlcat(speciliztion, align, MAX_SPECIALIZITION_LEN);
768             g_strlcat(speciliztion, ">", MAX_SPECIALIZITION_LEN);
769         }
770
771         if(color)
772         {
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
777                 {
778                         p += strlen("<color=");
779                         //memcpy(p, color, strlen(color));
780                         char *q = (char *)color;
781                         while ('\0' != p[0] && '\0' != q[0])
782                         {
783                                 *p = *q;
784                                 p++;
785                                 q++;
786                         }
787                         if('>' != p[0]) //invalid format
788                         {
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);
794                         }
795                         else
796                                 g_strlcat(speciliztion, input_str1, MAX_SPECIALIZITION_LEN);
797                 }
798                 else
799                 {
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);
805                 }
806         }
807         else
808         {
809                 g_strlcat(speciliztion, input_str, MAX_SPECIALIZITION_LEN);
810         }
811         if (align)
812         {
813                 g_strlcat(speciliztion, "</align>", MAX_SPECIALIZITION_LEN);
814         }
815         if (font_size > 0)
816         {
817                 g_strlcat(speciliztion, "</font_size>", MAX_SPECIALIZITION_LEN);
818         }
819
820         SETTING_TRACE("Exit %s, return :%s", __FUNCTION__, speciliztion);
821         return (char *)strdup(speciliztion);;
822 }
823