elm genlist: Added elm_genlist_item_flip_get/set APIs. Patch by
authorseoz <seoz@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 5 Mar 2012 15:03:12 +0000 (15:03 +0000)
committerseoz <seoz@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 5 Mar 2012 15:03:12 +0000 (15:03 +0000)
Hyoyoung Chang <hyoyoung@gmail.com>

On Wed, Feb 29, 2012 at 9:17 PM, Hyoyoung Chang <hyoyoung@gmail.com>
wrote:
> Dear all.
>
> I made a patch to introduce new genlist item mode.
> Two public apis are added.
> +EAPI void elm_genlist_item_flip_set(Elm_Object_Item *it, Eina_Bool
flip);
> +EAPI Eina_Bool elm_genlist_item_flip_get(Elm_Object_Item *it);
>
> It provides on-the-flying item change. It works like that a new item
> added on existed item.
> In elementary test, you can test it.
> It's useful at adding widgets or show buttons in genlist item.
>
> Thanks.

On Mon, Mar 5, 2012 at 5:56 PM, Hyoyoung Chang <hyoyoung@gmail.com>
wrote:
> Hello, I modifed fliP_set api to use ecore_job.
> It resolved version of mouse_{move, up} bugs.
>

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@68727 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

data/themes/widgets/genlist.edc
src/bin/test.c
src/bin/test_genlist.c
src/lib/elm_gen_common.h
src/lib/elm_genlist.c
src/lib/elm_genlist.h

index 5d0766c..b2acb97 100644 (file)
@@ -3,6 +3,7 @@ group { name: "elm/genlist/item/default/default";
    data.item: "texts" "elm.text";
    data.item: "contents" "elm.swallow.icon elm.swallow.end";
    data.item: "treesize" "20";
+   data.item: "flips" "elm.text.flip";
    //      data.item: "states" "";
    images {
       image: "bt_sm_base1.png" COMP;
@@ -165,6 +166,10 @@ group { name: "elm/genlist/item/default/default";
                offset:   -1   -5;
             }
          }
+         description { state: "flip_enabled" 0.0;
+            inherit: "default" 0.0;
+            visible: 0;
+         }
       }
       part { name: "elm.swallow.end";
          clip_to: "disclip";
@@ -183,6 +188,10 @@ group { name: "elm/genlist/item/default/default";
                offset:   -5   -5;
             }
          }
+         description { state: "flip_enabled" 0.0;
+            inherit: "default" 0.0;
+            visible: 0;
+         }
       }
       part { name: "elm.text";
          clip_to: "disclip";
@@ -219,6 +228,24 @@ group { name: "elm/genlist/item/default/default";
             color: 224 224 224 255;
             color3: 0 0 0 64;
          }
+         description { state: "flip_enabled" 0.0;
+            inherit: "default" 0.0;
+            visible: 0;
+         }
+      }
+      part { name: "elm.text.flip";
+         clip_to: "disclip";
+         type: SWALLOW;
+         scale: 1;
+         description { state: "default" 0.0;
+            visible: 0;
+            rel1.to_y: "elm.text";
+            rel2.to_y: "elm.text";
+         }
+         description { state: "flip_enabled" 0.0;
+            inherit: "default" 0.0;
+            visible: 1;
+         }
       }
       part { name: "fg1";
          clip_to: "disclip";
@@ -363,6 +390,24 @@ group { name: "elm/genlist/item/default/default";
          target:  "reorder_bg";
          transition: DECELERATE 0.5;
       }
+      program { name: "flip_enabled";
+         signal: "elm,state,flip,enabled";
+         source: "elm";
+         action: STATE_SET "flip_enabled" 0.0;
+         target: "elm.text";
+         target: "elm.text.flip";
+         target: "elm.swallow.icon";
+         target: "elm.swallow.end";
+      }
+      program { name: "flip_disabled";
+         signal: "elm,state,flip,disabled";
+         source: "elm";
+         action: STATE_SET "default" 0.0;
+         target: "elm.text";
+         target: "elm.text.flip";
+         target: "elm.swallow.icon";
+         target: "elm.swallow.end";
+      }
    }
 }
 group { name: "elm/genlist/item/group_index/default";
@@ -9302,6 +9347,10 @@ group { name: "elm/genlist/item/edit/default";
             inherit: "default" 0.0;
             align: 0.0 0.5;
          }
+         description { state: "disabled" 0.0;
+            inherit: "default" 0.0;
+            visible: 0;
+         }
       }
       part { name: "elm.padding.icon1.right";
          type: RECT;
@@ -9333,6 +9382,14 @@ group { name: "elm/genlist/item/edit/default";
                to_x: "elm.padding.icon2.left";
             }
          }
