diff options
Diffstat (limited to 'lib/common/View.cpp')
-rw-r--r-- | lib/common/View.cpp | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/lib/common/View.cpp b/lib/common/View.cpp new file mode 100644 index 0000000..c441368 --- /dev/null +++ b/lib/common/View.cpp @@ -0,0 +1,173 @@ +/* + * 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 "View.h" + +#include <ui-gadget-module.h> + +#include "phone.h" + +namespace Common +{ + View::View() + : back_cb(NULL), menu_cb(NULL), + m_Parent(NULL), m_Content(NULL) + { + PH_TRACE; + } + + View::View(const char *title) + : back_cb(NULL), menu_cb(NULL), + m_Title(title), m_Parent(NULL), m_Content(NULL) + { + PH_TRACE; + } + + View::~View() + { + PH_TRACE; + // m_Content and its children are destroyed by naviframe pop + } + + bool View::initialize(Evas_Object *parent) + { + PH_TRACE; + if(!parent || m_Parent) + { + return false; + } + + m_Parent = parent; + m_Content = elm_layout_add(m_Parent); + + if(!m_Content) + { + m_Parent = NULL; + return false; + } + + elm_layout_theme_set(m_Content, "layout", "application", "default"); + evas_object_size_hint_weight_set(m_Content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + + Evas_Object *bg = elm_bg_add(m_Content); + + if(!bg) + { + evas_object_del(m_Content); + m_Parent = NULL; + m_Content = NULL; + return false; + } + + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_part_content_set(m_Content, "elm.swallow.bg", bg); + + return true; + } + + const std::string & View::getTitle() const + { + PH_TRACE; + return m_Title; + } + + Evas_Object * View::getContent() const + { + PH_TRACE; + return m_Content; + } + + bool View::onBack() + { + PH_TRACE; + bool handled = false; + + if (child_ug) + { + DBG("send to child ug"); + ug_send_key_event (UG_KEY_EVENT_END); + handled = true; + } + else if (popup && evas_object_visible_get(popup)) //legacy popups + { + DBG("hide popup"); + evas_object_hide(popup); + handled = true; + } + else if (m_ContextMenu && evas_object_visible_get(m_ContextMenu)) + { + DBG("close contextual menu"); + elm_ctxpopup_dismiss(m_ContextMenu); + handled = true; + } + else if (m_Menu && evas_object_visible_get(m_Menu)) + { + DBG("close menu"); + elm_ctxpopup_dismiss(m_Menu); + handled = true; + } + else if (m_Widget && elm_object_focus_get(m_Widget)) + { + DBG("unfocus widget"); + widget_back_cb(this); + handled = true; + } + else if (back_cb) + { + DBG("call back_cb"); + back_cb(this); + handled = true; + } + + return handled; + } + + void View::onMenu() + { + PH_TRACE; + if(popup && evas_object_visible_get(popup)) + { + // no menu should appear, when popup is opened + return; + } + if(m_ContextMenu) + { + if(evas_object_visible_get(m_ContextMenu)) + { + DBG("close contextual menu"); + elm_ctxpopup_dismiss(m_ContextMenu); + } + } + if(m_Menu) + { + if(evas_object_visible_get(m_Menu)) + { + DBG("close menu"); + elm_ctxpopup_dismiss(m_Menu); + } + else if(menu_cb) + { + DBG("call menu_cb"); + menu_cb(this); + } + } + else if(menu_cb) + { + DBG("call menu_cb"); + menu_cb(this); + } + } +} |