From: Hermet Park Date: Fri, 29 Apr 2016 12:48:14 +0000 (+0900) Subject: remove template code. X-Git-Tag: submit/tizen/20160617.075742~49 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=178f8a64eeedda1071b807648cb160346f73c254;p=platform%2Fcore%2Fuifw%2Fui-viewmgr.git remove template code. let's simplify interface. This is third step for sorting up public interfaces. Change-Id: Id461b5f395ebfd35f431c70b6002e80abaa14166 --- diff --git a/src/include/efl/ui_base_overlay.h b/src/include/efl/ui_base_overlay.h index 849743d..ee0fb75 100644 --- a/src/include/efl/ui_base_overlay.h +++ b/src/include/efl/ui_base_overlay.h @@ -23,7 +23,7 @@ namespace efl_viewmanager class ui_base_viewmgr; class ui_base_view; -class ui_base_overlay: public ui_iface_overlay +class ui_base_overlay: public ui_iface_overlay { protected: ui_base_overlay(ui_base_view *view); diff --git a/src/include/efl/ui_base_view.h b/src/include/efl/ui_base_view.h index 58abebd..2f41438 100644 --- a/src/include/efl/ui_base_view.h +++ b/src/include/efl/ui_base_view.h @@ -32,7 +32,7 @@ namespace efl_viewmanager * @warning When the transitions are finished, the view must to call ui_iface_viewmgr :: _push_finished(), ui_iface_viewmgr :: _pop_finished() in order that * The ui_iface_viewmgr keeps the view states exactly. */ -class ui_base_view: public ui_iface_view +class ui_base_view: public ui_iface_view { friend class ui_base_viewmgr; diff --git a/src/include/efl/ui_base_viewmanager.h b/src/include/efl/ui_base_viewmanager.h index 0576ab5..f03c711 100644 --- a/src/include/efl/ui_base_viewmanager.h +++ b/src/include/efl/ui_base_viewmanager.h @@ -17,14 +17,13 @@ #ifndef _UI_BASE_VIEWMANAGER_H_ #define _UI_BASE_VIEWMANAGER_H_ -#include #include "../interface/ui_iface_viewmanager.h" #include "ui_base_overlay.h" #include "ui_base_key_listener.h" #include "ui_base_viewmgr.h" #include "ui_base_view.h" -#define UI_BASE_VIEWMGR dynamic_cast(ui_iface_viewmgr::get_instance()) +#define UI_BASE_VIEWMGR dynamic_cast(ui_iface_viewmgr::get_instance()) using namespace efl_viewmanager; diff --git a/src/include/efl/ui_base_viewmgr.h b/src/include/efl/ui_base_viewmgr.h index e505209..64b20f0 100644 --- a/src/include/efl/ui_base_viewmgr.h +++ b/src/include/efl/ui_base_viewmgr.h @@ -40,7 +40,7 @@ class ui_base_view; * * @warning viewmgr will remove all containing views when it's destroyed. */ -class ui_base_viewmgr: public ui_iface_viewmgr +class ui_base_viewmgr: public ui_iface_viewmgr { friend class ui_base_view; @@ -51,7 +51,7 @@ private: Elm_Layout *layout; //Viewmgr's base layout. ui_base_key_listener *key_listener; //HW Key Handler such as "BACK" key... ui_view_indicator indicator; //Mode of indicator. - string transition_style; //Current transiton effect style name + string transition_style; //Current transition effect style name map effect_map; //Map for effect layouts. Elm_Layout *set_transition_layout(string transition_style); diff --git a/src/include/interface/ui_iface_overlay.h b/src/include/interface/ui_iface_overlay.h index 960ac22..fcbaa43 100644 --- a/src/include/interface/ui_iface_overlay.h +++ b/src/include/interface/ui_iface_overlay.h @@ -20,24 +20,22 @@ namespace ui_viewmanager { -template class ui_iface_view; -template class ui_iface_overlay: public ui_iface_rotatable { private: - ui_iface_view *view; + ui_iface_view *view; T content; protected: - ui_iface_overlay(ui_iface_view *view); + ui_iface_overlay(ui_iface_view *view); virtual ~ui_iface_overlay(); public: virtual bool set_content(T content); virtual T unset_content(); - ui_iface_view *get_view(); + ui_iface_view *get_view(); virtual T get_content(); virtual void on_back(); virtual bool activate() = 0; @@ -45,51 +43,6 @@ public: virtual bool is_activated() = 0; }; - -template -ui_iface_overlay::ui_iface_overlay(ui_iface_view *view) - : view(view), content(NULL) -{ -} - -template -ui_iface_overlay::~ui_iface_overlay() -{ -} - -template -bool ui_iface_overlay::set_content(T content) -{ - this->content = content; - return true; -} - -template -T ui_iface_overlay::unset_content() -{ - T prev = this->content; - this->content = NULL; - return prev; -} - -template -T ui_iface_overlay::get_content() -{ - return this->content; -} - -template -ui_iface_view *ui_iface_overlay::get_view() -{ - return this->view; -} - -template -void ui_iface_overlay::on_back() -{ - this->deactivate(); -} - } #endif /* _UI_IFACE_OVERLAY_H_ */ diff --git a/src/include/interface/ui_iface_singleton.h b/src/include/interface/ui_iface_singleton.h index fe944ef..d351ad2 100644 --- a/src/include/interface/ui_iface_singleton.h +++ b/src/include/interface/ui_iface_singleton.h @@ -4,38 +4,38 @@ namespace ui_viewmanager { -template +template class singleton { private: - static T* inst; + static XX* inst; public: singleton(); virtual ~singleton(); - inline static T* get_instance(); + inline static XX* get_instance(); }; -template T* singleton::inst = NULL; +template XX* singleton::inst = NULL; -template -singleton::singleton() +template +singleton::singleton() { - T* pT = reinterpret_cast(1); + XX* pT = reinterpret_cast(1); //Derived Class - Singleton class - int offset = reinterpret_cast(pT) - reinterpret_cast(reinterpret_cast*>(pT)); - singleton::inst = reinterpret_cast((reinterpret_cast(this) + offset)); + int offset = reinterpret_cast(pT) - reinterpret_cast(reinterpret_cast*>(pT)); + singleton::inst = reinterpret_cast((reinterpret_cast(this) + offset)); } -template -singleton::~singleton() +template +singleton::~singleton() { singleton::inst = NULL; } -template -T* singleton::get_instance() +template +XX* singleton::get_instance() { return singleton::inst; } diff --git a/src/include/interface/ui_iface_view.h b/src/include/interface/ui_iface_view.h index 754e549..2e7774e 100644 --- a/src/include/interface/ui_iface_view.h +++ b/src/include/interface/ui_iface_view.h @@ -23,7 +23,6 @@ using namespace std; namespace ui_viewmanager { -template class ui_iface_viewmgr; /** @@ -39,16 +38,15 @@ class ui_iface_viewmgr; * @warning When the transitions are finished, the view must to call ui_iface_viewmgr :: _push_finished(), ui_iface_viewmgr :: _pop_finished() in order that * The ui_iface_viewmgr keeps the view states exactly. */ -template class ui_iface_view : public ui_iface_rotatable { - friend class ui_iface_viewmgr; + friend class ui_iface_viewmgr; private: T content; ///< A content instance for a screen as a view. string name; ///< View name. string transition_style; ///< View transition style name. - ui_iface_viewmgr *viewmgr; ///< Viewmgr which this view belongs to. + ui_iface_viewmgr *viewmgr ; ///< Viewmgr which this view belongs to. ui_view_state state; ///< View state. ui_view_indicator indicator; ///< View indicator mode. bool event_block; ///< State of event block. @@ -123,7 +121,7 @@ protected: /** @brief Return a viewmgr which this view is belonging to. */ //FIXME: Is it necessary? - ui_iface_viewmgr *get_viewmgr(); + ui_iface_viewmgr *get_viewmgr(); /** @brief This is for replacing or setting a content of the view. * @@ -232,176 +230,6 @@ public: void on_back(); }; - -template -bool ui_iface_view::get_event_block() -{ - return this->event_block; -} - -template -ui_iface_viewmgr *ui_iface_view::get_viewmgr() -{ - return this->viewmgr; -} - -template -void ui_iface_view::set_event_block(bool block) -{ - this->event_block = block; -} - -template -void ui_iface_view::on_load() -{ - this->state = UI_VIEW_STATE_LOAD; -} - -template -void ui_iface_view::on_unload() -{ - this->state = UI_VIEW_STATE_UNLOAD; - if (this->get_removable_content()) - { - this->set_content(NULL); - return; - } -} - -template -void ui_iface_view::on_activate() -{ - this->state = UI_VIEW_STATE_ACTIVATE; -} - -template -void ui_iface_view::on_deactivate() -{ - this->state = UI_VIEW_STATE_DEACTIVATE; -} - -template -void ui_iface_view::on_pause() -{ - this->state = UI_VIEW_STATE_PAUSE; -} - -template -void ui_iface_view::on_resume() -{ - this->state = UI_VIEW_STATE_ACTIVATE; -} - -template -void ui_iface_view::on_destroy() -{ -} - -template -ui_iface_view::ui_iface_view(const char *name) - : content(NULL), name(string(name ? name : "")), transition_style(string("default")), viewmgr(NULL), state(UI_VIEW_STATE_LOAD), - indicator(UI_VIEW_INDICATOR_DEFAULT), event_block(false), removable_content(true) -{ - this->state = UI_VIEW_STATE_UNLOAD; -} - -template -ui_iface_view::~ui_iface_view() -{ - this->viewmgr->remove_view(this); -} - -template -bool ui_iface_view::set_content(T content) -{ - this->content = content; - return true; -} - -template -T ui_iface_view::unset_content() -{ - T prev = this->content; - this->content = NULL; - return prev; -} - -template -bool ui_iface_view::set_transition_style(const char *style) -{ - this->transition_style.assign(style); - return true; -} - -template -bool ui_iface_view::set_name(const char *name) -{ - this->name.assign(name); - return true; -} - -template -void ui_iface_view::set_removable_content(bool removable) -{ - this->removable_content = removable; - - //FIXME: If this api is called on unload state? should we remove content right now? -} - -template -void ui_iface_view::set_indicator(ui_view_indicator indicator) -{ - this->indicator = indicator; -} - -template -const char *ui_iface_view::get_transition_style() -{ - return this->transition_style.c_str(); -} - -template -const char *ui_iface_view::get_name() -{ - return this->name.c_str(); -} - -template -T ui_iface_view::get_content() -{ - return this->content; -} - -template -ui_view_state ui_iface_view::get_state() -{ - return this->state; -} - -template -bool ui_iface_view::get_removable_content() -{ - return this->removable_content; -} - -template -ui_view_indicator ui_iface_view::get_indicator() -{ - return this->indicator; -} - -template -void ui_iface_view::on_back() -{ - ui_iface_viewmgr *viewmgr = this->get_viewmgr(); - if (!viewmgr) - { - LOGE("Failed to get a viewmgr, view =%p", this); - return; - } - viewmgr->pop_view(); -} - } #endif /* _UI_IFACE_VIEW_H_ */ diff --git a/src/include/interface/ui_iface_viewmanager.h b/src/include/interface/ui_iface_viewmanager.h index 35bcd7d..388ee3a 100644 --- a/src/include/interface/ui_iface_viewmanager.h +++ b/src/include/interface/ui_iface_viewmanager.h @@ -20,6 +20,14 @@ #include #include +#define UI_EFL 1 + +#if UI_EFL + #include + typedef Evas_Object* T; +#else if UI_DALI +#endif + #ifdef LOG_TAG #undef LOG_TAG #endif @@ -53,4 +61,13 @@ enum ui_view_state using namespace ui_viewmanager; +#define _UI_DECLARE_PRIVATE_IMPL(A) \ + class A_##impl *impl; \ + friend class A_##impl + +#define _UI_DISABLE_COPY_AND_ASSIGN(A) \ + A_##impl(const A_##impl&) = delete; \ + const A_##impl& operator=(const A_##impl&) = delete + + #endif /* UI_IFACE_VIEWMANAGER_H */ diff --git a/src/include/interface/ui_iface_viewmgr.h b/src/include/interface/ui_iface_viewmgr.h index 30d23c1..6907244 100644 --- a/src/include/interface/ui_iface_viewmgr.h +++ b/src/include/interface/ui_iface_viewmgr.h @@ -23,7 +23,6 @@ using namespace std; namespace ui_viewmanager { -template class ui_iface_view; /** @@ -38,16 +37,15 @@ class ui_iface_view; * * @warning viewmgr will remove all containing views when it's destroyed. */ -template class ui_iface_viewmgr { - friend class ui_iface_view; + friend class ui_iface_view; private: - static ui_iface_viewmgr *inst; + static ui_iface_viewmgr *inst; static bool soft_key; //If system doesn't support HW back key, then this value is @c true. static bool event_block; //Event block on view transition. This value should be configurable by system. - list *> view_list; //View list. + list view_list; //View list. bool activated; //Activated status of this viewmgr. /** @@ -60,7 +58,7 @@ private: * @warning If the given view is already connected to a viewmgr, this call will be failed. * @see disconnect_view() */ - bool connect_view(ui_iface_view *view); + bool connect_view(ui_iface_view *view); /** * @brief Disconnect a given view from this viewmgr. @@ -71,7 +69,7 @@ private: * * @see connect_view() */ - bool disconnect_view(ui_iface_view *view); + bool disconnect_view(ui_iface_view *view); /** * @brief Toggle event blocking to the given view. @@ -83,7 +81,7 @@ private: * @param view A view to toggle event blocking. * @param block @c true is blocking event, otherwise @c false. */ - void set_event_block(ui_iface_view *view, bool block); + void set_event_block(ui_iface_view *view, bool block); protected: /** @@ -95,7 +93,7 @@ protected: * * @warning This function must be called when push transition is finished. */ - bool push_view_finished(ui_iface_view *view); + bool push_view_finished(ui_iface_view *view); /** * @brief This function is designed for finishing process for pop transition. @@ -108,7 +106,7 @@ protected: * * @warning This function must be called when push transition is finished. */ - bool pop_view_finished(ui_iface_view *view); + bool pop_view_finished(ui_iface_view *view); /** * @brief Push a new view into this viewmgr. This function is used for when application switches a current view to a new one. @@ -127,7 +125,7 @@ protected: * @see insert_view_after() * @see pop_view() */ - ui_iface_view *push_view(ui_iface_view *view); + ui_iface_view *push_view(ui_iface_view *view); /** * @brief Pop the top(last) view from this viewmgr view list. @@ -152,7 +150,7 @@ protected: * * @return @c true on success or @c false otherwise. */ - bool insert_view_before(ui_iface_view *view, ui_iface_view *before); + bool insert_view_before(ui_iface_view *view, ui_iface_view *before); /** * @brief Insert a view in this viewmgr view list. Specifically, insert a given @p view right after of the given view, @after. @@ -162,7 +160,7 @@ protected: * * @return @c true on success or @c false otherwise. */ - bool insert_view_after(ui_iface_view *view, ui_iface_view *after); + bool insert_view_after(ui_iface_view *view, ui_iface_view *after); /** * @brief Remove the given view from this viewmgr view list. @@ -175,7 +173,7 @@ protected: * @see insert_view_after() * @see push_view() */ - bool remove_view(ui_iface_view *view); + bool remove_view(ui_iface_view *view); /** * @brief Return a view which is matched with the index @p idx. @@ -191,7 +189,7 @@ protected: * @see get_view_index() * @see get_view_count() */ - ui_iface_view* get_view(unsigned int idx); + ui_iface_view* get_view(unsigned int idx); /** * @brief Return a view which is matched with the @p name. @@ -205,14 +203,14 @@ protected: * * @see ui_iface_view::set_name() */ - ui_iface_view *get_view(const char *name); + ui_iface_view *get_view(const char *name); /** * @brief Return a last(top) view. * * @return The view which is last view of the viewmgr view list. */ - ui_iface_view *get_last_view(); + ui_iface_view *get_last_view(); /** * @brief Return a view index(page) number of the given view. @@ -224,7 +222,7 @@ protected: * * @warning The index number of views are variable since the view list is variable. */ - int get_view_index(const ui_iface_view *view); + int get_view_index(const ui_iface_view *view); ///Constructor. ui_iface_viewmgr(); @@ -286,376 +284,9 @@ public: * @return @c true if soft key is required, @c false otherwise. */ static bool need_soft_key(); - static ui_iface_viewmgr* get_instance(); + static ui_iface_viewmgr* get_instance(); }; - -template ui_iface_viewmgr *ui_iface_viewmgr::inst = NULL; - -#define VIEW_ITR typename list *>::iterator -#define VIEW_RITR typename list *>::reverse_iterator - -//FIXME: Read system profile to decide whether support software key or not. -template bool ui_iface_viewmgr::soft_key = true; -//FIXME: Read system profile to decide whether support event block or not. -template bool ui_iface_viewmgr::event_block = true; - - -template -bool ui_iface_viewmgr::insert_view_after(ui_iface_view *view, ui_iface_view *after) -{ - VIEW_ITR it; - - if (!view) - { - LOGE("invalid view argument. view(NULL)"); - return false; - } - - if (!this->connect_view(view)) - { - LOGE("connect view failed"); - return false; - } - - if (this->view_list.size() > 0) - { - for (it = this->view_list.begin(); it != this->view_list.end(); it++) - { - if (after == *it) - { - //If the after is a last item of list. - //view has to push now. - if (it == this->view_list.end()) - this->push_view(view); - else - this->view_list.insert(++it, view); - - return true; - } - } - } - - //If there is no matching after view with current list. - //also in case of after is NULL. - this->push_view(view); - - return true; -} - -template -bool ui_iface_viewmgr::need_soft_key() -{ - return ui_iface_viewmgr::soft_key; -} - -template -bool ui_iface_viewmgr::connect_view(ui_iface_view *view) -{ - //FIXME: If user call a set_viewmgr() before, It should not return false. - /* - if (view->viewmgr) - { - LOGE("view(%p) has already connected to viewmgr(%p)", view, this); - return false; - } - */ - - view->viewmgr = this; - return true; -} - -template -bool ui_iface_viewmgr::disconnect_view(ui_iface_view *view) -{ - if (!view->viewmgr) return false; - view->viewmgr = NULL; - return true; -} - -template -void ui_iface_viewmgr::set_event_block(ui_iface_view *view, bool block) -{ - if (!ui_iface_viewmgr::event_block) return; - view->set_event_block(block); -} - -template -bool ui_iface_viewmgr::push_view_finished(ui_iface_view *view) -{ - ui_iface_view *last = this->view_list.back(); - - //The previous view has been pushed. This should be unload. - if (last != view) - { - view->on_unload(); - return true; - } - - //A new view has been pushed. This should be activate. - view->on_activate(); - this->set_event_block(view, false); - - return true; -} - -template -bool ui_iface_viewmgr::pop_view_finished(ui_iface_view *view) -{ - ui_iface_view *last = this->view_list.back(); - - //This view has been popped. It should be destroyed. - if (last == view) - { - view->on_unload(); - view->on_destroy(); - delete (view); - return true; - } - - //The previous view has been popped. It should become activate. - view->on_activate(); - this->set_event_block(view, false); - - return true; -} - -template -ui_iface_viewmgr::ui_iface_viewmgr(const ui_iface_viewmgr& viewmgr) -{ -} - -template -ui_iface_viewmgr::ui_iface_viewmgr() - : activated(false) -{ - ui_iface_viewmgr::inst = this; -} - -template -ui_iface_viewmgr::~ui_iface_viewmgr() -{ - //Terminate views - for (VIEW_RITR it = this->view_list.rbegin(); it != this->view_list.rend(); it++) - { - ui_iface_view *view = *it; - view->on_deactivate(); - view->on_unload(); - view->on_destroy(); - delete (view); - } - - //FIXME: Window is destroyed. Terminate Application! - ui_app_exit(); - - ui_iface_viewmgr::inst = NULL; -} - -template -ui_iface_view *ui_iface_viewmgr::push_view(ui_iface_view *view) -{ - if (!view) - { - LOGE("invalid view argument. view(NULL)"); - return NULL; - } - - if (!this->connect_view(view)) - { - LOGE("connect view failed"); - return NULL; - } - - ui_iface_view *pview; - - //Previous view - if (this->view_list.size() > 0) - { - pview = this->view_list.back(); - pview->on_deactivate(); - this->set_event_block(pview, true); - } - - this->view_list.push_back(view); - - if (!view->get_content()) - { - view->on_load(); - } - - view->on_deactivate(); - - if (this->view_list.size() != 1) - { - this->set_event_block(view, true); - } - - return view; -} - -template -bool ui_iface_viewmgr::pop_view() -{ - //FIXME: No more view? - if (this->get_view_count() == 0) - { - LOGE("No Views. Can't pop anymore!"); - return false; - } - - //This is the last page. - if (this->get_view_count() == 1) - { - //destroy viewmgr? - ui_iface_view*view = this->view_list.back(); - view->on_deactivate(); - view->on_unload(); - view->on_destroy(); - delete(view); - - return true; - } - - //last page to be popped. - ui_iface_view*view = this->view_list.back(); - view->on_deactivate(); - this->set_event_block(view, true); - - //Below object has to be used in child class... - //Make this getter method? or define instance? - //previous page is to be an active page. - auto nx = prev(this->view_list.end(), 2); - ui_iface_view*pview = *nx; - pview->on_load(); - pview->on_deactivate(); - this->set_event_block(pview, true); - - return true; -} - -template -bool ui_iface_viewmgr::insert_view_before(ui_iface_view *view, ui_iface_view *before) -{ - VIEW_ITR it; - - if (!view) - { - LOGE("invalid view argument. view(NULL)"); - return false; - } - - if (!this->connect_view(view)) - { - LOGE("connect view failed"); - return false; - } - - if (this->view_list.size() > 0) - { - for (it = this->view_list.begin(); it != this->view_list.end(); it++) - { - if (before == *it) - { - this->view_list.insert(it, view); - - return true; - } - } - } - - //If there is no matching before view with current list. - //also in case of before is NULL. - this->push_view(view); - - return true; -} - -template -bool ui_iface_viewmgr::remove_view(ui_iface_view *view) -{ - this->view_list.remove(view); - this->disconnect_view(view); - - //TODO: If this view is the top on the stack ? - return true; -} - -template -ui_iface_view *ui_iface_viewmgr::get_view(unsigned int idx) -{ - if (idx < 0 || idx >= this->view_list.size()) - { - LOGE("Invalid idx(%d)! =? (idx range: %d ~ %d)", idx, 0, this->view_list.size() - 1); - return NULL; - } - VIEW_ITR it = this->view_list.begin(); - advance(it, idx); - return *it; -} - -template -int ui_iface_viewmgr::get_view_index(const ui_iface_view *view) -{ - int idx = 0; - - for (VIEW_ITR it = this->view_list.begin(); it != this->view_list.end(); it++) - { - if (view == *it) return idx; - ++idx; - } - - return -1; -} - -template -ui_iface_view *ui_iface_viewmgr::get_last_view() -{ - int cnt = this->get_view_count(); - return this->get_view(cnt - 1); -} - -template -bool ui_iface_viewmgr::activate() -{ - if (this->activated) return false; - if (this->get_view_count() == 0) return false; - this->activated = true; - return true; -} - -template -bool ui_iface_viewmgr::deactivate() -{ - if (!this->activated) return false; - this->activated = false; - return true; -} - -template -ui_iface_view *ui_iface_viewmgr::get_view(const char *name) -{ - //FIXME: ... - return NULL; -} - -template -bool ui_iface_viewmgr::is_activated() -{ - return this->activated; -} - -template -unsigned int ui_iface_viewmgr::get_view_count() -{ - return this->view_list.size(); -} - -template -ui_iface_viewmgr* ui_iface_viewmgr::get_instance() -{ - return ui_iface_viewmgr::inst; -} - } #endif /* _UI_IFACE_VIEWMGR_H_ */ diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index e52e293..eb85b84 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,4 +1,7 @@ SET(SRCS + interface/ui_iface_overlay.cpp + interface/ui_iface_view.cpp + interface/ui_iface_viewmgr.cpp efl/ui_base_view.cpp efl/ui_base_viewmgr.cpp efl/ui_base_key_listener.cpp diff --git a/src/lib/interface/ui_iface_overlay.cpp b/src/lib/interface/ui_iface_overlay.cpp new file mode 100644 index 0000000..e65aa3c --- /dev/null +++ b/src/lib/interface/ui_iface_overlay.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "../../include/interface/ui_iface_viewmanager.h" + +ui_iface_overlay::ui_iface_overlay(ui_iface_view *view) + : view(view), content(NULL) +{ +} + +ui_iface_overlay::~ui_iface_overlay() +{ +} + +bool ui_iface_overlay::set_content(T content) +{ + this->content = content; + return true; +} + +T ui_iface_overlay::unset_content() +{ + T prev = this->content; + this->content = NULL; + return prev; +} + +T ui_iface_overlay::get_content() +{ + return this->content; +} + +ui_iface_view *ui_iface_overlay::get_view() +{ + return this->view; +} + +void ui_iface_overlay::on_back() +{ + this->deactivate(); +} diff --git a/src/lib/interface/ui_iface_view.cpp b/src/lib/interface/ui_iface_view.cpp new file mode 100644 index 0000000..c06fcca --- /dev/null +++ b/src/lib/interface/ui_iface_view.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "../../include/interface/ui_iface_viewmanager.h" + +bool ui_iface_view::get_event_block() +{ + return this->event_block; +} + +ui_iface_viewmgr *ui_iface_view::get_viewmgr() +{ + return this->viewmgr; +} + +void ui_iface_view::set_event_block(bool block) +{ + this->event_block = block; +} + +void ui_iface_view::on_load() +{ + this->state = UI_VIEW_STATE_LOAD; +} + +void ui_iface_view::on_unload() +{ + this->state = UI_VIEW_STATE_UNLOAD; + if (this->get_removable_content()) + { + this->set_content(NULL); + return; + } +} + +void ui_iface_view::on_activate() +{ + this->state = UI_VIEW_STATE_ACTIVATE; +} + +void ui_iface_view::on_deactivate() +{ + this->state = UI_VIEW_STATE_DEACTIVATE; +} + +void ui_iface_view::on_pause() +{ + this->state = UI_VIEW_STATE_PAUSE; +} + +void ui_iface_view::on_resume() +{ + this->state = UI_VIEW_STATE_ACTIVATE; +} + +void ui_iface_view::on_destroy() +{ +} + +ui_iface_view::ui_iface_view(const char *name) + : content(NULL), name(string(name ? name : "")), transition_style(string("default")), viewmgr(NULL), state(UI_VIEW_STATE_LOAD), + indicator(UI_VIEW_INDICATOR_DEFAULT), event_block(false), removable_content(true) +{ + this->state = UI_VIEW_STATE_UNLOAD; +} + +ui_iface_view::~ui_iface_view() +{ + this->viewmgr->remove_view(this); +} + +bool ui_iface_view::set_content(T content) +{ + this->content = content; + return true; +} + +T ui_iface_view::unset_content() +{ + T prev = this->content; + this->content = NULL; + return prev; +} + +bool ui_iface_view::set_transition_style(const char *style) +{ + this->transition_style.assign(style); + return true; +} + +bool ui_iface_view::set_name(const char *name) +{ + this->name.assign(name); + return true; +} + +void ui_iface_view::set_removable_content(bool removable) +{ + this->removable_content = removable; + + //FIXME: If this api is called on unload state? should we remove content right now? +} + +void ui_iface_view::set_indicator(ui_view_indicator indicator) +{ + this->indicator = indicator; +} + +const char *ui_iface_view::get_transition_style() +{ + return this->transition_style.c_str(); +} + +const char *ui_iface_view::get_name() +{ + return this->name.c_str(); +} + +T ui_iface_view::get_content() +{ + return this->content; +} + +ui_view_state ui_iface_view::get_state() +{ + return this->state; +} + +bool ui_iface_view::get_removable_content() +{ + return this->removable_content; +} + +ui_view_indicator ui_iface_view::get_indicator() +{ + return this->indicator; +} + +void ui_iface_view::on_back() +{ + ui_iface_viewmgr *viewmgr = this->get_viewmgr(); + if (!viewmgr) + { + LOGE("Failed to get a viewmgr, view =%p", this); + return; + } + viewmgr->pop_view(); +} diff --git a/src/lib/interface/ui_iface_viewmgr.cpp b/src/lib/interface/ui_iface_viewmgr.cpp new file mode 100644 index 0000000..fe088d0 --- /dev/null +++ b/src/lib/interface/ui_iface_viewmgr.cpp @@ -0,0 +1,360 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "../../include/interface/ui_iface_viewmanager.h" + +ui_iface_viewmgr *ui_iface_viewmgr::inst = NULL; + +#define VIEW_ITR list::iterator +#define VIEW_RITR list::reverse_iterator + +//FIXME: Read system profile to decide whether support software key or not. +bool ui_iface_viewmgr::soft_key = true; +//FIXME: Read system profile to decide whether support event block or not. +bool ui_iface_viewmgr::event_block = true; + +bool ui_iface_viewmgr::insert_view_after(ui_iface_view *view, ui_iface_view *after) +{ + VIEW_ITR it; + + if (!view) + { + LOGE("invalid view argument. view(NULL)"); + return false; + } + + if (!this->connect_view(view)) + { + LOGE("connect view failed"); + return false; + } + + if (this->view_list.size() > 0) + { + for (it = this->view_list.begin(); it != this->view_list.end(); it++) + { + if (after == *it) + { + //If the after is a last item of list. + //view has to push now. + if (it == this->view_list.end()) + this->push_view(view); + else + this->view_list.insert(++it, view); + + return true; + } + } + } + + //If there is no matching after view with current list. + //also in case of after is NULL. + this->push_view(view); + + return true; +} + +bool ui_iface_viewmgr::need_soft_key() +{ + return ui_iface_viewmgr::soft_key; +} + +bool ui_iface_viewmgr::connect_view(ui_iface_view *view) +{ + //FIXME: If user call a set_viewmgr() before, It should not return false. + /* + if (view->viewmgr) + { + LOGE("view(%p) has already connected to viewmgr(%p)", view, this); + return false; + } + */ + + view->viewmgr = this; + return true; +} + +bool ui_iface_viewmgr::disconnect_view(ui_iface_view *view) +{ + if (!view->viewmgr) return false; + view->viewmgr = NULL; + return true; +} + +void ui_iface_viewmgr::set_event_block(ui_iface_view *view, bool block) +{ + if (!ui_iface_viewmgr::event_block) return; + view->set_event_block(block); +} + +bool ui_iface_viewmgr::push_view_finished(ui_iface_view *view) +{ + ui_iface_view *last = this->view_list.back(); + + //The previous view has been pushed. This should be unload. + if (last != view) + { + view->on_unload(); + return true; + } + + //A new view has been pushed. This should be activate. + view->on_activate(); + this->set_event_block(view, false); + + return true; +} + +bool ui_iface_viewmgr::pop_view_finished(ui_iface_view *view) +{ + ui_iface_view *last = this->view_list.back(); + + //This view has been popped. It should be destroyed. + if (last == view) + { + view->on_unload(); + view->on_destroy(); + delete (view); + return true; + } + + //The previous view has been popped. It should become activate. + view->on_activate(); + this->set_event_block(view, false); + + return true; +} + +ui_iface_viewmgr::ui_iface_viewmgr(const ui_iface_viewmgr& viewmgr) +{ +} + +ui_iface_viewmgr::ui_iface_viewmgr() + : activated(false) +{ + ui_iface_viewmgr::inst = this; +} + +ui_iface_viewmgr::~ui_iface_viewmgr() +{ + //Terminate views + for (VIEW_RITR it = this->view_list.rbegin(); it != this->view_list.rend(); it++) + { + ui_iface_view *view = *it; + view->on_deactivate(); + view->on_unload(); + view->on_destroy(); + delete (view); + } + + //FIXME: Window is destroyed. Terminate Application! + ui_app_exit(); + + ui_iface_viewmgr::inst = NULL; +} + +ui_iface_view *ui_iface_viewmgr::push_view(ui_iface_view *view) +{ + if (!view) + { + LOGE("invalid view argument. view(NULL)"); + return NULL; + } + + if (!this->connect_view(view)) + { + LOGE("connect view failed"); + return NULL; + } + + ui_iface_view *pview; + + //Previous view + if (this->view_list.size() > 0) + { + pview = this->view_list.back(); + pview->on_deactivate(); + this->set_event_block(pview, true); + } + + this->view_list.push_back(view); + + if (!view->get_content()) + { + view->on_load(); + } + + view->on_deactivate(); + + if (this->view_list.size() != 1) + { + this->set_event_block(view, true); + } + + return view; +} + +bool ui_iface_viewmgr::pop_view() +{ + //FIXME: No more view? + if (this->get_view_count() == 0) + { + LOGE("No Views. Can't pop anymore!"); + return false; + } + + //This is the last page. + if (this->get_view_count() == 1) + { + //destroy viewmgr? + ui_iface_view*view = this->view_list.back(); + view->on_deactivate(); + view->on_unload(); + view->on_destroy(); + delete(view); + + return true; + } + + //last page to be popped. + ui_iface_view*view = this->view_list.back(); + view->on_deactivate(); + this->set_event_block(view, true); + + //Below object has to be used in child class... + //Make this getter method? or define instance? + //previous page is to be an active page. + auto nx = prev(this->view_list.end(), 2); + ui_iface_view*pview = *nx; + pview->on_load(); + pview->on_deactivate(); + this->set_event_block(pview, true); + + return true; +} + +bool ui_iface_viewmgr::insert_view_before(ui_iface_view *view, ui_iface_view *before) +{ + VIEW_ITR it; + + if (!view) + { + LOGE("invalid view argument. view(NULL)"); + return false; + } + + if (!this->connect_view(view)) + { + LOGE("connect view failed"); + return false; + } + + if (this->view_list.size() > 0) + { + for (it = this->view_list.begin(); it != this->view_list.end(); it++) + { + if (before == *it) + { + this->view_list.insert(it, view); + + return true; + } + } + } + + //If there is no matching before view with current list. + //also in case of before is NULL. + this->push_view(view); + + return true; +} + +bool ui_iface_viewmgr::remove_view(ui_iface_view *view) +{ + this->view_list.remove(view); + this->disconnect_view(view); + + //TODO: If this view is the top on the stack ? + return true; +} + +ui_iface_view *ui_iface_viewmgr::get_view(unsigned int idx) +{ + if (idx < 0 || idx >= this->view_list.size()) + { + LOGE("Invalid idx(%d)! =? (idx range: %d ~ %d)", idx, 0, this->view_list.size() - 1); + return NULL; + } + VIEW_ITR it = this->view_list.begin(); + advance(it, idx); + return *it; +} + +int ui_iface_viewmgr::get_view_index(const ui_iface_view *view) +{ + int idx = 0; + + for (VIEW_ITR it = this->view_list.begin(); it != this->view_list.end(); it++) + { + if (view == *it) return idx; + ++idx; + } + + return -1; +} + +ui_iface_view *ui_iface_viewmgr::get_last_view() +{ + int cnt = this->get_view_count(); + return this->get_view(cnt - 1); +} + +bool ui_iface_viewmgr::activate() +{ + if (this->activated) return false; + if (this->get_view_count() == 0) return false; + this->activated = true; + return true; +} + +bool ui_iface_viewmgr::deactivate() +{ + if (!this->activated) return false; + this->activated = false; + return true; +} + +ui_iface_view *ui_iface_viewmgr::get_view(const char *name) +{ + //FIXME: ... + return NULL; +} + +bool ui_iface_viewmgr::is_activated() +{ + return this->activated; +} + +unsigned int ui_iface_viewmgr::get_view_count() +{ + return this->view_list.size(); +} + +ui_iface_viewmgr* ui_iface_viewmgr::get_instance() +{ + return ui_iface_viewmgr::inst; +}