Elementary segment_control: Introduced new widget by Govindaraju and Prince.
[framework/uifw/elementary.git] / src / lib / elm_clock.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Clock Clock
6  *
7  * It's a widget to show clock with animation. The update of time is
8  * shown in an animation like the flip of a sheet.
9  *
10  * Signals that you can add callbacks for are:
11  *
12  * "changed" - the user changed the time
13  */
14
15 typedef struct _Widget_Data Widget_Data;
16
17 struct _Widget_Data
18 {
19    Evas_Object *clk;
20    double interval, first_interval;
21    Eina_Bool seconds : 1;
22    Eina_Bool am_pm : 1;
23    Eina_Bool edit : 1;
24    Elm_Clock_Digedit digedit;
25    int hrs, min, sec, timediff;
26    Evas_Object *digit[6];
27    Evas_Object *ampm;
28    Evas_Object *sel_obj;
29    Ecore_Timer *ticker, *spin;
30    struct
31    {
32       int hrs, min, sec;
33       char ampm;
34       Eina_Bool seconds : 1;
35       Eina_Bool am_pm : 1;
36       Eina_Bool edit : 1;
37       Elm_Clock_Digedit digedit;
38    } cur;
39 };
40
41 static const char *widtype = NULL;
42 static void _del_hook(Evas_Object *obj);
43 static void _theme_hook(Evas_Object *obj);
44 static void _on_focus_hook(void *data, Evas_Object *obj);
45 static Eina_Bool _ticker(void *data);
46 static Eina_Bool _signal_clock_val_up(void *data);
47 static Eina_Bool _signal_clock_val_down(void *data);
48 static void _time_update(Evas_Object *obj);
49
50 static void
51 _del_hook(Evas_Object *obj)
52 {
53    Widget_Data *wd = elm_widget_data_get(obj);
54    if (!wd) return;
55    int i;
56    for (i = 0; i < 6; i++)
57      {
58         if (wd->digit[i]) evas_object_del(wd->digit[i]);
59      }
60    if (wd->ampm) evas_object_del(wd->ampm);
61    if (wd->ticker) ecore_timer_del(wd->ticker);
62    if (wd->spin) ecore_timer_del(wd->spin);
63    free(wd);
64 }
65
66 static void
67 _theme_hook(Evas_Object *obj)
68 {
69    Widget_Data *wd = elm_widget_data_get(obj);
70    if (!wd) return;
71    if (elm_widget_focus_get(obj))
72      edje_object_signal_emit(wd->clk, "elm,action,focus", "elm");
73    else
74      edje_object_signal_emit(wd->clk, "elm,action,unfocus", "elm");
75    wd->cur.am_pm = !wd->cur.am_pm; /* hack - force update */
76    _time_update(obj);
77 }
78
79 static void
80 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
81 {
82    Widget_Data *wd = elm_widget_data_get(obj);
83    if (!wd) return;
84    if (elm_widget_focus_get(obj))
85      {
86         edje_object_signal_emit(wd->clk, "elm,action,focus", "elm");
87         evas_object_focus_set(wd->clk, EINA_TRUE);
88      }
89    else
90      {
91         edje_object_signal_emit(wd->clk, "elm,action,unfocus", "elm");
92         evas_object_focus_set(wd->clk, EINA_FALSE);
93      }
94 }
95
96 static void
97 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
98 {
99    Widget_Data *wd = elm_widget_data_get(obj);
100    int i;
101    if (!wd) return;
102    edje_object_signal_emit(wd->clk, emission, source);
103    for (i = 0; i < 6; i++)
104      {
105         if (wd->digit[i])
106           edje_object_signal_emit(wd->digit[i], emission, source);
107      }
108 }
109
110 static void
111 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
112 {
113    Widget_Data *wd = elm_widget_data_get(obj);
114    int i;
115    if (!wd) return;
116    edje_object_signal_callback_add(wd->clk, emission, source, func_cb, data);
117    for (i = 0; i < 6; i++)
118      {
119         if (wd->digit[i])
120           edje_object_signal_callback_add(wd->digit[i], emission, source,
121                                           func_cb, data);
122      }
123 }
124
125 static void
126 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
127 {
128    Widget_Data *wd = elm_widget_data_get(obj);
129    int i;
130    for (i = 0; i < 6; i++)
131      {
132         edje_object_signal_callback_del_full(wd->digit[i], emission, source,
133                                              func_cb, data);
134      }
135    edje_object_signal_callback_del_full(wd->clk, emission, source, func_cb,
136                                         data);
137 }
138
139 static void
140 _timediff_set(Widget_Data *wd)
141 {
142    struct timeval timev;
143    struct tm *tm;
144    time_t tt;
145    gettimeofday(&timev, NULL);
146    tt = (time_t)(timev.tv_sec);
147    tzset();
148    tm = localtime(&tt);
149    wd->timediff = (((wd->hrs - tm->tm_hour) * 60 +
150                     wd->min - tm->tm_min) * 60) + wd->sec - tm->tm_sec;
151 }
152
153 static Eina_Bool
154 _ticker(void *data)
155 {
156    Widget_Data *wd = elm_widget_data_get(data);
157    double t;
158    struct timeval timev;
159    struct tm *tm;
160    time_t tt;
161    if (!wd) return ECORE_CALLBACK_CANCEL;
162    gettimeofday(&timev, NULL);
163    t = ((double)(1000000 - timev.tv_usec)) / 1000000.0;
164    wd->ticker = ecore_timer_add(t, _ticker, data);
165    if (!wd->edit)
166      {
167         tt = (time_t)(timev.tv_sec) + wd->timediff;
168         tzset();
169         tm = localtime(&tt);
170         if (tm)
171           {
172              wd->hrs = tm->tm_hour;
173              wd->min = tm->tm_min;
174              wd->sec = tm->tm_sec;
175              _time_update(data);
176           }
177      }
178    return ECORE_CALLBACK_CANCEL;
179 }
180
181 static Eina_Bool
182 _signal_clock_val_up(void *data)
183 {
184    Widget_Data *wd = elm_widget_data_get(data);
185    if (!wd) goto clock_val_up_exit_on_error;
186    if (!wd->edit) goto clock_val_up_cancel;
187    if (!wd->sel_obj) goto clock_val_up_cancel;
188    if (wd->sel_obj == wd->digit[0])
189      {
190         wd->hrs = wd->hrs + 10;
191         if (wd->hrs >= 24) wd->hrs -= 24;
192      }
193    if (wd->sel_obj == wd->digit[1])
194      {
195         wd->hrs = wd->hrs + 1;
196         if (wd->hrs >= 24) wd->hrs -= 24;
197      }
198    if (wd->sel_obj == wd->digit[2])
199      {
200         wd->min = wd->min + 10;
201         if (wd->min >= 60) wd->min -= 60;
202      }
203    if (wd->sel_obj == wd->digit[3])
204      {
205         wd->min = wd->min + 1;
206         if (wd->min >= 60) wd->min -= 60;
207      }
208    if (wd->sel_obj == wd->digit[4])
209      {
210         wd->sec = wd->sec + 10;
211         if (wd->sec >= 60) wd->sec -= 60;
212      }
213    if (wd->sel_obj == wd->digit[5])
214      {
215         wd->sec = wd->sec + 1;
216         if (wd->sec >= 60) wd->sec -= 60;
217      }
218    if (wd->sel_obj == wd->ampm)
219      {
220         wd->hrs = wd->hrs + 12;
221         if (wd->hrs > 23) wd->hrs -= 24;
222      }
223    wd->interval = wd->interval / 1.05;
224    ecore_timer_interval_set(wd->spin, wd->interval);
225    _time_update(data);
226    evas_object_smart_callback_call(data, "changed", NULL);
227    return ECORE_CALLBACK_RENEW;
228 clock_val_up_cancel:
229    wd->spin = NULL;
230 clock_val_up_exit_on_error:
231    return ECORE_CALLBACK_CANCEL;
232 }
233
234 static Eina_Bool
235 _signal_clock_val_down(void *data)
236 {
237    Widget_Data *wd = elm_widget_data_get(data);
238    if (!wd) goto clock_val_down_exit_on_error;
239    if (!wd->edit) goto clock_val_down_cancel;
240    if (!wd->sel_obj) goto clock_val_down_cancel;
241    if (wd->sel_obj == wd->digit[0])
242      {
243         wd->hrs = wd->hrs - 10;
244         if (wd->hrs < 0) wd->hrs += 24;
245      }
246    if (wd->sel_obj == wd->digit[1])
247      {
248         wd->hrs = wd->hrs - 1;
249         if (wd->hrs < 0) wd->hrs += 24;
250      }
251    if (wd->sel_obj == wd->digit[2])
252      {
253         wd->min = wd->min - 10;
254         if (wd->min < 0) wd->min += 60;
255      }
256    if (wd->sel_obj == wd->digit[3])
257      {
258         wd->min = wd->min - 1;
259         if (wd->min < 0) wd->min += 60;
260      }
261    if (wd->sel_obj == wd->digit[4])
262      {
263         wd->sec = wd->sec - 10;
264         if (wd->sec < 0) wd->sec += 60;
265      }
266    if (wd->sel_obj == wd->digit[5])
267      {
268         wd->sec = wd->sec - 1;
269         if (wd->sec < 0) wd->sec += 60;
270      }
271    if (wd->sel_obj == wd->ampm)
272      {
273         wd->hrs = wd->hrs - 12;
274         if (wd->hrs < 0) wd->hrs += 24;
275      }
276    wd->interval = wd->interval / 1.05;
277    ecore_timer_interval_set(wd->spin, wd->interval);
278    _time_update(data);
279    evas_object_smart_callback_call(data, "changed", NULL);
280    return ECORE_CALLBACK_RENEW;
281 clock_val_down_cancel:
282    wd->spin = NULL;
283 clock_val_down_exit_on_error:
284    return ECORE_CALLBACK_CANCEL;
285 }
286
287 static void
288 _signal_clock_val_up_start(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
289 {
290    Widget_Data *wd = elm_widget_data_get(data);
291    if (!wd) return;
292    wd->interval = wd->first_interval;
293    wd->sel_obj = obj;
294    if (wd->spin) ecore_timer_del(wd->spin);
295    wd->spin = ecore_timer_add(wd->interval, _signal_clock_val_up, data);
296    _signal_clock_val_up(data);
297 }
298
299 static void
300 _signal_clock_val_down_start(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
301 {
302    Widget_Data *wd = elm_widget_data_get(data);
303    if (!wd) return;
304    wd->interval = wd->first_interval;
305    wd->sel_obj = obj;
306    if (wd->spin) ecore_timer_del(wd->spin);
307    wd->spin = ecore_timer_add(wd->interval, _signal_clock_val_down, data);
308    _signal_clock_val_down(data);
309 }
310
311 static void
312 _signal_clock_val_change_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
313 {
314    Widget_Data *wd = elm_widget_data_get(data);
315    if (!wd) return;
316    if (wd->spin) ecore_timer_del(wd->spin);
317    wd->spin = NULL;
318    wd->sel_obj = NULL;
319 }
320
321 static void
322 _time_update(Evas_Object *obj)
323 {
324    Widget_Data *wd = elm_widget_data_get(obj);
325    Edje_Message_Int msg;
326    int ampm = 0;
327    const char *style = elm_widget_style_get(obj);
328    if (!wd) return;
329    if ((wd->cur.seconds != wd->seconds) || (wd->cur.am_pm != wd->am_pm) ||
330        (wd->cur.edit != wd->edit) || (wd->cur.digedit != wd->digedit))
331      {
332         int i;
333         Evas_Coord mw, mh;
334
335         for (i = 0; i < 6; i++)
336           {
337              if (wd->digit[i])
338                {
339                   evas_object_del(wd->digit[i]);
340                   wd->digit[i] = NULL;
341                }
342           }
343         if (wd->ampm)
344           {
345              evas_object_del(wd->ampm);
346              wd->ampm = NULL;
347           }
348
349         if ((wd->seconds) && (wd->am_pm))
350           _elm_theme_object_set(obj, wd->clk, "clock", "base-all", style);
351         else if (wd->seconds)
352           _elm_theme_object_set(obj, wd->clk, "clock", "base-seconds", style);
353         else if (wd->am_pm)
354           _elm_theme_object_set(obj, wd->clk, "clock", "base-am_pm", style);
355         else
356           _elm_theme_object_set(obj, wd->clk, "clock", "base", style);
357         edje_object_scale_set(wd->clk, elm_widget_scale_get(obj) *
358                               _elm_config->scale);
359
360         for (i = 0; i < 6; i++)
361           {
362              char buf[16];
363
364              if ((!wd->seconds) && (i >= 4)) break;
365              wd->digit[i] = edje_object_add(evas_object_evas_get(wd->clk));
366              _elm_theme_object_set(obj, wd->digit[i], "clock", "flipdigit", style);
367              edje_object_scale_set(wd->digit[i], elm_widget_scale_get(obj) *
368                                    _elm_config->scale);
369              if ((wd->edit) && (wd->digedit & (1 << i)))
370                edje_object_signal_emit(wd->digit[i], "elm,state,edit,on", "elm");
371              edje_object_signal_callback_add(wd->digit[i], "elm,action,up,start",
372                                              "", _signal_clock_val_up_start, obj);
373              edje_object_signal_callback_add(wd->digit[i], "elm,action,up,stop",
374                                              "", _signal_clock_val_change_stop, obj);
375              edje_object_signal_callback_add(wd->digit[i], "elm,action,down,start",
376                                              "", _signal_clock_val_down_start, obj);
377              edje_object_signal_callback_add(wd->digit[i], "elm,action,down,stop",
378                                              "", _signal_clock_val_change_stop, obj);
379              mw = mh = -1;
380              elm_coords_finger_size_adjust(1, &mw, 2, &mh);
381              edje_object_size_min_restricted_calc(wd->digit[i], &mw, &mh, mw, mh);
382              elm_coords_finger_size_adjust(1, &mw, 2, &mh);
383              edje_extern_object_min_size_set(wd->digit[i], mw, mh);
384              snprintf(buf, sizeof(buf), "d%i", i);
385              edje_object_part_swallow(wd->clk , buf, wd->digit[i]);
386              evas_object_show(wd->digit[i]);
387           }
388         if (wd->am_pm)
389           {
390              wd->ampm = edje_object_add(evas_object_evas_get(wd->clk));
391              _elm_theme_object_set(obj, wd->ampm, "clock", "flipampm", style);
392              edje_object_scale_set(wd->ampm, elm_widget_scale_get(obj) *
393                                    _elm_config->scale);
394              if (wd->edit)
395                edje_object_signal_emit(wd->ampm, "elm,state,edit,on", "elm");
396              edje_object_signal_callback_add(wd->ampm, "elm,action,up,start",
397                                              "", _signal_clock_val_up_start, obj);
398              edje_object_signal_callback_add(wd->ampm, "elm,action,up,stop",
399                                              "", _signal_clock_val_change_stop, obj);
400              edje_object_signal_callback_add(wd->ampm, "elm,action,down,start",
401                                              "", _signal_clock_val_down_start, obj);
402              edje_object_signal_callback_add(wd->ampm, "elm,action,down,stop",
403                                              "", _signal_clock_val_change_stop, obj);
404              mw = mh = -1;
405              elm_coords_finger_size_adjust(1, &mw, 2, &mh);
406              edje_object_size_min_restricted_calc(wd->ampm, &mw, &mh, mw, mh);
407              elm_coords_finger_size_adjust(1, &mw, 2, &mh);
408              edje_extern_object_min_size_set(wd->ampm, mw, mh);
409              edje_object_part_swallow(wd->clk , "ampm", wd->ampm);
410              evas_object_show(wd->ampm);
411           }
412
413         edje_object_size_min_calc(wd->clk, &mw, &mh);
414         evas_object_size_hint_min_set(obj, mw, mh);
415
416         wd->cur.hrs = 0;
417         wd->cur.min = 0;
418         wd->cur.sec = 0;
419         wd->cur.ampm = -1;
420         wd->cur.seconds = wd->seconds;
421         wd->cur.am_pm = wd->am_pm;
422         wd->cur.edit = wd->edit;
423         wd->cur.digedit = wd->digedit;
424      }
425    if (wd->hrs != wd->cur.hrs)
426      {
427         int hrs;
428         int d1, d2, dc1, dc2;
429
430         hrs = wd->hrs;
431         if (wd->am_pm)
432           {
433              if (hrs >= 12)
434                {
435                   if (hrs > 12) hrs -= 12;
436                   ampm = 1;
437                }
438              else if (!hrs) hrs = 12;
439           }
440         d1 = hrs / 10;
441         d2 = hrs % 10;
442         dc1 = wd->cur.hrs / 10;
443         dc2 = wd->cur.hrs % 10;
444         if (d1 != dc1)
445           {
446              msg.val = d1;
447              edje_object_message_send(wd->digit[0], EDJE_MESSAGE_INT, 1, &msg);
448           }
449         if (d2 != dc2)
450           {
451              msg.val = d2;
452              edje_object_message_send(wd->digit[1], EDJE_MESSAGE_INT, 1, &msg);
453           }
454         wd->cur.hrs = hrs;
455      }
456    if (wd->min != wd->cur.min)
457      {
458         int d1, d2, dc1, dc2;
459
460         d1 = wd->min / 10;
461         d2 = wd->min % 10;
462         dc1 = wd->cur.min / 10;
463         dc2 = wd->cur.min % 10;
464         if (d1 != dc1)
465           {
466              msg.val = d1;
467              edje_object_message_send(wd->digit[2], EDJE_MESSAGE_INT, 1, &msg);
468           }
469         if (d2 != dc2)
470           {
471              msg.val = d2;
472              edje_object_message_send(wd->digit[3], EDJE_MESSAGE_INT, 1, &msg);
473           }
474         wd->cur.min = wd->min;
475      }
476    if (wd->seconds)
477      {
478         if (wd->sec != wd->cur.sec)
479           {
480              int d1, d2, dc1, dc2;
481
482              d1 = wd->sec / 10;
483              d2 = wd->sec % 10;
484              dc1 = wd->cur.sec / 10;
485              dc2 = wd->cur.sec % 10;
486              if (d1 != dc1)
487                {
488                   msg.val = d1;
489                   edje_object_message_send(wd->digit[4], EDJE_MESSAGE_INT, 1, &msg);
490                }
491              if (d2 != dc2)
492                {
493                   msg.val = d2;
494                   edje_object_message_send(wd->digit[5], EDJE_MESSAGE_INT, 1, &msg);
495                }
496              wd->cur.sec = wd->sec;
497           }
498      }
499    else
500      wd->cur.sec = -1;
501
502    if (wd->am_pm)
503      {
504         if (wd->hrs >= 12) ampm = 1;
505         if (ampm != wd->cur.ampm)
506           {
507              if (wd->cur.ampm != ampm)
508                {
509                   msg.val = ampm;
510                   edje_object_message_send(wd->ampm, EDJE_MESSAGE_INT, 1, &msg);
511                }
512              wd->cur.ampm = ampm;
513           }
514      }
515    else
516      wd->cur.ampm = -1;
517 }
518
519 /**
520  * Add a new clock to the parent
521  *
522  * @param parent The parent object
523  *
524  * This function inserts a clock widget on a given canvas to show a
525  * animated clock.
526  *
527  * @ingroup Clock
528  */
529 EAPI Evas_Object *
530 elm_clock_add(Evas_Object *parent)
531 {
532    Evas_Object *obj;
533    Evas *e;
534    Widget_Data *wd;
535
536    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
537
538    ELM_SET_WIDTYPE(widtype, "clock");
539    elm_widget_type_set(obj, "clock");
540    elm_widget_sub_object_add(parent, obj);
541    elm_widget_data_set(obj, wd);
542    elm_widget_del_hook_set(obj, _del_hook);
543    elm_widget_theme_hook_set(obj, _theme_hook);
544    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
545    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
546    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
547    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
548    elm_widget_can_focus_set(obj, EINA_TRUE);
549
550    wd->clk = edje_object_add(e);
551    elm_widget_resize_object_set(obj, wd->clk);
552
553    wd->cur.ampm = -1;
554    wd->cur.seconds = EINA_TRUE;
555    wd->cur.am_pm = EINA_TRUE;
556    wd->cur.edit = EINA_TRUE;
557    wd->cur.digedit = ELM_CLOCK_NONE;
558    wd->first_interval = 0.85;
559    wd->timediff = 0;
560
561    _time_update(obj);
562    _ticker(obj);
563
564    return obj;
565 }
566
567 /**
568  * Set the clock time
569  *
570  * @param obj The clock object
571  * @param hrs The hours to set
572  * @param min The minutes to set
573  * @param sec The secondes to set
574  *
575  * This function updates the time that is showed by the clock widget
576  *
577  * @ingroup Clock
578  */
579 EAPI void
580 elm_clock_time_set(Evas_Object *obj, int hrs, int min, int sec)
581 {
582    ELM_CHECK_WIDTYPE(obj, widtype);
583    Widget_Data *wd = elm_widget_data_get(obj);
584    if (!wd) return;
585    wd->hrs = hrs;
586    wd->min = min;
587    wd->sec = sec;
588    _timediff_set(wd);
589    _time_update(obj);
590 }
591
592 /**
593  * Get clock time
594  *
595  * @param obj The clock object
596  * @param hrs Pointer to the variable to get the hour of this clock
597  * object
598  * @param min Pointer to the variable to get the minute of this clock
599  * object
600  * @param sec Pointer to the variable to get the second of this clock
601  * object
602  *
603  * This function gets the time set of the clock widget and returns it
604  * on the variables passed as the arguments to function
605  *
606  * @ingroup Clock
607  */
608 EAPI void
609 elm_clock_time_get(const Evas_Object *obj, int *hrs, int *min, int *sec)
610 {
611    ELM_CHECK_WIDTYPE(obj, widtype);
612    Widget_Data *wd = elm_widget_data_get(obj);
613    if (!wd) return;
614    if (hrs) *hrs = wd->hrs;
615    if (min) *min = wd->min;
616    if (sec) *sec = wd->sec;
617 }
618
619 /**
620  * Set if the clock settings can be edited
621  *
622  * @param obj The clock object
623  * @param edit Bool option for edited (1 = yes, 0 = no)
624  *
625  * This function sets if the clock settings can be edited or not.
626  * By default or if digit_edit option was previously set to ELM_CLOCK_NONE,
627  * all digits are editable. To choose what digits to make editable
628  * use elm_clock_digit_edit_set().
629  *
630  * @ingroup Clock
631  */
632 EAPI void
633 elm_clock_edit_set(Evas_Object *obj, Eina_Bool edit)
634 {
635    ELM_CHECK_WIDTYPE(obj, widtype);
636    Widget_Data *wd = elm_widget_data_get(obj);
637    if (!wd) return;
638    wd->edit = edit;
639    if (!edit)
640      _timediff_set(wd);
641    if ((edit) && (wd->digedit == ELM_CLOCK_NONE))
642      elm_clock_digit_edit_set(obj, ELM_CLOCK_ALL);
643    else
644      _time_update(obj);
645 }
646
647 /**
648  * Get if the clock settings can be edited
649  *
650  * @param obj The clock object
651  * @return Bool option for edited (1 = yes, 0 = no)
652  *
653  * This function gets if the clock settings can be edited or not.
654  *
655  * @ingroup Clock
656  */
657 EAPI Eina_Bool
658 elm_clock_edit_get(const Evas_Object *obj)
659 {
660    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
661    Widget_Data *wd = elm_widget_data_get(obj);
662    if (!wd) return EINA_FALSE;
663    return wd->edit;
664 }
665
666 /**
667  * Set what digits of the clock are editable
668  *
669  * @param obj The clock object
670  * @param digedit Bit mask indicating the digits to edit
671  *
672  * If the digedit param is ELM_CLOCK_NONE, editing will be disabled.
673  *
674  * @ingroup Clock
675  */
676 EAPI void
677 elm_clock_digit_edit_set(Evas_Object *obj, Elm_Clock_Digedit digedit)
678 {
679    ELM_CHECK_WIDTYPE(obj, widtype);
680    Widget_Data *wd = elm_widget_data_get(obj);
681    if (!wd) return;
682    wd->digedit = digedit;
683    if (digedit == ELM_CLOCK_NONE)
684      elm_clock_edit_set(obj, EINA_FALSE);
685    else
686      _time_update(obj);
687 }
688
689 /**
690  * Get what digits of the clock are editable
691  *
692  * @param obj The clock object
693  * @return Bit mask indicating the digits.
694  *
695  * @ingroup Clock
696  */
697 EAPI Elm_Clock_Digedit
698 elm_clock_digit_edit_get(const Evas_Object *obj)
699 {
700    ELM_CHECK_WIDTYPE(obj, widtype) 0;
701    Widget_Data *wd = elm_widget_data_get(obj);
702    if (!wd) return 0;
703    return wd->digedit;
704 }
705
706 /**
707  * Set if the clock shows hours in military or am/pm mode
708  *
709  * @param obj The clock object
710  * @param am_pm Bool option for the hours mode
711  * (1 = am/pm, 0 = military)
712  *
713  * This function sets the clock to show hours in military or am/pm
714  * mode. Some countries like Brazil the military mode (00-24h-format)
715  * is used in opposition to the USA where the am/pm mode is more
716  * common used.
717  *
718  * @ingroup Clock
719  */
720 EAPI void
721 elm_clock_show_am_pm_set(Evas_Object *obj, Eina_Bool am_pm)
722 {
723    ELM_CHECK_WIDTYPE(obj, widtype);
724    Widget_Data *wd = elm_widget_data_get(obj);
725    if (!wd) return;
726    wd->am_pm = am_pm;
727    _time_update(obj);
728 }
729
730 /**
731  * Get if the clock shows hours in military or am/pm mode
732  *
733  * @param obj The clock object
734  * @return Bool option for the hours mode
735  * (1 = am/pm, 0 = military)
736  *
737  * This function gets if the clock show hours in military or am/pm
738  * mode. Some countries like Brazil the military mode (00-24h-format)
739  * is used in opposition to the USA where the am/pm mode is more
740  * common used.
741  *
742  * @ingroup Clock
743  */
744 EAPI Eina_Bool
745 elm_clock_show_am_pm_get(const Evas_Object *obj)
746 {
747    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
748    Widget_Data *wd = elm_widget_data_get(obj);
749    if (!wd) return EINA_FALSE;
750    return wd->am_pm;
751 }
752
753 /**
754  * Set if the clock shows hour with the seconds
755  *
756  * @param obj The clock object
757  * @param seconds Bool option for the show seconds
758  * (1 = show seconds, 0 = not show seconds)
759  *
760  * This function sets the clock to show or not to show the elapsed
761  * seconds.
762  *
763  * @ingroup Clock
764  */
765 EAPI void
766 elm_clock_show_seconds_set(Evas_Object *obj, Eina_Bool seconds)
767 {
768    ELM_CHECK_WIDTYPE(obj, widtype);
769    Widget_Data *wd = elm_widget_data_get(obj);
770    if (!wd) return;
771    wd->seconds = seconds;
772    _time_update(obj);
773 }
774
775 /**
776  * Get if the clock shows hour with the seconds
777  *
778  * @param obj The clock object
779  * @return Bool option for the show seconds
780  * (1 = show seconds, 0 = not show seconds)
781  *
782  * This function gets if the clock show or not show the elapsed
783  * seconds.
784  *
785  * @ingroup Clock
786  */
787 EAPI Eina_Bool
788 elm_clock_show_seconds_get(const Evas_Object *obj)
789 {
790    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
791    Widget_Data *wd = elm_widget_data_get(obj);
792    if (!wd) return EINA_FALSE;
793    return wd->seconds;
794 }
795
796 /**
797  * Set the interval for the clock
798  *
799  * @param obj The clock object
800  * @param interval The interval value in seconds
801  *
802  * The interval value is decreased while the user increments or decrements
803  * the clock value. The next interval value is the previous interval / 1.05,
804  * so it speed up a bit. Default value is 0.85 seconds.
805  *
806  * @ingroup Clock
807  */
808 EAPI void
809 elm_clock_interval_set(Evas_Object *obj, double interval)
810 {
811    ELM_CHECK_WIDTYPE(obj, widtype);
812    Widget_Data *wd = elm_widget_data_get(obj);
813    if (!wd) return;
814    wd->first_interval = interval;
815 }
816
817 /**
818  * Get the interval of the clock
819  *
820  * @param obj The clock object
821  * @return The value of the first interval in seconds
822  *
823  * The interval value is decreased while the user increments or decrements
824  * the clock value. The next interval value is the previous interval / 1.05,
825  * so it speed up a bit. Default value is 0.85 seconds.
826  *
827  * @ingroup Clock
828  */
829 EAPI double
830 elm_clock_interval_get(const Evas_Object *obj)
831 {
832    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
833    Widget_Data *wd = elm_widget_data_get(obj);
834    if (!wd) return 0.0;
835    return wd->first_interval;
836 }