From f8fc00691417f628ba09e53552f7ac89cfd98faa Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 4 May 2014 17:12:08 +1000 Subject: New fangWin and Widget structures, and modify fangWin stuff to use them. --- src/extantz/chat.c | 20 ++++++++++------- src/extantz/extantz.c | 10 ++++++--- src/extantz/extantz.h | 33 +++++++++++++++++++++++----- src/extantz/fangWin.c | 60 ++++++++++++++++++++++++++++++++++++++------------- src/extantz/files.c | 20 +++++++++-------- src/extantz/woMan.c | 29 +++++++++++++------------ 6 files changed, 118 insertions(+), 54 deletions(-) diff --git a/src/extantz/chat.c b/src/extantz/chat.c index 4ad5033..ef40d08 100644 --- a/src/extantz/chat.c +++ b/src/extantz/chat.c @@ -1,19 +1,22 @@ #include "extantz.h" -void chat_add(globals *ourGlobals) + +fangWin *chat_add(globals *ourGlobals) { - Evas_Object *win, *bx, *en; + fangWin *me; + Widget *wid; + Evas_Object *bx, *en; - win = fang_win_add(ourGlobals); + me = fang_win_add(ourGlobals); - bx = eo_add(ELM_OBJ_BOX_CLASS, win); + bx = eo_add(ELM_OBJ_BOX_CLASS, me->win); eo_do(bx, evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL) ); - elm_win_resize_object_add(win, bx); + elm_win_resize_object_add(me->win, bx); - en = eo_add(ELM_OBJ_ENTRY_CLASS, win); + en = eo_add(ELM_OBJ_ENTRY_CLASS, me->win); elm_object_text_set(en, "History is shown here"); eo_do(en, elm_obj_entry_scrollable_set(EINA_TRUE), @@ -25,7 +28,7 @@ void chat_add(globals *ourGlobals) elm_box_pack_end(bx, en); eo_unref(en); - en = eo_add(ELM_OBJ_ENTRY_CLASS, win); + en = eo_add(ELM_OBJ_ENTRY_CLASS, me->win); elm_object_text_set(en, ""); eo_do(en, elm_obj_entry_scrollable_set(EINA_TRUE), @@ -42,5 +45,6 @@ void chat_add(globals *ourGlobals) evas_object_show(bx); eo_unref(bx); - fang_win_complete(ourGlobals, win, 30, 500, ourGlobals->win_w / 3, ourGlobals->win_h / 3); + fang_win_complete(ourGlobals, me, 30, 500, ourGlobals->win_w / 3, ourGlobals->win_h / 3); + return me; } diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 1d37ade..a9e5f3e 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -327,6 +327,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) Evas_Object *obj; EPhysics_World *world; GLData *gld = NULL; + fangWin *chat = NULL, *files = NULL, *woMan = NULL; char buf[PATH_MAX]; // Eina_Bool gotWebKit = elm_need_web(); // Initialise ewebkit if it exists, or return EINA_FALSE if it don't. @@ -410,9 +411,9 @@ EAPI_MAIN int elm_main(int argc, char **argv) elm_win_resize_object_add(ourGlobals.win, ourGlobals.bx); // overlay_add(&ourGlobals); - woMan_add(&ourGlobals); - chat_add(&ourGlobals); - files_add(&ourGlobals); + woMan = woMan_add(&ourGlobals); + chat = chat_add(&ourGlobals); +// files = files_add(&ourGlobals); // Gotta do this after adding the windows, otherwise the menu renders under the window. // This sucks, gotta redefine this menu each time we create a new window? @@ -447,6 +448,9 @@ EAPI_MAIN int elm_main(int argc, char **argv) { Evas_3D_Demo_fini(&ourGlobals); eo_unref(ourGlobals.tb); + fang_win_del(&ourGlobals, woMan); + fang_win_del(&ourGlobals, chat); + fang_win_del(&ourGlobals, files); eo_unref(ourGlobals.bx); evas_object_del(ourGlobals.win); } diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h index 1cc76cd..a5fb794 100644 --- a/src/extantz/extantz.h +++ b/src/extantz/extantz.h @@ -123,6 +123,27 @@ typedef struct short x, y, z; } ezLandmark; +typedef struct _fangWin +{ + Evas_Object *win; + Eina_Clist widgets; + void *data; + Evas_Smart_Cb on_del; +} fangWin; + +typedef struct _Widget +{ + char magic[8]; + Evas_Object *obj; + Eina_Clist node; + char *label, *look, *action, *help; + // foreground / background colour + // thing + // types {} + // skangCoord x, y, w, h + void *data; + Evas_Smart_Cb on_del; +} Widget; typedef struct _Scene_Data { @@ -246,13 +267,15 @@ void Evas_3D_Demo_fini(globals *ourGlobals); void cameraAdd(globals *ourGlobals, Evas_Object *win); -Evas_Object *fang_win_add(globals *ourGlobals); -void fang_win_complete(globals *ourGlobals, Evas_Object *win, int x, int y, int w, int h); +fangWin *fang_win_add(globals *ourGlobals); +void fang_win_complete(globals *ourGlobals, fangWin *win, int x, int y, int w, int h); +void fang_win_del(globals *ourGlobals, fangWin *win); void overlay_add(globals *ourGlobals); +Widget *widgetAdd(fangWin *win); -void chat_add(globals *ourGlobals); -void files_add(globals *ourGlobals); -void woMan_add(globals *ourGlobals); +fangWin *chat_add(globals *ourGlobals); +fangWin *files_add(globals *ourGlobals); +fangWin *woMan_add(globals *ourGlobals); #ifdef __cplusplus diff --git a/src/extantz/fangWin.c b/src/extantz/fangWin.c index e95910c..7a9f0d5 100644 --- a/src/extantz/fangWin.c +++ b/src/extantz/fangWin.c @@ -1,7 +1,6 @@ #include "extantz.h" - // Elm inlined image windows needs this to change focus on mouse click. // Evas style event callback. static void _cb_mouse_down_elm(void *data, Evas *evas, Evas_Object *obj, void *event_info) @@ -77,40 +76,60 @@ static void create_handles(Evas_Object *obj) } } -Evas_Object *fang_win_add(globals *ourGlobals) +fangWin *fang_win_add(globals *ourGlobals) { - Evas_Object *win, *bg; + fangWin *result; + Evas_Object *bg; + + result = calloc(1, sizeof(fangWin)); + eina_clist_init(&result->widgets); // In theory this should create an EWS window, in practice, I'm not seeing any difference. // Guess I'll have to implement my own internal window manager. I don't think a basic one will be that hard. Famous last words. // elm_config_engine_set("ews"); - win = elm_win_add(ourGlobals->win, "inlined", ELM_WIN_INLINED_IMAGE); + result->win = elm_win_add(ourGlobals->win, "inlined", ELM_WIN_INLINED_IMAGE); // On mouse down we try to shift focus to the backing image, this seems to be the correct thing to force focus onto it's widgets. // According to the Elm inlined image window example, this is what's needed to. - evas_object_event_callback_add(elm_win_inlined_image_object_get(win), EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, NULL); - elm_win_alpha_set(win, EINA_TRUE); + evas_object_event_callback_add(elm_win_inlined_image_object_get(result->win), EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, NULL); + elm_win_alpha_set(result->win, EINA_TRUE); // Apparently transparent is not good enough for ELM backgrounds, so make it a rectangle. // Apparently coz ELM prefers stuff to have edjes. A bit over the top if all I want is a transparent rectangle. - bg = evas_object_rectangle_add(evas_object_evas_get(win)); + bg = evas_object_rectangle_add(evas_object_evas_get(result->win)); evas_object_color_set(bg, 50, 0, 100, 100); evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_win_resize_object_add(win, bg); + elm_win_resize_object_add(result->win, bg); evas_object_show(bg); - return win; + return result; } -void fang_win_complete(globals *ourGlobals, Evas_Object *win, int x, int y, int w, int h) +void fang_win_complete(globals *ourGlobals, fangWin *win, int x, int y, int w, int h) { // image object for win is unlinked to its pos/size - so manual control // this allows also for using map and other things with it. - evas_object_move(elm_win_inlined_image_object_get(win), x, y); + evas_object_move(elm_win_inlined_image_object_get(win->win), x, y); // Odd, it needs to be resized twice. WTF? - evas_object_resize(win, w, h); - evas_object_resize(elm_win_inlined_image_object_get(win), w, h); - evas_object_show(win); - create_handles(elm_win_inlined_image_object_get(win)); + evas_object_resize(win->win, w, h); + evas_object_resize(elm_win_inlined_image_object_get(win->win), w, h); + evas_object_show(win->win); + create_handles(elm_win_inlined_image_object_get(win->win)); +} + +void fang_win_del(globals *ourGlobals, fangWin *win) +{ + Widget *wid; + + if (!win) return; + + // Elm will delete our widgets, but if we are using eo, we need to unref them. + EINA_CLIST_FOR_EACH_ENTRY(wid, &win->widgets, Widget, node) + { + if (wid->on_del) wid->on_del(wid, wid->obj, NULL); + eo_unref(wid->obj); + } + if (win->on_del) win->on_del(win, win->win, NULL); + evas_object_del(win->win); } void overlay_add(globals *ourGlobals) @@ -154,3 +173,14 @@ void overlay_add(globals *ourGlobals) evas_object_resize(elm_win_inlined_image_object_get(gld->winwin), ourGlobals->win_w, ourGlobals->win_h); evas_object_show(gld->winwin); } + +Widget *widgetAdd(fangWin *win) +{ + Widget *result; + + result = calloc(1, sizeof(Widget)); + strcpy(result->magic, "Widget"); + eina_clist_add_head(&win->widgets, &result->node); + + return result; +} diff --git a/src/extantz/files.c b/src/extantz/files.c index 7cfc5c0..84bf37b 100644 --- a/src/extantz/files.c +++ b/src/extantz/files.c @@ -153,19 +153,20 @@ static Eina_Bool _edje_filter(const char *path, Eina_Bool dir, void *data EINA_U return EINA_FALSE; } -void files_add(globals *ourGlobals) +fangWin *files_add(globals *ourGlobals) { - Evas_Object *win, *bx, *vbox, *fs, *bt, *rd = NULL, *rdg = NULL, *hoversel; + fangWin *me; + Evas_Object *bx, *vbox, *fs, *bt, *rd = NULL, *rdg = NULL, *hoversel; - win = fang_win_add(ourGlobals); + me = fang_win_add(ourGlobals); - bx = eo_add(ELM_OBJ_BOX_CLASS, win); + bx = eo_add(ELM_OBJ_BOX_CLASS, me->win); eo_do(bx, elm_obj_box_homogeneous_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) ); - elm_win_resize_object_add(win, bx); + elm_win_resize_object_add(me->win, bx); fs = eo_add(ELM_OBJ_FILESELECTOR_CLASS, bx); eo_do(fs, @@ -198,7 +199,7 @@ void files_add(globals *ourGlobals) eo_unref(fs); - vbox = eo_add(ELM_OBJ_BOX_CLASS, win); + vbox = eo_add(ELM_OBJ_BOX_CLASS, me->win); eo_do(vbox, elm_obj_box_homogeneous_set(EINA_FALSE), elm_obj_box_horizontal_set(EINA_TRUE), @@ -236,7 +237,7 @@ void files_add(globals *ourGlobals) hoversel = elm_hoversel_add(vbox); - elm_hoversel_hover_parent_set(hoversel, win); + elm_hoversel_hover_parent_set(hoversel, me->win); evas_object_data_set(hoversel, "fileselector", fs); elm_object_text_set(hoversel, "sorting"); @@ -253,7 +254,7 @@ void files_add(globals *ourGlobals) evas_object_show(hoversel); hoversel = elm_hoversel_add(vbox); - elm_hoversel_hover_parent_set(hoversel, win); + elm_hoversel_hover_parent_set(hoversel, me->win); evas_object_data_set(hoversel, "fileselector", fs); elm_object_text_set(hoversel, "size"); @@ -270,5 +271,6 @@ void files_add(globals *ourGlobals) evas_object_show(bx); eo_unref(bx); - fang_win_complete(ourGlobals, win, ourGlobals->win_w - 380, ourGlobals->win_w - 530, 350, 500); + fang_win_complete(ourGlobals, me, ourGlobals->win_w - 380, ourGlobals->win_w - 530, 350, 500); + return me; } diff --git a/src/extantz/woMan.c b/src/extantz/woMan.c index 2e5e741..ffb063c 100644 --- a/src/extantz/woMan.c +++ b/src/extantz/woMan.c @@ -151,23 +151,23 @@ static void _grid_sel_cb(void *data, Evas_Object *obj, void *event_info) } -void woMan_add(globals *ourGlobals) +fangWin *woMan_add(globals *ourGlobals) { -// Evas_Object *win, *bg, *bx, *ic, *bb, *av, *en, *bt, *nf, *tab, *tb, *gridList, *viewerList, *menu; - Evas_Object *win, *bx, *bt, *nf, *tab, *tb, *gridList, *viewerList, *menu; + fangWin *me; + Evas_Object *bx, *bt, *nf, *tab, *tb, *gridList, *viewerList, *menu; Elm_Object_Item *tb_it, *menu_it, *tab_it; char buf[PATH_MAX]; int i; - win = fang_win_add(ourGlobals); + me = fang_win_add(ourGlobals); - bx = elm_box_add(win); - elm_win_resize_object_add(win, bx); + bx = elm_box_add(me->win); + elm_win_resize_object_add(me->win, bx); evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL); // A tab thingy. - tb = elm_toolbar_add(win); + tb = elm_toolbar_add(me->win); evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_SCROLL); @@ -177,7 +177,7 @@ void woMan_add(globals *ourGlobals) elm_toolbar_item_menu_set(tb_it, EINA_TRUE); // Priority is for when toolbar items are set to hide or menu when there are too many of them. They get hidden or put on the menu based on priority. elm_toolbar_item_priority_set(tb_it, 9999); - elm_toolbar_menu_parent_set(tb, win); + elm_toolbar_menu_parent_set(tb, me->win); menu = elm_toolbar_item_menu_get(tb_it); menu_it = elm_menu_item_add(menu, NULL, NULL, "edit", NULL, NULL); @@ -192,7 +192,7 @@ void woMan_add(globals *ourGlobals) elm_box_pack_end(bx, tb); evas_object_show(tb); - gridList = elm_genlist_add(win); + gridList = elm_genlist_add(me->win); grids = eina_hash_stringshared_new(free); evas_object_data_set(gridList, "glob", ourGlobals); @@ -241,7 +241,7 @@ void woMan_add(globals *ourGlobals) } // Viewers stuff - viewerList = elm_genlist_add(win); + viewerList = elm_genlist_add(me->win); viewer_gic = elm_genlist_item_class_new(); viewer_gic->item_style = "double_label"; viewer_gic->func.text_get = _viewer_label_get; @@ -263,18 +263,18 @@ void woMan_add(globals *ourGlobals) } // Toolbar pages - nf = elm_naviframe_add(win); + nf = elm_naviframe_add(me->win); evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(nf, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(nf); sprintf(buf, "%s/%s", elm_app_data_dir_get(), img3); tab = viewerList; tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Viewers", _promote, tab_it); - tab = _content_image_new(win, strdup(buf)); tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Landmarks", _promote, tab_it); + tab = _content_image_new(me->win, strdup(buf)); tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Landmarks", _promote, tab_it); tab = gridList; tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Grids", _promote, tab_it); elm_box_pack_end(bx, nf); - bt = eo_add(ELM_OBJ_BUTTON_CLASS, win); + bt = eo_add(ELM_OBJ_BUTTON_CLASS, me->win); elm_object_text_set(bt, "Login"); // No eo interface for this that I can find. eo_do(bt, // evas_obj_text_set("Login"), @@ -287,5 +287,6 @@ void woMan_add(globals *ourGlobals) eo_unref(bt); evas_object_show(bx); - fang_win_complete(ourGlobals, win, 30, 30, ourGlobals->win_w / 3, ourGlobals->win_h / 3); + fang_win_complete(ourGlobals, me, 30, 30, ourGlobals->win_w / 3, ourGlobals->win_h / 3); + return me; } -- cgit v1.1