slider, slideshow and spinner with keyboard arrows
authorTiago Rezende Campos Falcao <developer@tiagofalcao.com>
Mon, 27 Sep 2010 21:13:41 +0000 (21:13 +0000)
committerTiago Rezende Campos Falcao <developer@tiagofalcao.com>
Mon, 27 Sep 2010 21:13:41 +0000 (21:13 +0000)
Author:    Helen Fornazier <helen.fornazier@profusion.mobi>

elm_slider now respond to the keyborad arrows depends on its position.
If it is in a horizontal mode, than its value will change by pressing
left and right, other wise it will respond by pressing up and down

elm_slideshow: go to next and previous with keyboard arrows

elm_spinner: respond to left and right keys in an animated way

SVN revision: 52816

data/themes/default.edc
src/lib/elm_slider.c
src/lib/elm_slideshow.c
src/lib/elm_spinner.c

index cda5f4c3b198637b6f509796a7888a866538837d..ce604d50f39ef71bac2476b55ae8d9a1edaa317b 100644 (file)
@@ -22137,6 +22137,22 @@ collections {
                source: "left_over2";
                action: SIGNAL_EMIT "elm,action,click" "";
            }
+           program {
+               name:   "left_bt_pressed_anim";
+               signal: "elm,left,anim,activate";
+               source: "elm";
+               action: STATE_SET "clicked" 0.0;
+               target: "left_bt";
+               target: "left_over3";
+               after: "left_bt_unpressed_anim";
+           }
+           program {
+               name:   "left_bt_unpressed_anim";
+               action: STATE_SET "default" 0.0;
+               transition: DECELERATE 0.5;
+               target: "left_bt";
+               target: "left_over3";
+           }
 
            program {
                name:   "right_bt_click";
@@ -22173,6 +22189,23 @@ collections {
                source: "right_over2";
                action: SIGNAL_EMIT "elm,action,click" "";
            }
+           program {
+               name:   "right_bt_pressed_anim";
+               signal: "elm,right,anim,activate";
+               source: "elm";
+               action: STATE_SET "clicked" 0.0;
+               target: "right_bt";
+               target: "right_over3";
+               after: "right_bt_unpressed_anim";
+           }
+           program {
+               name:   "right_bt_unpressed_anim";
+               action: STATE_SET "default" 0.0;
+               transition: DECELERATE 0.5;
+               target: "right_bt";
+               target: "right_over3";
+           }
+
            program { name: "disable";
                signal: "elm,state,disabled";
                source: "elm";
index db7d985b339ca9e4fe0410129f70f91d57c59d49..bc43ede16dc044b399b6d8bd87296157c59f8d74 100644 (file)
@@ -67,6 +67,12 @@ static void _units_set(Evas_Object *obj);
 static void _val_set(Evas_Object *obj);
 static void _indicator_set(Evas_Object *obj);
 static void _on_focus_hook(void *data, Evas_Object *obj);
+static void _drag_up(void *data, Evas_Object *obj,
+                    const char *emission, const char *source);
+static void _drag_down(void *data, Evas_Object *obj,
+                    const char *emission, const char *source);
+static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
+                             Evas_Callback_Type type, void *event_info);
 
 static const char SIG_CHANGED[] = "changed";
 static const char SIG_DELAY_CHANGED[] = "delay,changed";
@@ -80,6 +86,48 @@ static const Evas_Smart_Cb_Description _signals[] = {
   {NULL, NULL}
 };
 
+static Eina_Bool
+_event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
+{
+   if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
+   Evas_Event_Key_Down *ev = event_info;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return EINA_FALSE;
+   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
+   if (elm_widget_disabled_get(obj)) return EINA_FALSE;
+   if (!strcmp(ev->keyname, "Left")
+       || !strcmp(ev->keyname, "KP_Left"))
+     {
+        if (!wd->horizontal) return EINA_FALSE;
+        _drag_up(obj, NULL, NULL, NULL);
+        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+        return EINA_TRUE;
+     }
+   else if (!strcmp(ev->keyname, "Right")
+            || !strcmp(ev->keyname, "KP_Right"))
+     {
+        if (!wd->horizontal) return EINA_FALSE;
+        _drag_down(obj, NULL, NULL, NULL);
+        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+        return EINA_TRUE;
+     }
+   else if (!strcmp(ev->keyname, "Up") || !strcmp(ev->keyname, "KP_Up"))
+     {
+        if (wd->horizontal) return EINA_FALSE;
+        _drag_up(obj, NULL, NULL, NULL);
+        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+        return EINA_TRUE;
+     }
+   else if (!strcmp(ev->keyname, "Down") || !strcmp(ev->keyname, "KP_Down"))
+     {
+        if (wd->horizontal) return EINA_FALSE;
+        _drag_down(obj, NULL, NULL, NULL);
+        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+        return EINA_TRUE;
+     }
+   else return EINA_FALSE;
+}
+
 static void
 _del_hook(Evas_Object *obj)
 {
@@ -337,6 +385,7 @@ elm_slider_add(Evas_Object *parent)
    elm_widget_del_hook_set(obj, _del_hook);
    elm_widget_theme_hook_set(obj, _theme_hook);
    elm_widget_can_focus_set(obj, EINA_TRUE);
+   elm_widget_event_hook_set(obj, _event_hook);
 
    wd->horizontal = EINA_TRUE;
    wd->val = 0.0;
index 6a3c9db54df8c90c29a98daeb308041f42b981c9..183ea42d9e04288801e3aac7f73df9d277a5b2bc 100644 (file)
@@ -57,6 +57,42 @@ static void _sizing_eval(Evas_Object *obj);
 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
 static Eina_Bool _timer_cb(void *data);
 static void _on_focus_hook(void *data, Evas_Object *obj);
+static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
+                             Evas_Callback_Type type, void *event_info);
+
+static Eina_Bool
+_event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
+{
+   if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
+   Evas_Event_Key_Down *ev = event_info;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return EINA_FALSE;
+   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
+   if (elm_widget_disabled_get(obj)) return EINA_FALSE;
+   if (!strcmp(ev->keyname, "Left") || !strcmp(ev->keyname, "KP_Left"))
+     {
+        elm_slideshow_previous(obj);
+        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+        return EINA_TRUE;
+     }
+   if (!strcmp(ev->keyname, "Right") || !strcmp(ev->keyname, "KP_Right"))
+     {
+        elm_slideshow_next(obj);
+        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+        return EINA_TRUE;
+     }
+   if (!strcmp(ev->keyname, "Return") || !strcmp(ev->keyname, "space"))
+     {
+        if (wd->timeout)
+          elm_slideshow_timeout_set(obj, 0);
+        else
+          elm_slideshow_timeout_set(obj, 3);
+
+        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+        return EINA_TRUE;
+     }
+   return EINA_FALSE;
+}
 
 static void
 _del_hook(Evas_Object *obj)
@@ -265,6 +301,7 @@ elm_slideshow_add(Evas_Object *parent)
    elm_widget_del_hook_set(obj, _del_hook);
    elm_widget_theme_hook_set(obj, _theme_hook);
    elm_widget_can_focus_set(obj, EINA_TRUE);
+   elm_widget_event_hook_set(obj, _event_hook);
 
    wd->current = NULL;
    wd->previous = NULL;
index 4a45f134f74c2b1a1c9fcd9a420ece528c248ea3..c37894f1a70e177fb137566c565e1835b6a709bb 100644 (file)
@@ -52,6 +52,8 @@ static void _sizing_eval(Evas_Object *obj);
 //static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
 static Eina_Bool _value_set(Evas_Object *obj, double delta);
 static void _on_focus_hook(void *data, Evas_Object *obj);
+static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
+                             Evas_Callback_Type type, void *event_info);
 
 static void
 _del_hook(Evas_Object *obj)
