clock: Add elm_clock_pause_set and elm_clock_pause_get functions for elm_clock widget
authorMichal Jagiello <m.jagiello@samsung.com>
Wed, 18 Dec 2013 01:14:20 +0000 (10:14 +0900)
committerDaniel Juyung Seo <juyung.seo@samsung.com>
Wed, 18 Dec 2013 01:14:39 +0000 (10:14 +0900)
Summary: This patch add two functions for elm_clock widget - elm_clock_pause_set and elm_clock_pause_get. I've prepared it because I want to do a stopwatch using this widget, but now it is impossible to pause the clock without set an editable mode.

Reviewers: seoz, cedric, stanluk, z.kosinski

Reviewed By: seoz

Differential Revision: https://phab.enlightenment.org/D374

legacy/elementary/src/bin/test.c
legacy/elementary/src/bin/test_clock.c
legacy/elementary/src/lib/elm_clock.c
legacy/elementary/src/lib/elm_clock_eo.h
legacy/elementary/src/lib/elm_clock_legacy.h
legacy/elementary/src/lib/elm_widget_clock.h

index 3c4db35..bb32748 100644 (file)
@@ -39,6 +39,7 @@ void test_fileselector_entry(void *data, Evas_Object *obj, void *event_info);
 void test_clock(void *data, Evas_Object *obj, void *event_info);
 void test_clock2(void *data, Evas_Object *obj, void *event_info);
 void test_clock3(void *data, Evas_Object *obj, void *event_info);
+void test_clock4(void *data, Evas_Object *obj, void *event_info);
 void test_check(void *data, Evas_Object *obj, void *event_info);
 void test_check_toggle(void *data, Evas_Object *obj, void *event_info);
 void test_radio(void *data, Evas_Object *obj, void *event_info);
@@ -740,6 +741,7 @@ add_tests:
    ADD_TEST(NULL, "Times & Dates", "Clock", test_clock);
    ADD_TEST(NULL, "Times & Dates", "Clock 2", test_clock2);
    ADD_TEST(NULL, "Times & Dates", "Clock 3", test_clock3);
+   ADD_TEST(NULL, "Times & Dates", "Clock 4", test_clock4);
    ADD_TEST(NULL, "Times & Dates", "Datetime", test_datetime);
 
    //------------------------------//
index 51c661f..d661650 100644 (file)
@@ -215,6 +215,21 @@ _hmode_bt_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
    elm_clock_show_am_pm_set(ck, EINA_FALSE);
 }
 
