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