Support Ecore-Wayland2
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / window-impl.cpp
index 715861e..3c385ef 100644 (file)
 
 // INTERNAL HEADERS
 #include <dali/internal/input/common/drag-and-drop-detector-impl.h>
-#include <dali/internal/window-system/common/ecore-indicator-impl.h>
 #include <dali/internal/window-system/common/window-visibility-observer.h>
 #include <dali/internal/window-system/common/orientation-impl.h>
 #include <dali/internal/window-system/common/render-surface-factory.h>
-#include <dali/internal/window-system/common/window-base-factory.h>
+#include <dali/internal/window-system/common/window-factory.h>
 #include <dali/internal/window-system/common/window-base.h>
 #include <dali/internal/window-system/common/window-render-surface.h>
 
@@ -62,7 +61,7 @@ Window* Window::New( const PositionSize& positionSize, const std::string& name,
 Window::Window()
 : mSurface( NULL ),
   mWindowBase(),
-  mIndicatorVisible( Dali::Window::VISIBLE ),
+  mIndicatorVisible( Dali::Window::INVISIBLE ),   // TODO: Enable this after indicator implementation based on tizen 5.
   mIndicatorIsShown( false ),
   mShowRotatedIndicatorOnClose( false ),
   mStarted( false ),
@@ -72,7 +71,7 @@ Window::Window()
   mIconified( false ),
   mOpaqueState( false ),
   mResizeEnabled( false ),
-  mIndicator( NULL ),
+  mIndicator(),
   mIndicatorOrientation( Dali::Window::PORTRAIT ),
   mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
   mIndicatorOpacityMode( Dali::Window::OPAQUE ),
@@ -96,7 +95,6 @@ Window::~Window()
     Dali::RenderTask indicatorTask = taskList.GetTask(0);
     mOverlay->GetOverlayRenderTasks().RemoveTask(indicatorTask);
     mIndicator->Close();
-    delete mIndicator;
   }
 
   if ( mAdaptor )
@@ -111,17 +109,21 @@ Window::~Window()
 
 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
 {
-  // create a window render surface
+  // Create a window render surface
   Any surface;
   auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
-  auto windowRenderSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, name, className, mIsTransparent );
+  auto windowRenderSurface = renderSurfaceFactory->CreateWindowRenderSurface( positionSize, surface, mIsTransparent );
   mSurface = windowRenderSurface.release();
 
-  // create a window base
-  auto windowBaseFactory = Dali::Internal::Adaptor::GetWindowBaseFactory();
-  mWindowBase = windowBaseFactory->CreateWindowBase( this, mSurface );
+  // Get a window base
+  mWindowBase = mSurface->GetWindowBase();
 
-  mWindowBase->Initialize();
+  // Connect signals
+  mWindowBase->IconifyChangedSignal().Connect( this, &Window::OnIconifyChanged );
+  mWindowBase->FocusChangedSignal().Connect( this, &Window::OnFocusChanged );
+  mWindowBase->OutputTransformedSignal().Connect( this, &Window::OnOutputTransformed );
+  mWindowBase->DeleteRequestSignal().Connect( this, &Window::OnDeleteRequest );
+  mWindowBase->IndicatorFlickedSignal().Connect( this, &Window::OnIndicatorFlicked );
 
   if( !positionSize.IsEmpty() )
   {
@@ -174,7 +176,8 @@ WindowRenderSurface* Window::GetSurface()
 
 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
 {
-  mIndicatorVisible = visibleMode;
+  // TODO: Enable this after indicator implementation based on tizen 5.
+//  mIndicatorVisible = visibleMode;
 
   mWindowBase->ShowIndicator( mIndicatorVisible, mIndicatorOpacityMode );
 
@@ -193,7 +196,8 @@ void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode
 
 void Window::SetIndicatorVisibleMode( Dali::Window::IndicatorVisibleMode mode )
 {
-  mIndicatorVisible = mode;
+  // TODO: Enable this after indicator implementation based on tizen 5.
+//  mIndicatorVisible = mode;
 }
 
 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
@@ -297,7 +301,7 @@ Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
 
 Dali::Any Window::GetNativeHandle() const
 {
-  return mSurface->GetWindow();
+  return mSurface->GetNativeWindow();
 }
 
 void Window::SetAcceptFocus( bool accept )
@@ -560,60 +564,21 @@ void Window::RotationDone( int orientation, int width, int height )
   mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( width, height ) );
 }
 
