let's simplify interface.
This is third step for sorting up public interfaces.
Change-Id: Id461b5f395ebfd35f431c70b6002e80abaa14166
class ui_base_viewmgr;
class ui_base_view;
-class ui_base_overlay: public ui_iface_overlay<Evas_Object *>
+class ui_base_overlay: public ui_iface_overlay
{
protected:
ui_base_overlay(ui_base_view *view);
* @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<Evas_Object *>
+class ui_base_view: public ui_iface_view
{
friend class ui_base_viewmgr;
#ifndef _UI_BASE_VIEWMANAGER_H_
#define _UI_BASE_VIEWMANAGER_H_
-#include <Elementary.h>
#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_base_viewmgr *>(ui_iface_viewmgr<Evas_Object *>::get_instance())
+#define UI_BASE_VIEWMGR dynamic_cast<ui_base_viewmgr *>(ui_iface_viewmgr::get_instance())
using namespace efl_viewmanager;
*
* @warning viewmgr will remove all containing views when it's destroyed.
*/
-class ui_base_viewmgr: public ui_iface_viewmgr<Evas_Object *>
+class ui_base_viewmgr: public ui_iface_viewmgr
{
friend class ui_base_view;
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<string, Elm_Layout *> effect_map; //Map for effect layouts.
Elm_Layout *set_transition_layout(string transition_style);
namespace ui_viewmanager
{
-template<typename T>
class ui_iface_view;
-template<typename T>
class ui_iface_overlay: public ui_iface_rotatable
{
private:
- ui_iface_view<T> *view;
+ ui_iface_view *view;
T content;
protected:
- ui_iface_overlay(ui_iface_view<T> *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<T> *get_view();
+ ui_iface_view *get_view();
virtual T get_content();
virtual void on_back();
virtual bool activate() = 0;
virtual bool is_activated() = 0;
};
-
-template<typename T>
-ui_iface_overlay<T>::ui_iface_overlay(ui_iface_view<T> *view)
- : view(view), content(NULL)
-{
-}
-
-template<typename T>
-ui_iface_overlay<T>::~ui_iface_overlay()
-{
-}
-
-template<typename T>
-bool ui_iface_overlay<T>::set_content(T content)
-{
- this->content = content;
- return true;
-}
-
-template<typename T>
-T ui_iface_overlay<T>::unset_content()
-{
- T prev = this->content;
- this->content = NULL;
- return prev;
-}
-
-template<typename T>
-T ui_iface_overlay<T>::get_content()
-{
- return this->content;
-}
-
-template<typename T>
-ui_iface_view<T> *ui_iface_overlay<T>::get_view()
-{
- return this->view;
-}
-
-template<typename T>
-void ui_iface_overlay<T>::on_back()
-{
- this->deactivate();
-}
-
}
#endif /* _UI_IFACE_OVERLAY_H_ */
namespace ui_viewmanager
{
-template<typename T>
+template<typename XX>
class singleton
{
private:
- static T* inst;
+ static XX* inst;
public:
singleton();
virtual ~singleton();
- inline static T* get_instance();
+ inline static XX* get_instance();
};
-template<typename T> T* singleton<T>::inst = NULL;
+template<typename XX> XX* singleton<XX>::inst = NULL;
-template<typename T>
-singleton<T>::singleton()
+template<typename XX>
+singleton<XX>::singleton()
{
- T* pT = reinterpret_cast<T*>(1);
+ XX* pT = reinterpret_cast<XX*>(1);
//Derived Class - Singleton class
- int offset = reinterpret_cast<int>(pT) - reinterpret_cast<int>(reinterpret_cast<singleton<T>*>(pT));
- singleton::inst = reinterpret_cast<T*>((reinterpret_cast<int>(this) + offset));
+ int offset = reinterpret_cast<int>(pT) - reinterpret_cast<int>(reinterpret_cast<singleton<XX>*>(pT));
+ singleton::inst = reinterpret_cast<XX*>((reinterpret_cast<int>(this) + offset));
}
-template<typename T>
-singleton<T>::~singleton()
+template<typename XX>
+singleton<XX>::~singleton()
{
singleton::inst = NULL;
}
-template<typename T>
-T* singleton<T>::get_instance()
+template<typename XX>
+XX* singleton<XX>::get_instance()
{
return singleton::inst;
}
namespace ui_viewmanager {
-template<typename T>
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<typename T>
class ui_iface_view : public ui_iface_rotatable
{
- friend class ui_iface_viewmgr<T>;
+ 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<T> *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.
/** @brief Return a viewmgr which this view is belonging to.
*/
//FIXME: Is it necessary?
- ui_iface_viewmgr<T> *get_viewmgr();
+ ui_iface_viewmgr *get_viewmgr();
/** @brief This is for replacing or setting a content of the view.
*
void on_back();
};
-
-template<typename T>
-bool ui_iface_view<T>::get_event_block()
-{
- return this->event_block;
-}
-
-template<typename T>
-ui_iface_viewmgr<T> *ui_iface_view<T>::get_viewmgr()
-{
- return this->viewmgr;
-}
-
-template<typename T>
-void ui_iface_view<T>::set_event_block(bool block)
-{
- this->event_block = block;
-}
-
-template<typename T>
-void ui_iface_view<T>::on_load()
-{
- this->state = UI_VIEW_STATE_LOAD;
-}
-
-template<typename T>
-void ui_iface_view<T>::on_unload()
-{
- this->state = UI_VIEW_STATE_UNLOAD;
- if (this->get_removable_content())
- {
- this->set_content(NULL);
- return;
- }
-}
-
-template<typename T>
-void ui_iface_view<T>::on_activate()
-{
- this->state = UI_VIEW_STATE_ACTIVATE;
-}
-
-template<typename T>
-void ui_iface_view<T>::on_deactivate()
-{
- this->state = UI_VIEW_STATE_DEACTIVATE;
-}
-
-template<typename T>
-void ui_iface_view<T>::on_pause()
-{
- this->state = UI_VIEW_STATE_PAUSE;
-}
-
-template<typename T>
-void ui_iface_view<T>::on_resume()
-{
- this->state = UI_VIEW_STATE_ACTIVATE;
-}
-
-template<typename T>
-void ui_iface_view<T>::on_destroy()
-{
-}
-
-template<typename T>
-ui_iface_view<T>::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<typename T>
-ui_iface_view<T>::~ui_iface_view()
-{
- this->viewmgr->remove_view(this);
-}
-
-template<typename T>
-bool ui_iface_view<T>::set_content(T content)
-{
- this->content = content;
- return true;
-}
-
-template<typename T>
-T ui_iface_view<T>::unset_content()
-{
- T prev = this->content;
- this->content = NULL;
- return prev;
-}
-
-template<typename T>
-bool ui_iface_view<T>::set_transition_style(const char *style)
-{
- this->transition_style.assign(style);
- return true;
-}
-
-template<typename T>
-bool ui_iface_view<T>::set_name(const char *name)
-{
- this->name.assign(name);
- return true;
-}
-
-template<typename T>
-void ui_iface_view<T>::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<typename T>
-void ui_iface_view<T>::set_indicator(ui_view_indicator indicator)
-{
- this->indicator = indicator;
-}
-
-template<typename T>
-const char *ui_iface_view<T>::get_transition_style()
-{
- return this->transition_style.c_str();
-}
-
-template<typename T>
-const char *ui_iface_view<T>::get_name()
-{
- return this->name.c_str();
-}
-
-template<typename T>
-T ui_iface_view<T>::get_content()
-{
- return this->content;
-}
-
-template<typename T>
-ui_view_state ui_iface_view<T>::get_state()
-{
- return this->state;
-}
-
-template<typename T>
-bool ui_iface_view<T>::get_removable_content()
-{
- return this->removable_content;
-}
-
-template<typename T>
-ui_view_indicator ui_iface_view<T>::get_indicator()
-{
- return this->indicator;
-}
-
-template<typename T>
-void ui_iface_view<T>::on_back()
-{
- ui_iface_viewmgr<T> *viewmgr = this->get_viewmgr();
- if (!viewmgr)
- {
- LOGE("Failed to get a viewmgr, view =%p", this);
- return;
- }
- viewmgr->pop_view();
-}
-
}
#endif /* _UI_IFACE_VIEW_H_ */
#include <app.h>
#include <dlog.h>
+#define UI_EFL 1
+
+#if UI_EFL
+ #include <Elementary.h>
+ typedef Evas_Object* T;
+#else if UI_DALI
+#endif
+
#ifdef LOG_TAG
#undef LOG_TAG
#endif
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 */
namespace ui_viewmanager {
-template<typename T>
class ui_iface_view;
/**
*
* @warning viewmgr will remove all containing views when it's destroyed.
*/
-template<typename T>
class ui_iface_viewmgr
{
- friend class ui_iface_view<T>;
+ friend class ui_iface_view;
private:
- static ui_iface_viewmgr<T> *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<ui_iface_view<T> *> view_list; //View list.
+ list<ui_iface_view *> view_list; //View list.
bool activated; //Activated status of this viewmgr.
/**
* @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<T> *view);
+ bool connect_view(ui_iface_view *view);
/**
* @brief Disconnect a given view from this viewmgr.
*
* @see connect_view()
*/
- bool disconnect_view(ui_iface_view<T> *view);
+ bool disconnect_view(ui_iface_view *view);
/**
* @brief Toggle event blocking to the given view.
* @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<T> *view, bool block);
+ void set_event_block(ui_iface_view *view, bool block);
protected:
/**
*
* @warning This function must be called when push transition is finished.
*/
- bool push_view_finished(ui_iface_view<T> *view);
+ bool push_view_finished(ui_iface_view *view);
/**
* @brief This function is designed for finishing process for pop transition.
*
* @warning This function must be called when push transition is finished.
*/
- bool pop_view_finished(ui_iface_view<T> *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.
* @see insert_view_after()
* @see pop_view()
*/
- ui_iface_view<T> *push_view(ui_iface_view<T> *view);
+ ui_iface_view *push_view(ui_iface_view *view);
/**
* @brief Pop the top(last) view from this viewmgr view list.
*
* @return @c true on success or @c false otherwise.
*/
- bool insert_view_before(ui_iface_view<T> *view, ui_iface_view<T> *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.
*
* @return @c true on success or @c false otherwise.
*/
- bool insert_view_after(ui_iface_view<T> *view, ui_iface_view<T> *after);
+ bool insert_view_after(ui_iface_view *view, ui_iface_view *after);
/**
* @brief Remove the given view from this viewmgr view list.
* @see insert_view_after()
* @see push_view()
*/
- bool remove_view(ui_iface_view<T> *view);
+ bool remove_view(ui_iface_view *view);
/**
* @brief Return a view which is matched with the index @p idx.
* @see get_view_index()
* @see get_view_count()
*/
- ui_iface_view<T>* get_view(unsigned int idx);
+ ui_iface_view* get_view(unsigned int idx);
/**
* @brief Return a view which is matched with the @p name.
*
* @see ui_iface_view::set_name()
*/
- ui_iface_view<T> *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<T> *get_last_view();
+ ui_iface_view *get_last_view();
/**
* @brief Return a view index(page) number of the given view.
*
* @warning The index number of views are variable since the view list is variable.
*/
- int get_view_index(const ui_iface_view<T> *view);
+ int get_view_index(const ui_iface_view *view);
///Constructor.
ui_iface_viewmgr();
* @return @c true if soft key is required, @c false otherwise.
*/
static bool need_soft_key();
- static ui_iface_viewmgr<T>* get_instance();
+ static ui_iface_viewmgr* get_instance();
};
-
-template<typename T> ui_iface_viewmgr<T> *ui_iface_viewmgr<T>::inst = NULL;
-
-#define VIEW_ITR typename list<ui_iface_view<T> *>::iterator
-#define VIEW_RITR typename list<ui_iface_view<T> *>::reverse_iterator
-
-//FIXME: Read system profile to decide whether support software key or not.
-template<typename T> bool ui_iface_viewmgr<T>::soft_key = true;
-//FIXME: Read system profile to decide whether support event block or not.
-template<typename T> bool ui_iface_viewmgr<T>::event_block = true;
-
-
-template<typename T>
-bool ui_iface_viewmgr<T>::insert_view_after(ui_iface_view<T> *view, ui_iface_view<T> *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<typename T>
-bool ui_iface_viewmgr<T>::need_soft_key()
-{
- return ui_iface_viewmgr<T>::soft_key;
-}
-
-template<typename T>
-bool ui_iface_viewmgr<T>::connect_view(ui_iface_view<T> *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<typename T>
-bool ui_iface_viewmgr<T>::disconnect_view(ui_iface_view<T> *view)
-{
- if (!view->viewmgr) return false;
- view->viewmgr = NULL;
- return true;
-}
-
-template<typename T>
-void ui_iface_viewmgr<T>::set_event_block(ui_iface_view<T> *view, bool block)
-{
- if (!ui_iface_viewmgr::event_block) return;
- view->set_event_block(block);
-}
-
-template<typename T>
-bool ui_iface_viewmgr<T>::push_view_finished(ui_iface_view<T> *view)
-{
- ui_iface_view<T> *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<typename T>
-bool ui_iface_viewmgr<T>::pop_view_finished(ui_iface_view<T> *view)
-{
- ui_iface_view<T> *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<typename T>
-ui_iface_viewmgr<T>::ui_iface_viewmgr(const ui_iface_viewmgr<T>& viewmgr)
-{
-}
-
-template<typename T>
-ui_iface_viewmgr<T>::ui_iface_viewmgr()
- : activated(false)
-{
- ui_iface_viewmgr<T>::inst = this;
-}
-
-template<typename T>
-ui_iface_viewmgr<T>::~ui_iface_viewmgr()
-{
- //Terminate views
- for (VIEW_RITR it = this->view_list.rbegin(); it != this->view_list.rend(); it++)
- {
- ui_iface_view<T> *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<typename T>
-ui_iface_view<T> *ui_iface_viewmgr<T>::push_view(ui_iface_view<T> *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<T> *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<typename T>
-bool ui_iface_viewmgr<T>::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<T>*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<T>*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<T>*pview = *nx;
- pview->on_load();
- pview->on_deactivate();
- this->set_event_block(pview, true);
-
- return true;
-}
-
-template<typename T>
-bool ui_iface_viewmgr<T>::insert_view_before(ui_iface_view<T> *view, ui_iface_view<T> *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<typename T>
-bool ui_iface_viewmgr<T>::remove_view(ui_iface_view<T> *view)
-{
- this->view_list.remove(view);
- this->disconnect_view(view);
-
- //TODO: If this view is the top on the stack ?
- return true;
-}
-
-template<typename T>
-ui_iface_view<T> *ui_iface_viewmgr<T>::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<typename T>
-int ui_iface_viewmgr<T>::get_view_index(const ui_iface_view<T> *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<typename T>
-ui_iface_view<T> *ui_iface_viewmgr<T>::get_last_view()
-{
- int cnt = this->get_view_count();
- return this->get_view(cnt - 1);
-}
-
-template<typename T>
-bool ui_iface_viewmgr<T>::activate()
-{
- if (this->activated) return false;
- if (this->get_view_count() == 0) return false;
- this->activated = true;
- return true;
-}
-
-template<typename T>
-bool ui_iface_viewmgr<T>::deactivate()
-{
- if (!this->activated) return false;
- this->activated = false;
- return true;
-}
-
-template<typename T>
-ui_iface_view<T> *ui_iface_viewmgr<T>::get_view(const char *name)
-{
- //FIXME: ...
- return NULL;
-}
-
-template<typename T>
-bool ui_iface_viewmgr<T>::is_activated()
-{
- return this->activated;
-}
-
-template<typename T>
-unsigned int ui_iface_viewmgr<T>::get_view_count()
-{
- return this->view_list.size();
-}
-
-template<typename T>
-ui_iface_viewmgr<T>* ui_iface_viewmgr<T>::get_instance()
-{
- return ui_iface_viewmgr::inst;
-}
-
}
#endif /* _UI_IFACE_VIEWMGR_H_ */
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
--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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<ui_iface_view *>::iterator
+#define VIEW_RITR list<ui_iface_view *>::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;
+}