License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / style-change-processor.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_STYLE_CHANGE_PROCESSOR_H_
2 #define __DALI_TOOLKIT_INTERNAL_STYLE_CHANGE_PROCESSOR_H_
3
4 /*
5  * Copyright (c) 2014 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
21 // INTERNAL INCLUDES
22 #include <dali/dali.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 class ControlImpl;
31
32 namespace Internal
33 {
34
35 /**
36  * This observes and processes when any style changes occur.  When they do occur, it traverses through
37  * all registered controls and calls the StyleChanged method.
38  *
39  * This is created when a control first registers with it.  Subsequent registrations increase the
40  * reference count.  When the last control unregisters, i.e. the reference count is 0, the instance
41  * is also destroyed.
42  */
43 class StyleChangeProcessor : public ConnectionTracker
44 {
45 public:
46
47   /**
48    * Non virtual destructor.
49    * We should not derive from StyleChangeProcessor.
50    * Destructor is called when the last control unregisters.
51    */
52   ~StyleChangeProcessor();
53
54   /**
55    * Registers a control with the StyleChangeProcessor.
56    * @param[in] control The raw Control pointer.
57    */
58   static void Register( ControlImpl* control );
59
60   /**
61    * Unregisters a control from the StyleChangeProcessor.
62    * @param[in] control The raw Control pointer.
63    */
64   static void Unregister( ControlImpl* control );
65
66 public:
67
68   /**
69    * Increment the processor's reference count.
70    */
71   void Reference();
72
73   /**
74    * Decrement the processor's reference count.
75    */
76   void Unreference();
77
78   /**
79    * Retrieve the processor's reference count.
80    * @return The reference count
81    */
82   unsigned int ReferenceCount() const;
83
84 private:
85
86   /**
87    * Constructor.
88    * We should only create an instance upon first registration.
89    */
90   StyleChangeProcessor();
91
92   // Undefined
93   StyleChangeProcessor(const StyleChangeProcessor&);
94   StyleChangeProcessor& operator=(const StyleChangeProcessor&);
95
96 private:
97
98   /**
99    * Callback for the StyleMonitor when the style changes on the platform.
100    * @param[in]  styleMonitor  The Style Monitor.
101    * @param[in]  styleChange   The style change information.
102    */
103   void StyleChanged(Dali::StyleMonitor styleMonitor, Dali::StyleChange styleChange);
104
105   /**
106    * Propagates the style change to all Controls in the actor hierarchy.
107    * This is done with a bottom-up approach, i.e. the leaf Control's StyleChange method gets
108    * called first followed by its parent and so on.
109    * @param[in]  actor   The actor whose children to process and send style change notification to.
110    * @param[in]  change  The style change.
111    */
112   static void PropagateStyleChange(Actor actor, Dali::StyleChange change);
113
114 private:
115
116   unsigned int              mCount;        ///< The reference count
117   std::vector<ControlImpl*> mControls;     ///< Stores all registered controls.
118 };
119
120 } // namespace Internal
121
122 } // namespace Toolkit
123
124 } // namespace Dali
125
126 #endif // __DALI_TOOLKIT_INTERNAL_STYLE_CHANGE_PROCESSOR_H_