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-toolkit/public-api/controls/control.h>
19 #include <dali-toolkit/devel-api/controls/control-devel.h>
20 #include <dali-toolkit/internal/builder/style.h>
31 StylePtr stylePtr( new Style() );
35 void Style::ApplyVisualsAndPropertiesRecursively( Handle handle ) const
37 ApplyVisuals( handle );
38 ApplyProperties( handle );
40 Toolkit::Control control = Toolkit::Control::DownCast(handle);
43 Property::Value value = control.GetProperty(DevelControl::Property::STATE);
44 std::string stateName;
45 if( value.Get( stateName ) )
47 // Look up state in states table:
48 const StylePtr* stylePtr = subStates.FindCaseInsensitiveC( stateName );
51 const StylePtr statePtr(*stylePtr);
53 // We have a state match.
54 statePtr->ApplyVisuals( handle );
55 statePtr->ApplyProperties( handle );
57 // Apply substate visuals
58 Property::Value value = control.GetProperty(DevelControl::Property::SUB_STATE);
59 std::string subStateName;
60 if( value.Get( subStateName ) && ! subStateName.empty() )
62 const StylePtr* stylePtr = statePtr->subStates.FindCaseInsensitiveC( subStateName );
65 const StylePtr subStatePtr(*stylePtr);
66 // We have a sub-state match.
67 subStatePtr->ApplyVisuals( handle );
68 subStatePtr->ApplyProperties( handle );
76 void Style::ApplyVisuals( Handle handle ) const
78 for( Dictionary<Property::Map>::iterator iter = visuals.Begin(); iter != visuals.End() ; ++iter )
80 const std::string& visualName = (*iter).key;
81 const Property::Map& map = (*iter).entry;
82 Dali::Property::Index index = handle.GetPropertyIndex( visualName );
83 if( index != Property::INVALID_INDEX )
85 const Property::Value value(const_cast<Property::Map&>(map));
86 handle.SetProperty( index, value );
91 void Style::ApplyProperties( Handle handle ) const
93 for( Property::Map::SizeType i=0; i<properties.Count(); ++i )
95 KeyValuePair keyValue = properties.GetKeyValue( i );
96 if( keyValue.first.type == Property::Key::INDEX )
98 handle.SetProperty( keyValue.first.indexKey, keyValue.second );