Separate rotation implementation from app-core-cpp
[platform/core/appfw/app-core.git] / tizen-cpp / app-core-ui-cpp / app_core_ui_base.cc
index 2eeb488..beeef29 100644 (file)
@@ -35,6 +35,7 @@
 #include <utility>
 
 #include "app-core-cpp/app_core_base.hh"
+#include "app-core-rotation-cpp/app_core_rotation.hh"
 #include "app-core-ui-cpp/api/app_core_ui_base.h"
 #include "app-core-ui-cpp/app_core_task_base.hh"
 #include "app-core-ui-cpp/app_core_ui_delegator_private.hh"
@@ -54,7 +55,7 @@ constexpr const char K_HINT_RECENT_SCREEN_POSITION[] =
     "__K_HINT_RECENT_SCREEN_POSITION";
 const int APPID_MAX = 256;
 
-class AppCoreUiBase::Impl {
+class AppCoreUiBase::Impl : public AppCoreRotation::IEventListener {
  public:
   Impl(AppCoreUiBase* parent, unsigned int hint)
       : parent_(parent),
@@ -122,6 +123,9 @@ class AppCoreUiBase::Impl {
   Ecore_Wl2_Window* GetWindow() const;
   void Run(int argc, char** argv);
   void Exit();
+  void RotationInit();
+  void RotationShutdown();
+  void OnRotationChanged(int degree) override;
 
   std::list<std::shared_ptr<WinNode>> winnode_list_;
   unsigned int hint_;
@@ -142,6 +146,7 @@ class AppCoreUiBase::Impl {
   Ecore_Wl2_Window* window_ = nullptr;
   std::unique_ptr<WindowPositionManager> wp_manager_;
   std::unique_ptr<AppCoreUiThreadBase> thread_;
+  std::unique_ptr<AppCoreRotation> rotation_;
 };
 
 AppCoreUiBase::AppCoreUiBase(unsigned int hint)
@@ -544,6 +549,22 @@ void AppCoreUiBase::Impl::Exit() {
   parent_->DoExit();
 }
 
+void AppCoreUiBase::Impl::RotationInit() {
+  if (!rotation_) rotation_.reset(new AppCoreRotation(this));
+
+  rotation_->Init();
+}
+
+void AppCoreUiBase::Impl::RotationShutdown() {
+  if (rotation_) rotation_->Dispose();
+}
+
+void AppCoreUiBase::Impl::OnRotationChanged(int degree) {
+  AppCoreBase::SetRotationState(
+      static_cast<AppCoreBase::RotationState>(degree));
+  parent_->RaiseEvent(degree, IEvent::Type::DEVICE_ORIENTATION_CHANGED);
+}
+
 void AppCoreUiBase::Run(int argc, char** argv) {
   impl_->Run(argc, argv);
 }
@@ -980,4 +1001,22 @@ int AppCoreUiBase::GetWindowPosition(int* x, int* y, int* w, int* h) {
   return 0;
 }
 
+int AppCoreUiBase::OnSetEvent(IEvent::Type event) {
+  AppCoreBase::OnSetEvent(event);
+
+  if (event == IEvent::Type::DEVICE_ORIENTATION_CHANGED)
+    impl_->RotationInit();
+
+  return 0;
+}
+
+int AppCoreUiBase::OnUnsetEvent(IEvent::Type event) {
+  AppCoreBase::OnUnsetEvent(event);
+
+  if (event == IEvent::Type::DEVICE_ORIENTATION_CHANGED)
+    impl_->RotationShutdown();
+
+  return 0;
+}
+
 }  // namespace tizen_cpp