+         description { state: "flipped" 0.0;
+            inherit: "default" 0.0;
+            rel1.to_x: "elm.padding.left";
+            rel2 {
+               relative: 1.3 1.0;
+               to_x: "elm.padding.right";
+            }
+         }
       }
       part { name: "elm.padding.icon2.left";
          type: RECT;
@@ -9374,6 +9431,10 @@ group { name: "elm/genlist/item/edit/default";
             inherit: "default" 0.0;
             align: 1.0 0.5;
          }
+         description { state: "disabled" 0.0;
+            inherit: "default" 0.0;
+            visible: 0;
+         }
       }
       part { name: "disclip";
          type: RECT;
@@ -9473,5 +9534,30 @@ group { name: "elm/genlist/item/edit/default";
          target: "elm.edit.icon.1";
          target: "elm.edit.icon.2";
       }
+      program {
+         name:    "enable_flip_mode";
+         signal:  "elm,state,flip,enabled";
+         source:  "elm";
+         action:  STATE_SET "disabled" 0.0;
+         target:  "elm.edit.icon.1";
+         target:  "elm.edit.icon.2";
+         after:   "enable_flip_mode_next";
+      }
+      program {
+         name:    "enable_flip_mode_next";
+         action:  STATE_SET "flipped" 0.0;
+         transition: DECELERATE 0.5;
+         target:  "elm.swallow.edit.content";
+      }
+      program {
+         name:    "disable_flip_mode";
+         signal:  "elm,state,flip,disabled";
+         source:  "elm";
+         action:  STATE_SET "default" 0.0;
+         transition: DECELERATE 0.5;
+         target:  "elm.swallow.edit.content";
+         target:  "elm.edit.icon.1";
+         target:  "elm.edit.icon.2";
+      }
    }
 }
index 709b597..7cf3c38 100644 (file)
@@ -86,6 +86,7 @@ void test_genlist12(void *data, Evas_Object *obj, void *event_info);
 void test_genlist13(void *data, Evas_Object *obj, void *event_info);
 void test_genlist14(void *data, Evas_Object *obj, void *event_info);
 void test_genlist15(void *data, Evas_Object *obj, void *event_info);
+void test_genlist16(void *data, Evas_Object *obj, void *event_info);
 void test_gesture_layer(void *data, Evas_Object *obj, void *event_info);
 void test_gesture_layer2(void *data, Evas_Object *obj, void *event_info);
 void test_gesture_layer3(void *data, Evas_Object *obj, void *event_info);
@@ -431,6 +432,7 @@ add_tests:
    ADD_TEST(NULL, "Lists", "Genlist Tree, Insert Sorted", test_genlist13);
    ADD_TEST(NULL, "Lists", "Genlist Tree, Insert Relative", test_genlist14);
    ADD_TEST(NULL, "Lists", "Genlist Edit Mode", test_genlist15);
+   ADD_TEST(NULL, "Lists", "Genlist Flip Mode", test_genlist16);
    ADD_TEST(NULL, "Lists", "GenGrid", test_gengrid);
    ADD_TEST(NULL, "Lists", "GenGrid 2", test_gengrid2);
    ADD_TEST(NULL, "Lists", "GenGrid Group", test_gengrid3);
