[3.0] Resource ready signal for Controls (for ImageLoading)
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / control / control-data-impl.h
1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_IMPL_H
3
4 /*
5  * Copyright (c) 2017 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
24 #include <string>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/visuals/visual-resource-observer.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali/devel-api/common/owner-container.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 /**
42   * Struct used to store Visual within the control, index is a unique key for each visual.
43   */
44  struct RegisteredVisual
45  {
46    Property::Index index;
47    Toolkit::Visual::Base visual;
48    bool enabled;
49
50    RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled)
51    : index(aIndex), visual(aVisual), enabled(aEnabled)
52    {
53    }
54  };
55
56 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
57
58
59 /**
60  * @brief Holds the Implementation for the internal control class
61  */
62 class Control::Impl : public ConnectionTracker, public Visual::ResourceObserver
63 {
64
65 public:
66
67   /**
68    * @brief Retrieves the implementation of the internal control class.
69    * @param[in] internalControl A ref to the control whose internal implementation is required
70    * @return The internal implementation
71    */
72   static Control::Impl& Get( Internal::Control& internalControl );
73
74   /**
75    * @copydoc Get( Internal::Control& )
76    */
77   static const Control::Impl& Get( const Internal::Control& internalControl );
78
79   /**
80    * @brief Constructor.
81    * @param[in] controlImpl The control which own this implementation
82    */
83   Impl( Control& controlImpl );
84
85   /**
86    * @brief Destructor.
87    */
88   ~Impl();
89
90   /**
91    * @brief Called when a pinch is detected.
92    * @param[in] actor The actor the pinch occurred on
93    * @param[in] pinch The pinch gesture details
94    */
95   void PinchDetected(Actor actor, const PinchGesture& pinch);
96
97   /**
98    * @brief Called when a pan is detected.
99    * @param[in] actor The actor the pan occurred on
100    * @param[in] pan The pan gesture details
101    */
102   void PanDetected(Actor actor, const PanGesture& pan);
103
104   /**
105    * @brief Called when a tap is detected.
106    * @param[in] actor The actor the tap occurred on
107    * @param[in] tap The tap gesture details
108    */
109   void TapDetected(Actor actor, const TapGesture& tap);
110
111   /**
112    * @brief Called when a long-press is detected.
113    * @param[in] actor The actor the long-press occurred on
114    * @param[in] longPress The long-press gesture details
115    */
116   void LongPressDetected(Actor actor, const LongPressGesture& longPress);
117
118   /**
119    * @brief Called when a resource is ready.
120    * @param[in] object The visual whose resources are ready
121    * @note Overriding method in Visual::ResourceObserver.
122    */
123   virtual void ResourceReady( Visual::Base& object );
124
125   /**
126    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
127    */
128   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
129
130   /**
131    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
132    */
133   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
134
135   /**
136    * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
137    */
138   void UnregisterVisual( Property::Index index );
139
140   /**
141    * @copydoc Dali::Toolkit::DevelControl::GetVisual()
142    */
143   Toolkit::Visual::Base GetVisual( Property::Index index ) const;
144
145   /**
146    * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
147    */
148   void EnableVisual( Property::Index index, bool enable );
149
150   /**
151    * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
152    */
153   bool IsVisualEnabled( Property::Index index ) const;
154
155   /**
156    * @brief Stops observing the given visual.
157    * @param[in] visual The visual to stop observing
158    */
159   void StopObservingVisual( Toolkit::Visual::Base& visual );
160
161   /**
162    * @brief Starts observing the given visual.
163    * @param[in] visual The visual to start observing
164    */
165   void StartObservingVisual( Toolkit::Visual::Base& visual);
166
167   /**
168    * @brief Function used to set control properties.
169    * @param[in] object The object whose property to set
170    * @param[in] index The index of the property to set
171    * @param[in] value The value of the property to set
172    */
173   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
174
175   /**
176    * @brief Function used to retrieve the value of control properties.
177    * @param[in] object The object whose property to get
178    * @param[in] index The index of the property to get
179    * @return The value of the property
180    */
181   static Property::Value GetProperty( BaseObject* object, Property::Index index );
182
183   /**
184    * @brief Removes a visual from the control's container.
185    * @param[in] visuals The container of visuals
186    * @param[in] visualName The name of the visual to remove
187    */
188   void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
189
190   /**
191    * @brief Whether the resource is ready
192    * @return True if the resource is read.
193    */
194   bool IsResourceReady() const;
195
196   Control& mControlImpl;
197
198   RegisteredVisualContainer mVisuals;     ///< Stores visuals needed by the control, non trivial type so std::vector used.
199   std::string mStyleName;
200   Vector4 mBackgroundColor;               ///< The color of the background visual
201   Vector3* mStartingPinchScale;           ///< The scale when a pinch gesture starts, TODO: consider removing this
202   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
203   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
204   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
205
206   Toolkit::DevelControl::ResourceReadySignalType mResourceReadySignal;
207
208   // Gesture Detection
209   PinchGestureDetector mPinchGestureDetector;
210   PanGestureDetector mPanGestureDetector;
211   TapGestureDetector mTapGestureDetector;
212   LongPressGestureDetector mLongPressGestureDetector;
213
214   ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT;    ///< Flags passed in from constructor.
215   bool mIsKeyboardNavigationSupported :1;  ///< Stores whether keyboard navigation is supported by the control.
216   bool mIsKeyboardFocusGroup :1;           ///< Stores whether the control is a focus group.
217
218   // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
219   static const PropertyRegistration PROPERTY_1;
220   static const PropertyRegistration PROPERTY_2;
221   static const PropertyRegistration PROPERTY_3;
222   static const PropertyRegistration PROPERTY_4;
223   static const PropertyRegistration PROPERTY_5;
224
225 };
226
227
228 } // namespace Internal
229
230 } // namespace Toolkit
231
232 } // namespace Dali
233
234 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H