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