index 2980af4..0f67ec5 100644 (file)
@@ -2485,4 +2485,108 @@ test_genlist15(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_i
    evas_object_resize(win, 520, 520);
    evas_object_show(win);
 }
+
+static void _flip_icon_clicked_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+   const Testitem *tit = data;
+
+   if (elm_genlist_item_flip_get(tit->item))
+     elm_genlist_item_flip_set(tit->item, EINA_FALSE);
+   else
+     elm_genlist_item_flip_set(tit->item, EINA_TRUE);
+}
+
+char *gl16_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
+{
+   const Testitem *tit = data;
+   char buf[256];
+   snprintf(buf, sizeof(buf), "Item #%i", tit->mode);
+   return strdup(buf);
+}
+
+Evas_Object *gl16_content_get(void *data, Evas_Object *obj, const char *part)
+{
+   Testitem *tit = data;
+   char buf[PATH_MAX];
+
+   if (!strcmp(part, "elm.text.flip"))
+     {
+        Evas_Object *btn = elm_button_add(obj);
+        elm_object_text_set(btn, "flipped content placement");
+        evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
+        evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.0);
+        evas_object_smart_callback_add(btn, "clicked", _flip_icon_clicked_cb, (void *)tit);
+        evas_object_show(btn);
+        return btn;
+     }
+   else if (!strcmp(part, "elm.edit.icon.1"))
+     {
+        Evas_Object *icn = elm_icon_add(obj);
+        snprintf(buf, sizeof(buf), "%s/images/icon_04.png", PACKAGE_DATA_DIR);
+        elm_icon_file_set(icn, buf, NULL);
+        evas_object_propagate_events_set(icn, EINA_FALSE);
+        evas_object_size_hint_aspect_set(icn, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+        return icn;
+     }
+   else if (!strcmp(part, "elm.edit.icon.2"))
+     {
+        Evas_Object *icn = elm_icon_add(obj);
+        snprintf(buf, sizeof(buf), "%s/images/icon_09.png", PACKAGE_DATA_DIR);
+        elm_icon_file_set(icn, buf, NULL);
+        evas_object_propagate_events_set(icn, EINA_FALSE);
+        evas_object_size_hint_aspect_set(icn, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+        evas_object_smart_callback_add(icn, "clicked", _flip_icon_clicked_cb, (void *)tit);
+        return icn;
+     }
+   else return NULL;
+}
+
+void
+test_genlist16(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+   Evas_Object *win, *bx, *gl;
+   int i;
+   static Testitem tit[100];
+
+   win = elm_win_util_standard_add("genlist-flip-mode", "Genlist Flip Mode");
+   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);
+
+   gl = elm_genlist_add(win);
+   evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_show(gl);
+
+   elm_genlist_edit_mode_set(gl, EINA_TRUE);
+   elm_genlist_always_select_mode_set(gl, EINA_TRUE);
+
+   itc15 = elm_genlist_item_class_new();
+   itc15->item_style     = "default";
+   itc15->func.text_get = gl16_text_get;
+   itc15->func.content_get = gl16_content_get;
+   itc15->func.state_get = gl_state_get;
+   itc15->func.del       = NULL;
+   itc15->edit_item_style = "edit";
+
+   for (i = 0; i < 100; i++)
+     {
+        tit[i].mode = i;
+        tit[i].item = elm_genlist_item_append(gl, itc15,
+                                              &(tit[i])/* item data */,
+                                              NULL/* parent */,
+                                              ELM_GENLIST_ITEM_NONE/* flags */,
+                                              gl_sel/* func */,
+                                              (void *)(long)&(tit[i])/* func data */);
+     }
+   elm_genlist_item_class_free(itc15);
+   elm_box_pack_end(bx, gl);
+   evas_object_show(bx);
+
+   evas_object_resize(win, 520, 520);
+   evas_object_show(win);
+}
 #endif
