From e135278ddb46e0f301474da49b1d522552b42e6f Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 14 Mar 2016 18:19:38 +0900 Subject: [PATCH] + view menu popup! Change-Id: Icf75a6ac9229b7a65c692780ab2ae9e454fdf471 --- src/examples/efl/page1.h | 24 ++++- src/include/efl/mobile/ui_basic_view.h | 11 ++- src/lib/efl/mobile/ui_basic_view.cpp | 154 +++++++++++++++++++++++++++------ 3 files changed, 161 insertions(+), 28 deletions(-) diff --git a/src/examples/efl/page1.h b/src/examples/efl/page1.h index 3c8bd06..0df1305 100644 --- a/src/examples/efl/page1.h +++ b/src/examples/efl/page1.h @@ -14,6 +14,14 @@ * limitations under the License. * */ +static void ctxpopup_item_select_cb(void *data, Evas_Object *obj, void *event_info) +{ + ui_basic_view *view = static_cast(data); + Elm_Object_Item *it = static_cast(event_info); + elm_ctxpopup_dismiss(obj); + LOGE("Item (%s) is selected", elm_object_item_text_get(it)); +} + class page1: public ui_basic_controller { private: @@ -58,7 +66,21 @@ public: bool menu() { - LOGE("Menu!"); + ui_basic_view *view = dynamic_cast(this->get_view()); + + Evas_Object *ctxpopup = elm_ctxpopup_add(view->get_base()); + elm_ctxpopup_item_append(ctxpopup, "Phone calls", NULL, ctxpopup_item_select_cb, this); + elm_ctxpopup_item_append(ctxpopup, "Favorites", NULL, ctxpopup_item_select_cb, this); + elm_ctxpopup_item_append(ctxpopup, "Search", NULL, ctxpopup_item_select_cb, this); + elm_ctxpopup_item_append(ctxpopup, "Dialer", NULL, ctxpopup_item_select_cb, this); + elm_ctxpopup_item_append(ctxpopup, "Add contact", NULL, ctxpopup_item_select_cb, this); + elm_ctxpopup_item_append(ctxpopup, "Phone calls", NULL, ctxpopup_item_select_cb, this); + elm_ctxpopup_item_append(ctxpopup, "Favorites", NULL, ctxpopup_item_select_cb, this); + elm_ctxpopup_item_append(ctxpopup, "Search", NULL, ctxpopup_item_select_cb, this); + elm_ctxpopup_item_append(ctxpopup, "Dialer", NULL, ctxpopup_item_select_cb, this); + + view->set_menu(ctxpopup); + return true; } }; diff --git a/src/include/efl/mobile/ui_basic_view.h b/src/include/efl/mobile/ui_basic_view.h index 3835639..1db146f 100644 --- a/src/include/efl/mobile/ui_basic_view.h +++ b/src/include/efl/mobile/ui_basic_view.h @@ -25,7 +25,8 @@ namespace efl_viewmgr class ui_basic_view: public ui_view { private: - Evas_Object *layout; //Base layout for view + Evas_Object *layout; //Base layout for view + Evas_Object *ctxpopup; //Menu Widget bool create_layout(); bool destroy_layout(); @@ -49,6 +50,8 @@ public: bool set_title_right_btn(Evas_Object *title_right_btn); bool set_title(const char *text); bool set_toolbar(Evas_Object *toolbar); + bool set_menu(Evas_Object *menu); + Evas_Object * unset_menu(); virtual void menu(); @@ -57,6 +60,12 @@ public: if (!this->layout)this->create_layout(); return this->layout; } + + Evas_Object *get_menu() + { + return this->ctxpopup; + } + }; } diff --git a/src/lib/efl/mobile/ui_basic_view.cpp b/src/lib/efl/mobile/ui_basic_view.cpp index e686271..bd1154a 100644 --- a/src/lib/efl/mobile/ui_basic_view.cpp +++ b/src/lib/efl/mobile/ui_basic_view.cpp @@ -23,6 +23,28 @@ using namespace efl_viewmgr; using namespace viewmgr; + +static void update_menu(Evas_Object *win, Evas_Object *ctxpopup) +{ + /* We convince the top widget is a window */ + Evas_Coord w, h; + elm_win_screen_size_get(win, NULL, NULL, &w, &h); + int rot = elm_win_rotation_get(win); + + switch (rot) + { + case 0: + case 180: + evas_object_move(ctxpopup, (w / 2), h); + break; + case 90: + case 270: + evas_object_move(ctxpopup, (h / 2), w); + break; + } + evas_object_show(ctxpopup); +} + bool ui_basic_view::destroy_layout() { if (!this->layout) return false; @@ -82,13 +104,38 @@ bool ui_basic_view::create_layout() } } + //FIXME: .... ? + evas_object_event_callback_add(layout, EVAS_CALLBACK_RESIZE, + [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void + { + ui_basic_view *view = static_cast(data); + Evas_Object *ctxpopup = view->get_menu(); + if (ctxpopup && evas_object_visible_get(ctxpopup)) + { + update_menu(dynamic_cast(view->get_viewmgr())->get_window(), ctxpopup); + } + }, + this); + + evas_object_event_callback_add(layout, EVAS_CALLBACK_MOVE, + [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void + { + ui_basic_view *view = static_cast(data); + Evas_Object *ctxpopup = view->get_menu(); + if (ctxpopup && evas_object_visible_get(ctxpopup)) + { + elm_ctxpopup_dismiss(ctxpopup); + } + }, + this); + this->layout = layout; return true; } ui_basic_view::ui_basic_view(ui_controller *controller, const char *name) - : ui_view(controller, name), layout(NULL) + : ui_view(controller, name), layout(NULL), ctxpopup(NULL) { } @@ -99,6 +146,7 @@ ui_basic_view::ui_basic_view(const char *name) ui_basic_view::~ui_basic_view() { + evas_object_del(this->ctxpopup); destroy_layout(); } @@ -225,37 +273,78 @@ Evas_Object *ui_basic_view::set_content(Evas_Object *content, const char *title, return pcontent; } +Evas_Object* ui_basic_view::unset_menu() +{ + Evas_Object *menu = this->ctxpopup; + //FIXME: cancel callbacks + this->ctxpopup = NULL; + return menu; +} + +bool ui_basic_view::set_menu(Evas_Object *menu) +{ + if (this->ctxpopup) evas_object_del(this->ctxpopup); + + //validation! + if (strcmp(evas_object_type_get(menu), "elm_ctxpopup")) + { + LOGE("Menu widget is not a ctxpopup!"); + return false; + } + + //FIXME: rename style. + elm_object_style_set(menu, "more/default"); + elm_ctxpopup_auto_hide_disabled_set(menu, EINA_TRUE); + evas_object_smart_callback_add(menu, "dismissed", + [](void *data, Evas_Object *obj, void *event_info) -> void + { + evas_object_hide(obj); + }, + NULL); + evas_object_event_callback_add(menu, EVAS_CALLBACK_DEL, + [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void + { + ui_basic_view *view = static_cast(data); + view->unset_menu(); + }, + this); + + this->ctxpopup = menu; + + return true; +} + bool ui_basic_view::set_toolbar(Evas_Object *toolbar) { Evas_Object *layout = this->get_base(); - if (layout) + //FIXME: Keep this toolbar inside of this view then set up when layout is created after. + if (!layout) { - if ((!strcmp(elm_object_style_get(toolbar), "toolbar_with_title")) && - ((elm_toolbar_shrink_mode_get(toolbar) != ELM_TOOLBAR_SHRINK_EXPAND))) - { - elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND); - } - else if (!strcmp(elm_object_style_get(toolbar), "navigationbar")) - { - if (elm_toolbar_shrink_mode_get(toolbar) != ELM_TOOLBAR_SHRINK_SCROLL) - elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_SCROLL); - elm_toolbar_align_set(toolbar, 0.0); - } - elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE); + LOGE("Layout is not exist!"); + return false; + } - //FIXME: It can be deleted when the application want to handle this property. - // Some of application may want to select one of toolbar item when view activated. - elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS); + if (!strcmp(elm_object_style_get(toolbar), "navigationbar")) + { + if (elm_toolbar_shrink_mode_get(toolbar) != ELM_TOOLBAR_SHRINK_SCROLL) elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_SCROLL); + elm_toolbar_align_set(toolbar, 0.0); + } + else + { + elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND); + } + elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE); - elm_object_part_content_set(layout, "toolbar", toolbar); - if (toolbar) elm_object_signal_emit(layout, "elm,state,toolbar,show", "elm"); - else elm_object_signal_emit(layout, "elm,state,toolbar,hide", "elm"); + //FIXME: It can be deleted when the application want to handle this property. + // Some of application may want to select one of toolbar item when view activated. + elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS); - return true; - } - LOGE("Layout is not exist!"); - return false; + elm_object_part_content_set(layout, "toolbar", toolbar); + if (toolbar) elm_object_signal_emit(layout, "elm,state,toolbar,show", "elm"); + else elm_object_signal_emit(layout, "elm,state,toolbar,hide", "elm"); + + return true; } void ui_basic_view::unload_content() @@ -266,8 +355,21 @@ void ui_basic_view::unload_content() void ui_basic_view::menu() { - if (!this->get_controller()) return; - (dynamic_cast(this->get_controller()))->menu(); + if (this->ctxpopup && evas_object_visible_get(this->ctxpopup)) + { + elm_ctxpopup_dismiss(this->ctxpopup); + return; + } + + if (this->get_controller()) + { + (dynamic_cast(this->get_controller()))->menu(); + } + + if (this->ctxpopup) + { + update_menu(dynamic_cast(this->get_viewmgr())->get_window(), this->ctxpopup); + } } void ui_basic_view::set_event_block(bool block) -- 2.7.4