cedric pushed a commit to branch master.

http://git.enlightenment.org/core/elementary.git/commit/?id=0f6e1a46a402fd9cf848ffb1bd47c6b406eb7ffa

commit 0f6e1a46a402fd9cf848ffb1bd47c6b406eb7ffa
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Fri Jan 22 10:44:03 2016 -0800

    combobox: move responsibility to define filter and content to the user of a 
combobox
    
    Before this patch, the filter was set inside the combobox. This is 
confusing for the
    user of the object as it can't define a custom filter except on strings. It 
is also
    impossible to bind as binding require to know what was put in and they 
can't differentiate
    between a genlist filter being set from the binding to one being set 
internally by
    the combobox.
    
    @fix
---
 src/bin/test_combobox.c       | 10 ++++++++++
 src/lib/elc_combobox.c        | 35 ++++++++++++++++++++++++++++-------
 src/lib/elm_combobox.eo       |  1 +
 src/lib/elm_widget_combobox.h |  1 +
 4 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/src/bin/test_combobox.c b/src/bin/test_combobox.c
index 43bd4ef..b8ef5db 100644
--- a/src/bin/test_combobox.c
+++ b/src/bin/test_combobox.c
@@ -86,6 +86,14 @@ gl_filter_get(void *data, Evas_Object *obj EINA_UNUSED, void 
*key)
 }
 
 static void
+_gl_filter_restart_cb(void *data EINA_UNUSED,
+                       Evas_Object *obj,
+                       void *event_info EINA_UNUSED)
+{
+   elm_genlist_filter_set(obj, (void *)elm_object_text_get(obj));
+}
+
+static void
 _gl_filter_finished_cb(void *data EINA_UNUSED,
                        Evas_Object *obj EINA_UNUSED,
                        void *event_info EINA_UNUSED)
@@ -135,6 +143,8 @@ test_combobox(void *data EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED,
                                   _combobox_item_pressed_cb, NULL);
    evas_object_smart_callback_add(combobox, "filter,done",
                                   _gl_filter_finished_cb, NULL);
+   evas_object_smart_callback_add(combobox, "changed",
+                                  _gl_filter_restart_cb, NULL);
    elm_box_pack_end(bx, combobox);
    evas_object_show(combobox);
 
diff --git a/src/lib/elc_combobox.c b/src/lib/elc_combobox.c
index 4076c41..cb2a835 100644
--- a/src/lib/elc_combobox.c
+++ b/src/lib/elc_combobox.c
@@ -179,8 +179,18 @@ _gl_filter_finished_cb(void *data, Eo *obj EINA_UNUSED,
                        const Eo_Event_Description *desc EINA_UNUSED, void 
*event)
 {
    ELM_COMBOBOX_DATA_GET(data, sd);
-   eo_do(data, eo_event_callback_call(ELM_COMBOBOX_EVENT_FILTER_DONE, event));
+
    count_items_genlist(data);
+
+   if (sd->first_filter)
+     {
+        sd->first_filter = EINA_FALSE;
+        elm_combobox_hover_end(data);
+        return EINA_TRUE;
+     }
+
+   eo_do(data, eo_event_callback_call(ELM_COMBOBOX_EVENT_FILTER_DONE, event));
+
    if (sd->count > 0)
      {
         if (sd->expanded == EINA_TRUE)
@@ -204,16 +214,16 @@ static Eina_Bool
 _on_changed(void *data, Eo *obj EINA_UNUSED,
             const Eo_Event_Description *desc EINA_UNUSED, void *event_info 
EINA_UNUSED)
 {
-   elm_combobox_hover_begin(data);
+   eo_do(data, eo_event_callback_call(ELM_ENTRY_EVENT_CHANGED, NULL));
    return EINA_TRUE;
 }
 
 static void
-_on_clicked(void *data,
-            Evas_Object *obj EINA_UNUSED,
+_on_clicked(void *data EINA_UNUSED,
+            Evas_Object *obj,
             void *event_info EINA_UNUSED)
 {
-   elm_combobox_hover_begin(data);
+   elm_combobox_hover_begin(obj);
 }
 
 EOLIAN static void
@@ -275,6 +285,8 @@ _elm_combobox_eo_base_constructor(Eo *obj, 
Elm_Combobox_Data *sd)
 
    eo_do_super(obj, MY_CLASS, eo_constructor());
 
+   sd->first_filter = EINA_TRUE;
+
    eo_do(obj,
          evas_obj_type_set(MY_CLASS_NAME_LEGACY),
          evas_obj_smart_callbacks_descriptions_set(_smart_callbacks),
@@ -302,6 +314,7 @@ _elm_combobox_eo_base_constructor(Eo *obj, 
Elm_Combobox_Data *sd)
 
    // This is the genlist object that will take over the genlist call
    sd->genlist = gl = eo_add(ELM_GENLIST_CLASS, obj);
+   elm_genlist_filter_set(gl, NULL);
    elm_widget_mirrored_automatic_set(gl, EINA_FALSE);
    elm_widget_mirrored_set(gl, elm_widget_mirrored_get(obj));
    evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -340,11 +353,11 @@ _elm_combobox_eo_base_constructor(Eo *obj, 
Elm_Combobox_Data *sd)
 }
 
 EOLIAN static void
-_elm_combobox_hover_begin(Eo *obj EINA_UNUSED, Elm_Combobox_Data *sd)
+_elm_combobox_hover_begin(Eo *obj, Elm_Combobox_Data *sd)
 {
    if (!sd->hover) return;
    elm_object_focus_set(sd->entry, EINA_TRUE);
-   elm_genlist_filter_set(sd->genlist, (void *)elm_object_text_get(sd->entry));
+   _activate(obj);
 }
 
 EOLIAN static void
@@ -437,6 +450,14 @@ 
_elm_combobox_elm_interface_atspi_widget_action_elm_actions_get(Eo *obj EINA_UNU
 }
 
 EOLIAN void
+_elm_combobox_elm_genlist_filter_set(Eo *obj, Elm_Combobox_Data *pd, void *key)
+{
+   pd->first_filter = EINA_FALSE;
+
+   eo_do(pd->genlist, elm_obj_genlist_filter_set(key));
+}
+
+EOLIAN void
 _elm_combobox_elm_widget_part_text_set(Eo *obj EINA_UNUSED, Elm_Combobox_Data 
*pd,
                                        const char * part, const char *label)
 {
diff --git a/src/lib/elm_combobox.eo b/src/lib/elm_combobox.eo
index f189fca..4e13197 100644
--- a/src/lib/elm_combobox.eo
+++ b/src/lib/elm_combobox.eo
@@ -45,6 +45,7 @@ class Elm_Combobox (Elm.Button, Evas.Selectable_Interface,
       Elm.Widget.translate;
       Elm.Widget.event;
       Elm.Button.admits_autorepeat.get;
+      Elm.Genlist.filter.set;
       Elm_Interface_Atspi_Widget_Action.elm_actions.get;
    }
    events {
diff --git a/src/lib/elm_widget_combobox.h b/src/lib/elm_widget_combobox.h
index 80ffe25..f3ec5bf 100644
--- a/src/lib/elm_widget_combobox.h
+++ b/src/lib/elm_widget_combobox.h
@@ -38,6 +38,7 @@ struct _Elm_Combobox_Data
    int                   count;
    int                   item_height;
    Eina_Bool             expanded:1;
+   Eina_Bool             first_filter:1;
 };
 
 /**

-- 


Reply via email to