From f76c7d2d99c3adf6e96843d9157c3420d7d8cd11 Mon Sep 17 00:00:00 2001 From: Woochan Lee Date: Thu, 24 Nov 2016 19:56:00 +0900 Subject: [PATCH] Tabview: C api wrapping, Define error code. Change-Id: I351b0deb63a87493a6721504699c0f95de28c60d --- src/examples/efl/c/CMakeLists.txt | 1 + src/examples/efl/c/main.h | 1 + src/examples/efl/c/page16.cpp | 6 +- src/examples/efl/c/page17.cpp | 205 ++++++++++ src/include/efl/mobile/UiTabView.h | 12 +- src/include/efl/mobile/c/_ui_private.h | 1 + .../efl/mobile/c/ui_mobile_viewmanager.h | 2 + src/include/efl/mobile/c/ui_tab_view.h | 50 +++ src/include/interface/_UiIfacePrivate.h | 1 + src/lib/CMakeLists.txt | 1 + src/lib/efl/UiBaseViewmgr.cpp | 2 +- src/lib/efl/mobile/UiTabView.cpp | 83 ++-- src/lib/efl/mobile/c/ui_standard_view.cpp | 2 +- src/lib/efl/mobile/c/ui_tab_view.cpp | 382 ++++++++++++++++++ 14 files changed, 698 insertions(+), 51 deletions(-) create mode 100644 src/examples/efl/c/page17.cpp create mode 100644 src/include/efl/mobile/c/ui_tab_view.h create mode 100644 src/lib/efl/mobile/c/ui_tab_view.cpp diff --git a/src/examples/efl/c/CMakeLists.txt b/src/examples/efl/c/CMakeLists.txt index 8051a9a..b8a8e9c 100644 --- a/src/examples/efl/c/CMakeLists.txt +++ b/src/examples/efl/c/CMakeLists.txt @@ -17,6 +17,7 @@ SET(SRCS page14.cpp page15.cpp page16.cpp + page17.cpp ) ADD_EXECUTABLE(${BINNAME} ${SRCS}) diff --git a/src/examples/efl/c/main.h b/src/examples/efl/c/main.h index 9f41b12..9480a79 100644 --- a/src/examples/efl/c/main.h +++ b/src/examples/efl/c/main.h @@ -55,3 +55,4 @@ void create_page13(); void create_page14(); void create_page15(); void create_page16(); +void create_page17(); diff --git a/src/examples/efl/c/page16.cpp b/src/examples/efl/c/page16.cpp index c4c3bf7..e7bba94 100644 --- a/src/examples/efl/c/page16.cpp +++ b/src/examples/efl/c/page16.cpp @@ -30,11 +30,7 @@ prev_btn_clicked_cb(void *data, Eo *obj, void *event_info) static void next_btn_clicked_cb(void *data, Eo *obj, void *event_info) { - int ret = ui_viewmgr_deactivate(); - if (ret != UI_VIEWMGR_ERROR_NONE) - { - dlog_print(DLOG_ERROR, LOG_TAG, "ui_viewmgr_deactivate() is failed. err = %d", ret); - } + create_page17(); } static void diff --git a/src/examples/efl/c/page17.cpp b/src/examples/efl/c/page17.cpp new file mode 100644 index 0000000..5c30bcd --- /dev/null +++ b/src/examples/efl/c/page17.cpp @@ -0,0 +1,205 @@ +/* + * 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 "main.h" + +static void +prev_btn_clicked_cb(void *data, Eo *obj, void *event_info) +{ + int ret = ui_viewmgr_pop_view(); + if (ret != UI_VIEWMGR_ERROR_NONE) + { + dlog_print(DLOG_ERROR, LOG_TAG, "ui_viewmgr_pop_view() is failed. err = %d", ret); + } +} + +static void +next_btn_clicked_cb(void *data, Eo *obj, void *event_info) +{ + int ret = ui_viewmgr_deactivate(); + if (ret != UI_VIEWMGR_ERROR_NONE) + { + dlog_print(DLOG_ERROR, LOG_TAG, "ui_viewmgr_deactivate() is failed. err = %d", ret); + } +} + +static void +tab_activated(ui_tab_view *view, int id, void *user_data) +{ + printf("%d is activated. \n", id); +} + +static void +tab_deactivated(ui_tab_view *view, int id, void *user_data) +{ + printf("%d is deactivated. \n", id); +} + +static bool +view17_load_cb(ui_tab_view *view, void *user_data) +{ + Eo *base = NULL; + Eo *content1, *content2, *content3 = NULL; + int ret; + + //Get a base object from view. + base = ui_view_get_base(view); + if (!base) + { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to get a view base object"); + return false; + } + + //Create tab item content. + content1 = create_content(base, "ViewMgr Demo
Alarm Tab", prev_btn_clicked_cb, next_btn_clicked_cb); + if (!content1) return false; + + content2 = create_content(base, "ViewMgr Demo
Timer Tab", prev_btn_clicked_cb, next_btn_clicked_cb); + if (!content2) return false; + + content3 = create_content(base, "ViewMgr Demo
World Clock Tab", prev_btn_clicked_cb, next_btn_clicked_cb); + if (!content3) return false; + + //Add tab items. + ret = ui_tab_view_add_tab(view, 0); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to add tab item"); + return false; + } + ret = ui_tab_view_add_tab(view, 1); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to add tab item"); + return false; + } + ret = ui_tab_view_add_tab(view, 2); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to add tab item"); + return false; + } + + ret = ui_tab_view_set_tab_label(view, 0, "Alarm"); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab label"); + return false; + } + + ret = ui_tab_view_set_tab_label(view, 1, "Timer"); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab label"); + return false; + } + + ret = ui_tab_view_set_tab_label(view, 2, "World Clock"); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab label"); + return false; + } + + ret = ui_tab_view_set_tab_icon(view, 0, BINDIR"/data/images/icon_alarm.png"); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab icon"); + return false; + } + + ret = ui_tab_view_set_tab_icon(view, 1, BINDIR"/data/images/icon_timer.png"); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab icon"); + return false; + } + + ret = ui_tab_view_set_tab_icon(view, 2, BINDIR"/data/images/icon_worldclock.png"); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab icon"); + return false; + } + + ret = ui_tab_view_set_tab_content(view, 0, content1); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab content"); + return false; + } + + ret = ui_tab_view_set_tab_content(view, 1, content2); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab content"); + return false; + } + + ret = ui_tab_view_set_tab_content(view, 2, content3); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab content"); + return false; + } + + ret = ui_tab_view_select_tab(view, 2); + if (ret != UI_VIEWMGR_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to set tab content"); + return false; + } + + return true; +} + +void +create_page17() +{ + int ret = 0; + ui_tab_view *view = NULL; + + view = ui_tab_view_create("page17"); + if (!view) + { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to create a view"); + return; + } + + //Set View Load callback. + ret = ui_tab_view_set_event_cb(view, UI_TAB_ACTIVATED, tab_activated, NULL); + if (ret != UI_VIEWMGR_ERROR_NONE) + { + dlog_print(DLOG_ERROR, LOG_TAG, "ui_tab_view_set_event_cb() is failed. err = %d", ret); + ui_view_destroy(view); + return; + } + + //Set View Load callback. + ret = ui_tab_view_set_event_cb(view, UI_TAB_DEACTIVATED, tab_deactivated, NULL); + if (ret != UI_VIEWMGR_ERROR_NONE) + { + dlog_print(DLOG_ERROR, LOG_TAG, "ui_tab_view_set_event_cb() is failed. err = %d", ret); + ui_view_destroy(view); + return; + } + + //Set View Load callback. + ret = ui_view_set_event_cb(view, UI_VIEW_EVENT_LOAD, view17_load_cb, NULL); + if (ret != UI_VIEWMGR_ERROR_NONE) + { + dlog_print(DLOG_ERROR, LOG_TAG, "ui_view_set_event_cb() is failed. err = %d", ret); + ui_view_destroy(view); + return; + } + + //Push view. + ret = ui_viewmgr_push_view(view); + if (ret != UI_VIEWMGR_ERROR_NONE) + { + dlog_print(DLOG_ERROR, LOG_TAG, "ui_viewmgr_push_view() is failed. err = %d", ret); + ui_view_destroy(view); + } +} + diff --git a/src/include/efl/mobile/UiTabView.h b/src/include/efl/mobile/UiTabView.h index 69b5f33..7688db7 100644 --- a/src/include/efl/mobile/UiTabView.h +++ b/src/include/efl/mobile/UiTabView.h @@ -45,13 +45,13 @@ public: ///Destructor. virtual ~UiTabView(); - bool addTab(int id); + int addTab(int id); - bool setTabIcon(int id, const char *icon); + int setTabIcon(int id, const char *icon); - bool setTabLabel(int id, const char *label); + int setTabLabel(int id, const char *label); - bool setTabContent(int id, Eo *content); + int setTabContent(int id, Eo *content); const char *getTabIcon(int id); @@ -67,9 +67,9 @@ public: int getSelectedTab(); - bool removeTab(int id); + int removeTab(int id); - bool selectTab(int id); + int selectTab(int id); /** * @brief Get a base layout of viewmgr. diff --git a/src/include/efl/mobile/c/_ui_private.h b/src/include/efl/mobile/c/_ui_private.h index 5200117..036aa63 100644 --- a/src/include/efl/mobile/c/_ui_private.h +++ b/src/include/efl/mobile/c/_ui_private.h @@ -25,6 +25,7 @@ using namespace efl_viewmanager; using ui_viewmgr = UiViewmgr; using ui_view = UiView; using ui_standard_view = UiStandardView; +using ui_tab_view = UiTabView; using ui_menu = UiMenu; using ui_popup = UiPopup; diff --git a/src/include/efl/mobile/c/ui_mobile_viewmanager.h b/src/include/efl/mobile/c/ui_mobile_viewmanager.h index d57cd60..855829c 100644 --- a/src/include/efl/mobile/c/ui_mobile_viewmanager.h +++ b/src/include/efl/mobile/c/ui_mobile_viewmanager.h @@ -40,6 +40,7 @@ typedef struct ui_view_s ui_view; typedef ui_view ui_standard_view; +typedef ui_view ui_tab_view; typedef struct ui_menu_s ui_menu; typedef struct ui_popup_s ui_popup; @@ -53,5 +54,6 @@ typedef struct ui_popup_s ui_popup; #include "ui_viewmgr.h" #include "ui_view.h" #include "ui_standard_view.h" +#include "ui_tab_view.h" #endif /* UI_MOBILE_VIEWMANAGER_CAPI_H */ diff --git a/src/include/efl/mobile/c/ui_tab_view.h b/src/include/efl/mobile/c/ui_tab_view.h new file mode 100644 index 0000000..c7f1568 --- /dev/null +++ b/src/include/efl/mobile/c/ui_tab_view.h @@ -0,0 +1,50 @@ +#ifndef _UI_TAB_VIEW_CAPI_H_ +#define _UI_TAB_VIEW_CAPI_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*ui_tab_view_event_cb)(ui_tab_view *view, int id, void *user_data); + +typedef enum +{ + UI_TAB_ACTIVATED = 0, + UI_TAB_DEACTIVATED +} ui_tab_view_event_type_e; + +EAPI ui_tab_view *ui_tab_view_create(const char *name); + +EAPI int ui_tab_view_set_event_cb(ui_tab_view *view, ui_tab_view_event_type_e event_type, ui_tab_view_event_cb event_cb, void *user_data); + +EAPI int ui_tab_view_add_tab(ui_tab_view *view, int id); + +EAPI int ui_tab_view_set_tab_icon(ui_tab_view *view, int id, const char *icon); + +EAPI int ui_tab_view_set_tab_label(ui_tab_view *view, int id, const char *label); + +EAPI int ui_tab_view_set_tab_content(ui_tab_view *view, int id, Eo *content); + +EAPI const char *ui_tab_view_get_tab_icon(ui_tab_view *view, int id); + +EAPI const char *ui_tab_view_get_tab_label(ui_tab_view *view,int id); + +EAPI Eo *ui_tab_view_get_tab_content(ui_tab_view *view, int id); + +EAPI const char *ui_tab_view_unset_tab_icon(ui_tab_view *view, int id); + +EAPI const char *ui_tab_view_unset_tab_label(ui_tab_view *view, int id); + +EAPI Eo *ui_tab_view_unset_tab_content(ui_tab_view *view, int id); + +EAPI int ui_tab_view_get_selected_tab(ui_tab_view *view); + +EAPI int ui_tab_view_remove_tab(ui_tab_view *view, int id); + +EAPI int ui_tab_view_select_tab(ui_tab_view *view, int id); + +#ifdef __cplusplus +} +#endif + +#endif /* _UI_TAB_VIEW_CAPI_H_ */ diff --git a/src/include/interface/_UiIfacePrivate.h b/src/include/interface/_UiIfacePrivate.h index b468104..6d2bed1 100644 --- a/src/include/interface/_UiIfacePrivate.h +++ b/src/include/interface/_UiIfacePrivate.h @@ -6,5 +6,6 @@ #define _NUM_OF_UI_VIEW_INDICATOR 6 #define _NUM_OF_UI_VIEW_STATE 6 #define _NUM_OF_UI_VIEW_ORIENTATION_MODE 3 +#define _NUM_OF_UI_TAB_VIEW_EVENT_TYPE 2 #endif /* _UI_IFACE_PRIVATE_H_ */ diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 55dc95c..c424fd5 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -42,6 +42,7 @@ SET(SRCS efl/mobile/c/ui_popup.cpp efl/mobile/c/ui_view.cpp efl/mobile/c/ui_standard_view.cpp + efl/mobile/c/ui_tab_view.cpp efl/mobile/c/ui_viewmgr.cpp ) ENDIF() diff --git a/src/lib/efl/UiBaseViewmgr.cpp b/src/lib/efl/UiBaseViewmgr.cpp index 797f11d..754123a 100644 --- a/src/lib/efl/UiBaseViewmgr.cpp +++ b/src/lib/efl/UiBaseViewmgr.cpp @@ -547,5 +547,5 @@ void UiBaseViewmgr::setIndicator(UiViewIndicator indicator) int UiBaseViewmgr::activateTopView() { - this->_impl->activateTopView(); + return this->_impl->activateTopView(); } diff --git a/src/lib/efl/mobile/UiTabView.cpp b/src/lib/efl/mobile/UiTabView.cpp index e337925..7987779 100644 --- a/src/lib/efl/mobile/UiTabView.cpp +++ b/src/lib/efl/mobile/UiTabView.cpp @@ -53,11 +53,13 @@ private: _tabItem *_getItem(int id) { for (auto i : this->_itemList) { if (i->_itemId == id) { + set_last_result(UI_VIEWMGR_ERROR_NONE); return i; } } LOGE("There is no id(%d) in the item list", id); + set_last_result(UI_VIEWMGR_ERROR_INVALID_PARAMETER); return nullptr; } @@ -82,13 +84,13 @@ public: return this->_selectedItem; } - bool addTab(int id); + int addTab(int id); - bool setTabIcon(int id, const char *icon); + int setTabIcon(int id, const char *icon); - bool setTabLabel(int id, const char *label); + int setTabLabel(int id, const char *label); - bool setTabContent(int id, Eo *content); + int setTabContent(int id, Eo *content); const char *getTabIcon(int id); @@ -104,9 +106,9 @@ public: int getSelectedTab(); - bool removeTab(int id); + int removeTab(int id); - bool selectTab(int id); + int selectTab(int id); }; } @@ -173,6 +175,7 @@ bool UiTabViewImpl::_createToolbar() [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void { auto *view = static_cast(data); + if (!view->getSelectedItem()) return; elm_toolbar_item_selected_set(view->getSelectedItem()->_item, EINA_TRUE); @@ -211,12 +214,12 @@ Eo *UiTabViewImpl::getBase() const return this->_layout; } -bool UiTabViewImpl::addTab(int id) +int UiTabViewImpl::addTab(int id) { for (auto i : this->_itemList) { if (i->_itemId == id) { LOGE("Given id(%d) is already reserved.", id); - return false; + return UI_VIEWMGR_ERROR_INVALID_PARAMETER; } } @@ -243,28 +246,26 @@ bool UiTabViewImpl::addTab(int id) if (!it) { LOGE("Failed to create tabbar item"); - return NULL; + return UI_VIEWMGR_ERROR_OUT_OF_MEMORY; } tabItem->_item = it; + tabItem->_itemContent = nullptr; tabItem->_itemId = id; tabItem->_tabView = this; elm_object_item_data_set(it, tabItem); this->_itemList.push_back(tabItem); - if (this->_itemList.size() == 1) { - LOGE("WCC selcted it set!"); - this->_selectedItem = tabItem; - } + if (this->_itemList.size() == 1) this->_selectedItem = tabItem; - return true; + return UI_VIEWMGR_ERROR_NONE; } -bool UiTabViewImpl::setTabIcon(int id, const char *icon) +int UiTabViewImpl::setTabIcon(int id, const char *icon) { _tabItem *it = this->_getItem(id); - if (!it) return false; + if (!it) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; if (icon && !this->_icon) { elm_object_signal_emit(this->_layout, "elm,state,tabbar,icon,show", "viewmgr"); @@ -277,23 +278,23 @@ bool UiTabViewImpl::setTabIcon(int id, const char *icon) elm_toolbar_item_icon_set(it->_item, icon); - return true; + return UI_VIEWMGR_ERROR_NONE; } -bool UiTabViewImpl::setTabLabel(int id, const char *label) +int UiTabViewImpl::setTabLabel(int id, const char *label) { _tabItem *it = this->_getItem(id); - if (!it) return false; + if (!it) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; elm_object_item_text_set(it->_item, label); - return true; + return UI_VIEWMGR_ERROR_NONE;; } -bool UiTabViewImpl::setTabContent(int id, Eo *content) +int UiTabViewImpl::setTabContent(int id, Eo *content) { _tabItem *it = this->_getItem(id); - if (!it) return false; + if (!it) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; it->_itemContent = content; evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, @@ -309,7 +310,7 @@ bool UiTabViewImpl::setTabContent(int id, Eo *content) } }, this); - return true; + return UI_VIEWMGR_ERROR_NONE;; } const char *UiTabViewImpl::getTabIcon(int id) @@ -392,24 +393,30 @@ Eo *UiTabViewImpl::unsetTabContent(int id) int UiTabViewImpl::getSelectedTab() { Elm_Object_Item* it = elm_toolbar_selected_item_get(this->_toolbar); - _tabItem* tabItem = static_cast<_tabItem *>(elm_object_item_data_get(it)); + if (it) { + _tabItem* tabItem = static_cast<_tabItem *>(elm_object_item_data_get(it)); + + set_last_result(UI_VIEWMGR_ERROR_NONE); + return tabItem->_itemId; + } - return tabItem->_itemId; + set_last_result(UI_VIEWMGR_ERROR_NOT_PERMITTED); + return -1; } -bool UiTabViewImpl::removeTab(int id) +int UiTabViewImpl::removeTab(int id) { _tabItem *it = this->_getItem(id); - if (!it) return false; + if (!it) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; elm_object_item_del(it->_item); - return true; + return UI_VIEWMGR_ERROR_NONE;; } -bool UiTabViewImpl::selectTab(int id) +int UiTabViewImpl::selectTab(int id) { _tabItem *it = this->_getItem(id); - if (!it) return false; + if (!it) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; if (evas_object_visible_get(this->_toolbar)) { elm_toolbar_item_selected_set(it->_item, EINA_TRUE); @@ -418,7 +425,7 @@ bool UiTabViewImpl::selectTab(int id) this->_selectedItem = it; } - return true; + return UI_VIEWMGR_ERROR_NONE;; } /***********************************************************************************************/ @@ -467,27 +474,27 @@ Eo *UiTabView::getBase() const return this->_impl->getBase(); } -bool UiTabView::addTab(int id) +int UiTabView::addTab(int id) { if (id < 0) { LOGE("invalid index value. index value(%d) start since 0", id); - return NULL; + return UI_VIEWMGR_ERROR_INVALID_PARAMETER;; } return this->_impl->addTab(id); } -bool UiTabView::setTabIcon(int id, const char *icon) +int UiTabView::setTabIcon(int id, const char *icon) { return this->_impl->setTabIcon(id, icon); } -bool UiTabView::setTabLabel(int id, const char *label) +int UiTabView::setTabLabel(int id, const char *label) { return this->_impl->setTabLabel(id, label); } -bool UiTabView::setTabContent(int id, Eo *content) +int UiTabView::setTabContent(int id, Eo *content) { return this->_impl->setTabContent(id, content); } @@ -527,12 +534,12 @@ int UiTabView::getSelectedTab() return this->_impl->getSelectedTab(); } -bool UiTabView::removeTab(int id) +int UiTabView::removeTab(int id) { return this->_impl->removeTab(id); } -bool UiTabView::selectTab(int id) +int UiTabView::selectTab(int id) { return this->_impl->selectTab(id); } diff --git a/src/lib/efl/mobile/c/ui_standard_view.cpp b/src/lib/efl/mobile/c/ui_standard_view.cpp index cd171af..205a666 100644 --- a/src/lib/efl/mobile/c/ui_standard_view.cpp +++ b/src/lib/efl/mobile/c/ui_standard_view.cpp @@ -215,7 +215,7 @@ static ui_standard_view_capi *validate_view(const ui_standard_view *view) auto capi_view = dynamic_cast(const_cast(view)); if (!capi_view) { - LOGE("Invalid ui_standard_view = %p. Probably, you passed ui_view, not ui_standard_view.", view); + LOGE("Invalid ui_standard_view = %p. Probably, you passed other type of view, not ui_tab_view.", view); return nullptr; } diff --git a/src/lib/efl/mobile/c/ui_tab_view.cpp b/src/lib/efl/mobile/c/ui_tab_view.cpp new file mode 100644 index 0000000..5016227 --- /dev/null +++ b/src/lib/efl/mobile/c/ui_tab_view.cpp @@ -0,0 +1,382 @@ +#include "../../../../include/efl/mobile/c/_ui_private.h" +#include "../../../../include/efl/mobile/c/ui_view.h" +#include "../../../../include/efl/mobile/c/ui_tab_view.h" +#include "../../../../include/efl/mobile/c/_ui_common_view_capi.h" + +static const char *_this_type = "ui_tab_view"; + +class ui_tab_view_capi: public ui_tab_view, public ui_common_view_capi +{ +public: + ui_tab_view_event_cb tab_event_cb[_NUM_OF_UI_TAB_VIEW_EVENT_TYPE] = {nullptr, }; + void *tab_event_data[_NUM_OF_UI_TAB_VIEW_EVENT_TYPE] = {nullptr, }; + + void onLoad() override + { + if (this->event_cb[UI_VIEW_EVENT_LOAD]) + { + if (!this->event_cb[UI_VIEW_EVENT_LOAD](this, this->event_data[UI_VIEW_EVENT_LOAD])) return; + } + + ui_tab_view::onLoad(); + + if (this->event_cb[UI_VIEW_EVENT_LOAD_POST]) + { + if (!this->event_cb[UI_VIEW_EVENT_LOAD_POST](this, this->event_data[UI_VIEW_EVENT_LOAD_POST])) return; + } + } + + void onUnload() override + { + if (this->event_cb[UI_VIEW_EVENT_UNLOAD]) + { + if (!this->event_cb[UI_VIEW_EVENT_UNLOAD](this, this->event_data[UI_VIEW_EVENT_UNLOAD])) return; + } + + ui_tab_view::onUnload(); + + if (this->event_cb[UI_VIEW_EVENT_UNLOAD_POST]) + { + if (!this->event_cb[UI_VIEW_EVENT_UNLOAD_POST](this, this->event_data[UI_VIEW_EVENT_UNLOAD_POST])) return; + } + } + + void onPause() override + { + if (this->event_cb[UI_VIEW_EVENT_PAUSE]) + { + if (!this->event_cb[UI_VIEW_EVENT_PAUSE](this, this->event_data[UI_VIEW_EVENT_PAUSE])) return; + } + + ui_tab_view::onPause(); + + if (this->event_cb[UI_VIEW_EVENT_PAUSE_POST]) + { + if (!this->event_cb[UI_VIEW_EVENT_PAUSE_POST](this, this->event_data[UI_VIEW_EVENT_PAUSE_POST])) return; + } + } + + void onResume() override + { + if (this->event_cb[UI_VIEW_EVENT_RESUME]) + { + if (!this->event_cb[UI_VIEW_EVENT_RESUME](this, this->event_data[UI_VIEW_EVENT_RESUME])) return; + } + + ui_tab_view::onResume(); + + if (this->event_cb[UI_VIEW_EVENT_RESUME_POST]) + { + if (!this->event_cb[UI_VIEW_EVENT_RESUME_POST](this, this->event_data[UI_VIEW_EVENT_RESUME_POST])) return; + } + } + + void onActivate() override + { + if (this->event_cb[UI_VIEW_EVENT_ACTIVATE]) + { + if (!this->event_cb[UI_VIEW_EVENT_ACTIVATE](this, this->event_data[UI_VIEW_EVENT_ACTIVATE])) return; + } + + ui_tab_view::onActivate(); + + if (this->event_cb[UI_VIEW_EVENT_ACTIVATE_POST]) + { + if (!this->event_cb[UI_VIEW_EVENT_ACTIVATE_POST](this, this->event_data[UI_VIEW_EVENT_ACTIVATE_POST])) return; + } + } + + void onDeactivate() override + { + if (this->event_cb[UI_VIEW_EVENT_DEACTIVATE]) + { + if (!this->event_cb[UI_VIEW_EVENT_DEACTIVATE](this, this->event_data[UI_VIEW_EVENT_DEACTIVATE])) return; + } + + ui_tab_view::onDeactivate(); + + if (this->event_cb[UI_VIEW_EVENT_DEACTIVATE_POST]) + { + if (!this->event_cb[UI_VIEW_EVENT_DEACTIVATE_POST](this, this->event_data[UI_VIEW_EVENT_DEACTIVATE_POST])) return; + } + } + + void onDestroy() override + { + if (this->event_cb[UI_VIEW_EVENT_DESTROY]) + { + if (!this->event_cb[UI_VIEW_EVENT_DESTROY](this, this->event_data[UI_VIEW_EVENT_DESTROY])) return; + } + + ui_tab_view::onDestroy(); + + if (this->event_cb[UI_VIEW_EVENT_DESTROY_POST]) + { + if (!this->event_cb[UI_VIEW_EVENT_DESTROY_POST](this, this->event_data[UI_VIEW_EVENT_DESTROY_POST])) return; + } + } + + void onPortrait() override + { + if (this->event_cb[UI_VIEW_EVENT_PORTRAIT]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_PORTRAIT])(this, this->event_data[UI_VIEW_EVENT_PORTRAIT])) return; + } + + ui_tab_view::onPortrait(); + + if (this->event_cb[UI_VIEW_EVENT_PORTRAIT_POST]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_PORTRAIT_POST])(this, this->event_data[UI_VIEW_EVENT_PORTRAIT_POST])) return; + } + } + + void onLandscape() override + { + if (this->event_cb[UI_VIEW_EVENT_LANDSCAPE]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_LANDSCAPE])(this, this->event_data[UI_VIEW_EVENT_LANDSCAPE])) return; + } + + ui_tab_view::onLandscape(); + + if (this->event_cb[UI_VIEW_EVENT_LANDSCAPE_POST]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_LANDSCAPE_POST])(this, this->event_data[UI_VIEW_EVENT_LANDSCAPE_POST])) return; + } + } + + void onRotate(int degree) override + { + if (this->event_cb[UI_VIEW_EVENT_ROTATE]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_ROTATE])(this, this->event_data[UI_VIEW_EVENT_ROTATE])) return; + } + + ui_tab_view::onRotate(degree); + + if (this->event_cb[UI_VIEW_EVENT_ROTATE_POST]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_ROTATE_POST])(this, this->event_data[UI_VIEW_EVENT_ROTATE_POST])) return; + } + } + + void onBack() override + { + if (this->event_cb[UI_VIEW_EVENT_BACK]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_BACK])(this, this->event_data[UI_VIEW_EVENT_BACK])) return; + } + + ui_tab_view::onBack(); + + if (this->event_cb[UI_VIEW_EVENT_BACK_POST]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_BACK_POST])(this, this->event_data[UI_VIEW_EVENT_BACK_POST])) return; + } + } + + void onMenu(ui_menu *menu) override + { + if (this->event_cb[UI_VIEW_EVENT_MENU]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_MENU])(this, this->event_data[UI_VIEW_EVENT_MENU])) return; + } + + ui_tab_view::onMenu(menu); + + if (this->event_cb[UI_VIEW_EVENT_MENU_POST]) + { + if (!(*this->event_cb[UI_VIEW_EVENT_MENU_POST])(this, this->event_data[UI_VIEW_EVENT_MENU_POST])) return; + } + } + + ui_tab_view_capi(const char *name) + : ui_tab_view(name), ui_common_view_capi(_this_type) + { + } + + ~ui_tab_view_capi() + { + } + +protected: + void tabActivated(int id) + { + if (this->tab_event_cb[UI_TAB_ACTIVATED]) + { + (*this->tab_event_cb[UI_TAB_ACTIVATED])(this, id, this->tab_event_data[UI_TAB_ACTIVATED]); + } + } + + void tabDeactivated(int id) + { + if (this->tab_event_cb[UI_TAB_DEACTIVATED]) + { + (*this->tab_event_cb[UI_TAB_DEACTIVATED])(this, id, this->tab_event_data[UI_TAB_DEACTIVATED]); + } + } + +}; + +struct ui_tab_view_s +{ + ui_tab_view_capi *p; +}; + +static ui_tab_view_capi *validate_view(const ui_tab_view *view) +{ + if (!view) + { + LOGE("Invalid ui_tab_view = nullptr"); + set_last_result(UI_VIEWMGR_ERROR_INVALID_PARAMETER); + return nullptr; + } + + auto capi_view = dynamic_cast(const_cast(view)); + if (!capi_view) + { + LOGE("Invalid ui_tab_view = %p. Probably, you passed other type of view, not ui_tab_view.", view); + return nullptr; + } + + return capi_view; +} + +EAPI int ui_tab_view_set_event_cb(ui_tab_view *view, ui_tab_view_event_type_e event_type, ui_tab_view_event_cb event_cb, void *user_data) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; + + if (event_type < UI_TAB_ACTIVATED || event_type >= _NUM_OF_UI_TAB_VIEW_EVENT_TYPE) + { + LOGE("This view(%p) event_type is invalid(%d)", view, event_type); + return UI_VIEWMGR_ERROR_INVALID_PARAMETER; + } + + capi_view->tab_event_cb[event_type] = event_cb; + capi_view->tab_event_data[event_type] = user_data; + + return UI_VIEWMGR_ERROR_NONE; +} + + +EAPI ui_tab_view *ui_tab_view_create(const char *name) +{ + ui_tab_view *view = new ui_tab_view_capi(name); + + if (!view) + { + LOGE("Failed to create new ui_tab_view instance"); + set_last_result(UI_VIEWMGR_ERROR_OUT_OF_MEMORY); + return nullptr; + } + + set_last_result(UI_VIEWMGR_ERROR_NONE); + return new ui_tab_view_capi(name); +} + +EAPI int ui_tab_view_add_tab(ui_tab_view *view, int id) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; + + return capi_view->addTab(id); +} + +EAPI int ui_tab_view_set_tab_icon(ui_tab_view *view, int id, const char *icon) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; + + return capi_view->setTabIcon(id, icon); +} + +EAPI int ui_tab_view_set_tab_label(ui_tab_view *view, int id, const char *label) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; + + return capi_view->setTabLabel(id, label); +} + +EAPI int ui_tab_view_set_tab_content(ui_tab_view *view, int id, Eo *content) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; + + return capi_view->setTabContent(id, content); +} + +EAPI const char *ui_tab_view_get_tab_icon(ui_tab_view *view, int id) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return NULL; + + return capi_view->getTabIcon(id); +} + +EAPI const char *ui_tab_view_get_tab_label(ui_tab_view *view,int id) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return NULL; + + return capi_view->getTabLabel(id); +} + +EAPI Eo *ui_tab_view_get_tab_content(ui_tab_view *view, int id) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return NULL; + + return capi_view->getTabContent(id); +} + +EAPI const char *ui_tab_view_unset_tab_icon(ui_tab_view *view, int id) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return NULL; + + return capi_view->unsetTabIcon(id); +} + +EAPI const char *ui_tab_view_unset_tab_label(ui_tab_view *view, int id) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return NULL; + + return capi_view->unsetTabLabel(id); +} + +EAPI Eo *ui_tab_view_unset_tab_content(ui_tab_view *view, int id) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return NULL; + + return capi_view->unsetTabContent(id); +} + + +EAPI int ui_tab_view_select_tab(ui_tab_view *view, int id) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; + + return capi_view->selectTab(id); +} + +EAPI int ui_tab_view_get_selected_tab(ui_tab_view *view) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; + + return capi_view->getSelectedTab(); +} + +EAPI int ui_tab_view_remove_tab(ui_tab_view *view, int id) +{ + ui_tab_view_capi *capi_view = validate_view(view); + if (!capi_view) return UI_VIEWMGR_ERROR_INVALID_PARAMETER; + + return capi_view->removeTab(id); +} -- 2.34.1