@@ -492,27 +494,48 @@ _entry_activated(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNU
    wd->delay = ecore_timer_add(0.2, _delay_change, data);
 }
 
-static void
-_entry_event_key_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
-{
-   Evas_Event_Key_Down *ev = event_info;
-   Widget_Data *wd = elm_widget_data_get(data);
-   if (!wd) return;
-   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
-   if (!strcmp(ev->keyname, "Up")) _val_inc_start(data);
-   else if (!strcmp(ev->keyname, "Down")) _val_dec_start(data);
-}
-
-static void
-_entry_event_key_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
+static Eina_Bool
+_event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
 {
-   Evas_Event_Key_Down *ev = event_info;
-   Widget_Data *wd = elm_widget_data_get(data);
-   if (!wd) return;
-   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
-   if (!strcmp(ev->keyname, "Up")) _val_inc_stop(data);
-   else if (!strcmp(ev->keyname, "Down")) _val_dec_stop(data);
-   else if (!strcmp(ev->keyname, "Escape")) _reset_value(data);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return EINA_FALSE;
+   if (elm_widget_disabled_get(obj)) return EINA_FALSE;
+   if (type == EVAS_CALLBACK_KEY_DOWN)
+     {
+        Evas_Event_Key_Down *ev = event_info;
+        if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
+        else if (!strcmp(ev->keyname, "Left") || !strcmp(ev->keyname, "KP_Left")
+                 || !strcmp(ev->keyname, "Down") || !strcmp(ev->keyname, "KP_Down"))
+          {
+             _val_dec_start(obj);
+             edje_object_signal_emit(wd->spinner, "elm,left,anim,activate", "elm");
+             ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+             return EINA_TRUE;
+          }
+        else if (!strcmp(ev->keyname, "Right") || !strcmp(ev->keyname, "KP_Right")
+                 || !strcmp(ev->keyname, "Up") || !strcmp(ev->keyname, "KP_Up"))
+          {
+             _val_inc_start(obj);
+             edje_object_signal_emit(wd->spinner, "elm,right,anim,activate", "elm");
+             ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+             return EINA_TRUE;
+          }
+     }
+   else if (type == EVAS_CALLBACK_KEY_UP)
+     {
+        Evas_Event_Key_Down *ev = event_info;
+        if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
+        if (!strcmp(ev->keyname, "Right") || !strcmp(ev->keyname, "KP_Right")
+            || !strcmp(ev->keyname, "Up") || !strcmp(ev->keyname, "KP_Up"))
+          _val_inc_stop(obj);
+        else if (!strcmp(ev->keyname, "Left") || !strcmp(ev->keyname, "KP_Left")
+            || !strcmp(ev->keyname, "Down") || !strcmp(ev->keyname, "KP_Down"))
+          _val_dec_stop(obj);
+        else  return EINA_FALSE;
+        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+        return EINA_TRUE;
+     }
+     return EINA_FALSE;
 }
 
 /**
@@ -546,6 +569,7 @@ elm_spinner_add(Evas_Object *parent)
    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
    elm_widget_can_focus_set(obj, EINA_TRUE);
+   elm_widget_event_hook_set(obj, _event_hook);
 
    wd->val = 0.0;
    wd->val_min = 0.0;
@@ -580,11 +604,6 @@ elm_spinner_add(Evas_Object *parent)
    edje_object_part_drag_value_set(wd->spinner, "elm.dragable.slider", 
                                    0.0, 0.0);
 
-   evas_object_event_callback_add(wd->spinner, EVAS_CALLBACK_KEY_DOWN, 
-                                  _entry_event_key_down, obj);
-   evas_object_event_callback_add(wd->spinner, EVAS_CALLBACK_KEY_UP, 
-                                  _entry_event_key_up, obj);
-
    wd->ent = elm_entry_add(obj);
    elm_entry_single_line_set(wd->ent, 1);
    evas_object_smart_callback_add(wd->ent, "activated", _entry_activated, obj);