Elm slideshow: Now theslideshow use the same way than the genlist widget: callbacks to create/delete the items

SVN revision: 43039
This commit is contained in:
Jonathan Atton 2009-10-12 20:02:56 +00:00
parent 86547a1fa2
commit 5ac89d0727
2 changed files with 171 additions and 110 deletions

View File

@ -5,9 +5,17 @@
#ifndef ELM_LIB_QUICKLAUNCH
static Evas_Object *slideshow, *bt_start, *bt_stop;
static Elm_Slideshow_Item_Class itc;
static char *img1 = PACKAGE_DATA_DIR"/images/logo.png";
static char *img2 = PACKAGE_DATA_DIR"/images/plant_01.jpg";
static char *img3 = PACKAGE_DATA_DIR"/images/rock_01.jpg";
static char *img4 = PACKAGE_DATA_DIR"/images/rock_02.jpg";
static char *img5 = PACKAGE_DATA_DIR"/images/sky_01.jpg";
static char *img6 = PACKAGE_DATA_DIR"/images/sky_04.jpg";
static char *img7 = PACKAGE_DATA_DIR"/images/wood_01.jpg";
static void
_notify_show(void *data, Evas_Object *obj, void *event_info)
_notify_show(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
evas_object_show(data);
elm_notify_timer_init(data);
@ -69,6 +77,18 @@ _spin(void *data, Evas_Object *obj, void *event_info)
elm_slideshow_timeout_set(slideshow, (int)elm_spinner_value_get(data));
}
static Evas_Object *
_get(void *data, Evas_Object *obj)
{
Evas_Object *photo = evas_object_image_add(evas_object_evas_get(obj));
evas_object_image_file_set(photo, data, NULL);
evas_object_image_filled_set(photo, 1);
return photo;
}
void
test_slideshow(void *data, Evas_Object *obj, void *event_info)
{
@ -76,6 +96,7 @@ test_slideshow(void *data, Evas_Object *obj, void *event_info)
char buf[PATH_MAX];
const Eina_List *l;
const char *transition;
char *s;
win = elm_win_add(NULL, "Slideshow", ELM_WIN_BASIC);
elm_win_title_set(win, "Slideshow");
@ -92,34 +113,16 @@ test_slideshow(void *data, Evas_Object *obj, void *event_info)
evas_object_size_hint_weight_set(slideshow, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(slideshow);
photo = evas_object_image_add(evas_object_evas_get(win));
evas_object_image_file_set(photo, PACKAGE_DATA_DIR"/images/logo.png", NULL);
evas_object_image_filled_set(photo, 1);
elm_slideshow_item_add(slideshow, photo);
photo = evas_object_image_add(evas_object_evas_get(win));
evas_object_image_file_set(photo, PACKAGE_DATA_DIR"/images/plant_01.jpg", NULL);
evas_object_image_filled_set(photo, 1);
elm_slideshow_item_add(slideshow, photo);
photo = evas_object_image_add(evas_object_evas_get(win));
evas_object_image_file_set(photo, PACKAGE_DATA_DIR"/images/rock_01.jpg", NULL);
evas_object_image_filled_set(photo, 1);
elm_slideshow_item_add(slideshow, photo);
photo = evas_object_image_add(evas_object_evas_get(win));
evas_object_image_file_set(photo, PACKAGE_DATA_DIR"/images/rock_02.jpg", NULL);
evas_object_image_filled_set(photo, 1);
elm_slideshow_item_add(slideshow, photo);
photo = evas_object_image_add(evas_object_evas_get(win));
evas_object_image_file_set(photo, PACKAGE_DATA_DIR"/images/sky_01.jpg", NULL);
evas_object_image_filled_set(photo, 1);
elm_slideshow_item_add(slideshow, photo);
photo = evas_object_image_add(evas_object_evas_get(win));
evas_object_image_file_set(photo, PACKAGE_DATA_DIR"/images/sky_04.jpg", NULL);
evas_object_image_filled_set(photo, 1);
elm_slideshow_item_add(slideshow, photo);
photo = evas_object_image_add(evas_object_evas_get(win));
evas_object_image_file_set(photo, PACKAGE_DATA_DIR"/images/wood_01.jpg", NULL);
evas_object_image_filled_set(photo, 1);
elm_slideshow_item_add(slideshow, photo);
itc.func.get = _get;
itc.func.del = NULL;
elm_slideshow_item_add(slideshow, &itc, img1);
elm_slideshow_item_add(slideshow, &itc, img2);
elm_slideshow_item_add(slideshow, &itc, img3);
elm_slideshow_item_add(slideshow, &itc, img4);
elm_slideshow_item_add(slideshow, &itc, img5);
elm_slideshow_item_add(slideshow, &itc, img6);
elm_slideshow_item_add(slideshow, &itc, img7);
notify = elm_notify_add(win);
elm_notify_orient_set(notify, ELM_NOTIFY_ORIENT_BOTTOM);
@ -179,8 +182,8 @@ test_slideshow(void *data, Evas_Object *obj, void *event_info)
evas_object_show(bt);
evas_object_smart_callback_add(slideshow, "clicked", _notify_show, notify);
evas_object_smart_callback_add(slideshow, "move", _notify_show, notify);
evas_object_event_callback_add(slideshow, EVAS_CALLBACK_MOUSE_UP, _notify_show, notify);
evas_object_event_callback_add(slideshow, EVAS_CALLBACK_MOUSE_MOVE, _notify_show, notify);
evas_object_resize(win, 350, 200);
evas_object_show(win);

View File

@ -12,18 +12,31 @@
* consequently new animations can be added without having to update the
* applications.
*
* The slideshow use 2 callbacks to create and delete the objects displayed. When an item is displayed the function itc->func.get() is called. This function should create the object, for example the object can be an evas_object_image or a photocam. When a object is no more displayed the function itc->func.del() is called, the user can delete or hide the object here. If itc->func.del is NULL the slideshow delete the object with evas_object_del().
*/
typedef struct _Widget_Data Widget_Data;
struct _Elm_Slideshow_Item
{
Evas_Object *obj;
Eina_List *l;
const void *data;
const Elm_Slideshow_Item_Class *itc;
Evas_Object *o;
};
struct _Widget_Data
{
Evas_Object *slideshow;
// list of Evas_Object*
// list of Elm_Slideshow_Item*
Eina_List *items;
int current;
Evas_Object *previous;
Elm_Slideshow_Item *current;
Elm_Slideshow_Item *previous;
int loop;
Eina_List *transitions;
@ -90,44 +103,32 @@ _sub_del(void *data, Evas_Object *obj, void *event_info)
Evas_Object *sub = event_info;
}
static void
_signal_clicked(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
if (!wd) return;
evas_object_smart_callback_call(data, "clicked", NULL);
}
static void
_signal_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
if (!wd) return;
evas_object_smart_callback_call(data, "move", NULL);
}
static void
_end(void *data, Evas_Object *obj, const char *emission, const char *source)
{
Evas_Object *o;
Eina_List *l;
Elm_Slideshow_Item *item;
const char *part;
Widget_Data *wd = elm_widget_data_get(data);
if(wd->previous)
item = wd->previous;
if(item && item->o)
{
edje_object_part_unswallow(NULL, wd->previous);
evas_object_hide(wd->previous);
edje_object_part_unswallow(NULL, wd->previous->o);
if(item->o && item->itc->func.del)
item->itc->func.del((void*)item->data, wd->previous->o);
else if(item->o)
evas_object_del(item->o);
item->o = NULL;
wd->previous = NULL;
}
o = eina_list_nth(wd->items, wd->current);
if(!o) return;
item = wd->current;
if(!item || !item->o) return;
edje_object_part_unswallow(NULL, o);
edje_object_part_swallow(wd->slideshow, "elm.swallow.1", o);
edje_object_part_unswallow(NULL, item->o);
edje_object_part_swallow(wd->slideshow, "elm.swallow.1", item->o);
if(wd->timeout>0)
wd->timer = ecore_timer_add(wd->timeout, _timer_cb, data);
}
@ -168,7 +169,7 @@ elm_slideshow_add(Evas_Object *parent)
elm_widget_del_hook_set(obj, _del_hook);
elm_widget_theme_hook_set(obj, _theme_hook);
wd->current = -1;
wd->current = NULL;
wd->previous = NULL;
wd->slideshow = edje_object_add(e);
@ -182,11 +183,6 @@ elm_slideshow_add(Evas_Object *parent)
edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
evas_object_event_callback_add(wd->slideshow, EVAS_CALLBACK_MOUSE_DOWN,
_signal_clicked, obj);
evas_object_event_callback_add(wd->slideshow, EVAS_CALLBACK_MOUSE_MOVE,
_signal_move, obj);
evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
_sizing_eval(obj);
@ -196,21 +192,31 @@ elm_slideshow_add(Evas_Object *parent)
/**
* Add a object in the list. The object can be a evas object image or a elm photo for example.
*
* The object will become a member of the slideshow and will be deleted at the same time than the slideshow.
* @param obj The slideshow object
* @param file The object
* @aram itc Callbacks used to create/delete the object. If itc->del.del is NULL, the object will be destroyed with evas_object_del()
* @param data Data used by the user to identified the item
* @return Returns The slideshow item
*/
EAPI void
elm_slideshow_item_add(Evas_Object *obj, Evas_Object *item)
EAPI Elm_Slideshow_Item*
elm_slideshow_item_add(Evas_Object *obj, const Elm_Slideshow_Item_Class *itc, const void *data)
{
Elm_Slideshow_Item *item;
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
wd->items = eina_list_append(wd->items, item);
item = calloc(1, sizeof(Elm_Slideshow_Item));
item->data = data;
item->itc = itc;
item->obj = obj;
item->l = eina_list_append(item->l, item);
if(eina_list_count(wd->items) == 1)
elm_slideshow_goto(obj, 0);
wd->items = eina_list_merge(wd->items, item->l);
if(!wd->current)
elm_slideshow_show(item);
return item;
}
/**
@ -220,23 +226,27 @@ elm_slideshow_item_add(Evas_Object *obj, Evas_Object *item)
* @param pos The position of the item
*/
EAPI void
elm_slideshow_goto(Evas_Object *obj, int pos)
elm_slideshow_show(Elm_Slideshow_Item *item)
{
Evas_Object *o;
Eina_List *l;
const char *part;
Widget_Data *wd = elm_widget_data_get(obj);
Widget_Data *wd = elm_widget_data_get(item->obj);
if (!wd) return;
if ((pos < 0) || (pos>=eina_list_count(wd->items))) return;
if(item == wd->current) return;
_end(obj, obj, NULL, NULL);
_end(item->obj, item->obj, NULL, NULL);
wd->previous = eina_list_nth(wd->items, wd->current);
wd->current = pos;
o = eina_list_nth(wd->items, wd->current);
wd->previous = wd->current;
wd->current = item;
if(!item->o && item->itc->func.get)
{
item->o = item->itc->func.get((void*)item->data, item->obj);
evas_object_smart_member_add(item->o, item->obj);
}
_end(obj, obj, NULL, NULL);
_end(item->obj, item->obj, NULL, NULL);
}
/**
@ -250,31 +260,35 @@ elm_slideshow_next(Evas_Object *obj)
char buf[1024];
Eina_List *l;
const char *part;
Elm_Slideshow_Item *item;
Evas_Object *o;
int next;
Elm_Slideshow_Item *next = NULL;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
if ((eina_list_count(wd->items) <= 0) ||
((wd->current >= eina_list_count(wd->items) - 1))
&& (!wd->loop))
return;
if (wd->current >= eina_list_count(wd->items) - 1)
next = 0;
else
next = wd->current + 1;
if(wd->current)
next = eina_list_data_get(eina_list_next(wd->current->l));
if(wd->current && !next && wd->loop)
next = eina_list_data_get(wd->items);
o = eina_list_nth(wd->items, next);
if(!next || next == wd->current) return;
_end(obj, obj, NULL, NULL);
edje_object_part_swallow(wd->slideshow, "elm.swallow.2", o);
if(!next->o && next->itc->func.get)
{
next->o = next->itc->func.get((void*)next->data, obj);
evas_object_smart_member_add(next->o, obj);
}
edje_object_part_swallow(wd->slideshow, "elm.swallow.2", next->o);
snprintf(buf, 1024, "%s,next", wd->transition);
edje_object_signal_emit(wd->slideshow, buf, "slideshow");
wd->previous = eina_list_nth(wd->items, wd->current);
wd->previous = wd->current;
wd->current = next;
if (wd->timer) ecore_timer_del(wd->timer);
@ -293,30 +307,33 @@ elm_slideshow_previous(Evas_Object *obj)
Eina_List *l;
const char *part;
Evas_Object *o;
int previous;
Elm_Slideshow_Item *prev;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
if ((eina_list_count(wd->items) <= 0)
|| (wd->current <= 0 && !wd->loop))
return;
if(wd->current)
prev = eina_list_data_get(eina_list_prev(wd->current->l));
if(wd->current && !prev && wd->loop)
prev = eina_list_data_get(eina_list_last(wd->items));
if (wd->current <= 0)
previous = eina_list_count(wd->items) - 1;
else
previous = wd->current - 1;
o = eina_list_nth(wd->items, previous);
if(!prev || prev == wd->current) return;
_end(obj, obj, NULL, NULL);
edje_object_part_swallow(wd->slideshow, "elm.swallow.2", o);
if(!prev->o && prev->itc->func.get)
{
prev->o = prev->itc->func.get((void*)prev->data, obj);
evas_object_smart_member_add(prev->o, obj);
}
edje_object_part_swallow(wd->slideshow, "elm.swallow.2", prev->o);
snprintf(buf, 1024, "%s,previous", wd->transition);
edje_object_signal_emit(wd->slideshow, buf, "slideshow");
wd->previous = eina_list_nth(wd->items, wd->current);
wd->current = previous;
wd->previous = wd->current;
wd->current = prev;
if (wd->timer) ecore_timer_del(wd->timer);
wd->timer = NULL;
@ -404,22 +421,63 @@ elm_slideshow_loop_set(Evas_Object *obj, int loop)
}
/**
* Delete all the itemns
* Delete all the items
*
* @param obj The slideshow object
*/
EAPI void
elm_slideshow_clear(Evas_Object *obj)
{
Evas_Object *o;
Elm_Slideshow_Item *item;
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
wd->previous = NULL;
wd->current = -1;
EINA_LIST_FREE(wd->items, o)
wd->current = NULL;
EINA_LIST_FREE(wd->items, item)
{
evas_object_del(o);
if(item->o && item->itc->func.del)
item->itc->func.del((void*)item->data, wd->previous->o);
else if(item->o)
evas_object_del(item->o);
free(item);
}
}
/**
* Delete the item
*
* @param item The slideshow item
*/
EAPI void
elm_slideshow_item_del(Elm_Slideshow_Item *item)
{
if(!item) return;
Widget_Data *wd = elm_widget_data_get(item->obj);
if(wd->previous == item) wd->previous = NULL;
if(wd->current == item)
{
wd->current = NULL;
Eina_List *l = eina_list_data_find_list(wd->items, item);
Eina_List *l2 = eina_list_next(l);
if(!l2)
l2 = eina_list_nth_list(wd->items, eina_list_count(wd->items)-1);
if(l2)
elm_slideshow_show(eina_list_data_get(l2));
}
wd->items = eina_list_remove(wd->items, item);
if(item->o && item->itc->func.del)
item->itc->func.del((void*)item->data, wd->previous->o);
else if(item->o)
evas_object_del(item->o);
free(item);
}