DALi Version 2.1.5
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / style.h
1 #ifndef DALI_TOOLKIT_INTERNAL_BUILDER_STYLE_H
2 #define DALI_TOOLKIT_INTERNAL_BUILDER_STYLE_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
21 #include <dali-toolkit/internal/builder/dictionary.h>
22 #include <dali/public-api/object/ref-object.h>
23
24 namespace Dali
25 {
26 namespace Toolkit
27 {
28 namespace Internal
29 {
30 class Style;
31 typedef IntrusivePtr<Style> StylePtr;
32
33 /**
34  * This class encapsulates the style information for a given styled
35  * control.  It is generated only when a control instance looks up
36  * it's style information for the first time, and then stored by
37  * Builder.
38  *
39  * It contains the visual, property and transition definitions for the
40  * main control and for each state and sub-state within the control.
41  *
42  * It has methods to enable the base control to apply visuals and
43  * properties per state.
44  */
45 class Style : public RefObject
46 {
47 public:
48   static StylePtr New();
49
50 public:
51   /**
52    * Apply the visuals and properties for the current state/substate
53    * of the handle to the control pointed at by handle. Recurses
54    * through sub-states.
55    *
56    * @param[in] handle The handle to apply the visuals to
57    * @param[in] instancedProperties The maps from which to get instanced properties
58    */
59   void ApplyVisualsAndPropertiesRecursively(Handle                           handle,
60                                             const Dictionary<Property::Map>& instancedProperties) const;
61
62   /**
63    * Apply the visuals of the style to the control pointed at by
64    * handle.
65    *
66    * @param[in] handle The handle to apply the visuals to
67    * @param[in] instancedProperties The maps from which to get instanced properties
68    */
69   void ApplyVisuals(Handle                           handle,
70                     const Dictionary<Property::Map>& instancedProperties) const;
71
72   /**
73    * Apply the properties from the visualMaps and the instancedProperties
74    * to the control pointed at by handle.
75    *
76    * @param[in] handle The handle to apply the properties to
77    * @param[in] visualMaps The visual maps from which to get the styled properties
78    * @param[in] instancedProperties The maps from which to get instanced properties
79    */
80   static void ApplyVisuals(Handle                           handle,
81                            const Dictionary<Property::Map>& visualMaps,
82                            const Dictionary<Property::Map>& instancedProperties);
83
84   /**
85    * Apply the properties from the visualMap and optional instancedProperties
86    * to the control pointed at by handle.
87    */
88   static void ApplyVisual(Handle               handle,
89                           const std::string&   visualName,
90                           const Property::Map& visualMap,
91                           const Property::Map* instancedProperties);
92
93   /**
94    * Apply the properties of the style to the control pointed at by
95    * handle.
96    *
97    * @param[in] handle The handle to apply the properties to
98    */
99   void ApplyProperties(Handle handle) const;
100
101 protected:
102   /**
103    * @brief Default constructor.
104    */
105   Style();
106
107   /**
108    * @brief virtual destructor.
109    */
110   ~Style() override;
111
112 private:
113   // Not implemented
114   DALI_INTERNAL Style(const Style& rhs);
115
116   // Not implemented
117   DALI_INTERNAL Style& operator=(const Style& rhs);
118
119 public:
120   // Everything must be shallow-copiable.
121   Dictionary<StylePtr>      subStates; // Each named style maps to a state.
122   Dictionary<Property::Map> visuals;
123   Property::Map             properties;
124   Property::Array           transitions;
125   Toolkit::TransitionData   entryTransition;
126   Toolkit::TransitionData   exitTransition;
127 };
128
129 } // namespace Internal
130 } // namespace Toolkit
131 } // namespace Dali
132
133 #endif //DALI_TOOLKIT_INTERNAL_BUILDER_STYLE_H