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