DALi Version 2.1.5
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / style.cpp
index 988bd61..b834b13 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  * limitations under the License.
  */
 
-#include <dali/public-api/object/handle.h>
-#include <dali/devel-api/scripting/scripting.h>
-#include <dali-toolkit/public-api/controls/control.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
-#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/internal/builder/style.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/public-api/controls/control.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali/devel-api/scripting/scripting.h>
+#include <dali/public-api/object/handle.h>
 
 namespace Dali
 {
 namespace Toolkit
 {
-
 namespace Internal
 {
-
 extern const Dali::Scripting::StringEnum ControlStateTable[];
-extern const unsigned int ControlStateTableCount;
+extern const unsigned int                ControlStateTableCount;
 
 StylePtr Style::New()
 {
-  StylePtr stylePtr( new Style() );
+  StylePtr stylePtr(new Style());
   return stylePtr;
 }
 
 void Style::ApplyVisualsAndPropertiesRecursively(
-  Handle handle,
-  const Dictionary<Property::Map>& instancedProperties ) const
+  Handle                           handle,
+  const Dictionary<Property::Map>& instancedProperties) const
 {
-  ApplyVisuals( handle, instancedProperties );
-  ApplyProperties( handle );
+  ApplyVisuals(handle, instancedProperties);
+  ApplyProperties(handle);
 
   Toolkit::Control control = Toolkit::Control::DownCast(handle);
-  if( control )
+  if(control)
   {
-    std::string stateName;
-    Property::Value value = control.GetProperty(DevelControl::Property::STATE);
+    std::string                        stateName;
+    Property::Value                    value = control.GetProperty(DevelControl::Property::STATE);
     Dali::Toolkit::DevelControl::State state = static_cast<Dali::Toolkit::DevelControl::State>(value.Get<int>());
-    stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( state, ControlStateTable, ControlStateTableCount );
+    stateName                                = Scripting::GetEnumerationName<Toolkit::DevelControl::State>(state, ControlStateTable, ControlStateTableCount);
 
-    if( ! stateName.empty() )
+    if(!stateName.empty())
     {
       // Look up state in states table:
-      const StylePtr* stylePtr = subStates.FindConst( stateName );
-      if( stylePtr )
+      const StylePtr* stylePtr = subStates.FindConst(stateName);
+      if(stylePtr)
       {
         const StylePtr statePtr(*stylePtr);
 
         // We have a state match.
-        statePtr->ApplyVisuals( handle, instancedProperties );
-        statePtr->ApplyProperties( handle );
+        statePtr->ApplyVisuals(handle, instancedProperties);
+        statePtr->ApplyProperties(handle);
 
         // Apply substate visuals
         Property::Value value = control.GetProperty(DevelControl::Property::SUB_STATE);
-        std::string subStateName;
-        if( value.Get( subStateName ) && ! subStateName.empty() )
+        std::string     subStateName;
+        if(value.Get(subStateName) && !subStateName.empty())
         {
-          const StylePtr* stylePtr = statePtr->subStates.FindConst( subStateName );
-          if( stylePtr )
+          const StylePtr* stylePtr = statePtr->subStates.FindConst(subStateName);
+          if(stylePtr)
           {
             const StylePtr subStatePtr(*stylePtr);
             // We have a sub-state match.
-            subStatePtr->ApplyVisuals( handle, instancedProperties );
-            subStatePtr->ApplyProperties( handle );
+            subStatePtr->ApplyVisuals(handle, instancedProperties);
+            subStatePtr->ApplyProperties(handle);
           }
         }
       }
@@ -86,57 +84,57 @@ void Style::ApplyVisualsAndPropertiesRecursively(
 }
 
 void Style::ApplyVisuals(
-  Handle handle,
-  const Dictionary<Property::Map>& instancedProperties ) const
+  Handle                           handle,
+  const Dictionary<Property::Map>& instancedProperties) const
 {
-  ApplyVisuals( handle, visuals, instancedProperties );
+  ApplyVisuals(handle, visuals, instancedProperties);
 }
 
 void Style::ApplyVisuals(
-  Handle handle,
+  Handle                           handle,
   const Dictionary<Property::Map>& visualMaps,
-  const Dictionary<Property::Map>& instancedProperties )
+  const Dictionary<Property::Map>& instancedProperties)
 {
-  for( Dictionary<Property::Map>::iterator iter = visualMaps.Begin(); iter != visualMaps.End() ; ++iter )
+  for(Dictionary<Property::Map>::iterator iter = visualMaps.Begin(); iter != visualMaps.End(); ++iter)
   {
-    const std::string& visualName = (*iter).key;
-    Property::Map map = (*iter).entry;
-    Property::Map* instancedMap = instancedProperties.Find( visualName );
-    ApplyVisual( handle, visualName, map, instancedMap );
+    const std::string& visualName   = (*iter).key;
+    Property::Map      map          = (*iter).entry;
+    Property::Map*     instancedMap = instancedProperties.Find(visualName);
+    ApplyVisual(handle, visualName, map, instancedMap);
   }
 }
 
 void Style::ApplyVisual(
-  Handle handle,
-  const std::string& visualName,
+  Handle               handle,
+  const std::string&   visualName,
   const Property::Map& visualMap,
-  const Property::Map* instancedProperties )
+  const Property::Map* instancedProperties)
 {
   // Check if this visual name is a valid property of handle
-  Dali::Property::Index index = handle.GetPropertyIndex( visualName );
-  if( index != Property::INVALID_INDEX )
+  Dali::Property::Index index = handle.GetPropertyIndex(visualName);
+  if(index != Property::INVALID_INDEX)
   {
     const Property::Map* applyMap = &visualMap;
-    Property::Map mergedMap;
+    Property::Map        mergedMap;
 
     // If there are instanced properties, and the visual types match,
     // merge them into the visual map
-    if( instancedProperties )
+    if(instancedProperties)
     {
-      Property::Value* instanceTypeValue = instancedProperties->Find( Toolkit::DevelVisual::Property::TYPE);
-      Property::Value* newTypeValue = visualMap.Find( Toolkit::DevelVisual::Property::TYPE, VISUAL_TYPE );
-      if( instanceTypeValue && newTypeValue )
+      Property::Value* instanceTypeValue = instancedProperties->Find(Toolkit::Visual::Property::TYPE);
+      Property::Value* newTypeValue      = visualMap.Find(Toolkit::Visual::Property::TYPE, VISUAL_TYPE);
+      if(instanceTypeValue && newTypeValue)
       {
-        int instanceVisualType=-1;
-        int newVisualType=-1;
-        Scripting::GetEnumerationProperty( *instanceTypeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, instanceVisualType );
-        Scripting::GetEnumerationProperty( *newTypeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, newVisualType );
+        int instanceVisualType = -1;
+        int newVisualType      = -1;
+        Scripting::GetEnumerationProperty(*instanceTypeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, instanceVisualType);
+        Scripting::GetEnumerationProperty(*newTypeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, newVisualType);
 
-        if( instanceVisualType == newVisualType )
+        if(instanceVisualType == newVisualType)
         {
           // Same type - merge remaining instance data
-          mergedMap.Merge( visualMap );
-          mergedMap.Merge( *instancedProperties );
+          mergedMap.Merge(visualMap);
+          mergedMap.Merge(*instancedProperties);
           applyMap = &mergedMap;
         }
       }
@@ -144,18 +142,18 @@ void Style::ApplyVisual(
 
     // Apply the visual property map to the handle
     const Property::Value value(const_cast<Property::Map&>(*applyMap));
-    handle.SetProperty( index, value );
+    handle.SetProperty(index, value);
   }
 }
 
-void Style::ApplyProperties( Handle handle ) const
+void Style::ApplyProperties(Handle handle) const
 {
-  for( Property::Map::SizeType i=0; i<properties.Count(); ++i )
+  for(Property::Map::SizeType i = 0; i < properties.Count(); ++i)
   {
-    KeyValuePair keyValue = properties.GetKeyValue( i );
-    if( keyValue.first.type == Property::Key::INDEX )
+    KeyValuePair keyValue = properties.GetKeyValue(i);
+    if(keyValue.first.type == Property::Key::INDEX)
     {
-      handle.SetProperty( keyValue.first.indexKey, keyValue.second );
+      handle.SetProperty(keyValue.first.indexKey, keyValue.second);
     }
   }
 }
@@ -167,7 +165,6 @@ Style::~Style()
 {
 }
 
-
-} // Internal
-} // Toolkit
-} // Dali
+} // namespace Internal
+} // namespace Toolkit
+} // namespace Dali