From 3314ac30f127e43d279b4e4384ee98389c4b137a Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 12 May 2014 08:29:43 +1000 Subject: Move poor mans introspection into winFang.c, and use it in purkle. --- src/GuiLua/GuiLua.c | 10 ++---- src/extantz/files.c | 2 +- src/libraries/SledjHamr.h | 3 ++ src/libraries/winFang.c | 92 ++++++++++++++++++++++++++++++++++++----------- src/libraries/winFang.h | 29 ++++++++++++++- src/purkle/purkle.c | 26 +++----------- 6 files changed, 112 insertions(+), 50 deletions(-) diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index 06bc516..c845ff1 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -173,20 +173,16 @@ static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED static int widget(lua_State *L) { winFang *win = NULL; + Widget *wid; char *type = "button"; char *title = ":"; int x = -1, y = -1, w = -1, h = -1; pull_lua(L, 1, "*window $type $title %x %y %w %h", &win, &type, &title, &x, &y, &w, &h); - // Poor mans introspection, until I write real introspection into EFL. - // TODO - The alternative is to just lookup the ELM_*_CLASS in a hash table? - if (strcmp(type, "button") == 0) + wid = widgetAdd(win, type, title, x, y, w, h); + if (wid) { - Widget *wid; - - // These two lines are likely the only ones that will be different for the different sorts of widgets. - wid = widgetAdd(win, ELM_OBJ_BUTTON_CLASS, title, x, y, w, h); evas_object_smart_callback_add(wid->obj, "clicked", _on_click, wid); wid->data = L; diff --git a/src/extantz/files.c b/src/extantz/files.c index 9678e3e..1990091 100644 --- a/src/extantz/files.c +++ b/src/extantz/files.c @@ -148,7 +148,7 @@ winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool sa me = winFangAdd(ourGlobals->mainWindow, ourGlobals->win_w - 380, ourGlobals->win_w - 530, 300, 500, "file selector", "files", ourGlobals->world); - wid = widgetAdd(me, ELM_OBJ_FILESELECTOR_CLASS, NULL, -1, -1, -1, -1); + wid = widgetAdd(me, WT_FILES, NULL, -1, -1, -1, -1); fs = wid->obj; wid->data = ourGlobals; wid->on_del = _on_fs_del; diff --git a/src/libraries/SledjHamr.h b/src/libraries/SledjHamr.h index 956b37e..aee845d 100644 --- a/src/libraries/SledjHamr.h +++ b/src/libraries/SledjHamr.h @@ -14,6 +14,9 @@ #include +#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) + + void HamrTime(void *elm_main, char *domain); #endif diff --git a/src/libraries/winFang.c b/src/libraries/winFang.c index 4eb4a7b..d7feb39 100644 --- a/src/libraries/winFang.c +++ b/src/libraries/winFang.c @@ -1,6 +1,8 @@ #include "winFang.h" + + static void _checkWindowBounds(winFang *win, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h) { Evas_Object *test; @@ -341,43 +343,93 @@ void winFangDel(winFang *win) EINA_CLIST_FOR_EACH_ENTRY(wid, &win->widgets, Widget, node) { if (wid->on_del) wid->on_del(wid, wid->obj, NULL); + widgetDel(wid); eo_unref(wid->obj); } if (win->on_del) win->on_del(win, win->win, NULL); evas_object_del(win->win); } -Widget *widgetAdd(winFang *win, const Eo_Class *klass, char *title, int x, int y, int w, int h) + +static widgetSpec widgetClasses[15]; + +Widget *widgetAdd(winFang *win, char *type , char *title, int x, int y, int w, int h) { Widget *result; + const Eo_Class *klass = NULL; + int i; - result = calloc(1, sizeof(Widget)); - strcpy(result->magic, "Widget"); - eina_clist_add_head(&win->widgets, &result->node); - - result->obj = eo_add(klass, win->win, - evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), - evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), - evas_obj_visibility_set(EINA_TRUE), - eo_key_data_set("Widget", result, NULL) - ); + // Poor mans introspection. + if (NULL == widgetClasses[0].name) + { + i = 0; + widgetClasses[i].name = WT_CHECK; widgetClasses[i++].klass = ELM_OBJ_CHECK_CLASS; + widgetClasses[i].name = WT_BOX; widgetClasses[i++].klass = ELM_OBJ_BOX_CLASS; + widgetClasses[i].name = WT_BUTTON; widgetClasses[i++].klass = ELM_OBJ_BUTTON_CLASS; + widgetClasses[i].name = WT_ENTRY; widgetClasses[i++].klass = ELM_OBJ_ENTRY_CLASS; + widgetClasses[i].name = WT_FILES; widgetClasses[i++].klass = ELM_OBJ_FILESELECTOR_CLASS; + widgetClasses[i].name = WT_GRID; widgetClasses[i++].klass = ELM_OBJ_GRID_CLASS; + widgetClasses[i].name = WT_HOVER; widgetClasses[i++].klass = ELM_OBJ_HOVERSEL_CLASS; + widgetClasses[i].name = WT_IMAGE; widgetClasses[i++].klass = ELM_OBJ_IMAGE_CLASS; + widgetClasses[i].name = WT_LABEL; widgetClasses[i++].klass = ELM_OBJ_LABEL_CLASS; + widgetClasses[i].name = WT_LAYOUT; widgetClasses[i++].klass = ELM_OBJ_LAYOUT_CLASS; + widgetClasses[i].name = WT_RADIO; widgetClasses[i++].klass = ELM_OBJ_RADIO_CLASS; + widgetClasses[i].name = WT_RECT; widgetClasses[i++].klass = EVAS_OBJ_RECTANGLE_CLASS; + widgetClasses[i].name = WT_TEXT; widgetClasses[i++].klass = EVAS_OBJ_TEXT_CLASS; + widgetClasses[i].name = WT_TEXTBOX; widgetClasses[i++].klass = ELM_OBJ_ENTRY_CLASS; + widgetClasses[i].name = WT_TOOLBAR; widgetClasses[i++].klass = ELM_OBJ_TOOLBAR_CLASS; + } - if (x < 0) - elm_layout_box_append(win->win, WF_BOX, result->obj); - else - elm_grid_pack(win->grid, result->obj, x, y, w, h); - winFangCalcMinSize(win); + for (i = 0; i < ARRAY_LENGTH(widgetClasses); i++) + { + if (strcmp(type, widgetClasses[i].name) == 0) + { + klass = widgetClasses[i].klass; + break; + } + } - if (title) + if (klass) { - result->label = strdup(title); - elm_object_text_set(result->obj, result->label); - evas_object_name_set(result->obj, title); + result = calloc(1, sizeof(Widget)); + strcpy(result->magic, "Widget"); + strcpy(result->type, type); + eina_clist_add_head(&win->widgets, &result->node); + + result->obj = eo_add(klass, win->win, + evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), + evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), + evas_obj_visibility_set(EINA_TRUE), + eo_key_data_set("Widget", result, NULL) + ); + + if (x < 0) + elm_layout_box_append(win->win, WF_BOX, result->obj); + else + elm_grid_pack(win->grid, result->obj, x, y, w, h); + winFangCalcMinSize(win); + + if (title) + { + result->label = strdup(title); + elm_object_text_set(result->obj, result->label); + evas_object_name_set(result->obj, title); + } } return result; } +void widgetDel(Widget *wid) +{ + if (wid) + { + // TODO - This is to work around a bug in Elm entry, remove it when the bug is fixed. + // The bug is that editable entry widgets cause the app to hang on exit. + if (strcmp(WT_ENTRY, wid->type) == 0) + elm_entry_editable_set(wid->obj, EINA_FALSE); + } +} /* CALLBACK types diff --git a/src/libraries/winFang.h b/src/libraries/winFang.h index 1bdef20..edec11b 100644 --- a/src/libraries/winFang.h +++ b/src/libraries/winFang.h @@ -8,6 +8,8 @@ /* Enable access to unstable EFL EO API. */ #define EFL_EO_API_SUPPORT 1 +#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array)) + #include #include @@ -24,6 +26,29 @@ #define WF_SWALLOW "winFang/content" +typedef struct _widgetSpec +{ + char *name; + const Eo_Class *klass; +} widgetSpec; + +#define WT_CHECK "check" +#define WT_BOX "box" +#define WT_BUTTON "button" +#define WT_FILES "files" +#define WT_ENTRY "entry" +#define WT_GRID "grid" +#define WT_HOVER "hoversel" +#define WT_IMAGE "image" +#define WT_LABEL "label" +#define WT_LAYOUT "layout" +#define WT_RADIO "radio" +#define WT_RECT "rectangle" +#define WT_TEXT "text" +#define WT_TEXTBOX "textbox" +#define WT_TOOLBAR "toolbar" + + typedef struct _winFang { Evas *e; @@ -48,6 +73,7 @@ typedef struct _winFang typedef struct _Widget { char magic[8]; + char type[16]; Evas_Object *obj; char *label, *look, *action, *help; @@ -67,6 +93,7 @@ void winFangShow(winFang *win); void winFangCalcMinSize(winFang *win); void winFangDel(winFang *win); -Widget *widgetAdd(winFang *win, const Eo_Class *klass, char *title, int x, int y, int w, int h); +Widget *widgetAdd(winFang *win, char *type, char *title, int x, int y, int w, int h); +void widgetDel(Widget *wid); #endif diff --git a/src/purkle/purkle.c b/src/purkle/purkle.c index 7bd47e7..2ee4964 100644 --- a/src/purkle/purkle.c +++ b/src/purkle/purkle.c @@ -4,36 +4,20 @@ #include "winFang.h" -// TODO - This is to work around a bug in Elm entry, remove it when the bug is fixed. -// The bug is that editable entry widgets cause the app to hang on exit. -static void _on_entry_del(void *data, Evas_Object *obj, void *event_info) -{ -// winFang *me = data; - - elm_entry_editable_set(obj, EINA_FALSE); -} - static winFang *purkleAdd(winFang *parent, int w, int h, EPhysics_World *world) { winFang *me; Widget *wid; - Evas_Object *en; me = winFangAdd(parent, 30, 590, w, h, "chatter box", "purkle", world); - en = eo_add(ELM_OBJ_ENTRY_CLASS, me->win, + wid = widgetAdd(me, WT_TEXTBOX, "History is shown here", -1, -1, -1, -1); + eo_do(wid->obj, elm_obj_entry_scrollable_set(EINA_TRUE), - elm_obj_entry_editable_set(EINA_FALSE), - evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), - evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), - evas_obj_visibility_set(EINA_TRUE) + elm_obj_entry_editable_set(EINA_FALSE) ); - elm_object_text_set(en, "History is shown here"); - elm_layout_box_append(me->win, WF_BOX, en); - eo_unref(en); - wid = widgetAdd(me, ELM_OBJ_ENTRY_CLASS, "", -1, -1, -1, -1); - wid->on_del = _on_entry_del; + wid = widgetAdd(me, WT_ENTRY, "", -1, -1, -1, -1); eo_do(wid->obj, elm_obj_entry_scrollable_set(EINA_TRUE), elm_obj_entry_editable_set(EINA_TRUE) @@ -45,7 +29,7 @@ static winFang *purkleAdd(winFang *parent, int w, int h, EPhysics_World *world) } static const char *ourName = "purkle"; -int skang, _M; +static int skang, _M; int luaopen_purkle(lua_State *L) { -- cgit v1.1