1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_IMPL_H
5 * Copyright (c) 2019 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/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>
46 * Struct used to store Visual within the control, index is a unique key for each visual.
48 struct RegisteredVisual
50 Property::Index index;
51 Toolkit::Visual::Base visual;
55 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled, bool aPendingReplacement )
56 : index(aIndex), visual(aVisual), enabled(aEnabled), pending( aPendingReplacement )
61 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
65 * @brief Holds the Implementation for the internal control class
67 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
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
77 static Control::Impl& Get( Internal::Control& internalControl );
80 * @copydoc Get( Internal::Control& )
82 static const Control::Impl& Get( const Internal::Control& internalControl );
86 * @param[in] controlImpl The control which owns this implementation
88 Impl( Control& controlImpl );
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
100 void PinchDetected(Actor actor, const PinchGesture& pinch);
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
107 void PanDetected(Actor actor, const PanGesture& pan);
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
114 void TapDetected(Actor actor, const TapGesture& tap);
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
121 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
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.
128 virtual void ResourceReady( Visual::Base& object ) override;
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.
136 virtual void NotifyVisualEvent( Visual::Base& object, Property::Index signalId ) override;
139 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
141 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
144 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
146 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex );
149 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
151 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
154 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
156 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex );
159 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
161 void UnregisterVisual( Property::Index index );
164 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
166 Toolkit::Visual::Base GetVisual( Property::Index index ) const;
169 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
171 void EnableVisual( Property::Index index, bool enable );
174 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
176 bool IsVisualEnabled( Property::Index index ) const;
179 * @brief Stops observing the given visual.
180 * @param[in] visual The visual to stop observing
182 void StopObservingVisual( Toolkit::Visual::Base& visual );
185 * @brief Starts observing the given visual.
186 * @param[in] visual The visual to start observing
188 void StartObservingVisual( Toolkit::Visual::Base& visual);
191 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
193 Toolkit::Visual::ResourceStatus GetVisualResourceStatus( Property::Index index ) const;
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
201 void AddTransitions( Dali::Animation& animation,
202 const Toolkit::TransitionData& transitionData,
203 bool createAnimation = false );
206 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
208 Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
211 * @copydoc Dali::Toolkit::DevelControl::DoAction()
213 void DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes );
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
221 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
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
229 static Property::Value GetProperty( BaseObject* object, Property::Index index );
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
236 void SetState( DevelControl::State newState, bool withTransitions=true );
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
243 void SetSubState( const std::string& subStateName, bool withTransitions=true );
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
251 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
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
258 void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
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
265 void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
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
272 void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
275 * @brief On state change, ensures visuals are moved or created appropriately.
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
281 * @param[in] stateVisualsToChange The visuals to change
282 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
284 void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
287 * @brief Whether the resource is ready
288 * @return True if the resource is read.
290 bool IsResourceReady() const;
293 * @copydoc CustomActorImpl::OnStageDisconnection()
295 void OnStageDisconnection();
298 * @brief Sets the margin.
299 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
301 void SetMargin( Extents margin );
304 * @brief Returns the value of margin
305 * @return The value of margin
307 Extents GetMargin() const;
310 * @brief Sets the padding.
311 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
313 void SetPadding( Extents padding );
316 * @brief Returns the value of padding
317 * @return The value of padding
319 Extents GetPadding() const;
322 * @brief Set the input method context.
323 * @param[in] inputMethodContext The input method context.
325 void SetInputMethodContext( InputMethodContext& inputMethodContext );
328 * @brief Filter an key event.
329 * @param[in] event The key to be filtered.
330 * @return True if the key handled, otherwise false.
332 bool FilterKeyEvent( const KeyEvent& event );
335 * @copydoc DevelControl::VisualEventSignal()
337 DevelControl::VisualEventSignalType& VisualEventSignal();
342 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
348 DISABLED = 0, ///< Visual disabled.
349 ENABLED = 1 ///< Visual enabled.
354 * 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.
356 struct DepthIndexValue
360 NOT_SET = 0, ///< Visual depth value not set by caller.
361 SET = 1 ///< Visual depth value set by caller.
366 * @brief Adds the visual to the list of registered visuals.
367 * @param[in] index The Property index of the visual, used to reference visual
368 * @param[in,out] visual The visual to register, which can be altered in this function
369 * @param[in] enabled false if derived class wants to control when visual is set on stage
370 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
371 * @param[in] depthIndex The visual's depth-index is set to this
373 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
374 * occur once the replacement visual is ready (loaded).
376 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
380 Control& mControlImpl;
381 DevelControl::State mState;
382 std::string mSubStateName;
384 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
385 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
386 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
387 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
389 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
390 std::string mStyleName;
391 Vector4 mBackgroundColor; ///< The color of the background visual
392 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
393 Extents mMargin; ///< The margin values
394 Extents mPadding; ///< The padding values
395 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
396 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
397 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
398 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
399 DevelControl::VisualEventSignalType mVisualEventSignal;
402 PinchGestureDetector mPinchGestureDetector;
403 PanGestureDetector mPanGestureDetector;
404 TapGestureDetector mTapGestureDetector;
405 LongPressGestureDetector mLongPressGestureDetector;
410 InputMethodContext mInputMethodContext;
412 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
413 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
414 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
416 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
419 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
420 static const PropertyRegistration PROPERTY_1;
421 static const PropertyRegistration PROPERTY_2;
422 static const PropertyRegistration PROPERTY_3;
423 static const PropertyRegistration PROPERTY_4;
424 static const PropertyRegistration PROPERTY_5;
425 static const PropertyRegistration PROPERTY_6;
426 static const PropertyRegistration PROPERTY_7;
427 static const PropertyRegistration PROPERTY_8;
428 static const PropertyRegistration PROPERTY_9;
429 static const PropertyRegistration PROPERTY_10;
430 static const PropertyRegistration PROPERTY_11;
431 static const PropertyRegistration PROPERTY_12;
432 static const PropertyRegistration PROPERTY_13;
433 static const PropertyRegistration PROPERTY_14;
437 } // namespace Internal
439 } // namespace Toolkit
443 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H