summaryrefslogtreecommitdiff
path: root/src/lib/elementary/elm_clock.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-03-23 12:56:14 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-03-23 13:24:41 -0700
commitc2a1c49ab2042f559b28e840e54feb8494888e0e (patch)
treec6eb110b7c479499854eede9d0c3ab0a80c9a11a /src/lib/elementary/elm_clock.c
parent9340855597e7e465435c69b6278650346688da14 (diff)
elementary: move all legacy files to their expected new location.
Diffstat (limited to 'src/lib/elementary/elm_clock.c')
-rw-r--r--src/lib/elementary/elm_clock.c960
1 files changed, 960 insertions, 0 deletions
diff --git a/src/lib/elementary/elm_clock.c b/src/lib/elementary/elm_clock.c
new file mode 100644
index 0000000..a5f8a0b
--- /dev/null
+++ b/src/lib/elementary/elm_clock.c
@@ -0,0 +1,960 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
6
7#include <Elementary.h>
8#include "elm_priv.h"
9#include "elm_widget_clock.h"
10
11#define MY_CLASS ELM_CLOCK_CLASS
12
13#define MY_CLASS_NAME "Elm_Clock"
14#define MY_CLASS_NAME_LEGACY "elm_clock"
15
16#define DEFAULT_FIRST_INTERVAL 0.85
17static void _time_update(Evas_Object *obj, Eina_Bool theme_update);
18
19static const char SIG_CHANGED[] = "changed";
20
21static const Evas_Smart_Cb_Description _smart_callbacks[] = {
22 {SIG_CHANGED, ""},
23 {SIG_WIDGET_LANG_CHANGED, ""}, /**< handled by elm_widget */
24 {SIG_WIDGET_ACCESS_CHANGED, ""}, /**< handled by elm_widget */
25 {SIG_LAYOUT_FOCUSED, ""}, /**< handled by elm_layout */
26 {SIG_LAYOUT_UNFOCUSED, ""}, /**< handled by elm_layout */
27 {NULL, NULL}
28};
29
30static Eina_Bool
31_on_clock_val_up(void *data)
32{
33 ELM_CLOCK_DATA_GET(data, sd);
34
35 if (!sd->edit) goto clock_val_up_cancel;
36 if (!sd->sel_obj) goto clock_val_up_cancel;
37 if (sd->sel_obj == sd->digit[0])
38 {
39 sd->hrs = sd->hrs + 12;
40 if (sd->hrs >= 24) sd->hrs -= 24;
41 }
42 if (sd->sel_obj == sd->digit[1])
43 {
44 sd->hrs = sd->hrs + 1;
45 if (sd->hrs >= 24) sd->hrs -= 24;
46 }
47 if (sd->sel_obj == sd->digit[2])
48 {
49 sd->min = sd->min + 10;
50 if (sd->min >= 60) sd->min -= 60;
51 }
52 if (sd->sel_obj == sd->digit[3])
53 {
54 sd->min = sd->min + 1;
55 if (sd->min >= 60) sd->min -= 60;
56 }
57 if (sd->sel_obj == sd->digit[4])
58 {
59 sd->sec = sd->sec + 10;
60 if (sd->sec >= 60) sd->sec -= 60;
61 }
62 if (sd->sel_obj == sd->digit[5])
63 {
64 sd->sec = sd->sec + 1;
65 if (sd->sec >= 60) sd->sec -= 60;
66 }
67 if (sd->sel_obj == sd->am_pm_obj)
68 {
69 sd->hrs = sd->hrs + 12;
70 if (sd->hrs > 23) sd->hrs -= 24;
71 }
72
73 sd->interval = sd->interval / 1.05;
74 ecore_timer_interval_set(sd->spin, sd->interval);
75 _time_update(data, EINA_FALSE);
76 eo_event_callback_call(data, ELM_CLOCK_EVENT_CHANGED, NULL);
77 return ECORE_CALLBACK_RENEW;
78
79clock_val_up_cancel:
80
81 sd->spin = NULL;
82
83 return ECORE_CALLBACK_CANCEL;
84}
85
86static Eina_Bool
87_on_clock_val_down(void *data)
88{
89 ELM_CLOCK_DATA_GET(data, sd);
90
91 if (!sd->edit) goto clock_val_down_cancel;
92 if (!sd->sel_obj) goto clock_val_down_cancel;
93 if (sd->sel_obj == sd->digit[0])
94 {
95 sd->hrs = sd->hrs - 12;
96 if (sd->hrs < 0) sd->hrs += 24;
97 }
98 if (sd->sel_obj == sd->digit[1])
99 {
100 sd->hrs = sd->hrs - 1;
101 if (sd->hrs < 0) sd->hrs += 24;
102 }
103 if (sd->sel_obj == sd->digit[2])
104 {
105 sd->min = sd->min - 10;
106 if (sd->min < 0) sd->min += 60;
107 }
108 if (sd->sel_obj == sd->digit[3])
109 {
110 sd->min = sd->min - 1;
111 if (sd->min < 0) sd->min += 60;
112 }
113 if (sd->sel_obj == sd->digit[4])
114 {
115 sd->sec = sd->sec - 10;
116 if (sd->sec < 0) sd->sec += 60;
117 }
118 if (sd->sel_obj == sd->digit[5])
119 {
120 sd->sec = sd->sec - 1;
121 if (sd->sec < 0) sd->sec += 60;
122 }
123 if (sd->sel_obj == sd->am_pm_obj)
124 {
125 sd->hrs = sd->hrs - 12;
126 if (sd->hrs < 0) sd->hrs += 24;
127 }
128 sd->interval = sd->interval / 1.05;
129 ecore_timer_interval_set(sd->spin, sd->interval);
130 _time_update(data, EINA_FALSE);
131 eo_event_callback_call(data, ELM_CLOCK_EVENT_CHANGED, NULL);
132 return ECORE_CALLBACK_RENEW;
133
134clock_val_down_cancel:
135 sd->spin = NULL;
136
137 return ECORE_CALLBACK_CANCEL;
138}
139
140static void
141_on_clock_val_up_start(void *data,
142 Evas_Object *obj,
143 const char *emission EINA_UNUSED,
144 const char *source EINA_UNUSED)
145{
146 ELM_CLOCK_DATA_GET(data, sd);
147
148 sd->interval = sd->first_interval;
149 sd->sel_obj = obj;
150 ecore_timer_del(sd->spin);
151 sd->spin = ecore_timer_add(sd->interval, _on_clock_val_up, data);
152
153 _on_clock_val_up(data);
154}
155
156static void
157_on_clock_val_down_start(void *data,
158 Evas_Object *obj,
159 const char *emission EINA_UNUSED,
160 const char *source EINA_UNUSED)
161{
162 ELM_CLOCK_DATA_GET(data, sd);
163
164 sd->interval = sd->first_interval;
165 sd->sel_obj = obj;
166 ecore_timer_del(sd->spin);
167 sd->spin = ecore_timer_add(sd->interval, _on_clock_val_down, data);
168
169 _on_clock_val_down(data);
170}
171
172static void
173_on_clock_val_change_stop(void *data,
174 Evas_Object *obj EINA_UNUSED,
175 const char *emission EINA_UNUSED,
176 const char *source EINA_UNUSED)
177{
178 ELM_CLOCK_DATA_GET(data, sd);
179
180 ELM_SAFE_FREE(sd->spin, ecore_timer_del);
181 sd->sel_obj = NULL;
182}
183
184static void
185_access_activate_cb(void *data,
186 Evas_Object *part_obj,
187 Elm_Object_Item *item EINA_UNUSED)
188{
189 Evas_Object *digit, *inc_btn;
190 ELM_CLOCK_DATA_GET(data, sd);
191
192 digit = evas_object_smart_parent_get(part_obj);
193 if (!digit) return;
194
195 inc_btn = (Evas_Object *)edje_object_part_object_get(digit, "access.t");
196
197 if (part_obj != inc_btn)
198 _on_clock_val_down_start(data, digit, NULL, NULL);
199 else
200 _on_clock_val_up_start(data, digit, NULL, NULL);
201
202 _on_clock_val_change_stop(sd, NULL, NULL, NULL);
203}
204
205static void
206_access_time_register(Evas_Object *obj, Eina_Bool is_access)
207{
208 Evas_Object *ao, *po;
209
210 ELM_CLOCK_DATA_GET(obj, sd);
211
212 if (!sd->edit) return;
213
214 /* hour, min, sec edit button */
215 int i;
216 for (i = 0; i < 6; i++)
217 {
218 if (is_access && (sd->digedit & (1 << i)))
219 {
220 char *digit = NULL;
221
222 switch (1 << i)
223 {
224 case ELM_CLOCK_EDIT_HOUR_DECIMAL:
225 digit = "hour decimal";
226 break;
227 case ELM_CLOCK_EDIT_HOUR_UNIT:
228 digit = "hour unit";
229 break;
230 case ELM_CLOCK_EDIT_MIN_DECIMAL:
231 digit = "minute decimal";
232 break;
233 case ELM_CLOCK_EDIT_MIN_UNIT:
234 digit = "minute unit";
235 break;
236 case ELM_CLOCK_EDIT_SEC_DECIMAL:
237 digit = "second decimal";
238 break;
239 case ELM_CLOCK_EDIT_SEC_UNIT:
240 digit = "second unit";
241 break;
242 }
243
244 Eina_Strbuf *strbuf;
245 strbuf = eina_strbuf_new();
246
247 /* increment button */
248 ao = _elm_access_edje_object_part_object_register
249 (obj, sd->digit[i], "access.t");
250
251 eina_strbuf_append_printf(strbuf,
252 "clock increment button for %s", digit);
253 _elm_access_text_set(_elm_access_info_get(ao),
254 ELM_ACCESS_TYPE, eina_strbuf_string_get(strbuf));
255 _elm_access_activate_callback_set
256 (_elm_access_info_get(ao), _access_activate_cb, obj);
257
258 /* decrement button */
259 ao = _elm_access_edje_object_part_object_register
260 (obj, sd->digit[i], "access.b");
261
262 eina_strbuf_replace(strbuf, "increment", "decrement", 1);
263 _elm_access_text_set(_elm_access_info_get(ao),
264 ELM_ACCESS_TYPE, eina_strbuf_string_get(strbuf));
265 _elm_access_activate_callback_set
266 (_elm_access_info_get(ao), _access_activate_cb, obj);
267
268 eina_strbuf_free(strbuf);
269
270 edje_object_signal_emit
271 (sd->digit[i], "elm,state,access,edit,on", "elm");
272 }
273 else if (!is_access && (sd->digedit & (1 << i)))
274 {
275 _elm_access_edje_object_part_object_unregister
276 (obj, sd->digit[i], "access.t");
277
278 _elm_access_edje_object_part_object_unregister
279 (obj, sd->digit[i], "access.b");
280
281 edje_object_signal_emit
282 (sd->digit[i], "elm,state,access,edit,off", "elm");
283 }
284
285 /* no need to propagate mouse event with acess */
286 po = (Evas_Object *)edje_object_part_object_get
287 (sd->digit[i], "access.t");
288 evas_object_propagate_events_set(po, !is_access);
289
290 po = (Evas_Object *)edje_object_part_object_get
291 (sd->digit[i], "access.b");
292 evas_object_propagate_events_set(po, !is_access);
293
294 }
295
296 /* am, pm edit button */
297 if (is_access && sd->am_pm)
298 {
299 /* increment button */
300 ao = _elm_access_edje_object_part_object_register
301 (obj, sd->am_pm_obj, "access.t");
302 _elm_access_text_set(_elm_access_info_get(ao),
303 ELM_ACCESS_TYPE, E_("clock increment button for am,pm"));
304 _elm_access_activate_callback_set
305 (_elm_access_info_get(ao), _access_activate_cb, obj);
306
307 /* decrement button */
308 ao = _elm_access_edje_object_part_object_register
309 (obj, sd->am_pm_obj, "access.b");
310 _elm_access_text_set(_elm_access_info_get(ao),
311 ELM_ACCESS_TYPE, E_("clock decrement button for am,pm"));
312 _elm_access_activate_callback_set
313 (_elm_access_info_get(ao), _access_activate_cb, obj);
314
315 edje_object_signal_emit
316 (sd->am_pm_obj, "elm,state,access,edit,on", "elm");
317 }
318 else if (!is_access && sd->am_pm)
319 {
320 _elm_access_edje_object_part_object_register
321 (obj, sd->am_pm_obj, "access.t");
322
323 _elm_access_edje_object_part_object_register
324 (obj, sd->am_pm_obj, "access.b");
325
326 edje_object_signal_emit
327 (sd->am_pm_obj, "elm,state,access,edit,off", "elm");
328 }
329
330 /* no need to propagate mouse event with access */
331 po = (Evas_Object *)edje_object_part_object_get
332 (sd->am_pm_obj, "access.t");
333 evas_object_propagate_events_set(po, !is_access);
334
335 po = (Evas_Object *)edje_object_part_object_get
336 (sd->am_pm_obj, "access.b");
337 evas_object_propagate_events_set(po, !is_access);
338
339}
340
341static void
342_time_update(Evas_Object *obj, Eina_Bool theme_update)
343{
344 ELM_CLOCK_DATA_GET(obj, sd);
345 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
346
347 Edje_Message_Int msg;
348 const char *style = elm_widget_style_get(obj);
349
350 if ((sd->cur.seconds != sd->seconds) || (sd->cur.am_pm != sd->am_pm) ||
351 (sd->cur.edit != sd->edit) || (sd->cur.digedit != sd->digedit) || theme_update)
352 {
353 int i;
354 Evas_Coord mw, mh;
355
356 for (i = 0; i < 6; i++)
357 ELM_SAFE_FREE(sd->digit[i], evas_object_del);
358 ELM_SAFE_FREE(sd->am_pm_obj, evas_object_del);
359
360 if ((sd->seconds) && (sd->am_pm))
361 {
362 if (!elm_layout_theme_set(obj, "clock", "base-all", style))
363 CRI("Failed to set layout!");
364 }
365 else if (sd->seconds)
366 {
367 if (!elm_layout_theme_set(obj, "clock", "base-seconds", style))
368 CRI("Failed to set layout!");
369 }
370 else if (sd->am_pm)
371 {
372 if (!elm_layout_theme_set(obj, "clock", "base-am_pm", style))
373 CRI("Failed to set layout!");
374 }
375 else
376 {
377 if (!elm_layout_theme_set(obj, "clock", "base", style))
378 CRI("Failed to set layout!");
379 }
380
381 edje_object_scale_set
382 (wd->resize_obj, elm_widget_scale_get(obj) *
383 elm_config_scale_get());
384
385 for (i = 0; i < 6; i++)
386 {
387 char buf[16];
388
389 if ((!sd->seconds) && (i >= 4)) break;
390 sd->digit[i] = edje_object_add
391 (evas_object_evas_get(wd->resize_obj));
392 elm_widget_theme_object_set
393 (obj, sd->digit[i], "clock", "flipdigit", style);
394 edje_object_scale_set
395 (sd->digit[i], elm_widget_scale_get(obj) *
396 elm_config_scale_get());
397
398 if ((sd->edit) && (sd->digedit & (1 << i)))
399 edje_object_signal_emit
400 (sd->digit[i], "elm,state,edit,on", "elm");
401 edje_object_signal_callback_add
402 (sd->digit[i], "elm,action,up,start", "*",
403 _on_clock_val_up_start, obj);
404 edje_object_signal_callback_add
405 (sd->digit[i], "elm,action,up,stop", "*",
406 _on_clock_val_change_stop, obj);
407 edje_object_signal_callback_add
408 (sd->digit[i], "elm,action,down,start", "*",
409 _on_clock_val_down_start, obj);
410 edje_object_signal_callback_add
411 (sd->digit[i], "elm,action,down,stop", "*",
412 _on_clock_val_change_stop, obj);
413
414 mw = mh = -1;
415 elm_coords_finger_size_adjust(1, &mw, 2, &mh);
416 edje_object_size_min_restricted_calc
417 (sd->digit[i], &mw, &mh, mw, mh);
418 evas_object_size_hint_min_set(sd->digit[i], mw, mh);
419 snprintf(buf, sizeof(buf), "d%i", i);
420 elm_layout_content_set(obj, buf, sd->digit[i]);
421 evas_object_show(sd->digit[i]);
422 }
423 if (sd->am_pm)
424 {
425 sd->am_pm_obj =
426 edje_object_add(evas_object_evas_get(wd->resize_obj));
427 elm_widget_theme_object_set
428 (obj, sd->am_pm_obj, "clock", "flipampm", style);
429 edje_object_scale_set(sd->am_pm_obj, elm_widget_scale_get(obj) *
430 _elm_config->scale);
431 if (sd->edit)
432 edje_object_signal_emit
433 (sd->am_pm_obj, "elm,state,edit,on", "elm");
434 edje_object_signal_callback_add
435 (sd->am_pm_obj, "elm,action,up,start", "*",
436 _on_clock_val_up_start, obj);
437 edje_object_signal_callback_add
438 (sd->am_pm_obj, "elm,action,up,stop", "*",
439 _on_clock_val_change_stop, obj);
440 edje_object_signal_callback_add
441 (sd->am_pm_obj, "elm,action,down,start", "*",
442 _on_clock_val_down_start, obj);
443 edje_object_signal_callback_add
444 (sd->am_pm_obj, "elm,action,down,stop", "*",
445 _on_clock_val_change_stop, obj);
446
447 mw = mh = -1;
448 elm_coords_finger_size_adjust(1, &mw, 2, &mh);
449 edje_object_size_min_restricted_calc
450 (sd->am_pm_obj, &mw, &mh, mw, mh);
451 evas_object_size_hint_min_set(sd->am_pm_obj, mw, mh);
452 elm_layout_content_set(obj, "ampm", sd->am_pm_obj);
453 evas_object_show(sd->am_pm_obj);
454 }
455
456 /* access */
457 if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
458 _access_time_register(obj, EINA_TRUE);
459
460 edje_object_size_min_calc(wd->resize_obj, &mw, &mh);
461 evas_object_size_hint_min_set(obj, mw, mh);
462
463 sd->cur.hrs = 0;
464 sd->cur.min = 0;
465 sd->cur.sec = 0;
466 sd->cur.ampm = -1;
467 sd->cur.seconds = sd->seconds;
468 sd->cur.am_pm = sd->am_pm;
469 sd->cur.edit = sd->edit;
470 sd->cur.digedit = sd->digedit;
471 }
472 if (sd->hrs != sd->cur.hrs)
473 {
474 int hrs;
475 int d1, d2, dc1, dc2;
476
477 hrs = sd->hrs;
478 if (sd->am_pm)
479 {
480 if (hrs > 12) hrs -= 12;
481 else if (!hrs) hrs = 12;
482 }
483 d1 = hrs / 10;
484 d2 = hrs % 10;
485 dc1 = sd->cur.hrs / 10;
486 dc2 = sd->cur.hrs % 10;
487 if (d1 != dc1)
488 {
489 msg.val = d1;
490 edje_object_message_send(sd->digit[0], EDJE_MESSAGE_INT, 1, &msg);
491 }
492 if (d2 != dc2)
493 {
494 msg.val = d2;
495 edje_object_message_send(sd->digit[1], EDJE_MESSAGE_INT, 1, &msg);
496 }
497 sd->cur.hrs = hrs;
498 }
499 if (sd->min != sd->cur.min)
500 {
501 int d1, d2, dc1, dc2;
502
503 d1 = sd->min / 10;
504 d2 = sd->min % 10;
505 dc1 = sd->cur.min / 10;
506 dc2 = sd->cur.min % 10;
507 if (d1 != dc1)
508 {
509 msg.val = d1;
510 edje_object_message_send(sd->digit[2], EDJE_MESSAGE_INT, 1, &msg);
511 }
512 if (d2 != dc2)
513 {
514 msg.val = d2;
515 edje_object_message_send(sd->digit[3], EDJE_MESSAGE_INT, 1, &msg);
516 }
517 sd->cur.min = sd->min;
518 }
519 if (sd->seconds)
520 {
521 if (sd->sec != sd->cur.sec)
522 {
523 int d1, d2, dc1, dc2;
524
525 d1 = sd->sec / 10;
526 d2 = sd->sec % 10;
527 dc1 = sd->cur.sec / 10;
528 dc2 = sd->cur.sec % 10;
529 if (d1 != dc1)
530 {
531 msg.val = d1;
532 edje_object_message_send
533 (sd->digit[4], EDJE_MESSAGE_INT, 1, &msg);
534 }
535 if (d2 != dc2)
536 {
537 msg.val = d2;
538 edje_object_message_send
539 (sd->digit[5], EDJE_MESSAGE_INT, 1, &msg);
540 }
541 sd->cur.sec = sd->sec;
542 }
543 }
544 else
545 sd->cur.sec = -1;
546
547 if (sd->am_pm)
548 {
549 int ampm = 0;
550 if (sd->hrs >= 12) ampm = 1;
551 if (ampm != sd->cur.ampm)
552 {
553 msg.val = ampm;
554 edje_object_message_send
555 (sd->am_pm_obj, EDJE_MESSAGE_INT, 1, &msg);
556 sd->cur.ampm = ampm;
557 }
558 }
559 else
560 sd->cur.ampm = -1;
561}
562
563EOLIAN static Eina_Bool
564_elm_clock_elm_widget_theme_apply(Eo *obj, Elm_Clock_Data *sd EINA_UNUSED)
565{
566 Eina_Bool int_ret = EINA_FALSE;
567
568 int_ret = elm_obj_widget_theme_apply(eo_super(obj, MY_CLASS));
569 if (!int_ret) return EINA_FALSE;
570
571 _time_update(obj, EINA_TRUE);
572
573 return EINA_TRUE;
574}
575
576static Eina_Bool
577_ticker(void *data)
578{
579 ELM_CLOCK_DATA_GET(data, sd);
580
581 double t;
582 struct timeval timev;
583 struct tm *tm;
584 time_t tt;
585
586 gettimeofday(&timev, NULL);
587 t = ((double)(1000000 - timev.tv_usec)) / 1000000.0;
588
589 sd->ticker = ecore_timer_add(t, _ticker, data);
590 if (!sd->edit)
591 {
592 tt = (time_t)(timev.tv_sec) + sd->timediff;
593 tzset();
594 tm = localtime(&tt);
595 if (tm)
596 {
597 sd->hrs = tm->tm_hour;
598 sd->min = tm->tm_min;
599 sd->sec = tm->tm_sec;
600 _time_update(data, EINA_FALSE);
601 }
602 }
603
604 return ECORE_CALLBACK_CANCEL;
605}
606
607static char *
608_access_info_cb(void *data EINA_UNUSED, Evas_Object *obj)
609{
610 int hrs;
611 char *ret;
612 Eina_Strbuf *buf;
613
614 ELM_CLOCK_DATA_GET(obj, sd);
615
616 buf = eina_strbuf_new();
617
618 hrs = sd->hrs;
619
620 if (sd->am_pm)
621 {
622 char *ampm = NULL;
623 if (hrs >= 12)
624 {
625 if (hrs > 12) hrs -= 12;
626 ampm = "PM";
627 }
628 else ampm = "AM";
629
630 eina_strbuf_append_printf(buf, "%d, %d, %s", hrs, sd->min, ampm);
631 }
632 else
633 {
634 eina_strbuf_append_printf(buf, "%d, %d", hrs, sd->min);
635 }
636
637 ret = eina_strbuf_string_steal(buf);
638 eina_strbuf_free(buf);
639 return ret;
640}
641
642static char *
643_access_state_cb(void *data EINA_UNUSED, Evas_Object *obj)
644{
645 ELM_CLOCK_DATA_GET(obj, sd);
646 if (sd->edit)
647 return strdup(E_("State: Editable"));
648
649 return NULL;
650}
651
652EOLIAN static void
653_elm_clock_evas_object_smart_add(Eo *obj, Elm_Clock_Data *priv)
654{
655 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
656
657 evas_obj_smart_add(eo_super(obj, MY_CLASS));
658 elm_widget_sub_object_parent_add(obj);
659
660 priv->cur.ampm = -1;
661 priv->cur.seconds = EINA_TRUE;
662 priv->cur.am_pm = EINA_TRUE;
663 priv->cur.edit = EINA_TRUE;
664 priv->cur.digedit = ELM_CLOCK_EDIT_DEFAULT;
665 priv->first_interval = DEFAULT_FIRST_INTERVAL;
666
667 elm_widget_can_focus_set(obj, EINA_TRUE);
668
669 _time_update(obj, EINA_FALSE);
670 _ticker(obj);
671
672 /* access */
673 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
674 {
675 evas_object_propagate_events_set(obj, EINA_FALSE);
676 edje_object_signal_emit(wd->resize_obj,
677 "elm,state,access,on", "elm");
678 }
679
680 _elm_access_object_register(obj, wd->resize_obj);
681 _elm_access_text_set
682 (_elm_access_info_get(obj), ELM_ACCESS_TYPE, E_("Clock"));
683 _elm_access_callback_set
684 (_elm_access_info_get(obj), ELM_ACCESS_INFO, _access_info_cb, NULL);
685 evas_object_propagate_events_set(obj, EINA_FALSE);
686 _elm_access_callback_set
687 (_elm_access_info_get(obj), ELM_ACCESS_STATE, _access_state_cb, NULL);
688}
689
690EOLIAN static void
691_elm_clock_evas_object_smart_del(Eo *obj, Elm_Clock_Data *sd)
692{
693
694 ecore_timer_del(sd->ticker);
695 ecore_timer_del(sd->spin);
696
697 /* NB: digits are killed for being sub objects, automatically */
698
699 evas_obj_smart_del(eo_super(obj, MY_CLASS));
700}
701
702static Eina_Bool _elm_clock_smart_focus_next_enable = EINA_FALSE;
703
704EOLIAN static Eina_Bool
705_elm_clock_elm_widget_focus_next_manager_is(Eo *obj EINA_UNUSED, Elm_Clock_Data *_pd EINA_UNUSED)
706{
707 return _elm_clock_smart_focus_next_enable;
708}
709
710EOLIAN static Eina_Bool
711_elm_clock_elm_widget_focus_next(Eo *obj, Elm_Clock_Data *sd, Elm_Focus_Direction dir, Evas_Object **next, Elm_Object_Item **next_item)
712{
713 Evas_Object *ao, *po;
714 Eina_List *items = NULL;
715
716
717 if (!sd->edit)
718 {
719 *next = (Evas_Object *)obj;
720 return !elm_widget_highlight_get(obj);
721 }
722 else if (!elm_widget_highlight_get(obj))
723 {
724 *next = (Evas_Object *)obj;
725 return EINA_TRUE;
726 }
727
728 int i;
729 for (i = 0; i < 6; i++)
730 {
731 if ((!sd->seconds) && (i >= 4)) break;
732 if (sd->digedit & (1 << i))
733 {
734 po = (Evas_Object *)edje_object_part_object_get
735 (sd->digit[i], "access.t");
736 ao = evas_object_data_get(po, "_part_access_obj");
737 items = eina_list_append(items, ao);
738
739 po = (Evas_Object *)edje_object_part_object_get
740 (sd->digit[i], "access.b");
741 ao = evas_object_data_get(po, "_part_access_obj");
742 items = eina_list_append(items, ao);
743 }
744 }
745
746 if (sd->am_pm)
747 {
748 po = (Evas_Object *)edje_object_part_object_get
749 (sd->am_pm_obj, "access.t");
750 ao = evas_object_data_get(po, "_part_access_obj");
751 items = eina_list_append(items, ao);
752
753 po = (Evas_Object *)edje_object_part_object_get
754 (sd->am_pm_obj, "access.b");
755 ao = evas_object_data_get(po, "_part_access_obj");
756 items = eina_list_append(items, ao);
757 }
758
759 return elm_widget_focus_list_next_get
760 (obj, items, eina_list_data_get, dir, next, next_item);
761}
762
763static void
764_access_obj_process(Evas_Object *obj, Eina_Bool is_access)
765{
766 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
767
768 /* clock object */
769 evas_object_propagate_events_set(obj, !is_access);
770
771 if (is_access)
772 edje_object_signal_emit(wd->resize_obj,
773 "elm,state,access,on", "elm");
774 else
775 edje_object_signal_emit(wd->resize_obj,
776 "elm,state,access,off", "elm");
777
778 /* clock time objects */
779 _access_time_register(obj, is_access);
780}
781
782EOLIAN static void
783_elm_clock_elm_widget_access(Eo *obj EINA_UNUSED, Elm_Clock_Data *_pd EINA_UNUSED, Eina_Bool acs)
784{
785 _elm_clock_smart_focus_next_enable = acs;
786 _access_obj_process(obj, _elm_clock_smart_focus_next_enable);
787}
788
789EAPI Evas_Object *
790elm_clock_add(Evas_Object *parent)
791{
792 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
793 Evas_Object *obj = eo_add(MY_CLASS, parent);
794 return obj;
795}
796
797EOLIAN static Eo *
798_elm_clock_eo_base_constructor(Eo *obj, Elm_Clock_Data *_pd EINA_UNUSED)
799{
800 obj = eo_constructor(eo_super(obj, MY_CLASS));
801 evas_obj_type_set(obj, MY_CLASS_NAME_LEGACY);
802 evas_obj_smart_callbacks_descriptions_set(obj, _smart_callbacks);
803 elm_interface_atspi_accessible_role_set(obj, ELM_ATSPI_ROLE_TEXT);
804
805 return obj;
806}
807
808static void
809_timediff_set(Elm_Clock_Data *sd)
810{
811 struct timeval timev;
812 struct tm *tm;
813 time_t tt;
814
815 gettimeofday(&timev, NULL);
816 tt = (time_t)(timev.tv_sec);
817 tzset();
818 tm = localtime(&tt);
819
820 if (tm)
821 {
822 sd->timediff = (((sd->hrs - tm->tm_hour) * 60 +
823 sd->min - tm->tm_min) * 60) + sd->sec - tm->tm_sec;
824 }
825 else
826 {
827 ERR("Failed to get local time!");
828 sd->timediff = 0;
829 }
830}
831
832EOLIAN static void
833_elm_clock_time_set(Eo *obj, Elm_Clock_Data *sd, int hrs, int min, int sec)
834{
835 sd->hrs = hrs;
836 sd->min = min;
837 sd->sec = sec;
838
839 _timediff_set(sd);
840 _time_update(obj, EINA_FALSE);
841}
842
843EOLIAN static void
844_elm_clock_time_get(Eo *obj EINA_UNUSED, Elm_Clock_Data *sd, int *hrs, int *min, int *sec)
845{
846 if (hrs) *hrs = sd->hrs;
847 if (min) *min = sd->min;
848 if (sec) *sec = sd->sec;
849}
850
851EOLIAN static void
852_elm_clock_edit_set(Eo *obj, Elm_Clock_Data *sd, Eina_Bool edit)
853{
854 sd->edit = edit;
855 if (!edit)
856 _timediff_set(sd);
857 if ((edit) && (sd->digedit == ELM_CLOCK_EDIT_DEFAULT))
858 elm_clock_edit_mode_set(obj, ELM_CLOCK_EDIT_ALL);
859 else
860 _time_update(obj, EINA_FALSE);
861}
862
863EOLIAN static Eina_Bool
864_elm_clock_edit_get(Eo *obj EINA_UNUSED, Elm_Clock_Data *sd)
865{
866 return sd->edit;
867}
868
869EOLIAN static void
870_elm_clock_edit_mode_set(Eo *obj, Elm_Clock_Data *sd, Elm_Clock_Edit_Mode digedit)
871{
872 sd->digedit = digedit;
873 if (digedit == ELM_CLOCK_EDIT_DEFAULT)
874 elm_clock_edit_set(obj, EINA_FALSE);
875 else
876 _time_update(obj, EINA_FALSE);
877}
878
879EOLIAN static Elm_Clock_Edit_Mode
880_elm_clock_edit_mode_get(Eo *obj EINA_UNUSED, Elm_Clock_Data *sd)
881{
882 return sd->digedit;
883}
884
885EOLIAN static void
886_elm_clock_show_am_pm_set(Eo *obj, Elm_Clock_Data *sd, Eina_Bool am_pm)
887{
888 sd->am_pm = !!am_pm;
889 _time_update(obj, EINA_FALSE);
890}
891
892EOLIAN static Eina_Bool
893_elm_clock_show_am_pm_get(Eo *obj EINA_UNUSED, Elm_Clock_Data *sd)
894{
895 return sd->am_pm;
896}
897
898EOLIAN static void
899_elm_clock_show_seconds_set(Eo *obj, Elm_Clock_Data *sd, Eina_Bool seconds)
900{
901 sd->seconds = !!seconds;
902 _time_update(obj, EINA_FALSE);
903}
904
905EOLIAN static Eina_Bool
906_elm_clock_show_seconds_get(Eo *obj EINA_UNUSED, Elm_Clock_Data *sd)
907{
908 return sd->seconds;
909}
910
911EOLIAN static void
912_elm_clock_first_interval_set(Eo *obj EINA_UNUSED, Elm_Clock_Data *sd, double interval)
913{
914 sd->first_interval = interval;
915}
916
917EOLIAN static double
918_elm_clock_first_interval_get(Eo *obj EINA_UNUSED, Elm_Clock_Data *sd)
919{
920 return sd->first_interval;
921}
922
923EOLIAN static void
924_elm_clock_pause_set(Eo *obj EINA_UNUSED, Elm_Clock_Data *sd, Eina_Bool paused)
925{
926 paused = !!paused;
927 if (sd->paused == paused)
928 return;
929 sd->paused = paused;
930 if (paused)
931 ecore_timer_freeze(sd->ticker);
932 else
933 {
934 _timediff_set(sd);
935 ecore_timer_thaw(sd->ticker);
936 }
937}
938
939EOLIAN static Eina_Bool
940_elm_clock_pause_get(Eo *obj EINA_UNUSED, Elm_Clock_Data *sd)
941{
942 return sd->paused;
943}
944
945EOLIAN static Eina_Bool
946_elm_clock_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, Elm_Clock_Data *_pd EINA_UNUSED)
947{
948 return EINA_FALSE;
949}
950
951static void
952_elm_clock_class_constructor(Eo_Class *klass)
953{
954 evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
955
956 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
957 _elm_clock_smart_focus_next_enable = EINA_TRUE;
958}
959
960#include "elm_clock.eo.c"