1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_IMPL_H
5 * Copyright (c) 2017 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-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>
45 * Struct used to store Visual within the control, index is a unique key for each visual.
47 struct RegisteredVisual
49 Property::Index index;
50 Toolkit::Visual::Base visual;
54 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled, bool aPendingReplacement )
55 : index(aIndex), visual(aVisual), enabled(aEnabled), pending( aPendingReplacement )
60 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
64 * @brief Holds the Implementation for the internal control class
66 class Control::Impl : public ConnectionTracker, public Visual::ResourceObserver
72 * @brief Retrieves the implementation of the internal control class.
73 * @param[in] internalControl A ref to the control whose internal implementation is required
74 * @return The internal implementation
76 static Control::Impl& Get( Internal::Control& internalControl );
79 * @copydoc Get( Internal::Control& )
81 static const Control::Impl& Get( const Internal::Control& internalControl );
85 * @param[in] controlImpl The control which own this implementation
87 Impl( Control& controlImpl );
95 * @brief Called when a pinch is detected.
96 * @param[in] actor The actor the pinch occurred on
97 * @param[in] pinch The pinch gesture details
99 void PinchDetected(Actor actor, const PinchGesture& pinch);
102 * @brief Called when a pan is detected.
103 * @param[in] actor The actor the pan occurred on
104 * @param[in] pinch The pan gesture details
106 void PanDetected(Actor actor, const PanGesture& pan);
109 * @brief Called when a tap is detected.
110 * @param[in] actor The actor the tap occurred on
111 * @param[in] pinch The tap gesture details
113 void TapDetected(Actor actor, const TapGesture& tap);
116 * @brief Called when a long-press is detected.
117 * @param[in] actor The actor the long-press occurred on
118 * @param[in] pinch The long-press gesture details
120 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
123 * @brief Called when a resource is ready.
124 * @param[in] object The visual whose resources are ready
125 * @note Overriding method in Visual::ResourceObserver.
127 virtual void ResourceReady( Visual::Base& object );
130 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
132 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
135 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
137 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex );
140 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
142 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
145 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
147 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex );
150 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
152 void UnregisterVisual( Property::Index index );
155 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
157 Toolkit::Visual::Base GetVisual( Property::Index index ) const;
160 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
162 void EnableVisual( Property::Index index, bool enable );
165 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
167 bool IsVisualEnabled( Property::Index index ) const;
170 * @brief Stops observing the given visual.
171 * @param[in] visual The visual to stop observing
173 void StopObservingVisual( Toolkit::Visual::Base& visual );
176 * @brief Starts observing the given visual.
177 * @param[in] visual The visual to start observing
179 void StartObservingVisual( Toolkit::Visual::Base& visual);
182 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
184 Toolkit::Visual::ResourceStatus GetVisualResourceStatus( Property::Index index ) const;
187 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
189 Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
192 * @brief Function used to set control properties.
193 * @param[in] object The object whose property to set
194 * @param[in] index The index of the property to set
195 * @param[in] value The value of the property to set
197 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
200 * @brief Function used to retrieve the value of control properties.
201 * @param[in] object The object whose property to get
202 * @param[in] index The index of the property to get
203 * @return The value of the property
205 static Property::Value GetProperty( BaseObject* object, Property::Index index );
208 * @brief Sets the state of the control.
209 * @param[in] newState The state to set
210 * @param[in] withTransitions Whether to show a transition when changing to the new state
212 void SetState( DevelControl::State newState, bool withTransitions=true );
215 * @brief Sets the sub-state of the control.
216 * @param[in] newState The sub-state to set
217 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
219 void SetSubState( const std::string& subStateName, bool withTransitions=true );
222 * @brief Replaces visuals and properties from the old state to the new state.
223 * @param[in] oldState The old state
224 * @param[in] newState The new state
225 * @param[in] subState The current sub state
227 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
230 * @brief Removes a visual from the control's container.
231 * @param[in] visuals The container of visuals
232 * @param[in] visualName The name of the visual to remove
234 void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
237 * @brief Removes several visuals from the control's container.
238 * @param[in] visuals The container of visuals
239 * @param[in] removeVisuals The visuals to remove
241 void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
244 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
245 * @param[in] visuals The control's visual container
246 * @param[out] instancedProperties The instanced properties are added to this container
248 void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
251 * @brief On state change, ensures visuals are moved or created appropriately.
253 * Go through the list of visuals that are common to both states.
254 * If they are different types, or are both image types with different
255 * URLs, then the existing visual needs moving and the new visual needs creating
257 * @param[in] stateVisualsToChange The visuals to change
258 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
260 void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
263 * @brief Whether the resource is ready
264 * @return True if the resource is read.
266 bool IsResourceReady() const;
269 * @copydoc CustomActorImpl::OnStageDisconnection()
271 void OnStageDisconnection();
274 * @brief Sets the margin.
275 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
277 void SetMargin( Extents margin );
280 * @brief Returns the value of margin
281 * @return The value of margin
283 Extents GetMargin() const;
286 * @brief Sets the padding.
287 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
289 void SetPadding( Extents padding );
292 * @brief Returns the value of padding
293 * @return The value of padding
295 Extents GetPadding() const;
300 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
306 DISABLED = 0, ///< Visual disabled.
307 ENABLED = 1 ///< Visual enabled.
312 * 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.
314 struct DepthIndexValue
318 NOT_SET = 0, ///< Visual depth value not set by caller.
319 SET = 1 ///< Visual depth value set by caller.
324 * @brief Adds the visual to the list of registered visuals.
325 * @param[in] index The Property index of the visual, used to reference visual
326 * @param[in,out] visual The visual to register, which can be altered in this function
327 * @param[in] enabled false if derived class wants to control when visual is set on stage
328 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
329 * @param[in] depthIndex The visual's depth-index is set to this
331 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
332 * occur once the replacement visual is ready (loaded).
334 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
338 Control& mControlImpl;
339 DevelControl::State mState;
340 std::string mSubStateName;
342 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
343 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
344 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
345 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
347 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
348 std::string mStyleName;
349 Vector4 mBackgroundColor; ///< The color of the background visual
350 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
351 Extents mMargin; ///< The margin values
352 Extents mPadding; ///< The padding values
353 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
354 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
355 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
356 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
359 PinchGestureDetector mPinchGestureDetector;
360 PanGestureDetector mPanGestureDetector;
361 TapGestureDetector mTapGestureDetector;
362 LongPressGestureDetector mLongPressGestureDetector;
367 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
368 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
369 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
371 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
373 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
374 static const PropertyRegistration PROPERTY_1;
375 static const PropertyRegistration PROPERTY_2;
376 static const PropertyRegistration PROPERTY_3;
377 static const PropertyRegistration PROPERTY_4;
378 static const PropertyRegistration PROPERTY_5;
379 static const PropertyRegistration PROPERTY_6;
380 static const PropertyRegistration PROPERTY_7;
381 static const PropertyRegistration PROPERTY_8;
382 static const PropertyRegistration PROPERTY_9;
383 static const PropertyRegistration PROPERTY_10;
384 static const PropertyRegistration PROPERTY_11;
385 static const PropertyRegistration PROPERTY_12;
386 static const PropertyRegistration PROPERTY_13;
387 static const PropertyRegistration PROPERTY_14;
391 } // namespace Internal
393 } // namespace Toolkit
397 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H