From 6ba509773be4ee48a7975fd002d889b37748cddf Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 18 Feb 2016 17:09:37 +0900 Subject: [PATCH] ui_viewmgr: intensively implementing basic functions. Change-Id: I907c3dc5ba762ddf5fcea7226b61412c5a06f701 --- src/app_controller.h | 226 +++++++++++++++++++++------------------------ src/main.cpp | 6 +- src/ui_basic_view.cpp | 111 ++++++++++++++++++---- src/ui_basic_view.h | 12 ++- src/ui_controller.cpp | 7 +- src/ui_controller_base.cpp | 1 - src/ui_view.cpp | 4 +- src/ui_view.h | 15 +-- src/ui_view_base.cpp | 64 ++++++------- src/ui_view_base.h | 6 +- src/ui_viewmgr.cpp | 60 ++++++++---- src/ui_viewmgr.h | 186 ------------------------------------- src/ui_viewmgr_base.cpp | 30 +++--- src/ui_viewmgr_base.h | 20 +++- 14 files changed, 326 insertions(+), 422 deletions(-) diff --git a/src/app_controller.h b/src/app_controller.h index 8526c5a..80c8d44 100644 --- a/src/app_controller.h +++ b/src/app_controller.h @@ -1,6 +1,5 @@ #include "ui_controller.h" - static Evas_Object* create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad) { @@ -44,184 +43,163 @@ create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_cli } - - - class app_controller4: public ui_controller { private: appdata_s *ad; - Evas_Object *content; - - static void page_clicked_cb(void *data, Evas_Object *obj, void *event_info) - { - - appdata_s *ad = static_cast(data); - - } public: - app_controller4(appdata_s *ad) : - ad(ad), content(NULL) + app_controller4(appdata_s *ad) + : ad(ad) { } ~app_controller4() { - LOGE("controller 4"); } void load() { - LOGE("view 4 button create"); - ui_view *view = this->get_view(); - Evas_Object *btn = elm_button_add(view->get_base()); - elm_object_text_set(btn, "Page 4"); - view->set_content(btn); + //Initialize contents. + + ui_basic_view *view = dynamic_cast(this->get_view()); - evas_object_smart_callback_add(btn, "clicked", page_clicked_cb, this->ad); + //Create a main content. + Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 4", + //Prev Button + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->pop_view(); + }, + //Next Button + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->deactivate(); + }, this->ad); - this->content = btn; + //Arguments: content, title + view->set_content(content, "TitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"); + view->set_title_badge("999+"); } void unload() { - LOGE("controller4"); - evas_object_del(this->content); + //You could destroy the content here for save memory. ui_view *view = this->get_view(); - view->set_content(NULL); - } - - void active() - { - LOGE("controller4"); + Evas_Object *content = view->set_content(NULL); + evas_object_del(content); } - void inactive() - { - LOGE("controller4"); - } - - void destroy() - { - LOGE("controller4"); - } }; + class app_controller3: public ui_controller { private: appdata_s *ad; - Evas_Object *content; - - static void page_clicked_cb(void *data, Evas_Object *obj, void *event_info) - { - - appdata_s *ad = static_cast(data); - - //View 4 - - app_controller4 *controller = new app_controller4(ad); - ad->viewmgr->push_view(new ui_basic_view(controller)); - - } public: - app_controller3(appdata_s *ad) : - ad(ad), content(NULL) + app_controller3(appdata_s *ad) + : ad(ad) { } ~app_controller3() { - LOGE("controller 3"); } void load() { - ui_view *view = this->get_view(); - Evas_Object *btn = elm_button_add(view->get_base()); - elm_object_text_set(btn, "Page 3"); - view->set_content(btn); + //Initialize contents. - evas_object_smart_callback_add(btn, "clicked", page_clicked_cb, this->ad); + ui_basic_view *view = dynamic_cast(this->get_view()); - this->content = btn; + //Create a main content. + Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 3", + //Prev Button + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->pop_view(); + }, + //Next Button + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + app_controller4 *controller = new app_controller4(ad); + ad->viewmgr->push_view(new ui_basic_view(controller)); + }, this->ad); + + //Arguments: content, title, subtitle, icon, title left button, title right button + view->set_content(content, "Title", "Subtitle", NULL, NULL, NULL); } void unload() { - LOGE("controller3"); - evas_object_del(this->content); + //You could destroy the content here for save memory. ui_view *view = this->get_view(); - view->set_content(NULL); - } - - void active() - { - LOGE("controller3"); - } - - void inactive() - { - LOGE("controller3"); - } - - void destroy() - { - LOGE("controller3"); + Evas_Object *content = view->set_content(NULL); + evas_object_del(content); } }; + class app_controller2: public ui_controller { private: appdata_s *ad; - Evas_Object *content; - - static void next_clicked_cb(void *data, Evas_Object *obj, void *event_info) - { - appdata_s *ad = static_cast(data); - //View 2 - app_controller2 *controller = new app_controller2(ad); - ad->viewmgr->push_view(new ui_basic_view(controller)); - } - static void prev_clicked_cb(void *data, Evas_Object *obj, void *event_info) - { - appdata_s *ad = static_cast(data); - ad->viewmgr->deactivate(); - } public: - app_controller2(appdata_s *ad) : - ad(ad), content(NULL) + app_controller2(appdata_s *ad) + : ad(ad) { } - ~app_controller2() { } void load() { + //Initialize contents. + ui_basic_view *view = dynamic_cast(ui_controller::get_view()); - Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 2", prev_clicked_cb, next_clicked_cb, this->ad); + //Create a main content. + Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 2", + //Prev Button + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->pop_view(); + }, + //Next Button + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + app_controller3 *controller = new app_controller3(ad); + ad->viewmgr->push_view(new ui_basic_view(controller)); + }, this->ad); + + //Title left button Evas_Object *left_title_btn = elm_button_add(view->get_base()); elm_object_text_set(left_title_btn, "Cancel"); + //Title right button Evas_Object *right_title_btn = elm_button_add(view->get_base()); elm_object_text_set(right_title_btn, "Done"); - view->set_content(content, "Title Buttons", NULL, left_title_btn, right_title_btn); - this->content = content; + //Arguments: content, title, subtitle, icon, title left button, title right button + view->set_content(content, "Title Buttons", NULL, NULL, left_title_btn, right_title_btn); } void unload() { - evas_object_del(this->content); + //You could destroy the content here for save memory. ui_view *view = this->get_view(); - view->set_content(NULL); + Evas_Object *content = view->set_content(NULL); + evas_object_del(content); } }; @@ -230,40 +208,46 @@ class app_controller1: public ui_controller private: appdata_s *ad; - static void next_clicked_cb(void *data, Evas_Object *obj, void *event_info) - { - appdata_s *ad = static_cast(data); - //View 2 - app_controller2 *controller = new app_controller2(ad); - ad->viewmgr->push_view(new ui_basic_view(controller)); - } - static void prev_clicked_cb(void *data, Evas_Object *obj, void *event_info) - { - appdata_s *ad = static_cast(data); - ad->viewmgr->deactivate(); - } - public: - app_controller1(appdata_s *ad) : - ad(ad) + app_controller1(appdata_s *ad) + : ad(ad) { } - ~app_controller1() { } void load() { + //Initialize contents. + ui_basic_view *view = dynamic_cast(ui_controller::get_view()); - Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 1", prev_clicked_cb, next_clicked_cb, this->ad); + + //Create a main content. + Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 1", + //Prev Button + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + ad->viewmgr->deactivate(); + }, + //Next Button + [](void *data, Evas_Object *obj, void *event_info) -> void + { + appdata_s *ad = static_cast(data); + app_controller2 *controller = new app_controller2(ad); + ui_basic_view *view = new ui_basic_view(controller, "page2"); + ad->viewmgr->push_view(view); + }, this->ad); + view->set_content(content, "Title"); } void unload() { - ui_view *view = ui_controller::get_view(); - Evas_Object *btn = view->set_content(NULL); - evas_object_del(btn); + //You could destroy the content here for save memory. + ui_view *view = this->get_view(); + Evas_Object *content = view->set_content(NULL); + evas_object_del(content); } }; diff --git a/src/main.cpp b/src/main.cpp index fc398f5..b8a8653 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,15 +25,14 @@ static void create_base_gui(appdata_s *ad) //View 1 { app_controller1 *controller = new app_controller1(ad); - ad->viewmgr->push_view(new ui_basic_view(controller)); + ad->viewmgr->push_view(new ui_basic_view(controller, "page1")); } /* //View 2 { app_controller2 *controller = new app_controller2(ad); - ad->viewmgr->push_view(new ui_basic_view(controller)); + ad->viewmgr->push_view(new ui_basic_view(controller, "page2")); } - //View 3 { app_controller3 *controller = new app_controller3(ad); @@ -91,6 +90,7 @@ static void ui_app_lang_changed(app_event_info_h event_info, void *user_data) system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale); elm_language_set(locale); free(locale); + return; } diff --git a/src/ui_basic_view.cpp b/src/ui_basic_view.cpp index dbe09c5..f1dbb36 100644 --- a/src/ui_basic_view.cpp +++ b/src/ui_basic_view.cpp @@ -47,8 +47,8 @@ bool ui_basic_view::create_layout() return true; } -ui_basic_view::ui_basic_view(ui_controller *controller) : - ui_view(controller), layout(NULL) +ui_basic_view::ui_basic_view(ui_controller *controller, const char *name) + : ui_view(controller, name), layout(NULL) { } @@ -63,14 +63,14 @@ void ui_basic_view::load() ui_view::load(); } -void ui_basic_view ::unload() +void ui_basic_view::unload() { this->destroy_layout(); ui_view::unload(); } Evas_Object * -ui_basic_view::set_content(Evas_Object *content) +ui_basic_view::set_content(Evas_Object *content, const char *title) { Evas_Object *pcontent = ui_view::set_content(content); @@ -78,6 +78,7 @@ ui_basic_view::set_content(Evas_Object *content) { elm_object_part_content_unset(this->layout, "elm.swallow.content"); elm_object_part_content_set(this->layout, "elm.swallow.content", content); + elm_object_part_text_set(this->layout, "elm.text.title", title); } else { @@ -87,32 +88,111 @@ ui_basic_view::set_content(Evas_Object *content) return pcontent; } - -Evas_Object * -ui_basic_view::set_content(Evas_Object *content, const char *title, const char *subtitle, Evas_Object *title_left_btn, Evas_Object *title_right_btn) +bool ui_basic_view::set_subtitle(const char *text) { + if (this->layout) + { + elm_object_part_text_set(this->layout, "elm.text.subtitle", text); + if (text) elm_object_signal_emit(this->layout, "elm,state,subtitle,show", "elm"); + else elm_object_signal_emit(this->layout, "elm,state,subtitle,hide", "elm"); + return true; + } + LOGE("Layout is not exist!"); + return false; +} - Evas_Object *pcontent = this->set_content(content); +bool ui_basic_view::set_icon(Evas_Object *icon) +{ + if (this->layout) + { + elm_object_part_content_set(this->layout, "elm.swallow.icon", icon); + if (icon) elm_object_signal_emit(this->layout, "elm,state,icon,show", "elm"); + else elm_object_signal_emit(this->layout, "elm,state,icon,hide", "elm"); + return true; + } + LOGE("Layout is not exist!"); + return false; +} +bool ui_basic_view::set_title_left_btn(Evas_Object *title_left_btn) +{ if (this->layout) { - if (title) elm_object_part_text_set(this->layout, "elm.text.title", title); - if (subtitle) elm_object_part_text_set(this->layout, "elm.text.subtitle", subtitle); if (title_left_btn) { elm_object_style_set(title_left_btn, "naviframe/title_left"); - //FIXME: + //FIXME: naviframe/title_left -> tizen_view/title_left //elm_object_style_set(title_left_btn, "tizen_view/title_left"); - elm_object_part_content_set(this->layout, "title_left_btn", title_left_btn); } + elm_object_part_content_set(this->layout, "title_left_btn", title_left_btn); + if (title_left_btn) elm_object_signal_emit(this->layout, "elm,state,title_left_btn,show", "elm"); + else elm_object_signal_emit(this->layout, "elm,state,title_left_btn,hide", "elm"); + return true; + } + LOGE("Layout is not exist!"); + return false; +} + +bool +ui_basic_view::set_title_right_btn(Evas_Object *title_right_btn) +{ + if (this->layout) + { if (title_right_btn) { - LOGE("AHHHHHHHHHHHHH"); elm_object_style_set(title_right_btn, "naviframe/title_right"); - //FIXME: + //FIXME: naviframe/title_right -> tizen_view/title_right //elm_object_style_set(title_left_btn, "tizen_view/title_right"); - elm_object_part_content_set(this->layout, "title_right_btn", title_right_btn); } + elm_object_part_content_set(this->layout, "title_right_btn", title_right_btn); + if (title_right_btn) elm_object_signal_emit(this->layout, "elm,state,title_right_btn,show", "elm"); + else elm_object_signal_emit(this->layout, "elm,state,title_right_btn,hide", "elm"); + return true; + } + LOGE("Layout is not exist!"); + return false; +} + +bool ui_basic_view::set_title_badge(const char *text) +{ + if (this->layout) + { + elm_object_part_text_set(this->layout, "title_badge", text); + if (text) elm_object_signal_emit(this->layout, "elm,state,title_badge,show", "elm"); + else elm_object_signal_emit(this->layout, "elm,state,title_badge,hide", "elm"); + return true; + } + LOGE("Layout is not exist!"); + return false; +} + +bool +ui_basic_view::set_title(const char *text) +{ + if (this->layout) + { + elm_object_part_text_set(this->layout, "elm.text.title", text); + if (text) elm_object_signal_emit(this->layout, "elm,state,title,show", "elm"); + else elm_object_signal_emit(this->layout, "elm,state,title,hide", "elm"); + return true; + } + LOGE("Layout is not exist!"); + return false; +} + +Evas_Object * +ui_basic_view::set_content(Evas_Object *content, const char *title, const char *subtitle, Evas_Object *icon, Evas_Object *title_left_btn, + Evas_Object *title_right_btn) +{ + Evas_Object *pcontent = this->set_content(content); + + if (this->layout) + { + this->set_title(title); + this->set_subtitle(subtitle); + this->set_icon(icon); + this->set_title_left_btn(title_left_btn); + this->set_title_right_btn(title_right_btn); } else { @@ -122,4 +202,3 @@ ui_basic_view::set_content(Evas_Object *content, const char *title, const char * return pcontent; } - diff --git a/src/ui_basic_view.h b/src/ui_basic_view.h index 4f096fd..d942190 100644 --- a/src/ui_basic_view.h +++ b/src/ui_basic_view.h @@ -18,7 +18,7 @@ protected: void unload(); public: - ui_basic_view(ui_controller *controller); + ui_basic_view(ui_controller *controller, const char *name = NULL); virtual ~ui_basic_view(); Evas_Object *get_base() @@ -26,8 +26,14 @@ public: return this->layout; } - Evas_Object *set_content(Evas_Object *content); - Evas_Object *set_content(Evas_Object *content, const char *title, const char *subtitle = NULL, Evas_Object *title_left_btn = NULL, Evas_Object *title_right_btn = NULL); + Evas_Object *set_content(Evas_Object *content, const char *title = NULL); + Evas_Object *set_content(Evas_Object *content, const char *title, const char *subtitle, Evas_Object *icon, Evas_Object *title_left_btn, Evas_Object *title_right_btn); + bool set_title_badge(const char *text); + bool set_subtitle(const char *text); + bool set_icon(Evas_Object *icon); + bool set_title_left_btn(Evas_Object *title_left_btn); + bool set_title_right_btn(Evas_Object *title_right_btn); + bool set_title(const char *text); }; } diff --git a/src/ui_controller.cpp b/src/ui_controller.cpp index 035e38f..e312012 100644 --- a/src/ui_controller.cpp +++ b/src/ui_controller.cpp @@ -8,11 +8,6 @@ ui_view * ui_controller::get_view() { ui_view_base *view = ui_controller_base::get_view(); - if (!view) - { - LOGI("view ahhhhh =%p", view); - return NULL; - } - LOGI("view =%p", view); + if (!view) return NULL; return dynamic_cast(view); } diff --git a/src/ui_controller_base.cpp b/src/ui_controller_base.cpp index 900510e..53d1cb9 100644 --- a/src/ui_controller_base.cpp +++ b/src/ui_controller_base.cpp @@ -8,6 +8,5 @@ void ui_controller_base::set_view(ui_view_base *view) { //TODO: ? } - LOGI("view =%p", view); this->view = view; } diff --git a/src/ui_view.cpp b/src/ui_view.cpp index 113f45d..36d7bf3 100644 --- a/src/ui_view.cpp +++ b/src/ui_view.cpp @@ -4,8 +4,8 @@ using namespace efl; -ui_view::ui_view(ui_controller *controller) : - ui_view_base(controller) +ui_view::ui_view(ui_controller *controller, const char *name) : + ui_view_base(controller, name) { } diff --git a/src/ui_view.h b/src/ui_view.h index 879f810..edf4d59 100644 --- a/src/ui_view.h +++ b/src/ui_view.h @@ -14,27 +14,16 @@ class ui_controller; class ui_view: public ui_view_base { public: - ui_view(ui_controller *controller); + ui_view(ui_controller *controller, const char *name = NULL); virtual ~ui_view(); virtual Evas_Object *set_content(Evas_Object *content); - //virtual Evas_Object *set_content(Evas_Object *content, const char *title); virtual Evas_Object *get_base(); protected: virtual void load(); - - /* protected: - - virtual void set_event_block(bool block) - { - //TO DO: Implement below to proper way. - //if (block) - // evas_object_freeze_events_set(elm_object_part_content_get(this->content, "swallow.view.this"), EINA_FALSE); - //else - // evas_object_freeze_events_set(ui_view_content_get(view_mgr->anim.view_this), EINA_TRUE); - } */ }; + } #endif /* UI_VIEW */ diff --git a/src/ui_view_base.cpp b/src/ui_view_base.cpp index ae5fb07..637ffda 100644 --- a/src/ui_view_base.cpp +++ b/src/ui_view_base.cpp @@ -13,92 +13,82 @@ void ui_view_base::set_event_block(bool block) void ui_view_base::load() { this->state = UI_VIEW_STATE_LOAD; - if (this->content) - return; - if (!this->controller) - return; + if (this->content) return; + if (!this->controller) return; this->controller->load(); } void ui_view_base::unload() { this->state = UI_VIEW_STATE_UNLOAD; - if (!this->content) - return; - if (!this->controller) - return; + if (!this->content) return; + if (!this->controller) return; this->controller->unload(); } void ui_view_base::active() { this->state = UI_VIEW_STATE_ACTIVE; - if (!this->controller) - return; + if (!this->controller) return; this->controller->active(); } void ui_view_base::inactive() { this->state = UI_VIEW_STATE_INACTIVE; - if (!this->controller) - return; + if (!this->controller) return; this->controller->inactive(); } void ui_view_base::pause() { this->state = UI_VIEW_STATE_PAUSE; - if (!this->content) - return; - if (state != UI_VIEW_STATE_ACTIVE) - return; - if (!this->controller) - return; + if (!this->content) return; + if (state != UI_VIEW_STATE_ACTIVE) return; + if (!this->controller) return; this->controller->pause(); } void ui_view_base::resume() { this->state = UI_VIEW_STATE_ACTIVE; - if (state != UI_VIEW_STATE_PAUSE) - return; - if (!this->content) - return; - if (!this->controller) - return; + if (state != UI_VIEW_STATE_PAUSE) return; + if (!this->content) return; + if (!this->controller) return; this->controller->resume(); } void ui_view_base::destroy() { - if (!this->controller) - return; + if (!this->controller) return; this->controller->destroy(); } -ui_view_base::ui_view_base(T content, ui_controller_base *controller) : - content(content), controller(controller), name(string()), style(string()), viewmgr(NULL), state(UI_VIEW_STATE_LOAD), event_block( - false) +ui_view_base::ui_view_base(T content, ui_controller_base *controller, const char *name) + : content(content), controller(controller), name(string(name ? name : "")), style(string()), viewmgr(NULL), state(UI_VIEW_STATE_LOAD), event_block( + false) { - if (!content) - this->state = UI_VIEW_STATE_UNLOAD; - else - this->state = UI_VIEW_STATE_LOAD; + if (!content) this->state = UI_VIEW_STATE_UNLOAD; + else this->state = UI_VIEW_STATE_LOAD; controller->set_view(this); } -ui_view_base::ui_view_base(ui_controller_base *controller = NULL) : - ui_view_base(NULL, controller) +ui_view_base::ui_view_base(ui_controller_base *controller, const char *name) + : ui_view_base(NULL, controller, name) { this->state = UI_VIEW_STATE_UNLOAD; } +ui_view_base::ui_view_base(const char *name) + : ui_view_base(NULL, name) +{ + +} + ui_view_base::~ui_view_base() { this->viewmgr->remove_view(this); - if (this->controller) - delete (this->controller); + if (this->controller) delete (this->controller); } ui_controller_base* diff --git a/src/ui_view_base.h b/src/ui_view_base.h index db7cf36..fbcc30b 100644 --- a/src/ui_view_base.h +++ b/src/ui_view_base.h @@ -151,9 +151,11 @@ public: */ //Constructor - ui_view_base(T content, ui_controller_base *controller); + ui_view_base(T content, ui_controller_base *controller, const char *name); ///Constructor for initializing with controller. - ui_view_base(ui_controller_base *controller); + ui_view_base(ui_controller_base *controller, const char *name = NULL); + ///Constructor for initializing with name. + ui_view_base(const char *name = NULL); ///Destructor for terminating view. virtual ~ui_view_base(); diff --git a/src/ui_viewmgr.cpp b/src/ui_viewmgr.cpp index 657186b..5845eb7 100644 --- a/src/ui_viewmgr.cpp +++ b/src/ui_viewmgr.cpp @@ -9,14 +9,16 @@ win_delete_request_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info { ui_viewmgr *viewmgr = static_cast(data); delete(viewmgr); + + //FIXME: Window is destroyed. Terminate Application! + //ui_app_exit(); } Evas_Object * ui_viewmgr::create_conformant(Evas_Object *win) { Evas_Object *conform = elm_conformant_add(win); - if (!conform) - return NULL; + if (!conform) return NULL; evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(win, conform); @@ -30,10 +32,7 @@ Evas_Object * ui_viewmgr::create_base_layout(Evas_Object *conform) { Evas_Object *layout = elm_layout_add(conform); - if (!layout) - { - return NULL; - } + if (!layout) return NULL; elm_layout_theme_set(layout, "layout", "application", "default"); elm_object_content_set(conform, layout); @@ -41,8 +40,8 @@ ui_viewmgr::create_base_layout(Evas_Object *conform) return layout; } -ui_viewmgr::ui_viewmgr(const char *pkg) : - ui_viewmgr_base() +ui_viewmgr::ui_viewmgr(const char *pkg) + : ui_viewmgr_base() { if (!pkg) { @@ -61,11 +60,22 @@ ui_viewmgr::ui_viewmgr(const char *pkg) : //Set window rotation if (elm_win_wm_rotation_supported_get(this->win)) { - int rots[4] = { 0, 90, 180, 270 }; + int rots[4] = + { 0, 90, 180, 270 }; elm_win_wm_rotation_available_rotations_set(this->win, (const int *) (&rots), 4); } - evas_object_smart_callback_add(this->win, "delete,request", win_delete_request_cb, this); + //Window is requested to delete. + evas_object_smart_callback_add(this->win, "delete,request", + [](void *data, Evas_Object *obj, void *event_info) -> void + { + ui_viewmgr *viewmgr = static_cast(data); + delete(viewmgr); + + //FIXME: Window is destroyed. Terminate Application! + //ui_app_exit(); + }, + this); //Conformant: Make this configurable. this->conform = this->create_conformant(this->win); @@ -87,7 +97,6 @@ ui_viewmgr::ui_viewmgr(const char *pkg) : //Set Indicator properties elm_win_indicator_mode_set(this->win, ELM_WIN_INDICATOR_SHOW); elm_win_indicator_opacity_set(this->win, ELM_WIN_INDICATOR_TRANSPARENT); - elm_win_autodel_set(this->win, EINA_TRUE); } @@ -97,6 +106,8 @@ ui_viewmgr::~ui_viewmgr() bool ui_viewmgr::activate() { + ui_viewmgr_base :: activate(); + elm_object_part_content_unset(this->base_layout, "elm.swallow.content"); ui_view *view = dynamic_cast(this->get_last_view()); @@ -106,7 +117,8 @@ bool ui_viewmgr::activate() if (content == this->base_layout) { elm_object_part_content_set(this->base_layout, "elm.swallow.content", CONVERT_TO_EO(view->get_content())); - } else + } + else { elm_object_part_content_set(this->base_layout, "elm.swallow.content", CONVERT_TO_EO(view->get_base())); } @@ -118,8 +130,19 @@ bool ui_viewmgr::activate() bool ui_viewmgr::deactivate() { - //TODO: based on the profile, we could hide window or destroy window. - evas_object_lower(this->win); + ui_viewmgr_base ::deactivate(); + + //FIXME: based on the profile, we should app to go behind or terminate. + if (true) + { + evas_object_lower(this->win); + } + else + { + //FIXME: exit app + //ui_app_exit(); + } + return true; } @@ -137,7 +160,8 @@ bool ui_viewmgr::pop_view() if (content == this->base_layout) { elm_object_part_content_set(this->base_layout, "elm.swallow.content", CONVERT_TO_EO(view->get_content())); - } else + } + else { elm_object_part_content_set(this->base_layout, "elm.swallow.content", CONVERT_TO_EO(view->get_base())); } @@ -150,7 +174,8 @@ ui_viewmgr::push_view(ui_view *view) { ui_viewmgr_base::push_view(view); - if (this->get_view_count() == 1) return view; + //Don't prepare yet if viewmgr is not activated. + if (!this->is_activated()) return view; elm_object_part_content_unset(this->base_layout, "elm.swallow.content"); @@ -159,7 +184,8 @@ ui_viewmgr::push_view(ui_view *view) if (content == this->base_layout) { elm_object_part_content_set(this->base_layout, "elm.swallow.content", CONVERT_TO_EO(view->get_content())); - } else + } + else { LOGE("view->base = %p", view->get_base()); elm_object_part_content_set(this->base_layout, "elm.swallow.content", CONVERT_TO_EO(view->get_base())); diff --git a/src/ui_viewmgr.h b/src/ui_viewmgr.h index b3c6df6..409c550 100644 --- a/src/ui_viewmgr.h +++ b/src/ui_viewmgr.h @@ -23,192 +23,6 @@ private: Evas_Object * create_conformant(Evas_Object *win); Evas_Object * create_base_layout(Evas_Object *conform); - /* - static void - _appear_finished_cb(void *data, Evas_Object *obj, const char *emision, const char *source) - { - LOGI("CALLED"); - ui_viewmgr *viewmgr = (ui_viewmgr *)data; - - viewmgr->_push_view_finished(viewmgr->anim.view_this); - - //TODO: Appear finish callback call? - - elm_object_part_content_set(viewmgr->base_layout, "swallow.back", obj); - - //TODO: Thaw event? - - viewmgr->anim.view_this = NULL; - viewmgr->anim.view_other = NULL; - viewmgr->animation_ongoing = false; - viewmgr->to_show = false; - } - - static void - _appear_effect(ui_viewmgr *viewmgr) - { - LOGI("CALLED"); - Evas_Object *layout; - - //TODO: send a style intead of NULL value below. - layout = _create_layout(viewmgr->base_layout, NULL); - elm_object_part_content_set(viewmgr->base_layout, "swallow.front", layout); - evas_object_show(layout); - - if (!viewmgr->anim.view_this->get_content()) - { - //TODO: Content load here? - } - - if (viewmgr->anim.view_this->get_content()) - { - //TODO: Freeze event? - elm_object_part_content_set(layout,"swallow.view.this", - viewmgr->anim.view_this->get_content()); - //View appear start. - } - - if (viewmgr->anim.view_other) - { - if (viewmgr->anim.view_other->get_content()) - { - //TODO: Freeze event? - elm_object_part_content_set(layout,"swallow.view.other", - viewmgr->anim.view_other->get_content()); - //View disappear start. - } - } - //ui_view_base *appear_view = viewmgr->view_list.back(); - - // delete old layout if any - _delete_layout(elm_object_part_content_get(viewmgr->base_layout, "swallow.back")); - - // start the animation - elm_object_signal_emit(layout, "appear,effect", "elm"); - elm_object_signal_callback_add(layout, "appear,effect,finished", "*", _appear_finished_cb, viewmgr); - } - - static void - _disappear_finished_cb(void *data, Evas_Object *obj, const char *emision, const char *source) - { - LOGI("CALLED"); - ui_viewmgr *viewmgr = (ui_viewmgr *)data; - - ui_view_base *appear_view = viewmgr->view_list.back(); - //appear_view->active(); - - //viewmgr->_pop_view_finished(appear_view); - - elm_object_part_content_set(viewmgr->base_layout, "swallow.back", obj); - //evas_object_freeze_events_set(elm_object_part_content_get(obj, "swallow.view.this"), EINA_FALSE); - //evas_object_freeze_events_set(elm_object_part_content_get(obj, "swallow.view.other"), EINA_FALSE); - - //destroy the view - // remove it from the view stack - //viewmgr->view_list.pop_back(); - elm_object_part_content_unset(obj,"swallow.view.this"); - viewmgr-> _pop_view_finished(viewmgr->anim.view_this); - //delete(viewmgr->anim.view_this); - //Do it in unload method? - evas_object_del(viewmgr->anim.view_this->get_content()); - - viewmgr->anim.view_this = NULL; - viewmgr->anim.view_other = NULL; - viewmgr->animation_ongoing = false; - } - - static void - _disappear_effect(ui_viewmgr* viewmgr) - { - LOGI("CALLED"); - Evas_Object *layout; - - //TODO: send a style intead of NULL value below. - layout = _create_layout(viewmgr->base_layout, NULL); - elm_object_part_content_set(viewmgr->base_layout, "swallow.front", layout); - evas_object_show(layout); - - //TODO: check the content is? - //TODO: event freeze? - - elm_object_part_content_set(layout,"swallow.view.this", - viewmgr->anim.view_this->get_content()); - elm_object_part_content_set(layout,"swallow.view.other", - viewmgr->anim.view_other->get_content()); - - //TODO: check is it right? - //ui_view_base *appear_view = viewmgr->view_list.back(); - - //view appear start - //elm_object_part_content_set(layout,"swallow.view.this", appear_view->get_content()); - - //evas_object_freeze_events_set(ui_view_content_get(view_mgr->anim.view_this), EINA_TRUE); - //evas_object_freeze_events_set(ui_view_content_get(view_mgr->anim.view_other), EINA_TRUE); - - // delete old layout if any - _delete_layout(elm_object_part_content_get(viewmgr->base_layout, "swallow.back")); - - elm_object_signal_emit(layout, "disappear,effect", "elm"); - elm_object_signal_callback_add(layout, "disappear,effect,finished", "*", _disappear_finished_cb, viewmgr); - } - - static void _animation_cb(void *data) - { - ui_viewmgr *viewmgr = (ui_viewmgr *)data; - viewmgr->animation_job = NULL; - - if (viewmgr->animation_ongoing) { - viewmgr->animation_job = ecore_job_add(_animation_cb, viewmgr); - return; - } else { - viewmgr->animation_ongoing = true; - } - - viewmgr->anim.view_this = viewmgr->view_list.back(); - - //TODO: fix below hard coding :( - - //if (viewmgr->anim.view_this->get_state() == 3) - if (viewmgr->to_show) - { - std::list*>::iterator li; - - for (li = viewmgr->view_list.begin(); li!= viewmgr->view_list.end(); li++) - { - ui_view *view = (ui_view *)*li; - if (view->get_state() == 2) - { - printf("Find active view %p\n", view); - viewmgr->anim.view_other = view; - break; - } - } - - _appear_effect(viewmgr); - } - else - { - std::list*>::reverse_iterator li; - - int i = 0; - for (li = viewmgr->view_list.rbegin(); li!= viewmgr->view_list.rend(); li++) - { - i++; - ui_view *view = (ui_view *)*li; - //if (view->get_state() == 2) - if (i == 2) - { - printf("Find view %p\n", view); - viewmgr->anim.view_other = view; - break; - } - } - - if (viewmgr->anim.view_other) - _disappear_effect(viewmgr); - } - } - */ public: ui_viewmgr(const char *pkg); ~ui_viewmgr(); diff --git a/src/ui_viewmgr_base.cpp b/src/ui_viewmgr_base.cpp index 0e8a27a..d7f100b 100644 --- a/src/ui_viewmgr_base.cpp +++ b/src/ui_viewmgr_base.cpp @@ -5,7 +5,6 @@ bool ui_viewmgr_base::_connect_view(ui_view_base *view) { - LOGE("Conneted view with viewmgr"); if (view->viewmgr) { LOGE("view(%p) has already connected to viewmgr(%p)", view, this); @@ -18,8 +17,7 @@ bool ui_viewmgr_base::_connect_view(ui_view_base *view) bool ui_viewmgr_base::_disconnect_view(ui_view_base *view) { - if (!view->viewmgr) - return false; + if (!view->viewmgr) return false; view->viewmgr = NULL; return true; } @@ -27,8 +25,7 @@ bool ui_viewmgr_base::_disconnect_view(ui_view_base *view) void ui_viewmgr_base::_set_event_block(ui_view_base *view, bool block) { - if (!this->event_block) - return; + if (!this->event_block) return; view->set_event_block(block); } @@ -70,8 +67,8 @@ bool ui_viewmgr_base::_pop_view_finished(ui_view_base *view) return true; } -ui_viewmgr_base::ui_viewmgr_base() : - event_block(true) +ui_viewmgr_base::ui_viewmgr_base() + : event_block(true), activated(false) { //TODO: Initialize ? } @@ -162,7 +159,6 @@ bool ui_viewmgr_base::pop_view() //previous page to be current active. auto nx = std::prev(this->view_list.end(), 2); ui_view_base *pview = *nx; - LOGE("pview = %p", pview); pview->load(); pview->inactive(); this->_set_event_block(pview, true); @@ -217,8 +213,7 @@ int ui_viewmgr_base::get_view_index(const ui_view_base *view) for (typename std::list::iterator it = this->view_list.begin(); it != this->view_list.end(); it++) { - if (view == *it) - return idx; + if (view == *it) return idx; ++idx; } @@ -229,6 +224,19 @@ ui_view_base * ui_viewmgr_base::get_last_view() { int cnt = this->get_view_count(); - LOGE("cnt = %d", cnt); return this->get_view(cnt - 1); } + +bool ui_viewmgr_base::activate() +{ + if (this->activated) return false; + this->activated = true; + return true; +} + +bool ui_viewmgr_base::deactivate() +{ + if (!this->activated) return false; + this->activated = false; + return true; +} diff --git a/src/ui_viewmgr_base.h b/src/ui_viewmgr_base.h index 9156384..eefb05e 100644 --- a/src/ui_viewmgr_base.h +++ b/src/ui_viewmgr_base.h @@ -37,6 +37,7 @@ private: //TODO: change name to view_stack std::list view_list; //view list. bool event_block; //event block on view transition. This value should be configurable by system. + bool activated; //activated status of this viewmgr. /** * @brief link a given view to this viewmgr. @@ -99,11 +100,11 @@ public: ///Destructor. Delete all contained views. virtual ~ui_viewmgr_base(); - //Activate a viewmgr. Implement this body to activate a viewmgr. - virtual bool activate() = 0; + //Activate a viewmgr. + virtual bool activate(); - //Deactivate a viewmgr. Implement this body to deactivate a viewmgr. - virtual bool deactivate() = 0; + //Deactivate a viewmgr. + virtual bool deactivate(); /** * @brief Push a new view into the viewmgr stack. @@ -206,6 +207,17 @@ public: } /** + * @brief Return the active status of viewmgr. + * + * @return active status + * + */ + bool is_activated() + { + return this->activated; + } + + /** * @brief Return a list of views which this viewmgr has. * * @return a pointer of list of views. -- 2.7.4