Let the user choose what digits of the clock are editable.
authorIván Briano <sachieru@gmail.com>
Tue, 11 May 2010 15:25:01 +0000 (15:25 +0000)
committerIván Briano <sachieru@gmail.com>
Tue, 11 May 2010 15:25:01 +0000 (15:25 +0000)
Patch by Rafael "15 years of experience" Fonseca.

SVN revision: 48757

data/themes/default.edc
src/bin/test_clock.c
src/lib/Elementary.h.in
src/lib/elm_clock.c

index 9174bfa..535ddb8 100644 (file)
@@ -2226,21 +2226,31 @@ collections {
            type: RECT;
            mouse_events: 1;
            description { state: "default" 0.0;
+              visible: 0;
               rel1.to: "base";
               rel1.relative: 0.0 0.5;
               rel2.to: "base";
               color: 0 0 0 0;
            }
+           description { state: "visible" 0.0;
+              inherit: "default" 0.0;
+              visible: 1;
+           }
         }
         part { name: "t";
            type: RECT;
            mouse_events: 1;
            description { state: "default" 0.0;
+              visible: 0;
               rel1.to: "base";
               rel2.to: "base";
               rel2.relative: 1.0 0.5;
               color: 0 0 0 0;
            }
+           description { state: "visible" 0.0;
+              inherit: "default" 0.0;
+              visible: 1;
+           }
         }
         part { name: "bot0";
            mouse_events: 0;
@@ -2675,6 +2685,8 @@ collections {
            action: STATE_SET "visible" 0.0;
            target: "atop";
            target: "abot";
+           target: "t";
+           target: "b";
         }
         program { name: "edit_off";
             signal: "elm,state,edit,off";
@@ -2682,6 +2694,8 @@ collections {
            action: STATE_SET "default" 0.0;
            target: "atop";
            target: "abot";
+           target: "t";
+           target: "b";
         }
         program { name: "up";
            signal: "mouse,down,1";
index 89ba7b6..0f01d3b 100644 (file)
@@ -4,6 +4,7 @@ void
 test_clock(void *data, Evas_Object *obj, void *event_info)
 {
    Evas_Object *win, *bg, *bx, *ck;
+   unsigned int digedit;
 
    win = elm_win_add(NULL, "clock", ELM_WIN_BASIC);
    elm_win_title_set(win, "Clock");
@@ -47,6 +48,14 @@ test_clock(void *data, Evas_Object *obj, void *event_info)
    elm_box_pack_end(bx, ck);
    evas_object_show(ck);
 
+   ck = elm_clock_add(win);
+   elm_clock_show_seconds_set(ck, 1);
+   elm_clock_edit_set(ck, 1);
+   digedit = ELM_CLOCK_HOUR_UNIT | ELM_CLOCK_MIN_UNIT | ELM_CLOCK_SEC_UNIT;
+   elm_clock_digit_edit_set(ck, digedit);
+   elm_box_pack_end(bx, ck);
+   evas_object_show(ck);
+
    evas_object_show(win);
 }
 #endif
index cbd5fe8..909ef88 100644 (file)
@@ -196,6 +196,18 @@ extern "C" {
        ELM_THUMB_ANIMATION_LAST
     } Elm_Thumb_Animation_Setting;
 
+  typedef enum _Elm_Clock_Digedit
+    {
+       ELM_CLOCK_NONE          = 0,
+       ELM_CLOCK_HOUR_DECIMAL  = 1 << 0,
+       ELM_CLOCK_HOUR_UNIT     = 1 << 1,
+       ELM_CLOCK_MIN_DECIMAL   = 1 << 2,
+       ELM_CLOCK_MIN_UNIT      = 1 << 3,
+       ELM_CLOCK_SEC_DECIMAL   = 1 << 4,
+       ELM_CLOCK_SEC_UNIT      = 1 << 5,
+       ELM_CLOCK_ALL           = (1 << 6) - 1
+    } Elm_Clock_Digedit;
+
 #ifndef ELM_LIB_QUICKLAUNCH
 #define ELM_MAIN() int main(int argc, char **argv) {elm_init(argc, argv); return elm_main(argc, argv);}
 #else
@@ -587,6 +599,8 @@ extern "C" {
    EAPI void         elm_clock_time_get(const Evas_Object *obj, int *hrs, int *min, int *sec);
    EAPI void         elm_clock_edit_set(Evas_Object *obj, Eina_Bool edit);
    EAPI Eina_Bool    elm_clock_edit_get(const Evas_Object *obj);
+   EAPI void        elm_clock_digit_edit_set(Evas_Object *obj, unsigned int digedit);
+   EAPI unsigned int elm_clock_digit_edit_get(const Evas_Object *obj);
    EAPI void         elm_clock_show_am_pm_set(Evas_Object *obj, Eina_Bool am_pm);
    EAPI Eina_Bool    elm_clock_show_am_pm_get(const Evas_Object *obj);
    EAPI void         elm_clock_show_seconds_set(Evas_Object *obj, Eina_Bool seconds);
index 01711bc..7598ac7 100644 (file)
@@ -17,6 +17,7 @@ struct _Widget_Data
    Eina_Bool seconds : 1;
    Eina_Bool am_pm : 1;
    Eina_Bool edit : 1;
+   unsigned int digedit;
    int hrs, min, sec;
    Evas_Object *digit[6];
    Evas_Object *ampm;
@@ -28,6 +29,7 @@ struct _Widget_Data
         Eina_Bool seconds : 1;
         Eina_Bool am_pm : 1;
         Eina_Bool edit : 1;
+       unsigned int digedit;
      } cur;
 };
 
@@ -190,7 +192,7 @@ _time_update(Evas_Object *obj)
    const char *style = elm_widget_style_get(obj);
    if (!wd) return;
    if ((wd->cur.seconds != wd->seconds) || (wd->cur.am_pm != wd->am_pm) ||
-       (wd->cur.edit != wd->edit))
+       (wd->cur.edit != wd->edit) || (wd->cur.digedit != wd->digedit))
      {
        int i;
        Evas_Coord mw, mh;
@@ -229,7 +231,7 @@ _time_update(Evas_Object *obj)
             _elm_theme_set(wd->digit[i], "clock", "flipdigit", style);
             edje_object_scale_set(wd->digit[i], elm_widget_scale_get(obj) * 
                                    _elm_config->scale);
-            if (wd->edit)
+            if (wd->edit && (wd->digedit & (1 << i)))
               edje_object_signal_emit(wd->digit[i], "elm,state,edit,on", "elm");
             edje_object_signal_callback_add(wd->digit[i], "elm,action,up", "",
                                             _signal_clock_val_up, obj);
@@ -275,6 +277,7 @@ _time_update(Evas_Object *obj)
        wd->cur.seconds = wd->seconds;
        wd->cur.am_pm = wd->am_pm;
        wd->cur.edit = wd->edit;
+       wd->cur.digedit = wd->digedit;
      }
    if (wd->hrs != wd->cur.hrs)
      {
@@ -404,6 +407,7 @@ elm_clock_add(Evas_Object *parent)
    wd->cur.seconds = EINA_TRUE;
    wd->cur.am_pm = EINA_TRUE;
    wd->cur.edit = EINA_TRUE;
+   wd->cur.digedit = ELM_CLOCK_NONE;
 
    _time_update(obj);
    _ticker(obj);
@@ -469,6 +473,9 @@ elm_clock_time_get(const Evas_Object *obj, int *hrs, int *min, int *sec)
  * @param edit Bool option for edited (1 = yes, 0 = no)
  *
  * This function sets if the clock settings can be edited or not.
+ * By default or if digit_edit option was previously set to ELM_CLOCK_NONE,
+ * all digits are editable. To choose what digits to make editable
+ * use elm_clock_digit_edit_set().
  *
  * @ingroup Clock
  */
@@ -479,7 +486,10 @@ elm_clock_edit_set(Evas_Object *obj, Eina_Bool edit)
    Widget_Data *wd = elm_widget_data_get(obj);
    if (!wd) return;
    wd->edit = edit;
-   _time_update(obj);
+   if (edit && (wd->digedit == ELM_CLOCK_NONE))
+     elm_clock_digit_edit_set(obj, ELM_CLOCK_ALL);
+   else
+     _time_update(obj);
 }
 
 /**
@@ -502,6 +512,46 @@ elm_clock_edit_get(const Evas_Object *obj)
 }
 
 /**
+ * Set what digits of the clock are editable
+ *
+ * @param obj The clock object
+ * @param digedit Bit mask indicating the digits to edit
+ *
+ * If the digedit param is ELM_CLOCK_NONE, editing will be disabled.
+ *
+ * @ingroup Clock
+ */
+EAPI void
+elm_clock_digit_edit_set(Evas_Object *obj, Elm_Clock_Digedit digedit)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   wd->digedit = digedit;
+   if (digedit == ELM_CLOCK_NONE)
+     elm_clock_edit_set(obj, EINA_FALSE);
+   else
+     _time_update(obj);
+}
+
+/**
+ * Get what digits of the clock are editable
+ *
+ * @param obj The clock object
+ * @return Bit mask indicating the digits.
+ *
+ * @ingroup Clock
+ */
+EAPI unsigned int
+elm_clock_digit_edit_get(const Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) 0;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return 0;
+   return wd->digedit;
+}
+
+/**
  * Set if the clock shows hours in military or am/pm mode
  *
  * @param obj The clock object