Update common test util
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-orientation.cpp
index 62598d3..b1b5660 100644 (file)
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://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 "toolkit-orientation.h"
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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 <dali/devel-api/adaptor-framework/orientation.h>
 
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/object/base-object.h>
-#include <dali/public-api/signals/dali-signal-v2.h>
+#include <dali/public-api/signals/dali-signal.h>
 
-namespace Dali
-{
+using namespace Dali;
 
-namespace
+namespace Dali
 {
-ToolkitOrientation* gToolkitOrientation(NULL);
-} // unnamed namespace
+class Adaptor;
 
 namespace Internal
 {
-
 namespace Adaptor
 {
+class Window;
+
+
+struct RotationEvent
+{
+  int angle;     ///< one of 0, 90, 180, 270
+  int winResize; ///< true if the window should be resized
+  int width;     ///< new window width
+  int height;    ///< new window height
+};
 
 /**
- * Stub for the Orientation
+ * The RotationObserver can be overridden in order to listen to rotation events.
  */
-class Orientation : public BaseObject
+class RotationObserver
 {
-public: // Creation & Destruction
+public:
+  virtual void OnRotationPrepare( const RotationEvent& rotation ) = 0;
+  virtual void OnRotationRequest( ) = 0;
 
-  Orientation();
-  Orientation(ToolkitOrientation *orientation);
-  ~Orientation();
+protected:
+  RotationObserver(){}
+  virtual ~RotationObserver(){}
+};
 
-public: // Setters & Getters
+class Orientation : public BaseObject, public RotationObserver
+{
+public:
+  typedef Dali::Orientation::OrientationSignalType OrientationSignalType;
 
-  void SetDegrees( int degrees )
+  static Orientation* New(Window* window)
+  {
+    Orientation* orientation = new Orientation(window);
+    return orientation;
+  }
+  Orientation(Window* window)
   {
-    mOrientation = degrees;
   }
 
-  int GetDegrees() const;
-  float GetRadians() const;
-
-public: // Signals
-
-  Dali::Orientation::OrientationSignalV2& ChangedSignal();
-
-  void EmitChangedSignal()
+protected:
+  virtual ~Orientation()
+  {
+  }
+public:
+  void SetAdaptor(Dali::Adaptor& adaptor)
+  {
+  }
+  int GetDegrees() const
+  {
+    return 0;
+  }
+  float GetRadians() const
   {
-    mChangedSignal.Emit(Dali::Orientation(this));
+    return 0.0f;
   }
+  OrientationSignalType& ChangedSignal()
+  {
+    return mChangedSignal;
+  }
+  virtual void OnRotationPrepare( const RotationEvent& rotation )
+  {
+  };
+  virtual void OnRotationRequest( )
+  {
+  };
 
 private:
-
-  Dali::Orientation::OrientationSignalV2 mChangedSignal;
-
-  ToolkitOrientation* mToolkitOrientation;
-
-  int mOrientation;
+  Orientation(const Orientation&);
+  Orientation& operator=(Orientation&);
+  OrientationSignalType mChangedSignal;
 };
 
-Orientation::Orientation()
-: mToolkitOrientation(NULL),
-  mOrientation(0)
-{
-}
+} // Adaptor namespace
+} // Internal namespace
 
-Orientation::Orientation(ToolkitOrientation *orientation)
-: mToolkitOrientation(orientation),
-  mOrientation(0)
+inline Internal::Adaptor::Orientation& GetImplementation (Dali::Orientation& orientation)
 {
+  DALI_ASSERT_ALWAYS(orientation && "Orientation handle is empty");
+  BaseObject& handle = orientation.GetBaseObject();
+  return static_cast<Internal::Adaptor::Orientation&>(handle);
 }
-
-Orientation::~Orientation()
+inline const Internal::Adaptor::Orientation& GetImplementation(const Dali::Orientation& orientation)
 {
+  DALI_ASSERT_ALWAYS(orientation && "Orientation handle is empty");
+  const BaseObject& handle = orientation.GetBaseObject();
+  return static_cast<const Internal::Adaptor::Orientation&>(handle);
 }
 
-int Orientation::GetDegrees() const
+Orientation::Orientation()
 {
-  mToolkitOrientation->mFunctionsCalled.GetDegrees = true;
-  return mOrientation;
 }
-
-float Orientation::GetRadians() const
+Orientation::~Orientation()
 {
-  mToolkitOrientation->mFunctionsCalled.GetRadians = true;
-  return Math::PI * (float)mOrientation / 180.0f;
 }
-
-Dali::Orientation::OrientationSignalV2& Orientation::ChangedSignal()
+Orientation::Orientation(const Orientation& handle)
+: BaseHandle(handle)
 {
-  mToolkitOrientation->mFunctionsCalled.ChangedSignal = true;
-  return mChangedSignal;
 }
 
-} // namespace Adaptor
-
-} // namespace Internal
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-ToolkitOrientation::ToolkitOrientation()
-: mOrientationStub(new Internal::Adaptor::Orientation(this)),
-  mOrientation( mOrientationStub )
+Orientation& Orientation::operator=(const Orientation& rhs)
 {
-  gToolkitOrientation = this;
+  BaseHandle::operator=(rhs);
+  return *this;
 }
 
-ToolkitOrientation::~ToolkitOrientation()
+int Orientation::GetDegrees() const
 {
-  gToolkitOrientation = NULL;
+  return GetImplementation(*this).GetDegrees();
 }
 
-Orientation ToolkitOrientation::GetHandle()
+float Orientation::GetRadians() const
 {
-  return mOrientation;
+  return GetImplementation(*this).GetRadians();
 }
 
-void ToolkitOrientation::SetDegrees( int degrees )
+Orientation::OrientationSignalType& Orientation::ChangedSignal()
 {
-  mOrientationStub->SetDegrees( degrees );
+  return GetImplementation(*this).ChangedSignal();
 }
 
-void ToolkitOrientation::EmitChangedSignal()
+Orientation::Orientation( Internal::Adaptor::Orientation* orientation )
+: BaseHandle(orientation)
 {
-  mOrientationStub->EmitChangedSignal();
 }
 
-} // namespace Dali
+} // Dali