index e01925e..185522d 100644 (file)
@@ -71,6 +71,7 @@ struct Elm_Gen_Item
    Eina_Bool                 group : 1;
    Eina_Bool                 reorder : 1;
    Eina_Bool                 mode_set : 1; /* item uses style mode for highlight/select */
+   Eina_Bool                 flipped : 1; /* a flag that shows the flip status of the item. */
 };
 
 typedef struct _Pan Pan;
index 2c97995..b691e15 100644 (file)
@@ -896,7 +896,7 @@ _mouse_move(void        *data,
         if (!it->wd->on_hold)
           {
              it->wd->on_hold = EINA_TRUE;
-             if (!it->wd->wasselected)
+             if ((!it->wd->wasselected) && (!it->flipped))
                {
                   _item_unhighlight(it);
                   _item_unselect(it);
@@ -1367,7 +1367,7 @@ _mouse_up(void        *data,
    if (it->wd->longpressed)
      {
         it->wd->longpressed = EINA_FALSE;
-        if (!it->wd->wasselected)
+        if ((!it->wd->wasselected) && (!it->flipped))
           {
              _item_unhighlight(it);
              _item_unselect(it);
@@ -1625,7 +1625,7 @@ _item_cache_find(Elm_Gen_Item *it)
         if ((itc->tree == tree) &&
             (itc->compress == it->wd->compress) &&
             (((!it->itc->item_style) && (!itc->item_style)) ||
-             (it->itc->item_style && itc->item_style && 
+             (it->itc->item_style && itc->item_style &&
             (!strcmp(it->itc->item_style, itc->item_style)))))
           {
              it->wd->item_cache = eina_inlist_remove(it->wd->item_cache,
@@ -1891,6 +1891,41 @@ _item_state_realize(Elm_Gen_Item *it,
      }
 }
 
+static Eina_List *
+_item_flips_realize(Elm_Gen_Item *it,
+                    Evas_Object *target,
+                    Eina_List **source)
+{
+   Eina_List *res = NULL;
+
+   if (it->itc->func.content_get)
+     {
+        const Eina_List *l;
+        const char *key;
+        Evas_Object *ic = NULL;
+
+        *source = elm_widget_stringlist_get(edje_object_data_get(target, "flips"));
+
+        EINA_LIST_FOREACH(*source, l, key)
+          {
+             if (it->itc->func.content_get)
+               ic = it->itc->func.content_get
+                  ((void *)it->base.data, WIDGET(it), key);
+             if (ic)
+               {
+                  res = eina_list_append(res, ic);
+                  edje_object_part_swallow(target, key, ic);
+                  evas_object_show(ic);
+                  elm_widget_sub_object_add(WIDGET(it), ic);
+                  if (elm_widget_item_disabled_get(it))
+                    elm_widget_disabled_set(ic, EINA_TRUE);
+               }
+          }
+     }
+
+   return res;
+}
+
 static void
 _item_realize(Elm_Gen_Item *it,
               int               in,
@@ -2031,6 +2066,11 @@ _item_realize(Elm_Gen_Item *it,
         _item_text_realize(it, VIEW(it), &it->texts, NULL);
         it->content_objs = _item_content_realize(it, VIEW(it), &it->contents, NULL);
         _item_state_realize(it, VIEW(it), &it->states, NULL);
+        if (it->flipped)
+          {
+             edje_object_signal_emit(VIEW(it), "elm,state,flip,enabled", "elm");
+             it->content_objs = _item_flips_realize(it, VIEW(it), &it->contents);
+          }
 
         if (!it->item->mincalcd)
           {
@@ -3253,6 +3293,7 @@ _edit_mode_item_realize(Elm_Gen_Item *it, Eina_Bool effect_on)
                                   _multi_move, it);
 
    _item_text_realize(it, it->edit_obj, &it->item->edit_texts, NULL);
+   if (it->flipped)  edje_object_signal_emit(it->edit_obj, "elm,state,flip,enabled", "elm");
    it->item->edit_content_objs =
      _item_content_realize(it, it->edit_obj, &it->item->edit_contents, NULL);
    _item_state_realize(it, it->edit_obj, &it->item->edit_states, NULL);
@@ -3286,7 +3327,7 @@ _edit_mode_item_unrealize(Elm_Gen_Item *it)
    elm_widget_stringlist_free(it->item->edit_states);
    it->item->edit_states = NULL;
    EINA_LIST_FREE(it->item->edit_content_objs, icon)
-      evas_object_del(icon);
+     evas_object_del(icon);
    edje_object_message_signal_process(it->edit_obj);
 
    evas_object_event_callback_del_full(it->edit_obj, EVAS_CALLBACK_MOUSE_DOWN,
@@ -5653,6 +5694,48 @@ elm_genlist_item_class_unref(Elm_Genlist_Item_Class *itc)
      }
 }
 
+void _flip_job(void *data)
+{
+   Elm_Gen_Item *it = (Elm_Gen_Item *) data;
+   _elm_genlist_item_unrealize(it, EINA_FALSE);
+   if (it->selected) _item_unselect(it);
+   it->flipped = EINA_TRUE;
+   it->item->nocache = EINA_TRUE;
+}
+
+EAPI void
+elm_genlist_item_flip_set(Elm_Object_Item *it,
+                          Eina_Bool flip)
+{
+   ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
+   Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
+
+   flip = !!flip;
+   if (_it->flipped == flip) return;
+
+   if (flip)
+     {
+        ecore_job_add(_flip_job, _it);
+        if (_it->wd->calc_job) ecore_job_del(_it->wd->calc_job);
+        _it->wd->calc_job = ecore_job_add(_calc_job, _it->wd);
+     }
+   else
+     {
+        _it->flipped = flip;
+        _it->item->nocache = EINA_TRUE;
+        _item_cache_zero(_it->wd);
+        elm_genlist_item_update(it);
+     }
+}
+
+EAPI Eina_Bool
+elm_genlist_item_flip_get(const Elm_Object_Item *it)
+{
+   ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
+   Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
+   return _it->flipped;
+}
+
 /* for gengrid as of now */
 void
 _elm_genlist_page_relative_set(Evas_Object *obj,
index b941c6b..39cecc9 100644 (file)
@@ -1948,5 +1948,38 @@ EAPI void               elm_genlist_edit_mode_set(Evas_Object *obj, Eina_Bool ed
 EAPI Eina_Bool          elm_genlist_edit_mode_get(const Evas_Object *obj);
 
 /**
+ * Set the flip state of a given genlist item.
+ *
+ * @param it The genlist item object
+ * @param flip The flip mode
+ * (EINA_TRUE = on, EINA_FALSE = off)
+ *
+ * This function sets the flip state of a given genlist item.
+ * Flip mode overrides current item object.
+ * It can be used for on-the-fly item replace.
+ *
+ * @see elm_genlist_item_flip_get()
+ *
+ * @ingroup Genlist
+ */
+
+EAPI void elm_genlist_item_flip_set(Elm_Object_Item *it, Eina_Bool flip);
+
+/**
+ * Get the flip state of a given genlist item.
+ *
+ * @param it The genlist item object
+ *
+ * This function returns the flip state of a given genlist item.
+ * If the parameter is invalid, it returns EINA_FALSE.
+ *
+ * @see elm_genlist_item_flip_set()
+ *
+ * @ingroup Genlist
+ */
+
+EAPI Eina_Bool elm_genlist_item_flip_get(const Elm_Object_Item *it);
+
+/**
  * @}
  */