-void Window::OnIconifyChanged( bool iconified )
-{
-  if( iconified )
-  {
-    mIconified = true;
-
-    if( mVisible )
-    {
-      WindowVisibilityObserver* observer( mAdaptor );
-      observer->OnWindowHidden();
-      DALI_LOG_RELEASE_INFO( "Window (%p) Iconified\n", this );
-    }
-  }
-  else
-  {
-    mIconified = false;
-
-    if( mVisible )
-    {
-      WindowVisibilityObserver* observer( mAdaptor );
-      observer->OnWindowShown();
-      DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified\n", this );
-    }
-  }
-}
-
-void Window::OnFocusChanged( bool focusIn )
-{
-  mFocusChangedSignal.Emit( focusIn );
-}
-
-void Window::OnOutputTransformed()
-{
-  PositionSize positionSize = mSurface->GetPositionSize();
-  mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
-  mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
-}
-
-void Window::OnDeleteRequest()
-{
-  mDeleteRequestSignal.Emit();
-}
-
 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
 {
   if( mIndicator == NULL )
   {
     if( mIndicatorVisible != Dali::Window::INVISIBLE )
     {
-      mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
-      mIndicator->SetOpacityMode( mIndicatorOpacityMode );
-      Dali::Actor actor = mIndicator->GetActor();
-      SetIndicatorActorRotation();
-      mOverlay->Add(actor);
+      auto windowFactory = Dali::Internal::Adaptor::GetWindowFactory();
+      mIndicator = windowFactory->CreateIndicator( mAdaptor, mIndicatorOrientation, this );
+      if( mIndicator )
+      {
+        mIndicator->SetOpacityMode( mIndicatorOpacityMode );
+        Dali::Actor actor = mIndicator->GetActor();
+        SetIndicatorActorRotation();
+        mOverlay->Add(actor);
+      }
     }
     // else don't create a hidden indicator
   }
@@ -649,7 +614,10 @@ void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
   {
     mShowRotatedIndicatorOnClose = true;
     mNextIndicatorOrientation = orientation;
-    mIndicator->Close(); // May synchronously call IndicatorClosed() callback
+    if( mIndicator )
+    {
+      mIndicator->Close(); // May synchronously call IndicatorClosed() callback
+    }
   }
   else
   {
@@ -662,31 +630,32 @@ void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
 void Window::SetIndicatorActorRotation()
 {
   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
-  DALI_ASSERT_DEBUG( mIndicator != NULL );
-
-  Dali::Actor actor = mIndicator->GetActor();
-  switch( mIndicatorOrientation )
+  if( mIndicator )
   {
-    case Dali::Window::PORTRAIT:
-      actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
-      actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
-      actor.SetOrientation( Degree(0), Vector3::ZAXIS );
-      break;
-    case Dali::Window::PORTRAIT_INVERSE:
-      actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
-      actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
-      actor.SetOrientation( Degree(180), Vector3::ZAXIS );
-      break;
-    case Dali::Window::LANDSCAPE:
-      actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
-      actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
-      actor.SetOrientation( Degree(270), Vector3::ZAXIS );
-      break;
-    case Dali::Window::LANDSCAPE_INVERSE:
-      actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
-      actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
-      actor.SetOrientation( Degree(90), Vector3::ZAXIS );
-      break;
+    Dali::Actor actor = mIndicator->GetActor();
+    switch( mIndicatorOrientation )
+    {
+      case Dali::Window::PORTRAIT:
+        actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
+        actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
+        actor.SetOrientation( Degree(0), Vector3::ZAXIS );
+        break;
+      case Dali::Window::PORTRAIT_INVERSE:
+        actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+        actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
+        actor.SetOrientation( Degree(180), Vector3::ZAXIS );
+        break;
+      case Dali::Window::LANDSCAPE:
+        actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
+        actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
+        actor.SetOrientation( Degree(270), Vector3::ZAXIS );
+        break;
+      case Dali::Window::LANDSCAPE_INVERSE:
+        actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
+        actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
+        actor.SetOrientation( Degree(90), Vector3::ZAXIS );
+        break;
+    }
   }
 }
 
@@ -695,7 +664,58 @@ void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientatio
   mWindowBase->SetIndicatorProperties( isShow, lastOrientation );
 }
 
-void Window::IndicatorTypeChanged(Indicator::Type type)
+void Window::OnIconifyChanged( bool iconified )
+{
+  if( iconified )
+  {
+    mIconified = true;
+
+    if( mVisible )
+    {
+      WindowVisibilityObserver* observer( mAdaptor );
+      observer->OnWindowHidden();
+      DALI_LOG_RELEASE_INFO( "Window (%p) Iconified\n", this );
+    }
+  }
+  else
+  {
+    mIconified = false;
+
+    if( mVisible )
+    {
+      WindowVisibilityObserver* observer( mAdaptor );
+      observer->OnWindowShown();
+      DALI_LOG_RELEASE_INFO( "Window (%p) Deiconified\n", this );
+    }
+  }
+}
+
+void Window::OnFocusChanged( bool focusIn )
+{
+  mFocusChangedSignal.Emit( focusIn );
+}
+
+void Window::OnOutputTransformed()
+{
+  PositionSize positionSize = mSurface->GetPositionSize();
+  mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
+  mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
+}
+
+void Window::OnDeleteRequest()
+{
+  mDeleteRequestSignal.Emit();
+}
+
+void Window::OnIndicatorFlicked()
+{
+  if( mIndicator )
+  {
+    mIndicator->Flicked();
+  }
+}
+
+void Window::IndicatorTypeChanged( IndicatorInterface::Type type )
 {
   mWindowBase->IndicatorTypeChanged( type );
 }
@@ -707,7 +727,10 @@ void Window::IndicatorClosed( IndicatorInterface* indicator )
   if( mShowRotatedIndicatorOnClose )
   {
     Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
-    mIndicator->Open( mNextIndicatorOrientation );
+    if( mIndicator )
+    {
+      mIndicator->Open( mNextIndicatorOrientation );
+    }
     mIndicatorOrientation = mNextIndicatorOrientation;
     SetIndicatorActorRotation();
     DoShowIndicator( currentOrientation );
@@ -746,8 +769,7 @@ void Window::OnStop()
     mIndicator->Close();
   }
 
-  delete mIndicator;
-  mIndicator = NULL;
+  mIndicator.release();
 }
 
 void Window::OnDestroy()