Provided color-conversion helpers
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / style.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
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>
21
22 namespace Dali
23 {
24 namespace Toolkit
25 {
26 namespace Internal
27 {
28
29 StylePtr Style::New()
30 {
31   StylePtr stylePtr( new Style() );
32   return stylePtr;
33 }
34
35 void Style::ApplyVisualsAndPropertiesRecursively( Handle handle ) const
36 {
37   ApplyVisuals( handle );
38   ApplyProperties( handle );
39
40   Toolkit::Control control = Toolkit::Control::DownCast(handle);
41   if( control )
42   {
43     Property::Value value = control.GetProperty(DevelControl::Property::STATE);
44     std::string stateName;
45     if( value.Get( stateName ) )
46     {
47       // Look up state in states table:
48       const StylePtr* stylePtr = subStates.FindCaseInsensitiveC( stateName );
49       if( stylePtr )
50       {
51         const StylePtr statePtr(*stylePtr);
52
53         // We have a state match.
54         statePtr->ApplyVisuals( handle );
55         statePtr->ApplyProperties( handle );
56
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() )
61         {
62           const StylePtr* stylePtr = statePtr->subStates.FindCaseInsensitiveC( subStateName );
63           if( stylePtr )
64           {
65             const StylePtr subStatePtr(*stylePtr);
66             // We have a sub-state match.
67             subStatePtr->ApplyVisuals( handle );
68             subStatePtr->ApplyProperties( handle );
69           }
70         }
71       }
72     }
73   }
74 }
75
76 void Style::ApplyVisuals( Handle handle ) const
77 {
78   for( Dictionary<Property::Map>::iterator iter = visuals.Begin(); iter != visuals.End() ; ++iter )
79   {
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 )
84     {
85       const Property::Value value(const_cast<Property::Map&>(map));
86       handle.SetProperty( index, value );
87     }
88   }
89 }
90
91 void Style::ApplyProperties( Handle handle ) const
92 {
93   for( Property::Map::SizeType i=0; i<properties.Count(); ++i )
94   {
95     KeyValuePair keyValue = properties.GetKeyValue( i );
96     if( keyValue.first.type == Property::Key::INDEX )
97     {
98       handle.SetProperty( keyValue.first.indexKey, keyValue.second );
99     }
100   }
101 }
102
103 Style::Style()
104 {
105 }
106
107 Style::~Style()
108 {
109 }
110
111
112 } // Internal
113 } // Toolkit
114 } // Dali