1 #include <Elementary.h>
6 #define DEFAULT_FIRST_INTERVAL 0.85
7 >>>>>>> remotes/origin/upstream
8 typedef struct _Widget_Data Widget_Data;
13 double interval, first_interval;
14 Eina_Bool seconds : 1;
18 Elm_Clock_Digedit digedit;
20 Elm_Clock_Edit_Mode digedit;
21 >>>>>>> remotes/origin/upstream
22 int hrs, min, sec, timediff;
23 Evas_Object *digit[6];
26 Ecore_Timer *ticker, *spin;
31 Eina_Bool seconds : 1;
35 Elm_Clock_Digedit digedit;
37 Elm_Clock_Edit_Mode digedit;
38 >>>>>>> remotes/origin/upstream
42 static const char *widtype = NULL;
43 static void _del_hook(Evas_Object *obj);
44 static void _theme_hook(Evas_Object *obj);
45 static void _on_focus_hook(void *data, Evas_Object *obj);
46 static Eina_Bool _ticker(void *data);
47 static Eina_Bool _signal_clock_val_up(void *data);
48 static Eina_Bool _signal_clock_val_down(void *data);
49 static void _time_update(Evas_Object *obj);
51 static const char SIG_CHANGED[] = "changed";
53 static const Evas_Smart_Cb_Description _signals[] = {
60 _del_hook(Evas_Object *obj)
62 Widget_Data *wd = elm_widget_data_get(obj);
65 for (i = 0; i < 6; i++)
67 if (wd->digit[i]) evas_object_del(wd->digit[i]);
69 if (wd->ampm) evas_object_del(wd->ampm);
70 if (wd->ticker) ecore_timer_del(wd->ticker);
71 if (wd->spin) ecore_timer_del(wd->spin);
76 _theme_hook(Evas_Object *obj)
78 Widget_Data *wd = elm_widget_data_get(obj);
80 if (elm_widget_focus_get(obj))
81 edje_object_signal_emit(wd->clk, "elm,action,focus", "elm");
83 edje_object_signal_emit(wd->clk, "elm,action,unfocus", "elm");
84 wd->cur.am_pm = !wd->cur.am_pm; /* hack - force update */
89 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
91 Widget_Data *wd = elm_widget_data_get(obj);
93 if (elm_widget_focus_get(obj))
95 edje_object_signal_emit(wd->clk, "elm,action,focus", "elm");
96 evas_object_focus_set(wd->clk, EINA_TRUE);
100 edje_object_signal_emit(wd->clk, "elm,action,unfocus", "elm");
101 evas_object_focus_set(wd->clk, EINA_FALSE);
106 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
108 Widget_Data *wd = elm_widget_data_get(obj);
111 edje_object_signal_emit(wd->clk, emission, source);
112 for (i = 0; i < 6; i++)
115 edje_object_signal_emit(wd->digit[i], emission, source);
120 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
122 Widget_Data *wd = elm_widget_data_get(obj);
125 edje_object_signal_callback_add(wd->clk, emission, source, func_cb, data);
126 for (i = 0; i < 6; i++)
129 edje_object_signal_callback_add(wd->digit[i], emission, source,
135 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
137 Widget_Data *wd = elm_widget_data_get(obj);
139 for (i = 0; i < 6; i++)
141 edje_object_signal_callback_del_full(wd->digit[i], emission, source,
144 edje_object_signal_callback_del_full(wd->clk, emission, source, func_cb,
149 _timediff_set(Widget_Data *wd)
151 struct timeval timev;
154 gettimeofday(&timev, NULL);
155 tt = (time_t)(timev.tv_sec);
158 wd->timediff = (((wd->hrs - tm->tm_hour) * 60 +
159 wd->min - tm->tm_min) * 60) + wd->sec - tm->tm_sec;
165 Widget_Data *wd = elm_widget_data_get(data);
167 struct timeval timev;
170 if (!wd) return ECORE_CALLBACK_CANCEL;
171 gettimeofday(&timev, NULL);
172 t = ((double)(1000000 - timev.tv_usec)) / 1000000.0;
173 wd->ticker = ecore_timer_add(t, _ticker, data);
176 tt = (time_t)(timev.tv_sec) + wd->timediff;
181 wd->hrs = tm->tm_hour;
182 wd->min = tm->tm_min;
183 wd->sec = tm->tm_sec;
187 return ECORE_CALLBACK_CANCEL;
191 _signal_clock_val_up(void *data)
193 Widget_Data *wd = elm_widget_data_get(data);
194 if (!wd) goto clock_val_up_exit_on_error;
195 if (!wd->edit) goto clock_val_up_cancel;
196 if (!wd->sel_obj) goto clock_val_up_cancel;
197 if (wd->sel_obj == wd->digit[0])
199 wd->hrs = wd->hrs + 10;
200 if (wd->hrs >= 24) wd->hrs -= 24;
202 if (wd->sel_obj == wd->digit[1])
204 wd->hrs = wd->hrs + 1;
205 if (wd->hrs >= 24) wd->hrs -= 24;
207 if (wd->sel_obj == wd->digit[2])
209 wd->min = wd->min + 10;
210 if (wd->min >= 60) wd->min -= 60;
212 if (wd->sel_obj == wd->digit[3])
214 wd->min = wd->min + 1;
215 if (wd->min >= 60) wd->min -= 60;
217 if (wd->sel_obj == wd->digit[4])
219 wd->sec = wd->sec + 10;
220 if (wd->sec >= 60) wd->sec -= 60;
222 if (wd->sel_obj == wd->digit[5])
224 wd->sec = wd->sec + 1;
225 if (wd->sec >= 60) wd->sec -= 60;
227 if (wd->sel_obj == wd->ampm)
229 wd->hrs = wd->hrs + 12;
230 if (wd->hrs > 23) wd->hrs -= 24;
232 wd->interval = wd->interval / 1.05;
233 ecore_timer_interval_set(wd->spin, wd->interval);
235 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
236 return ECORE_CALLBACK_RENEW;
239 clock_val_up_exit_on_error:
240 return ECORE_CALLBACK_CANCEL;
244 _signal_clock_val_down(void *data)
246 Widget_Data *wd = elm_widget_data_get(data);
247 if (!wd) goto clock_val_down_exit_on_error;
248 if (!wd->edit) goto clock_val_down_cancel;
249 if (!wd->sel_obj) goto clock_val_down_cancel;
250 if (wd->sel_obj == wd->digit[0])
252 wd->hrs = wd->hrs - 10;
253 if (wd->hrs < 0) wd->hrs += 24;
255 if (wd->sel_obj == wd->digit[1])
257 wd->hrs = wd->hrs - 1;
258 if (wd->hrs < 0) wd->hrs += 24;
260 if (wd->sel_obj == wd->digit[2])
262 wd->min = wd->min - 10;
263 if (wd->min < 0) wd->min += 60;
265 if (wd->sel_obj == wd->digit[3])
267 wd->min = wd->min - 1;
268 if (wd->min < 0) wd->min += 60;
270 if (wd->sel_obj == wd->digit[4])
272 wd->sec = wd->sec - 10;
273 if (wd->sec < 0) wd->sec += 60;
275 if (wd->sel_obj == wd->digit[5])
277 wd->sec = wd->sec - 1;
278 if (wd->sec < 0) wd->sec += 60;
280 if (wd->sel_obj == wd->ampm)
282 wd->hrs = wd->hrs - 12;
283 if (wd->hrs < 0) wd->hrs += 24;
285 wd->interval = wd->interval / 1.05;
286 ecore_timer_interval_set(wd->spin, wd->interval);
288 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
289 return ECORE_CALLBACK_RENEW;
290 clock_val_down_cancel:
292 clock_val_down_exit_on_error:
293 return ECORE_CALLBACK_CANCEL;
297 _signal_clock_val_up_start(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
299 Widget_Data *wd = elm_widget_data_get(data);
301 wd->interval = wd->first_interval;
303 if (wd->spin) ecore_timer_del(wd->spin);
304 wd->spin = ecore_timer_add(wd->interval, _signal_clock_val_up, data);
305 _signal_clock_val_up(data);
309 _signal_clock_val_down_start(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
311 Widget_Data *wd = elm_widget_data_get(data);
313 wd->interval = wd->first_interval;
315 if (wd->spin) ecore_timer_del(wd->spin);
316 wd->spin = ecore_timer_add(wd->interval, _signal_clock_val_down, data);
317 _signal_clock_val_down(data);
321 _signal_clock_val_change_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
323 Widget_Data *wd = elm_widget_data_get(data);
325 if (wd->spin) ecore_timer_del(wd->spin);
331 _time_update(Evas_Object *obj)
333 Widget_Data *wd = elm_widget_data_get(obj);
334 Edje_Message_Int msg;
336 const char *style = elm_widget_style_get(obj);
338 if ((wd->cur.seconds != wd->seconds) || (wd->cur.am_pm != wd->am_pm) ||
339 (wd->cur.edit != wd->edit) || (wd->cur.digedit != wd->digedit))
344 for (i = 0; i < 6; i++)
348 evas_object_del(wd->digit[i]);
354 evas_object_del(wd->ampm);
358 if ((wd->seconds) && (wd->am_pm))
359 _elm_theme_object_set(obj, wd->clk, "clock", "base-all", style);
360 else if (wd->seconds)
361 _elm_theme_object_set(obj, wd->clk, "clock", "base-seconds", style);
363 _elm_theme_object_set(obj, wd->clk, "clock", "base-am_pm", style);
365 _elm_theme_object_set(obj, wd->clk, "clock", "base", style);
366 edje_object_scale_set(wd->clk, elm_widget_scale_get(obj) *
369 for (i = 0; i < 6; i++)
373 if ((!wd->seconds) && (i >= 4)) break;
374 wd->digit[i] = edje_object_add(evas_object_evas_get(wd->clk));
375 _elm_theme_object_set(obj, wd->digit[i], "clock", "flipdigit", style);
376 edje_object_scale_set(wd->digit[i], elm_widget_scale_get(obj) *
378 if ((wd->edit) && (wd->digedit & (1 << i)))
379 edje_object_signal_emit(wd->digit[i], "elm,state,edit,on", "elm");
380 edje_object_signal_callback_add(wd->digit[i], "elm,action,up,start",
381 "", _signal_clock_val_up_start, obj);
382 edje_object_signal_callback_add(wd->digit[i], "elm,action,up,stop",
383 "", _signal_clock_val_change_stop, obj);
384 edje_object_signal_callback_add(wd->digit[i], "elm,action,down,start",
385 "", _signal_clock_val_down_start, obj);
386 edje_object_signal_callback_add(wd->digit[i], "elm,action,down,stop",
387 "", _signal_clock_val_change_stop, obj);
389 elm_coords_finger_size_adjust(1, &mw, 2, &mh);
390 edje_object_size_min_restricted_calc(wd->digit[i], &mw, &mh, mw, mh);
391 elm_coords_finger_size_adjust(1, &mw, 2, &mh);
392 edje_extern_object_min_size_set(wd->digit[i], mw, mh);
393 snprintf(buf, sizeof(buf), "d%i", i);
394 edje_object_part_swallow(wd->clk , buf, wd->digit[i]);
395 evas_object_show(wd->digit[i]);
399 wd->ampm = edje_object_add(evas_object_evas_get(wd->clk));
400 _elm_theme_object_set(obj, wd->ampm, "clock", "flipampm", style);
401 edje_object_scale_set(wd->ampm, elm_widget_scale_get(obj) *
404 edje_object_signal_emit(wd->ampm, "elm,state,edit,on", "elm");
405 edje_object_signal_callback_add(wd->ampm, "elm,action,up,start",
406 "", _signal_clock_val_up_start, obj);
407 edje_object_signal_callback_add(wd->ampm, "elm,action,up,stop",
408 "", _signal_clock_val_change_stop, obj);
409 edje_object_signal_callback_add(wd->ampm, "elm,action,down,start",
410 "", _signal_clock_val_down_start, obj);
411 edje_object_signal_callback_add(wd->ampm, "elm,action,down,stop",
412 "", _signal_clock_val_change_stop, obj);
414 elm_coords_finger_size_adjust(1, &mw, 2, &mh);
415 edje_object_size_min_restricted_calc(wd->ampm, &mw, &mh, mw, mh);
416 elm_coords_finger_size_adjust(1, &mw, 2, &mh);
417 edje_extern_object_min_size_set(wd->ampm, mw, mh);
418 edje_object_part_swallow(wd->clk , "ampm", wd->ampm);
419 evas_object_show(wd->ampm);
422 edje_object_size_min_calc(wd->clk, &mw, &mh);
423 evas_object_size_hint_min_set(obj, mw, mh);
429 wd->cur.seconds = wd->seconds;
430 wd->cur.am_pm = wd->am_pm;
431 wd->cur.edit = wd->edit;
432 wd->cur.digedit = wd->digedit;
434 if (wd->hrs != wd->cur.hrs)
437 int d1, d2, dc1, dc2;
444 if (hrs > 12) hrs -= 12;
447 else if (!hrs) hrs = 12;
451 dc1 = wd->cur.hrs / 10;
452 dc2 = wd->cur.hrs % 10;
456 edje_object_message_send(wd->digit[0], EDJE_MESSAGE_INT, 1, &msg);
461 edje_object_message_send(wd->digit[1], EDJE_MESSAGE_INT, 1, &msg);
465 if (wd->min != wd->cur.min)
467 int d1, d2, dc1, dc2;
471 dc1 = wd->cur.min / 10;
472 dc2 = wd->cur.min % 10;
476 edje_object_message_send(wd->digit[2], EDJE_MESSAGE_INT, 1, &msg);
481 edje_object_message_send(wd->digit[3], EDJE_MESSAGE_INT, 1, &msg);
483 wd->cur.min = wd->min;
487 if (wd->sec != wd->cur.sec)
489 int d1, d2, dc1, dc2;
493 dc1 = wd->cur.sec / 10;
494 dc2 = wd->cur.sec % 10;
498 edje_object_message_send(wd->digit[4], EDJE_MESSAGE_INT, 1, &msg);
503 edje_object_message_send(wd->digit[5], EDJE_MESSAGE_INT, 1, &msg);
505 wd->cur.sec = wd->sec;
513 if (wd->hrs >= 12) ampm = 1;
514 if (ampm != wd->cur.ampm)
516 if (wd->cur.ampm != ampm)
519 edje_object_message_send(wd->ampm, EDJE_MESSAGE_INT, 1, &msg);
529 elm_clock_add(Evas_Object *parent)
535 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
537 ELM_SET_WIDTYPE(widtype, "clock");
538 elm_widget_type_set(obj, "clock");
539 elm_widget_sub_object_add(parent, obj);
540 elm_widget_data_set(obj, wd);
541 elm_widget_del_hook_set(obj, _del_hook);
542 elm_widget_theme_hook_set(obj, _theme_hook);
543 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
544 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
545 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
546 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
547 elm_widget_can_focus_set(obj, EINA_TRUE);
549 wd->clk = edje_object_add(e);
550 elm_widget_resize_object_set(obj, wd->clk);
553 wd->cur.seconds = EINA_TRUE;
554 wd->cur.am_pm = EINA_TRUE;
555 wd->cur.edit = EINA_TRUE;
557 wd->cur.digedit = ELM_CLOCK_NONE;
558 wd->first_interval = 0.85;
560 wd->cur.digedit = ELM_CLOCK_EDIT_DEFAULT;
561 wd->first_interval = DEFAULT_FIRST_INTERVAL;
562 >>>>>>> remotes/origin/upstream
568 evas_object_smart_callbacks_descriptions_set(obj, _signals);
574 elm_clock_time_set(Evas_Object *obj, int hrs, int min, int sec)
576 ELM_CHECK_WIDTYPE(obj, widtype);
577 Widget_Data *wd = elm_widget_data_get(obj);
587 elm_clock_time_get(const Evas_Object *obj, int *hrs, int *min, int *sec)
589 ELM_CHECK_WIDTYPE(obj, widtype);
590 Widget_Data *wd = elm_widget_data_get(obj);
592 if (hrs) *hrs = wd->hrs;
593 if (min) *min = wd->min;
594 if (sec) *sec = wd->sec;
598 elm_clock_edit_set(Evas_Object *obj, Eina_Bool edit)
600 ELM_CHECK_WIDTYPE(obj, widtype);
601 Widget_Data *wd = elm_widget_data_get(obj);
607 if ((edit) && (wd->digedit == ELM_CLOCK_NONE))
608 elm_clock_digit_edit_set(obj, ELM_CLOCK_ALL);
610 if ((edit) && (wd->digedit == ELM_CLOCK_EDIT_DEFAULT))
611 elm_clock_edit_mode_set(obj, ELM_CLOCK_EDIT_ALL);
612 >>>>>>> remotes/origin/upstream
618 elm_clock_edit_get(const Evas_Object *obj)
620 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
621 Widget_Data *wd = elm_widget_data_get(obj);
622 if (!wd) return EINA_FALSE;
628 elm_clock_digit_edit_set(Evas_Object *obj, Elm_Clock_Digedit digedit)
630 elm_clock_edit_mode_set(Evas_Object *obj, Elm_Clock_Edit_Mode digedit)
631 >>>>>>> remotes/origin/upstream
633 ELM_CHECK_WIDTYPE(obj, widtype);
634 Widget_Data *wd = elm_widget_data_get(obj);
636 wd->digedit = digedit;
638 if (digedit == ELM_CLOCK_NONE)
640 if (digedit == ELM_CLOCK_EDIT_DEFAULT)
641 >>>>>>> remotes/origin/upstream
642 elm_clock_edit_set(obj, EINA_FALSE);
648 EAPI Elm_Clock_Digedit
649 elm_clock_digit_edit_get(const Evas_Object *obj)
651 EAPI Elm_Clock_Edit_Mode
652 elm_clock_edit_mode_get(const Evas_Object *obj)
653 >>>>>>> remotes/origin/upstream
655 ELM_CHECK_WIDTYPE(obj, widtype) 0;
656 Widget_Data *wd = elm_widget_data_get(obj);
662 elm_clock_show_am_pm_set(Evas_Object *obj, Eina_Bool am_pm)
664 ELM_CHECK_WIDTYPE(obj, widtype);
665 Widget_Data *wd = elm_widget_data_get(obj);
671 >>>>>>> remotes/origin/upstream
676 elm_clock_show_am_pm_get(const Evas_Object *obj)
678 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
679 Widget_Data *wd = elm_widget_data_get(obj);
680 if (!wd) return EINA_FALSE;
685 elm_clock_show_seconds_set(Evas_Object *obj, Eina_Bool seconds)
687 ELM_CHECK_WIDTYPE(obj, widtype);
688 Widget_Data *wd = elm_widget_data_get(obj);
691 wd->seconds = seconds;
693 wd->seconds = !!seconds;
694 >>>>>>> remotes/origin/upstream
699 elm_clock_show_seconds_get(const Evas_Object *obj)
701 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
702 Widget_Data *wd = elm_widget_data_get(obj);
703 if (!wd) return EINA_FALSE;
709 elm_clock_interval_set(Evas_Object *obj, double interval)
711 elm_clock_first_interval_set(Evas_Object *obj, double interval)
712 >>>>>>> remotes/origin/upstream
714 ELM_CHECK_WIDTYPE(obj, widtype);
715 Widget_Data *wd = elm_widget_data_get(obj);
718 wd->first_interval = interval;
722 elm_clock_interval_get(const Evas_Object *obj)
724 wd->first_interval = !!interval;
728 elm_clock_first_interval_get(const Evas_Object *obj)
729 >>>>>>> remotes/origin/upstream
731 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
732 Widget_Data *wd = elm_widget_data_get(obj);
734 return wd->first_interval;