#include "private.h" typedef struct _Grid Grid; struct _Grid { Evas_Object_Smart_Clipped_Data __clipped_data; Evas *evas; struct { int size, chw, chh; const char *name; } font; struct { int w, h; Evas_Object *obj; } grid; struct { Evas_Object *top, *bottom, *theme; } sel; struct { int x, y; Evas_Object *obj; } cursor; Evas_Object *o_event; Ecore_Timer *delayed_size_timer; }; /* local variables */ static Evas_Smart *_smart = NULL; static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL; /* local function prototypes */ static void _smart_calculate(Evas_Object *obj); /* local functions */ static void _smart_apply(Evas_Object *obj) { Grid *sd; Evas_Coord ox, oy; /* try to get smart data */ if (!(sd = evas_object_smart_data_get(obj))) return; evas_object_geometry_get(obj, &ox, &oy, NULL, NULL); /* TODO: finish */ /* loop cells on grid */ /* TODO: test scrolling */ evas_object_show(sd->cursor.obj); evas_object_move(sd->cursor.obj, ox + (sd->cursor.x * sd->font.chw), oy + (sd->cursor.y * sd->font.chh)); /* TODO: show/hide sel.theme object */ } static void _smart_size(Evas_Object *obj, int w, int h, Eina_Bool force) { Grid *sd; /* try to get smart data */ if (!(sd = evas_object_smart_data_get(obj))) return; if (w < 1) w = 1; if (h < 1) h = 1; if (!force) { if ((w == sd->grid.w) && (h == sd->grid.h)) return; } evas_event_freeze(sd->evas); evas_object_textgrid_size_set(sd->grid.obj, w, h); sd->grid.w = w; sd->grid.h = h; evas_object_resize(sd->cursor.obj, sd->font.chw, sd->font.chh); evas_object_size_hint_min_set(obj, sd->font.chw, sd->font.chh); evas_object_size_hint_request_set(obj, sd->font.chw * sd->grid.w, sd->font.chh * sd->grid.h); _smart_calculate(obj); _smart_apply(obj); evas_event_thaw(sd->evas); } static Eina_Bool _smart_cb_delayed_size(void *data) { Evas_Object *obj; Grid *sd; Evas_Coord ow = 0, oh = 0; obj = data; /* try to get smart data */ if (!(sd = evas_object_smart_data_get(obj))) return EINA_FALSE; sd->delayed_size_timer = NULL; evas_object_geometry_get(obj, NULL, NULL, &ow, &oh); _smart_size(obj, (ow / sd->font.chw), (oh / sd->font.chh), EINA_FALSE); return EINA_FALSE; } /* static Eina_Bool */ /* _smart_cb_change(void *data) */ /* { */ /* Evas_Object *obj; */ /* Grid *sd; */ /* obj = data; */ /* if (!(sd = evas_object_smart_data_get(obj))) return EINA_FALSE; */ /* _smart_apply(obj); */ /* evas_object_smart_callback_call(obj, "changed", NULL); */ /* return EINA_FALSE; */ /* } */ static void _smart_cb_cursor_move(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED) { Grid *sd; /* try to get smart data */ if (!(sd = evas_object_smart_data_get(data))) return; /* TODO: imf_cursor_set */ } static void _smart_calculate(Evas_Object *obj) { Grid *sd; Evas_Coord ox, oy, ow, oh; /* try to get smart data */ if (!(sd = evas_object_smart_data_get(obj))) return; evas_object_geometry_get(obj, &ox, &oy, &ow, &oh); evas_object_move(sd->grid.obj, ox, oy); evas_object_resize(sd->grid.obj, sd->grid.w * sd->font.chw, sd->grid.h * sd->font.chh); evas_object_move(sd->cursor.obj, ox + (sd->cursor.x * sd->font.chw), oy + (sd->cursor.y * sd->font.chh)); evas_object_move(sd->o_event, ox, oy); evas_object_resize(sd->o_event, ow, oh); } static void _smart_add(Evas_Object *obj) { Grid *sd; /* try to allocate space for new smart data */ if (!(sd = calloc(1, sizeof(Grid)))) return; /* FIXME */ sd->font.size = 8; sd->font.chw = 1; sd->font.chh = 1; evas_object_smart_data_set(obj, sd); _parent_sc.add(obj); sd->evas = evas_object_evas_get(obj); /* create grid object */ sd->grid.obj = evas_object_textgrid_add(sd->evas); evas_object_pass_events_set(sd->grid.obj, EINA_TRUE); evas_object_propagate_events_set(sd->grid.obj, EINA_FALSE); evas_object_smart_member_add(sd->grid.obj, obj); evas_object_show(sd->grid.obj); /* create cursor */ sd->cursor.obj = edje_object_add(sd->evas); evas_object_pass_events_set(sd->cursor.obj, EINA_TRUE); evas_object_propagate_events_set(sd->cursor.obj, EINA_FALSE); evas_object_smart_member_add(sd->cursor.obj, obj); evas_object_event_callback_add(sd->cursor.obj, EVAS_CALLBACK_MOVE, _smart_cb_cursor_move, obj); /* create selection */ sd->sel.top = evas_object_rectangle_add(sd->evas); evas_object_pass_events_set(sd->sel.top, EINA_TRUE); evas_object_propagate_events_set(sd->sel.top, EINA_FALSE); sd->sel.bottom = evas_object_rectangle_add(sd->evas); evas_object_pass_events_set(sd->sel.bottom, EINA_TRUE); evas_object_propagate_events_set(sd->sel.bottom, EINA_FALSE); sd->sel.theme = edje_object_add(sd->evas); evas_object_smart_member_add(sd->sel.theme, obj); /* TODO: callbacks */ /* create event object */ sd->o_event = evas_object_rectangle_add(sd->evas); evas_object_repeat_events_set(sd->o_event, EINA_TRUE); evas_object_color_set(sd->o_event, 255, 0, 0,32); evas_object_smart_member_add(sd->o_event, obj); evas_object_show(sd->o_event); /* TODO: Finish callbacks & imf */ } static void _smart_del(Evas_Object *obj) { Grid *sd; /* try to get smart data */ if (!(sd = evas_object_smart_data_get(obj))) return; if (sd->delayed_size_timer) ecore_timer_del(sd->delayed_size_timer); if (sd->cursor.obj) evas_object_del(sd->cursor.obj); if (sd->o_event) evas_object_del(sd->o_event); if (sd->sel.top) evas_object_del(sd->sel.top); if (sd->sel.bottom) evas_object_del(sd->sel.bottom); if (sd->sel.theme) evas_object_del(sd->sel.theme); if (sd->grid.obj) evas_object_del(sd->grid.obj); /* TODO: finish */ _parent_sc.del(obj); } static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h) { Grid *sd; Evas_Coord ow, oh; /* try to get smart data */ if (!(sd = evas_object_smart_data_get(obj))) return; evas_object_geometry_get(obj, NULL, NULL, &ow, &oh); if ((ow == w) && (oh == h)) return; evas_object_smart_changed(obj); if (!sd->delayed_size_timer) { sd->delayed_size_timer = ecore_timer_add(0.0, _smart_cb_delayed_size, obj); } else ecore_timer_delay(sd->delayed_size_timer, 0.0); evas_object_resize(sd->o_event, ow, oh); } static void _smart_move(Evas_Object *obj, Evas_Coord x EINA_UNUSED, Evas_Coord y EINA_UNUSED) { evas_object_smart_changed(obj); } static void _smart_init(void) { static Evas_Smart_Class sc; evas_object_smart_clipped_smart_set(&_parent_sc); sc = _parent_sc; sc.name = "grid"; sc.version = EVAS_SMART_CLASS_VERSION; sc.add = _smart_add; sc.del = _smart_del; sc.resize = _smart_resize; sc.move = _smart_move; sc.calculate = _smart_calculate; _smart = evas_smart_class_new(&sc); } Evas_Object * _grid_add(Evas_Object *parent) { Evas_Object *obj; Grid *sd; Evas *evas; if (!parent) return NULL; if (!(evas = evas_object_evas_get(parent))) return NULL; if (!_smart) _smart_init(); obj = evas_object_smart_add(evas, _smart); if (!(sd = evas_object_smart_data_get(obj))) return obj; _smart_size(obj, 80, 24, EINA_FALSE); return obj; }