From 1eb28d10d1ceafecccf497ca0f4affaafe4b31cc Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 28 Apr 2016 23:28:55 +0900 Subject: [PATCH] remove singleton inheritation. let's simplify interfaces. This is second step for sorting up public interfaces. Change-Id: Ia1ab4422069bdae44f397b15b6d25c32d93d949f --- src/include/efl/ui_base_overlay.h | 2 +- src/include/efl/ui_base_view.h | 2 +- src/include/efl/ui_base_viewmanager.h | 2 +- src/include/efl/ui_base_viewmgr.h | 2 +- src/include/interface/ui_iface_overlay.h | 38 ++--- src/include/interface/ui_iface_view.h | 112 +++++++------- src/include/interface/ui_iface_viewmgr.h | 185 +++++++++++------------ 7 files changed, 170 insertions(+), 173 deletions(-) diff --git a/src/include/efl/ui_base_overlay.h b/src/include/efl/ui_base_overlay.h index 5e4abc4..849743d 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 fb62a9d..58abebd 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 2115d6f..0576ab5 100644 --- a/src/include/efl/ui_base_viewmanager.h +++ b/src/include/efl/ui_base_viewmanager.h @@ -24,7 +24,7 @@ #include "ui_base_viewmgr.h" #include "ui_base_view.h" -#define UI_BASE_VIEWMGR ui_base_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 729d9a2..e505209 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; diff --git a/src/include/interface/ui_iface_overlay.h b/src/include/interface/ui_iface_overlay.h index 076c21b..960ac22 100644 --- a/src/include/interface/ui_iface_overlay.h +++ b/src/include/interface/ui_iface_overlay.h @@ -20,24 +20,24 @@ namespace ui_viewmanager { -template +template class ui_iface_view; -template +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; @@ -46,46 +46,46 @@ public: }; -template -ui_iface_overlay::ui_iface_overlay(ui_iface_view *view) +template +ui_iface_overlay::ui_iface_overlay(ui_iface_view *view) : view(view), content(NULL) { } -template -ui_iface_overlay::~ui_iface_overlay() +template +ui_iface_overlay::~ui_iface_overlay() { } -template -bool ui_iface_overlay::set_content(T content) +template +bool ui_iface_overlay::set_content(T content) { this->content = content; return true; } -template -T ui_iface_overlay::unset_content() +template +T ui_iface_overlay::unset_content() { T prev = this->content; this->content = NULL; return prev; } -template -T ui_iface_overlay::get_content() +template +T ui_iface_overlay::get_content() { return this->content; } -template -ui_iface_view *ui_iface_overlay::get_view() +template +ui_iface_view *ui_iface_overlay::get_view() { return this->view; } -template -void ui_iface_overlay::on_back() +template +void ui_iface_overlay::on_back() { this->deactivate(); } diff --git a/src/include/interface/ui_iface_view.h b/src/include/interface/ui_iface_view.h index 4deda6a..754e549 100644 --- a/src/include/interface/ui_iface_view.h +++ b/src/include/interface/ui_iface_view.h @@ -23,7 +23,7 @@ using namespace std; namespace ui_viewmanager { -template +template class ui_iface_viewmgr; /** @@ -39,16 +39,16 @@ 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 +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 +123,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. * @@ -233,32 +233,32 @@ public: }; -template -bool ui_iface_view::get_event_block() +template +bool ui_iface_view::get_event_block() { return this->event_block; } -template -ui_iface_viewmgr *ui_iface_view::get_viewmgr() +template +ui_iface_viewmgr *ui_iface_view::get_viewmgr() { return this->viewmgr; } -template -void ui_iface_view::set_event_block(bool block) +template +void ui_iface_view::set_event_block(bool block) { this->event_block = block; } -template -void ui_iface_view::on_load() +template +void ui_iface_view::on_load() { this->state = UI_VIEW_STATE_LOAD; } -template -void ui_iface_view::on_unload() +template +void ui_iface_view::on_unload() { this->state = UI_VIEW_STATE_UNLOAD; if (this->get_removable_content()) @@ -268,132 +268,132 @@ void ui_iface_view::on_unload() } } -template -void ui_iface_view::on_activate() +template +void ui_iface_view::on_activate() { this->state = UI_VIEW_STATE_ACTIVATE; } -template -void ui_iface_view::on_deactivate() +template +void ui_iface_view::on_deactivate() { this->state = UI_VIEW_STATE_DEACTIVATE; } -template -void ui_iface_view::on_pause() +template +void ui_iface_view::on_pause() { this->state = UI_VIEW_STATE_PAUSE; } -template -void ui_iface_view::on_resume() +template +void ui_iface_view::on_resume() { this->state = UI_VIEW_STATE_ACTIVATE; } -template -void ui_iface_view::on_destroy() +template +void ui_iface_view::on_destroy() { } -template -ui_iface_view::ui_iface_view(const char *name) +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() +template +ui_iface_view::~ui_iface_view() { this->viewmgr->remove_view(this); } -template -bool ui_iface_view::set_content(T content) +template +bool ui_iface_view::set_content(T content) { this->content = content; return true; } -template -T ui_iface_view::unset_content() +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) +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) +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) +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) +template +void ui_iface_view::set_indicator(ui_view_indicator indicator) { this->indicator = indicator; } -template -const char *ui_iface_view::get_transition_style() +template +const char *ui_iface_view::get_transition_style() { return this->transition_style.c_str(); } -template -const char *ui_iface_view::get_name() +template +const char *ui_iface_view::get_name() { return this->name.c_str(); } -template -T ui_iface_view::get_content() +template +T ui_iface_view::get_content() { return this->content; } -template -ui_view_state ui_iface_view::get_state() +template +ui_view_state ui_iface_view::get_state() { return this->state; } -template -bool ui_iface_view::get_removable_content() +template +bool ui_iface_view::get_removable_content() { return this->removable_content; } -template -ui_view_indicator ui_iface_view::get_indicator() +template +ui_view_indicator ui_iface_view::get_indicator() { return this->indicator; } -template -void ui_iface_view::on_back() +template +void ui_iface_view::on_back() { - ui_iface_viewmgr *viewmgr = this->get_viewmgr(); + ui_iface_viewmgr *viewmgr = this->get_viewmgr(); if (!viewmgr) { LOGE("Failed to get a viewmgr, view =%p", this); diff --git a/src/include/interface/ui_iface_viewmgr.h b/src/include/interface/ui_iface_viewmgr.h index 0da1bc8..30d23c1 100644 --- a/src/include/interface/ui_iface_viewmgr.h +++ b/src/include/interface/ui_iface_viewmgr.h @@ -23,7 +23,7 @@ using namespace std; namespace ui_viewmanager { -template +template class ui_iface_view; /** @@ -38,16 +38,17 @@ class ui_iface_view; * * @warning viewmgr will remove all containing views when it's destroyed. */ -template -class ui_iface_viewmgr: public singleton +template +class ui_iface_viewmgr { - friend class ui_iface_view; + friend class ui_iface_view; private: - 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. - bool activated; //Activated status of this viewmgr. + 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. + bool activated; //Activated status of this viewmgr. /** * @brief Connect a given view to this viewmgr. @@ -59,7 +60,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. @@ -70,7 +71,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. @@ -82,7 +83,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: /** @@ -94,7 +95,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. @@ -107,22 +108,7 @@ protected: * * @warning This function must be called when push transition is finished. */ - bool pop_view_finished(ui_iface_view *view); - -//FIXME: Necessary? -#if 0 - /** - * @brief Return a list of views which this viewmgr has. - * - * @return a pointer of list of views. - * - * @warning Don't modify this view list. - */ - const list*>* const get_view_list() - { - return &this->view_list; - } -#endif + 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. @@ -141,7 +127,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. @@ -166,7 +152,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. @@ -176,7 +162,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. @@ -189,7 +175,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. @@ -205,7 +191,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. @@ -219,14 +205,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. @@ -238,7 +224,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(); @@ -300,20 +286,23 @@ public: * @return @c true if soft key is required, @c false otherwise. */ static bool need_soft_key(); + static ui_iface_viewmgr* get_instance(); }; -#define VIEW_ITR typename list *>::iterator -#define VIEW_RITR typename list *>::reverse_iterator +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; +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::event_block = true; -template -bool ui_iface_viewmgr::insert_view_after(ui_iface_view *view, ui_iface_view *after) +template +bool ui_iface_viewmgr::insert_view_after(ui_iface_view *view, ui_iface_view *after) { VIEW_ITR it; @@ -354,14 +343,14 @@ bool ui_iface_viewmgr::insert_view_after(ui_iface_view *view, ui_i return true; } -template -bool ui_iface_viewmgr::need_soft_key() +template +bool ui_iface_viewmgr::need_soft_key() { - return ui_iface_viewmgr::soft_key; + return ui_iface_viewmgr::soft_key; } -template -bool ui_iface_viewmgr::connect_view(ui_iface_view *view) +template +bool ui_iface_viewmgr::connect_view(ui_iface_view *view) { //FIXME: If user call a set_viewmgr() before, It should not return false. /* @@ -376,25 +365,25 @@ bool ui_iface_viewmgr::connect_view(ui_iface_view *view) return true; } -template -bool ui_iface_viewmgr::disconnect_view(ui_iface_view *view) +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) +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) +template +bool ui_iface_viewmgr::push_view_finished(ui_iface_view *view) { - ui_iface_view *last = this->view_list.back(); + ui_iface_view *last = this->view_list.back(); //The previous view has been pushed. This should be unload. if (last != view) @@ -410,10 +399,10 @@ bool ui_iface_viewmgr::push_view_finished(ui_iface_view *view) return true; } -template -bool ui_iface_viewmgr::pop_view_finished(ui_iface_view *view) +template +bool ui_iface_viewmgr::pop_view_finished(ui_iface_view *view) { - ui_iface_view *last = this->view_list.back(); + ui_iface_view *last = this->view_list.back(); //This view has been popped. It should be destroyed. if (last == view) @@ -431,25 +420,25 @@ bool ui_iface_viewmgr::pop_view_finished(ui_iface_view *view) return true; } -template -ui_iface_viewmgr::ui_iface_viewmgr(const ui_iface_viewmgr& viewmgr) +template +ui_iface_viewmgr::ui_iface_viewmgr(const ui_iface_viewmgr& viewmgr) { - } -template -ui_iface_viewmgr::ui_iface_viewmgr() - : singleton(), activated(false) +template +ui_iface_viewmgr::ui_iface_viewmgr() + : activated(false) { + ui_iface_viewmgr::inst = this; } -template -ui_iface_viewmgr::~ui_iface_viewmgr() +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; + ui_iface_view *view = *it; view->on_deactivate(); view->on_unload(); view->on_destroy(); @@ -458,10 +447,12 @@ ui_iface_viewmgr::~ui_iface_viewmgr() //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) +template +ui_iface_view *ui_iface_viewmgr::push_view(ui_iface_view *view) { if (!view) { @@ -475,7 +466,7 @@ ui_iface_view *ui_iface_viewmgr::push_view(ui_iface_view *v return NULL; } - ui_iface_view *pview; + ui_iface_view *pview; //Previous view if (this->view_list.size() > 0) @@ -502,8 +493,8 @@ ui_iface_view *ui_iface_viewmgr::push_view(ui_iface_view *v return view; } -template -bool ui_iface_viewmgr::pop_view() +template +bool ui_iface_viewmgr::pop_view() { //FIXME: No more view? if (this->get_view_count() == 0) @@ -516,7 +507,7 @@ bool ui_iface_viewmgr::pop_view() if (this->get_view_count() == 1) { //destroy viewmgr? - ui_iface_view*view = this->view_list.back(); + ui_iface_view*view = this->view_list.back(); view->on_deactivate(); view->on_unload(); view->on_destroy(); @@ -526,7 +517,7 @@ bool ui_iface_viewmgr::pop_view() } //last page to be popped. - ui_iface_view*view = this->view_list.back(); + ui_iface_view*view = this->view_list.back(); view->on_deactivate(); this->set_event_block(view, true); @@ -534,7 +525,7 @@ bool ui_iface_viewmgr::pop_view() //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; + ui_iface_view*pview = *nx; pview->on_load(); pview->on_deactivate(); this->set_event_block(pview, true); @@ -542,8 +533,8 @@ bool ui_iface_viewmgr::pop_view() return true; } -template -bool ui_iface_viewmgr::insert_view_before(ui_iface_view *view, ui_iface_view *before) +template +bool ui_iface_viewmgr::insert_view_before(ui_iface_view *view, ui_iface_view *before) { VIEW_ITR it; @@ -579,8 +570,8 @@ bool ui_iface_viewmgr::insert_view_before(ui_iface_view *view, ui_ return true; } -template -bool ui_iface_viewmgr::remove_view(ui_iface_view *view) +template +bool ui_iface_viewmgr::remove_view(ui_iface_view *view) { this->view_list.remove(view); this->disconnect_view(view); @@ -589,8 +580,8 @@ bool ui_iface_viewmgr::remove_view(ui_iface_view *view) return true; } -template -ui_iface_view *ui_iface_viewmgr::get_view(unsigned int idx) +template +ui_iface_view *ui_iface_viewmgr::get_view(unsigned int idx) { if (idx < 0 || idx >= this->view_list.size()) { @@ -602,8 +593,8 @@ ui_iface_view *ui_iface_viewmgr::get_view(unsigned int idx) return *it; } -template -int ui_iface_viewmgr::get_view_index(const ui_iface_view *view) +template +int ui_iface_viewmgr::get_view_index(const ui_iface_view *view) { int idx = 0; @@ -616,15 +607,15 @@ int ui_iface_viewmgr::get_view_index(const ui_iface_view *view) return -1; } -template -ui_iface_view *ui_iface_viewmgr::get_last_view() +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() +template +bool ui_iface_viewmgr::activate() { if (this->activated) return false; if (this->get_view_count() == 0) return false; @@ -632,33 +623,39 @@ bool ui_iface_viewmgr::activate() return true; } -template -bool ui_iface_viewmgr::deactivate() +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) +template +ui_iface_view *ui_iface_viewmgr::get_view(const char *name) { //FIXME: ... return NULL; } -template -bool ui_iface_viewmgr::is_activated() +template +bool ui_iface_viewmgr::is_activated() { return this->activated; } -template -unsigned int ui_iface_viewmgr::get_view_count() +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_ */ -- 2.34.1