typedef struct _Pan Pan;
#define PRELOAD 1
+#define REORDER_EFFECT_TIME 0.5
struct _Elm_Gengrid_Item
{
Evas_Object *spacer;
const Elm_Gengrid_Item_Class *gic;
Ecore_Timer *long_timer;
+ Ecore_Animator *item_moving_effect_timer;
Widget_Data *wd;
Eina_List *labels, *icons, *states, *icon_objs;
struct
const void *data;
} func;
- Evas_Coord x, y, dx, dy;
- int relcount;
- int walking;
+ Evas_Coord x, y, dx, dy, ox, oy, tx, ty, rx, ry;
+ unsigned int moving_effect_start_time;
+ int relcount;
+ int walking;
struct
{
Eina_Bool disabled : 1;
Eina_Bool selected : 1;
Eina_Bool hilighted : 1;
+ Eina_Bool moving : 1;
};
struct _Widget_Data
Eina_Inlist *items;
Ecore_Job *calc_job;
Eina_List *selected;
- Elm_Gengrid_Item *last_selected_item;
+ Elm_Gengrid_Item *last_selected_item, *reorder_item;
double align_x, align_y;
- Evas_Coord pan_x, pan_y;
+ Evas_Coord pan_x, pan_y, old_pan_x, old_pan_y;
Evas_Coord item_width, item_height; /* Each item size */
Evas_Coord minw, minh; /* Total obj size */
+ Evas_Coord reorder_item_x, reorder_item_y;
unsigned int nmax;
long count;
int walking;
Eina_Bool wasselected : 1;
Eina_Bool always_select : 1;
Eina_Bool clear_me : 1;
+ Eina_Bool h_bounce : 1;
+ Eina_Bool v_bounce : 1;
+ Eina_Bool reorder_mode : 1;
+ Eina_Bool reorder_item_changed : 1;
+ Eina_Bool move_effect_enabled : 1;
};
#define ELM_GENGRID_ITEM_FROM_INLIST(item) \
static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
+static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
+static const char SIG_SELECTED[] = "selected";
+static const char SIG_UNSELECTED[] = "unselected";
+static const char SIG_REALIZED[] = "realized";
+static const char SIG_UNREALIZED[] = "unrealized";
+static const char SIG_CHANGED[] = "changed";
+static const char SIG_DRAG_START_UP[] = "drag,start,up";
+static const char SIG_DRAG_START_DOWN[] = "drag,start,down";
+static const char SIG_DRAG_START_LEFT[] = "drag,start,left";
+static const char SIG_DRAG_START_RIGHT[] = "drag,start,right";
+static const char SIG_DRAG_STOP[] = "drag,stop";
+static const char SIG_DRAG[] = "drag";
+static const char SIG_SCROLL[] = "scroll";
+static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
+static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
+static const char SIG_MOVED[] = "moved";
+
+static const Evas_Smart_Cb_Description _signals[] = {
+ {SIG_CLICKED_DOUBLE, ""},
+ {SIG_SELECTED, ""},
+ {SIG_UNSELECTED, ""},
+ {SIG_REALIZED, ""},
+ {SIG_UNREALIZED, ""},
+ {SIG_CHANGED, ""},
+ {SIG_DRAG_START_UP, ""},
+ {SIG_DRAG_START_DOWN, ""},
+ {SIG_DRAG_START_LEFT, ""},
+ {SIG_DRAG_START_RIGHT, ""},
+ {SIG_DRAG_STOP, ""},
+ {SIG_DRAG, ""},
+ {SIG_SCROLL, ""},
+ {SIG_SCROLL_DRAG_START, ""},
+ {SIG_SCROLL_DRAG_STOP, ""},
+ {SIG_MOVED, ""},
+ {NULL, NULL}
+};
+
+static Eina_Compare_Cb _elm_gengrid_item_compare_cb;
+static Eina_Compare_Cb _elm_gengrid_item_compare_data_cb;
+
static Eina_Bool
_event_hook(Evas_Object *obj,
Evas_Object *src __UNUSED__,
(!strcmp(ev->keyname, "space")))
{
item = elm_gengrid_selected_item_get(obj);
- evas_object_smart_callback_call(item->wd->self, "clicked,double", item);
- evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
+ evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
}
else return EINA_FALSE;
Elm_Gengrid_Item *item = data;
Evas_Event_Mouse_Move *ev = event_info;
Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
+ Evas_Coord ox, oy, ow, oh, it_scrl_x, it_scrl_y;
if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
{
ecore_timer_del(item->long_timer);
item->long_timer = NULL;
}
- evas_object_smart_callback_call(item->wd->self, "drag", item);
+ evas_object_smart_callback_call(item->wd->self, SIG_DRAG, item);
return;
}
if ((!item->down) || (item->wd->longpressed))
ecore_timer_del(item->long_timer);
item->long_timer = NULL;
}
+ if ((item->wd->reorder_mode) && (item->wd->reorder_item))
+ {
+ evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &ow, &oh);
+
+ it_scrl_x = ev->cur.canvas.x - item->wd->reorder_item->dx;
+ it_scrl_y = ev->cur.canvas.y - item->wd->reorder_item->dy;
+
+ if (it_scrl_x < ox) item->wd->reorder_item_x = ox;
+ else if (it_scrl_x + item->wd->item_width > ox + ow)
+ item->wd->reorder_item_x = ox + ow - item->wd->item_width;
+ else item->wd->reorder_item_x = it_scrl_x;
+
+ if (it_scrl_y < oy) item->wd->reorder_item_y = oy;
+ else if (it_scrl_y + item->wd->item_height > oy + oh)
+ item->wd->reorder_item_y = oy + oh - item->wd->item_height;
+ else item->wd->reorder_item_y = it_scrl_y;
+
+ if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
+ item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
+ }
return;
}
if (!item->display_only)
const char *left_drag, *right_drag;
if (!elm_widget_mirrored_get(item->wd->self))
{
- left_drag = "drag,start,left";
- right_drag = "drag,start,right";
+ left_drag = SIG_DRAG_START_LEFT;
+ right_drag = SIG_DRAG_START_RIGHT;
}
else
{
- left_drag = "drag,start,right";
- right_drag = "drag,start,left";
+ left_drag = SIG_DRAG_START_RIGHT;
+ right_drag = SIG_DRAG_START_LEFT;
}
item->dragging = 1;
if (dy < 0)
{
if (ady > adx)
- evas_object_smart_callback_call(item->wd->self, "drag,start,up",
+ evas_object_smart_callback_call(item->wd->self, SIG_DRAG_START_UP,
item);
else
{
{
if (ady > adx)
evas_object_smart_callback_call(item->wd->self,
- "drag,start,down", item);
+ SIG_DRAG_START_DOWN, item);
else
{
if (dx < 0)
if ((item->disabled) || (item->dragging)) return ECORE_CALLBACK_CANCEL;
item->wd->longpressed = EINA_TRUE;
evas_object_smart_callback_call(item->wd->self, "longpressed", item);
+ if (item->wd->reorder_mode)
+ {
+ item->wd->reorder_item = item;
+ evas_object_raise(item->base.view);
+ elm_smart_scroller_hold_set(item->wd->scr, EINA_TRUE);
+ elm_smart_scroller_bounce_allow_set(item->wd->scr, EINA_FALSE, EINA_FALSE);
+ edje_object_signal_emit(item->base.view, "elm,state,reorder,enabled", "elm");
+ }
return ECORE_CALLBACK_CANCEL;
}
_item_hilight(item);
if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
{
- evas_object_smart_callback_call(item->wd->self, "clicked,double", item);
+ evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
}
if (item->long_timer) ecore_timer_del(item->long_timer);
if (item->dragging)
{
item->dragging = EINA_FALSE;
- evas_object_smart_callback_call(item->wd->self, "drag,stop", item);
+ evas_object_smart_callback_call(item->wd->self, SIG_DRAG_STOP, item);
dragged = EINA_TRUE;
}
if (item->wd->on_hold)
item->wd->on_hold = EINA_FALSE;
return;
}
+ if ((item->wd->reorder_mode) && (item->wd->reorder_item))
+ {
+ if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
+ item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
+
+ evas_object_smart_callback_call(item->wd->self, SIG_MOVED, item->wd->reorder_item);
+ item->wd->reorder_item = NULL;
+ elm_smart_scroller_hold_set(item->wd->scr, EINA_FALSE);
+ elm_smart_scroller_bounce_allow_set(item->wd->scr, item->wd->h_bounce, item->wd->v_bounce);
+ edje_object_signal_emit(item->base.view, "elm,state,reorder,disabled", "elm");
+ }
if (item->wd->longpressed)
{
item->wd->longpressed = EINA_FALSE;
item->want_unrealize = EINA_FALSE;
}
+static Eina_Bool
+_reorder_item_moving_effect_timer_cb(void *data)
+{
+ Elm_Gengrid_Item *item = data;
+ double time, t;
+ Evas_Coord dx, dy;
+
+ time = REORDER_EFFECT_TIME;
+ t = ((0.0 > (t = ecore_loop_time_get()-item->moving_effect_start_time)) ? 0.0 : t);
+ dx = ((item->tx - item->ox) / 10) * _elm_config->scale;
+ dy = ((item->ty - item->oy) / 10) * _elm_config->scale;
+
+ if (t <= time)
+ {
+ item->rx += (1 * sin((t / time) * (M_PI / 2)) * dx);
+ item->ry += (1 * sin((t / time) * (M_PI / 2)) * dy);
+ }
+ else
+ {
+ item->rx += dx;
+ item->ry += dy;
+ }
+
+ if ((((dx > 0) && (item->rx >= item->tx)) || ((dx <= 0) && (item->rx <= item->tx))) &&
+ (((dy > 0) && (item->ry >= item->ty)) || ((dy <= 0) && (item->ry <= item->ty))))
+ {
+ evas_object_move(item->base.view, item->tx, item->ty);
+ evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
+ item->moving = EINA_FALSE;
+ item->item_moving_effect_timer = NULL;
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ evas_object_move(item->base.view, item->rx, item->ry);
+ evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
+
+ return ECORE_CALLBACK_RENEW;
+}
+
static void
_item_place(Elm_Gengrid_Item *item,
Evas_Coord cx,
{
Evas_Coord x, y, ox, oy, cvx, cvy, cvw, cvh;
Evas_Coord tch, tcw, alignw = 0, alignh = 0, vw, vh;
+ Eina_Bool reorder_item_move_forward = EINA_FALSE;
item->x = cx;
item->y = cy;
evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &vw, &vh);
{
_item_realize(item);
if (!was_realized)
- evas_object_smart_callback_call(item->wd->self, "realized", item);
+ evas_object_smart_callback_call(item->wd->self, SIG_REALIZED, item);
+ if ((item->wd->reorder_mode) && (item->wd->reorder_item))
+ {
+ if (item->moving) return;
+
+ if (!item->wd->move_effect_enabled)
+ {
+ item->ox = x;
+ item->oy = y;
+ }
+ if (item->wd->reorder_item == item)
+ {
+ evas_object_move(item->base.view,
+ item->wd->reorder_item_x, item->wd->reorder_item_y);
+ evas_object_resize(item->base.view,
+ item->wd->item_width, item->wd->item_height);
+ return;
+ }
+ else
+ {
+ if (item->wd->move_effect_enabled)
+ {
+ if ((item->ox != x) || (item->oy != y))
+ {
+ if (((item->wd->old_pan_x == item->wd->pan_x) && (item->wd->old_pan_y == item->wd->pan_y)) ||
+ ((item->wd->old_pan_x != item->wd->pan_x) && !(item->ox - item->wd->pan_x + item->wd->old_pan_x == x)) ||
+ ((item->wd->old_pan_y != item->wd->pan_y) && !(item->oy - item->wd->pan_y + item->wd->old_pan_y == y)))
+ {
+ item->tx = x;
+ item->ty = y;
+ item->rx = item->ox;
+ item->ry = item->oy;
+ item->moving = EINA_TRUE;
+ item->moving_effect_start_time = ecore_loop_time_get();
+ item->item_moving_effect_timer = ecore_animator_add(_reorder_item_moving_effect_timer_cb, item);
+ return;
+ }
+ }
+ }
+
+ if (ELM_RECTS_INTERSECT(item->wd->reorder_item_x, item->wd->reorder_item_y,
+ item->wd->item_width, item->wd->item_height,
+ x+(item->wd->item_width/2), y+(item->wd->item_height/2),
+ 1, 1))
+ {
+ if (item->wd->horizontal)
+ {
+ if ((item->wd->nmax * item->wd->reorder_item->x + item->wd->reorder_item->y) >
+ (item->wd->nmax * item->x + item->y))
+ reorder_item_move_forward = EINA_TRUE;
+ }
+ else
+ {
+ if ((item->wd->nmax * item->wd->reorder_item->y + item->wd->reorder_item->x) >
+ (item->wd->nmax * item->y + item->x))
+ reorder_item_move_forward = EINA_TRUE;
+ }
+
+ item->wd->items = eina_inlist_remove(item->wd->items,
+ EINA_INLIST_GET(item->wd->reorder_item));
+ if (reorder_item_move_forward)
+ item->wd->items = eina_inlist_prepend_relative(item->wd->items,
+ EINA_INLIST_GET(item->wd->reorder_item),
+ EINA_INLIST_GET(item));
+ else
+ item->wd->items = eina_inlist_append_relative(item->wd->items,
+ EINA_INLIST_GET(item->wd->reorder_item),
+ EINA_INLIST_GET(item));
+
+ item->wd->reorder_item_changed = EINA_TRUE;
+ item->wd->move_effect_enabled = EINA_TRUE;
+ if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
+ item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
+
+ return;
+ }
+ }
+ }
evas_object_move(item->base.view, x, y);
evas_object_resize(item->base.view, item->wd->item_width,
item->wd->item_height);
{
_item_unrealize(item);
if (was_realized)
- evas_object_smart_callback_call(item->wd->self, "unrealized", item);
+ evas_object_smart_callback_call(item->wd->self, SIG_UNREALIZED, item);
}
}
if (item->func.func)
item->func.func((void *)item->func.data, item->wd->self, item);
if (!item->delete_me)
- evas_object_smart_callback_call(item->wd->self, "selected", item);
+ evas_object_smart_callback_call(item->wd->self, SIG_SELECTED, item);
item->walking--;
item->wd->walking--;
+ item->wd->last_selected_item = item;
if ((item->wd->clear_me) && (!item->wd->walking))
elm_gengrid_clear(item->base.widget);
else
if ((!item->walking) && (item->delete_me))
if (!item->relcount) _item_del(item);
}
- item->wd->last_selected_item = item;
}
static void
{
item->selected = EINA_FALSE;
item->wd->selected = eina_list_remove(item->wd->selected, item);
- evas_object_smart_callback_call(item->wd->self, "unselected", item);
+ evas_object_smart_callback_call(item->wd->self, SIG_UNSELECTED, item);
}
}
}
wd->nmax = nmax;
- wd->calc_job = NULL;
evas_object_smart_changed(wd->pan_smart);
}
+ wd->calc_job = NULL;
}
static void
if (!sd) return;
if (!sd->wd->nmax) return;
+ sd->wd->reorder_item_changed = EINA_FALSE;
+
EINA_INLIST_FOREACH(sd->wd->items, item)
{
_item_place(item, cx, cy);
+ if (sd->wd->reorder_item_changed) return;
if (sd->wd->horizontal)
{
cy = (cy + 1) % sd->wd->nmax;
if (!cx) cy++;
}
}
- evas_object_smart_callback_call(sd->wd->self, "changed", NULL);
+
+ if ((sd->wd->reorder_mode) && (sd->wd->reorder_item))
+ {
+ if (!sd->wd->reorder_item_changed)
+ {
+ sd->wd->old_pan_x = sd->wd->pan_x;
+ sd->wd->old_pan_y = sd->wd->pan_y;
+ }
+ sd->wd->move_effect_enabled = EINA_FALSE;
+ }
+ evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
}
static void
Evas_Object *obj __UNUSED__,
void *event_info __UNUSED__)
{
- evas_object_smart_callback_call(data, "scroll,drag,start", NULL);
+ evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
}
static void
Evas_Object *obj __UNUSED__,
void *event_info __UNUSED__)
{
- evas_object_smart_callback_call(data, "scroll,drag,stop", NULL);
+ evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
}
static void
Evas_Object *obj __UNUSED__,
void *event_info __UNUSED__)
{
- evas_object_smart_callback_call(data, "scroll", NULL);
+ evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
+}
+
+static int
+_elm_gengrid_item_compare_data(const void *data, const void *data1)
+{
+ const Elm_Gengrid_Item *item = data;
+ const Elm_Gengrid_Item *item1 = data1;
+
+ return _elm_gengrid_item_compare_data_cb(item->base.data, item1->base.data);
+}
+
+static int
+_elm_gengrid_item_compare(const void *data, const void *data1)
+{
+ Elm_Gengrid_Item *item, *item1;
+ item = ELM_GENGRID_ITEM_FROM_INLIST(data);
+ item1 = ELM_GENGRID_ITEM_FROM_INLIST(data1);
+ return _elm_gengrid_item_compare_cb(item, item1);
}
/**
wd->self = obj;
wd->align_x = 0.5;
wd->align_y = 0.5;
+ wd->h_bounce = bounce;
+ wd->v_bounce = bounce;
wd->no_select = EINA_FALSE;
evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
+ evas_object_smart_callbacks_descriptions_set(obj, _signals);
+
if (!smart)
{
static Evas_Smart_Class sc;
return item;
}
+EAPI Elm_Gengrid_Item *
+elm_gengrid_item_direct_sorted_insert(Evas_Object *obj,
+ const Elm_Gengrid_Item_Class *gic,
+ const void *data,
+ Eina_Compare_Cb comp,
+ Evas_Smart_Cb func,
+ const void *func_data)
+{
+ Elm_Gengrid_Item *item;
+ ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return NULL;
+
+ item = _item_create(wd, gic, data, func, func_data);
+ if (!item) return NULL;
+
+ _elm_gengrid_item_compare_cb = comp;
+ wd->items = eina_inlist_sorted_insert(wd->items, EINA_INLIST_GET(item),
+ _elm_gengrid_item_compare);
+ if (wd->calc_job) ecore_job_del(wd->calc_job);
+ wd->calc_job = ecore_job_add(_calc_job, wd);
+
+ return item;
+}
+
+EAPI Elm_Gengrid_Item *
+elm_gengrid_item_sorted_insert(Evas_Object *obj,
+ const Elm_Gengrid_Item_Class *gic,
+ const void *data,
+ Eina_Compare_Cb comp,
+ Evas_Smart_Cb func,
+ const void *func_data)
+{
+ _elm_gengrid_item_compare_data_cb = comp;
+
+ return elm_gengrid_item_direct_sorted_insert(obj, gic, data, _elm_gengrid_item_compare_data, func, func_data);
+}
+
/**
* Remove an item from the Gengrid.
*
elm_gengrid_item_update(item);
}
+EAPI const Elm_Gengrid_Item_Class *
+elm_gengrid_item_item_class_get(const Elm_Gengrid_Item *item)
+{
+ ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
+ if (item->delete_me) return NULL;
+ return item->gic;
+}
+
+EAPI void
+elm_gengrid_item_item_class_set(Elm_Gengrid_Item *item,
+ const Elm_Gengrid_Item_Class *gic)
+{
+ ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
+ EINA_SAFETY_ON_NULL_RETURN(gic);
+ if (item->delete_me) return;
+ item->gic = gic;
+ elm_gengrid_item_update(item);
+}
+
/**
* Get the item's coordinates.
*
ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
if (item->disabled == disabled) return;
if (item->delete_me) return;
- item->disabled = disabled;
+ item->disabled = !!disabled;
if (item->realized)
{
if (item->disabled)
if (!label)
return NULL;
elm_object_style_set(label, "tooltip");
- elm_label_label_set(label, data);
+ elm_object_text_set(label, data);
return label;
}
}
/**
+ * Set the reorder mode
+ *
+ * @param obj The Gengrid object
+ * @param reorder_mode The reorder mode
+ * (EINA_TRUE = on, EINA_FALSE = off)
+ *
+ * @ingroup Gengrid
+ */
+EAPI void
+elm_gengrid_reorder_mode_set(Evas_Object *obj,
+ Eina_Bool reorder_mode)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ wd->reorder_mode = reorder_mode;
+}
+
+/**
+ * Get the reorder mode
+ *
+ * @param obj The Gengrid object
+ * @return The reorder mode
+ * (EINA_TRUE = on, EINA_FALSE = off)
+ *
+ * @ingroup Gengrid
+ */
+EAPI Eina_Bool
+elm_gengrid_reorder_mode_get(const Evas_Object *obj)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return EINA_FALSE;
+ return wd->reorder_mode;
+}
+
+/**
* Set the always select mode.
*
* Cells will only call their selection func and callback when first
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
+ wd->h_bounce = h_bounce;
+ wd->v_bounce = v_bounce;
}
/**
ELM_CHECK_WIDTYPE(obj, widtype);
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
- elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
+ *h_bounce = wd->h_bounce;
+ *v_bounce = wd->v_bounce;
}
/**