New size negotiation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / navigation-frame / navigation-control-impl.cpp
index 37ca96a..91fb19f 100644 (file)
@@ -1,26 +1,34 @@
-//
-// 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.
-//
+/*
+ * 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.
+ *
+ */
 
 // CLASS HEADER
 #include "navigation-control-impl.h"
 
-//INTERNAL INCLUDES
+// EXTERNAL INCLUDES
+#include <dali/public-api/animation/animation.h>
+#include <dali/public-api/events/key-event.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/size-negotiation/relayout-container.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/focus-manager/focus-manager.h>
 #include <dali-toolkit/internal/controls/navigation-frame/navigation-tool-bar.h>
 #include <dali-toolkit/internal/controls/navigation-frame/navigation-title-bar.h>
-#include <dali-toolkit/internal/controls/relayout-controller.h>
 #include <dali-toolkit/public-api/focus-manager/focus-manager.h>
 
 namespace Dali
@@ -34,19 +42,24 @@ namespace Internal
 
 namespace // to register type
 {
+
 BaseHandle Create()
 {
   return Toolkit::NavigationControl::New();
 }
 
-TypeRegistration mType( typeid(Toolkit::NavigationControl), typeid(Toolkit::Control), Create );
+// Setup properties, signals and actions using the type-registry.
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::NavigationControl, Toolkit::Control, Create )
+
+DALI_ACTION_REGISTRATION( NavigationControl, "push", ACTION_PUSH )
+DALI_ACTION_REGISTRATION( NavigationControl, "pop",  ACTION_POP  )
+
+DALI_TYPE_REGISTRATION_END()
 
-TypeAction a1(mType, Toolkit::NavigationControl::ACTION_PUSH, &NavigationControl::DoAction);
-TypeAction a2(mType, Toolkit::NavigationControl::ACTION_POP, &NavigationControl::DoAction);
 }
 
 NavigationControl::NavigationControl()
-: ControlImpl( true ),
+: Control( REQUIRES_TOUCH_EVENTS ),
   mToolBar(NULL),
   mTitleBar(NULL),
   mOrientationAngle( 0 ),
@@ -252,7 +265,6 @@ void NavigationControl::OrientationChanged( int angle )
     }
 
     Animation animation = Animation::New( mOrientationAnimationDuration );
-    animation.SetDestroyAction( Animation::Bake );
     animation.RotateTo( Self(), Degree( -angle ), Vector3::ZAXIS, mOrientationAnimationAlphaFunc );
     animation.Play();
 
@@ -273,7 +285,7 @@ Layer NavigationControl::GetBarLayer() const
   return mBarLayer;
 }
 
-void NavigationControl::OnRelaidOut( Vector2 size, ActorSizeContainer& container )
+void NavigationControl::OnRelayout( const Vector2& size, RelayoutContainer& container )
 {
   const Vector2 setSize( size );
 
@@ -296,11 +308,11 @@ void NavigationControl::OnRelaidOut( Vector2 size, ActorSizeContainer& container
     mCurrentItem.SetPosition( mItemPositionCoefficient * positionOffset);
     Vector2 itemSize( setSize.x, setSize.y-sizeShrink );
 
-    Relayout(mCurrentItem, itemSize, container);
+    container.Add( mCurrentItem, itemSize );
   }
 
-  container.push_back(ActorSizePair( mBarLayer, setSize ));
-  container.push_back(ActorSizePair( mPopupLayer, setSize ));
+  container.Add( mBarLayer, setSize );
+  container.Add( mPopupLayer, setSize );
 }
 
 void NavigationControl::OnControlSizeSet( const Vector3& size )
@@ -398,48 +410,48 @@ void NavigationControl::OnPopupTouchedOutside()
   }
 }
 
-Toolkit::NavigationControl::ItemPushedSignalV2& NavigationControl::ItemPushedSignal()
+Toolkit::NavigationControl::ItemPushedSignalType& NavigationControl::ItemPushedSignal()
 {
   return mItemPushedSignal;
 }
 
-Toolkit::NavigationControl::ItemPoppedSignalV2& NavigationControl::ItemPoppedSignal()
+Toolkit::NavigationControl::ItemPoppedSignalType& NavigationControl::ItemPoppedSignal()
 {
   return mItemPoppedSignal;
 }
 
-bool NavigationControl::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
+bool NavigationControl::DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes )
 {
   bool ret = false;
 
-  Dali::BaseHandle handle(object);
-  Toolkit::NavigationControl control = Toolkit::NavigationControl::DownCast(handle);
-  DALI_ASSERT_ALWAYS(control);
+  Dali::BaseHandle handle( object );
+  Toolkit::NavigationControl control = Toolkit::NavigationControl::DownCast( handle );
+  DALI_ASSERT_ALWAYS( control );
 
-  if (Toolkit::NavigationControl::ACTION_PUSH == actionName)
+  if( 0 == strcmp( actionName.c_str(), ACTION_PUSH ) )
   {
-    for (PropertyValueConstIter iter = attributes.begin(); iter != attributes.end(); ++iter)
+    for( PropertyValueConstIter iter = attributes.begin(); iter != attributes.end(); ++iter )
     {
       const Property::Value& value = *iter;
 
-      DALI_ASSERT_ALWAYS(value.GetType() == Property::STRING);
-      std::string itemName = value.Get<std::string> ();
+      DALI_ASSERT_ALWAYS( value.GetType() == Property::STRING );
+      std::string itemName = value.Get<std::string>();
 
-      for (std::list<Toolkit::Page>::iterator itemsIter = GetImpl(control).mUnpushedItems.begin(); itemsIter != GetImpl(control).mUnpushedItems.end(); ++itemsIter)
+      for( std::list<Toolkit::Page>::iterator itemsIter = GetImpl( control ).mUnpushedItems.begin(); itemsIter != GetImpl( control ).mUnpushedItems.end(); ++itemsIter )
       {
         Toolkit::Page page = *itemsIter;
-        if (page.GetName() == itemName)
+        if( page.GetName() == itemName )
         {
-          GetImpl(control).PushItem(page);
+          GetImpl( control ).PushItem( page );
           ret = true;
           break;
         }
       }
     }
   }
-  else if(Toolkit::NavigationControl::ACTION_POP == actionName)
+  else if( 0 == strcmp( actionName.c_str(), ACTION_POP ) )
   {
-    GetImpl(control).PopItem();
+    GetImpl( control ).PopItem();
 
     ret = true;
   }