[dali_1.4.52] 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) 2019 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-event-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 #include <dali-toolkit/public-api/visuals/visual-properties.h>
35
36 namespace Dali
37 {
38
39 namespace Toolkit
40 {
41
42 namespace Internal
43 {
44
45  /**
46   * Struct used to store Visual within the control, index is a unique key for each visual.
47   */
48 struct RegisteredVisual
49 {
50   Property::Index index;
51   Toolkit::Visual::Base visual;
52   bool enabled : 1;
53   bool pending : 1;
54
55   RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled, bool aPendingReplacement )
56   : index(aIndex), visual(aVisual), enabled(aEnabled), pending( aPendingReplacement )
57   {
58   }
59 };
60
61 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
62
63
64 /**
65  * @brief Holds the Implementation for the internal control class
66  */
67 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
68 {
69
70 public:
71
72   /**
73    * @brief Retrieves the implementation of the internal control class.
74    * @param[in] internalControl A ref to the control whose internal implementation is required
75    * @return The internal implementation
76    */
77   static Control::Impl& Get( Internal::Control& internalControl );
78
79   /**
80    * @copydoc Get( Internal::Control& )
81    */
82   static const Control::Impl& Get( const Internal::Control& internalControl );
83
84   /**
85    * @brief Constructor.
86    * @param[in] controlImpl The control which owns this implementation
87    */
88   Impl( Control& controlImpl );
89
90   /**
91    * @brief Destructor.
92    */
93   ~Impl();
94
95   /**
96    * @brief Called when a pinch is detected.
97    * @param[in] actor The actor the pinch occurred on
98    * @param[in] pinch The pinch gesture details
99    */
100   void PinchDetected(Actor actor, const PinchGesture& pinch);
101
102   /**
103    * @brief Called when a pan is detected.
104    * @param[in] actor The actor the pan occurred on
105    * @param[in] pinch The pan gesture details
106    */
107   void PanDetected(Actor actor, const PanGesture& pan);
108
109   /**
110    * @brief Called when a tap is detected.
111    * @param[in] actor The actor the tap occurred on
112    * @param[in] pinch The tap gesture details
113    */
114   void TapDetected(Actor actor, const TapGesture& tap);
115
116   /**
117    * @brief Called when a long-press is detected.
118    * @param[in] actor The actor the long-press occurred on
119    * @param[in] pinch The long-press gesture details
120    */
121   void LongPressDetected(Actor actor, const LongPressGesture& longPress);
122
123   /**
124    * @brief Called when a resource is ready.
125    * @param[in] object The visual whose resources are ready
126    * @note Overriding method in Visual::EventObserver.
127    */
128   virtual void ResourceReady( Visual::Base& object ) override;
129
130   /**
131    * @brief Called when an event occurs.
132    * @param[in] object The visual whose events occur
133    * @param[in] signalId The signal to emit. See Visual to find supported signals
134    * @note Overriding method in Visual::EventObserver.
135    */
136   virtual void NotifyVisualEvent( Visual::Base& object, Property::Index signalId ) override;
137
138   /**
139    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
140    */
141   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
142
143   /**
144    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
145    */
146   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex );
147
148   /**
149    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
150    */
151   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
152
153   /**
154    * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
155    */
156   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex );
157
158   /**
159    * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
160    */
161   void UnregisterVisual( Property::Index index );
162
163   /**
164    * @copydoc Dali::Toolkit::DevelControl::GetVisual()
165    */
166   Toolkit::Visual::Base GetVisual( Property::Index index ) const;
167
168   /**
169    * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
170    */
171   void EnableVisual( Property::Index index, bool enable );
172
173   /**
174    * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
175    */
176   bool IsVisualEnabled( Property::Index index ) const;
177
178   /**
179    * @brief Stops observing the given visual.
180    * @param[in] visual The visual to stop observing
181    */
182   void StopObservingVisual( Toolkit::Visual::Base& visual );
183
184   /**
185    * @brief Starts observing the given visual.
186    * @param[in] visual The visual to start observing
187    */
188   void StartObservingVisual( Toolkit::Visual::Base& visual);
189
190   /**
191    * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
192    */
193   Toolkit::Visual::ResourceStatus GetVisualResourceStatus( Property::Index index ) const;
194
195   /**
196    * @param[in,out] animation Handle to existing animation, or an empty handle that
197    * can be set to a New animation if createAnimation is true
198    * @param[in] transitionData The transition data describing the animation
199    * @param[in] createAnimation True if the animation should be created
200    */
201   void AddTransitions( Dali::Animation& animation,
202                        const Toolkit::TransitionData& transitionData,
203                        bool createAnimation = false );
204
205   /**
206    * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
207    */
208   Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
209
210   /**
211    * @copydoc Dali::Toolkit::DevelControl::DoAction()
212    */
213   void DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes );
214
215   /**
216    * @brief Function used to set control properties.
217    * @param[in] object The object whose property to set
218    * @param[in] index The index of the property to set
219    * @param[in] value The value of the property to set
220    */
221   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
222
223   /**
224    * @brief Function used to retrieve the value of control properties.
225    * @param[in] object The object whose property to get
226    * @param[in] index The index of the property to get
227    * @return The value of the property
228    */
229   static Property::Value GetProperty( BaseObject* object, Property::Index index );
230
231   /**
232    * @brief Sets the state of the control.
233    * @param[in] newState The state to set
234    * @param[in] withTransitions Whether to show a transition when changing to the new state
235    */
236   void SetState( DevelControl::State newState, bool withTransitions=true );
237
238   /**
239    * @brief Sets the sub-state of the control.
240    * @param[in] newState The sub-state to set
241    * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
242    */
243   void SetSubState( const std::string& subStateName, bool withTransitions=true );
244
245   /**
246    * @brief Replaces visuals and properties from the old state to the new state.
247    * @param[in] oldState The old state
248    * @param[in] newState The new state
249    * @param[in] subState The current sub state
250    */
251   void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
252
253   /**
254    * @brief Removes a visual from the control's container.
255    * @param[in] visuals The container of visuals
256    * @param[in] visualName The name of the visual to remove
257    */
258   void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
259
260   /**
261    * @brief Removes several visuals from the control's container.
262    * @param[in] visuals The container of visuals
263    * @param[in] removeVisuals The visuals to remove
264    */
265   void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
266
267   /**
268    * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
269    * @param[in] visuals The control's visual container
270    * @param[out] instancedProperties The instanced properties are added to this container
271    */
272   void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
273
274   /**
275    * @brief On state change, ensures visuals are moved or created appropriately.
276    *
277    * Go through the list of visuals that are common to both states.
278    * If they are different types, or are both image types with different
279    * URLs, then the existing visual needs moving and the new visual needs creating
280    *
281    * @param[in] stateVisualsToChange The visuals to change
282    * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
283    */
284   void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
285
286   /**
287    * @brief Whether the resource is ready
288    * @return True if the resource is read.
289    */
290   bool IsResourceReady() const;
291
292   /**
293    * @copydoc CustomActorImpl::OnStageDisconnection()
294    */
295   void OnStageDisconnection();
296
297   /**
298    * @brief Sets the margin.
299    * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
300    */
301   void SetMargin( Extents margin );
302
303   /**
304    * @brief Returns the value of margin
305    * @return The value of margin
306    */
307   Extents GetMargin() const;
308
309   /**
310    * @brief Sets the padding.
311    * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
312    */
313   void SetPadding( Extents padding );
314
315   /**
316    * @brief Returns the value of padding
317    * @return The value of padding
318    */
319   Extents GetPadding() const;
320
321   /**
322    * @brief Set the input method context.
323    * @param[in] inputMethodContext The input method context.
324    */
325   void SetInputMethodContext( InputMethodContext& inputMethodContext );
326
327   /**
328    * @brief Filter an key event.
329    * @param[in] event The key to be filtered.
330    * @return True if the key handled, otherwise false.
331    */
332   bool FilterKeyEvent( const KeyEvent& event );
333
334   /**
335    * @copydoc DevelControl::VisualEventSignal()
336    */
337   DevelControl::VisualEventSignalType& VisualEventSignal();
338
339   /**
340    * @brief Sets the shadow with a property map.
341    * @param[in] map The shadow property map
342    */
343   void SetShadow(const Property::Map& map);
344
345   /**
346    * @brief Clear the shadow.
347    */
348   void ClearShadow();
349
350 private:
351
352   /**
353    * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
354    */
355   struct VisualState
356   {
357     enum Type
358     {
359       DISABLED = 0, ///< Visual disabled.
360       ENABLED = 1   ///< Visual enabled.
361     };
362   };
363
364   /**
365    * 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.
366    */
367   struct DepthIndexValue
368   {
369     enum Type
370     {
371       NOT_SET = 0, ///< Visual depth value not set by caller.
372       SET = 1      ///< Visual depth value set by caller.
373     };
374   };
375
376   /**
377    * @brief Adds the visual to the list of registered visuals.
378    * @param[in] index The Property index of the visual, used to reference visual
379    * @param[in,out] visual The visual to register, which can be altered in this function
380    * @param[in] enabled false if derived class wants to control when visual is set on stage
381    * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
382    * @param[in] depthIndex The visual's depth-index is set to this
383    *
384    * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
385    *       occur once the replacement visual is ready (loaded).
386    */
387   void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
388
389 public:
390
391   Control& mControlImpl;
392   DevelControl::State mState;
393   std::string mSubStateName;
394
395   int mLeftFocusableActorId;       ///< Actor ID of Left focusable control.
396   int mRightFocusableActorId;      ///< Actor ID of Right focusable control.
397   int mUpFocusableActorId;         ///< Actor ID of Up focusable control.
398   int mDownFocusableActorId;       ///< Actor ID of Down focusable control.
399
400   RegisteredVisualContainer mVisuals;     ///< Stores visuals needed by the control, non trivial type so std::vector used.
401   std::string mStyleName;
402   Vector4 mBackgroundColor;               ///< The color of the background visual
403   Vector3* mStartingPinchScale;           ///< The scale when a pinch gesture starts, TODO: consider removing this
404   Extents mMargin;                        ///< The margin values
405   Extents mPadding;                       ///< The padding values
406   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
407   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
408   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
409   Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
410   DevelControl::VisualEventSignalType mVisualEventSignal;
411
412   // Gesture Detection
413   PinchGestureDetector mPinchGestureDetector;
414   PanGestureDetector mPanGestureDetector;
415   TapGestureDetector mTapGestureDetector;
416   LongPressGestureDetector mLongPressGestureDetector;
417
418   // Tooltip
419   TooltipPtr mTooltip;
420
421   InputMethodContext mInputMethodContext;
422
423   ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT;    ///< Flags passed in from constructor.
424   bool mIsKeyboardNavigationSupported :1;  ///< Stores whether keyboard navigation is supported by the control.
425   bool mIsKeyboardFocusGroup :1;           ///< Stores whether the control is a focus group.
426
427   RegisteredVisualContainer mRemoveVisuals;         ///< List of visuals that are being replaced by another visual once ready
428
429
430   // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
431   static const PropertyRegistration PROPERTY_1;
432   static const PropertyRegistration PROPERTY_2;
433   static const PropertyRegistration PROPERTY_3;
434   static const PropertyRegistration PROPERTY_4;
435   static const PropertyRegistration PROPERTY_5;
436   static const PropertyRegistration PROPERTY_6;
437   static const PropertyRegistration PROPERTY_7;
438   static const PropertyRegistration PROPERTY_8;
439   static const PropertyRegistration PROPERTY_9;
440   static const PropertyRegistration PROPERTY_10;
441   static const PropertyRegistration PROPERTY_11;
442   static const PropertyRegistration PROPERTY_12;
443   static const PropertyRegistration PROPERTY_13;
444   static const PropertyRegistration PROPERTY_14;
445   static const PropertyRegistration PROPERTY_15;
446 };
447
448
449 } // namespace Internal
450
451 } // namespace Toolkit
452
453 } // namespace Dali
454
455 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H