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;
53 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled)
54 : index(aIndex), visual(aVisual), enabled(aEnabled)
59 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
63 * @brief Holds the Implementation for the internal control class
65 class Control::Impl : public ConnectionTracker, public Visual::ResourceObserver
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
75 static Control::Impl& Get( Internal::Control& internalControl );
78 * @copydoc Get( Internal::Control& )
80 static const Control::Impl& Get( const Internal::Control& internalControl );
84 * @param[in] controlImpl The control which own this implementation
86 Impl( Control& controlImpl );
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
98 void PinchDetected(Actor actor, const PinchGesture& pinch);
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
105 void PanDetected(Actor actor, const PanGesture& pan);
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
112 void TapDetected(Actor actor, const TapGesture& tap);
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
119 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
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.
126 virtual void ResourceReady( Visual::Base& object );
129 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
131 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
134 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
136 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
139 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
141 void UnregisterVisual( Property::Index index );
144 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
146 Toolkit::Visual::Base GetVisual( Property::Index index ) const;
149 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
151 void EnableVisual( Property::Index index, bool enable );
154 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
156 bool IsVisualEnabled( Property::Index index ) const;
159 * @brief Stops observing the given visual.
160 * @param[in] visual The visual to stop observing
162 void StopObservingVisual( Toolkit::Visual::Base& visual );
165 * @brief Starts observing the given visual.
166 * @param[in] visual The visual to start observing
168 void StartObservingVisual( Toolkit::Visual::Base& visual);
171 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
173 Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
176 * @brief Function used to set control properties.
177 * @param[in] object The object whose property to set
178 * @param[in] index The index of the property to set
179 * @param[in] value The value of the property to set
181 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
184 * @brief Function used to retrieve the value of control properties.
185 * @param[in] object The object whose property to get
186 * @param[in] index The index of the property to get
187 * @return The value of the property
189 static Property::Value GetProperty( BaseObject* object, Property::Index index );
192 * @brief Sets the state of the control.
193 * @param[in] newState The state to set
194 * @param[in] withTransitions Whether to show a transition when changing to the new state
196 void SetState( DevelControl::State newState, bool withTransitions=true );
199 * @brief Sets the sub-state of the control.
200 * @param[in] newState The sub-state to set
201 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
203 void SetSubState( const std::string& subStateName, bool withTransitions=true );
206 * @brief Replaces visuals and properties from the old state to the new state.
207 * @param[in] oldState The old state
208 * @param[in] newState The new state
209 * @param[in] subState The current sub state
211 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
214 * @brief Removes a visual from the control's container.
215 * @param[in] visuals The container of visuals
216 * @param[in] visualName The name of the visual to remove
218 void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
221 * @brief Removes several visuals from the control's container.
222 * @param[in] visuals The container of visuals
223 * @param[in] removeVisuals The visuals to remove
225 void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
228 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
229 * @param[in] visuals The control's visual container
230 * @param[out] instancedProperties The instanced properties are added to this container
232 void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
235 * @brief On state change, ensures visuals are moved or created appropriately.
237 * Go through the list of visuals that are common to both states.
238 * If they are different types, or are both image types with different
239 * URLs, then the existing visual needs moving and the new visual needs creating
241 * @param[in] stateVisualsToChange The visuals to change
242 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
244 void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
247 * @brief Whether the resource is ready
248 * @return True if the resource is read.
250 bool IsResourceReady() const;
252 Control& mControlImpl;
253 DevelControl::State mState;
254 std::string mSubStateName;
256 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
257 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
258 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
259 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
261 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
262 std::string mStyleName;
263 Vector4 mBackgroundColor; ///< The color of the background visual
264 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
265 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
266 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
267 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
269 Toolkit::DevelControl::ResourceReadySignalType mResourceReadySignal;
272 PinchGestureDetector mPinchGestureDetector;
273 PanGestureDetector mPanGestureDetector;
274 TapGestureDetector mTapGestureDetector;
275 LongPressGestureDetector mLongPressGestureDetector;
280 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
281 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
282 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
284 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
285 static const PropertyRegistration PROPERTY_1;
286 static const PropertyRegistration PROPERTY_2;
287 static const PropertyRegistration PROPERTY_3;
288 static const PropertyRegistration PROPERTY_4;
289 static const PropertyRegistration PROPERTY_5;
290 static const PropertyRegistration PROPERTY_6;
291 static const PropertyRegistration PROPERTY_7;
292 static const PropertyRegistration PROPERTY_8;
293 static const PropertyRegistration PROPERTY_9;
294 static const PropertyRegistration PROPERTY_10;
295 static const PropertyRegistration PROPERTY_11;
296 static const PropertyRegistration PROPERTY_12;
300 } // namespace Internal
302 } // namespace Toolkit
306 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H