summaryrefslogtreecommitdiff
path: root/lib/common/ViewManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common/ViewManager.cpp')
-rw-r--r--lib/common/ViewManager.cpp190
1 files changed, 190 insertions, 0 deletions
diff --git a/lib/common/ViewManager.cpp b/lib/common/ViewManager.cpp
new file mode 100644
index 0000000..ee211af
--- /dev/null
+++ b/lib/common/ViewManager.cpp
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2012-2013 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 "ViewManager.h"
+
+#include <efl_assist.h>
+#include <ui-gadget-module.h>
+
+#include "phone.h"
+#include "View.h"
+
+namespace Common
+{
+ ViewManager::ViewManager()
+ : m_Layout(NULL)
+ {
+ PH_TRACE;
+ }
+
+ ViewManager::~ViewManager()
+ {
+ if(m_Layout)
+ {
+ evas_object_del(m_Layout);
+ m_Layout = NULL;
+ }
+ }
+
+ bool ViewManager::initialize(Evas_Object *win, Evas_Object *parent)
+ {
+ PH_TRACE;
+ if(!parent || m_Layout)
+ {
+ return false;
+ }
+
+ m_Layout = elm_layout_add(parent);
+ if(!m_Layout)
+ {
+ return false;
+ }
+
+ evas_object_size_hint_weight_set(m_Layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_layout_theme_set(m_Layout, "layout", "application", "default");
+ evas_object_show(m_Layout);
+
+ Evas_Object *bg = elm_bg_add(m_Layout);
+ if(!bg)
+ {
+ evas_object_del(m_Layout);
+ m_Layout = NULL;
+ return false;
+ }
+
+ evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_part_content_set(m_Layout, "elm.swallow.bg", bg);
+
+ navi = elm_naviframe_add(m_Layout);
+ if(!navi)
+ {
+ evas_object_del(m_Layout);
+ m_Layout = NULL;
+ return false;
+ }
+
+ elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
+ elm_object_part_content_set(m_Layout, "elm.swallow.content", navi);
+ evas_object_data_set(navi, "ViewManager", this);
+ ea_object_event_callback_add(navi, EA_CALLBACK_BACK, &Common::ViewManager::onBack, win);
+ ea_object_event_callback_add(navi, EA_CALLBACK_MORE, &Common::ViewManager::onMenu, NULL);
+
+ return true;
+ }
+
+ Evas_Object * ViewManager::getContent() const
+ {
+ return m_Layout;
+ }
+
+ void ViewManager::push(View &view)
+ {
+ PH_TRACE;
+ Elm_Object_Item *item = elm_naviframe_item_push(navi, view.getTitle().c_str(), NULL, NULL, view.getContent(), NULL);
+ elm_object_item_data_set(item, &view);
+ evas_object_event_callback_add(view.getContent(), EVAS_CALLBACK_DEL, onViewDestroy, &view);
+ }
+
+ void ViewManager::pop()
+ {
+ PH_TRACE;
+ elm_naviframe_item_pop(navi);
+ }
+
+ void ViewManager::onBack(void *data, Evas_Object *obj, void *event)
+ {
+ PH_TRACE;
+ if(!obj)
+ {
+ return;
+ }
+
+ Elm_Object_Item *top = elm_naviframe_top_item_get(obj);
+
+ if(!top)
+ {
+ //naviframe is empty, nothing to handle
+ return;
+ }
+
+ View *view = static_cast<View *>(elm_object_item_data_get(top));
+ DBG("view = %p", view);
+
+ if (view && view->onBack())
+ {
+ DBG("onBack handled");
+ return;
+ }
+
+ //naviframe has only one item
+ if (top == elm_naviframe_bottom_item_get(obj))
+ {
+ if(view && view->ug)
+ {
+ DBG("destroy self, removing view-callbacks");
+ ea_object_event_callback_del(view->navi, EA_CALLBACK_BACK, &Common::ViewManager::onBack);
+ ea_object_event_callback_del(view->navi, EA_CALLBACK_MORE, &Common::ViewManager::onMenu);
+ ug_destroy_me(view->ug);
+ }
+ else if(data)
+ {
+ DBG("lower win");
+ elm_win_lower(static_cast<Evas_Object *>(data));
+ return;
+ }
+ }
+ else
+ {
+ DBG("pop item");
+ elm_naviframe_item_pop(obj);
+ return;
+ }
+ }
+
+ void ViewManager::onMenu(void *data, Evas_Object *obj, void *event)
+ {
+ PH_TRACE;
+ if(!obj)
+ {
+ return;
+ }
+
+ Elm_Object_Item *top = elm_naviframe_top_item_get(obj);
+
+ if(!top)
+ {
+ //naviframe is empty, nothing to handle
+ return;
+ }
+
+ View *view = static_cast<View *>(elm_object_item_data_get(top));
+
+ if (view)
+ {
+ view->onMenu();
+ }
+ }
+
+ void ViewManager::onViewDestroy(void *data, Evas *e, Evas_Object *obj, void *event_info)
+ {
+ PH_TRACE;
+ if(data)
+ {
+ delete static_cast<View *>(data);
+ }
+ }
+}