upload codes for TIZEN 2.0
[apps/home/clock.git] / clock-common / src / clock_fwk_widget.c
1 /*
2 *
3 * Copyright 2012  Samsung Electronics Co., Ltd
4 *
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *    http://www.tizenopensource.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 */
18
19 #include <time.h>
20 #include <appcore-efl.h>
21 #include <Ecore_X.h>
22 #include <vconf-keys.h>
23 #include <vconf.h>
24 #include "clock_fwk_widget.h"
25 #include "clock_fwk_util.h"
26
27 /**********************************************************************
28 ******************Local function declear, extern function declear*************************************
29 ***********************************************************************/
30
31 static void _widget_def_popup_response_cb(void *data, Evas_Object * obj,
32                                           void *event_info);
33 /**********************************************************************
34 ******************Local function ref*************************************
35 ***********************************************************************/
36
37 /**
38 * send
39 * This function is  used to be default cb in the elm_popup when get signle:"response"
40 * @param           data   pointer to data
41 * @param           obj    pointer to current evas object
42 * @param           event_info    pointer to current event
43 * @return          void
44 * @exception     I
45 */
46 static void _widget_def_popup_response_cb(void *data, Evas_Object * obj,
47                                           void *event_info)
48 {
49         EVAS_OBJECT_DELIF(obj);
50 }
51
52 static void _entry_changed_cb(void *data, Evas_Object * obj, void *event_info)
53 {
54
55         if (elm_object_focus_get(data)) {
56                 if (elm_entry_is_empty(obj))
57                         elm_object_signal_emit(data, "elm,state,eraser,hide",
58                                                "elm");
59                 else
60                         elm_object_signal_emit(data, "elm,state,eraser,show",
61                                                "elm");
62         }
63 }
64
65 static void _entry_focused_cb(void *data, Evas_Object * obj, void *event_info)
66 {
67         if (!elm_entry_is_empty(obj))
68                 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
69         elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
70
71 }
72
73 static void _entry_unfocused_cb(void *data, Evas_Object * obj, void *event_info)
74 {
75
76         if (elm_entry_is_empty(obj))
77                 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
78         elm_object_signal_emit(data, "elm,state,eraser,hide", "elm");
79 }
80
81 static void _eraser_clicked_cb(void *data, Evas_Object * obj,
82                                const char *emission, const char *source)
83 {
84         elm_entry_entry_set(data, "");
85 }
86
87 /**********************************************************************
88 ******************Global function ref*************************************
89 ***********************************************************************/
90
91 /**
92 * send
93 * This function is  used to set navigationbar's button's visible with icon
94 * @param           btn           pointer to button evas_object
95 * @param           bVisible      Eina_Bool for button visible(EINA_TRUE) or invisible(EINA_FALSE)
96 * @param           icon_path     char for button's icon path
97 * @return          when success, return SUCCESS, or return FAILED
98 * @exception
99 */
100 int widget_button_set(Evas_Object * btn, Eina_Bool bVisible, char *icon_path)
101 {
102         Evas_Object *icon = NULL;
103         int nErr = SUCCESS;
104         int ret = SUCCESS;
105         // //CLK_FUN_BEG();
106         CLK_RETVM_IF(!btn, FAILED, "btn is null");
107         if (!icon_path) {
108                 elm_object_disabled_set(btn, !bVisible);
109                 goto End;
110         }
111         icon = widget_create_icon(btn, icon_path);
112         CLK_RETVM_IF(!icon, FAILED, "icon is null");
113         if (EINA_TRUE == bVisible) {
114                 elm_object_part_content_set(btn, "icon", icon);
115                 elm_object_disabled_set(btn, !bVisible);
116         } else {
117                 elm_object_disabled_set(btn, !bVisible);
118                 elm_object_part_content_set(btn, "icon", icon);
119         }
120         evas_object_show(btn);
121  End:
122         // //CLK_FUN_END();
123         return ret;
124 }
125
126 /**
127 * send
128 * This function is  used to create navibar
129 * @param           navi_bar   pointer to Evas object, as navigationbar's pointer
130 * @param           title      string for navigationbar title
131 * @param           fn_btn1    pointer to evas object, as navigationbar's button1
132 * @param           fn_btn2    pointer to evas object, as navigationbar's button2
133 * @param           fn_btn3    pointer to evas object, as navigationbar's button3
134 * @param           content    pointer to evas object, as navigationbar's content
135 * @param           cbar       pointer to evas object, as controlbar's content
136 * @return          when success, return a pointer to evas object, or return NULL
137 * @exception
138 */
139 Elm_Object_Item *widget_naviframe_push(Evas_Object * navi_bar,
140                                        const char *title_label,
141                                        Evas_Object * prev_btn,
142                                        Evas_Object * next_btn,
143                                        Evas_Object * content,
144                                        const char *item_style,
145                                        Evas_Object * cbar)
146 {
147         CLK_FUN_BEG();
148         retv_if(!navi_bar, NULL);
149         Elm_Object_Item *item =
150             elm_naviframe_item_push(navi_bar, title_label, prev_btn, next_btn,
151                                     content, item_style);
152         if (cbar) {
153                 elm_object_item_part_content_set(item, "controlbar", cbar);
154         }
155         CLK_FUN_END();
156         return item;
157 }
158
159 //
160 Evas_Object *widget_create_controlbar(Evas_Object * parent, const char *style)
161 {
162         retv_if(!parent, NULL);
163         CLK_FUN_BEG();
164         Evas_Object *ret = elm_toolbar_add(parent);
165         elm_toolbar_shrink_mode_set(ret, ELM_TOOLBAR_SHRINK_EXPAND);
166         if (style) {
167                 elm_object_style_set(ret, style);
168                 if (0 == strcmp(style, "tabbar")) {
169                         elm_toolbar_select_mode_set(ret,
170                                                     ELM_OBJECT_SELECT_MODE_ALWAYS);
171                 }
172         }
173         CLK_FUN_END();
174         return ret;
175 }
176
177 /**
178 * send
179 * This function is  used to create button
180 * @param           parent       pointer to Evas object, as the  parent
181 * @param           label        string for  title
182 * @param           icon_path    string for  icon path
183 * @param           cb           as cb when get signle "clicked"
184 * @param           cb_data      as cb'data
185 * @param           style        as style
186 * @return          when success, return a pointer to evas object, or return NULL
187 * @exception
188 */
189 Evas_Object *widget_create_button(Evas_Object * parent, char *style,
190                                   const char *label, const char *icon_path,
191                                   EO_SMART_CB cb, void *cb_data)
192 {
193         Evas_Object *ret = NULL;
194         Evas_Object *icon = NULL;
195         int nErr = SUCCESS;
196         CLK_FUN_BEG();
197         ret = elm_button_add(parent);
198         CLK_RETVM_IF(!ret, NULL, "elm_button_add error!");
199         elm_object_style_set(ret, style);
200         evas_object_size_hint_weight_set(ret, EVAS_HINT_EXPAND,
201                                          EVAS_HINT_EXPAND);
202         evas_object_size_hint_align_set(ret, EVAS_HINT_FILL, 0.5);
203         if (icon_path) {
204                 icon = widget_create_icon(parent, icon_path);
205         }
206         if (label) {
207                 elm_object_text_set(ret, label);
208         }
209         if (icon) {
210                 elm_object_part_content_set(ret, "icon", icon);
211         }
212         if (cb && cb_data) {
213                 evas_object_smart_callback_add(ret, "clicked", cb, cb_data);
214         }
215         evas_object_show(ret);
216  End:
217         CLK_FUN_END();
218         return ret;
219 }
220
221 //
222 Evas_Object *widget_create_slider(Evas_Object * parent, char *style,
223                                   char *indicator, double d_min, double d_max)
224 {
225         Evas_Object *ret = NULL;
226         int nErr = SUCCESS;
227         //CLK_FUN_BEG();
228         ret = elm_slider_add(parent);
229         elm_object_style_set(ret, "expanded_indicator_button");
230         CLK_RETVM_IF(!ret, NULL, "elm_slider_add error!");
231 //  elm_object_style_set(ret, style);
232         evas_object_size_hint_weight_set(ret, EVAS_HINT_EXPAND, 0.0);
233         evas_object_size_hint_align_set(ret, EVAS_HINT_FILL, 0.5);
234         //evas_object_pass_events_set(ret, 1);
235         evas_object_propagate_events_set(ret, 0);
236         elm_slider_indicator_show_set(ret, EINA_TRUE);
237         elm_slider_indicator_format_set(ret, indicator);
238         elm_slider_min_max_set(ret, d_min, d_max);
239  End:
240         //CLK_FUN_END();
241         return ret;
242 }
243
244 //
245 Evas_Object *widget_create_conformant(Evas_Object * parent, char *style,
246                                       Evas_Object * content)
247 {
248         Evas_Object *ret = NULL;
249         int nErr = SUCCESS;
250         //CLK_FUN_BEG();
251         elm_win_conformant_set(parent, 1);
252         ret = elm_conformant_add(parent);
253         CLK_RETVM_IF(!ret, NULL, "ret error!");
254         elm_object_style_set(ret, style);
255         elm_object_content_set(ret, content);
256  End:
257         //CLK_FUN_END();
258         return ret;
259 }
260
261 /**
262 * send
263 * This function is  used to create icon
264 * @param           parent       pointer to Evas object, as the  parent
265 * @param           path         string for  icon path
266 * @return          when success, return a pointer to evas object, or return NULL
267 * @exception
268 */
269 Evas_Object *widget_create_icon(Evas_Object * parent, const gchar * path)
270 {
271         Evas_Object *ret = NULL;
272         int nErr = SUCCESS;
273         //CLK_FUN_BEG();
274         CLK_RETVM_IF(!path, NULL, "path is NULL");
275         ret = elm_icon_add(parent);
276         CLK_RETVM_IF(!ret, NULL, "elm_icon_add error!");
277         elm_icon_file_set(ret, path, NULL);
278  End:
279         //CLK_FUN_END();
280         return ret;
281 }
282
283 /**
284 * send
285 * This function is  used to create editfield
286 * @param           parent           pointer to Evas object, as the  parent
287 * @param           title            string for title
288 * @param           str              string for guide text
289 * @param           clicked_cb       cb, when get single "clicked"
290 * @param           data_clicked     @clicked_cb data
291 * @param           unfocused_cb     cb, when get signle "unfocused"
292 * @param           data_unfocused   @unfocused data
293 * @return          when success, return a pointer to evas object, or return NULL
294 * @exception
295 */
296 Evas_Object *widget_create_editfield(Evas_Object * parent, gchar * title,
297                                      gchar * str, EO_SMART_CB clicked_cb,
298                                      void *data_clicked,
299                                      EO_SMART_CB unfocused_cb,
300                                      void *data_unfocused)
301 {
302         Evas_Object *ret = NULL;
303         int nErr = SUCCESS;
304         Evas_Object *layout = elm_layout_add(parent);
305         elm_layout_theme_set(layout, "layout", "editfield", "title");
306         Evas_Object *entry = elm_entry_add(parent);
307         elm_object_part_content_set(layout, "elm.swallow.content", entry);
308         ret = layout;
309         CLK_RETVM_IF(!ret, NULL, "elm_editfield_add error!");
310         elm_object_part_text_set(layout, "elm.text", title);
311         elm_object_part_text_set(layout, "elm.text", str);
312         elm_entry_single_line_set(entry, EINA_TRUE);
313         elm_entry_scrollable_set(entry, EINA_TRUE);
314
315         evas_object_size_hint_weight_set(ret, EVAS_HINT_EXPAND,
316                                          EVAS_HINT_EXPAND);
317         evas_object_size_hint_align_set(ret, EVAS_HINT_FILL, 0);
318         //cb
319         evas_object_smart_callback_add(entry, "changed", _entry_changed_cb,
320                                        layout);
321
322         evas_object_smart_callback_add(entry, "focused", _entry_focused_cb,
323                                        layout);
324
325         evas_object_smart_callback_add(entry, "unfocused", _entry_unfocused_cb,
326                                        layout);
327         elm_object_signal_callback_add(layout, "elm,eraser,clicked", "elm",
328                                        _eraser_clicked_cb, entry);
329  End:
330         //CLK_FUN_END();
331         return ret;
332
333 }
334
335 /**
336 * send
337 * This function is  used to create box
338 * @param           parent           pointer to evas object, as the  parent
339 * @return          when success, return a pointer to evas object, or return NULL
340 * @exception
341 */
342 Evas_Object *widget_create_box(Evas_Object * parent)
343 {
344         Evas_Object *ret = NULL;
345         int nErr = SUCCESS;
346         //CLK_FUN_BEG();
347         ret = elm_box_add(parent);
348         CLK_RETVM_IF(!ret, NULL, "elm_box_add error!");
349         //beat style
350         elm_box_horizontal_set(ret, 0);
351         evas_object_size_hint_weight_set(ret, EVAS_HINT_EXPAND, 0.0);
352         evas_object_size_hint_align_set(ret, EVAS_HINT_FILL, 0.0);
353  End:
354         //CLK_FUN_END();
355         return ret;
356 }
357
358 /**
359 * send
360 * This function is  used to create layout
361 * @param           parent           pointer to evas object, as the  parent
362 * @return          when success, return a pointer to evas object, or return NULL
363 * @exception
364 */
365 Evas_Object *widget_create_layout(Evas_Object * parent)
366 {
367         Evas_Object *ret = elm_layout_add(parent);
368         retvm_if(!ret, NULL, "elm_layout_add error!");
369         elm_layout_theme_set(ret, "layout", "application", "noindicator");
370         evas_object_size_hint_weight_set(ret, EVAS_HINT_EXPAND,
371                                          EVAS_HINT_EXPAND);
372         evas_object_show(ret);
373         return ret;
374 }
375
376 /**
377 * send
378 * This function is  used to create popup
379 * @param           parent[in]               pointer to evas object, as the  parent
380 * @param           content_str[in]          string for description text.
381 * @param           title_str[in]            string for label
382 * @param           timeout[double]          double for popup time
383 * @param           response_cb[in]          cb to get single "response"
384 * @param           data[in]                 @response_cb data
385 * @return          when success, return a pointer to evas object, or return NULL
386 * @exception
387 */
388 Evas_Object *widget_create_popup(Evas_Object * parent, char *content_str,
389                                  char *title_str, double timeout,
390                                  EO_SMART_CB response_cb, void *data)
391 {
392         Evas_Object *popup = elm_popup_add(parent);
393         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
394                                          EVAS_HINT_EXPAND);
395         if (content_str) {
396                 gchar r_str_text[200] = { 0 };
397                 snprintf(r_str_text, sizeof(r_str_text),
398                          "<font_size=32><align=center>%s</align></font_size>",
399                          content_str);
400                 elm_object_text_set(popup, r_str_text);
401         }
402         if (title_str) {
403                 elm_object_text_set(popup, title_str);
404         }
405         if (timeout > 0) {
406                 elm_popup_timeout_set(popup, timeout);
407         }
408         if (response_cb) {
409                 evas_object_smart_callback_add(popup, "response", response_cb,
410                                                data);
411         } else {
412                 evas_object_smart_callback_add(popup, "response",
413                                                _widget_def_popup_response_cb,
414                                                data);
415         }
416         evas_object_show(popup);
417         return popup;
418 }
419
420 /**
421 * send
422 * This function is  used to create blank
423 * @param           parent[in]               pointer to evas object, as the  parent
424 * @param           minw[in]                 Evas_Coord, as min width
425 * @param           minh[in]                 Evas_Coord, as min height
426 * @return          when success, return a pointer to evas object, or return NULL
427 * @exception
428 */
429 Evas_Object *widget_create_rectangle_blank(Evas_Object * parent,
430                                            Evas_Object * parent_box,
431                                            Evas_Coord minw, Evas_Coord minh)
432 {
433         Evas_Object *rect;
434         //CLK_FUN_BEG();
435         rect = evas_object_rectangle_add(evas_object_evas_get(parent));
436         retvm_if(NULL_CHECK(rect), NULL, "rect null");
437         evas_object_size_hint_min_set(rect, minw, minh);
438         evas_object_size_hint_weight_set(rect, 0.0, 0.0);
439         evas_object_size_hint_align_set(rect, EVAS_HINT_FILL, EVAS_HINT_FILL);
440         evas_object_color_set(rect, 0, 0, 0, 0);
441         elm_box_pack_end(parent_box, rect);
442         evas_object_show(rect);
443         //CLK_FUN_END();
444         return rect;
445 }
446
447 /**********************************************************************
448 ****************** BEG: EDC Widget button*************************************
449 ***********************************************************************/
450 //
451 static Edje_Color_Class g_Edje_Color_Class;
452 static Eina_Bool g_bPressed = EINA_FALSE;
453 //
454 static void _clk_btn_mouse_down_cb(void *data, Evas_Object * obj,
455                                    const char *emission, const char *source)
456 {
457         Edje_Color_Class *color_class = (Edje_Color_Class *) data;
458         edje_object_color_class_get(obj, color_class->name,
459                                     &g_Edje_Color_Class.r,
460                                     &g_Edje_Color_Class.g,
461                                     &g_Edje_Color_Class.b,
462                                     &g_Edje_Color_Class.a,
463                                     &g_Edje_Color_Class.r2,
464                                     &g_Edje_Color_Class.g2,
465                                     &g_Edje_Color_Class.b2,
466                                     &g_Edje_Color_Class.a2,
467                                     &g_Edje_Color_Class.r3,
468                                     &g_Edje_Color_Class.g3,
469                                     &g_Edje_Color_Class.b3,
470                                     &g_Edje_Color_Class.a3);
471         edje_object_color_class_set(obj, color_class->name, color_class->r,
472                                     color_class->g, color_class->b,
473                                     color_class->a, color_class->r2,
474                                     color_class->g2, color_class->b2,
475                                     color_class->a2, color_class->r3,
476                                     color_class->g3, color_class->b3,
477                                     color_class->a3);
478         g_bPressed = EINA_TRUE;
479 }
480
481 //
482 static void _clk_btn_mouse_up_cb(void *data, Evas_Object * obj,
483                                  const char *emission, const char *source)
484 {
485         Edje_Color_Class *color_class = (Edje_Color_Class *) data;
486         if (g_bPressed) {
487                 edje_object_color_class_set(obj, color_class->name,
488                                             g_Edje_Color_Class.r,
489                                             g_Edje_Color_Class.g,
490                                             g_Edje_Color_Class.b,
491                                             g_Edje_Color_Class.a,
492                                             g_Edje_Color_Class.r2,
493                                             g_Edje_Color_Class.g2,
494                                             g_Edje_Color_Class.b2,
495                                             g_Edje_Color_Class.a2,
496                                             g_Edje_Color_Class.r3,
497                                             g_Edje_Color_Class.g3,
498                                             g_Edje_Color_Class.b3,
499                                             g_Edje_Color_Class.a3);
500                 g_bPressed = EINA_FALSE;
501         }
502 }
503
504 //
505 Evas_Object *clk_widget_create_button(Evas_Object * parent,
506                                       const char *file, const char *group,
507                                       Edje_Color_Class * color_class,
508                                       Edje_Signal_Cb clicked_cb, void *data)
509 {
510         retvm_if(NULL_CHECK(parent), NULL, "parent null");
511         retvm_if(NULL_CHECK(file), NULL, "file null");
512         retvm_if(NULL_CHECK(group), NULL, "group null");
513         retvm_if(NULL_CHECK(color_class), NULL, "color_class null");
514         CLK_FUN_BEG();
515         Evas_Object *ret = NULL;
516         ret = load_edj(parent, file, group);
517         retvm_if(NULL_CHECK(ret), NULL, "ret null");
518         edje_object_signal_callback_add(_EDJ(ret), "mouse,down", "rect",
519                                         _clk_btn_mouse_down_cb,
520                                         (void *)color_class);
521         edje_object_signal_callback_add(_EDJ(ret), "mouse,up", "rect",
522                                         _clk_btn_mouse_up_cb,
523                                         (void *)color_class);
524         if (clicked_cb) {
525                 edje_object_signal_callback_add(_EDJ(ret), "mouse,clicked",
526                                                 "rect", clicked_cb, data);
527         }
528         CLK_FUN_END();
529         return ret;
530 }
531
532 /**********************************************************************
533 ****************** END: EDC Widget button*************************************
534 ***********************************************************************/