Dear all.
I make controversial apis for item class management.
As raster and other guys suggest, I simplify APIs and its behaviors.
First, Two public apis and two internal apis are introduced
+EAPI Elm_Genlist_Item_Class *
+elm_genlist_item_class_new(void)
+EAPI void
+elm_genlist_item_class_free(Elm_Genlist_Item_Class *itc)
+void
+_elm_genlist_item_class_ref(Elm_Genlist_Item_Class *itc)
+void
+_elm_genlist_item_class_unref(Elm_Genlist_Item_Class *itc)
genlist item class is maintained by genlist in automatic manner.
And three fields are introduced in genlist item class.
+ int version;
+ unsigned int refcount;
+ Eina_Bool delete_me;
Normally a user add a elm_genlist_item_class by elm_genlist_item_class_new().
Then its reference counter is automatic maintained.
If the user wanna to remove the elm_genlist_item_class, then call
elm_genlist_item_class_free()
After refcount reaches to 0, it will be removed.
Thank you.
PS: I made those apis in genlist. If its accepted i'll make a new
patch for gengrid.
Index: elementary/src/lib/elm_genlist.c
===================================================================
--- elementary/src/lib/elm_genlist.c (리비전 67815)
+++ elementary/src/lib/elm_genlist.c (작업 사본)
@@ -796,6 +796,7 @@
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(it->itc);
evas_event_thaw(evas_object_evas_get(obj));
evas_event_thaw_eval(evas_object_evas_get(obj));
}
@@ -2438,6 +2439,11 @@
minw = itb->minw;
minw_change = EINA_TRUE;
}
+ if (minw > wd->w)
+ {
+ minw = wd->w;
+ minw_change = EINA_TRUE;
+ }
itb->w = minw;
itb->h = itb->minh;
y += itb->h;
@@ -3316,6 +3322,7 @@
it->wd = wd;
it->generation = wd->generation;
it->itc = itc;
+ _elm_genlist_item_class_ref(itc);
it->base.data = data;
it->parent = parent;
it->func.func = func;
@@ -3807,6 +3814,27 @@
evas_object_smart_callback_call(WIDGET(it), SIG_MOVED, it);
}
+void
+_elm_genlist_item_class_ref(Elm_Genlist_Item_Class *itc)
+{
+ if (itc->version == ELM_GENLIST_ITEM_CLASS_VERSION)
+ {
+ itc->refcount++;
+ if (itc->refcount == 0) itc->refcount--;
+ }
+}
+
+void
+_elm_genlist_item_class_unref(Elm_Genlist_Item_Class *itc)
+{
+ if (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);
+ }
+}
+
EAPI Elm_Object_Item *
elm_genlist_item_append(Evas_Object *obj,
const Elm_Genlist_Item_Class *itc,
@@ -5316,6 +5344,36 @@
return wd->reorder_mode;
}
+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 = 0;
+ itc->delete_me = EINA_FALSE;
+
+ return itc;
+}
+
+EAPI void
+elm_genlist_item_class_free(Elm_Genlist_Item_Class *itc)
+{
+ if (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);
+ }
+ }
+}
+
/* for gengrid as of now */
void
_elm_genlist_page_relative_set(Evas_Object *obj,
Index: elementary/src/lib/elm_genlist.h
===================================================================
--- elementary/src/lib/elm_genlist.h (리비전 67815)
+++ elementary/src/lib/elm_genlist.h (작업 사본)
@@ -1831,6 +1831,41 @@
*/
EAPI Eina_Bool elm_genlist_reorder_mode_get(const
Evas_Object *obj);
+#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()
+ *
+ * @ingroup Genlist
+ */
+EAPI void elm_genlist_item_class_free(Elm_Genlist_Item_Class *itc);
+
+/**
* @}
*/
Index: elementary/src/lib/elm_gen_common.h
===================================================================
--- elementary/src/lib/elm_gen_common.h (리비전 67815)
+++ elementary/src/lib/elm_gen_common.h (작업 사본)
@@ -196,4 +196,8 @@
void _elm_genlist_item_del_notserious(Elm_Gen_Item *it);
+void _elm_genlist_item_class_ref(Elm_Genlist_Item_Class *itc);
+
+void _elm_genlist_item_class_unref(Elm_Genlist_Item_Class *itc);
+
#endif
Index: elementary/src/lib/elm_deprecated_before.h
===================================================================
--- elementary/src/lib/elm_deprecated_before.h (리비전 67815)
+++ elementary/src/lib/elm_deprecated_before.h (작업 사본)
@@ -17,4 +17,7 @@
Elm_Gen_Item_State_Get_Cb state_get;
Elm_Gen_Item_Del_Cb del;
} func;
+ int version;
+ unsigned int refcount;
+ Eina_Bool delete_me;
};
Index: elementary/src/bin/test_genlist.c
===================================================================
--- elementary/src/bin/test_genlist.c (리비전 67815)
+++ elementary/src/bin/test_genlist.c (작업 사본)
@@ -20,7 +20,7 @@
} 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];
@@ -140,11 +140,12 @@
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");
@@ -158,7 +159,7 @@
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,
@@ -188,13 +189,13 @@
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,
@@ -210,11 +211,11 @@
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)
@@ -223,7 +224,7 @@
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 */,
@@ -240,11 +241,11 @@
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)
@@ -253,7 +254,7 @@
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 */,
@@ -367,31 +368,32 @@
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 */);
@@ -1390,11 +1392,12 @@
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;
@@ -1491,7 +1494,7 @@
}
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,
@@ -1538,17 +1541,17 @@
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 */,
@@ -1603,11 +1606,12 @@
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;
@@ -1619,26 +1623,26 @@
(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 */);
@@ -1875,16 +1879,17 @@
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 */,
@@ -1929,15 +1934,15 @@
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,
@@ -2047,11 +2052,11 @@
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)
@@ -2060,7 +2065,7 @@
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 */,
@@ -2076,11 +2081,11 @@
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)
@@ -2089,7 +2094,7 @@
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 */,
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel