From 2b57e81b177be1931d4b75bd2509976b7a723525 Mon Sep 17 00:00:00 2001 From: Woochan Lee Date: Tue, 22 Mar 2016 11:41:59 +0900 Subject: [PATCH] Add rotated method in controller. Change-Id: Id136fc79a8a15b086f3dbff41f8fa861b7e375c6 --- src/examples/efl/page1.h | 18 +++++++++ src/include/efl/ui_controller.h | 26 +++++++++++++ src/include/efl/ui_view.h | 57 +++++++++++++++++++---------- src/include/interface/ui_iface_controller.h | 28 ++++++++++++++ src/lib/efl/ui_view.cpp | 34 +++++++++++++++++ src/lib/efl/ui_viewmgr.cpp | 15 ++++++++ 6 files changed, 159 insertions(+), 19 deletions(-) diff --git a/src/examples/efl/page1.h b/src/examples/efl/page1.h index 0df1305..e8b15b5 100644 --- a/src/examples/efl/page1.h +++ b/src/examples/efl/page1.h @@ -45,6 +45,9 @@ public: ui_basic_view *view = dynamic_cast(this->get_view()); + //Check the current rotation for set portrait or landscape content if any. + LOGE("view 1 load rotation = %d\n", view->get_degree()); + //Create a main content. Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 1", //Prev Button Callback @@ -83,6 +86,21 @@ public: return true; } + + void rotate(int degree) + { + LOGE("Current view's degree is %d\n", degree); + } + + void portrait() + { + LOGE("View is on portrait mode\n"); + } + + void landscape() + { + LOGE("View is on landscape mode\n"); + } }; void create_page1(appdata_s *ad) diff --git a/src/include/efl/ui_controller.h b/src/include/efl/ui_controller.h index 2828c2e..dcab8e5 100644 --- a/src/include/efl/ui_controller.h +++ b/src/include/efl/ui_controller.h @@ -103,7 +103,33 @@ public: */ virtual void destroy() {} + /** @brief Back key callback. + * + * @note In default. current view will be popped by viewmgr in those scenarios + * that viewmgr is requested to poo the current view. + * If you return false in the overriding, then popping will be stopped. + */ virtual bool back() { return true; } + + /** @brief View rotate callback. + * + * @param degree Current rotation degree. + * + * @note This method will be called when view rotation occurred. + */ + virtual void rotate(int degree) {} + + /** @brief Portrait callback. + * + * @note When current view is on portrait mode. + */ + virtual void portrait() {} + + /** @brief Landscape callback. + * + * @note When current view is on landscape mode. + */ + virtual void landscape() {} }; } diff --git a/src/include/efl/ui_view.h b/src/include/efl/ui_view.h index 5ff67ae..66a7425 100644 --- a/src/include/efl/ui_view.h +++ b/src/include/efl/ui_view.h @@ -43,6 +43,29 @@ class ui_view: public viewmgr::ui_iface_view { friend class ui_viewmgr; +protected: + /** @brief Unload current view's content + * + * @note Make this view's content as NULL, then destroy content. + */ + virtual void unload_content(); + + /** @brief Get a parent object of view. + * + * @note This is calling viewmgr get_base() method internally. + * + * @return base layout of viewmgr. + */ + Evas_Object *get_parent(); + + /** @brief toggle event block. + * + * @note It makes internal conformant event freeze during effect showing. + * + * @param block @c true, when blocking is enabled, otherwise @c false. + */ + virtual void set_event_block(bool block); + public: ///Constructor. ui_view(ui_controller *controller, const char *name = NULL); @@ -64,36 +87,32 @@ public: */ virtual Evas_Object *get_base(); + /** @brief This is for calling controller's back method. + */ virtual void back(); - /** @brief Set the indicator mode. - * - * @param indicator The mode to set, one of #ui_view_indicator. + /** @brief This is for calling controller's rotate method. */ - void set_indicator(ui_view_indicator indicator); + virtual void rotate(int degree); -protected: - /** @brief Unload current view's content - * - * @note Make this view's content as NULL, then destroy content. + /** @brief This is for calling controller's portrait method. */ - virtual void unload_content(); + virtual void portrait(); - /** @brief Get a parent object of view. - * - * @note This is calling viewmgr get_base() method internally. + /** @brief This is for calling controller's landscape method. + */ + virtual void landscape(); + /** @brief Set the indicator mode. * - * @return base layout of viewmgr. + * @param indicator The mode to set, one of #ui_view_indicator. */ - Evas_Object *get_parent(); + void set_indicator(ui_view_indicator indicator); - /** @brief toggle event block. - * - * @note It makes internal conformant event freeze during effect showing. + /** @brief Get current view's degree. * - * @param block @c true, when blocking is enabled, otherwise @c false. + * @return Current rotation degree, -1 if failed to get viewmgr degree. */ - virtual void set_event_block(bool block); + int get_degree(); }; } diff --git a/src/include/interface/ui_iface_controller.h b/src/include/interface/ui_iface_controller.h index 72b7d59..e854c01 100644 --- a/src/include/interface/ui_iface_controller.h +++ b/src/include/interface/ui_iface_controller.h @@ -120,6 +120,34 @@ public: * @note When this view is on destroying by popping or deleting. */ virtual void destroy() = 0; + + /** @brief Back key callback. + * + * @note In default. current view will be popped by viewmgr in those scenarios + * that viewmgr is requested to poo the current view. + * If you return false in the overriding, then popping will be stopped. + */ + virtual bool back() = 0; + + /** @brief View rotate callback. + * + * @param degree Current rotation degree. + * + * @note This method will be called when view rotation occurred. + */ + virtual void rotate(int degree) = 0; + + /** @brief Portrait callback. + * + * @note When current view is on portrait mode. + */ + virtual void portrait() = 0; + + /** @brief Landscape callback. + * + * @note When current view is on landscape mode. + */ + virtual void landscape() = 0; }; } diff --git a/src/lib/efl/ui_view.cpp b/src/lib/efl/ui_view.cpp index bbc5da3..b547925 100644 --- a/src/lib/efl/ui_view.cpp +++ b/src/lib/efl/ui_view.cpp @@ -93,8 +93,42 @@ void ui_view::back() dynamic_cast(this->get_viewmgr())->pop_view(); } +void ui_view::rotate(int degree) +{ + if (this->get_controller()) + { + dynamic_cast(this->get_controller())->rotate(degree); + } +} + +void ui_view::portrait() +{ + if (this->get_controller()) + { + dynamic_cast(this->get_controller())->portrait(); + } +} + +void ui_view::landscape() +{ + if (this->get_controller()) + { + dynamic_cast(this->get_controller())->landscape(); + } +} void ui_view::set_event_block(bool block) { ui_iface_view::set_event_block(block); evas_object_freeze_events_set(CONVERT_TO_EO(this->get_content()), block); } + +int ui_view::get_degree() +{ + ui_viewmgr *viewmgr = dynamic_cast(ui_iface_view::get_viewmgr()); + if (!viewmgr) + { + LOGE("Failed to get a viewmgr"); + return -1; + } + return elm_win_rotation_get(viewmgr->get_window()); +} diff --git a/src/lib/efl/ui_viewmgr.cpp b/src/lib/efl/ui_viewmgr.cpp index bfa12b3..fe954f9 100644 --- a/src/lib/efl/ui_viewmgr.cpp +++ b/src/lib/efl/ui_viewmgr.cpp @@ -188,6 +188,7 @@ ui_viewmgr::ui_viewmgr(const char *pkg, ui_key_listener *key_listener) return; } + //FIXME: Make a method? to set available rotation degree. //Set window rotation if (elm_win_wm_rotation_supported_get(this->win)) { @@ -195,6 +196,20 @@ ui_viewmgr::ui_viewmgr(const char *pkg, ui_key_listener *key_listener) { 0, 90, 180, 270 }; elm_win_wm_rotation_available_rotations_set(this->win, (const int *) (&rots), 4); } + evas_object_smart_callback_add(this->win, "wm,rotation,changed", + [](void *data, Evas_Object *obj, void *event_info) -> void + { + int rot = elm_win_rotation_get(obj); + + ui_viewmgr *viewmgr = static_cast(data); + ui_view *view = viewmgr->get_last_view(); + view->rotate(rot); + + //FIXME: Change this configurable? + if (rot == 0 || rot == 180) view->portrait(); + else view->landscape(); + } + , this); //Window is requested to delete. evas_object_smart_callback_add(this->win, "delete,request", -- 2.7.4