From db8f53b3b89ab250fc3ffc81d9133ede0351f6e5 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Sat, 5 Nov 2005 12:12:17 +0000 Subject: [PATCH] starting work on ilist... gfx suck atm. need to eat. commit. SVN revision: 18318 --- data/themes/Makefile.am | 3 +- data/themes/default.edc | 1 + data/themes/default_ilist.edc | 102 ++++++++ data/themes/default_scrollframe.edc | 3 + src/bin/Makefile.am | 4 +- src/bin/e_ilist.c | 360 ++++++++++++++++++++++++++++ src/bin/e_ilist.h | 18 ++ src/bin/e_includes.h | 1 + src/bin/e_test.c | 89 ++++++- 9 files changed, 578 insertions(+), 3 deletions(-) create mode 100644 data/themes/default_ilist.edc create mode 100644 src/bin/e_ilist.c create mode 100644 src/bin/e_ilist.h diff --git a/data/themes/Makefile.am b/data/themes/Makefile.am index fd9db74da..5760d7425 100644 --- a/data/themes/Makefile.am +++ b/data/themes/Makefile.am @@ -46,7 +46,8 @@ default_radio.edc \ default_frame.edc \ default_label.edc \ default_button.edc \ -default_scrollframe.edc +default_scrollframe.edc \ +default_ilist.edc default.edj: Makefile $(EXTRA_DIST) $(EDJE_CC) $(EDJE_FLAGS) \ diff --git a/data/themes/default.edc b/data/themes/default.edc index 58424a079..8ec7a26ea 100644 --- a/data/themes/default.edc +++ b/data/themes/default.edc @@ -55,5 +55,6 @@ collections { #include "default_button.edc" #include "default_label.edc" #include "default_scrollframe.edc" +#include "default_ilist.edc" } diff --git a/data/themes/default_ilist.edc b/data/themes/default_ilist.edc new file mode 100644 index 000000000..b6186be95 --- /dev/null +++ b/data/themes/default_ilist.edc @@ -0,0 +1,102 @@ +images { + image: "focus.png" COMP; +} +group { + name: "widgets/ilist"; + parts { + part { + name: "icon_swallow"; + type: SWALLOW; + mouse_events: 0; + description { + state: "default" 0.0; + align: 0.0 0.5; + aspect: 1.0 1.0; + aspect_preference: VERTICAL; + rel1 { + relative: 0.0 0.0; + offset: 2 2; + } + rel2 { + relative: 0.0 1.0; + offset: 2 -3; + } + } + } + part { + name: "label"; + type: TEXT; + effect: SHADOW; + mouse_events: 0; + description { + state: "default" 0.0; + min: 16 16; + rel1 { + to_x: "icon_swallow"; + relative: 1.0 0.0; + offset: 2 2; + } + rel2 { + relative: 1.0 1.0; + offset: -2 -2; + } + color: 0 0 0 255; + color3: 255 255 255 128; + text { + text: "Item Label"; + font: "Edje-Vera"; + size: 10; + min: 1 1; + align: 0.0 0.5; + } + } + } + part { + name: "overlay"; + mouse_events: 0; + description { + state: "default" 0.0; + visible: 1; + color: 255 255 255 32; + image { + normal: "focus.png"; + border: 7 7 7 7; + middle: 0; + } + fill { + smooth: 0; + } + } + description { + state: "active" 0.0; + inherit: "default" 0.0; + visible: 1; + color: 255 255 255 255; + } + } + part { + name: "event"; + type: RECT; + description { + state: "default" 0.0; + color: 0 0 0 0; + } + } + } + programs { + program { + name: "go_active"; + signal: "active"; + source: ""; + action: STATE_SET "active" 0.0; + target: "overlay"; + } + program { + name: "go_passive"; + signal: "passive"; + source: ""; + action: STATE_SET "default" 0.0; + target: "overlay"; + } + } +} diff --git a/data/themes/default_scrollframe.edc b/data/themes/default_scrollframe.edc index 5e17aa33d..a320af290 100644 --- a/data/themes/default_scrollframe.edc +++ b/data/themes/default_scrollframe.edc @@ -61,6 +61,9 @@ group { description { state: "default" 0.0; color: 0 0 0 0; + rel1 { + offset: 3 3; + } rel2 { relative: 0.0 0.0; offset: -1 -1; diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index ffda47eef..c730766ba 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -108,7 +108,8 @@ e_widget_fileman.h \ e_scrollframe.h \ e_file_selector.h \ e_file_dialog.h \ -e_int_border_menu.h +e_int_border_menu.h \ +e_ilist.h enlightenment_src = \ e_user.c \ @@ -198,6 +199,7 @@ e_scrollframe.c \ e_file_selector.c \ e_file_dialog.c \ e_int_border_menu.c \ +e_ilist.c \ $(ENLIGHTENMENTHEADERS) enlightenment_SOURCES = \ diff --git a/src/bin/e_ilist.c b/src/bin/e_ilist.c new file mode 100644 index 000000000..d32e7f7ee --- /dev/null +++ b/src/bin/e_ilist.c @@ -0,0 +1,360 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#include "e.h" + +#define SMART_NAME "e_ilist" +#define API_ENTRY E_Smart_Data *sd; sd = evas_object_smart_data_get(obj); if ((!obj) || (!sd) || (evas_object_type_get(obj) && strcmp(evas_object_type_get(obj), SMART_NAME))) +#define INTERNAL_ENTRY E_Smart_Data *sd; sd = evas_object_smart_data_get(obj); if (!sd) return; +typedef struct _E_Smart_Data E_Smart_Data; +typedef struct _E_Smart_Item E_Smart_Item; + +struct _E_Smart_Data +{ + Evas_Coord x, y, w, h; + + Evas_Object *smart_obj; + Evas_Object *box_obj; + Evas_List *items; + int selected; + Evas_Coord icon_w, icon_h; +}; + +struct _E_Smart_Item +{ + E_Smart_Data *sd; + Evas_Object *base_obj; + Evas_Object *icon_obj; + void (*func) (void *data); + void *data; +}; + +/* local subsystem functions */ +static void _e_smart_event_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info); +static void _e_smart_event_key_down(void *data, Evas *e, Evas_Object *obj, void *event_info); +static void _e_smart_reconfigure(E_Smart_Data *sd); +static void _e_smart_add(Evas_Object *obj); +static void _e_smart_del(Evas_Object *obj); +static void _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y); +static void _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); +static void _e_smart_show(Evas_Object *obj); +static void _e_smart_hide(Evas_Object *obj); +static void _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a); +static void _e_smart_clip_set(Evas_Object *obj, Evas_Object * clip); +static void _e_smart_clip_unset(Evas_Object *obj); +static void _e_smart_init(void); + +/* local subsystem globals */ +static Evas_Smart *_e_smart = NULL; + +/* externally accessible functions */ +Evas_Object * +e_ilist_add(Evas *evas) +{ + _e_smart_init(); + return evas_object_smart_add(evas, _e_smart); +} + +void +e_ilist_icon_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h) +{ + Evas_List *l; + + API_ENTRY return; + if ((sd->icon_w == w) && (sd->icon_h == h)) return; + sd->icon_w = w; + sd->icon_h = h; + for (l = sd->items; l; l = l->next) + { + E_Smart_Item *si; + + si = l->data; + if (si->icon_obj) + { + Evas_Coord mw = 0, mh = 0; + + edje_extern_object_min_size_set(si->icon_obj, sd->icon_w, sd->icon_h); + edje_object_part_swallow(si->base_obj, "icon_swallow", si->icon_obj); + edje_object_size_min_calc(si->base_obj, &mw, &mh); + e_box_pack_options_set(si->icon_obj, + 1, 1, /* fill */ + 1, 0, /* expand */ + 0.5, 0.5, /* align */ + mw, mh, /* min */ + 99999, 99999 /* max */ + ); + } + } +} + +void +e_ilist_append(Evas_Object *obj, Evas_Object *icon, char *label, void (*func) (void *data), void *data) +{ + E_Smart_Item *si; + Evas_Coord mw = 0, mh = 0; + + API_ENTRY return; + si = E_NEW(E_Smart_Item, 1); + si->sd = sd; + si->base_obj = edje_object_add(evas_object_evas_get(sd->smart_obj)); +// if (evas_list_count(sd->items) & 0x1) +// e_theme_edje_object_set(si->base_obj, "base/theme/widgets", +// "widgets/ilist_odd"); +// else + e_theme_edje_object_set(si->base_obj, "base/theme/widgets", + "widgets/ilist"); + edje_object_part_text_set(si->base_obj, "label", label); + si->icon_obj = icon; + if (si->icon_obj) + { + edje_extern_object_min_size_set(si->icon_obj, sd->icon_w, sd->icon_h); + edje_object_part_swallow(si->base_obj, "icon_swallow", si->icon_obj); + evas_object_show(si->icon_obj); + } + si->func = func; + si->data = data; + sd->items = evas_list_append(sd->items, si); + edje_object_size_min_calc(si->base_obj, &mw, &mh); + e_box_pack_end(sd->box_obj, si->base_obj); + e_box_pack_options_set(si->base_obj, + 1, 1, /* fill */ + 1, 1, /* expand */ + 0.5, 0.5, /* align */ + mw, mh, /* min */ + 99999, 99999 /* max */ + ); + if (sd->selected == (evas_list_count(sd->items) - 1)) + { + edje_object_signal_emit(si->base_obj, "active", ""); + if (si->func) si->func(si->data); + } + evas_object_event_callback_add(si->base_obj, EVAS_CALLBACK_MOUSE_DOWN, _e_smart_event_mouse_down, si); + evas_object_show(si->base_obj); +} + +void +e_ilist_select_set(Evas_Object *obj, int n) +{ + E_Smart_Item *si; + + API_ENTRY return; + if (!sd->items) return; + if (n >= evas_list_count(sd->items)) n = evas_list_count(sd->items) - 1; + else if (n < 0) n = 0; + if (sd->selected == n) return; + si = evas_list_nth(sd->items, sd->selected); + if (si) edje_object_signal_emit(si->base_obj, "passive", ""); + sd->selected = n; + si = evas_list_nth(sd->items, sd->selected); + if (si) + { + edje_object_signal_emit(si->base_obj, "active", ""); + if (si->func) si->func(si->data); + } +} + +int +e_ilist_select_get(Evas_Object *obj) +{ + API_ENTRY return -1; + if (!sd->items) return -1; + return sd->selected; +} + +void * +e_ilist_select_data_get(Evas_Object *obj) +{ + E_Smart_Item *si; + + API_ENTRY return NULL; + if (!sd->items) return NULL; + si = evas_list_nth(sd->items, sd->selected); + if (si) return si->data; + return NULL; +} + +void +e_ilist_selected_geometry_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h) +{ + E_Smart_Item *si; + + API_ENTRY return; + si = evas_list_nth(sd->items, sd->selected); + if (si) + { + evas_object_geometry_get(si->base_obj, x, y, w, h); + *x -= sd->x; + *y -= sd->y; + } +} + +void +e_ilist_min_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h) +{ + API_ENTRY return; + e_box_min_size_get(sd->box_obj, w, h); +} + +/* local subsystem functions */ +static void +_e_smart_event_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Down *ev; + E_Smart_Item *si; + Evas_List *l; + int i; + + si = data; + ev = event_info; + for (i = 0, l = si->sd->items; l; l = l->next, i++) + { + if (l->data == si) + { + e_ilist_select_set(si->sd->smart_obj, i); + break; + } + } +} + +static void +_e_smart_event_key_down(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + Evas_Event_Key_Down *ev; + E_Smart_Data *sd; + + sd = data; + ev = event_info; + if (!strcmp(ev->keyname, "Up")) + { + int n; + + n = e_ilist_select_get(sd->smart_obj); + e_ilist_select_set(sd->smart_obj, n - 1); + } + else if (!strcmp(ev->keyname, "Down")) + { + int n; + + n = e_ilist_select_get(sd->smart_obj); + e_ilist_select_set(sd->smart_obj, n + 1); + } +} + +static void +_e_smart_reconfigure(E_Smart_Data *sd) +{ + evas_object_move(sd->box_obj, sd->x, sd->y); + evas_object_resize(sd->box_obj, sd->w, sd->h); +} + +static void +_e_smart_add(Evas_Object *obj) +{ + E_Smart_Data *sd; + Evas_Object *o; + + sd = calloc(1, sizeof(E_Smart_Data)); + if (!sd) return; + evas_object_smart_data_set(obj, sd); + + sd->smart_obj = obj; + sd->x = 0; + sd->y = 0; + sd->w = 0; + sd->h = 0; + + sd->icon_w = 24; + sd->icon_h = 24; + + sd->box_obj = e_box_add(evas_object_evas_get(obj)); + e_box_align_set(sd->box_obj, 0.0, 0.0); + e_box_homogenous_set(sd->box_obj, 0); + evas_object_smart_member_add(sd->box_obj, obj); + + evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _e_smart_event_key_down, sd); + evas_object_propagate_events_set(obj, 0); +} + +static void +_e_smart_del(Evas_Object *obj) +{ + INTERNAL_ENTRY; + evas_object_del(sd->box_obj); + free(sd); +} + +static void +_e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y) +{ + INTERNAL_ENTRY; + if ((sd->x == x) && (sd->y == y)) return; + sd->x = x; + sd->y = y; + _e_smart_reconfigure(sd); +} + +static void +_e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h) +{ + INTERNAL_ENTRY; + if ((sd->w == w) && (sd->h == h)) return; + sd->w = w; + sd->h = h; + _e_smart_reconfigure(sd); +} + +static void +_e_smart_show(Evas_Object *obj) +{ + INTERNAL_ENTRY; + evas_object_show(sd->box_obj); +} + +static void +_e_smart_hide(Evas_Object *obj) +{ + INTERNAL_ENTRY; + evas_object_hide(sd->box_obj); +} + +static void +_e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a) +{ + INTERNAL_ENTRY; + evas_object_color_set(sd->box_obj, r, g, b, a); +} + +static void +_e_smart_clip_set(Evas_Object *obj, Evas_Object * clip) +{ + INTERNAL_ENTRY; + evas_object_clip_set(sd->box_obj, clip); +} + +static void +_e_smart_clip_unset(Evas_Object *obj) +{ + INTERNAL_ENTRY; + evas_object_clip_unset(sd->box_obj); +} + +/* never need to touch this */ + +static void +_e_smart_init(void) +{ + if (_e_smart) return; + _e_smart = evas_smart_new(SMART_NAME, + _e_smart_add, + _e_smart_del, + NULL, NULL, NULL, NULL, NULL, + _e_smart_move, + _e_smart_resize, + _e_smart_show, + _e_smart_hide, + _e_smart_color_set, + _e_smart_clip_set, + _e_smart_clip_unset, + NULL); +} + diff --git a/src/bin/e_ilist.h b/src/bin/e_ilist.h new file mode 100644 index 000000000..a71ff0bfc --- /dev/null +++ b/src/bin/e_ilist.h @@ -0,0 +1,18 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ +#ifdef E_TYPEDEFS +#else +#ifndef E_ILIST_H +#define E_ILIST_H + +EAPI Evas_Object *e_ilist_add (Evas *evas); +EAPI void e_ilist_append (Evas_Object *obj, Evas_Object *icon, char *label, void (*func) (void *data), void *data); +EAPI void e_ilist_select_set (Evas_Object *obj, int n); +EAPI int e_ilist_select_get (Evas_Object *obj); +EAPI void *e_ilist_select_data_get (Evas_Object *obj); +EAPI void e_ilist_selected_geometry_get (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h); +EAPI void e_ilist_min_size_get (Evas_Object *obj, Evas_Coord *w, Evas_Coord *h); + +#endif +#endif diff --git a/src/bin/e_includes.h b/src/bin/e_includes.h index 0835d18c6..aa41d750e 100644 --- a/src/bin/e_includes.h +++ b/src/bin/e_includes.h @@ -89,3 +89,4 @@ #include "e_file_dialog.h" #include "e_widget_fileman.h" #include "e_int_border_menu.h" +#include "e_ilist.h" diff --git a/src/bin/e_test.c b/src/bin/e_test.c index 7c5e48997..965a4ff08 100644 --- a/src/bin/e_test.c +++ b/src/bin/e_test.c @@ -339,7 +339,6 @@ _e_test_internal(E_Container *con) o2 = e_scrollframe_add(dia->win->evas); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _e_test_click, o2); // e_scrollframe_custom_theme_set(o2, "base/theme/widgets", "widgets/scrollframe"); - evas_object_resize(o2, 200, 300); evas_object_show(o2); #if 0 o3 = e_pan_add(dia->win->evas); @@ -393,6 +392,94 @@ _e_test_internal(E_Container *con) tcon = con; _e_test_timer(NULL); } +#elif 0 + +struct _tmp +{ + Evas_Object *ilist, *scrollframe; +}; + +static struct _tmp tmp = {NULL, NULL}; + +static void +_e_test_sel(void *data) +{ + Evas_Coord x, y, w, h; + + printf("SEL:\n"); + e_ilist_selected_geometry_get(tmp.ilist, &x, &y, &w, &h); + e_scrollframe_child_region_show(tmp.scrollframe, x, y, w, h); +} + +static void +_e_test_internal(E_Container *con) +{ + E_Dialog *dia; + Evas_Coord mw, mh, vw, vh; + Evas_Object *o, *o2, *o3; + + dia = e_dialog_new(con); + e_dialog_title_set(dia, "A Test Dialog"); + + o = e_ilist_add(dia->win->evas); + + o3 = e_icon_add(dia->win->evas); + e_icon_file_set(o3, "/home/raster/C/stuff/icons/star_office.png"); + e_ilist_append(o, o3, "Item 1", _e_test_sel, NULL); + + o3 = e_icon_add(dia->win->evas); + e_icon_file_set(o3, "/home/raster/C/stuff/icons/palette.png"); + e_ilist_append(o, o3, "Item 2 (Some really long text goes here for testing)", _e_test_sel, NULL); + + o3 = e_icon_add(dia->win->evas); + e_icon_file_set(o3, "/home/raster/C/stuff/icons/mozilla.png"); + e_ilist_append(o, o3, "Item 3 (Medium length)", _e_test_sel, NULL); + + o3 = e_icon_add(dia->win->evas); + e_icon_file_set(o3, "/home/raster/C/stuff/icons/trash_open.png"); + e_ilist_append(o, o3, "Item POOP", _e_test_sel, NULL); + + o3 = e_icon_add(dia->win->evas); + e_icon_file_set(o3, "/home/raster/C/stuff/icons/watch.png"); + e_ilist_append(o, o3, "Item BLING BLING", _e_test_sel, NULL); + + o3 = e_icon_add(dia->win->evas); + e_icon_file_set(o3, "/home/raster/C/stuff/icons/quake3.png"); + e_ilist_append(o, o3, "Sukebelinth", _e_test_sel, NULL); + + o3 = e_icon_add(dia->win->evas); + e_icon_file_set(o3, "/home/raster/C/stuff/icons/opera6.png"); + e_ilist_append(o, o3, "Panties", _e_test_sel, NULL); + + o3 = e_icon_add(dia->win->evas); + e_icon_file_set(o3, "/home/raster/C/stuff/icons/drawer_open.png"); + e_ilist_append(o, o3, "Flimbert the cagey", _e_test_sel, NULL); + + o3 = e_icon_add(dia->win->evas); + e_icon_file_set(o3, "/home/raster/C/stuff/icons/cd.png"); + e_ilist_append(o, o3, "Norbert", _e_test_sel, NULL); + + e_ilist_min_size_get(o, &mw, &mh); + evas_object_resize(o, mw, mh); + evas_object_focus_set(o, 1); + evas_object_show(o); + + o2 = e_scrollframe_add(dia->win->evas); + evas_object_resize(o2, mw, 150); + evas_object_show(o2); + e_scrollframe_child_set(o2, o); + + e_scrollframe_child_viewport_size_get(o2, &vw, &vh); + e_dialog_content_set(dia, o2, mw + (mw - vw), 150); + e_dialog_button_add(dia, "OK", NULL, NULL, NULL); + e_win_centered_set(dia->win, 1); + e_dialog_show(dia); + + tmp.ilist = o; + tmp.scrollframe = o2; + + evas_object_focus_set(o, 1); +} #else static void _e_test_internal(E_Container *con)