void test_icon(void *data, Evas_Object *obj, void *event_info);
void test_box_vert(void *data, Evas_Object *obj, void *event_info);
void test_box_vert2(void *data, Evas_Object *obj, void *event_info);
+void test_box_pack(void *data, Evas_Object *obj, void *event_info);
void test_box_horiz(void *data, Evas_Object *obj, void *event_info);
+void test_box_homo(void *data, Evas_Object *obj, void *event_info);
void test_box_transition(void *data, Evas_Object *obj, void *event_info);
void test_button(void *data, Evas_Object *obj, void *event_info);
void test_cnp(void *data, Evas_Object *obj, void *event_info);
//------------------------------//
ADD_TEST(NULL, "Containers", "Box Vert", test_box_vert);
ADD_TEST(NULL, "Containers", "Box Vert 2", test_box_vert2);
+ ADD_TEST(NULL, "Containers", "Box Pack", test_box_pack);
ADD_TEST(NULL, "Containers", "Box Horiz", test_box_horiz);
+ ADD_TEST(NULL, "Containers", "Box Homogeneous", test_box_homo);
ADD_TEST(NULL, "Containers", "Box Transition", test_box_transition);
ADD_TEST(NULL, "Containers", "Table", test_table);
ADD_TEST(NULL, "Containers", "Table Homogeneous", test_table2);
# include "elementary_config.h"
#endif
#ifndef ELM_LIB_QUICKLAUNCH
+
+typedef enum
+{
+ BOX_PACK_POSITION_START,
+ BOX_PACK_POSITION_BEFORE,
+ BOX_PACK_POSITION_AFTER,
+ BOX_PACK_POSITION_END
+} _Box_Pack_Position;
+
void
test_box_vert(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
{
evas_object_show(win);
}
+static void
+_unpack_btn_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Evas_Object *box, *radio;
+ Eina_List *rl, *l;
+ int value, svalue;
+
+ box = (Evas_Object *) data;
+
+ rl = (Eina_List *) evas_object_data_get(box, "radio-list");
+ EINA_LIST_FOREACH(rl, l, radio)
+ {
+ value = elm_radio_value_get(radio);
+ svalue = elm_radio_state_value_get(radio);
+
+ if (value != svalue) continue;
+
+ elm_radio_value_set(radio, -1);
+ elm_box_unpack(box, radio);
+ rl = eina_list_remove(rl, radio);
+ evas_object_data_set(box, "radio-list", rl);
+ evas_object_del(radio);
+ }
+}
+
+static void
+_unpack_all_btn_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Evas_Object *box, *radio;
+ Eina_List *rl, *l;
+
+ box = (Evas_Object *) data;
+ elm_box_unpack_all(box);
+
+ rl = (Eina_List *) evas_object_data_get(box, "radio-list");
+ EINA_LIST_FOREACH(rl, l, radio) evas_object_del(radio);
+
+ evas_object_data_del(box, "radio-list");
+ eina_list_free(rl);
+}
+
+static Evas_Object *
+_radio_new(Evas_Object *obj, int index)
+{
+ Evas_Object *ic, *rd;
+ char buf[PATH_MAX];
+
+ ic = elm_icon_add(obj);
+ snprintf(buf, sizeof(buf), "%s/images/icon_0%d.png",
+ elm_app_data_dir_get(), index);
+ elm_icon_file_set(ic, buf, NULL);
+ evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+
+ rd = elm_radio_add(obj);
+ elm_radio_state_value_set(rd, index);
+ evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(rd, EVAS_HINT_FILL, 0.5);
+ elm_object_part_content_set(rd, "icon", ic);
+
+ evas_object_show(rd);
+ evas_object_show(ic);
+
+ return rd;
+}
+
+static void
+_pack(Evas_Object *box, _Box_Pack_Position pos)
+{
+ Evas_Object *radio;
+ Evas_Object *rd, *rdg = NULL;
+ Eina_List *rl, *l = NULL;
+ int value, svalue, count;
+
+ rl = (Eina_List *) evas_object_data_get(box, "radio-list");
+ if (!rl && (pos == BOX_PACK_POSITION_START || pos == BOX_PACK_POSITION_END))
+ {
+ rd = _radio_new(box, 0);
+ if (pos == BOX_PACK_POSITION_START) elm_box_pack_start(box, rd);
+ else elm_box_pack_end(box, rd);
+
+ l = eina_list_append(l, rd);
+ evas_object_data_set(box, "radio-list", l);
+
+ rdg = rd;
+ evas_object_data_set(box, "radio-group", rdg);
+
+ return;
+ }
+
+ count = eina_list_count(rl);
+ EINA_LIST_FOREACH(rl, l, radio)
+ {
+ value = elm_radio_value_get(radio);
+ svalue = elm_radio_state_value_get(radio);
+
+ if (value != svalue) continue;
+
+ rd = _radio_new(box, count);
+
+ switch(pos)
+ {
+ case BOX_PACK_POSITION_START:
+ elm_box_pack_start(box, rd);
+ break;
+ case BOX_PACK_POSITION_BEFORE:
+ elm_box_pack_before(box, rd, radio);
+ break;
+ case BOX_PACK_POSITION_AFTER:
+ elm_box_pack_after(box, rd, radio);
+ break;
+ case BOX_PACK_POSITION_END:
+ elm_box_pack_end(box, rd);
+ break;
+ }
+
+ rdg = evas_object_data_get(box, "radio-group");
+ elm_radio_group_add(rd, rdg);
+
+ rl = eina_list_append(rl, rd);
+ evas_object_data_set(box, "radio-list", rl);
+ }
+}
+
+static void
+_pack_start_btn_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Evas_Object *box;
+ if (!data) return;
+
+ box = (Evas_Object *) data;
+ _pack(box, BOX_PACK_POSITION_START);
+}
+
+static void
+_pack_before_btn_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Evas_Object *box;
+ if (!data) return;
+
+ box = (Evas_Object *) data;
+ _pack(box, BOX_PACK_POSITION_BEFORE);
+}
+
+static void
+_pack_after_btn_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Evas_Object *box;
+ if (!data) return;
+
+ box = (Evas_Object *) data;
+ _pack(box, BOX_PACK_POSITION_AFTER);
+}
+
+static void
+_pack_end_btn_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Evas_Object *box;
+ if (!data) return;
+
+ box = (Evas_Object *) data;
+ _pack(box, BOX_PACK_POSITION_END);
+}
+
+void
+test_box_pack(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Evas_Object *win, *bg;
+ Evas_Object *box, *lbox, *rbox;
+ Evas_Object *sc;
+ Evas_Object *bt;
+ Evas_Object *rd, *rdg = NULL;
+ Eina_List *l = NULL;
+ int i;
+
+ win = elm_win_add(NULL, "box-pack", ELM_WIN_BASIC);
+ elm_win_title_set(win, "Box Pack");
+ elm_win_autodel_set(win, EINA_TRUE);
+
+ bg = elm_bg_add(win);
+ evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(win, bg);
+ evas_object_show(bg);
+
+ box = elm_box_add(win);
+ elm_box_horizontal_set(box, EINA_TRUE);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_win_resize_object_add(win, box);
+ evas_object_show(box);
+
+ // left side
+ lbox = elm_box_add(win);
+ evas_object_size_hint_weight_set(lbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(lbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ sc = elm_scroller_add(win);
+ elm_scroller_bounce_set(sc, 0, 1);
+ evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(sc, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ for(i = 0; i < 3; i++)
+ {
+ rd = _radio_new(win, i);
+ elm_box_pack_end(lbox, rd);
+ l = eina_list_append(l, rd);
+ if (i == 0) rdg = rd;
+ else elm_radio_group_add(rd, rdg);
+ }
+
+ evas_object_data_set(lbox, "radio-list", l);
+ evas_object_data_set(lbox, "radio-group", rdg);
+ elm_object_content_set(sc, lbox);
+ evas_object_show(lbox);
+ elm_box_pack_end(box, sc);
+ evas_object_show(sc);
+
+ // right side
+ rbox = elm_box_add(win);
+ evas_object_size_hint_weight_set(rbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(rbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(rbox);
+ elm_box_pack_end(box, rbox);
+
+ bt = elm_button_add(win);
+ elm_object_text_set(bt, "Pack Start");
+ evas_object_show(bt);
+ elm_box_pack_end(rbox, bt);
+ evas_object_smart_callback_add(bt, "clicked", _pack_start_btn_cb, lbox);
+
+ bt = elm_button_add(win);
+ elm_object_text_set(bt, "Pack Before");
+ evas_object_show(bt);
+ elm_box_pack_end(rbox, bt);
+ evas_object_smart_callback_add(bt, "clicked", _pack_before_btn_cb, lbox);
+
+ bt = elm_button_add(win);
+ elm_object_text_set(bt, "Pack After");
+ evas_object_show(bt);
+ elm_box_pack_end(rbox, bt);
+ evas_object_smart_callback_add(bt, "clicked", _pack_after_btn_cb, lbox);
+
+ bt = elm_button_add(win);
+ elm_object_text_set(bt, "Pack End");
+ evas_object_show(bt);
+ elm_box_pack_end(rbox, bt);
+ evas_object_smart_callback_add(bt, "clicked", _pack_end_btn_cb, lbox);
+
+ bt = elm_button_add(win);
+ elm_object_text_set(bt, "Unpack");
+ evas_object_show(bt);
+ elm_box_pack_end(rbox, bt);
+ evas_object_smart_callback_add(bt, "clicked", _unpack_btn_cb, lbox);
+
+ bt = elm_button_add(win);
+ elm_object_text_set(bt, "Unpack All");
+ evas_object_show(bt);
+ elm_box_pack_end(rbox, bt);
+ evas_object_smart_callback_add(bt, "clicked", _unpack_all_btn_cb, lbox);
+
+ evas_object_resize(win, 320, 320);
+ evas_object_show(win);
+}
+
+static void
+_cb_check_changed(void *data, Evas_Object *obj, void *event __UNUSED__)
+{
+ Eina_Bool homo;
+ Evas_Object *box = data;
+
+ homo = elm_check_state_get(obj);
+ elm_box_homogeneous_set(box, homo);
+
+}
+
+void
+test_box_homo(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Evas_Object *win, *bg;
+ Evas_Object *box, *o_bg;
+ Evas_Object *rd;
+ char buf[PATH_MAX];
+
+ win = elm_win_add(NULL, "box-homogeneous", ELM_WIN_BASIC);
+ elm_win_title_set(win, "Box Homogeneous");
+ elm_win_autodel_set(win, EINA_TRUE);
+
+ bg = elm_bg_add(win);
+ evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(win, bg);
+ evas_object_show(bg);
+
+ box = elm_box_add(win);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(win, box);
+ evas_object_show(box);
+
+ o_bg = elm_bg_add(win);
+ snprintf(buf, sizeof(buf), "%s/images/twofish.jpg", elm_app_data_dir_get());
+ elm_bg_file_set(o_bg, buf, NULL);
+ evas_object_size_hint_weight_set(o_bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(o_bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_box_pack_end(box, o_bg);
+
+ rd = elm_check_add(win);
+ elm_object_text_set(rd, "Homogeneous");
+ evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
+ evas_object_smart_callback_add(rd, "changed", _cb_check_changed, box);
+ elm_box_pack_end(box, rd);
+ evas_object_show(rd);
+
+ evas_object_show(o_bg);
+ evas_object_size_hint_min_set(bg, 160, 160);
+ evas_object_size_hint_max_set(bg, 640, 640);
+ evas_object_resize(win, 320, 320);
+ evas_object_show(win);
+}
+
typedef struct
{
Eina_List *transitions;
} Testitem;
-static Elm_Genlist_Item_Class itc1;
+static Elm_Genlist_Item_Class *itc1;
char *gl_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
{
char buf[256];
evas_object_size_hint_weight_set(over, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, over);
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = gl_content_get;
- itc1.func.state_get = gl_state_get;
- itc1.func.del = gl_del;
+ itc1 = elm_genlist_item_class_new();
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = gl_content_get;
+ itc1->func.state_get = gl_state_get;
+ itc1->func.del = gl_del;
bt_50 = elm_button_add(win);
elm_object_text_set(bt_50, "Go to 50");
for (i = 0; i < 2000; i++)
{
- gli = elm_genlist_item_append(gl, &itc1,
+ gli = elm_genlist_item_append(gl, itc1,
(void *)(long)i/* item data */,
NULL/* parent */,
ELM_GENLIST_ITEM_NONE,
else if (i == 1500)
evas_object_smart_callback_add(bt_1500, "clicked", _bt1500_cb, gli);
}
+ elm_genlist_item_class_free(itc1);
+
evas_object_resize(win, 480, 800);
evas_object_show(win);
}
Evas_Object *gl = data;
static int i = 0;
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = gl_content_get;
- itc1.func.state_get = gl_state_get;
- itc1.func.del = gl_del;
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = gl_content_get;
+ itc1->func.state_get = gl_state_get;
+ itc1->func.del = gl_del;
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)(long)i/* item data */,
NULL/* parent */,
ELM_GENLIST_ITEM_NONE,
static int i = 0;
Elm_Object_Item *gli_selected;
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = gl_content_get;
- itc1.func.state_get = gl_state_get;
- itc1.func.del = gl_del;
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = gl_content_get;
+ itc1->func.state_get = gl_state_get;
+ itc1->func.del = gl_del;
gli_selected = elm_genlist_selected_item_get(gl);
if (!gli_selected)
return ;
}
- elm_genlist_item_insert_before(gl, &itc1,
+ elm_genlist_item_insert_before(gl, itc1,
(void *)(long)i/* item data */,
NULL/* parent */,
gli_selected /* item before */,
static int i = 0;
Elm_Object_Item *gli_selected;
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = gl_content_get;
- itc1.func.state_get = gl_state_get;
- itc1.func.del = gl_del;
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = gl_content_get;
+ itc1->func.state_get = gl_state_get;
+ itc1->func.del = gl_del;
gli_selected = elm_genlist_selected_item_get(gl);
if (!gli_selected)
return ;
}
- elm_genlist_item_insert_after(gl, &itc1,
+ elm_genlist_item_insert_after(gl, itc1,
(void *)(long)i/* item data */,
NULL/* parent */,
gli_selected /* item after */,
evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(gl);
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = gl_content_get;
- itc1.func.state_get = gl_state_get;
- itc1.func.del = gl_del;
+ itc1 = elm_genlist_item_class_new();
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = gl_content_get;
+ itc1->func.state_get = gl_state_get;
+ itc1->func.del = gl_del;
- gli[0] = elm_genlist_item_append(gl, &itc1,
+ gli[0] = elm_genlist_item_append(gl, itc1,
(void *)1001/* item data */, NULL/* parent */, ELM_GENLIST_ITEM_NONE, gl_sel/* func */,
(void *)1001/* func data */);
- gli[1] = elm_genlist_item_append(gl, &itc1,
+ gli[1] = elm_genlist_item_append(gl, itc1,
(void *)1002/* item data */, NULL/* parent */, ELM_GENLIST_ITEM_NONE, gl_sel/* func */,
(void *)1002/* func data */);
- gli[2] = elm_genlist_item_append(gl, &itc1,
+ gli[2] = elm_genlist_item_append(gl, itc1,
(void *)1003/* item data */, NULL/* parent */, ELM_GENLIST_ITEM_NONE, gl_sel/* func */,
(void *)1003/* func data */);
- gli[3] = elm_genlist_item_prepend(gl, &itc1,
+ gli[3] = elm_genlist_item_prepend(gl, itc1,
(void *)1004/* item data */, NULL/* parent */, ELM_GENLIST_ITEM_NONE, gl_sel/* func */,
(void *)1004/* func data */);
- gli[4] = elm_genlist_item_prepend(gl, &itc1,
+ gli[4] = elm_genlist_item_prepend(gl, itc1,
(void *)1005/* item data */, NULL/* parent */, ELM_GENLIST_ITEM_NONE, gl_sel/* func */,
(void *)1005/* func data */);
- gli[5] = elm_genlist_item_insert_before(gl, &itc1,
+ gli[5] = elm_genlist_item_insert_before(gl, itc1,
(void *)1006/* item data */, NULL/* parent */, gli[2]/* rel */, ELM_GENLIST_ITEM_NONE,
gl_sel/* func */, (void *)1006/* func data */);
- gli[6] = elm_genlist_item_insert_after(gl, &itc1,
+ gli[6] = elm_genlist_item_insert_after(gl, itc1,
(void *)1007/* item data */, NULL/* parent */, gli[2]/* rel */, ELM_GENLIST_ITEM_NONE,
gl_sel/* func */, (void *)1007/* func data */);
-
elm_box_pack_end(bx, gl);
bx2 = elm_box_add(win);
elm_box_pack_end(bx, bx3);
evas_object_show(bx3);
+ /* item_class_ref is needed for itc1. some items can be added in callbacks */
+ elm_genlist_item_class_ref(itc1);
+ elm_genlist_item_class_free(itc1);
evas_object_resize(win, 320, 320);
evas_object_show(win);
elm_box_pack_end(bx, gl);
evas_object_show(gl);
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = gl_content_get;
- itc1.func.state_get = gl_state_get;
- itc1.func.del = gl_del;
+ itc1 = elm_genlist_item_class_new();
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = gl_content_get;
+ itc1->func.state_get = gl_state_get;
+ itc1->func.del = gl_del;
itc_group.item_style = "group_index";
itc_group.func.text_get = gl8_text_get;
}
else if (git)
{
- gli = elm_genlist_item_append(gl, &itc1,
+ gli = elm_genlist_item_append(gl, itc1,
(void *)(long)i/* item data */,
git/* parent */,
ELM_GENLIST_ITEM_NONE,
break;
}
}
+ elm_genlist_item_class_free(itc1);
evas_object_resize(win, 480, 800);
evas_object_show(win);
Evas_Object *gl = elm_object_item_widget_get(glit);
int val = (int)(long) elm_object_item_data_get(glit);
val *= 10;
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)(long) (val + 1)/* item data */,
glit/* parent */,
ELM_GENLIST_ITEM_NONE, gl4_sel/* func */,
NULL/* func data */);
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)(long) (val + 2)/* item data */,
glit/* parent */,
ELM_GENLIST_ITEM_NONE, gl4_sel/* func */,
NULL/* func data */);
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)(long) (val + 3)/* item data */,
glit/* parent */,
ELM_GENLIST_ITEM_SUBITEMS, gl4_sel/* func */,
elm_box_pack_end(bx, gl);
evas_object_show(gl);
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = gl_content_get;
- itc1.func.state_get = gl_state_get;
- itc1.func.del = gl_del;
+ itc1 = elm_genlist_item_class_new();
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = gl_content_get;
+ itc1->func.state_get = gl_state_get;
+ itc1->func.del = gl_del;
itc_group.item_style = "group_index";
itc_group.func.text_get = gl8_text_get;
(void *)0/* item data */, NULL/* parent */, ELM_GENLIST_ITEM_GROUP, gl4_sel/* func */,
NULL/* func data */);
elm_genlist_item_display_only_set(git, EINA_TRUE);
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)1/* item data */, git/* parent */, ELM_GENLIST_ITEM_SUBITEMS, gl4_sel/* func */,
NULL/* func data */);
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)2/* item data */, git/* parent */, ELM_GENLIST_ITEM_NONE, gl4_sel/* func */,
NULL/* func data */);
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)3/* item data */, git/* parent */, ELM_GENLIST_ITEM_SUBITEMS, gl4_sel/* func */,
NULL/* func data */);
git = elm_genlist_item_append(gl, &itc_group,
(void *)4/* item data */, NULL/* parent */, ELM_GENLIST_ITEM_GROUP, gl4_sel/* func */,
NULL/* func data */);
elm_genlist_item_display_only_set(git, EINA_TRUE);
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)5/* item data */, git/* parent */, ELM_GENLIST_ITEM_SUBITEMS, gl4_sel/* func */,
NULL/* func data */);
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)6/* item data */, git/* parent */, ELM_GENLIST_ITEM_NONE, gl4_sel/* func */,
NULL/* func data */);
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)7/* item data */, git/* parent */, ELM_GENLIST_ITEM_SUBITEMS, gl4_sel/* func */,
NULL/* func data */);
+ elm_genlist_item_class_free(itc1);
evas_object_smart_callback_add(gl, "expand,request", gl9_exp_req, gl);
evas_object_smart_callback_add(gl, "contract,request", gl9_con_req, gl);
elm_box_pack_end(bx, tg);
evas_object_show(tg);
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = gl_content_get;
- itc1.func.state_get = gl_state_get;
- itc1.func.del = gl_del;
+ itc1 = elm_genlist_item_class_new();
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = gl_content_get;
+ itc1->func.state_get = gl_state_get;
+ itc1->func.del = gl_del;
evas_object_smart_callback_add(gl, "moved", (Evas_Smart_Cb)gl_moved, gl);
for (i = 0; i < 50; i++)
elm_genlist_item_append(gl,
- &itc1,
+ itc1,
(void *)(1 + i)/* item data */,
NULL/* parent */,
ELM_GENLIST_ITEM_NONE/* flags */,
NULL/* func */,
NULL/* func data */);
+ elm_genlist_item_class_free(itc1);
+
elm_box_pack_end(bx, gl);
evas_object_resize(win, 400, 500);
elm_box_pack_end(bx, gl);
evas_object_show(gl);
- itc1.item_style = "message";
- itc1.func.text_get = gl12_text_get;
- itc1.func.content_get = gl_content_get;
- itc1.func.state_get = gl_state_get;
- itc1.func.del = gl_del;
+ itc1->item_style = "message";
+ itc1->func.text_get = gl12_text_get;
+ itc1->func.content_get = gl_content_get;
+ itc1->func.state_get = gl_state_get;
+ itc1->func.del = gl_del;
for (i = 0; i < 1000; i++)
{
- elm_genlist_item_append(gl, &itc1,
+ elm_genlist_item_append(gl, itc1,
(void *)(long)i/* item data */,
NULL/* parent */,
ELM_GENLIST_ITEM_NONE,
gl_sel/* func */,
(void *)(long)(i * 10)/* func data */);
}
+ elm_genlist_item_class_free(itc1);
evas_object_resize(win, 400, 500);
evas_object_show(win);
static int i = 1000;
Elm_Object_Item *gli_selected;
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = NULL;
- itc1.func.state_get = NULL;
- itc1.func.del = NULL;
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = NULL;
+ itc1->func.state_get = NULL;
+ itc1->func.del = NULL;
gli_selected = elm_genlist_selected_item_get(gl);
if (!gli_selected)
return;
}
- elm_genlist_item_insert_before(gl, &itc1,
+ elm_genlist_item_insert_before(gl, itc1,
(void *)(long)i/* item data */,
elm_genlist_item_parent_get(gli_selected),
gli_selected/* item before */,
static int i = 0;
Elm_Object_Item *gli_selected;
- itc1.item_style = "default";
- itc1.func.text_get = gl_text_get;
- itc1.func.content_get = NULL;
- itc1.func.state_get = NULL;
- itc1.func.del = NULL;
+ itc1->item_style = "default";
+ itc1->func.text_get = gl_text_get;
+ itc1->func.content_get = NULL;
+ itc1->func.state_get = NULL;
+ itc1->func.del = NULL;
gli_selected = elm_genlist_selected_item_get(gl);
if (!gli_selected)
return;
}
- elm_genlist_item_insert_after(gl, &itc1,
+ elm_genlist_item_insert_after(gl, itc1,
(void *)(long)i/* item data */,
elm_genlist_item_parent_get(gli_selected),
gli_selected/* item after */,
evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(gl);
+ itc1 = elm_genlist_item_class_new();
+
itc4.item_style = "default";
itc4.func.text_get = gl4_text_get;
itc4.func.content_get = NULL;
elm_box_pack_end(bx, bx2);
evas_object_show(bx2);
+ /* item_class_ref is needed for itc1. some items can be added in callbacks */
+ elm_genlist_item_class_ref(itc1);
+ elm_genlist_item_class_free(itc1);
+
evas_object_resize(win, 320, 320);
evas_object_show(win);
}
}
// store callbacks to handle loading/parsing/freeing of store items from src
-static Elm_Genlist_Item_Class itc1 =
-{
- "message", { NULL, NULL, NULL, NULL}
-};
+static Elm_Genlist_Item_Class *itc1;
static const Elm_Store_Item_Mapping it1_mapping[] =
{
// choose the item genlist item class to use (only item style should be
// provided by the app, store will fill everything else in, so it also
// has to be writable
- info->base.item_class = &itc1; // based on item info - return the item class wanted (only style field used - rest reset to internal funcs store sets up to get label/icon etc)
+ info->base.item_class = itc1; // based on item info - return the item class wanted (only style field used - rest reset to internal funcs store sets up to get label/icon etc)
info->base.mapping = it1_mapping;
info->base.data = NULL; // if we can already parse and load all of item here and want to - set this
return EINA_TRUE; // return true to include this, false not to
elm_box_pack_end(bx, gl);
evas_object_show(gl);
+ itc1 = elm_genlist_item_class_new();
+ itc1->item_style = "message";
+
st = elm_store_filesystem_new();
elm_store_list_func_set(st, _st_store_list, NULL);
elm_store_fetch_func_set(st, _st_store_fetch, NULL);
elm_store_target_genlist_set(st, gl);
elm_store_filesystem_directory_set(st, "./store");
+ /* item_class_ref is needed for itc1. some items can be added in callbacks */
+ elm_genlist_item_class_ref(itc1);
+ elm_genlist_item_class_free(itc1);
+
evas_object_resize(win, 480, 800);
evas_object_show(win);
}
ELM_FILE_LAST
} Elm_Fileselector_Type;
-static Elm_Genlist_Item_Class list_itc[ELM_FILE_LAST] = {
- { "default", { NULL, NULL, NULL, NULL } },
- { "default", { NULL, NULL, NULL, NULL } },
- { "default", { NULL, NULL, NULL, NULL } }
-};
+static Elm_Genlist_Item_Class *list_itc[ELM_FILE_LAST];
static Elm_Gengrid_Item_Class grid_itc[ELM_FILE_LAST] = {
- { "default", { NULL, NULL, NULL, NULL } },
- { "default", { NULL, NULL, NULL, NULL } },
- { "default", { NULL, NULL, NULL, NULL } }
+ { ELM_GENGRID_ITEM_CLASS_HEADER, "default", { NULL, NULL, NULL, NULL } },
+ { ELM_GENGRID_ITEM_CLASS_HEADER, "default", { NULL, NULL, NULL, NULL } },
+ { ELM_GENGRID_ITEM_CLASS_HEADER, "default", { NULL, NULL, NULL, NULL } },
};
static const char *widtype = NULL;
wd = elm_widget_data_get(obj);
if (!wd) return;
+ elm_genlist_item_class_free(list_itc[ELM_DIRECTORY]);
+ elm_genlist_item_class_free(list_itc[ELM_FILE_IMAGE]);
+ elm_genlist_item_class_free(list_itc[ELM_FILE_UNKNOW]);
+
#ifdef HAVE_EIO
if (wd->current)
eio_file_cancel(wd->current);
if (info->type == EINA_FILE_DIR)
{
eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_DIRECTORY], NULL);
- eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_DIRECTORY], NULL);
+ eio_file_associate_direct_add(handler, "type/list", list_itc[ELM_DIRECTORY], NULL);
}
else
{
if (evas_object_image_extension_can_load_get(info->path + info->name_start))
{
eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_IMAGE], NULL);
- eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_IMAGE], NULL);
+ eio_file_associate_direct_add(handler, "type/list", list_itc[ELM_FILE_IMAGE], NULL);
}
else
{
eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_UNKNOW], NULL);
- eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_UNKNOW], NULL);
+ eio_file_associate_direct_add(handler, "type/list", list_itc[ELM_FILE_UNKNOW], NULL);
}
}
const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
- if (ca == &list_itc[ELM_DIRECTORY])
+ if (ca == list_itc[ELM_DIRECTORY])
{
- if (cb != &list_itc[ELM_DIRECTORY])
+ if (cb != list_itc[ELM_DIRECTORY])
return -1;
}
- else if (cb == &list_itc[ELM_DIRECTORY])
+ else if (cb == list_itc[ELM_DIRECTORY])
{
return 1;
}
if (wr->wd->mode == ELM_FILESELECTOR_LIST)
{
- Eina_Bool is_dir = (eio_file_associate_find(handler, "type/list") == &list_itc[ELM_DIRECTORY]);
+ Eina_Bool is_dir = (eio_file_associate_find(handler, "type/list") == list_itc[ELM_DIRECTORY]);
elm_genlist_item_direct_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
EINA_LIST_FREE(dirs, real)
{
if (wd->mode == ELM_FILESELECTOR_LIST)
- elm_genlist_item_append(wd->files_list, &list_itc[ELM_DIRECTORY],
+ elm_genlist_item_append(wd->files_list, list_itc[ELM_DIRECTORY],
real, /* item data */
parent,
wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
if (wd->mode == ELM_FILESELECTOR_LIST)
- elm_genlist_item_append(wd->files_list, &list_itc[type],
+ elm_genlist_item_append(wd->files_list, list_itc[type],
real, /* item data */
parent, ELM_GENLIST_ITEM_NONE,
NULL, NULL);
elm_widget_sub_object_add(obj, bt);
wd->home_button = bt;
- list_itc[ELM_DIRECTORY].func.content_get = grid_itc[ELM_DIRECTORY].func.content_get = _itc_icon_folder_get;
- list_itc[ELM_FILE_IMAGE].func.content_get = grid_itc[ELM_FILE_IMAGE].func.content_get = _itc_icon_image_get;
- list_itc[ELM_FILE_UNKNOW].func.content_get = grid_itc[ELM_FILE_UNKNOW].func.content_get = _itc_icon_file_get;
+ list_itc[ELM_DIRECTORY] = elm_genlist_item_class_new();
+ list_itc[ELM_FILE_IMAGE] = elm_genlist_item_class_new();
+ list_itc[ELM_FILE_UNKNOW] = elm_genlist_item_class_new();
+
+ list_itc[ELM_DIRECTORY]->func.content_get = grid_itc[ELM_DIRECTORY].func.content_get = _itc_icon_folder_get;
+ list_itc[ELM_FILE_IMAGE]->func.content_get = grid_itc[ELM_FILE_IMAGE].func.content_get = _itc_icon_image_get;
+ list_itc[ELM_FILE_UNKNOW]->func.content_get = grid_itc[ELM_FILE_UNKNOW].func.content_get = _itc_icon_file_get;
for (i = 0; i < ELM_FILE_LAST; ++i)
{
- list_itc[i].func.text_get = grid_itc[i].func.text_get = _itc_text_get;
- list_itc[i].func.state_get = grid_itc[i].func.state_get = _itc_state_get;
- list_itc[i].func.del = grid_itc[i].func.del = _itc_del;
+ list_itc[i]->item_style = "default";
+ list_itc[i]->func.text_get = grid_itc[i].func.text_get = _itc_text_get;
+ list_itc[i]->func.state_get = grid_itc[i].func.state_get = _itc_state_get;
+ list_itc[i]->func.del = grid_itc[i].func.del = _itc_del;
}
li = elm_genlist_add(parent);
typedef void (*Elm_Gen_Item_Del_Cb)(void *data, Evas_Object *obj); /**< Deletion class function for gen item classes. */
struct _Elm_Gen_Item_Class
{
+ int version;
+ unsigned int refcount;
+ Eina_Bool delete_me : 1;
const char *item_style;
struct _Elm_Gen_Item_Class_Func
{
*/
typedef struct _Elm_Gengrid_Item_Class Elm_Gengrid_Item_Class; /**< Gengrid item class definition structs */
+#define ELM_GENGRID_ITEM_CLASS_HEADER 0, 0, 0
+
#define Elm_Gengrid_Item_Class Elm_Gen_Item_Class
typedef struct _Elm_Gengrid_Item_Class_Func Elm_Gengrid_Item_Class_Func; /**< Class functions for gengrid item classes. */
it->parent->item->items = eina_list_remove(it->parent->item->items, it);
if (it->item->swipe_timer) ecore_timer_del(it->item->swipe_timer);
_elm_genlist_item_del_serious(it);
+ elm_genlist_item_class_unref((Elm_Genlist_Item_Class *)it->itc);
evas_event_thaw(evas_object_evas_get(obj));
evas_event_thaw_eval(evas_object_evas_get(obj));
}
it->wd = wd;
it->generation = wd->generation;
it->itc = itc;
+ elm_genlist_item_class_ref((Elm_Genlist_Item_Class *)itc);
it->base.data = data;
it->parent = parent;
it->func.func = func;
return _it->item->flags;
}
+EAPI Elm_Genlist_Item_Class *
+elm_genlist_item_class_new(void)
+{
+ Elm_Genlist_Item_Class *itc;
+
+ itc = calloc(1, sizeof(Elm_Genlist_Item_Class));
+ if (!itc)
+ return NULL;
+ itc->version = ELM_GENLIST_ITEM_CLASS_VERSION;
+ itc->refcount = 1;
+ itc->delete_me = EINA_FALSE;
+
+ return itc;
+}
+
+EAPI void
+elm_genlist_item_class_free(Elm_Genlist_Item_Class *itc)
+{
+ if (itc && (itc->version == ELM_GENLIST_ITEM_CLASS_VERSION))
+ {
+ if (!itc->delete_me) itc->delete_me = EINA_TRUE;
+ if (itc->refcount > 0) elm_genlist_item_class_unref(itc);
+ else
+ {
+ itc->version = 0;
+ free(itc);
+ }
+ }
+}
+
+EAPI void
+elm_genlist_item_class_ref(Elm_Genlist_Item_Class *itc)
+{
+ if (itc && (itc->version == ELM_GENLIST_ITEM_CLASS_VERSION))
+ {
+ itc->refcount++;
+ if (itc->refcount == 0) itc->refcount--;
+ }
+}
+
+EAPI void
+elm_genlist_item_class_unref(Elm_Genlist_Item_Class *itc)
+{
+ if (itc && (itc->version == ELM_GENLIST_ITEM_CLASS_VERSION))
+ {
+ if (itc->refcount > 0) itc->refcount--;
+ if (itc->delete_me && (!itc->refcount))
+ elm_genlist_item_class_free(itc);
+ }
+}
+
/* for gengrid as of now */
void
_elm_genlist_page_relative_set(Evas_Object *obj,
ELM_GENLIST_ITEM_FIELD_STATE = (1 << 2)
} Elm_Genlist_Item_Field_Flags;
typedef struct _Elm_Genlist_Item_Class Elm_Genlist_Item_Class; /**< Genlist item class definition structs */
+#define ELM_GENLIST_ITEM_CLASS_HEADER 0, 0, 0
#define Elm_Genlist_Item_Class Elm_Gen_Item_Class
typedef struct _Elm_Genlist_Item_Class_Func Elm_Genlist_Item_Class_Func; /**< Class functions for genlist item class */
*/
EAPI Elm_Genlist_Item_Flags elm_genlist_item_flags_get(const Elm_Object_Item *it);
+#define ELM_GENLIST_ITEM_CLASS_VERSION 2 /* current version number */
+
+/**
+ * Add a new genlist item class in a given genlist widget.
+ *
+ * @return New allocated a genlist item class.
+ *
+ * This adds genlist item class for the genlist widget. When adding a item,
+ * genlist_item_{append, prepend, insert} function needs item class of the item.
+ * Given callback paramters are used at retrieving {text, content} of
+ * added item. Set as NULL if it's not used.
+ * If there's no available memory, return can be NULL.
+ *
+ * @see elm_genlist_item_class_free()
+ * @see elm_genlist_item_append()
+ *
+ * @ingroup Genlist
+ */
+EAPI Elm_Genlist_Item_Class *elm_genlist_item_class_new(void);
+
+/**
+ * Remove a item class in a given genlist widget.
+ *
+ * @param itc The itc to be removed.
+ *
+ * This removes item class from the genlist widget.
+ * Whenever it has no more references to it, item class is going to be freed.
+ * Otherwise it just decreases its reference count.
+ *
+ * @see elm_genlist_item_class_new()
+ * @see elm_genlist_item_class_ref()
+ * @see elm_genlist_item_class_unref()
+ *
+ * @ingroup Genlist
+ */
+EAPI void elm_genlist_item_class_free(Elm_Genlist_Item_Class *itc);
+
+/**
+ * Increments object reference count for the item class.
+ *
+ * @param itc The given item class object to reference
+ *
+ * This API just increases its reference count for item class management.
+ *
+ * @see elm_genlist_item_class_unref()
+ *
+ * @ingroup Genlist
+ */
+EAPI void elm_genlist_item_class_ref(Elm_Genlist_Item_Class *itc);
+
+/**
+ * Decrements object reference count for the item class.
+ *
+ * @param itc The given item class object to reference
+ *
+ * This API just decreases its reference count for item class management.
+ * Reference count can't be less than 0.
+ *
+ * @see elm_genlist_item_class_ref()
+ * @see elm_genlist_item_class_free()
+ *
+ * @ingroup Genlist
+ */
+EAPI void elm_genlist_item_class_unref(Elm_Genlist_Item_Class *itc);
+
/**
* @}
*/