+static void
+_pause_resume_bt_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
+{
+   Evas_Object *ck = data;
+
+   if (!elm_clock_pause_get(ck))
+     {
+        elm_object_text_set(obj, "Resume");
+        elm_clock_pause_set(ck, EINA_TRUE);
+        return;
+     }
+   elm_object_text_set(obj, "Pause");
+   elm_clock_pause_set(ck, EINA_FALSE);
+}
+
 void
 test_clock2(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
 {
@@ -318,3 +333,31 @@ test_clock3(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
 
    evas_object_show(win);
 }
+
+void
+test_clock4(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+   Evas_Object *win, *bx, *ck, *bt;
+
+   win = elm_win_util_standard_add("clock4", "Clock4");
+   elm_win_autodel_set(win, EINA_TRUE);
+
+   bx = elm_box_add(win);
+   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   elm_win_resize_object_add(win, bx);
+   evas_object_show(bx);
+
+   ck = elm_clock_add(win);
+   elm_clock_show_seconds_set(ck, EINA_TRUE);
+   elm_clock_time_set(ck, 0, 0, 0);
+   elm_box_pack_end(bx, ck);
+   evas_object_show(ck);
+
+   bt = elm_button_add(win);
+   elm_object_text_set(bt, "Pause");
+   evas_object_smart_callback_add(bt, "clicked", _pause_resume_bt_clicked, ck);
+   elm_box_pack_end(bx, bt);
+   evas_object_show(bt);
+
+   evas_object_show(win);
+}
index 0dca6f1..d377d76 100644 (file)
@@ -1078,6 +1078,49 @@ _first_interval_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
    *ret = sd->first_interval;
 }
 
+EAPI void
+elm_clock_pause_set(Evas_Object *obj, Eina_Bool pause)
+{
+   ELM_CLOCK_CHECK(obj);
+   eo_do(obj, elm_obj_clock_pause_set(pause));
+}
+
+static void
+_pause_set(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
+{
+   Eina_Bool pause = va_arg(*list, int);
+   Elm_Clock_Smart_Data *sd = _pd;
+   pause = !!pause;
+   if (sd->paused == pause)
+     return;
+   sd->paused = pause;
+   if (pause)
+     ecore_timer_freeze(sd->ticker);
+   else
+     {
+        _timediff_set(sd);
+        ecore_timer_thaw(sd->ticker);
+     }
+}
+
+EAPI Eina_Bool
+elm_clock_pause_get(const Evas_Object *obj)
+{
+   ELM_CLOCK_CHECK(obj) EINA_FALSE;
+   Eina_Bool ret = EINA_FALSE;
+   eo_do(obj, elm_obj_clock_pause_get(&ret));
+   return ret;
+}
+
+static void
+_pause_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
+{
+   Eina_Bool *ret = va_arg(*list, Eina_Bool *);
+   Elm_Clock_Smart_Data *sd = _pd;
+
+   *ret = sd->paused;
+}
+
 static void
 _elm_clock_smart_focus_direction_manager_is(Eo *obj EINA_UNUSED, void *_pd EINA_UNUSED, va_list *list)
 {
@@ -1112,6 +1155,8 @@ _class_constructor(Eo_Class *klass)
         EO_OP_FUNC(ELM_OBJ_CLOCK_ID(ELM_OBJ_CLOCK_SUB_ID_SHOW_SECONDS_GET), _show_seconds_get),
         EO_OP_FUNC(ELM_OBJ_CLOCK_ID(ELM_OBJ_CLOCK_SUB_ID_FIRST_INTERVAL_SET), _first_interval_set),
         EO_OP_FUNC(ELM_OBJ_CLOCK_ID(ELM_OBJ_CLOCK_SUB_ID_FIRST_INTERVAL_GET), _first_interval_get),
+        EO_OP_FUNC(ELM_OBJ_CLOCK_ID(ELM_OBJ_CLOCK_SUB_ID_PAUSE_SET), _pause_set),
+        EO_OP_FUNC(ELM_OBJ_CLOCK_ID(ELM_OBJ_CLOCK_SUB_ID_PAUSE_GET), _pause_get),
         EO_OP_FUNC_SENTINEL
    };
    eo_class_funcs_set(klass, func_desc);
@@ -1134,6 +1179,8 @@ static const Eo_Op_Description op_desc[] = {
      EO_OP_DESCRIPTION(ELM_OBJ_CLOCK_SUB_ID_SHOW_SECONDS_GET, "Get whether the given clock widget is showing time with seconds."),
      EO_OP_DESCRIPTION(ELM_OBJ_CLOCK_SUB_ID_FIRST_INTERVAL_SET, "Set the first interval on time updates for a user mouse button hold."),
      EO_OP_DESCRIPTION(ELM_OBJ_CLOCK_SUB_ID_FIRST_INTERVAL_GET, "Get the first interval on time updates for a user mouse button hold."),
+     EO_OP_DESCRIPTION(ELM_OBJ_CLOCK_SUB_ID_PAUSE_SET, "Set whether the given clock widget should be paused or not."),
+     EO_OP_DESCRIPTION(ELM_OBJ_CLOCK_SUB_ID_PAUSE_GET, "Get if the given clock widget is paused."),
      EO_OP_DESCRIPTION_SENTINEL
 };
 static const Eo_Class_Description class_desc = {
index 653c125..86a2515 100644 (file)
@@ -18,7 +18,9 @@ enum
    ELM_OBJ_CLOCK_SUB_ID_SHOW_SECONDS_GET,
    ELM_OBJ_CLOCK_SUB_ID_FIRST_INTERVAL_SET,
    ELM_OBJ_CLOCK_SUB_ID_FIRST_INTERVAL_GET,
-   ELM_OBJ_CLOCK_SUB_ID_LAST
+   ELM_OBJ_CLOCK_SUB_ID_PAUSE_SET,
+   ELM_OBJ_CLOCK_SUB_ID_PAUSE_GET,
+   ELM_OBJ_CLOCK_SUB_ID_LAST,
 };
 
 #define ELM_OBJ_CLOCK_ID(sub_id) (ELM_OBJ_CLOCK_BASE_ID + sub_id)
@@ -200,3 +202,31 @@ enum
  * @ingroup Clock
  */
 #define elm_obj_clock_first_interval_get(ret) ELM_OBJ_CLOCK_ID(ELM_OBJ_CLOCK_SUB_ID_FIRST_INTERVAL_GET), EO_TYPECHECK(double *, ret)
+
+/**
+ * @def elm_obj_clock_pause_set
+ * @since 1.9
+ *
+ * Set whether the given clock widget should be paused or not.
+ *
+ * @param[in] pause
+ *
+ * @see elm_clock_pause_set
+ *
+ * @ingroup Clock
+ */
+#define elm_obj_clock_pause_set(pause) ELM_OBJ_CLOCK_ID(ELM_OBJ_CLOCK_SUB_ID_PAUSE_SET), EO_TYPECHECK(Eina_Bool, pause)
+
+/**
+ * @def elm_obj_clock_pause_get
+ * @since 1.9
+ *
+ * Get whether the given clock widget is paused.
+ *
+ * @param[out] ret
+ *
+ * @see elm_clock_pause_get
+ *
+ * @ingroup Clock
+ */
+#define elm_obj_clock_pause_get(ret) ELM_OBJ_CLOCK_ID(ELM_OBJ_CLOCK_SUB_ID_PAUSE_GET), EO_TYPECHECK(Eina_Bool *, ret)
index c3e61fc..1a760bd 100644 (file)
@@ -228,3 +228,33 @@ EAPI void              elm_clock_first_interval_set(Evas_Object *obj, double int
  * @ingroup Clock
  */
 EAPI double            elm_clock_first_interval_get(const Evas_Object *obj);
+
+/**
+ * Set whether the given clock widget should be paused or not.
+ * 
+ * @param obj The clock object
+ * @param pause @c EINA_TRUE to pause clock, @c EINA_FALSE otherwise
+ * 
+ * This function pauses or starts the clock widget.
+ * 
+ * @see elm_clock_pause_get()
+ * 
+ * @ingroup Clock
+ * @since 1.9
+ */
+EAPI void              elm_clock_pause_set(Evas_Object *obj, Eina_Bool pause);
+
+/**
+ * Get whether the given clock widget is paused.
+ * 
+ * @param obj The clock object
+ * @return @c EINA_TRUE if it's paused @c EINA_FALSE otherwise
+ * 
+ * This function gets whether the clock is paused or not.
+ * 
+ * @see elm_clock_pause_set()
+ * 
+ * @ingroup Clock
+ * @since 1.9
+ */
+EAPI Eina_Bool         elm_clock_pause_get(const Evas_Object *obj);
index ec47232..b91297a 100644 (file)
@@ -41,6 +41,7 @@ struct _Elm_Clock_Smart_Data
       Eina_Bool           edit : 1;
    } cur;
 
+   Eina_Bool paused : 1; /**< a flag whether clock is paused or not */
    Eina_Bool seconds : 1;
    Eina_Bool am_pm : 1;
    Eina_Bool edit : 1;