Languages

Menu
Sites
Language
How to Click checkbox only on the genlist item?

I have developed a genlist. There are two sub-items in each item.

1. text 2. checkbox

/*callback for item text*/ 
static char* item_text_get_cb(void *data, Evas_Object *obj, const char *part)
{
  if (!strcmp("elm.text", part)) 
      return strdup("Sample Text"); 
  return NULL; 
} 
/*create checkbox*/
static Evas_Object* create_check(Evas_Object *parent, void *data)
{
    Evas_Object *check;
    check = elm_check_add(parent);
    evas_object_smart_callback_add(check, "changed", check_changed_item_cb, data);
    return check;
}
/*callback for adding checkbox*/
static Evas_Object* type1_1line_content_get_cb(void *data, Evas_Object *obj, const char *part) 
{ 
  if (!strcmp("elm.swallow.end", part))
      return create_check(obj, data);
  return NULL;
} 
/*create genlist*/ 
create_genlist() 
{ 
itc = elm_genlist_item_class_new();
itc->item_style = "type1"; 
itc->func.content_get = type1_1line_content_get_cb;
itc->func.text_get = item_text_get_cb;

for (int index = 0; index < num_of_rows; index++)
{
it = elm_genlist_item_append(genlist, // genlist object
                             itc, // item class 
                             data, // item class user data 
                             NULL, 
                             ELM_GENLIST_ITEM_NONE, // item type 
                             genlist_item_selected_cb, // select smart callback 
                             data); // smart callback user data 
}

elm_genlist_item_class_free(itc); 
elm_object_part_content_set(layout, PART_HISTORY_CONTENT, genlist); 
} /*end of genlist creation*/

I need to separate both genlist item selection and checkbox change callback.

Problem is, when I press checkbox, it calls two callback. One for checkbox changed another for genlist item selection. How can I stop calling genlist item selection when changing (select/de-select) checkbox?

Don't ask me to set elm_genlist_no_select_mode_set(). I also need this selection.

Edited by: Mohammad Nur Nobi on 08 Nov, 2015
View Selected Answer

Responses

4 Replies
Alex Dem

Hi,
I am not sure that it is good solution (to use timer for such cases do not good definitely ), but should works. You could use timer and try to add/delete "selected" callback for genlist every time after checkbox was set. Here 2 methods should be modified, 1 should be added.

Eina_Bool ecore_timer_cb(void *data)
{
    Evas_Object * genlist = (Evas_Object * )data;
    Elm_Object_Item * it = elm_genlist_selected_item_get(genlist);
    elm_genlist_item_selected_set(it, EINA_FALSE);
    evas_object_smart_callback_add(genlist, "selected", gl_selected_cb, NULL);
    return ECORE_CALLBACK_CANCEL;
}

static void
check_changed_item_cb(void *data, Evas_Object *obj, void *event_info)
{
    Evas_Object * genlist = (Evas_Object * )data;
    evas_object_smart_callback_del(genlist, "selected", gl_selected_cb);
    ecore_timer_add(0.1, ecore_timer_cb, genlist);
}

/*create checkbox*/
static Evas_Object* create_check(Evas_Object *parent, void *data)
{
    Evas_Object *check;
    check = elm_check_add(parent);
    evas_object_smart_callback_add(check, "changed", check_changed_item_cb, parent);
    return check;
}


p.s. Also important note: it is possible because of checkbox "changed" callback comes before genlist "selected" callback (checked on emulator).
Also when you click on "checkbox" is whole item is selected and possible to unselect it only in ecore_timer_cb.
Alexey.

Mohammad Nur Nobi

May be it will be work. I think, in this specific case, timer will not be good practice as user may click single checkbox multiple time. 

However, adding properties evas_object_propagate_events_set(check, EINA_FALSE) to checkbox creation resolve this problem.

By the way, I appreciate your quick alternative solution.

 

Mark as answer
Jeongsu Kim

add evas_object_propagate_events_set(check, EINA_FALSE);  to create_check().
Genlist item selected callback is called because check propagate its event to parent. That api prevents this behavior.
But you should notice that genlist item can be selected because checkbox is not big enough to get touch event.
(In this case, genlist item will be selected instead of checkbox.)

 

/*create checkbox*/
static Evas_Object* create_check(Evas_Object *parent, void *data)
{
    Evas_Object *check;
    check = elm_check_add(parent);
    evas_object_smart_callback_add(check, "changed", check_changed_item_cb, data);
    evas_object_propagate_events_set(check, EINA_FALSE);
    return check;
}

 

Mohammad Nur Nobi

Hi

Thank you for the suggestion.

Its working superb with evas_object_propagate_events_set(check, EINA_FALSE); :)

Happy to get rid myself from this stucking point.

Appreciate your co-operation :)