2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <dali/public-api/object/handle.h>
18 #include <dali/devel-api/scripting/scripting.h>
19 #include <dali-toolkit/public-api/controls/control.h>
20 #include <dali-toolkit/devel-api/controls/control-devel.h>
21 #include <dali-toolkit/internal/builder/style.h>
31 extern const Dali::Scripting::StringEnum ControlStateTable[];
32 extern const unsigned int ControlStateTableCount;
36 StylePtr stylePtr( new Style() );
40 void Style::ApplyVisualsAndPropertiesRecursively( Handle handle ) const
42 ApplyVisuals( handle );
43 ApplyProperties( handle );
45 Toolkit::Control control = Toolkit::Control::DownCast(handle);
48 std::string stateName;
49 Property::Value value = control.GetProperty(DevelControl::Property::STATE);
50 Dali::Toolkit::DevelControl::State state = static_cast<Dali::Toolkit::DevelControl::State>(value.Get<int>());
51 stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( state, ControlStateTable, ControlStateTableCount );
53 if( ! stateName.empty() )
55 // Look up state in states table:
56 const StylePtr* stylePtr = subStates.FindConst( stateName );
59 const StylePtr statePtr(*stylePtr);
61 // We have a state match.
62 statePtr->ApplyVisuals( handle );
63 statePtr->ApplyProperties( handle );
65 // Apply substate visuals
66 Property::Value value = control.GetProperty(DevelControl::Property::SUB_STATE);
67 std::string subStateName;
68 if( value.Get( subStateName ) && ! subStateName.empty() )
70 const StylePtr* stylePtr = statePtr->subStates.FindConst( subStateName );
73 const StylePtr subStatePtr(*stylePtr);
74 // We have a sub-state match.
75 subStatePtr->ApplyVisuals( handle );
76 subStatePtr->ApplyProperties( handle );
84 void Style::ApplyVisuals( Handle handle ) const
86 for( Dictionary<Property::Map>::iterator iter = visuals.Begin(); iter != visuals.End() ; ++iter )
88 const std::string& visualName = (*iter).key;
89 const Property::Map& map = (*iter).entry;
90 Dali::Property::Index index = handle.GetPropertyIndex( visualName );
91 if( index != Property::INVALID_INDEX )
93 const Property::Value value(const_cast<Property::Map&>(map));
94 handle.SetProperty( index, value );
99 void Style::ApplyProperties( Handle handle ) const
101 for( Property::Map::SizeType i=0; i<properties.Count(); ++i )
103 KeyValuePair keyValue = properties.GetKeyValue( i );
104 if( keyValue.first.type == Property::Key::INDEX )
106 handle.SetProperty( keyValue.first.indexKey, keyValue.second );