1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_IMPL_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
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/layouting/layout-item-impl.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
32 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
33 #include <dali-toolkit/internal/builder/style.h>
34 #include <dali-toolkit/internal/builder/dictionary.h>
35 #include <dali-toolkit/public-api/visuals/visual-properties.h>
47 * Struct used to store Visual within the control, index is a unique key for each visual.
49 struct RegisteredVisual
51 Property::Index index;
52 Toolkit::Visual::Base visual;
56 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled, bool aPendingReplacement )
57 : index(aIndex), visual(aVisual), enabled(aEnabled), pending( aPendingReplacement )
62 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
66 * @brief Holds the Implementation for the internal control class
68 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
74 * @brief Retrieves the implementation of the internal control class.
75 * @param[in] internalControl A ref to the control whose internal implementation is required
76 * @return The internal implementation
78 static Control::Impl& Get( Internal::Control& internalControl );
81 * @copydoc Get( Internal::Control& )
83 static const Control::Impl& Get( const Internal::Control& internalControl );
87 * @param[in] controlImpl The control which owns this implementation
89 Impl( Control& controlImpl );
97 * @brief Called when a pinch is detected.
98 * @param[in] actor The actor the pinch occurred on
99 * @param[in] pinch The pinch gesture details
101 void PinchDetected(Actor actor, const PinchGesture& pinch);
104 * @brief Called when a pan is detected.
105 * @param[in] actor The actor the pan occurred on
106 * @param[in] pinch The pan gesture details
108 void PanDetected(Actor actor, const PanGesture& pan);
111 * @brief Called when a tap is detected.
112 * @param[in] actor The actor the tap occurred on
113 * @param[in] pinch The tap gesture details
115 void TapDetected(Actor actor, const TapGesture& tap);
118 * @brief Called when a long-press is detected.
119 * @param[in] actor The actor the long-press occurred on
120 * @param[in] pinch The long-press gesture details
122 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
125 * @brief Called when a resource is ready.
126 * @param[in] object The visual whose resources are ready
127 * @note Overriding method in Visual::EventObserver.
129 virtual void ResourceReady( Visual::Base& object ) override;
132 * @brief Called when an event occurs.
133 * @param[in] object The visual whose events occur
134 * @param[in] signalId The signal to emit. See Visual to find supported signals
135 * @note Overriding method in Visual::EventObserver.
137 virtual void NotifyVisualEvent( Visual::Base& object, Property::Index signalId ) override;
140 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
142 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
145 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
147 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex );
150 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
152 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
155 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
157 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex );
160 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
162 void UnregisterVisual( Property::Index index );
165 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
167 Toolkit::Visual::Base GetVisual( Property::Index index ) const;
170 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
172 void EnableVisual( Property::Index index, bool enable );
175 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
177 bool IsVisualEnabled( Property::Index index ) const;
180 * @brief Stops observing the given visual.
181 * @param[in] visual The visual to stop observing
183 void StopObservingVisual( Toolkit::Visual::Base& visual );
186 * @brief Starts observing the given visual.
187 * @param[in] visual The visual to start observing
189 void StartObservingVisual( Toolkit::Visual::Base& visual);
192 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
194 Toolkit::Visual::ResourceStatus GetVisualResourceStatus( Property::Index index ) const;
197 * @param[in,out] animation Handle to existing animation, or an empty handle that
198 * can be set to a New animation if createAnimation is true
199 * @param[in] transitionData The transition data describing the animation
200 * @param[in] createAnimation True if the animation should be created
202 void AddTransitions( Dali::Animation& animation,
203 const Toolkit::TransitionData& transitionData,
204 bool createAnimation = false );
207 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
209 Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
212 * @copydoc Dali::Toolkit::DevelControl::DoAction()
214 void DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes );
217 * @brief Function used to set control properties.
218 * @param[in] object The object whose property to set
219 * @param[in] index The index of the property to set
220 * @param[in] value The value of the property to set
222 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
225 * @brief Function used to retrieve the value of control properties.
226 * @param[in] object The object whose property to get
227 * @param[in] index The index of the property to get
228 * @return The value of the property
230 static Property::Value GetProperty( BaseObject* object, Property::Index index );
233 * @brief Sets the state of the control.
234 * @param[in] newState The state to set
235 * @param[in] withTransitions Whether to show a transition when changing to the new state
237 void SetState( DevelControl::State newState, bool withTransitions=true );
240 * @brief Sets the sub-state of the control.
241 * @param[in] newState The sub-state to set
242 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
244 void SetSubState( const std::string& subStateName, bool withTransitions=true );
247 * @brief Replaces visuals and properties from the old state to the new state.
248 * @param[in] oldState The old state
249 * @param[in] newState The new state
250 * @param[in] subState The current sub state
252 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
255 * @brief Removes a visual from the control's container.
256 * @param[in] visuals The container of visuals
257 * @param[in] visualName The name of the visual to remove
259 void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
262 * @brief Removes several visuals from the control's container.
263 * @param[in] visuals The container of visuals
264 * @param[in] removeVisuals The visuals to remove
266 void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
269 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
270 * @param[in] visuals The control's visual container
271 * @param[out] instancedProperties The instanced properties are added to this container
273 void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
276 * @brief On state change, ensures visuals are moved or created appropriately.
278 * Go through the list of visuals that are common to both states.
279 * If they are different types, or are both image types with different
280 * URLs, then the existing visual needs moving and the new visual needs creating
282 * @param[in] stateVisualsToChange The visuals to change
283 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
285 void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
288 * @brief Whether the resource is ready
289 * @return True if the resource is read.
291 bool IsResourceReady() const;
294 * @copydoc CustomActorImpl::OnStageDisconnection()
296 void OnStageDisconnection();
299 * @brief Sets the margin.
300 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
302 void SetMargin( Extents margin );
305 * @brief Returns the value of margin
306 * @return The value of margin
308 Extents GetMargin() const;
311 * @brief Sets the padding.
312 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
314 void SetPadding( Extents padding );
317 * @brief Returns the value of padding
318 * @return The value of padding
320 Extents GetPadding() const;
323 * @brief Set the input method context.
324 * @param[in] inputMethodContext The input method context.
326 void SetInputMethodContext( InputMethodContext& inputMethodContext );
329 * @brief Filter an key event.
330 * @param[in] event The key to be filtered.
331 * @return True if the key handled, otherwise false.
333 bool FilterKeyEvent( const KeyEvent& event );
336 * @brief Get the layout associated with this control, if any.
338 * @return A pointer to the layout, or NULL.
340 Toolkit::Internal::LayoutItemPtr GetLayout() const;
343 * @brief Set the layout on this control.
344 * @param[in] layout Pointer to the layout
346 void SetLayout( Toolkit::Internal::LayoutItem& layout );
349 * @brief Remove the layout from this control
351 * @note This does not remove any children from this control, nor does it strip
352 * layouts from them but it does remove them from the layout hierarchy.
357 * @copydoc DevelControl::SetLayoutingRequired
359 void SetLayoutingRequired( bool layoutingRequired );
362 * @copydoc DevelControl::IsLayoutingRequired()
364 bool IsLayoutingRequired();
367 * @copydoc DevelControl::VisualEventSignal()
369 DevelControl::VisualEventSignalType& VisualEventSignal();
374 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
380 DISABLED = 0, ///< Visual disabled.
381 ENABLED = 1 ///< Visual enabled.
386 * 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.
388 struct DepthIndexValue
392 NOT_SET = 0, ///< Visual depth value not set by caller.
393 SET = 1 ///< Visual depth value set by caller.
398 * @brief Adds the visual to the list of registered visuals.
399 * @param[in] index The Property index of the visual, used to reference visual
400 * @param[in,out] visual The visual to register, which can be altered in this function
401 * @param[in] enabled false if derived class wants to control when visual is set on stage
402 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
403 * @param[in] depthIndex The visual's depth-index is set to this
405 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
406 * occur once the replacement visual is ready (loaded).
408 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
412 Control& mControlImpl;
413 DevelControl::State mState;
414 std::string mSubStateName;
417 Toolkit::Internal::LayoutItemPtr mLayout;
419 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
420 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
421 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
422 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
424 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
425 std::string mStyleName;
426 Vector4 mBackgroundColor; ///< The color of the background visual
427 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
428 Extents mMargin; ///< The margin values
429 Extents mPadding; ///< The padding values
430 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
431 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
432 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
433 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
434 DevelControl::VisualEventSignalType mVisualEventSignal;
437 PinchGestureDetector mPinchGestureDetector;
438 PanGestureDetector mPanGestureDetector;
439 TapGestureDetector mTapGestureDetector;
440 LongPressGestureDetector mLongPressGestureDetector;
445 InputMethodContext mInputMethodContext;
447 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
448 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
449 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
450 bool mIsLayoutingRequired :1; ///< Stores whether the control needs to be Layout
452 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
455 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
456 static const PropertyRegistration PROPERTY_1;
457 static const PropertyRegistration PROPERTY_2;
458 static const PropertyRegistration PROPERTY_3;
459 static const PropertyRegistration PROPERTY_4;
460 static const PropertyRegistration PROPERTY_5;
461 static const PropertyRegistration PROPERTY_6;
462 static const PropertyRegistration PROPERTY_7;
463 static const PropertyRegistration PROPERTY_8;
464 static const PropertyRegistration PROPERTY_9;
465 static const PropertyRegistration PROPERTY_10;
466 static const PropertyRegistration PROPERTY_11;
467 static const PropertyRegistration PROPERTY_12;
468 static const PropertyRegistration PROPERTY_13;
469 static const PropertyRegistration PROPERTY_14;
473 } // namespace Internal
475 } // namespace Toolkit
479 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H