[dali_1.2.47] Merge branch 'devel/master'
[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 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
32 #include <dali-toolkit/internal/builder/style.h>
33 #include <dali-toolkit/internal/builder/dictionary.h>
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 /**
45   * Struct used to store Visual within the control, index is a unique key for each visual.
46   */
47  struct RegisteredVisual
48  {
49    Property::Index index;
50    Toolkit::Visual::Base visual;
51    bool enabled;
52
53    RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled)
54    : index(aIndex), visual(aVisual), enabled(aEnabled)
55    {
56    }
57  };
58
59 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
60
61
62 /**
63  * @brief Holds the Implementation for the internal control class
64  */
65 class Control::Impl : public ConnectionTracker, public Visual::ResourceObserver
66 {
67
68 public:
69
70   /**
71    * @brief Retrieves the implementation of the internal control class.
72    * @param[in] internalControl A ref to the control whose internal implementation is required
73    * @return The internal implementation
74    */
75   static Control::Impl& Get( Internal::Control& internalControl );
76
77   /**
78    * @copydoc Get( Internal::Control& )
79    */
80   static const Control::Impl& Get( const Internal::Control& internalControl );
81
82   /**
83    * @brief Constructor.
84    * @param[in] controlImpl The control which own this implementation
85    */
86   Impl( Control& controlImpl );
87
88   /**
89    * @brief Destructor.
90    */
91   ~Impl();
92
93   /**
94    * @brief Called when a pinch is detected.
95    * @param[in] actor The actor the pinch occurred on
96    * @param[in] pinch The pinch gesture details
97    */
98   void PinchDetected(Actor actor, const PinchGesture& pinch);
99
100   /**
101    * @brief Called when a pan is detected.
102    * @param[in] actor The actor the pan occurred on
103    * @param[in] pinch The pan gesture details
104    */
105   void PanDetected(Actor actor, const PanGesture& pan);
106
107   /**
108    * @brief Called when a tap is detected.
109    * @param[in] actor The actor the tap occurred on
110    * @param[in] pinch The tap gesture details
111    */
112   void TapDetected(Actor actor, const TapGesture& tap);
113
114   /**
115    * @brief Called when a long-press is detected.
116    * @param[in] actor The actor the long-press occurred on
117    * @param[in] pinch The long-press gesture details
118    */
119   void LongPressDetected(Actor actor, const LongPressGesture& longPress);
120
121   /**
122    * @brief Called when a resource is ready.
123    * @param[in] object The visual whose resources are ready
124    * @note Overriding method in Visual::ResourceObserver.
125    */
126   virtual void ResourceReady( Visual::Base& object );
127
128   /**
129    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
130    */
131   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
132
133   /**
134    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
135    */
136   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex );
137
138   /**
139    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
140    */
141   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
142
143   /**
144    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
145    */
146   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex );
147
148   /**
149    * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
150    */
151   void UnregisterVisual( Property::Index index );
152
153   /**
154    * @copydoc Dali::Toolkit::DevelControl::GetVisual()
155    */
156   Toolkit::Visual::Base GetVisual( Property::Index index ) const;
157
158   /**
159    * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
160    */
161   void EnableVisual( Property::Index index, bool enable );
162
163   /**
164    * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
165    */
166   bool IsVisualEnabled( Property::Index index ) const;
167
168   /**
169    * @brief Stops observing the given visual.
170    * @param[in] visual The visual to stop observing
171    */
172   void StopObservingVisual( Toolkit::Visual::Base& visual );
173
174   /**
175    * @brief Starts observing the given visual.
176    * @param[in] visual The visual to start observing
177    */
178   void StartObservingVisual( Toolkit::Visual::Base& visual);
179
180   /**
181    * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
182    */
183   Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
184
185   /**
186    * @brief Function used to set control properties.
187    * @param[in] object The object whose property to set
188    * @param[in] index The index of the property to set
189    * @param[in] value The value of the property to set
190    */
191   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
192
193   /**
194    * @brief Function used to retrieve the value of control properties.
195    * @param[in] object The object whose property to get
196    * @param[in] index The index of the property to get
197    * @return The value of the property
198    */
199   static Property::Value GetProperty( BaseObject* object, Property::Index index );
200
201   /**
202    * @brief Sets the state of the control.
203    * @param[in] newState The state to set
204    * @param[in] withTransitions Whether to show a transition when changing to the new state
205    */
206   void SetState( DevelControl::State newState, bool withTransitions=true );
207
208   /**
209    * @brief Sets the sub-state of the control.
210    * @param[in] newState The sub-state to set
211    * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
212    */
213   void SetSubState( const std::string& subStateName, bool withTransitions=true );
214
215   /**
216    * @brief Replaces visuals and properties from the old state to the new state.
217    * @param[in] oldState The old state
218    * @param[in] newState The new state
219    * @param[in] subState The current sub state
220    */
221   void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
222
223   /**
224    * @brief Removes a visual from the control's container.
225    * @param[in] visuals The container of visuals
226    * @param[in] visualName The name of the visual to remove
227    */
228   void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
229
230   /**
231    * @brief Removes several visuals from the control's container.
232    * @param[in] visuals The container of visuals
233    * @param[in] removeVisuals The visuals to remove
234    */
235   void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
236
237   /**
238    * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
239    * @param[in] visuals The control's visual container
240    * @param[out] instancedProperties The instanced properties are added to this container
241    */
242   void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
243
244   /**
245    * @brief On state change, ensures visuals are moved or created appropriately.
246    *
247    * Go through the list of visuals that are common to both states.
248    * If they are different types, or are both image types with different
249    * URLs, then the existing visual needs moving and the new visual needs creating
250    *
251    * @param[in] stateVisualsToChange The visuals to change
252    * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
253    */
254   void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
255
256   /**
257    * @brief Whether the resource is ready
258    * @return True if the resource is read.
259    */
260   bool IsResourceReady() const;
261
262 private:
263
264   /**
265    * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
266    */
267   struct VisualState
268   {
269     enum Type
270     {
271       DISABLED = 0, ///< Visual disabled.
272       ENABLED = 1   ///< Visual enabled.
273     };
274   };
275
276   /**
277    * Used as an alternative to boolean so that it is obvious whether a visual's depth value has been set or not by the caller.
278    */
279   struct DepthIndexValue
280   {
281     enum Type
282     {
283       NOT_SET = 0, ///< Visual depth value not set by caller.
284       SET = 1      ///< Visual depth value set by caller.
285     };
286   };
287
288   /**
289    * @brief Adds the visual to the list of registered visuals.
290    * @param[in] index The Property index of the visual, used to reference visual
291    * @param[in,out] visual The visual to register, which can be altered in this function
292    * @param[in] enabled false if derived class wants to control when visual is set on stage
293    * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
294    * @param[in] depthIndex The visual's depth-index is set to this
295    *
296    * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
297    *       occur once the replacement visual is ready (loaded).
298    */
299   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
300
301 public:
302
303   Control& mControlImpl;
304   DevelControl::State mState;
305   std::string mSubStateName;
306
307   int mLeftFocusableActorId;       ///< Actor ID of Left focusable control.
308   int mRightFocusableActorId;      ///< Actor ID of Right focusable control.
309   int mUpFocusableActorId;         ///< Actor ID of Up focusable control.
310   int mDownFocusableActorId;       ///< Actor ID of Down focusable control.
311
312   RegisteredVisualContainer mVisuals;     ///< Stores visuals needed by the control, non trivial type so std::vector used.
313   std::string mStyleName;
314   Vector4 mBackgroundColor;               ///< The color of the background visual
315   Vector3* mStartingPinchScale;           ///< The scale when a pinch gesture starts, TODO: consider removing this
316   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
317   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
318   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
319
320   Toolkit::DevelControl::ResourceReadySignalType mResourceReadySignal;
321
322   // Gesture Detection
323   PinchGestureDetector mPinchGestureDetector;
324   PanGestureDetector mPanGestureDetector;
325   TapGestureDetector mTapGestureDetector;
326   LongPressGestureDetector mLongPressGestureDetector;
327
328   // Tooltip
329   TooltipPtr mTooltip;
330
331   ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT;    ///< Flags passed in from constructor.
332   bool mIsKeyboardNavigationSupported :1;  ///< Stores whether keyboard navigation is supported by the control.
333   bool mIsKeyboardFocusGroup :1;           ///< Stores whether the control is a focus group.
334
335   RegisteredVisualContainer mReplacementVisuals;         ///< List of visuals that will be used for replacing current visuals.
336
337   // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
338   static const PropertyRegistration PROPERTY_1;
339   static const PropertyRegistration PROPERTY_2;
340   static const PropertyRegistration PROPERTY_3;
341   static const PropertyRegistration PROPERTY_4;
342   static const PropertyRegistration PROPERTY_5;
343   static const PropertyRegistration PROPERTY_6;
344   static const PropertyRegistration PROPERTY_7;
345   static const PropertyRegistration PROPERTY_8;
346   static const PropertyRegistration PROPERTY_9;
347   static const PropertyRegistration PROPERTY_10;
348   static const PropertyRegistration PROPERTY_11;
349   static const PropertyRegistration PROPERTY_12;
350 };
351
352
353 } // namespace Internal
354
355 } // namespace Toolkit
356
357 } // namespace Dali
358
359 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H