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