Merge "Change the double tap and long press events on top of no text actions to highl...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / button-impl.cpp
index 0c7005b..79ac7db 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -39,6 +39,7 @@
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/visuals/text/text-visual.h>
 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 
@@ -348,11 +349,7 @@ bool Button::IsSelected() const
 
 void Button::SetLabelText( const std::string& label )
 {
-  Property::Map labelProperty;
-  labelProperty.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT)
-               .Add( Toolkit::TextVisual::Property::TEXT, label );
-
-  Self().SetProperty( Toolkit::Button::Property::LABEL, labelProperty );
+  Self().SetProperty( Toolkit::Button::Property::LABEL, label );
 }
 
 std::string Button::GetLabelText() const
@@ -372,7 +369,7 @@ std::string Button::GetLabelText() const
   return textLabel;
 }
 
-void Button::MergeLabelProperties( const Property::Map& inMap, Property::Map& outMap )
+void Button::MergeWithExistingLabelProperties( const Property::Map& inMap, Property::Map& outMap )
 {
   DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "MergeLabelProperties with %d properties\n", inMap.Count() );
 
@@ -983,7 +980,7 @@ void Button::OnRelayout( const Vector2& size, RelayoutContainer& container )
     Property::Map visualTransform;
 
     visualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, size )
-                   .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 0.0f, 0.0f, 1.0f, 1.0f) );  // Use relative size
+                   .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) );
 
     currentBackGroundVisual.SetTransformAndSize( visualTransform, size );
   }
@@ -996,7 +993,8 @@ void Button::OnRelayout( const Vector2& size, RelayoutContainer& container )
 
     visualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, visualSize )
                    .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, visualPosition )
-                   .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 1.0f, 1.0f, 1.0f, 1.0f) )  // Use absolute size
+                   .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) )
+                   .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) )
                    .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
                    .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, visualAnchorPoint );
 
@@ -1026,7 +1024,8 @@ void Button::OnRelayout( const Vector2& size, RelayoutContainer& container )
       Property::Map textVisualTransform;
       textVisualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, preSize )
                          .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, labelPosition )
-                         .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 1.0f, 1.0f, 1.0f,1.0f ) ) // Use absolute size
+                         .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) )
+                         .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) )
                          .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
                          .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, visualAnchorPoint );
 
@@ -1224,13 +1223,33 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope
 
       case Toolkit::Button::Property::LABEL:
       {
-        // Get a Property::Map from the property if possible.
-        Property::Map* setPropertyMap = value.GetMap();
-        if( setPropertyMap )
+        Property::Map outTextVisualProperties;
+        std::string textString;
+
+        if ( value.Get( textString ) )
+        {
+          DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty Setting TextVisual with string[%s]\n", textString.c_str() );
+
+          Property::Map setPropertyMap;
+          setPropertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
+                        .Add( Toolkit::TextVisual::Property::TEXT, textString );
+
+          GetImplementation( button ).MergeWithExistingLabelProperties( setPropertyMap, outTextVisualProperties );
+        }
+        else
+        {
+          // Get a Property::Map from the property if possible.
+          Property::Map* setPropertyMap = value.GetMap();
+          if( setPropertyMap )
+          {
+            TextVisual::ConvertStringKeysToIndexKeys( *setPropertyMap );
+            GetImplementation( button ).MergeWithExistingLabelProperties( *setPropertyMap, outTextVisualProperties );
+          }
+        }
+
+        if( !outTextVisualProperties.Empty() )
         {
-          Property::Map textVisualProperties;
-          GetImplementation( button ).MergeLabelProperties( *setPropertyMap, textVisualProperties );
-          GetImplementation( button ).CreateVisualsForComponent( index, textVisualProperties, DepthIndex::CONTENT );
+          GetImplementation( button ).CreateVisualsForComponent( index, outTextVisualProperties, DepthIndex::CONTENT );
           GetImplementation( button ).RelayoutRequest();
         }
         break;